From d76e56d93c27856b10d6636882a5ffcd79a9d967 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Tue, 13 Feb 2018 10:20:13 -0500 Subject: Add SkCharacterization creation helper to GrContextThreadSafeProxy Change-Id: I8ad7cf335f2b586cf501eaa70573690fbbd53efa Reviewed-on: https://skia-review.googlesource.com/106105 Reviewed-by: Brian Salomon Commit-Queue: Robert Phillips --- tests/DeferredDisplayListTest.cpp | 65 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'tests/DeferredDisplayListTest.cpp') diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp index 468a3695e9..13989a18d7 100644 --- a/tests/DeferredDisplayListTest.cpp +++ b/tests/DeferredDisplayListTest.cpp @@ -20,6 +20,51 @@ #include "SkSurfaceProps.h" #include "Test.h" +#include "gl/GrGLDefines.h" +#ifdef SK_VULKAN +#include "vk/GrVkDefines.h" +#endif + +static GrBackendFormat create_backend_format(GrContext* context, SkColorType colorType) { + const GrCaps* caps = context->caps(); + + switch (context->contextPriv().getBackend()) { + case kOpenGL_GrBackend: + if (kRGBA_8888_SkColorType == colorType) { + GrGLenum format = caps->srgbSupport() ? GR_GL_SRGB8_ALPHA8 : GR_GL_RGBA8; + return GrBackendFormat::MakeGL(format, GR_GL_TEXTURE_2D); + } else if (kRGBA_F16_SkColorType == colorType) { + return GrBackendFormat::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D); + } + break; +#ifdef SK_VULKAN + case kVulkan_GrBackend: + if (kRGBA_8888_SkColorType == colorType) { + VkFormat format = caps->srgbSupport() ? VK_FORMAT_R8G8B8A8_SRGB + : VK_FORMAT_B8G8R8A8_UNORM; + return GrBackendFormat::MakeVK(format); + } else if (kRGBA_F16_SkColorType == colorType) { + return GrBackendFormat::MakeVK(VK_FORMAT_R16G16B16A16_SFLOAT); + } + break; +#endif + case kMock_GrBackend: + if (kRGBA_8888_SkColorType == colorType) { + GrPixelConfig config = caps->srgbSupport() ? kSRGBA_8888_GrPixelConfig + : kRGBA_8888_GrPixelConfig; + return GrBackendFormat::MakeMock(config); + } else if (kRGBA_F16_SkColorType == colorType) { + return GrBackendFormat::MakeMock(kRGBA_half_GrPixelConfig); + } + break; + default: + return GrBackendFormat(); // return an invalid format + } + + return GrBackendFormat(); // return an invalid format +} + + class SurfaceParameters { public: static const int kNumParams = 9; @@ -80,8 +125,20 @@ public: return nullptr; } - SkSurfaceCharacterization c; - SkAssertResult(s->characterize(&c)); + int maxResourceCount; + size_t maxResourceBytes; + context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); + + // Note that Ganesh doesn't make use of the SkImageInfo's alphaType + SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType, + kPremul_SkAlphaType, fColorSpace); + + GrBackendFormat backendFormat = create_backend_format(context, fColorType); + + SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization( + maxResourceBytes, ii, backendFormat, fSampleCount, + fOrigin, fSurfaceProps, fShouldCreateMipMaps); + SkAssertResult(c.isValid()); SkDeferredDisplayListRecorder r(c); SkCanvas* canvas = r.getCanvas(); @@ -161,6 +218,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) SurfaceParameters params; ddl = params.createDDL(context); + SkAssertResult(ddl); // The DDL should draw into an SkSurface created with the same parameters sk_sp s = params.make(context); @@ -212,9 +270,6 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) size_t maxResourceBytes; context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); - context->setResourceCacheLimits(maxResourceCount/2, maxResourceBytes); - REPORTER_ASSERT(reporter, !s->draw(ddl.get())); - context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2); REPORTER_ASSERT(reporter, !s->draw(ddl.get())); -- cgit v1.2.3