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