Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
clear_swizzle.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 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
12#include "include/core/SkRect.h"
15#include "src/gpu/Swizzle.h"
19
20namespace skiagm {
21
22// Size of each clear
23static constexpr int kSize = 64;
24
25DEF_SIMPLE_GPU_GM_CAN_FAIL(clear_swizzle, rContext, canvas, errorMsg, 6*kSize, 2*kSize) {
26 if (rContext->abandoned()) {
28 return DrawResult::kSkip;
29 }
30
32 if (!sfc) {
34 return DrawResult::kSkip;
35 }
36
37 auto make_offscreen = [&](const SkISize dimensions) {
38 skgpu::Swizzle readSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
39 skgpu::Swizzle{"bgra"});
40 skgpu::Swizzle writeSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
41 skgpu::Swizzle{"bgra"});
42 return rContext->priv().makeSFC(kPremul_SkAlphaType,
43 sfc->colorInfo().refColorSpace(),
44 dimensions,
46 sfc->asSurfaceProxy()->backendFormat(),
47 /* sample count*/ 1,
48 skgpu::Mipmapped::kNo,
49 sfc->asSurfaceProxy()->isProtected(),
50 readSwizzle,
51 writeSwizzle,
54 /*label=*/{});
55 };
56
57 struct {
58 SkIRect rect;
60 } clears[] {
61 {{ 0, 0, kSize, kSize}, {1, 0, 0, 1}},
62 {{kSize, 0, 2*kSize, kSize}, {0, 1, 0, 1}},
63 {{ 0, kSize, kSize, 2*kSize}, {0, 0, 1, 1}},
64 {{kSize, kSize, 2*kSize, 2*kSize}, {1, 0, 1, 1}},
65 };
66
67 // onscreen for reference
68 for (const auto& c : clears) {
69 sfc->clear(c.rect, c.color);
70 }
71
72 // partial clear offscreen
73 auto offscreen = make_offscreen({2*kSize, 2*kSize});
74 for (const auto& c : clears) {
75 offscreen->clear(c.rect, c.color);
76 }
77 sfc->blitTexture(offscreen->readSurfaceView(),
79 SkIPoint{2*kSize, 0});
80
81 // full offscreen clears
82 for (const auto& c : clears) {
83 offscreen = make_offscreen(c.rect.size());
84 offscreen->clear(SkIRect::MakeSize(c.rect.size()), c.color);
85 sfc->blitTexture(offscreen->readSurfaceView(),
86 SkIRect::MakeSize(offscreen->dimensions()),
87 c.rect.topLeft() + SkIPoint{4*kSize, 0});
88 }
89
90 return DrawResult::kOk;
91}
92
93} // namespace skiagm
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
SkColor4f color
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
static constexpr Swizzle Concat(const Swizzle &a, const Swizzle &b)
Definition Swizzle.h:156
static constexpr char kErrorMsg_DrawSkippedGpuOnly[]
Definition gm.h:127
SurfaceFillContext * TopDeviceSurfaceFillContext(const SkCanvas *canvas)
Definition GrCanvas.cpp:27
DEF_SIMPLE_GPU_GM_CAN_FAIL(clear_swizzle, rContext, canvas, errorMsg, 6 *kSize, 2 *kSize)
constexpr int kSize
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66
constexpr SkIPoint topLeft() const
Definition SkRect.h:151