| OLD | NEW |
| 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/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 AccelerationHint, | 90 AccelerationHint, |
| 91 SnapshotReason, | 91 SnapshotReason, |
| 92 const FloatSize&) const { | 92 const FloatSize&) const { |
| 93 if (status) | 93 if (status) |
| 94 *status = NormalSourceImageStatus; | 94 *status = NormalSourceImageStatus; |
| 95 return m_image; | 95 return m_image; |
| 96 } | 96 } |
| 97 | 97 |
| 98 //============================================================================ | 98 //============================================================================ |
| 99 | 99 |
| 100 enum LinearPixelMathState { LinearPixelMathDisabled, LinearPixelMathEnabled }; |
| 101 |
| 100 class CanvasRenderingContext2DTest : public ::testing::Test { | 102 class CanvasRenderingContext2DTest : public ::testing::Test { |
| 101 protected: | 103 protected: |
| 102 CanvasRenderingContext2DTest(); | 104 CanvasRenderingContext2DTest(); |
| 103 void SetUp() override; | 105 void SetUp() override; |
| 104 | 106 |
| 105 DummyPageHolder& page() const { return *m_dummyPageHolder; } | 107 DummyPageHolder& page() const { return *m_dummyPageHolder; } |
| 106 Document& document() const { return *m_document; } | 108 Document& document() const { return *m_document; } |
| 107 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } | 109 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } |
| 108 CanvasRenderingContext2D* context2d() const { | 110 CanvasRenderingContext2D* context2d() const { |
| 109 return static_cast<CanvasRenderingContext2D*>( | 111 return static_cast<CanvasRenderingContext2D*>( |
| 110 canvasElement().renderingContext()); | 112 canvasElement().renderingContext()); |
| 111 } | 113 } |
| 112 intptr_t getGlobalGPUMemoryUsage() const { | 114 intptr_t getGlobalGPUMemoryUsage() const { |
| 113 return ImageBuffer::getGlobalGPUMemoryUsage(); | 115 return ImageBuffer::getGlobalGPUMemoryUsage(); |
| 114 } | 116 } |
| 115 unsigned getGlobalAcceleratedImageBufferCount() const { | 117 unsigned getGlobalAcceleratedImageBufferCount() const { |
| 116 return ImageBuffer::getGlobalAcceleratedImageBufferCount(); | 118 return ImageBuffer::getGlobalAcceleratedImageBufferCount(); |
| 117 } | 119 } |
| 118 intptr_t getCurrentGPUMemoryUsage() const { | 120 intptr_t getCurrentGPUMemoryUsage() const { |
| 119 return canvasElement().buffer()->getGPUMemoryUsage(); | 121 return canvasElement().buffer()->getGPUMemoryUsage(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void createContext(OpacityMode, String colorSpace = String()); | 124 void createContext(OpacityMode, |
| 125 String colorSpace = String(), |
| 126 LinearPixelMathState = LinearPixelMathDisabled); |
| 123 ScriptState* getScriptState() { | 127 ScriptState* getScriptState() { |
| 124 return ScriptState::forMainWorld(m_canvasElement->frame()); | 128 return ScriptState::forMainWorld(m_canvasElement->frame()); |
| 125 } | 129 } |
| 126 | 130 |
| 127 void TearDown(); | 131 void TearDown(); |
| 128 void unrefCanvas(); | 132 void unrefCanvas(); |
| 129 PassRefPtr<Canvas2DLayerBridge> makeBridge( | 133 PassRefPtr<Canvas2DLayerBridge> makeBridge( |
| 130 std::unique_ptr<FakeWebGraphicsContext3DProvider>, | 134 std::unique_ptr<FakeWebGraphicsContext3DProvider>, |
| 131 const IntSize&, | 135 const IntSize&, |
| 132 Canvas2DLayerBridge::AccelerationMode); | 136 Canvas2DLayerBridge::AccelerationMode); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 StringOrCanvasGradientOrCanvasPattern& alphaGradient() { | 171 StringOrCanvasGradientOrCanvasPattern& alphaGradient() { |
| 168 return m_wrapGradients->m_alphaGradient; | 172 return m_wrapGradients->m_alphaGradient; |
| 169 } | 173 } |
| 170 }; | 174 }; |
| 171 | 175 |
| 172 CanvasRenderingContext2DTest::CanvasRenderingContext2DTest() | 176 CanvasRenderingContext2DTest::CanvasRenderingContext2DTest() |
| 173 : m_wrapGradients(WrapGradients::create()), | 177 : m_wrapGradients(WrapGradients::create()), |
| 174 m_opaqueBitmap(IntSize(10, 10), OpaqueBitmap), | 178 m_opaqueBitmap(IntSize(10, 10), OpaqueBitmap), |
| 175 m_alphaBitmap(IntSize(10, 10), TransparentBitmap) {} | 179 m_alphaBitmap(IntSize(10, 10), TransparentBitmap) {} |
| 176 | 180 |
| 177 void CanvasRenderingContext2DTest::createContext(OpacityMode opacityMode, | 181 void CanvasRenderingContext2DTest::createContext( |
| 178 String colorSpace) { | 182 OpacityMode opacityMode, |
| 183 String colorSpace, |
| 184 LinearPixelMathState linearPixelMathState) { |
| 179 String canvasType("2d"); | 185 String canvasType("2d"); |
| 180 CanvasContextCreationAttributes attributes; | 186 CanvasContextCreationAttributes attributes; |
| 181 attributes.setAlpha(opacityMode == NonOpaque); | 187 attributes.setAlpha(opacityMode == NonOpaque); |
| 182 if (!colorSpace.isEmpty()) | 188 if (!colorSpace.isEmpty()) { |
| 183 attributes.setColorSpace(colorSpace); | 189 attributes.setColorSpace(colorSpace); |
| 190 if (linearPixelMathState == LinearPixelMathEnabled) { |
| 191 attributes.setPixelFormat("float16"); |
| 192 attributes.setLinearPixelMath(true); |
| 193 } |
| 194 } |
| 184 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); | 195 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); |
| 185 } | 196 } |
| 186 | 197 |
| 187 void CanvasRenderingContext2DTest::SetUp() { | 198 void CanvasRenderingContext2DTest::SetUp() { |
| 188 Page::PageClients pageClients; | 199 Page::PageClients pageClients; |
| 189 fillWithEmptyClients(pageClients); | 200 fillWithEmptyClients(pageClients); |
| 190 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients); | 201 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients); |
| 191 m_document = &m_dummyPageHolder->document(); | 202 m_document = &m_dummyPageHolder->document(); |
| 192 m_document->documentElement()->setInnerHTML( | 203 m_document->documentElement()->setInnerHTML( |
| 193 "<body><canvas id='c'></canvas></body>"); | 204 "<body><canvas id='c'></canvas></body>"); |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 } | 1229 } |
| 1219 | 1230 |
| 1220 TEST_F(CanvasRenderingContext2DTest, | 1231 TEST_F(CanvasRenderingContext2DTest, |
| 1221 LinearRGBColorSpaceUsesTransformToLinearSRGBColorBehavior) { | 1232 LinearRGBColorSpaceUsesTransformToLinearSRGBColorBehavior) { |
| 1222 // Set the global target color space to something distinctly recognizable (not | 1233 // Set the global target color space to something distinctly recognizable (not |
| 1223 // srgb) | 1234 // srgb) |
| 1224 gfx::ColorSpace savedGlobalTargetColorSpace = | 1235 gfx::ColorSpace savedGlobalTargetColorSpace = |
| 1225 ColorBehavior::globalTargetColorSpace(); | 1236 ColorBehavior::globalTargetColorSpace(); |
| 1226 ColorBehavior::setGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace()); | 1237 ColorBehavior::setGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace()); |
| 1227 | 1238 |
| 1228 createContext(NonOpaque, "linear-rgb"); | 1239 createContext(NonOpaque, "srgb", LinearPixelMathEnabled); |
| 1229 ColorBehavior behavior = context2d()->drawImageColorBehavior(); | 1240 ColorBehavior behavior = context2d()->drawImageColorBehavior(); |
| 1230 EXPECT_TRUE(behavior.isTransformToTargetColorSpace()); | 1241 EXPECT_TRUE(behavior.isTransformToTargetColorSpace()); |
| 1231 EXPECT_TRUE(gfx::ColorSpace::CreateSCRGBLinear() == | 1242 EXPECT_TRUE(gfx::ColorSpace::CreateSCRGBLinear() == |
| 1232 behavior.targetColorSpace()); | 1243 behavior.targetColorSpace()); |
| 1233 | 1244 |
| 1234 // Restore global state to avoid interfering with other tests | 1245 // Restore global state to avoid interfering with other tests |
| 1235 ColorBehavior::setGlobalTargetColorSpaceForTesting( | 1246 ColorBehavior::setGlobalTargetColorSpaceForTesting( |
| 1236 savedGlobalTargetColorSpace); | 1247 savedGlobalTargetColorSpace); |
| 1237 } | 1248 } |
| 1238 | 1249 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 | 1376 |
| 1366 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( | 1377 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( |
| 1367 experimentalCanvasFeaturesRuntimeFlag); | 1378 experimentalCanvasFeaturesRuntimeFlag); |
| 1368 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( | 1379 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( |
| 1369 colorCorrectRenderingRuntimeFlag); | 1380 colorCorrectRenderingRuntimeFlag); |
| 1370 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( | 1381 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( |
| 1371 colorCorrectRenderingDefaultModeRuntimeFlag); | 1382 colorCorrectRenderingDefaultModeRuntimeFlag); |
| 1372 } | 1383 } |
| 1373 | 1384 |
| 1374 } // namespace blink | 1385 } // namespace blink |
| OLD | NEW |