blob: a554c3ccb69fabf774d2e88345b8d3942d46cac7 [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"
Robert Phillips7a0d3c32021-07-21 15:39:51 -040014#include "src/core/SkCanvasPriv.h"
John Stileseed56f02020-06-04 13:30:51 -040015#include "src/gpu/GrFragmentProcessor.h"
Brian Salomon27c42022021-04-28 12:39:21 -040016#include "src/gpu/SkGr.h"
Robert Phillipsf3868622021-08-04 13:27:43 -040017#include "src/gpu/SurfaceFillContext.h"
Robert Phillips550de7f2021-07-06 16:28:52 -040018#include "src/gpu/effects/GrTextureEffect.h"
John Stileseed56f02020-06-04 13:30:51 -040019#include "tools/Resources.h"
John Stileseed56f02020-06-04 13:30:51 -040020
Robert Phillips7a0d3c32021-07-21 15:39:51 -040021DEF_SIMPLE_GPU_GM(swizzle, rContext, canvas, 512, 512) {
22 auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas);
John Stilesab7ff172021-07-30 10:59:25 -040023 if (!sfc) {
24 return;
25 }
Robert Phillips7a0d3c32021-07-21 15:39:51 -040026
John Stileseed56f02020-06-04 13:30:51 -040027 SkBitmap bmp;
28 GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp);
Robert Phillipsba701382021-07-07 14:15:12 -040029 auto view = std::get<0>(GrMakeCachedBitmapProxyView(rContext, bmp, 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
Robert Phillips7a0d3c32021-07-21 15:39:51 -040037 sfc->fillWithFP(std::move(fp));
John Stileseed56f02020-06-04 13:30:51 -040038}