aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LazyProxyTest.cpp
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-03-08 15:27:36 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-08 21:05:21 +0000
commit4684f82ebca85d4c7043e5c1028e34cf5631da32 (patch)
tree6e640d1b212ab614fa19ccd4e43c5adff440dacd /tests/LazyProxyTest.cpp
parent3adc12213b2d1efbe417476517ff3381af17a311 (diff)
Add ability to uninstantiate lazy proxies after every flush.
Bug: skia: Change-Id: Id32540cda54a9c5e3e6cb721776699be3cc8ac1a Reviewed-on: https://skia-review.googlesource.com/113263 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests/LazyProxyTest.cpp')
-rw-r--r--tests/LazyProxyTest.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp
index 9253678dbb..88cbd01649 100644
--- a/tests/LazyProxyTest.cpp
+++ b/tests/LazyProxyTest.cpp
@@ -22,6 +22,7 @@
#include "GrTextureProxyPriv.h"
#include "SkMakeUnique.h"
#include "SkRectPriv.h"
+#include "mock/GrMockGpu.h"
#include "mock/GrMockTypes.h"
// This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks,
@@ -341,7 +342,127 @@ DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) {
REPORTER_ASSERT(reporter, 2 == executeTestValue);
}
}
+}
+
+class LazyUninstantiateTestOp : public GrDrawOp {
+public:
+ DEFINE_OP_CLASS_ID
+
+ LazyUninstantiateTestOp(sk_sp<GrTextureProxy> proxy)
+ : INHERITED(ClassID())
+ , fLazyProxy(std::move(proxy)) {
+
+ 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 "LazyUninstantiateTestOp"; }
+ 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 {}
+
+ sk_sp<GrSurfaceProxy> fLazyProxy;
+
+ typedef GrDrawOp INHERITED;
+};
+
+static void UninstantiateReleaseProc(void* releaseValue) {
+ (*static_cast<int*>(releaseValue))++;
+}
+
+// Test that lazy proxies with the Uninstantiate LazyCallbackType are uninstantiated and released as
+// expected.
+DEF_GPUTEST(LazyProxyUninstantiateTest, reporter, /* options */) {
+ GrMockOptions mockOptions;
+ sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
+ GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
+ GrGpu* gpu = ctx->contextPriv().getGpu();
+
+ using LazyType = GrSurfaceProxy::LazyInstantiationType;
+ for (auto lazyType : {LazyType::kSingleUse, LazyType::kMultipleUse, LazyType::kUninstantiate}) {
+ sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
+ SkBackingFit::kExact, 100, 100,
+ kRGBA_8888_GrPixelConfig, nullptr);
+ REPORTER_ASSERT(reporter, rtc);
+
+ rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
+
+ int instantiateTestValue = 0;
+ int releaseTestValue = 0;
+ int* instantiatePtr = &instantiateTestValue;
+ int* releasePtr = &releaseTestValue;
+ GrSurfaceDesc desc;
+ desc.fWidth = kSize;
+ desc.fHeight = kSize;
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+
+ GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
+ nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo);
+
+ sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy(
+ [instantiatePtr, releasePtr, backendTex](GrResourceProvider* rp) {
+ if (!rp) {
+ return sk_sp<GrTexture>();
+ }
+
+ sk_sp<GrTexture> texture = rp->wrapBackendTexture(backendTex);
+ if (!texture) {
+ return sk_sp<GrTexture>();
+ }
+ (*instantiatePtr)++;
+ texture->setRelease(UninstantiateReleaseProc, releasePtr);
+ return texture;
+ },
+ desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact,
+ SkBudgeted::kNo);
+
+ lazyProxy->priv().testingOnly_setLazyInstantiationType(lazyType);
+
+ rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
+
+ ctx->flush();
+
+ REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
+ if (LazyType::kUninstantiate == lazyType) {
+ REPORTER_ASSERT(reporter, 1 == releaseTestValue);
+ } else {
+ REPORTER_ASSERT(reporter, 0 == releaseTestValue);
+ }
+ // This should cause the uninstantiate proxies to be instantiated again but have no effect
+ // on the others
+ rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
+ // Add a second op to make sure we only instantiate once.
+ rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
+ ctx->flush();
+
+ if (LazyType::kUninstantiate == lazyType) {
+ REPORTER_ASSERT(reporter, 2 == instantiateTestValue);
+ REPORTER_ASSERT(reporter, 2 == releaseTestValue);
+ } else {
+ REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
+ REPORTER_ASSERT(reporter, 0 == releaseTestValue);
+ }
+
+ lazyProxy.reset();
+ if (LazyType::kUninstantiate == lazyType) {
+ REPORTER_ASSERT(reporter, 2 == releaseTestValue);
+ } else {
+ REPORTER_ASSERT(reporter, 1 == releaseTestValue);
+ }
+
+ gpu->deleteTestingOnlyBackendTexture(&backendTex);
+ }
}
#endif