Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: tests/SurfaceTest.cpp

Issue 2270823002: Some tests around surface creation and snapshotting with color space (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <functional> 8 #include <functional>
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorSpace_Base.h"
10 #include "SkData.h" 11 #include "SkData.h"
11 #include "SkDevice.h" 12 #include "SkDevice.h"
12 #include "SkImage_Base.h" 13 #include "SkImage_Base.h"
13 #include "SkPath.h" 14 #include "SkPath.h"
14 #include "SkRRect.h" 15 #include "SkRRect.h"
15 #include "SkSurface.h" 16 #include "SkSurface.h"
16 #include "SkUtils.h" 17 #include "SkUtils.h"
17 #include "Test.h" 18 #include "Test.h"
18 19
19 #if SK_SUPPORT_GPU 20 #if SK_SUPPORT_GPU
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 // our surface functions. 904 // our surface functions.
904 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo pLayerDrawContext() 905 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo pLayerDrawContext()
905 ->accessRenderTarget(); 906 ->accessRenderTarget();
906 REPORTER_ASSERT(reporter, 907 REPORTER_ASSERT(reporter,
907 ctxInfo.grContext()->resourceProvider()->attachStenc ilAttachment(rt)); 908 ctxInfo.grContext()->resourceProvider()->attachStenc ilAttachment(rt));
908 gpu->deleteTestingOnlyBackendTexture(textureObject); 909 gpu->deleteTestingOnlyBackendTexture(textureObject);
909 } 910 }
910 } 911 }
911 } 912 }
912 #endif 913 #endif
914
915 DEF_TEST(SurfaceCreationWithColorSpace, reporter) {
916 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
917 auto adobeColorSpace = SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named) ;
918 SkMatrix44 srgbMatrix = srgbColorSpace->xyz();
919 const float oddGamma[] = { 2.4f, 2.4f, 2.4f };
920 auto oddColorSpace = SkColorSpace_Base::NewRGB(oddGamma, srgbMatrix);
921 auto linearColorSpace = SkColorSpace::NewRGB(SkColorSpace::kLinear_GammaName d, srgbMatrix);
922
923 const struct {
924 SkColorType fColorType;
925 sk_sp<SkColorSpace> fColorSpace;
926 bool fShouldWork;
927 const char* fDescription;
928 } testConfigs[] = {
929 { kN32_SkColorType, nullptr, true, "N32-nullptr" },
930 { kN32_SkColorType, linearColorSpace, true, "N32-linear" }, // T ODO: 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.
931 { kN32_SkColorType, srgbColorSpace, true, "N32-srgb" },
932 { kN32_SkColorType, adobeColorSpace, true, "N32-adobe" },
933 { kN32_SkColorType, oddColorSpace, false, "N32-odd" },
934 { kRGBA_F16_SkColorType, nullptr, true, "F16-nullptr" }, // T ODO: 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.
935 { kRGBA_F16_SkColorType, linearColorSpace, true, "F16-linear" },
936 { kRGBA_F16_SkColorType, srgbColorSpace, true, "F16-srgb" },
937 { kRGBA_F16_SkColorType, adobeColorSpace, true, "F16-adobe" },
938 { kRGBA_F16_SkColorType, oddColorSpace, true, "F16-odd" }, // T ODO: 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
939 { kRGB_565_SkColorType, srgbColorSpace, false, "565-srgb" },
940 { kAlpha_8_SkColorType, srgbColorSpace, false, "A8-srgb" }, // T ODO: 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
941 };
942
943 for (auto& testConfig : testConfigs) {
944 SkImageInfo info = SkImageInfo::Make(10, 10, testConfig.fColorType, kPre mul_SkAlphaType,
945 testConfig.fColorSpace);
946 auto surface(SkSurface::MakeRaster(info));
947 REPORTER_ASSERT_MESSAGE(reporter, SkToBool(surface) == testConfig.fShoul dWork,
948 testConfig.fDescription);
949
950 if (testConfig.fShouldWork && surface) {
951 sk_sp<SkImage> image(surface->makeImageSnapshot());
952 REPORTER_ASSERT_MESSAGE(reporter, image, testConfig.fDescription);
953 SkColorSpace* imageColorSpace = as_IB(image)->onImageInfo().colorSpa ce();
954 REPORTER_ASSERT_MESSAGE(reporter, imageColorSpace == testConfig.fCol orSpace.get(),
955 testConfig.fDescription);
956 }
957 }
958 }
OLDNEW
« src/image/SkSurface_Raster.cpp ('K') | « src/image/SkSurface_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698