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" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkImageInfo.h" |
| 11 | #include "include/core/SkMatrix.h" |
| 12 | #include "include/core/SkRect.h" |
| 13 | #include "include/core/SkTypes.h" |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 14 | #include "src/core/SkCanvasPriv.h" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrFragmentProcessor.h" |
Brian Salomon | 27c4202 | 2021-04-28 12:39:21 -0400 | [diff] [blame] | 16 | #include "src/gpu/SkGr.h" |
Robert Phillips | f386862 | 2021-08-04 13:27:43 -0400 | [diff] [blame^] | 17 | #include "src/gpu/SurfaceFillContext.h" |
Robert Phillips | 550de7f | 2021-07-06 16:28:52 -0400 | [diff] [blame] | 18 | #include "src/gpu/effects/GrTextureEffect.h" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 19 | #include "tools/Resources.h" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 20 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 21 | DEF_SIMPLE_GPU_GM(swizzle, rContext, canvas, 512, 512) { |
| 22 | auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas); |
John Stiles | ab7ff17 | 2021-07-30 10:59:25 -0400 | [diff] [blame] | 23 | if (!sfc) { |
| 24 | return; |
| 25 | } |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 26 | |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 27 | SkBitmap bmp; |
| 28 | GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); |
Robert Phillips | ba70138 | 2021-07-07 14:15:12 -0400 | [diff] [blame] | 29 | auto view = std::get<0>(GrMakeCachedBitmapProxyView(rContext, bmp, GrMipmapped::kNo)); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 30 | if (!view) { |
| 31 | return; |
| 32 | } |
| 33 | std::unique_ptr<GrFragmentProcessor> imgFP = |
| 34 | GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix()); |
| 35 | auto fp = GrFragmentProcessor::SwizzleOutput(std::move(imgFP), GrSwizzle("grb1")); |
| 36 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 37 | sfc->fillWithFP(std::move(fp)); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 38 | } |