From 6b6fcc78620270ec2dcd57bd520ec500f60f4505 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Fri, 30 Mar 2018 13:57:00 -0400 Subject: Add SkSurface factory that takes an SkSurfaceCharacterization TBR=bsalomon@google.com Change-Id: Ie38123dc7c35005bfe8500bf4a16e0d16bbf36bd Reviewed-on: https://skia-review.googlesource.com/117236 Reviewed-by: Robert Phillips Reviewed-by: Greg Daniel Commit-Queue: Robert Phillips --- tests/DeferredDisplayListTest.cpp | 49 +++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp index d9aa522125..ddbb4a84c0 100644 --- a/tests/DeferredDisplayListTest.cpp +++ b/tests/DeferredDisplayListTest.cpp @@ -121,13 +121,7 @@ public: } } - // Create a DDL whose characterization captures the current settings - std::unique_ptr createDDL(GrContext* context) const { - sk_sp s = this->make(context); - if (!s) { - return nullptr; - } - + SkSurfaceCharacterization createCharacterization(GrContext* context) const { int maxResourceCount; size_t maxResourceBytes; context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); @@ -141,6 +135,12 @@ public: SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization( maxResourceBytes, ii, backendFormat, fSampleCount, fOrigin, fSurfaceProps, fShouldCreateMipMaps); + return c; + } + + // Create a DDL whose characterization captures the current settings + std::unique_ptr createDDL(GrContext* context) const { + SkSurfaceCharacterization c = this->createCharacterization(context); SkAssertResult(c.isValid()); SkDeferredDisplayListRecorder r(c); @@ -205,6 +205,7 @@ private: bool fShouldCreateMipMaps; }; +//////////////////////////////////////////////////////////////////////////////// // This tests SkSurfaceCharacterization/SkSurface compatibility DEF_GPUTEST_FOR_ALL_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); @@ -258,6 +259,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) } if (SurfaceParameters::kMipMipCount == i && !context->caps()->mipMapSupport()) { + // If changing the mipmap setting won't result in a different surface characterization, + // skip this step continue; } @@ -345,6 +348,35 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) } } +//////////////////////////////////////////////////////////////////////////////// +// This tests the SkSurface::MakeRenderTarget variant that takes an SkSurfaceCharacterization. +// In particular, the SkSurface and the SkSurfaceCharacterization should always be compatible. +DEF_GPUTEST_FOR_ALL_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) { + GrContext* context = ctxInfo.grContext(); + + for (int i = 0; i < SurfaceParameters::kNumParams; ++i) { + SurfaceParameters params; + params.modify(i); + + SkSurfaceCharacterization c = params.createCharacterization(context); + + sk_sp s = params.make(context); + if (!s) { + REPORTER_ASSERT(reporter, !c.isValid()); + continue; + } + + REPORTER_ASSERT(reporter, c.isValid()); + + s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes); + REPORTER_ASSERT(reporter, s); + + SkSurface_Gpu* g = static_cast(s.get()); + REPORTER_ASSERT(reporter, g->isCompatible(c)); + } +} + +//////////////////////////////////////////////////////////////////////////////// static constexpr int kSize = 8; struct TextureReleaseChecker { @@ -411,6 +443,7 @@ static void dummy_fulfill_proc(void*, GrBackendTexture*) { SkASSERT(0); } static void dummy_release_proc(void*) { SkASSERT(0); } static void dummy_done_proc(void*) { } +//////////////////////////////////////////////////////////////////////////////// // Test out the behavior of an invalid DDLRecorder DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); @@ -450,6 +483,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) { } +//////////////////////////////////////////////////////////////////////////////// // Ensure that flushing while DDL recording doesn't cause a crash DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); @@ -467,6 +501,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) { canvas->getGrContext()->flush(); } +//////////////////////////////////////////////////////////////////////////////// // Check that the texture-specific flags (i.e., for external & rectangle textures) work // for promise images. As such, this is a GL-only test. DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) { -- cgit v1.2.3