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 "src/core/SkCanvasPriv.h" 15#include "src/gpu/GrFragmentProcessor.h" 16#include "src/gpu/SkGr.h" 17#include "src/gpu/SurfaceFillContext.h" 18#include "src/gpu/effects/GrTextureEffect.h" 19#include "tools/Resources.h" 20 21DEF_SIMPLE_GPU_GM(swizzle, rContext, canvas, 512, 512) { 22 auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas); 23 if (!sfc) { 24 return; 25 } 26 27 SkBitmap bmp; 28 GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); 29 auto view = std::get<0>(GrMakeCachedBitmapProxyView(rContext, bmp, GrMipmapped::kNo)); 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 sfc->fillWithFP(std::move(fp)); 38} 39