Index: tests/SurfaceTest.cpp |
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp |
index 2703b541fc59854b2ac27989bfcea59adad2db0c..e75e5fdc5d12f83c774aa7f36fee679535a45f07 100644 |
--- a/tests/SurfaceTest.cpp |
+++ b/tests/SurfaceTest.cpp |
@@ -7,6 +7,7 @@ |
#include <functional> |
#include "SkCanvas.h" |
+#include "SkColorSpace_Base.h" |
#include "SkData.h" |
#include "SkDevice.h" |
#include "SkImage_Base.h" |
@@ -910,3 +911,48 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf |
} |
} |
#endif |
+ |
+DEF_TEST(SurfaceCreationWithColorSpace, reporter) { |
+ auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
+ auto adobeColorSpace = SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named); |
+ SkMatrix44 srgbMatrix = srgbColorSpace->xyz(); |
+ const float oddGamma[] = { 2.4f, 2.4f, 2.4f }; |
+ auto oddColorSpace = SkColorSpace_Base::NewRGB(oddGamma, srgbMatrix); |
+ auto linearColorSpace = SkColorSpace::NewRGB(SkColorSpace::kLinear_GammaNamed, srgbMatrix); |
+ |
+ const struct { |
+ SkColorType fColorType; |
+ sk_sp<SkColorSpace> fColorSpace; |
+ bool fShouldWork; |
+ const char* fDescription; |
+ } testConfigs[] = { |
+ { kN32_SkColorType, nullptr, true, "N32-nullptr" }, |
+ { kN32_SkColorType, linearColorSpace, true, "N32-linear" }, // TODO: Disallow this? |
Brian Osman
2016/08/23 13:25:56
Starting from the statement: "If there is a color
msarett
2016/08/23 13:46:11
FWIW, image decoders support linear 8-bit. But it
mtklein
2016/08/23 14:24:51
Yes, ban it. If you're well informed about color
Brian Osman
2016/08/23 14:58:33
Acknowledged.
|
+ { kN32_SkColorType, srgbColorSpace, true, "N32-srgb" }, |
+ { kN32_SkColorType, adobeColorSpace, true, "N32-adobe" }, |
+ { kN32_SkColorType, oddColorSpace, false, "N32-odd" }, |
+ { kRGBA_F16_SkColorType, nullptr, true, "F16-nullptr" }, // TODO: Disallow this? |
Brian Osman
2016/08/23 13:25:56
We've mentioned requiring a color space with F16.
msarett
2016/08/23 13:46:11
Image decoders will fail (on purpose) if you ask f
mtklein
2016/08/23 14:24:50
Yes, let's ban this. There are no legacy users of
Brian Osman
2016/08/23 14:58:33
Acknowledged.
|
+ { kRGBA_F16_SkColorType, linearColorSpace, true, "F16-linear" }, |
+ { kRGBA_F16_SkColorType, srgbColorSpace, true, "F16-srgb" }, |
+ { kRGBA_F16_SkColorType, adobeColorSpace, true, "F16-adobe" }, |
+ { kRGBA_F16_SkColorType, oddColorSpace, true, "F16-odd" }, // TODO: Disallow this? |
Brian Osman
2016/08/23 13:25:56
Should we allow this? The gamma is ignored, so in
msarett
2016/08/23 13:46:11
Supporting this doesn't bother the image decoders.
mtklein
2016/08/23 14:24:50
Remind me why we'd support non-linear gamma for F1
Brian Osman
2016/08/23 14:58:33
I have several arguments each way:
1) We get an i
|
+ { kRGB_565_SkColorType, srgbColorSpace, false, "565-srgb" }, |
+ { kAlpha_8_SkColorType, srgbColorSpace, false, "A8-srgb" }, // TODO: Allow this? |
Brian Osman
2016/08/23 13:25:56
Pretty sure we don't want to support this - obviou
msarett
2016/08/23 13:46:11
Agree with your gut. It's a nice simplification t
mtklein
2016/08/23 14:24:50
Right, let's ban non-linear alpha entirely.
Grey8-
Brian Osman
2016/08/23 14:58:33
... actually, we don't support Grey8 as a surface
|
+ }; |
+ |
+ for (auto& testConfig : testConfigs) { |
+ SkImageInfo info = SkImageInfo::Make(10, 10, testConfig.fColorType, kPremul_SkAlphaType, |
+ testConfig.fColorSpace); |
+ auto surface(SkSurface::MakeRaster(info)); |
+ REPORTER_ASSERT_MESSAGE(reporter, SkToBool(surface) == testConfig.fShouldWork, |
+ testConfig.fDescription); |
+ |
+ if (testConfig.fShouldWork && surface) { |
+ sk_sp<SkImage> image(surface->makeImageSnapshot()); |
+ REPORTER_ASSERT_MESSAGE(reporter, image, testConfig.fDescription); |
+ SkColorSpace* imageColorSpace = as_IB(image)->onImageInfo().colorSpace(); |
+ REPORTER_ASSERT_MESSAGE(reporter, imageColorSpace == testConfig.fColorSpace.get(), |
+ testConfig.fDescription); |
+ } |
+ } |
+} |