diff options
author | Chris Dalton <csmartdalton@google.com> | 2017-11-29 22:01:06 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-30 15:37:12 +0000 |
commit | 706a6ff60c55bee85cff06fc9f8f3764f6e5154b (patch) | |
tree | ce416111dc4101cf58ee12bd7c35007317f33819 /tests | |
parent | de2f1dfebd9d28787cdfd77496f365ed3eb6894d (diff) |
Add "lazy" texture proxies
Adds ultra-deferred proxies that are instantiated by a user-supplied
callback during flush.
Bug: skia:7190
Change-Id: I75a7ac6dba953c3b0a99febc203a7f4d2f3789fc
Reviewed-on: https://skia-review.googlesource.com/76461
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LazyProxyTest.cpp | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp new file mode 100644 index 0000000000..8a620b6a38 --- /dev/null +++ b/tests/LazyProxyTest.cpp @@ -0,0 +1,189 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "Test.h" + +#if SK_SUPPORT_GPU + +#include "GrClip.h" +#include "GrContextPriv.h" +#include "GrOnFlushResourceProvider.h" +#include "GrRenderTargetContext.h" +#include "GrRenderTargetContextPriv.h" +#include "GrSurfaceProxy.h" +#include "GrTexture.h" +#include "GrTextureProxy.h" +#include "GrTextureProxyPriv.h" +#include "SkMakeUnique.h" +#include "mock/GrMockTypes.h" + +// This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks, +// but before Ops are executed. It also ensures that lazy proxy callbacks are invoked both for +// regular Ops and for clips. +class LazyProxyTest final : public GrOnFlushCallbackObject { +public: + LazyProxyTest(skiatest::Reporter* reporter) + : fReporter(reporter) + , fHasOpTexture(false) + , fHasClipTexture(false) { + } + + ~LazyProxyTest() override { + REPORTER_ASSERT(fReporter, fHasOpTexture); + REPORTER_ASSERT(fReporter, fHasClipTexture); + } + + void preFlush(GrOnFlushResourceProvider*, const uint32_t*, int, + SkTArray<sk_sp<GrRenderTargetContext>>*) override { + REPORTER_ASSERT(fReporter, !fHasOpTexture); + REPORTER_ASSERT(fReporter, !fHasClipTexture); + } + + void postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, int numOpListIDs) override { + REPORTER_ASSERT(fReporter, fHasOpTexture); + REPORTER_ASSERT(fReporter, fHasClipTexture); + } + + class Op final : public GrDrawOp { + public: + DEFINE_OP_CLASS_ID + + Op(LazyProxyTest* test, bool nullTexture) : GrDrawOp(ClassID()), fTest(test) { + fProxy = GrSurfaceProxy::MakeLazy([this, nullTexture](GrResourceProvider* rp, + GrSurfaceOrigin* origin) { + REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture); + fTest->fHasOpTexture = true; + *origin = kTopLeft_GrSurfaceOrigin; + if (nullTexture) { + return sk_sp<GrTexture>(); + } else { + GrSurfaceDesc desc; + desc.fWidth = 1234; + desc.fHeight = 567; + desc.fOrigin = kTopLeft_GrSurfaceOrigin; + desc.fConfig = kRGB_565_GrPixelConfig; + sk_sp<GrTexture> texture = rp->createTexture(desc, SkBudgeted::kYes); + REPORTER_ASSERT(fTest->fReporter, texture); + return texture; + } + }, GrSurfaceProxy::Renderable::kNo, kRGB_565_GrPixelConfig); + this->setBounds(SkRect::MakeLargest(), GrOp::HasAABloat::kNo, GrOp::IsZeroArea::kNo); + } + + void visitProxies(const VisitProxyFunc& func) const override { + func(fProxy.get()); + } + + void onExecute(GrOpFlushState*) override { + REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture); + REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture); + } + + private: + const char* name() const override { return "LazyProxyTest::Op"; } + FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } + RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*, + GrPixelConfigIsClamped) override { + return RequiresDstTexture::kNo; + } + void wasRecorded(GrRenderTargetOpList*) override {} + bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; } + void onPrepare(GrOpFlushState*) override {} + + LazyProxyTest* const fTest; + sk_sp<GrTextureProxy> fProxy; + }; + + class ClipFP : public GrFragmentProcessor { + public: + ClipFP(LazyProxyTest* test, GrTextureProxy* atlas) + : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) + , fTest(test) + , fAtlas(atlas) { + fLazyProxy = GrSurfaceProxy::MakeLazy([this](GrResourceProvider* rp, + GrSurfaceOrigin* origin) { + REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture); + fTest->fHasClipTexture = true; + *origin = kBottomLeft_GrSurfaceOrigin; + fAtlas->instantiate(rp); + return sk_ref_sp(fAtlas->priv().peekTexture()); + }, GrSurfaceProxy::Renderable::kYes, kAlpha_half_GrPixelConfig); + fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest, + GrSamplerState::WrapMode::kClamp, kFragment_GrShaderFlag); + this->addTextureSampler(&fAccess); + } + + private: + const char* name() const override { return "LazyProxyTest::ClipFP"; } + std::unique_ptr<GrFragmentProcessor> clone() const override { + return skstd::make_unique<ClipFP>(fTest, fAtlas); + } + GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; } + void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} + bool onIsEqual(const GrFragmentProcessor&) const override { return false; } + + LazyProxyTest* const fTest; + GrTextureProxy* const fAtlas; + sk_sp<GrTextureProxy> fLazyProxy; + TextureSampler fAccess; + }; + + + class Clip : public GrClip { + public: + Clip(LazyProxyTest* test, GrTextureProxy* atlas) + : fTest(test) + , fAtlas(atlas) {} + + private: + bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out, + SkRect* bounds) const override { + out->addCoverageFP(skstd::make_unique<ClipFP>(fTest, fAtlas)); + return true; + } + bool quickContains(const SkRect&) const final { return false; } + bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; } + void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final { + rect->set(0, 0, width, height); + if (iior) { + *iior = false; + } + } + + LazyProxyTest* const fTest; + GrTextureProxy* fAtlas; + }; + +private: + skiatest::Reporter* fReporter; + bool fHasOpTexture; + bool fHasClipTexture; +}; + +DEF_GPUTEST(LazyProxyTest, reporter, /* options */) { + GrMockOptions mockOptions; + mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderable[0] = true; + mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true; + sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); + for (bool nullTexture : {false, true}) { + LazyProxyTest test(reporter); + ctx->contextPriv().addOnFlushCallbackObject(&test); + sk_sp<GrRenderTargetContext> rtc = + ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact, 100, 100, + kRGBA_8888_GrPixelConfig, nullptr); + REPORTER_ASSERT(reporter, rtc); + sk_sp<GrRenderTargetContext> mockAtlas = + ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact, 10, 10, + kAlpha_half_GrPixelConfig, nullptr); + REPORTER_ASSERT(reporter, mockAtlas); + rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()), + skstd::make_unique<LazyProxyTest::Op>(&test, nullTexture)); + ctx->contextPriv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test); + } +} + +#endif |