Chromium Code Reviews| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 intptr_t getGlobalGPUMemoryUsage() const { | 112 intptr_t getGlobalGPUMemoryUsage() const { |
| 113 return ImageBuffer::getGlobalGPUMemoryUsage(); | 113 return ImageBuffer::getGlobalGPUMemoryUsage(); |
| 114 } | 114 } |
| 115 unsigned getGlobalAcceleratedImageBufferCount() const { | 115 unsigned getGlobalAcceleratedImageBufferCount() const { |
| 116 return ImageBuffer::getGlobalAcceleratedImageBufferCount(); | 116 return ImageBuffer::getGlobalAcceleratedImageBufferCount(); |
| 117 } | 117 } |
| 118 intptr_t getCurrentGPUMemoryUsage() const { | 118 intptr_t getCurrentGPUMemoryUsage() const { |
| 119 return canvasElement().buffer()->getGPUMemoryUsage(); | 119 return canvasElement().buffer()->getGPUMemoryUsage(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void createContext(OpacityMode, String colorSpace = String()); | 122 void createContext(OpacityMode, |
| 123 String colorSpace = String(), | |
| 124 bool useF16 = false); | |
|
Justin Novosad
2017/02/23 18:48:13
Better to use an enum than a bool for this. Makes
zakerinasab
2017/02/23 20:22:33
Done.
| |
| 123 ScriptState* getScriptState() { | 125 ScriptState* getScriptState() { |
| 124 return ScriptState::forMainWorld(m_canvasElement->frame()); | 126 return ScriptState::forMainWorld(m_canvasElement->frame()); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void TearDown(); | 129 void TearDown(); |
| 128 void unrefCanvas(); | 130 void unrefCanvas(); |
| 129 PassRefPtr<Canvas2DLayerBridge> makeBridge( | 131 PassRefPtr<Canvas2DLayerBridge> makeBridge( |
| 130 std::unique_ptr<FakeWebGraphicsContext3DProvider>, | 132 std::unique_ptr<FakeWebGraphicsContext3DProvider>, |
| 131 const IntSize&, | 133 const IntSize&, |
| 132 Canvas2DLayerBridge::AccelerationMode); | 134 Canvas2DLayerBridge::AccelerationMode); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 return m_wrapGradients->m_alphaGradient; | 170 return m_wrapGradients->m_alphaGradient; |
| 169 } | 171 } |
| 170 }; | 172 }; |
| 171 | 173 |
| 172 CanvasRenderingContext2DTest::CanvasRenderingContext2DTest() | 174 CanvasRenderingContext2DTest::CanvasRenderingContext2DTest() |
| 173 : m_wrapGradients(WrapGradients::create()), | 175 : m_wrapGradients(WrapGradients::create()), |
| 174 m_opaqueBitmap(IntSize(10, 10), OpaqueBitmap), | 176 m_opaqueBitmap(IntSize(10, 10), OpaqueBitmap), |
| 175 m_alphaBitmap(IntSize(10, 10), TransparentBitmap) {} | 177 m_alphaBitmap(IntSize(10, 10), TransparentBitmap) {} |
| 176 | 178 |
| 177 void CanvasRenderingContext2DTest::createContext(OpacityMode opacityMode, | 179 void CanvasRenderingContext2DTest::createContext(OpacityMode opacityMode, |
| 178 String colorSpace) { | 180 String colorSpace, |
| 181 bool useF16) { | |
| 179 String canvasType("2d"); | 182 String canvasType("2d"); |
| 180 CanvasContextCreationAttributes attributes; | 183 CanvasContextCreationAttributes attributes; |
| 181 attributes.setAlpha(opacityMode == NonOpaque); | 184 attributes.setAlpha(opacityMode == NonOpaque); |
| 182 if (!colorSpace.isEmpty()) | 185 if (!colorSpace.isEmpty()) { |
| 183 attributes.setColorSpace(colorSpace); | 186 attributes.setColorSpace(colorSpace); |
| 187 if (useF16) { | |
| 188 attributes.setPixelFormat("float16"); | |
| 189 attributes.setLinearPixelMath(true); | |
| 190 } | |
| 191 } | |
| 184 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); | 192 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); |
| 185 } | 193 } |
| 186 | 194 |
| 187 void CanvasRenderingContext2DTest::SetUp() { | 195 void CanvasRenderingContext2DTest::SetUp() { |
| 188 Page::PageClients pageClients; | 196 Page::PageClients pageClients; |
| 189 fillWithEmptyClients(pageClients); | 197 fillWithEmptyClients(pageClients); |
| 190 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients); | 198 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients); |
| 191 m_document = &m_dummyPageHolder->document(); | 199 m_document = &m_dummyPageHolder->document(); |
| 192 m_document->documentElement()->setInnerHTML( | 200 m_document->documentElement()->setInnerHTML( |
| 193 "<body><canvas id='c'></canvas></body>"); | 201 "<body><canvas id='c'></canvas></body>"); |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1218 } | 1226 } |
| 1219 | 1227 |
| 1220 TEST_F(CanvasRenderingContext2DTest, | 1228 TEST_F(CanvasRenderingContext2DTest, |
| 1221 LinearRGBColorSpaceUsesTransformToLinearSRGBColorBehavior) { | 1229 LinearRGBColorSpaceUsesTransformToLinearSRGBColorBehavior) { |
| 1222 // Set the global target color space to something distinctly recognizable (not | 1230 // Set the global target color space to something distinctly recognizable (not |
| 1223 // srgb) | 1231 // srgb) |
| 1224 gfx::ColorSpace savedGlobalTargetColorSpace = | 1232 gfx::ColorSpace savedGlobalTargetColorSpace = |
| 1225 ColorBehavior::globalTargetColorSpace(); | 1233 ColorBehavior::globalTargetColorSpace(); |
| 1226 ColorBehavior::setGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace()); | 1234 ColorBehavior::setGlobalTargetColorSpaceForTesting(AdobeRGBColorSpace()); |
| 1227 | 1235 |
| 1228 createContext(NonOpaque, "linear-rgb"); | 1236 createContext(NonOpaque, "srgb", true); |
| 1229 ColorBehavior behavior = context2d()->drawImageColorBehavior(); | 1237 ColorBehavior behavior = context2d()->drawImageColorBehavior(); |
| 1230 EXPECT_TRUE(behavior.isTransformToTargetColorSpace()); | 1238 EXPECT_TRUE(behavior.isTransformToTargetColorSpace()); |
| 1231 EXPECT_TRUE(gfx::ColorSpace::CreateSCRGBLinear() == | 1239 EXPECT_TRUE(gfx::ColorSpace::CreateSCRGBLinear() == |
| 1232 behavior.targetColorSpace()); | 1240 behavior.targetColorSpace()); |
| 1233 | 1241 |
| 1234 // Restore global state to avoid interfering with other tests | 1242 // Restore global state to avoid interfering with other tests |
| 1235 ColorBehavior::setGlobalTargetColorSpaceForTesting( | 1243 ColorBehavior::setGlobalTargetColorSpaceForTesting( |
| 1236 savedGlobalTargetColorSpace); | 1244 savedGlobalTargetColorSpace); |
| 1237 } | 1245 } |
| 1238 | 1246 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1365 | 1373 |
| 1366 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( | 1374 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( |
| 1367 experimentalCanvasFeaturesRuntimeFlag); | 1375 experimentalCanvasFeaturesRuntimeFlag); |
| 1368 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( | 1376 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( |
| 1369 colorCorrectRenderingRuntimeFlag); | 1377 colorCorrectRenderingRuntimeFlag); |
| 1370 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( | 1378 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( |
| 1371 colorCorrectRenderingDefaultModeRuntimeFlag); | 1379 colorCorrectRenderingDefaultModeRuntimeFlag); |
| 1372 } | 1380 } |
| 1373 | 1381 |
| 1374 } // namespace blink | 1382 } // namespace blink |
| OLD | NEW |