blob: 7873513ec3e1532ac6f7b063e60cdb3763f27cde [file] [log] [blame]
Chris Daltond7291ba2019-03-07 14:17:03 -07001/*
2 * Copyright 2019 Google Inc.
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkBlendMode.h"
10#include "include/core/SkCanvas.h"
11#include "include/core/SkColorSpace.h"
12#include "include/core/SkMatrix.h"
13#include "include/core/SkRect.h"
14#include "include/core/SkRefCnt.h"
15#include "include/core/SkSize.h"
16#include "include/core/SkString.h"
17#include "include/core/SkTypes.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040018#include "include/gpu/GrRecordingContext.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040019#include "include/gpu/GrTypes.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040020#include "include/private/GrTypesPriv.h"
21#include "include/private/SkColorData.h"
22#include "src/gpu/GrBuffer.h"
23#include "src/gpu/GrCaps.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040024#include "src/gpu/GrColorSpaceXform.h"
Adlai Hollera0693042020-10-14 11:23:11 -040025#include "src/gpu/GrDirectContextPriv.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040026#include "src/gpu/GrGeometryProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/GrMemoryPool.h"
28#include "src/gpu/GrOpFlushState.h"
Greg Daniel2d41d0d2019-08-26 11:08:51 -040029#include "src/gpu/GrOpsRenderPass.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040030#include "src/gpu/GrPaint.h"
31#include "src/gpu/GrPipeline.h"
32#include "src/gpu/GrPrimitiveProcessor.h"
33#include "src/gpu/GrProcessor.h"
34#include "src/gpu/GrProcessorSet.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050035#include "src/gpu/GrRecordingContextPriv.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040036#include "src/gpu/GrSamplerState.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040037#include "src/gpu/GrShaderCaps.h"
38#include "src/gpu/GrShaderVar.h"
Brian Salomoneebe7352020-12-09 16:37:04 -050039#include "src/gpu/GrSurfaceDrawContext.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040040#include "src/gpu/GrSurfaceProxy.h"
41#include "src/gpu/GrTextureProxy.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040042#include "src/gpu/GrUserStencilSettings.h"
43#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050044#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
45#include "src/gpu/glsl/GrGLSLGeometryProcessor.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040046#include "src/gpu/glsl/GrGLSLPrimitiveProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050047#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
48#include "src/gpu/glsl/GrGLSLVarying.h"
49#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040050#include "src/gpu/ops/GrDrawOp.h"
51#include "src/gpu/ops/GrOp.h"
Robert Phillips34cea002019-11-21 16:02:34 -050052#include "tools/gpu/ProxyUtils.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040053
54#include <memory>
55#include <utility>
56
57class GrAppliedClip;
58class GrGLSLProgramDataManager;
Chris Daltond7291ba2019-03-07 14:17:03 -070059
60namespace skiagm {
61
62enum class GradType : bool {
63 kHW,
64 kSW
65};
66
67/**
68 * This test ensures that the shaderBuilder's sample offsets and sample mask are correlated with
69 * actual HW sample locations. It does so by drawing pseudo-random subpixel boxes, and only turning
70 * off the samples whose locations fall inside the boxes.
71 */
72class SampleLocationsGM : public GpuGM {
73public:
74 SampleLocationsGM(GradType gradType, GrSurfaceOrigin origin)
75 : fGradType(gradType)
76 , fOrigin(origin) {}
77
78private:
Hal Canaryfa3305a2019-07-18 12:36:54 -040079 SkString onShortName() override {
80 return SkStringPrintf("samplelocations%s%s",
81 (GradType::kHW == fGradType) ? "_hwgrad" : "_swgrad",
82 (kTopLeft_GrSurfaceOrigin == fOrigin) ? "_topleft" : "_botleft");
83 }
84
Chris Daltond7291ba2019-03-07 14:17:03 -070085 SkISize onISize() override { return SkISize::Make(200, 200); }
Brian Salomoneebe7352020-12-09 16:37:04 -050086 DrawResult onDraw(GrRecordingContext*, GrSurfaceDrawContext*,
Robert Phillips95c250c2020-06-29 15:36:12 -040087 SkCanvas*, SkString* errorMsg) override;
Chris Daltond7291ba2019-03-07 14:17:03 -070088
89 const GradType fGradType;
90 const GrSurfaceOrigin fOrigin;
91};
92
93////////////////////////////////////////////////////////////////////////////////////////////////////
94// SkSL code.
95
96class SampleLocationsTestProcessor : public GrGeometryProcessor {
97public:
Robert Phillipsfbfc3552019-11-18 11:50:54 -050098 static GrGeometryProcessor* Make(SkArenaAlloc* arena, GradType gradType) {
Mike Kleinf1241082020-12-14 15:59:09 -060099 return arena->make([&](void* ptr) {
100 return new (ptr) SampleLocationsTestProcessor(gradType);
101 });
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500102 }
103
104 const char* name() const override { return "SampleLocationsTestProcessor"; }
105
106 void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
107 b->add32((uint32_t)fGradType);
108 }
109
110 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
111
112private:
Chris Daltond7291ba2019-03-07 14:17:03 -0700113 SampleLocationsTestProcessor(GradType gradType)
114 : GrGeometryProcessor(kSampleLocationsTestProcessor_ClassID)
115 , fGradType(gradType) {
116 this->setWillUseCustomFeature(CustomFeatures::kSampleLocations);
117 }
Chris Daltond7291ba2019-03-07 14:17:03 -0700118
Chris Daltond7291ba2019-03-07 14:17:03 -0700119 const GradType fGradType;
120
121 class Impl;
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500122
John Stiles7571f9e2020-09-02 22:42:33 -0400123 using INHERITED = GrGeometryProcessor;
Chris Daltond7291ba2019-03-07 14:17:03 -0700124};
125
126class SampleLocationsTestProcessor::Impl : public GrGLSLGeometryProcessor {
127 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
128 const auto& proc = args.fGP.cast<SampleLocationsTestProcessor>();
129 auto* v = args.fVertBuilder;
130 auto* f = args.fFragBuilder;
131
132 GrGLSLVarying coord(kFloat2_GrSLType);
133 GrGLSLVarying grad(kFloat2_GrSLType);
134 args.fVaryingHandler->addVarying("coord", &coord);
135 if (GradType::kSW == proc.fGradType) {
136 args.fVaryingHandler->addVarying("grad", &grad);
137 }
138
139 // Pixel grid.
140 v->codeAppendf("int x = sk_InstanceID %% 200;");
141 v->codeAppendf("int y = sk_InstanceID / 200;");
142
143 // Create pseudo-random rectangles inside a 16x16 subpixel grid. This works out nicely
144 // because there are 17 positions on the grid (including both edges), and 17 is a great
145 // prime number for generating pseudo-random numbers.
146 v->codeAppendf("int ileft = (sk_InstanceID*929) %% 17;");
147 v->codeAppendf("int iright = ileft + 1 + ((sk_InstanceID*1637) %% (17 - ileft));");
148 v->codeAppendf("int itop = (sk_InstanceID*313) %% 17;");
149 v->codeAppendf("int ibot = itop + 1 + ((sk_InstanceID*1901) %% (17 - itop));");
150
151 // Outset (or inset) the rectangle, for the very likely scenario that samples fall on exact
152 // 16ths of a pixel. GL_SUBPIXEL_BITS is allowed to be as low as 4, so try not to let the
153 // outset value to get too small.
154 v->codeAppendf("float outset = 1/32.0;");
155 v->codeAppendf("outset = (0 == (x + y) %% 2) ? -outset : +outset;");
John Stilesaf9b58e2021-01-13 17:48:36 -0500156 v->codeAppendf("float l = float(ileft)/16.0 - outset;");
157 v->codeAppendf("float r = float(iright)/16.0 + outset;");
158 v->codeAppendf("float t = float(itop)/16.0 - outset;");
159 v->codeAppendf("float b = float(ibot)/16.0 + outset;");
Chris Daltond7291ba2019-03-07 14:17:03 -0700160
161 v->codeAppendf("float2 vertexpos;");
162 v->codeAppendf("vertexpos.x = float(x) + ((0 == (sk_VertexID %% 2)) ? l : r);");
163 v->codeAppendf("vertexpos.y = float(y) + ((0 == (sk_VertexID / 2)) ? t : b);");
164 gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertexpos");
165
166 v->codeAppendf("%s.x = (0 == (sk_VertexID %% 2)) ? -1 : +1;", coord.vsOut());
167 v->codeAppendf("%s.y = (0 == (sk_VertexID / 2)) ? -1 : +1;", coord.vsOut());
168 if (GradType::kSW == proc.fGradType) {
169 v->codeAppendf("%s = 2/float2(r - l, b - t);", grad.vsOut());
170 }
171
172 // Fragment shader: Output RED.
173 f->codeAppendf("%s = half4(1,0,0,1);", args.fOutputColor);
174 f->codeAppendf("%s = half4(1);", args.fOutputCoverage);
175
176 // Now turn off all the samples inside our sub-rectangle. As long as the shaderBuilder's
177 // sample offsets and sample mask are correlated with actual HW sample locations, no red
178 // will bleed through.
179 f->codeAppendf("for (int i = 0; i < %i; ++i) {",
180 f->getProgramBuilder()->effectiveSampleCnt());
181 if (GradType::kHW == proc.fGradType) {
182 f->codeAppendf("float2x2 grad = float2x2(dFdx(%s), dFdy(%s));",
183 coord.fsIn(), coord.fsIn());
184 } else {
185 f->codeAppendf("float2x2 grad = float2x2(%s.x, 0, 0, %s.y);", grad.fsIn(), grad.fsIn());
186 }
187 f->codeAppendf( "float2 samplecoord = %s[i] * grad + %s;",
188 f->sampleOffsets(), coord.fsIn());
189 f->codeAppendf( "if (all(lessThanEqual(abs(samplecoord), float2(1)))) {");
190 f->maskOffMultisampleCoverage(
Chris Dalton0dffbab2019-03-27 13:08:50 -0600191 "~(1 << i)", GrGLSLFPFragmentBuilder::ScopeFlags::kInsideLoop);
Chris Daltond7291ba2019-03-07 14:17:03 -0700192 f->codeAppendf( "}");
193 f->codeAppendf("}");
194 }
195
Brian Osman609f1592020-07-01 15:14:39 -0400196 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) override {}
Chris Daltond7291ba2019-03-07 14:17:03 -0700197};
198
199GrGLSLPrimitiveProcessor* SampleLocationsTestProcessor::createGLSLInstance(
200 const GrShaderCaps&) const {
201 return new Impl();
202}
203
204////////////////////////////////////////////////////////////////////////////////////////////////////
205// Draw Op.
206
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500207static constexpr GrUserStencilSettings gStencilWrite(
208 GrUserStencilSettings::StaticInit<
209 0x0001,
210 GrUserStencilTest::kAlways,
211 0xffff,
212 GrUserStencilOp::kReplace,
213 GrUserStencilOp::kKeep,
214 0xffff>()
215);
216
Chris Daltond7291ba2019-03-07 14:17:03 -0700217class SampleLocationsTestOp : public GrDrawOp {
218public:
219 DEFINE_OP_CLASS_ID
220
Herb Derbyc76d4092020-10-07 16:46:15 -0400221 static GrOp::Owner Make(
Chris Daltond7291ba2019-03-07 14:17:03 -0700222 GrRecordingContext* ctx, const SkMatrix& viewMatrix, GradType gradType) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400223 return GrOp::Make<SampleLocationsTestOp>(ctx, gradType);
Chris Daltond7291ba2019-03-07 14:17:03 -0700224 }
225
226private:
227 SampleLocationsTestOp(GradType gradType) : GrDrawOp(ClassID()), fGradType(gradType) {
Greg Daniel5faf4742019-10-01 15:14:44 -0400228 this->setBounds(SkRect::MakeIWH(200, 200), HasAABloat::kNo, IsHairline::kNo);
Chris Daltond7291ba2019-03-07 14:17:03 -0700229 }
230
231 const char* name() const override { return "SampleLocationsTestOp"; }
232 FixedFunctionFlags fixedFunctionFlags() const override {
233 return FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil;
234 }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600235 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
236 bool hasMixedSampledCoverage, GrClampType) override {
Chris Daltond7291ba2019-03-07 14:17:03 -0700237 return GrProcessorSet::EmptySetAnalysis();
238 }
Chris Daltond7291ba2019-03-07 14:17:03 -0700239
Robert Phillipsac6156c2020-02-28 16:02:40 -0500240
241 GrProgramInfo* createProgramInfo(const GrCaps* caps,
242 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500243 const GrSurfaceProxyView& writeView,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500244 GrAppliedClip&& appliedClip,
Greg Danield358cbe2020-09-11 09:33:54 -0400245 const GrXferProcessor::DstProxyView& dstProxyView,
Greg Daniel42dbca52020-11-20 10:22:43 -0500246 GrXferBarrierFlags renderPassXferBarriers,
247 GrLoadOp colorLoadOp) const {
Robert Phillipsac6156c2020-02-28 16:02:40 -0500248 GrGeometryProcessor* geomProc = SampleLocationsTestProcessor::Make(arena, fGradType);
249
250 GrPipeline::InputFlags flags = GrPipeline::InputFlags::kHWAntialias;
251
Brian Salomon8afde5f2020-04-01 16:22:00 -0400252 return sk_gpu_test::CreateProgramInfo(caps, arena, writeView,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500253 std::move(appliedClip), dstProxyView,
254 geomProc, SkBlendMode::kSrcOver,
255 GrPrimitiveType::kTriangleStrip,
Greg Daniel42dbca52020-11-20 10:22:43 -0500256 renderPassXferBarriers, colorLoadOp,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500257 flags, &gStencilWrite);
258 }
259
260 GrProgramInfo* createProgramInfo(GrOpFlushState* flushState) const {
261 return this->createProgramInfo(&flushState->caps(),
262 flushState->allocator(),
Brian Salomon8afde5f2020-04-01 16:22:00 -0400263 flushState->writeView(),
Robert Phillipsac6156c2020-02-28 16:02:40 -0500264 flushState->detachAppliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400265 flushState->dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500266 flushState->renderPassBarriers(),
267 flushState->colorLoadOp());
Robert Phillipsac6156c2020-02-28 16:02:40 -0500268 }
269
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500270 void onPrePrepare(GrRecordingContext* context,
Adlai Hollere2296f72020-11-19 13:41:26 -0500271 const GrSurfaceProxyView& writeView,
Robert Phillips34cea002019-11-21 16:02:34 -0500272 GrAppliedClip* clip,
Greg Danield358cbe2020-09-11 09:33:54 -0400273 const GrXferProcessor::DstProxyView& dstProxyView,
Greg Daniel42dbca52020-11-20 10:22:43 -0500274 GrXferBarrierFlags renderPassXferBarriers,
275 GrLoadOp colorLoadOp) final {
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500276 // We're going to create the GrProgramInfo (and the GrPipeline and geometry processor
277 // it relies on) in the DDL-record-time arena.
278 SkArenaAlloc* arena = context->priv().recordTimeAllocator();
Chris Daltonbaa1b352019-04-03 12:03:00 -0600279
Robert Phillips34cea002019-11-21 16:02:34 -0500280 // This is equivalent to a GrOpFlushState::detachAppliedClip
Michael Ludwigd1d997e2020-06-04 15:52:44 -0400281 GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled();
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500282
Brian Salomon8afde5f2020-04-01 16:22:00 -0400283 fProgramInfo = this->createProgramInfo(context->priv().caps(), arena, writeView,
Greg Danield358cbe2020-09-11 09:33:54 -0400284 std::move(appliedClip), dstProxyView,
Greg Daniel42dbca52020-11-20 10:22:43 -0500285 renderPassXferBarriers, colorLoadOp);
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500286
Robert Phillipsac6156c2020-02-28 16:02:40 -0500287 context->priv().recordProgramInfo(fProgramInfo);
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500288 }
289
290 void onPrepare(GrOpFlushState*) final {}
291
292 void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) final {
Robert Phillips34cea002019-11-21 16:02:34 -0500293 if (!fProgramInfo) {
Robert Phillipsac6156c2020-02-28 16:02:40 -0500294 fProgramInfo = this->createProgramInfo(flushState);
Robert Phillips34cea002019-11-21 16:02:34 -0500295 }
296
Chris Daltonaa0e45c2020-03-16 10:05:11 -0600297 flushState->bindPipelineAndScissorClip(*fProgramInfo, SkRect::MakeIWH(200, 200));
298 flushState->bindBuffers(nullptr, nullptr, nullptr);
299 flushState->drawInstanced(200*200, 0, 4, 0);
Chris Daltond7291ba2019-03-07 14:17:03 -0700300 }
301
302 const GradType fGradType;
303
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500304 // The program info (and both the GrPipeline and GrPrimitiveProcessor it relies on), when
Robert Phillips34cea002019-11-21 16:02:34 -0500305 // allocated, are allocated in either the ddl-record-time or flush-time arena. It is the
306 // arena's job to free up their memory so we just have a bare programInfo pointer here. We
307 // don't even store the GrPipeline and GrPrimitiveProcessor pointers here bc they are
308 // guaranteed to have the same lifetime as the program info.
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500309 GrProgramInfo* fProgramInfo = nullptr;
310
Herb Derbyc76d4092020-10-07 16:46:15 -0400311 friend class ::GrOp; // for ctor
Robert Phillipsfbfc3552019-11-18 11:50:54 -0500312
John Stiles7571f9e2020-09-02 22:42:33 -0400313 using INHERITED = GrDrawOp;
Chris Daltond7291ba2019-03-07 14:17:03 -0700314};
315
316////////////////////////////////////////////////////////////////////////////////////////////////////
317// Test.
318
Brian Salomoneebe7352020-12-09 16:37:04 -0500319DrawResult SampleLocationsGM::onDraw(GrRecordingContext* ctx, GrSurfaceDrawContext* rtc,
Robert Phillips95c250c2020-06-29 15:36:12 -0400320 SkCanvas* canvas, SkString* errorMsg) {
Chris Daltond7291ba2019-03-07 14:17:03 -0700321 if (!ctx->priv().caps()->sampleLocationsSupport()) {
322 *errorMsg = "Requires support for sample locations.";
323 return DrawResult::kSkip;
324 }
Chris Dalton8a64a442019-10-29 18:54:58 -0600325 if (!ctx->priv().caps()->shaderCaps()->sampleMaskSupport()) {
326 *errorMsg = "Requires support for sample mask.";
Chris Daltond7291ba2019-03-07 14:17:03 -0700327 return DrawResult::kSkip;
328 }
Chris Dalton03fdf6a2020-04-07 12:31:59 -0600329 if (!ctx->priv().caps()->drawInstancedSupport()) {
330 *errorMsg = "Requires support for instanced rendering.";
331 return DrawResult::kSkip;
332 }
Chris Daltoneffee202019-07-01 22:28:03 -0600333 if (rtc->numSamples() <= 1 && !ctx->priv().caps()->mixedSamplesSupport()) {
334 *errorMsg = "MSAA and mixed samples only.";
335 return DrawResult::kSkip;
336 }
337
Brian Salomoneebe7352020-12-09 16:37:04 -0500338 auto offscreenRTC = GrSurfaceDrawContext::Make(
Greg Daniele20fcad2020-01-08 11:52:34 -0500339 ctx, rtc->colorInfo().colorType(), nullptr, SkBackingFit::kExact, {200, 200},
Brian Salomon7e67dca2020-07-21 09:27:25 -0400340 rtc->numSamples(), GrMipmapped::kNo, GrProtected::kNo, fOrigin);
Chris Daltoneffee202019-07-01 22:28:03 -0600341 if (!offscreenRTC) {
342 *errorMsg = "Failed to create offscreen render target.";
343 return DrawResult::kFail;
344 }
345 if (offscreenRTC->numSamples() <= 1 &&
Greg Daniel46e366a2019-12-16 14:38:36 -0500346 !offscreenRTC->asRenderTargetProxy()->canUseMixedSamples(*ctx->priv().caps())) {
Chris Daltoneffee202019-07-01 22:28:03 -0600347 *errorMsg = "MSAA and mixed samples only.";
348 return DrawResult::kSkip;
349 }
Chris Daltond7291ba2019-03-07 14:17:03 -0700350
351 static constexpr GrUserStencilSettings kStencilCover(
352 GrUserStencilSettings::StaticInit<
353 0x0000,
354 GrUserStencilTest::kNotEqual,
355 0xffff,
356 GrUserStencilOp::kZero,
357 GrUserStencilOp::kKeep,
358 0xffff>()
359 );
360
Brian Salomon590f5672020-12-16 11:44:47 -0500361 offscreenRTC->clear(SkPMColor4f{0, 1, 0, 1});
Chris Daltond7291ba2019-03-07 14:17:03 -0700362
Chris Daltoneffee202019-07-01 22:28:03 -0600363 // Stencil.
Brian Salomon70fe17e2020-11-30 14:33:58 -0500364 offscreenRTC->addDrawOp(SampleLocationsTestOp::Make(ctx, canvas->getTotalMatrix(), fGradType));
Chris Dalton6ce447a2019-06-23 18:07:38 -0600365
Chris Daltoneffee202019-07-01 22:28:03 -0600366 // Cover.
367 GrPaint coverPaint;
368 coverPaint.setColor4f({1,0,0,1});
369 coverPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrcOver));
Brian Salomon70fe17e2020-11-30 14:33:58 -0500370 rtc->stencilRect(nullptr, &kStencilCover, std::move(coverPaint), GrAA::kNo, SkMatrix::I(),
371 SkRect::MakeWH(200, 200));
Chris Daltond7291ba2019-03-07 14:17:03 -0700372
Chris Daltoneffee202019-07-01 22:28:03 -0600373 // Copy offscreen texture to canvas.
Brian Salomone69b9ef2020-07-22 11:18:06 -0400374 rtc->drawTexture(nullptr,
375 offscreenRTC->readSurfaceView(),
Greg Daniel40903af2020-01-30 14:55:05 -0500376 offscreenRTC->colorInfo().alphaType(),
Brian Salomone69b9ef2020-07-22 11:18:06 -0400377 GrSamplerState::Filter::kNearest,
378 GrSamplerState::MipmapMode::kNone,
379 SkBlendMode::kSrc,
380 SK_PMColor4fWHITE,
381 {0, 0, 200, 200},
382 {0, 0, 200, 200},
383 GrAA::kNo,
384 GrQuadAAFlags::kNone,
385 SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint,
386 SkMatrix::I(),
Brian Salomonfc118442019-11-22 19:09:27 -0500387 nullptr);
Chris Daltond7291ba2019-03-07 14:17:03 -0700388
389 return skiagm::DrawResult::kOk;
390}
391
392DEF_GM( return new SampleLocationsGM(GradType::kHW, kTopLeft_GrSurfaceOrigin); )
393DEF_GM( return new SampleLocationsGM(GradType::kHW, kBottomLeft_GrSurfaceOrigin); )
394DEF_GM( return new SampleLocationsGM(GradType::kSW, kTopLeft_GrSurfaceOrigin); )
395DEF_GM( return new SampleLocationsGM(GradType::kSW, kBottomLeft_GrSurfaceOrigin); )
396
John Stilesa6841be2020-08-06 14:11:56 -0400397} // namespace skiagm