xref: /aosp_15_r20/external/skia/gm/swizzle.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
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"
9 #include "include/core/SkBitmap.h"
10 #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"
15 #include "src/core/SkCanvasPriv.h"
16 #include "src/gpu/ganesh/GrCanvas.h"
17 #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"
21 #include "tools/DecodeUtils.h"
22 #include "tools/Resources.h"
23 
24 DEF_SIMPLE_GPU_GM(swizzle, rContext, canvas, 512, 512) {
25     auto sfc = skgpu::ganesh::TopDeviceSurfaceFillContext(canvas);
26     if (!sfc) {
27         return;
28     }
29 
30     SkBitmap bmp;
31     ToolUtils::GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp);
32     auto view = std::get<0>(GrMakeCachedBitmapProxyView(
33             rContext, bmp, /*label=*/"Gm_Swizzle", skgpu::Mipmapped::kNo));
34     if (!view) {
35         return;
36     }
37     std::unique_ptr<GrFragmentProcessor> imgFP =
38         GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix());
39     auto fp = GrFragmentProcessor::SwizzleOutput(std::move(imgFP), skgpu::Swizzle("grb1"));
40 
41     sfc->fillWithFP(std::move(fp));
42 }
43