From efcc41805b43347444b83c1705d3d60c8d0caa70 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Thu, 5 Jan 2017 10:41:39 -0500 Subject: Explicitly fail read/writePixels in invalid color space scenarios It's not well defined what to do when moving from a nullptr color space to a tagged destination (drawing, reading, writing, etc...). In these scenarios, at least, we can choose to disallow the operation (rather than produce an unexpected or inconsistent result). BUG=skia: Change-Id: I033b23c6f2bb00664efc8fdab1b3f52053d77695 Reviewed-on: https://skia-review.googlesource.com/6600 Commit-Queue: Brian Osman Reviewed-by: Brian Salomon Reviewed-by: Matt Sarett --- tests/ReadPixelsTest.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/ReadPixelsTest.cpp') diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 71cd8f5fc9..487152c42a 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -487,3 +487,40 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) { } } #endif + +#if SK_SUPPORT_GPU +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixelsColorSpaceVariants_Gpu, reporter, ctxInfo) { + // Create surfaces with and without an attached color space + sk_sp srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + SkImageInfo srgbInfo = SkImageInfo::MakeS32(DEV_W, DEV_H, kPremul_SkAlphaType); + SkImageInfo legacyInfo = srgbInfo.makeColorSpace(nullptr); + + sk_sp srgbSurface = SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, + srgbInfo); + sk_sp legacySurface = SkSurface::MakeRenderTarget(ctxInfo.grContext(), + SkBudgeted::kNo, legacyInfo); + SkCanvas* srgbCanvas = srgbSurface->getCanvas(); + SkCanvas* legacyCanvas = legacySurface->getCanvas(); + + struct { + SkCanvas* fCanvas; + const SkImageInfo& fBmpInfo; + bool fExpectSuccess; + } kTestConfigs[] ={ + // Both kinds of surface should be able to read into a legacy destination + { srgbCanvas, legacyInfo, true }, + { legacyCanvas, legacyInfo, true }, + // Tagged surface should be able to read into tagged destination + { srgbCanvas, srgbInfo, true }, + // Legacy surface shouldn't read into tagged destination + { legacyCanvas, srgbInfo, false }, + }; + + for (auto testConfig : kTestConfigs) { + SkBitmap bmp; + bmp.setInfo(testConfig.fBmpInfo); + bool result = testConfig.fCanvas->readPixels(&bmp, 0, 0); + REPORTER_ASSERT(reporter, result == testConfig.fExpectSuccess); + } +} +#endif -- cgit v1.2.3