blob: 2e3a2b3ce6365f906fa3f85bf03f8446e130aa5c [file] [log] [blame]
John Stileseed56f02020-06-04 13:30:51 -04001/*
2 * Copyright 2019 Google LLC.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
Kevin Lubick677a12f2022-03-09 08:23:14 -05009#include "include/core/SkBitmap.h"
John Stileseed56f02020-06-04 13:30:51 -040010#include "include/core/SkCanvas.h"
11#include "include/core/SkImageInfo.h"
12#include "include/core/SkMatrix.h"
13#include "include/core/SkRect.h"
14#include "include/core/SkTypes.h"
Robert Phillips7a0d3c32021-07-21 15:39:51 -040015#include "src/core/SkCanvasPriv.h"
Kevin Lubickacdc1082023-06-09 11:05:24 -040016#include "src/gpu/ganesh/GrCanvas.h"
Greg Daniel719239c2022-04-07 11:20:24 -040017#include "src/gpu/ganesh/GrFragmentProcessor.h"
18#include "src/gpu/ganesh/SkGr.h"
19#include "src/gpu/ganesh/SurfaceFillContext.h"
20#include "src/gpu/ganesh/effects/GrTextureEffect.h"
Kevin Lubick8b741882023-10-06 11:41:38 -040021#include "tools/DecodeUtils.h"
John Stileseed56f02020-06-04 13:30:51 -040022#include "tools/Resources.h"
John Stileseed56f02020-06-04 13:30:51 -040023
Robert Phillips7a0d3c32021-07-21 15:39:51 -040024DEF_SIMPLE_GPU_GM(swizzle, rContext, canvas, 512, 512) {
Kevin Lubickacdc1082023-06-09 11:05:24 -040025 auto sfc = skgpu::ganesh::TopDeviceSurfaceFillContext(canvas);
John Stilesab7ff172021-07-30 10:59:25 -040026 if (!sfc) {
27 return;
28 }
Robert Phillips7a0d3c32021-07-21 15:39:51 -040029
John Stileseed56f02020-06-04 13:30:51 -040030 SkBitmap bmp;
Kevin Lubick8b741882023-10-06 11:41:38 -040031 ToolUtils::GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp);
Kevin Lubickdf73d162023-09-11 11:56:53 -040032 auto view = std::get<0>(GrMakeCachedBitmapProxyView(
33 rContext, bmp, /*label=*/"Gm_Swizzle", skgpu::Mipmapped::kNo));
John Stileseed56f02020-06-04 13:30:51 -040034 if (!view) {
35 return;
36 }
37 std::unique_ptr<GrFragmentProcessor> imgFP =
38 GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix());
Jim Van Verthd6245fc2022-02-15 16:30:59 -050039 auto fp = GrFragmentProcessor::SwizzleOutput(std::move(imgFP), skgpu::Swizzle("grb1"));
John Stileseed56f02020-06-04 13:30:51 -040040
Robert Phillips7a0d3c32021-07-21 15:39:51 -040041 sfc->fillWithFP(std::move(fp));
John Stileseed56f02020-06-04 13:30:51 -040042}