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" |
| 14 | #include "include/gpu/GrContext.h" |
| 15 | #include "src/gpu/GrBitmapTextureMaker.h" |
| 16 | #include "src/gpu/GrContextPriv.h" |
| 17 | #include "src/gpu/GrFragmentProcessor.h" |
| 18 | #include "src/gpu/GrRenderTargetContext.h" |
| 19 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 20 | #include "src/gpu/ops/GrFillRectOp.h" |
| 21 | #include "tools/Resources.h" |
| 22 | #include "tools/ToolUtils.h" |
| 23 | |
| 24 | DEF_SIMPLE_GPU_GM(swizzle, ctx, rtCtx, canvas, 512, 512) { |
| 25 | SkRect bounds = SkRect::MakeIWH(512, 512); |
| 26 | |
| 27 | SkBitmap bmp; |
| 28 | GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); |
| 29 | GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw); |
| 30 | auto view = maker.view(GrMipMapped::kNo); |
| 31 | if (!view) { |
| 32 | return; |
| 33 | } |
| 34 | std::unique_ptr<GrFragmentProcessor> imgFP = |
| 35 | GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix()); |
| 36 | auto fp = GrFragmentProcessor::SwizzleOutput(std::move(imgFP), GrSwizzle("grb1")); |
| 37 | |
| 38 | GrPaint grPaint; |
| 39 | grPaint.addColorFragmentProcessor(std::move(fp)); |
| 40 | |
| 41 | rtCtx->priv().testingOnly_addDrawOp( |
| 42 | GrFillRectOp::MakeNonAARect(ctx, std::move(grPaint), SkMatrix(), bounds)); |
| 43 | } |