diff options
author | Greg Daniel <egdaniel@google.com> | 2018-01-29 10:34:25 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-29 16:01:21 +0000 |
commit | aa3dfbe51e6f14db5ccc048b4167ad334ce05176 (patch) | |
tree | 29ecae5f1461148747751d7c51e00e3cc470db9b /tests/LazyProxyTest.cpp | |
parent | 03bd9ee472ed1f7b3b2320277fdf32e461abc54d (diff) |
Remove Ops whose lazy proxies fail to instantiate on flush
Bug: skia:
Change-Id: If8b5b9e5d0c306be28ba192b731d34d185427354
Reviewed-on: https://skia-review.googlesource.com/99440
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests/LazyProxyTest.cpp')
-rw-r--r-- | tests/LazyProxyTest.cpp | 91 |
1 files changed, 89 insertions, 2 deletions
diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index d43f07d959..029a5a5ed1 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -194,14 +194,16 @@ DEF_GPUTEST(LazyProxyTest, reporter, /* options */) { } } +static const int kSize = 16; + DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { GrMockOptions mockOptions; sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); auto proxyProvider = ctx->contextPriv().proxyProvider(); GrSurfaceDesc desc; - desc.fWidth = 16; - desc.fHeight = 16; + desc.fWidth = kSize; + desc.fHeight = kSize; desc.fConfig = kRGBA_8888_GrPixelConfig; for (bool doInstantiate : {true, false}) { @@ -231,4 +233,89 @@ DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { } } +class LazyFailedInstantiationTestOp : public GrDrawOp { +public: + DEFINE_OP_CLASS_ID + + LazyFailedInstantiationTestOp(GrProxyProvider* proxyProvider, int* testExecuteValue, + bool shouldFailInstantiation) + : INHERITED(ClassID()) + , fTestExecuteValue(testExecuteValue) { + GrSurfaceDesc desc; + desc.fWidth = kSize; + desc.fHeight = kSize; + desc.fConfig = kRGBA_8888_GrPixelConfig; + + fLazyProxy = proxyProvider->createLazyProxy( + [testExecuteValue, shouldFailInstantiation, desc] ( + GrResourceProvider* rp, GrSurfaceOrigin* /*origin*/) { + *testExecuteValue = 1; + if (shouldFailInstantiation || !rp) { + return sk_sp<GrTexture>(); + } + return rp->createTexture(desc, SkBudgeted::kNo); + }, desc, GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kNo); + + this->setBounds(SkRect::MakeIWH(kSize, kSize), + HasAABloat::kNo, IsZeroArea::kNo); + } + + void visitProxies(const VisitProxyFunc& func) const override { + func(fLazyProxy.get()); + } + +private: + const char* name() const override { return "LazyFailedInstantiationTestOp"; } + FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } + RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*, + GrPixelConfigIsClamped) override { + return RequiresDstTexture::kNo; + } + bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; } + void onPrepare(GrOpFlushState*) override {} + void onExecute(GrOpFlushState* state) override { + *fTestExecuteValue = 2; + } + + int* fTestExecuteValue; + sk_sp<GrSurfaceProxy> fLazyProxy; + + typedef GrDrawOp INHERITED; +}; + +// Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was +// associated with. +DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) { + GrMockOptions mockOptions; + sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); + GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); + for (bool failInstantiation : {false, true}) { + sk_sp<GrRenderTargetContext> rtc = + ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact, 100, 100, + kRGBA_8888_GrPixelConfig, nullptr); + REPORTER_ASSERT(reporter, rtc); + + rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes); + + int executeTestValue = 0; + rtc->priv().testingOnly_addDrawOp( + skstd::make_unique<LazyFailedInstantiationTestOp>(proxyProvider, &executeTestValue, + failInstantiation)); + ctx->flush(); + + if (failInstantiation) { +#ifdef SK_DISABLE_EXPLICIT_GPU_RESOURCE_ALLOCATION + // When we disable explicit gpu resource allocation we don't throw away ops that have + // uninstantiated proxies. + REPORTER_ASSERT(reporter, 2 == executeTestValue); +#else + REPORTER_ASSERT(reporter, 1 == executeTestValue); +#endif + } else { + REPORTER_ASSERT(reporter, 2 == executeTestValue); + } + } + +} + #endif |