John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 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" |
Kevin Lubick | 677a12f | 2022-03-09 08:23:14 -0500 | [diff] [blame] | 9 | #include "include/core/SkBitmap.h" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 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" |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 15 | #include "src/core/SkCanvasPriv.h" |
Kevin Lubick | acdc108 | 2023-06-09 11:05:24 -0400 | [diff] [blame] | 16 | #include "src/gpu/ganesh/GrCanvas.h" |
Greg Daniel | 719239c | 2022-04-07 11:20:24 -0400 | [diff] [blame] | 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" |
Kevin Lubick | 8b74188 | 2023-10-06 11:41:38 -0400 | [diff] [blame] | 21 | #include "tools/DecodeUtils.h" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 22 | #include "tools/Resources.h" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 23 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 24 | DEF_SIMPLE_GPU_GM(swizzle, rContext, canvas, 512, 512) { |
Kevin Lubick | acdc108 | 2023-06-09 11:05:24 -0400 | [diff] [blame] | 25 | auto sfc = skgpu::ganesh::TopDeviceSurfaceFillContext(canvas); |
John Stiles | ab7ff17 | 2021-07-30 10:59:25 -0400 | [diff] [blame] | 26 | if (!sfc) { |
| 27 | return; |
| 28 | } |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 29 | |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 30 | SkBitmap bmp; |
Kevin Lubick | 8b74188 | 2023-10-06 11:41:38 -0400 | [diff] [blame] | 31 | ToolUtils::GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); |
Kevin Lubick | df73d16 | 2023-09-11 11:56:53 -0400 | [diff] [blame] | 32 | auto view = std::get<0>(GrMakeCachedBitmapProxyView( |
| 33 | rContext, bmp, /*label=*/"Gm_Swizzle", skgpu::Mipmapped::kNo)); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 34 | if (!view) { |
| 35 | return; |
| 36 | } |
| 37 | std::unique_ptr<GrFragmentProcessor> imgFP = |
| 38 | GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix()); |
Jim Van Verth | d6245fc | 2022-02-15 16:30:59 -0500 | [diff] [blame] | 39 | auto fp = GrFragmentProcessor::SwizzleOutput(std::move(imgFP), skgpu::Swizzle("grb1")); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 40 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 41 | sfc->fillWithFP(std::move(fp)); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 42 | } |