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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp

Issue 2893243003: color: Add ColorCanvasExtensions runtime flag (Closed)
Patch Set: Fix logic error in ImageBitmap Created 3 years, 6 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/canvas2d/CanvasRenderingContext2D.h" 5 #include "modules/canvas2d/CanvasRenderingContext2D.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "bindings/core/v8/V8BindingForCore.h" 8 #include "bindings/core/v8/V8BindingForCore.h"
9 #include "bindings/core/v8/V8BindingForTesting.h" 9 #include "bindings/core/v8/V8BindingForTesting.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
(...skipping 25 matching lines...) Expand all
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 #include "third_party/skia/include/core/SkColorSpaceXform.h" 37 #include "third_party/skia/include/core/SkColorSpaceXform.h"
38 #include "third_party/skia/include/core/SkImage.h" 38 #include "third_party/skia/include/core/SkImage.h"
39 #include "third_party/skia/include/core/SkSurface.h" 39 #include "third_party/skia/include/core/SkSurface.h"
40 #include "third_party/skia/include/core/SkSwizzle.h" 40 #include "third_party/skia/include/core/SkSwizzle.h"
41 41
42 using ::testing::Mock; 42 using ::testing::Mock;
43 43
44 namespace blink { 44 namespace blink {
45 45
46 namespace {
47
48 gfx::ColorSpace AdobeRGBColorSpace() {
49 return gfx::ColorSpace(gfx::ColorSpace::PrimaryID::ADOBE_RGB,
50 gfx::ColorSpace::TransferID::GAMMA22);
51 }
52
53 } // namespace
54
55 enum BitmapOpacity { kOpaqueBitmap, kTransparentBitmap }; 46 enum BitmapOpacity { kOpaqueBitmap, kTransparentBitmap };
56 47
57 class FakeImageSource : public CanvasImageSource { 48 class FakeImageSource : public CanvasImageSource {
58 public: 49 public:
59 FakeImageSource(IntSize, BitmapOpacity); 50 FakeImageSource(IntSize, BitmapOpacity);
60 51
61 PassRefPtr<Image> GetSourceImageForCanvas(SourceImageStatus*, 52 PassRefPtr<Image> GetSourceImageForCanvas(SourceImageStatus*,
62 AccelerationHint, 53 AccelerationHint,
63 SnapshotReason, 54 SnapshotReason,
64 const FloatSize&) override; 55 const FloatSize&) override;
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 CanvasElement().GetImageBuffer()->DisableAcceleration(); 1100 CanvasElement().GetImageBuffer()->DisableAcceleration();
1110 EXPECT_FALSE(CanvasElement().GetImageBuffer()->IsAccelerated()); 1101 EXPECT_FALSE(CanvasElement().GetImageBuffer()->IsAccelerated());
1111 1102
1112 context->fillRect(10, 10, 100, 100); 1103 context->fillRect(10, 10, 100, 100);
1113 1104
1114 EXPECT_EQ(0, GetCurrentGPUMemoryUsage()); 1105 EXPECT_EQ(0, GetCurrentGPUMemoryUsage());
1115 EXPECT_EQ(0, GetGlobalGPUMemoryUsage()); 1106 EXPECT_EQ(0, GetGlobalGPUMemoryUsage());
1116 EXPECT_EQ(0u, GetGlobalAcceleratedImageBufferCount()); 1107 EXPECT_EQ(0u, GetGlobalAcceleratedImageBufferCount());
1117 } 1108 }
1118 1109
1119 TEST_F(CanvasRenderingContext2DTest,
1120 LegacyColorSpaceUsesGlobalTargetColorBehavior) {
1121 // Set the global target color space to something distinctly recognizable (not
1122 // srgb)
1123 gfx::ColorSpace saved_global_target_color_space =
1124 ColorBehavior::GlobalTargetColorSpace();
1125 ColorBehavior::SetGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace());
1126 bool saved_color_correct_rendering_enabled =
1127 RuntimeEnabledFeatures::colorCorrectRenderingEnabled();
1128
1129 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(false);
1130 CreateContext(kNonOpaque, "legacy-srgb");
1131 ColorBehavior behavior = Context2d()->DrawImageColorBehavior();
1132 EXPECT_TRUE(behavior.IsTransformToTargetColorSpace());
1133 EXPECT_TRUE(ColorBehavior::GlobalTargetColorSpace() ==
1134 behavior.TargetColorSpace());
1135
1136 // Restore global state to avoid interfering with other tests
1137 ColorBehavior::SetGlobalTargetColorSpaceForTesting(
1138 saved_global_target_color_space);
1139 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(
1140 saved_color_correct_rendering_enabled);
1141 }
1142
1143 TEST_F(CanvasRenderingContext2DTest,
1144 LegacyColorSpaceUsesSRGBWhenColorCorrectRenderingEnabled) {
1145 // Set the global target color space to something distinctly recognizable (not
1146 // srgb)
1147 gfx::ColorSpace saved_global_target_color_space =
1148 ColorBehavior::GlobalTargetColorSpace();
1149 ColorBehavior::SetGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace());
1150 bool saved_color_correct_rendering_enabled =
1151 RuntimeEnabledFeatures::colorCorrectRenderingEnabled();
1152
1153 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(true);
1154 CreateContext(kNonOpaque, "legacy-srgb");
1155 ColorBehavior behavior = Context2d()->DrawImageColorBehavior();
1156 EXPECT_TRUE(behavior.IsTransformToTargetColorSpace());
1157 EXPECT_TRUE(gfx::ColorSpace::CreateSRGB() == behavior.TargetColorSpace());
1158
1159 // Restore global state to avoid interfering with other tests
1160 ColorBehavior::SetGlobalTargetColorSpaceForTesting(
1161 saved_global_target_color_space);
1162 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(
1163 saved_color_correct_rendering_enabled);
1164 }
1165
1166 TEST_F(CanvasRenderingContext2DTest,
Justin Novosad 2017/05/23 19:20:28 Why is this test being removed?
ccameron 2017/05/23 19:23:49 This is testing DrawImageColorBehavior(), but that
1167 SRGBColorSpaceUsesTransformToSRGBColorBehavior) {
1168 // Set the global target color space to something distinctly recognizable (not
1169 // srgb)
1170 gfx::ColorSpace saved_global_target_color_space =
1171 ColorBehavior::GlobalTargetColorSpace();
1172 ColorBehavior::SetGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace());
1173
1174 CreateContext(kNonOpaque, "srgb");
1175 ColorBehavior behavior = Context2d()->DrawImageColorBehavior();
1176 EXPECT_TRUE(behavior.IsTransformToTargetColorSpace());
1177 EXPECT_TRUE(gfx::ColorSpace::CreateSRGB() == behavior.TargetColorSpace());
1178
1179 // Restore global state to avoid interfering with other tests
1180 ColorBehavior::SetGlobalTargetColorSpaceForTesting(
1181 saved_global_target_color_space);
1182 }
1183
1184 TEST_F(CanvasRenderingContext2DTest,
Justin Novosad 2017/05/23 19:20:28 and this one?
ccameron 2017/05/23 19:23:49 (same deal -- the behavior will be always be "tag"
1185 LinearRGBColorSpaceUsesTransformToLinearSRGBColorBehavior) {
1186 // Set the global target color space to something distinctly recognizable (not
1187 // srgb)
1188 gfx::ColorSpace saved_global_target_color_space =
1189 ColorBehavior::GlobalTargetColorSpace();
1190 ColorBehavior::SetGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace());
1191
1192 CreateContext(kNonOpaque, "srgb", kLinearPixelMathEnabled);
1193 ColorBehavior behavior = Context2d()->DrawImageColorBehavior();
1194 EXPECT_TRUE(behavior.IsTransformToTargetColorSpace());
1195 EXPECT_TRUE(gfx::ColorSpace::CreateSCRGBLinear() ==
1196 behavior.TargetColorSpace());
1197
1198 // Restore global state to avoid interfering with other tests
1199 ColorBehavior::SetGlobalTargetColorSpaceForTesting(
1200 saved_global_target_color_space);
1201 }
1202
1203 enum class ColorSpaceConversion : uint8_t { 1110 enum class ColorSpaceConversion : uint8_t {
1204 NONE = 0, 1111 NONE = 0,
1205 DEFAULT_NOT_COLOR_CORRECTED = 1, 1112 DEFAULT_NOT_COLOR_CORRECTED = 1,
1206 DEFAULT_COLOR_CORRECTED = 2, 1113 DEFAULT_COLOR_CORRECTED = 2,
1207 SRGB = 3, 1114 SRGB = 3,
1208 LINEAR_RGB = 4, 1115 LINEAR_RGB = 4,
1209 1116
1210 LAST = LINEAR_RGB 1117 LAST = LINEAR_RGB
1211 }; 1118 };
1212 1119
1213 static ImageBitmapOptions PrepareBitmapOptionsAndSetRuntimeFlags( 1120 static ImageBitmapOptions PrepareBitmapOptionsAndSetRuntimeFlags(
1214 const ColorSpaceConversion& color_space_conversion) { 1121 const ColorSpaceConversion& color_space_conversion) {
1215 // Set the color space conversion in ImageBitmapOptions 1122 // Set the color space conversion in ImageBitmapOptions
1216 ImageBitmapOptions options; 1123 ImageBitmapOptions options;
1217 static const Vector<String> kConversions = {"none", "default", "default", 1124 static const Vector<String> kConversions = {"none", "default", "default",
1218 "srgb", "linear-rgb"}; 1125 "srgb", "linear-rgb"};
1219 options.setColorSpaceConversion( 1126 options.setColorSpaceConversion(
1220 kConversions[static_cast<uint8_t>(color_space_conversion)]); 1127 kConversions[static_cast<uint8_t>(color_space_conversion)]);
1221 1128
1222 // Set the runtime flags 1129 // Set the runtime flags
1223 bool flag = (color_space_conversion != 1130 bool flag = (color_space_conversion !=
1224 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); 1131 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED);
1225 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(true); 1132 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(true);
1226 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(flag); 1133 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(flag);
1227 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled(!flag);
1228 1134
1229 return options; 1135 return options;
1230 } 1136 }
1231 1137
1232 TEST_F(CanvasRenderingContext2DTest, ImageBitmapColorSpaceConversion) { 1138 TEST_F(CanvasRenderingContext2DTest, ImageBitmapColorSpaceConversion) {
1233 bool experimental_canvas_features_runtime_flag = 1139 bool experimental_canvas_features_runtime_flag =
1234 RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); 1140 RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled();
1235 bool color_correct_rendering_runtime_flag = 1141 bool color_correct_rendering_runtime_flag =
1236 RuntimeEnabledFeatures::colorCorrectRenderingEnabled(); 1142 RuntimeEnabledFeatures::colorCorrectRenderingEnabled();
1237 bool color_correct_rendering_default_mode_runtime_flag =
1238 RuntimeEnabledFeatures::colorCorrectRenderingDefaultModeEnabled();
1239 1143
1240 Persistent<HTMLCanvasElement> canvas = 1144 Persistent<HTMLCanvasElement> canvas =
1241 Persistent<HTMLCanvasElement>(CanvasElement()); 1145 Persistent<HTMLCanvasElement>(CanvasElement());
1242 CanvasContextCreationAttributes attributes; 1146 CanvasContextCreationAttributes attributes;
1243 attributes.setAlpha(true); 1147 attributes.setAlpha(true);
1244 attributes.setColorSpace("srgb"); 1148 attributes.setColorSpace("srgb");
1245 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>( 1149 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(
1246 canvas->GetCanvasRenderingContext("2d", attributes)); 1150 canvas->GetCanvasRenderingContext("2d", attributes));
1247 StringOrCanvasGradientOrCanvasPattern fill_style; 1151 StringOrCanvasGradientOrCanvasPattern fill_style;
1248 fill_style.setString("#FF0000"); 1152 fill_style.setString("#FF0000");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 1223
1320 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(), 1224 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(),
1321 image_info.bytesPerPixel()); 1225 image_info.bytesPerPixel());
1322 ASSERT_EQ(compare, 0); 1226 ASSERT_EQ(compare, 0);
1323 } 1227 }
1324 1228
1325 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( 1229 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(
1326 experimental_canvas_features_runtime_flag); 1230 experimental_canvas_features_runtime_flag);
1327 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( 1231 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(
1328 color_correct_rendering_runtime_flag); 1232 color_correct_rendering_runtime_flag);
1329 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled(
1330 color_correct_rendering_default_mode_runtime_flag);
1331 } 1233 }
1332 1234
1333 bool ConvertPixelsToColorSpaceAndPixelFormatForTest( 1235 bool ConvertPixelsToColorSpaceAndPixelFormatForTest(
1334 DOMArrayBufferView* data_array, 1236 DOMArrayBufferView* data_array,
1335 CanvasColorSpace src_color_space, 1237 CanvasColorSpace src_color_space,
1336 CanvasColorSpace dst_color_space, 1238 CanvasColorSpace dst_color_space,
1337 CanvasPixelFormat dst_pixel_format, 1239 CanvasPixelFormat dst_pixel_format,
1338 std::unique_ptr<uint8_t[]>& converted_pixels) { 1240 std::unique_ptr<uint8_t[]>& converted_pixels) {
1339 // Setting SkColorSpaceXform::apply parameters 1241 // Setting SkColorSpaceXform::apply parameters
1340 SkColorSpaceXform::ColorFormat src_color_format = 1242 SkColorSpaceXform::ColorFormat src_color_format =
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 1587
1686 // Wake up again, which should request a compositing update synchronously. 1588 // Wake up again, which should request a compositing update synchronously.
1687 GetDocument().GetPage()->SetVisibilityState(kPageVisibilityStateVisible, 1589 GetDocument().GetPage()->SetVisibilityState(kPageVisibilityStateVisible,
1688 false); 1590 false);
1689 EXPECT_EQ(!!CANVAS2D_HIBERNATION_ENABLED, 1591 EXPECT_EQ(!!CANVAS2D_HIBERNATION_ENABLED,
1690 layer->NeedsCompositingInputsUpdate()); 1592 layer->NeedsCompositingInputsUpdate());
1691 RunUntilIdle(); // Clear task queue. 1593 RunUntilIdle(); // Clear task queue.
1692 } 1594 }
1693 1595
1694 } // namespace blink 1596 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698