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" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrBitmapTextureMaker.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrDirectContextPriv.h" |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrFragmentProcessor.h" |
| 17 | #include "src/gpu/GrRenderTargetContext.h" |
| 18 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 19 | #include "src/gpu/ops/GrFillRectOp.h" |
| 20 | #include "tools/Resources.h" |
| 21 | #include "tools/ToolUtils.h" |
| 22 | |
| 23 | DEF_SIMPLE_GPU_GM(swizzle, ctx, rtCtx, canvas, 512, 512) { |
| 24 | SkRect bounds = SkRect::MakeIWH(512, 512); |
| 25 | |
| 26 | SkBitmap bmp; |
| 27 | GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); |
| 28 | GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw); |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 29 | auto view = maker.view(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 | |
| 37 | GrPaint grPaint; |
John Stiles | 5933d7d | 2020-07-21 12:28:35 -0400 | [diff] [blame] | 38 | grPaint.setColorFragmentProcessor(std::move(fp)); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 39 | |
| 40 | rtCtx->priv().testingOnly_addDrawOp( |
| 41 | GrFillRectOp::MakeNonAARect(ctx, std::move(grPaint), SkMatrix(), bounds)); |
| 42 | } |