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