blob: e08079f87e0a1244ff6a84e7e90d3b0ef55ac9c2 [file] [log] [blame]
John Stileseed56f02020-06-04 13:30:51 -04001/*
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 Stileseed56f02020-06-04 13:30:51 -040014#include "src/gpu/GrBitmapTextureMaker.h"
Adlai Hollera0693042020-10-14 11:23:11 -040015#include "src/gpu/GrDirectContextPriv.h"
John Stileseed56f02020-06-04 13:30:51 -040016#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
23DEF_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 Salomon7e67dca2020-07-21 09:27:25 -040029 auto view = maker.view(GrMipmapped::kNo);
John Stileseed56f02020-06-04 13:30:51 -040030 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 Stiles5933d7d2020-07-21 12:28:35 -040038 grPaint.setColorFragmentProcessor(std::move(fp));
John Stileseed56f02020-06-04 13:30:51 -040039
40 rtCtx->priv().testingOnly_addDrawOp(
41 GrFillRectOp::MakeNonAARect(ctx, std::move(grPaint), SkMatrix(), bounds));
42}