Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "tests/Test.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrTexture.h" |
| 11 | #include "include/gpu/mock/GrMockTypes.h" |
| 12 | #include "include/private/GrSurfaceProxy.h" |
| 13 | #include "include/private/GrTextureProxy.h" |
| 14 | #include "src/core/SkExchange.h" |
| 15 | #include "src/core/SkMakeUnique.h" |
| 16 | #include "src/core/SkRectPriv.h" |
| 17 | #include "src/gpu/GrClip.h" |
| 18 | #include "src/gpu/GrContextPriv.h" |
| 19 | #include "src/gpu/GrMemoryPool.h" |
| 20 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 21 | #include "src/gpu/GrProxyProvider.h" |
| 22 | #include "src/gpu/GrRecordingContextPriv.h" |
| 23 | #include "src/gpu/GrRenderTargetContext.h" |
| 24 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 25 | #include "src/gpu/GrSurfaceProxyPriv.h" |
| 26 | #include "src/gpu/GrTextureProxyPriv.h" |
| 27 | #include "src/gpu/mock/GrMockGpu.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 28 | |
| 29 | // This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks, |
| 30 | // but before Ops are executed. It also ensures that lazy proxy callbacks are invoked both for |
| 31 | // regular Ops and for clips. |
| 32 | class LazyProxyTest final : public GrOnFlushCallbackObject { |
| 33 | public: |
| 34 | LazyProxyTest(skiatest::Reporter* reporter) |
| 35 | : fReporter(reporter) |
| 36 | , fHasOpTexture(false) |
| 37 | , fHasClipTexture(false) { |
| 38 | } |
| 39 | |
| 40 | ~LazyProxyTest() override { |
| 41 | REPORTER_ASSERT(fReporter, fHasOpTexture); |
| 42 | REPORTER_ASSERT(fReporter, fHasClipTexture); |
| 43 | } |
| 44 | |
| 45 | void preFlush(GrOnFlushResourceProvider*, const uint32_t*, int, |
| 46 | SkTArray<sk_sp<GrRenderTargetContext>>*) override { |
| 47 | REPORTER_ASSERT(fReporter, !fHasOpTexture); |
| 48 | REPORTER_ASSERT(fReporter, !fHasClipTexture); |
| 49 | } |
| 50 | |
| 51 | void postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, int numOpListIDs) override { |
| 52 | REPORTER_ASSERT(fReporter, fHasOpTexture); |
| 53 | REPORTER_ASSERT(fReporter, fHasClipTexture); |
| 54 | } |
| 55 | |
| 56 | class Op final : public GrDrawOp { |
| 57 | public: |
| 58 | DEFINE_OP_CLASS_ID |
| 59 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 60 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 61 | GrProxyProvider* proxyProvider, |
| 62 | LazyProxyTest* test, |
| 63 | bool nullTexture) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 64 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 65 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 66 | return pool->allocate<Op>(context, proxyProvider, test, nullTexture); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 69 | void visitProxies(const VisitProxyFunc& func, VisitorType) const override { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 70 | func(fProxy.get()); |
| 71 | } |
| 72 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 73 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 74 | REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture); |
| 75 | REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture); |
| 76 | } |
| 77 | |
| 78 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 79 | friend class GrOpMemoryPool; // for ctor |
| 80 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 81 | Op(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, |
| 82 | LazyProxyTest* test, bool nullTexture) |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 83 | : GrDrawOp(ClassID()), fTest(test) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 84 | const GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 85 | ctx->priv().caps()->getBackendFormatFromColorType(kRGB_565_SkColorType); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 86 | fProxy = GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 87 | [this, nullTexture]( |
| 88 | GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 89 | REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture); |
| 90 | fTest->fHasOpTexture = true; |
| 91 | if (nullTexture) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 92 | return {}; |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 93 | } else { |
| 94 | GrSurfaceDesc desc; |
| 95 | desc.fWidth = 1234; |
| 96 | desc.fHeight = 567; |
| 97 | desc.fConfig = kRGB_565_GrPixelConfig; |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 98 | sk_sp<GrTexture> texture = rp->createTexture( |
| 99 | desc, SkBudgeted::kYes, GrResourceProvider::Flags::kNoPendingIO); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 100 | REPORTER_ASSERT(fTest->fReporter, texture); |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 101 | return std::move(texture); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 102 | } |
| 103 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 104 | format, GrProxyProvider::Renderable::kNo, kTopLeft_GrSurfaceOrigin, |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 105 | kRGB_565_GrPixelConfig, *proxyProvider->caps()); |
| 106 | |
| 107 | this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo, |
| 108 | GrOp::IsZeroArea::kNo); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 111 | const char* name() const override { return "LazyProxyTest::Op"; } |
| 112 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 113 | GrProcessorSet::Analysis finalize( |
Robert Phillips | 3966738 | 2019-04-17 16:03:30 -0400 | [diff] [blame] | 114 | const GrCaps&, const GrAppliedClip* clip, GrFSAAType, GrClampType) override { |
| 115 | if (clip) { |
| 116 | for (int i = 0; i < clip->numClipCoverageFragmentProcessors(); ++i) { |
| 117 | const GrFragmentProcessor* clipFP = clip->clipCoverageFragmentProcessor(i); |
| 118 | clipFP->markPendingExecution(); |
| 119 | } |
| 120 | } |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 121 | return GrProcessorSet::EmptySetAnalysis(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 122 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 123 | void onPrepare(GrOpFlushState*) override {} |
| 124 | |
| 125 | LazyProxyTest* const fTest; |
| 126 | sk_sp<GrTextureProxy> fProxy; |
| 127 | }; |
| 128 | |
| 129 | class ClipFP : public GrFragmentProcessor { |
| 130 | public: |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 131 | ClipFP(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 132 | GrTextureProxy* atlas) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 133 | : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 134 | , fContext(ctx) |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 135 | , fProxyProvider(proxyProvider) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 136 | , fTest(test) |
| 137 | , fAtlas(atlas) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 138 | const GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 139 | ctx->priv().caps()->getBackendFormatFromGrColorType(GrColorType::kAlpha_F16, |
| 140 | GrSRGBEncoded::kNo); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 141 | fLazyProxy = GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 142 | [this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult { |
| 143 | REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture); |
| 144 | fTest->fHasClipTexture = true; |
| 145 | fAtlas->instantiate(rp); |
| 146 | return sk_ref_sp(fAtlas->peekTexture()); |
| 147 | }, |
| 148 | format, GrProxyProvider::Renderable::kYes, kBottomLeft_GrSurfaceOrigin, |
| 149 | kAlpha_half_GrPixelConfig, *proxyProvider->caps()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 150 | fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 151 | GrSamplerState::WrapMode::kClamp); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 152 | this->setTextureSamplerCnt(1); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | private: |
| 156 | const char* name() const override { return "LazyProxyTest::ClipFP"; } |
| 157 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 158 | return skstd::make_unique<ClipFP>(fContext, fProxyProvider, fTest, fAtlas); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 159 | } |
| 160 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; } |
| 161 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
| 162 | bool onIsEqual(const GrFragmentProcessor&) const override { return false; } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 163 | const TextureSampler& onTextureSampler(int) const override { return fAccess; } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 164 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 165 | GrRecordingContext* const fContext; |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 166 | GrProxyProvider* const fProxyProvider; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 167 | LazyProxyTest* const fTest; |
| 168 | GrTextureProxy* const fAtlas; |
| 169 | sk_sp<GrTextureProxy> fLazyProxy; |
| 170 | TextureSampler fAccess; |
| 171 | }; |
| 172 | |
| 173 | |
| 174 | class Clip : public GrClip { |
| 175 | public: |
| 176 | Clip(LazyProxyTest* test, GrTextureProxy* atlas) |
| 177 | : fTest(test) |
| 178 | , fAtlas(atlas) {} |
| 179 | |
| 180 | private: |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 181 | bool apply(GrRecordingContext* context, GrRenderTargetContext*, bool useHWAA, |
| 182 | bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const override { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 183 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 184 | out->addCoverageFP(skstd::make_unique<ClipFP>(context, proxyProvider, fTest, fAtlas)); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 185 | return true; |
| 186 | } |
| 187 | bool quickContains(const SkRect&) const final { return false; } |
| 188 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; } |
| 189 | void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final { |
| 190 | rect->set(0, 0, width, height); |
| 191 | if (iior) { |
| 192 | *iior = false; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | LazyProxyTest* const fTest; |
| 197 | GrTextureProxy* fAtlas; |
| 198 | }; |
| 199 | |
| 200 | private: |
| 201 | skiatest::Reporter* fReporter; |
| 202 | bool fHasOpTexture; |
| 203 | bool fHasClipTexture; |
| 204 | }; |
| 205 | |
| 206 | DEF_GPUTEST(LazyProxyTest, reporter, /* options */) { |
| 207 | GrMockOptions mockOptions; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 208 | mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderability = |
| 209 | GrMockOptions::ConfigOptions::Renderability::kNonMSAA; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 210 | mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true; |
| 211 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 212 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 213 | for (bool nullTexture : {false, true}) { |
| 214 | LazyProxyTest test(reporter); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 215 | ctx->priv().addOnFlushCallbackObject(&test); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 216 | GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 217 | ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
| 218 | sk_sp<GrRenderTargetContext> rtc = ctx->priv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 219 | format, SkBackingFit::kExact, 100, 100, |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 220 | kRGBA_8888_GrPixelConfig, nullptr); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 221 | REPORTER_ASSERT(reporter, rtc); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 222 | format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 223 | ctx->priv().caps()->getBackendFormatFromGrColorType(GrColorType::kAlpha_F16, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 224 | GrSRGBEncoded::kNo); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 225 | sk_sp<GrRenderTargetContext> mockAtlas = ctx->priv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 226 | format, SkBackingFit::kExact, 10, 10, |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 227 | kAlpha_half_GrPixelConfig, nullptr); |
| 228 | REPORTER_ASSERT(reporter, mockAtlas); |
| 229 | rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()), |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 230 | LazyProxyTest::Op::Make(ctx.get(), proxyProvider, &test, nullTexture)); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 231 | ctx->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 235 | static const int kSize = 16; |
| 236 | |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 237 | DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { |
| 238 | GrMockOptions mockOptions; |
| 239 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 240 | auto proxyProvider = ctx->priv().proxyProvider(); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 241 | |
| 242 | GrSurfaceDesc desc; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 243 | desc.fWidth = kSize; |
| 244 | desc.fHeight = kSize; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 245 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 246 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 247 | GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 248 | ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 249 | |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 250 | using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType; |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 251 | using LazyInstantiationResult = GrSurfaceProxy::LazyInstantiationResult; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 252 | for (bool doInstantiate : {true, false}) { |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 253 | for (auto lazyType : {LazyInstantiationType::kSingleUse, |
| 254 | LazyInstantiationType::kMultipleUse, |
| 255 | LazyInstantiationType::kDeinstantiate}) { |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 256 | int testCount = 0; |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 257 | // Sets an integer to 1 when the callback is called and -1 when it is deleted. |
| 258 | class TestCallback { |
| 259 | public: |
| 260 | TestCallback(int* value) : fValue(value) {} |
| 261 | TestCallback(const TestCallback& that) { SkASSERT(0); } |
| 262 | TestCallback(TestCallback&& that) : fValue(that.fValue) { that.fValue = nullptr; } |
| 263 | |
| 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 Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 272 | LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const { |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 273 | *fValue = 1; |
| 274 | return {}; |
| 275 | } |
| 276 | |
| 277 | private: |
| 278 | int* fValue = nullptr; |
| 279 | }; |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 280 | sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy( |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 281 | TestCallback(&testCount), format, desc, kTopLeft_GrSurfaceOrigin, |
| 282 | GrMipMapped::kNo, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, |
| 283 | SkBudgeted::kNo, lazyType); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 284 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 285 | REPORTER_ASSERT(reporter, proxy.get()); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 286 | REPORTER_ASSERT(reporter, 0 == testCount); |
| 287 | |
| 288 | if (doInstantiate) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 289 | proxy->priv().doLazyInstantiation(ctx->priv().resourceProvider()); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 290 | if (LazyInstantiationType::kSingleUse == proxy->priv().lazyInstantiationType()) { |
| 291 | // In SingleUse we will call the cleanup and delete the callback in the |
| 292 | // doLazyInstantiationCall. |
| 293 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 294 | } else { |
| 295 | REPORTER_ASSERT(reporter, 1 == testCount); |
| 296 | } |
| 297 | proxy.reset(); |
| 298 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 299 | } else { |
| 300 | proxy.reset(); |
| 301 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 302 | } |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 307 | class LazyFailedInstantiationTestOp : public GrDrawOp { |
| 308 | public: |
| 309 | DEFINE_OP_CLASS_ID |
| 310 | |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 311 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 312 | GrProxyProvider* proxyProvider, |
| 313 | int* testExecuteValue, |
| 314 | bool shouldFailInstantiation) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 315 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 316 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 317 | return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 318 | testExecuteValue, |
| 319 | shouldFailInstantiation); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 320 | } |
| 321 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 322 | void visitProxies(const VisitProxyFunc& func, VisitorType) const override { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 323 | func(fLazyProxy.get()); |
| 324 | } |
| 325 | |
| 326 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 327 | friend class GrOpMemoryPool; // for ctor |
| 328 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 329 | LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider, |
| 330 | int* testExecuteValue, bool shouldFailInstantiation) |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 331 | : INHERITED(ClassID()) |
| 332 | , fTestExecuteValue(testExecuteValue) { |
| 333 | GrSurfaceDesc desc; |
| 334 | desc.fWidth = kSize; |
| 335 | desc.fHeight = kSize; |
| 336 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 337 | GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 338 | ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 339 | |
| 340 | fLazyProxy = proxyProvider->createLazyProxy( |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 341 | [testExecuteValue, shouldFailInstantiation, |
| 342 | desc](GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 343 | if (shouldFailInstantiation) { |
| 344 | *testExecuteValue = 1; |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 345 | return {}; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 346 | } |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 347 | return {rp->createTexture(desc, SkBudgeted::kNo, |
| 348 | GrResourceProvider::Flags::kNoPendingIO), |
Brian Salomon | 01ceae9 | 2019-04-02 11:49:54 -0400 | [diff] [blame] | 349 | GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced}; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 350 | }, |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 351 | format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact, |
| 352 | SkBudgeted::kNo); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 353 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 354 | SkASSERT(fLazyProxy.get()); |
| 355 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 356 | this->setBounds(SkRect::MakeIWH(kSize, kSize), |
| 357 | HasAABloat::kNo, IsZeroArea::kNo); |
| 358 | } |
| 359 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 360 | const char* name() const override { return "LazyFailedInstantiationTestOp"; } |
| 361 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 362 | GrProcessorSet::Analysis finalize( |
| 363 | const GrCaps&, const GrAppliedClip*, GrFSAAType, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 364 | return GrProcessorSet::EmptySetAnalysis(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 365 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 366 | void onPrepare(GrOpFlushState*) override {} |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 367 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 368 | *fTestExecuteValue = 2; |
| 369 | } |
| 370 | |
| 371 | int* fTestExecuteValue; |
| 372 | sk_sp<GrSurfaceProxy> fLazyProxy; |
| 373 | |
| 374 | typedef GrDrawOp INHERITED; |
| 375 | }; |
| 376 | |
| 377 | // Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was |
| 378 | // associated with. |
| 379 | DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) { |
| 380 | GrMockOptions mockOptions; |
| 381 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 382 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 383 | GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 384 | ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 385 | for (bool failInstantiation : {false, true}) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 386 | sk_sp<GrRenderTargetContext> rtc = ctx->priv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 387 | format, SkBackingFit::kExact, 100, 100, |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 388 | kRGBA_8888_GrPixelConfig, nullptr); |
| 389 | REPORTER_ASSERT(reporter, rtc); |
| 390 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 391 | rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad), |
| 392 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 393 | |
| 394 | int executeTestValue = 0; |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 395 | rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make( |
| 396 | ctx.get(), proxyProvider, &executeTestValue, failInstantiation)); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 397 | ctx->flush(); |
| 398 | |
| 399 | if (failInstantiation) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 400 | REPORTER_ASSERT(reporter, 1 == executeTestValue); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 401 | } else { |
| 402 | REPORTER_ASSERT(reporter, 2 == executeTestValue); |
| 403 | } |
| 404 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 405 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 406 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 407 | class LazyDeinstantiateTestOp : public GrDrawOp { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 408 | public: |
| 409 | DEFINE_OP_CLASS_ID |
| 410 | |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 411 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, sk_sp<GrTextureProxy> proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 412 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 413 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 414 | return pool->allocate<LazyDeinstantiateTestOp>(std::move(proxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 415 | } |
| 416 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 417 | void visitProxies(const VisitProxyFunc& func, VisitorType) const override { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 418 | func(fLazyProxy.get()); |
| 419 | } |
| 420 | |
| 421 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 422 | friend class GrOpMemoryPool; // for ctor |
| 423 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 424 | LazyDeinstantiateTestOp(sk_sp<GrTextureProxy> proxy) |
| 425 | : INHERITED(ClassID()), fLazyProxy(std::move(proxy)) { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 426 | this->setBounds(SkRect::MakeIWH(kSize, kSize), HasAABloat::kNo, IsZeroArea::kNo); |
| 427 | } |
| 428 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 429 | const char* name() const override { return "LazyDeinstantiateTestOp"; } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 430 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 431 | GrProcessorSet::Analysis finalize( |
| 432 | const GrCaps&, const GrAppliedClip*, GrFSAAType, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 433 | return GrProcessorSet::EmptySetAnalysis(); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 434 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 435 | void onPrepare(GrOpFlushState*) override {} |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 436 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override {} |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 437 | |
| 438 | sk_sp<GrSurfaceProxy> fLazyProxy; |
| 439 | |
| 440 | typedef GrDrawOp INHERITED; |
| 441 | }; |
| 442 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 443 | static void DeinstantiateReleaseProc(void* releaseValue) { (*static_cast<int*>(releaseValue))++; } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 444 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 445 | // Test that lazy proxies with the Deinstantiate LazyCallbackType are deinstantiated and released as |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 446 | // expected. |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 447 | DEF_GPUTEST(LazyProxyDeinstantiateTest, reporter, /* options */) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 448 | GrMockOptions mockOptions; |
| 449 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 450 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 451 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 452 | GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 453 | ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 454 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 455 | using LazyType = GrSurfaceProxy::LazyInstantiationType; |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 456 | for (auto lazyType : {LazyType::kSingleUse, LazyType::kMultipleUse, LazyType::kDeinstantiate}) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 457 | sk_sp<GrRenderTargetContext> rtc = ctx->priv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 458 | format, SkBackingFit::kExact, 100, 100, |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 459 | kRGBA_8888_GrPixelConfig, nullptr); |
| 460 | REPORTER_ASSERT(reporter, rtc); |
| 461 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 462 | rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad), |
| 463 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 464 | |
| 465 | int instantiateTestValue = 0; |
| 466 | int releaseTestValue = 0; |
| 467 | int* instantiatePtr = &instantiateTestValue; |
| 468 | int* releasePtr = &releaseTestValue; |
| 469 | GrSurfaceDesc desc; |
| 470 | desc.fWidth = kSize; |
| 471 | desc.fHeight = kSize; |
| 472 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 473 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 474 | GrBackendTexture backendTex = ctx->createBackendTexture( |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 475 | kSize, kSize, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 476 | |
| 477 | sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy( |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 478 | [instantiatePtr, releasePtr, |
| 479 | backendTex](GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult { |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 480 | sk_sp<GrTexture> texture = |
| 481 | rp->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 482 | GrWrapCacheable::kNo, kRead_GrIOType); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 483 | if (!texture) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 484 | return {}; |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 485 | } |
| 486 | (*instantiatePtr)++; |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 487 | texture->setRelease(DeinstantiateReleaseProc, releasePtr); |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 488 | return std::move(texture); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 489 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 490 | format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 491 | GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, SkBudgeted::kNo, lazyType); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 492 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 493 | REPORTER_ASSERT(reporter, lazyProxy.get()); |
| 494 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 495 | rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 496 | |
| 497 | ctx->flush(); |
| 498 | |
| 499 | REPORTER_ASSERT(reporter, 1 == instantiateTestValue); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 500 | if (LazyType::kDeinstantiate == lazyType) { |
| 501 | REPORTER_ASSERT(reporter, 1 == releaseTestValue); |
| 502 | } else { |
| 503 | REPORTER_ASSERT(reporter, 0 == releaseTestValue); |
| 504 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 505 | |
| 506 | // This should cause the uninstantiate proxies to be instantiated again but have no effect |
| 507 | // on the others |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 508 | rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 509 | // Add a second op to make sure we only instantiate once. |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 510 | rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 511 | ctx->flush(); |
| 512 | |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 513 | if (LazyType::kDeinstantiate == lazyType) { |
| 514 | REPORTER_ASSERT(reporter, 2 == instantiateTestValue); |
| 515 | REPORTER_ASSERT(reporter, 2 == releaseTestValue); |
| 516 | } else { |
| 517 | REPORTER_ASSERT(reporter, 1 == instantiateTestValue); |
| 518 | REPORTER_ASSERT(reporter, 0 == releaseTestValue); |
| 519 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 520 | |
| 521 | lazyProxy.reset(); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 522 | if (LazyType::kDeinstantiate == lazyType) { |
| 523 | REPORTER_ASSERT(reporter, 2 == releaseTestValue); |
| 524 | } else { |
| 525 | REPORTER_ASSERT(reporter, 1 == releaseTestValue); |
| 526 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 527 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 528 | ctx->deleteBackendTexture(backendTex); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 529 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 530 | } |