blob: 4ba74e7ff05b15ddd6272d6f76da81a326e7da38 [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/mock/GrMockTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/core/SkExchange.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/core/SkRectPriv.h"
13#include "src/gpu/GrClip.h"
14#include "src/gpu/GrContextPriv.h"
15#include "src/gpu/GrMemoryPool.h"
16#include "src/gpu/GrOnFlushResourceProvider.h"
17#include "src/gpu/GrProxyProvider.h"
18#include "src/gpu/GrRecordingContextPriv.h"
19#include "src/gpu/GrRenderTargetContext.h"
20#include "src/gpu/GrRenderTargetContextPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040021#include "src/gpu/GrSurfaceProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/GrSurfaceProxyPriv.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000023#include "src/gpu/GrTexture.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 {
Brian Salomona56a7462020-02-07 14:17:25 -050093 static constexpr SkISize kDimensions = {1234, 567};
Brian Salomone8a766b2019-07-19 14:24:36 -040094 sk_sp<GrTexture> texture = rp->createTexture(
Brian Salomona56a7462020-02-07 14:17:25 -050095 kDimensions, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
Brian Salomona90382f2019-09-17 09:01:56 -040096 SkBudgeted::kYes, GrProtected::kNo);
Chris Dalton4c458b12018-06-16 17:22:59 -060097 REPORTER_ASSERT(fTest->fReporter, texture);
Brian Salomon9c73e3d2019-08-15 10:55:49 -040098 return texture;
Chris Dalton4c458b12018-06-16 17:22:59 -060099 }
100 },
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400101 format, GrRenderable::kNo, 1, GrProtected::kNo, *proxyProvider->caps(),
102 GrSurfaceProxy::UseAllocator::kYes);
Chris Dalton4c458b12018-06-16 17:22:59 -0600103
104 this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo,
Greg Daniel5faf4742019-10-01 15:14:44 -0400105 GrOp::IsHairline::kNo);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700106 }
107
Chris Dalton706a6ff2017-11-29 22:01:06 -0700108 const char* name() const override { return "LazyProxyTest::Op"; }
109 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600110 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip* clip,
111 bool hasMixedSampledCoverage, GrClampType) override {
Chris Dalton4b62aed2019-01-15 11:53:00 -0700112 return GrProcessorSet::EmptySetAnalysis();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700113 }
Robert Phillipsc655c3a2020-03-18 13:23:45 -0400114 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400115 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -0400116 GrAppliedClip*,
117 const GrXferProcessor::DstProxyView&) override {}
118
Chris Dalton706a6ff2017-11-29 22:01:06 -0700119 void onPrepare(GrOpFlushState*) override {}
120
121 LazyProxyTest* const fTest;
122 sk_sp<GrTextureProxy> fProxy;
123 };
124
125 class ClipFP : public GrFragmentProcessor {
126 public:
Robert Phillips6f0e02f2019-02-13 11:02:28 -0500127 ClipFP(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test,
Greg Daniel4065d452018-11-16 15:43:41 -0500128 GrTextureProxy* atlas)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700129 : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags)
Greg Daniel4065d452018-11-16 15:43:41 -0500130 , fContext(ctx)
Robert Phillips777707b2018-01-17 11:40:14 -0500131 , fProxyProvider(proxyProvider)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700132 , fTest(test)
133 , fAtlas(atlas) {
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000134 static const GrColorType kColorType = GrColorType::kAlpha_F16;
135 static const GrSurfaceOrigin kOrigin = kBottomLeft_GrSurfaceOrigin;
Greg Daniel4065d452018-11-16 15:43:41 -0500136 const GrBackendFormat format =
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000137 ctx->priv().caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
Greg Danielce3ddaa2020-01-22 16:58:15 -0500138 GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(format, kColorType);
Chris Dalton4c458b12018-06-16 17:22:59 -0600139 fLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
Brian Salomonbeb7f522019-08-30 16:19:42 -0400140 [this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
Brian Salomonb6a3a3b2019-04-01 12:29:34 -0400141 REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
142 fTest->fHasClipTexture = true;
143 fAtlas->instantiate(rp);
144 return sk_ref_sp(fAtlas->peekTexture());
145 },
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400146 format, GrRenderable::kYes, 1, GrProtected::kNo, *proxyProvider->caps(),
147 GrSurfaceProxy::UseAllocator::kYes);
Greg Danielce3ddaa2020-01-22 16:58:15 -0500148 fAccess.set(GrSurfaceProxyView(fLazyProxy, kOrigin, readSwizzle),
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
Robert Phillips0a15cc62019-07-30 12:49:10 -0400234 GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
235 GrRenderable::kNo);
Greg Daniel4065d452018-11-16 15:43:41 -0500236
Brian Salomona56a7462020-02-07 14:17:25 -0500237 auto tex = ctx->priv().resourceProvider()->createTexture({kSize, kSize}, format,
238 GrRenderable::kNo, 1, GrMipMapped::kNo,
239 SkBudgeted::kNo, GrProtected::kNo);
Brian Salomonbeb7f522019-08-30 16:19:42 -0400240 using LazyInstantiationResult = GrSurfaceProxy::LazyCallbackResult;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500241 for (bool doInstantiate : {true, false}) {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400242 for (bool releaseCallback : {false, true}) {
Greg Daniel457469c2018-02-08 15:05:44 -0500243 int testCount = 0;
Brian Salomon67f01952019-02-14 13:05:25 -0500244 // Sets an integer to 1 when the callback is called and -1 when it is deleted.
245 class TestCallback {
246 public:
Brian Salomonbeb7f522019-08-30 16:19:42 -0400247 TestCallback(int* value, bool releaseCallback, sk_sp<GrTexture> tex)
248 : fValue(value)
249 , fReleaseCallback(releaseCallback)
250 , fTexture(std::move(tex)) {}
Brian Salomon67f01952019-02-14 13:05:25 -0500251 TestCallback(const TestCallback& that) { SkASSERT(0); }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400252 TestCallback(TestCallback&& that)
253 : fValue(that.fValue)
254 , fReleaseCallback(that.fReleaseCallback)
255 , fTexture(std::move(that.fTexture)) {
256 that.fValue = nullptr;
257 }
Brian Salomon67f01952019-02-14 13:05:25 -0500258
259 ~TestCallback() { fValue ? (void)(*fValue = -1) : void(); }
260
261 TestCallback& operator=(TestCallback&& that) {
262 fValue = skstd::exchange(that.fValue, nullptr);
263 return *this;
264 }
265 TestCallback& operator=(const TestCallback& that) = delete;
266
Brian Salomonb6a3a3b2019-04-01 12:29:34 -0400267 LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const {
Brian Salomon67f01952019-02-14 13:05:25 -0500268 *fValue = 1;
Brian Salomonbeb7f522019-08-30 16:19:42 -0400269 return {fTexture, fReleaseCallback};
Brian Salomon67f01952019-02-14 13:05:25 -0500270 }
271
272 private:
273 int* fValue = nullptr;
Brian Salomonbeb7f522019-08-30 16:19:42 -0400274 bool fReleaseCallback;
275 sk_sp<GrTexture> fTexture;
Brian Salomon67f01952019-02-14 13:05:25 -0500276 };
Greg Daniel457469c2018-02-08 15:05:44 -0500277 sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
Brian Salomona56a7462020-02-07 14:17:25 -0500278 TestCallback(&testCount, releaseCallback, tex), format, {kSize, kSize},
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400279 GrRenderable::kNo, 1, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated,
280 GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo,
281 GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
Greg Daniel94a6ce82018-01-16 16:14:41 -0500282
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400283 REPORTER_ASSERT(reporter, proxy.get());
Greg Daniel457469c2018-02-08 15:05:44 -0500284 REPORTER_ASSERT(reporter, 0 == testCount);
285
286 if (doInstantiate) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500287 proxy->priv().doLazyInstantiation(ctx->priv().resourceProvider());
Brian Salomonbeb7f522019-08-30 16:19:42 -0400288 if (releaseCallback) {
289 // We will call the cleanup and delete the callback in the
Greg Daniel457469c2018-02-08 15:05:44 -0500290 // doLazyInstantiationCall.
291 REPORTER_ASSERT(reporter, -1 == testCount);
292 } else {
293 REPORTER_ASSERT(reporter, 1 == testCount);
294 }
295 proxy.reset();
296 REPORTER_ASSERT(reporter, -1 == testCount);
297 } else {
298 proxy.reset();
299 REPORTER_ASSERT(reporter, -1 == testCount);
300 }
Greg Daniel94a6ce82018-01-16 16:14:41 -0500301 }
302 }
303}
304
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500305class LazyFailedInstantiationTestOp : public GrDrawOp {
306public:
307 DEFINE_OP_CLASS_ID
308
Robert Phillips88a32ef2018-06-07 11:05:56 -0400309 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
310 GrProxyProvider* proxyProvider,
311 int* testExecuteValue,
312 bool shouldFailInstantiation) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500313 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -0400314
Greg Daniel4065d452018-11-16 15:43:41 -0500315 return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider,
Robert Phillipsc994a932018-06-19 13:09:54 -0400316 testExecuteValue,
317 shouldFailInstantiation);
Robert Phillips88a32ef2018-06-07 11:05:56 -0400318 }
319
Chris Dalton1706cbf2019-05-21 19:35:29 -0600320 void visitProxies(const VisitProxyFunc& func) const override {
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600321 func(fLazyProxy.get(), GrMipMapped::kNo);
Robert Phillips88a32ef2018-06-07 11:05:56 -0400322 }
323
324private:
Robert Phillips7c525e62018-06-12 10:11:12 -0400325 friend class GrOpMemoryPool; // for ctor
326
Greg Daniel4065d452018-11-16 15:43:41 -0500327 LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider,
328 int* testExecuteValue, bool shouldFailInstantiation)
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500329 : INHERITED(ClassID())
330 , fTestExecuteValue(testExecuteValue) {
Brian Salomona56a7462020-02-07 14:17:25 -0500331 SkISize desc;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500332 desc.fWidth = kSize;
333 desc.fHeight = kSize;
Greg Daniel4065d452018-11-16 15:43:41 -0500334 GrBackendFormat format =
Robert Phillips0a15cc62019-07-30 12:49:10 -0400335 ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
336 GrRenderable::kNo);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500337
338 fLazyProxy = proxyProvider->createLazyProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -0400339 [testExecuteValue, shouldFailInstantiation, desc,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400340 format](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
Greg Daniel0a375db2018-02-01 12:21:39 -0500341 if (shouldFailInstantiation) {
342 *testExecuteValue = 1;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -0400343 return {};
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500344 }
Brian Salomona90382f2019-09-17 09:01:56 -0400345 return {rp->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
346 SkBudgeted::kNo, GrProtected::kNo),
Brian Salomonbeb7f522019-08-30 16:19:42 -0400347 true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
Brian Salomon2a4f9832018-03-03 22:43:43 -0500348 },
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400349 format, desc, GrRenderable::kNo, 1, GrMipMapped::kNo,
Greg Daniel3a365112020-02-14 10:47:18 -0500350 GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact,
351 SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500352
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400353 SkASSERT(fLazyProxy.get());
354
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500355 this->setBounds(SkRect::MakeIWH(kSize, kSize),
Greg Daniel5faf4742019-10-01 15:14:44 -0400356 HasAABloat::kNo, IsHairline::kNo);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500357 }
358
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500359 const char* name() const override { return "LazyFailedInstantiationTestOp"; }
360 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600361 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
362 bool hasMixedSampledCoverage, GrClampType) override {
Chris Dalton4b62aed2019-01-15 11:53:00 -0700363 return GrProcessorSet::EmptySetAnalysis();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500364 }
Robert Phillipsc655c3a2020-03-18 13:23:45 -0400365 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400366 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -0400367 GrAppliedClip*,
368 const GrXferProcessor::DstProxyView&) override {}
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500369 void onPrepare(GrOpFlushState*) override {}
Brian Salomon588cec72018-11-14 13:56:37 -0500370 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500371 *fTestExecuteValue = 2;
372 }
373
374 int* fTestExecuteValue;
Greg Danieldcf9ca12019-08-27 14:30:21 -0400375 sk_sp<GrTextureProxy> fLazyProxy;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500376
377 typedef GrDrawOp INHERITED;
378};
379
380// Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was
381// associated with.
382DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) {
383 GrMockOptions mockOptions;
384 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips9da87e02019-02-04 13:26:26 -0500385 GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500386 for (bool failInstantiation : {false, true}) {
Greg Daniele20fcad2020-01-08 11:52:34 -0500387 auto rtc = GrRenderTargetContext::Make(
388 ctx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {100, 100});
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500389 REPORTER_ASSERT(reporter, rtc);
390
Brian Osman9a9baae2018-11-05 15:06:26 -0500391 rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad),
392 GrRenderTargetContext::CanClearFullscreen::kYes);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500393
394 int executeTestValue = 0;
Robert Phillips88a32ef2018-06-07 11:05:56 -0400395 rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make(
396 ctx.get(), proxyProvider, &executeTestValue, failInstantiation));
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500397 ctx->flush();
398
399 if (failInstantiation) {
Robert Phillips12c46292019-04-23 07:36:17 -0400400 REPORTER_ASSERT(reporter, 1 == executeTestValue);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500401 } else {
402 REPORTER_ASSERT(reporter, 2 == executeTestValue);
403 }
404 }
Greg Daniel4684f822018-03-08 15:27:36 -0500405}