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 | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 87 | [this, format, |
| 88 | nullTexture](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { |
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 | 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 | }, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 105 | format, GrRenderable::kNo, 1, GrProtected::kNo, kTopLeft_GrSurfaceOrigin, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 106 | kRGB_565_GrPixelConfig, *proxyProvider->caps(), |
| 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) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 134 | const GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 135 | ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kAlpha_F16, |
| 136 | GrRenderable::kYes); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 137 | fLazyProxy = GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 138 | [this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 139 | REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture); |
| 140 | fTest->fHasClipTexture = true; |
| 141 | fAtlas->instantiate(rp); |
| 142 | return sk_ref_sp(fAtlas->peekTexture()); |
| 143 | }, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 144 | format, GrRenderable::kYes, 1, GrProtected::kNo, kBottomLeft_GrSurfaceOrigin, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 145 | kAlpha_half_GrPixelConfig, *proxyProvider->caps(), |
| 146 | GrSurfaceProxy::UseAllocator::kYes); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 147 | fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 148 | GrSamplerState::WrapMode::kClamp); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 149 | this->setTextureSamplerCnt(1); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | private: |
| 153 | const char* name() const override { return "LazyProxyTest::ClipFP"; } |
| 154 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 155 | return skstd::make_unique<ClipFP>(fContext, fProxyProvider, fTest, fAtlas); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 156 | } |
| 157 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; } |
| 158 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
| 159 | bool onIsEqual(const GrFragmentProcessor&) const override { return false; } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 160 | const TextureSampler& onTextureSampler(int) const override { return fAccess; } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 161 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 162 | GrRecordingContext* const fContext; |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 163 | GrProxyProvider* const fProxyProvider; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 164 | LazyProxyTest* const fTest; |
| 165 | GrTextureProxy* const fAtlas; |
| 166 | sk_sp<GrTextureProxy> fLazyProxy; |
| 167 | TextureSampler fAccess; |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | class Clip : public GrClip { |
| 172 | public: |
| 173 | Clip(LazyProxyTest* test, GrTextureProxy* atlas) |
| 174 | : fTest(test) |
| 175 | , fAtlas(atlas) {} |
| 176 | |
| 177 | private: |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 178 | bool apply(GrRecordingContext* context, GrRenderTargetContext*, bool useHWAA, |
| 179 | bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const override { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 180 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 181 | out->addCoverageFP(skstd::make_unique<ClipFP>(context, proxyProvider, fTest, fAtlas)); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 182 | return true; |
| 183 | } |
| 184 | bool quickContains(const SkRect&) const final { return false; } |
| 185 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; } |
| 186 | void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 187 | rect->setLTRB(0, 0, width, height); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 188 | if (iior) { |
| 189 | *iior = false; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | LazyProxyTest* const fTest; |
| 194 | GrTextureProxy* fAtlas; |
| 195 | }; |
| 196 | |
| 197 | private: |
| 198 | skiatest::Reporter* fReporter; |
| 199 | bool fHasOpTexture; |
| 200 | bool fHasClipTexture; |
| 201 | }; |
| 202 | |
| 203 | DEF_GPUTEST(LazyProxyTest, reporter, /* options */) { |
| 204 | GrMockOptions mockOptions; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 205 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability = |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 206 | GrMockOptions::ConfigOptions::Renderability::kNonMSAA; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 207 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 208 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 209 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 210 | for (bool nullTexture : {false, true}) { |
| 211 | LazyProxyTest test(reporter); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 212 | ctx->priv().addOnFlushCallbackObject(&test); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 213 | auto rtc = ctx->priv().makeDeferredRenderTargetContext(SkBackingFit::kExact, 100, 100, |
| 214 | GrColorType::kRGBA_8888, nullptr); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 215 | REPORTER_ASSERT(reporter, rtc); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 216 | auto mockAtlas = ctx->priv().makeDeferredRenderTargetContext( |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 217 | SkBackingFit::kExact, 10, 10, GrColorType::kAlpha_F16, nullptr); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 218 | REPORTER_ASSERT(reporter, mockAtlas); |
| 219 | rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()), |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 220 | LazyProxyTest::Op::Make(ctx.get(), proxyProvider, &test, nullTexture)); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 221 | ctx->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 225 | static const int kSize = 16; |
| 226 | |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 227 | DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { |
| 228 | GrMockOptions mockOptions; |
| 229 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 230 | auto proxyProvider = ctx->priv().proxyProvider(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 231 | const GrCaps* caps = ctx->priv().caps(); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 232 | |
| 233 | GrSurfaceDesc desc; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 234 | desc.fWidth = kSize; |
| 235 | desc.fHeight = kSize; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 236 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 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 | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 281 | sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy( |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 282 | TestCallback(&testCount, releaseCallback, tex), format, desc, GrRenderable::kNo, |
| 283 | 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 284 | GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 285 | GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 286 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 287 | REPORTER_ASSERT(reporter, proxy.get()); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 288 | REPORTER_ASSERT(reporter, 0 == testCount); |
| 289 | |
| 290 | if (doInstantiate) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 291 | proxy->priv().doLazyInstantiation(ctx->priv().resourceProvider()); |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 292 | if (releaseCallback) { |
| 293 | // We will call the cleanup and delete the callback in the |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 294 | // doLazyInstantiationCall. |
| 295 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 296 | } else { |
| 297 | REPORTER_ASSERT(reporter, 1 == testCount); |
| 298 | } |
| 299 | proxy.reset(); |
| 300 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 301 | } else { |
| 302 | proxy.reset(); |
| 303 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 304 | } |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 309 | class LazyFailedInstantiationTestOp : public GrDrawOp { |
| 310 | public: |
| 311 | DEFINE_OP_CLASS_ID |
| 312 | |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 313 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 314 | GrProxyProvider* proxyProvider, |
| 315 | int* testExecuteValue, |
| 316 | bool shouldFailInstantiation) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 317 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 318 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 319 | return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 320 | testExecuteValue, |
| 321 | shouldFailInstantiation); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 324 | void visitProxies(const VisitProxyFunc& func) const override { |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 325 | func(fLazyProxy.get(), GrMipMapped::kNo); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 329 | friend class GrOpMemoryPool; // for ctor |
| 330 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 331 | LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider, |
| 332 | int* testExecuteValue, bool shouldFailInstantiation) |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 333 | : INHERITED(ClassID()) |
| 334 | , fTestExecuteValue(testExecuteValue) { |
| 335 | GrSurfaceDesc desc; |
| 336 | desc.fWidth = kSize; |
| 337 | desc.fHeight = kSize; |
| 338 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 339 | GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 340 | ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 341 | GrRenderable::kNo); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 342 | |
| 343 | fLazyProxy = proxyProvider->createLazyProxy( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 344 | [testExecuteValue, shouldFailInstantiation, desc, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 345 | format](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 346 | if (shouldFailInstantiation) { |
| 347 | *testExecuteValue = 1; |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 348 | return {}; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 349 | } |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 350 | return {rp->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo, |
| 351 | SkBudgeted::kNo, GrProtected::kNo), |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 352 | true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced}; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 353 | }, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 354 | format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 355 | GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, |
| 356 | SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 357 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 358 | SkASSERT(fLazyProxy.get()); |
| 359 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 360 | this->setBounds(SkRect::MakeIWH(kSize, kSize), |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame^] | 361 | HasAABloat::kNo, IsHairline::kNo); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 362 | } |
| 363 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 364 | const char* name() const override { return "LazyFailedInstantiationTestOp"; } |
| 365 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 366 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
| 367 | bool hasMixedSampledCoverage, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 368 | return GrProcessorSet::EmptySetAnalysis(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 369 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 370 | void onPrepare(GrOpFlushState*) override {} |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 371 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 372 | *fTestExecuteValue = 2; |
| 373 | } |
| 374 | |
| 375 | int* fTestExecuteValue; |
Greg Daniel | dcf9ca1 | 2019-08-27 14:30:21 -0400 | [diff] [blame] | 376 | sk_sp<GrTextureProxy> fLazyProxy; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 377 | |
| 378 | typedef GrDrawOp INHERITED; |
| 379 | }; |
| 380 | |
| 381 | // Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was |
| 382 | // associated with. |
| 383 | DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) { |
| 384 | GrMockOptions mockOptions; |
| 385 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 386 | GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 387 | for (bool failInstantiation : {false, true}) { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 388 | auto rtc = ctx->priv().makeDeferredRenderTargetContext(SkBackingFit::kExact, 100, 100, |
| 389 | GrColorType::kRGBA_8888, nullptr); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 390 | REPORTER_ASSERT(reporter, rtc); |
| 391 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 392 | rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad), |
| 393 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 394 | |
| 395 | int executeTestValue = 0; |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 396 | rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make( |
| 397 | ctx.get(), proxyProvider, &executeTestValue, failInstantiation)); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 398 | ctx->flush(); |
| 399 | |
| 400 | if (failInstantiation) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 401 | REPORTER_ASSERT(reporter, 1 == executeTestValue); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 402 | } else { |
| 403 | REPORTER_ASSERT(reporter, 2 == executeTestValue); |
| 404 | } |
| 405 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 406 | } |