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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/core/SkRectPriv.h" |
| 14 | #include "src/gpu/GrClip.h" |
| 15 | #include "src/gpu/GrContextPriv.h" |
| 16 | #include "src/gpu/GrMemoryPool.h" |
| 17 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 18 | #include "src/gpu/GrProxyProvider.h" |
| 19 | #include "src/gpu/GrRecordingContextPriv.h" |
| 20 | #include "src/gpu/GrRenderTargetContext.h" |
| 21 | #include "src/gpu/GrRenderTargetContextPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrSurfaceProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrSurfaceProxyPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 24 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrTextureProxyPriv.h" |
| 26 | #include "src/gpu/mock/GrMockGpu.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 27 | |
| 28 | // This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks, |
| 29 | // but before Ops are executed. It also ensures that lazy proxy callbacks are invoked both for |
| 30 | // regular Ops and for clips. |
| 31 | class LazyProxyTest final : public GrOnFlushCallbackObject { |
| 32 | public: |
| 33 | LazyProxyTest(skiatest::Reporter* reporter) |
| 34 | : fReporter(reporter) |
| 35 | , fHasOpTexture(false) |
| 36 | , fHasClipTexture(false) { |
| 37 | } |
| 38 | |
| 39 | ~LazyProxyTest() override { |
| 40 | REPORTER_ASSERT(fReporter, fHasOpTexture); |
| 41 | REPORTER_ASSERT(fReporter, fHasClipTexture); |
| 42 | } |
| 43 | |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 44 | void preFlush(GrOnFlushResourceProvider*, const uint32_t*, int) override { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 45 | REPORTER_ASSERT(fReporter, !fHasOpTexture); |
| 46 | REPORTER_ASSERT(fReporter, !fHasClipTexture); |
| 47 | } |
| 48 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 49 | void postFlush(GrDeferredUploadToken, const uint32_t* opsTaskIDs, int numOpsTaskIDs) override { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 50 | REPORTER_ASSERT(fReporter, fHasOpTexture); |
| 51 | REPORTER_ASSERT(fReporter, fHasClipTexture); |
| 52 | } |
| 53 | |
| 54 | class Op final : public GrDrawOp { |
| 55 | public: |
| 56 | DEFINE_OP_CLASS_ID |
| 57 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 58 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 59 | GrProxyProvider* proxyProvider, |
| 60 | LazyProxyTest* test, |
| 61 | bool nullTexture) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 62 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 63 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 64 | return pool->allocate<Op>(context, proxyProvider, test, nullTexture); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 67 | void visitProxies(const VisitProxyFunc& func) const override { |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 68 | func(fProxy.get(), GrMipMapped::kNo); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 71 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 72 | REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture); |
| 73 | REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture); |
| 74 | } |
| 75 | |
| 76 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 77 | friend class GrOpMemoryPool; // for ctor |
| 78 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 79 | Op(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, |
| 80 | LazyProxyTest* test, bool nullTexture) |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 81 | : GrDrawOp(ClassID()), fTest(test) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 82 | const GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 83 | ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kBGR_565, |
| 84 | GrRenderable::kNo); |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 85 | GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle( |
| 86 | format, GrColorType::kBGR_565); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 87 | fProxy = GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 88 | [this, format, |
| 89 | nullTexture](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 90 | REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture); |
| 91 | fTest->fHasOpTexture = true; |
| 92 | if (nullTexture) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 93 | return {}; |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 94 | } else { |
| 95 | GrSurfaceDesc desc; |
| 96 | desc.fWidth = 1234; |
| 97 | desc.fHeight = 567; |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 98 | sk_sp<GrTexture> texture = rp->createTexture( |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 99 | desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo, |
| 100 | SkBudgeted::kYes, GrProtected::kNo); |
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 | }, |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 105 | format, readSwizzle, GrRenderable::kNo, 1, GrProtected::kNo, |
Greg Daniel | b58a3c7 | 2020-01-23 10:05:14 -0500 | [diff] [blame^] | 106 | kTopLeft_GrSurfaceOrigin, *proxyProvider->caps(), |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 107 | GrSurfaceProxy::UseAllocator::kYes); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 108 | |
| 109 | this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo, |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 110 | GrOp::IsHairline::kNo); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 113 | const char* name() const override { return "LazyProxyTest::Op"; } |
| 114 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 115 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip* clip, |
| 116 | bool hasMixedSampledCoverage, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 117 | return GrProcessorSet::EmptySetAnalysis(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 118 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 119 | void onPrepare(GrOpFlushState*) override {} |
| 120 | |
| 121 | LazyProxyTest* const fTest; |
| 122 | sk_sp<GrTextureProxy> fProxy; |
| 123 | }; |
| 124 | |
| 125 | class ClipFP : public GrFragmentProcessor { |
| 126 | public: |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 127 | ClipFP(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 128 | GrTextureProxy* atlas) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 129 | : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 130 | , fContext(ctx) |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 131 | , fProxyProvider(proxyProvider) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 132 | , fTest(test) |
| 133 | , fAtlas(atlas) { |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 134 | static const GrColorType kColorType = GrColorType::kAlpha_F16; |
| 135 | static const GrSurfaceOrigin kOrigin = kBottomLeft_GrSurfaceOrigin; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 136 | const GrBackendFormat format = |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 137 | ctx->priv().caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes); |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 138 | GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(format, kColorType); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 139 | fLazyProxy = GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 140 | [this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 141 | REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture); |
| 142 | fTest->fHasClipTexture = true; |
| 143 | fAtlas->instantiate(rp); |
| 144 | return sk_ref_sp(fAtlas->peekTexture()); |
| 145 | }, |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 146 | format, readSwizzle, GrRenderable::kYes, 1, GrProtected::kNo, kOrigin, |
Greg Daniel | b58a3c7 | 2020-01-23 10:05:14 -0500 | [diff] [blame^] | 147 | *proxyProvider->caps(), GrSurfaceProxy::UseAllocator::kYes); |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 148 | fAccess.set(GrSurfaceProxyView(fLazyProxy, kOrigin, readSwizzle), |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 149 | GrSamplerState::Filter::kNearest); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 150 | this->setTextureSamplerCnt(1); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | private: |
| 154 | const char* name() const override { return "LazyProxyTest::ClipFP"; } |
| 155 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 156 | return std::make_unique<ClipFP>(fContext, fProxyProvider, fTest, fAtlas); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 157 | } |
| 158 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; } |
| 159 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
| 160 | bool onIsEqual(const GrFragmentProcessor&) const override { return false; } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 161 | const TextureSampler& onTextureSampler(int) const override { return fAccess; } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 162 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 163 | GrRecordingContext* const fContext; |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 164 | GrProxyProvider* const fProxyProvider; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 165 | LazyProxyTest* const fTest; |
| 166 | GrTextureProxy* const fAtlas; |
| 167 | sk_sp<GrTextureProxy> fLazyProxy; |
| 168 | TextureSampler fAccess; |
| 169 | }; |
| 170 | |
| 171 | |
| 172 | class Clip : public GrClip { |
| 173 | public: |
| 174 | Clip(LazyProxyTest* test, GrTextureProxy* atlas) |
| 175 | : fTest(test) |
| 176 | , fAtlas(atlas) {} |
| 177 | |
| 178 | private: |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 179 | bool apply(GrRecordingContext* context, GrRenderTargetContext*, bool useHWAA, |
| 180 | bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const override { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 181 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 182 | out->addCoverageFP(std::make_unique<ClipFP>(context, proxyProvider, fTest, fAtlas)); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 183 | return true; |
| 184 | } |
| 185 | bool quickContains(const SkRect&) const final { return false; } |
| 186 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; } |
| 187 | void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 188 | rect->setLTRB(0, 0, width, height); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 189 | if (iior) { |
| 190 | *iior = false; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | LazyProxyTest* const fTest; |
| 195 | GrTextureProxy* fAtlas; |
| 196 | }; |
| 197 | |
| 198 | private: |
| 199 | skiatest::Reporter* fReporter; |
| 200 | bool fHasOpTexture; |
| 201 | bool fHasClipTexture; |
| 202 | }; |
| 203 | |
| 204 | DEF_GPUTEST(LazyProxyTest, reporter, /* options */) { |
| 205 | GrMockOptions mockOptions; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 206 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability = |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 207 | GrMockOptions::ConfigOptions::Renderability::kNonMSAA; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 208 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 209 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 210 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 211 | for (bool nullTexture : {false, true}) { |
| 212 | LazyProxyTest test(reporter); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 213 | ctx->priv().addOnFlushCallbackObject(&test); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 214 | auto rtc = GrRenderTargetContext::Make( |
| 215 | ctx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {100, 100}); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 216 | REPORTER_ASSERT(reporter, rtc); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 217 | auto mockAtlas = GrRenderTargetContext::Make( |
| 218 | ctx.get(), GrColorType::kAlpha_F16, nullptr, SkBackingFit::kExact, {10, 10}); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 219 | REPORTER_ASSERT(reporter, mockAtlas); |
| 220 | rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()), |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 221 | LazyProxyTest::Op::Make(ctx.get(), proxyProvider, &test, nullTexture)); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 222 | ctx->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 226 | static const int kSize = 16; |
| 227 | |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 228 | DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { |
| 229 | GrMockOptions mockOptions; |
| 230 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 231 | auto proxyProvider = ctx->priv().proxyProvider(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 232 | const GrCaps* caps = ctx->priv().caps(); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 233 | |
| 234 | GrSurfaceDesc desc; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 235 | desc.fWidth = kSize; |
| 236 | desc.fHeight = kSize; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 237 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 238 | GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 239 | GrRenderable::kNo); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 240 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 241 | auto tex = ctx->priv().resourceProvider()->createTexture(desc, format, GrRenderable::kNo, 1, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 242 | GrMipMapped::kNo, SkBudgeted::kNo, |
| 243 | GrProtected::kNo); |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 244 | using LazyInstantiationResult = GrSurfaceProxy::LazyCallbackResult; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 245 | for (bool doInstantiate : {true, false}) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 246 | for (bool releaseCallback : {false, true}) { |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 247 | int testCount = 0; |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 248 | // Sets an integer to 1 when the callback is called and -1 when it is deleted. |
| 249 | class TestCallback { |
| 250 | public: |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 251 | TestCallback(int* value, bool releaseCallback, sk_sp<GrTexture> tex) |
| 252 | : fValue(value) |
| 253 | , fReleaseCallback(releaseCallback) |
| 254 | , fTexture(std::move(tex)) {} |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 255 | TestCallback(const TestCallback& that) { SkASSERT(0); } |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 256 | TestCallback(TestCallback&& that) |
| 257 | : fValue(that.fValue) |
| 258 | , fReleaseCallback(that.fReleaseCallback) |
| 259 | , fTexture(std::move(that.fTexture)) { |
| 260 | that.fValue = nullptr; |
| 261 | } |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 262 | |
| 263 | ~TestCallback() { fValue ? (void)(*fValue = -1) : void(); } |
| 264 | |
| 265 | TestCallback& operator=(TestCallback&& that) { |
| 266 | fValue = skstd::exchange(that.fValue, nullptr); |
| 267 | return *this; |
| 268 | } |
| 269 | TestCallback& operator=(const TestCallback& that) = delete; |
| 270 | |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 271 | LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const { |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 272 | *fValue = 1; |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 273 | return {fTexture, fReleaseCallback}; |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | private: |
| 277 | int* fValue = nullptr; |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 278 | bool fReleaseCallback; |
| 279 | sk_sp<GrTexture> fTexture; |
Brian Salomon | 67f0195 | 2019-02-14 13:05:25 -0500 | [diff] [blame] | 280 | }; |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 281 | GrSwizzle readSwizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 282 | sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy( |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 283 | TestCallback(&testCount, releaseCallback, tex), format, desc, readSwizzle, |
| 284 | GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
| 285 | GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, |
| 286 | SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo, |
| 287 | GrSurfaceProxy::UseAllocator::kYes); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 288 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 289 | REPORTER_ASSERT(reporter, proxy.get()); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 290 | REPORTER_ASSERT(reporter, 0 == testCount); |
| 291 | |
| 292 | if (doInstantiate) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 293 | proxy->priv().doLazyInstantiation(ctx->priv().resourceProvider()); |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 294 | if (releaseCallback) { |
| 295 | // We will call the cleanup and delete the callback in the |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 296 | // doLazyInstantiationCall. |
| 297 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 298 | } else { |
| 299 | REPORTER_ASSERT(reporter, 1 == testCount); |
| 300 | } |
| 301 | proxy.reset(); |
| 302 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 303 | } else { |
| 304 | proxy.reset(); |
| 305 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 306 | } |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 311 | class LazyFailedInstantiationTestOp : public GrDrawOp { |
| 312 | public: |
| 313 | DEFINE_OP_CLASS_ID |
| 314 | |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 315 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 316 | GrProxyProvider* proxyProvider, |
| 317 | int* testExecuteValue, |
| 318 | bool shouldFailInstantiation) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 319 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 320 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 321 | return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 322 | testExecuteValue, |
| 323 | shouldFailInstantiation); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 326 | void visitProxies(const VisitProxyFunc& func) const override { |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 327 | func(fLazyProxy.get(), GrMipMapped::kNo); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 331 | friend class GrOpMemoryPool; // for ctor |
| 332 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 333 | LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider, |
| 334 | int* testExecuteValue, bool shouldFailInstantiation) |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 335 | : INHERITED(ClassID()) |
| 336 | , fTestExecuteValue(testExecuteValue) { |
| 337 | GrSurfaceDesc desc; |
| 338 | desc.fWidth = kSize; |
| 339 | desc.fHeight = kSize; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 340 | GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 341 | ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 342 | GrRenderable::kNo); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 343 | |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 344 | GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle( |
| 345 | format, GrColorType::kRGBA_8888); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 346 | fLazyProxy = proxyProvider->createLazyProxy( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 347 | [testExecuteValue, shouldFailInstantiation, desc, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 348 | format](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 349 | if (shouldFailInstantiation) { |
| 350 | *testExecuteValue = 1; |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 351 | return {}; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 352 | } |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 353 | return {rp->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo, |
| 354 | SkBudgeted::kNo, GrProtected::kNo), |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 355 | true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced}; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 356 | }, |
Greg Daniel | ce3ddaa | 2020-01-22 16:58:15 -0500 | [diff] [blame] | 357 | format, desc, readSwizzle, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, |
| 358 | GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, |
| 359 | SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo, |
| 360 | GrSurfaceProxy::UseAllocator::kYes); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 361 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 362 | SkASSERT(fLazyProxy.get()); |
| 363 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 364 | this->setBounds(SkRect::MakeIWH(kSize, kSize), |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 365 | HasAABloat::kNo, IsHairline::kNo); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 366 | } |
| 367 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 368 | const char* name() const override { return "LazyFailedInstantiationTestOp"; } |
| 369 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 370 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
| 371 | bool hasMixedSampledCoverage, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 372 | return GrProcessorSet::EmptySetAnalysis(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 373 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 374 | void onPrepare(GrOpFlushState*) override {} |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 375 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 376 | *fTestExecuteValue = 2; |
| 377 | } |
| 378 | |
| 379 | int* fTestExecuteValue; |
Greg Daniel | dcf9ca1 | 2019-08-27 14:30:21 -0400 | [diff] [blame] | 380 | sk_sp<GrTextureProxy> fLazyProxy; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 381 | |
| 382 | typedef GrDrawOp INHERITED; |
| 383 | }; |
| 384 | |
| 385 | // Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was |
| 386 | // associated with. |
| 387 | DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) { |
| 388 | GrMockOptions mockOptions; |
| 389 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 390 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 391 | for (bool failInstantiation : {false, true}) { |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 392 | auto rtc = GrRenderTargetContext::Make( |
| 393 | ctx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {100, 100}); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 394 | REPORTER_ASSERT(reporter, rtc); |
| 395 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 396 | rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad), |
| 397 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 398 | |
| 399 | int executeTestValue = 0; |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 400 | rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make( |
| 401 | ctx.get(), proxyProvider, &executeTestValue, failInstantiation)); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 402 | ctx->flush(); |
| 403 | |
| 404 | if (failInstantiation) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 405 | REPORTER_ASSERT(reporter, 1 == executeTestValue); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 406 | } else { |
| 407 | REPORTER_ASSERT(reporter, 2 == executeTestValue); |
| 408 | } |
| 409 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 410 | } |