| 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/SkBitmap.h" |
| 10 |
#include "include/core/SkCanvas.h" |
| 11 |
#include "include/core/SkImageInfo.h" |
| 12 |
#include "include/core/SkMatrix.h" |
| 13 |
#include "include/core/SkRect.h" |
| 14 |
#include "include/core/SkTypes.h" |
| 15 |
#include "src/core/SkCanvasPriv.h" |
| 16 |
#include "src/gpu/ganesh/GrCanvas.h" |
| 17 |
#include "src/gpu/ganesh/GrFragmentProcessor.h" |
| 18 |
#include "src/gpu/ganesh/SkGr.h" |
| 19 |
#include "src/gpu/ganesh/SurfaceFillContext.h" |
| 20 |
#include "src/gpu/ganesh/effects/GrTextureEffect.h" |
| 21 |
#include "src/gpu/ganesh/image/GrMippedBitmap.h" |
| 22 |
#include "tools/DecodeUtils.h" |
| 23 |
#include "tools/Resources.h" |
| 24 |
|
| 25 |
DEF_SIMPLE_GPU_GM(swizzle, rContext, canvas, 512, 512) { |
| 26 |
auto sfc = skgpu::ganesh::TopDeviceSurfaceFillContext(canvas); |
| 27 |
if (!sfc) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
SkBitmap bmp; |
| 32 |
ToolUtils::GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); |
| 33 |
auto bitmap = GrMippedBitmap::Make(bmp.pixmap()); |
| 34 |
SkASSERT_RELEASE(bitmap); |
| 35 |
SkAlphaType alphaType = bitmap->alphaType(); |
| 36 |
auto view = std::get<0>(GrMakeCachedBitmapProxyView( |
| 37 |
rContext, bitmap.value(), /*label=*/"Gm_Swizzle", skgpu::Mipmapped::kNo)); |
| 38 |
if (!view) { |
| 39 |
return; |
| 40 |
} |
| 41 |
std::unique_ptr<GrFragmentProcessor> imgFP = |
| 42 |
GrTextureEffect::Make(std::move(view), alphaType, SkMatrix()); |
| 43 |
auto fp = GrFragmentProcessor::SwizzleOutput(std::move(imgFP), skgpu::Swizzle("grb1")); |
| 44 |
|
| 45 |
sfc->fillWithFP(std::move(fp)); |
| 46 |
} |