blob: fe10373ec0b2e782b14235d165823427328e9b86 [file] [log] [blame]
Brian Salomon07bc9a22020-12-02 13:37:16 -05001/*
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"
Kevin Lubick8499e372022-04-05 12:56:01 -04009
10#include "include/core/SkColorSpace.h"
Brian Salomon07bc9a22020-12-02 13:37:16 -050011#include "include/core/SkPoint.h"
12#include "include/core/SkRect.h"
13#include "include/private/SkColorData.h"
Robert Phillips7a0d3c32021-07-21 15:39:51 -040014#include "src/core/SkCanvasPriv.h"
Jim Van Verthd6245fc2022-02-15 16:30:59 -050015#include "src/gpu/Swizzle.h"
Kevin Lubickacdc1082023-06-09 11:05:24 -040016#include "src/gpu/ganesh/GrCanvas.h"
Greg Daniel719239c2022-04-07 11:20:24 -040017#include "src/gpu/ganesh/GrRecordingContextPriv.h"
18#include "src/gpu/ganesh/SurfaceFillContext.h"
Brian Salomon07bc9a22020-12-02 13:37:16 -050019
Robert Phillips7a0d3c32021-07-21 15:39:51 -040020namespace skiagm {
21
Brian Salomon07bc9a22020-12-02 13:37:16 -050022// Size of each clear
23static constexpr int kSize = 64;
24
Robert Phillips7a0d3c32021-07-21 15:39:51 -040025DEF_SIMPLE_GPU_GM_CAN_FAIL(clear_swizzle, rContext, canvas, errorMsg, 6*kSize, 2*kSize) {
26 if (rContext->abandoned()) {
27 *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
28 return DrawResult::kSkip;
29 }
30
Kevin Lubickacdc1082023-06-09 11:05:24 -040031 auto sfc = skgpu::ganesh::TopDeviceSurfaceFillContext(canvas);
Robert Phillips400f52e2021-07-26 13:23:10 -040032 if (!sfc) {
Robert Phillips7a0d3c32021-07-21 15:39:51 -040033 *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
34 return DrawResult::kSkip;
Brian Salomon07bc9a22020-12-02 13:37:16 -050035 }
36
37 auto make_offscreen = [&](const SkISize dimensions) {
Jim Van Verthd6245fc2022-02-15 16:30:59 -050038 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"});
Robert Phillips33bf2b52021-08-02 11:14:38 -040042 return rContext->priv().makeSFC(kPremul_SkAlphaType,
43 sfc->colorInfo().refColorSpace(),
44 dimensions,
45 SkBackingFit::kExact,
46 sfc->asSurfaceProxy()->backendFormat(),
47 /* sample count*/ 1,
Kevin Lubickdf73d162023-09-11 11:56:53 -040048 skgpu::Mipmapped::kNo,
Robert Phillips33bf2b52021-08-02 11:14:38 -040049 sfc->asSurfaceProxy()->isProtected(),
50 readSwizzle,
51 writeSwizzle,
52 kTopLeft_GrSurfaceOrigin,
Kevin Lubickecd3a2f2023-01-05 08:17:45 -050053 skgpu::Budgeted::kYes,
Aditya Kushwah97f17482022-08-31 17:04:26 -070054 /*label=*/{});
Brian Salomon07bc9a22020-12-02 13:37:16 -050055 };
56
57 struct {
58 SkIRect rect;
59 SkPMColor4f color;
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) {
Robert Phillips400f52e2021-07-26 13:23:10 -040069 sfc->clear(c.rect, c.color);
Brian Salomon07bc9a22020-12-02 13:37:16 -050070 }
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 }
Robert Phillips400f52e2021-07-26 13:23:10 -040077 sfc->blitTexture(offscreen->readSurfaceView(),
Robert Phillips7a0d3c32021-07-21 15:39:51 -040078 SkIRect::MakeSize({2*kSize, 2*kSize}),
79 SkIPoint{2*kSize, 0});
Brian Salomon07bc9a22020-12-02 13:37:16 -050080
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);
Robert Phillips400f52e2021-07-26 13:23:10 -040085 sfc->blitTexture(offscreen->readSurfaceView(),
Robert Phillips7a0d3c32021-07-21 15:39:51 -040086 SkIRect::MakeSize(offscreen->dimensions()),
87 c.rect.topLeft() + SkIPoint{4*kSize, 0});
Brian Salomon07bc9a22020-12-02 13:37:16 -050088 }
Robert Phillips7a0d3c32021-07-21 15:39:51 -040089
90 return DrawResult::kOk;
Brian Salomon07bc9a22020-12-02 13:37:16 -050091}
Robert Phillips7a0d3c32021-07-21 15:39:51 -040092
93} // namespace skiagm