2 * Copyright 2020 Google LLC.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "include/core/SkColorSpace.h"
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkRect.h"
13 #include "include/private/SkColorData.h"
14 #include "src/core/SkCanvasPriv.h"
15 #include "src/gpu/Swizzle.h"
16 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
17 #include "src/gpu/ganesh/SurfaceFillContext.h"
22 static constexpr int kSize = 64;
24 DEF_SIMPLE_GPU_GM_CAN_FAIL(clear_swizzle, rContext, canvas, errorMsg, 6*kSize, 2*kSize) {
25 if (rContext->abandoned()) {
26 *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
27 return DrawResult::kSkip;
30 auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas);
32 *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
33 return DrawResult::kSkip;
36 auto make_offscreen = [&](const SkISize dimensions) {
37 skgpu::Swizzle readSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
38 skgpu::Swizzle{"bgra"});
39 skgpu::Swizzle writeSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
40 skgpu::Swizzle{"bgra"});
41 return rContext->priv().makeSFC(kPremul_SkAlphaType,
42 sfc->colorInfo().refColorSpace(),
45 sfc->asSurfaceProxy()->backendFormat(),
48 sfc->asSurfaceProxy()->isProtected(),
51 kTopLeft_GrSurfaceOrigin,
59 {{ 0, 0, kSize, kSize}, {1, 0, 0, 1}},
60 {{kSize, 0, 2*kSize, kSize}, {0, 1, 0, 1}},
61 {{ 0, kSize, kSize, 2*kSize}, {0, 0, 1, 1}},
62 {{kSize, kSize, 2*kSize, 2*kSize}, {1, 0, 1, 1}},
65 // onscreen for reference
66 for (const auto& c : clears) {
67 sfc->clear(c.rect, c.color);
70 // partial clear offscreen
71 auto offscreen = make_offscreen({2*kSize, 2*kSize});
72 for (const auto& c : clears) {
73 offscreen->clear(c.rect, c.color);
75 sfc->blitTexture(offscreen->readSurfaceView(),
76 SkIRect::MakeSize({2*kSize, 2*kSize}),
77 SkIPoint{2*kSize, 0});
79 // full offscreen clears
80 for (const auto& c : clears) {
81 offscreen = make_offscreen(c.rect.size());
82 offscreen->clear(SkIRect::MakeSize(c.rect.size()), c.color);
83 sfc->blitTexture(offscreen->readSurfaceView(),
84 SkIRect::MakeSize(offscreen->dimensions()),
85 c.rect.topLeft() + SkIPoint{4*kSize, 0});
88 return DrawResult::kOk;