blob: 654bdf32d5a106e0780c269bd746eb555a4e600a [file] [log] [blame]
Chris Dalton706a6ff2017-11-29 22:01:06 -07001/*
2 * Copyright 2017 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 "tests/Test.h"
Chris Dalton706a6ff2017-11-29 22:01:06 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/gpu/GrTexture.h"
11#include "include/gpu/mock/GrMockTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/core/SkExchange.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/core/SkRectPriv.h"
14#include "src/gpu/GrClip.h"
15#include "src/gpu/GrContextPriv.h"
16#include "src/gpu/GrMemoryPool.h"
17#include "src/gpu/GrOnFlushResourceProvider.h"
18#include "src/gpu/GrProxyProvider.h"
19#include "src/gpu/GrRecordingContextPriv.h"
20#include "src/gpu/GrRenderTargetContext.h"
21#include "src/gpu/GrRenderTargetContextPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040022#include "src/gpu/GrSurfaceProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrSurfaceProxyPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040024#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/GrTextureProxyPriv.h"
26#include "src/gpu/mock/GrMockGpu.h"
Chris Dalton706a6ff2017-11-29 22:01:06 -070027
28// This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks,
29// but before Ops are executed. It also ensures that lazy proxy callbacks are invoked both for
30// regular Ops and for clips.
31class LazyProxyTest final : public GrOnFlushCallbackObject {
32public:
33 LazyProxyTest(skiatest::Reporter* reporter)
34 : fReporter(reporter)
35 , fHasOpTexture(false)
36 , fHasClipTexture(false) {
37 }
38
39 ~LazyProxyTest() override {
40 REPORTER_ASSERT(fReporter, fHasOpTexture);
41 REPORTER_ASSERT(fReporter, fHasClipTexture);
42 }
43
Chris Daltonc4b47352019-08-23 10:10:36 -060044 void preFlush(GrOnFlushResourceProvider*, const uint32_t*, int) override {
Chris Dalton706a6ff2017-11-29 22:01:06 -070045 REPORTER_ASSERT(fReporter, !fHasOpTexture);
46 REPORTER_ASSERT(fReporter, !fHasClipTexture);
47 }
48
Greg Danielf41b2bd2019-08-22 16:19:24 -040049 void postFlush(GrDeferredUploadToken, const uint32_t* opsTaskIDs, int numOpsTaskIDs) override {
Chris Dalton706a6ff2017-11-29 22:01:06 -070050 REPORTER_ASSERT(fReporter, fHasOpTexture);
51 REPORTER_ASSERT(fReporter, fHasClipTexture);
52 }
53
54 class Op final : public GrDrawOp {
55 public:
56 DEFINE_OP_CLASS_ID
57
Robert Phillips6f0e02f2019-02-13 11:02:28 -050058 static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
Robert Phillips88a32ef2018-06-07 11:05:56 -040059 GrProxyProvider* proxyProvider,
60 LazyProxyTest* test,
61 bool nullTexture) {
Robert Phillips9da87e02019-02-04 13:26:26 -050062 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040063
Greg Daniel4065d452018-11-16 15:43:41 -050064 return pool->allocate<Op>(context, proxyProvider, test, nullTexture);
Robert Phillips88a32ef2018-06-07 11:05:56 -040065 }
66
Chris Dalton1706cbf2019-05-21 19:35:29 -060067 void visitProxies(const VisitProxyFunc& func) const override {
Chris Dalton7eb5c0f2019-05-23 15:15:47 -060068 func(fProxy.get(), GrMipMapped::kNo);
Robert Phillips88a32ef2018-06-07 11:05:56 -040069 }
70
Brian Salomon588cec72018-11-14 13:56:37 -050071 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override {
Robert Phillips88a32ef2018-06-07 11:05:56 -040072 REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture);
73 REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture);
74 }
75
76 private:
Robert Phillips7c525e62018-06-12 10:11:12 -040077 friend class GrOpMemoryPool; // for ctor
78
Robert Phillips6f0e02f2019-02-13 11:02:28 -050079 Op(GrRecordingContext* ctx, GrProxyProvider* proxyProvider,
80 LazyProxyTest* test, bool nullTexture)
Robert Phillips777707b2018-01-17 11:40:14 -050081 : GrDrawOp(ClassID()), fTest(test) {
Greg Daniel4065d452018-11-16 15:43:41 -050082 const GrBackendFormat format =
Robert Phillips0a15cc62019-07-30 12:49:10 -040083 ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kBGR_565,
84 GrRenderable::kNo);
Chris Dalton4c458b12018-06-16 17:22:59 -060085 fProxy = GrProxyProvider::MakeFullyLazyProxy(
Brian Salomonbeb7f522019-08-30 16:19:42 -040086 [this, format,
87 nullTexture](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
Chris Dalton4c458b12018-06-16 17:22:59 -060088 REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture);
89 fTest->fHasOpTexture = true;
90 if (nullTexture) {
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040091 return {};
Chris Dalton4c458b12018-06-16 17:22:59 -060092 } else {
93 GrSurfaceDesc desc;
94 desc.fWidth = 1234;
95 desc.fHeight = 567;
96 desc.fConfig = kRGB_565_GrPixelConfig;
Brian Salomone8a766b2019-07-19 14:24:36 -040097 sk_sp<GrTexture> texture = rp->createTexture(
Brian Salomona90382f2019-09-17 09:01:56 -040098 desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
99 SkBudgeted::kYes, GrProtected::kNo);
Chris Dalton4c458b12018-06-16 17:22:59 -0600100 REPORTER_ASSERT(fTest->fReporter, texture);
Brian Salomon9c73e3d2019-08-15 10:55:49 -0400101 return texture;
Chris Dalton4c458b12018-06-16 17:22:59 -0600102 }
103 },
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400104 format, GrRenderable::kNo, 1, GrProtected::kNo, kTopLeft_GrSurfaceOrigin,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400105 kRGB_565_GrPixelConfig, *proxyProvider->caps(),
106 GrSurfaceProxy::UseAllocator::kYes);
Chris Dalton4c458b12018-06-16 17:22:59 -0600107
108 this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo,
Greg Daniel5faf4742019-10-01 15:14:44 -0400109 GrOp::IsHairline::kNo);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700110 }
111
Chris Dalton706a6ff2017-11-29 22:01:06 -0700112 const char* name() const override { return "LazyProxyTest::Op"; }
113 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600114 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip* clip,
115 bool hasMixedSampledCoverage, GrClampType) override {
Chris Dalton4b62aed2019-01-15 11:53:00 -0700116 return GrProcessorSet::EmptySetAnalysis();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700117 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700118 void onPrepare(GrOpFlushState*) override {}
119
120 LazyProxyTest* const fTest;
121 sk_sp<GrTextureProxy> fProxy;
122 };
123
124 class ClipFP : public GrFragmentProcessor {
125 public:
Robert Phillips6f0e02f2019-02-13 11:02:28 -0500126 ClipFP(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test,
Greg Daniel4065d452018-11-16 15:43:41 -0500127 GrTextureProxy* atlas)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700128 : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags)
Greg Daniel4065d452018-11-16 15:43:41 -0500129 , fContext(ctx)
Robert Phillips777707b2018-01-17 11:40:14 -0500130 , fProxyProvider(proxyProvider)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700131 , fTest(test)
132 , fAtlas(atlas) {
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000133 static const GrColorType kColorType = GrColorType::kAlpha_F16;
134 static const GrSurfaceOrigin kOrigin = kBottomLeft_GrSurfaceOrigin;
Greg Daniel4065d452018-11-16 15:43:41 -0500135 const GrBackendFormat format =
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000136 ctx->priv().caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Chris Dalton4c458b12018-06-16 17:22:59 -0600137 fLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
Brian Salomonbeb7f522019-08-30 16:19:42 -0400138 [this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
Brian Salomonb6a3a3b2019-04-01 12:29:34 -0400139 REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
140 fTest->fHasClipTexture = true;
141 fAtlas->instantiate(rp);
142 return sk_ref_sp(fAtlas->peekTexture());
143 },
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000144 format, GrRenderable::kYes, 1, GrProtected::kNo, kOrigin,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400145 kAlpha_half_GrPixelConfig, *proxyProvider->caps(),
146 GrSurfaceProxy::UseAllocator::kYes);
Greg Daniel14b57212019-12-17 16:18:06 -0500147 GrSwizzle swizzle = ctx->priv().caps()->getReadSwizzle(format, kColorType);
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000148 fAccess.set(GrSurfaceProxyView(fLazyProxy, kOrigin, swizzle),
Brian Salomonccb61422020-01-09 10:46:36 -0500149 GrSamplerState::Filter::kNearest);
Brian Salomonf7dcd762018-07-30 14:48:15 -0400150 this->setTextureSamplerCnt(1);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700151 }
152
153 private:
154 const char* name() const override { return "LazyProxyTest::ClipFP"; }
155 std::unique_ptr<GrFragmentProcessor> clone() const override {
Mike Kleinf46d5ca2019-12-11 10:45:01 -0500156 return std::make_unique<ClipFP>(fContext, fProxyProvider, fTest, fAtlas);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700157 }
158 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; }
159 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
160 bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
Brian Salomonf7dcd762018-07-30 14:48:15 -0400161 const TextureSampler& onTextureSampler(int) const override { return fAccess; }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700162
Robert Phillips6f0e02f2019-02-13 11:02:28 -0500163 GrRecordingContext* const fContext;
Robert Phillips777707b2018-01-17 11:40:14 -0500164 GrProxyProvider* const fProxyProvider;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700165 LazyProxyTest* const fTest;
166 GrTextureProxy* const fAtlas;
167 sk_sp<GrTextureProxy> fLazyProxy;
168 TextureSampler fAccess;
169 };
170
171
172 class Clip : public GrClip {
173 public:
174 Clip(LazyProxyTest* test, GrTextureProxy* atlas)
175 : fTest(test)
176 , fAtlas(atlas) {}
177
178 private:
Robert Phillips6f0e02f2019-02-13 11:02:28 -0500179 bool apply(GrRecordingContext* context, GrRenderTargetContext*, bool useHWAA,
180 bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const override {
Robert Phillips9da87e02019-02-04 13:26:26 -0500181 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Mike Kleinf46d5ca2019-12-11 10:45:01 -0500182 out->addCoverageFP(std::make_unique<ClipFP>(context, proxyProvider, fTest, fAtlas));
Chris Dalton706a6ff2017-11-29 22:01:06 -0700183 return true;
184 }
185 bool quickContains(const SkRect&) const final { return false; }
186 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; }
187 void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
Mike Reed92b33352019-08-24 19:39:13 -0400188 rect->setLTRB(0, 0, width, height);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700189 if (iior) {
190 *iior = false;
191 }
192 }
193
194 LazyProxyTest* const fTest;
195 GrTextureProxy* fAtlas;
196 };
197
198private:
199 skiatest::Reporter* fReporter;
200 bool fHasOpTexture;
201 bool fHasClipTexture;
202};
203
204DEF_GPUTEST(LazyProxyTest, reporter, /* options */) {
205 GrMockOptions mockOptions;
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400206 mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability =
Brian Salomonbdecacf2018-02-02 20:32:49 -0500207 GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400208 mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700209 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips9da87e02019-02-04 13:26:26 -0500210 GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700211 for (bool nullTexture : {false, true}) {
212 LazyProxyTest test(reporter);
Robert Phillips9da87e02019-02-04 13:26:26 -0500213 ctx->priv().addOnFlushCallbackObject(&test);
Greg Daniele20fcad2020-01-08 11:52:34 -0500214 auto rtc = GrRenderTargetContext::Make(
215 ctx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {100, 100});
Chris Dalton706a6ff2017-11-29 22:01:06 -0700216 REPORTER_ASSERT(reporter, rtc);
Greg Daniele20fcad2020-01-08 11:52:34 -0500217 auto mockAtlas = GrRenderTargetContext::Make(
218 ctx.get(), GrColorType::kAlpha_F16, nullptr, SkBackingFit::kExact, {10, 10});
Chris Dalton706a6ff2017-11-29 22:01:06 -0700219 REPORTER_ASSERT(reporter, mockAtlas);
220 rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()),
Robert Phillips88a32ef2018-06-07 11:05:56 -0400221 LazyProxyTest::Op::Make(ctx.get(), proxyProvider, &test, nullTexture));
Robert Phillips9da87e02019-02-04 13:26:26 -0500222 ctx->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700223 }
224}
225
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500226static const int kSize = 16;
227
Greg Daniel94a6ce82018-01-16 16:14:41 -0500228DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) {
229 GrMockOptions mockOptions;
230 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips9da87e02019-02-04 13:26:26 -0500231 auto proxyProvider = ctx->priv().proxyProvider();
Robert Phillips0a15cc62019-07-30 12:49:10 -0400232 const GrCaps* caps = ctx->priv().caps();
Greg Daniel94a6ce82018-01-16 16:14:41 -0500233
234 GrSurfaceDesc desc;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500235 desc.fWidth = kSize;
236 desc.fHeight = kSize;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500237 desc.fConfig = kRGBA_8888_GrPixelConfig;
238
Robert Phillips0a15cc62019-07-30 12:49:10 -0400239 GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
240 GrRenderable::kNo);
Greg Daniel4065d452018-11-16 15:43:41 -0500241
Brian Salomonbeb7f522019-08-30 16:19:42 -0400242 auto tex = ctx->priv().resourceProvider()->createTexture(desc, format, GrRenderable::kNo, 1,
Brian Salomona90382f2019-09-17 09:01:56 -0400243 GrMipMapped::kNo, SkBudgeted::kNo,
244 GrProtected::kNo);
Brian Salomonbeb7f522019-08-30 16:19:42 -0400245 using LazyInstantiationResult = GrSurfaceProxy::LazyCallbackResult;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500246 for (bool doInstantiate : {true, false}) {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400247 for (bool releaseCallback : {false, true}) {
Greg Daniel457469c2018-02-08 15:05:44 -0500248 int testCount = 0;
Brian Salomon67f01952019-02-14 13:05:25 -0500249 // Sets an integer to 1 when the callback is called and -1 when it is deleted.
250 class TestCallback {
251 public:
Brian Salomonbeb7f522019-08-30 16:19:42 -0400252 TestCallback(int* value, bool releaseCallback, sk_sp<GrTexture> tex)
253 : fValue(value)
254 , fReleaseCallback(releaseCallback)
255 , fTexture(std::move(tex)) {}
Brian Salomon67f01952019-02-14 13:05:25 -0500256 TestCallback(const TestCallback& that) { SkASSERT(0); }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400257 TestCallback(TestCallback&& that)
258 : fValue(that.fValue)
259 , fReleaseCallback(that.fReleaseCallback)
260 , fTexture(std::move(that.fTexture)) {
261 that.fValue = nullptr;
262 }
Brian Salomon67f01952019-02-14 13:05:25 -0500263
264 ~TestCallback() { fValue ? (void)(*fValue = -1) : void(); }
265
266 TestCallback& operator=(TestCallback&& that) {
267 fValue = skstd::exchange(that.fValue, nullptr);
268 return *this;
269 }
270 TestCallback& operator=(const TestCallback& that) = delete;
271
Brian Salomonb6a3a3b2019-04-01 12:29:34 -0400272 LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const {
Brian Salomon67f01952019-02-14 13:05:25 -0500273 *fValue = 1;
Brian Salomonbeb7f522019-08-30 16:19:42 -0400274 return {fTexture, fReleaseCallback};
Brian Salomon67f01952019-02-14 13:05:25 -0500275 }
276
277 private:
278 int* fValue = nullptr;
Brian Salomonbeb7f522019-08-30 16:19:42 -0400279 bool fReleaseCallback;
280 sk_sp<GrTexture> fTexture;
Brian Salomon67f01952019-02-14 13:05:25 -0500281 };
Greg Daniel457469c2018-02-08 15:05:44 -0500282 sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
Brian Salomonbeb7f522019-08-30 16:19:42 -0400283 TestCallback(&testCount, releaseCallback, tex), format, desc, GrRenderable::kNo,
284 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated,
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600285 GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400286 GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
Greg Daniel94a6ce82018-01-16 16:14:41 -0500287
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400288 REPORTER_ASSERT(reporter, proxy.get());
Greg Daniel457469c2018-02-08 15:05:44 -0500289 REPORTER_ASSERT(reporter, 0 == testCount);
290
291 if (doInstantiate) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500292 proxy->priv().doLazyInstantiation(ctx->priv().resourceProvider());
Brian Salomonbeb7f522019-08-30 16:19:42 -0400293 if (releaseCallback) {
294 // We will call the cleanup and delete the callback in the
Greg Daniel457469c2018-02-08 15:05:44 -0500295 // doLazyInstantiationCall.
296 REPORTER_ASSERT(reporter, -1 == testCount);
297 } else {
298 REPORTER_ASSERT(reporter, 1 == testCount);
299 }
300 proxy.reset();
301 REPORTER_ASSERT(reporter, -1 == testCount);
302 } else {
303 proxy.reset();
304 REPORTER_ASSERT(reporter, -1 == testCount);
305 }
Greg Daniel94a6ce82018-01-16 16:14:41 -0500306 }
307 }
308}
309
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500310class LazyFailedInstantiationTestOp : public GrDrawOp {
311public:
312 DEFINE_OP_CLASS_ID
313
Robert Phillips88a32ef2018-06-07 11:05:56 -0400314 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
315 GrProxyProvider* proxyProvider,
316 int* testExecuteValue,
317 bool shouldFailInstantiation) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500318 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -0400319
Greg Daniel4065d452018-11-16 15:43:41 -0500320 return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider,
Robert Phillipsc994a932018-06-19 13:09:54 -0400321 testExecuteValue,
322 shouldFailInstantiation);
Robert Phillips88a32ef2018-06-07 11:05:56 -0400323 }
324
Chris Dalton1706cbf2019-05-21 19:35:29 -0600325 void visitProxies(const VisitProxyFunc& func) const override {
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600326 func(fLazyProxy.get(), GrMipMapped::kNo);
Robert Phillips88a32ef2018-06-07 11:05:56 -0400327 }
328
329private:
Robert Phillips7c525e62018-06-12 10:11:12 -0400330 friend class GrOpMemoryPool; // for ctor
331
Greg Daniel4065d452018-11-16 15:43:41 -0500332 LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider,
333 int* testExecuteValue, bool shouldFailInstantiation)
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500334 : INHERITED(ClassID())
335 , fTestExecuteValue(testExecuteValue) {
336 GrSurfaceDesc desc;
337 desc.fWidth = kSize;
338 desc.fHeight = kSize;
339 desc.fConfig = kRGBA_8888_GrPixelConfig;
Greg Daniel4065d452018-11-16 15:43:41 -0500340 GrBackendFormat format =
Robert Phillips0a15cc62019-07-30 12:49:10 -0400341 ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
342 GrRenderable::kNo);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500343
344 fLazyProxy = proxyProvider->createLazyProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400345 [testExecuteValue, shouldFailInstantiation, desc,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400346 format](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
Greg Daniel0a375db2018-02-01 12:21:39 -0500347 if (shouldFailInstantiation) {
348 *testExecuteValue = 1;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -0400349 return {};
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500350 }
Brian Salomona90382f2019-09-17 09:01:56 -0400351 return {rp->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
352 SkBudgeted::kNo, GrProtected::kNo),
Brian Salomonbeb7f522019-08-30 16:19:42 -0400353 true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
Brian Salomon2a4f9832018-03-03 22:43:43 -0500354 },
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400355 format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400356 GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact,
357 SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500358
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400359 SkASSERT(fLazyProxy.get());
360
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500361 this->setBounds(SkRect::MakeIWH(kSize, kSize),
Greg Daniel5faf4742019-10-01 15:14:44 -0400362 HasAABloat::kNo, IsHairline::kNo);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500363 }
364
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500365 const char* name() const override { return "LazyFailedInstantiationTestOp"; }
366 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600367 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
368 bool hasMixedSampledCoverage, GrClampType) override {
Chris Dalton4b62aed2019-01-15 11:53:00 -0700369 return GrProcessorSet::EmptySetAnalysis();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500370 }
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500371 void onPrepare(GrOpFlushState*) override {}
Brian Salomon588cec72018-11-14 13:56:37 -0500372 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500373 *fTestExecuteValue = 2;
374 }
375
376 int* fTestExecuteValue;
Greg Danieldcf9ca12019-08-27 14:30:21 -0400377 sk_sp<GrTextureProxy> fLazyProxy;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500378
379 typedef GrDrawOp INHERITED;
380};
381
382// Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was
383// associated with.
384DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) {
385 GrMockOptions mockOptions;
386 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips9da87e02019-02-04 13:26:26 -0500387 GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500388 for (bool failInstantiation : {false, true}) {
Greg Daniele20fcad2020-01-08 11:52:34 -0500389 auto rtc = GrRenderTargetContext::Make(
390 ctx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {100, 100});
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500391 REPORTER_ASSERT(reporter, rtc);
392
Brian Osman9a9baae2018-11-05 15:06:26 -0500393 rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad),
394 GrRenderTargetContext::CanClearFullscreen::kYes);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500395
396 int executeTestValue = 0;
Robert Phillips88a32ef2018-06-07 11:05:56 -0400397 rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make(
398 ctx.get(), proxyProvider, &executeTestValue, failInstantiation));
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500399 ctx->flush();
400
401 if (failInstantiation) {
Robert Phillips12c46292019-04-23 07:36:17 -0400402 REPORTER_ASSERT(reporter, 1 == executeTestValue);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500403 } else {
404 REPORTER_ASSERT(reporter, 2 == executeTestValue);
405 }
406 }
Greg Daniel4684f822018-03-08 15:27:36 -0500407}