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