| 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 "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/ImageBitmap.h" | 10 #include "core/frame/ImageBitmap.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 DEFINE_INLINE_TRACE() { | 128 DEFINE_INLINE_TRACE() { |
| 129 visitor->trace(m_opaqueGradient); | 129 visitor->trace(m_opaqueGradient); |
| 130 visitor->trace(m_alphaGradient); | 130 visitor->trace(m_alphaGradient); |
| 131 } | 131 } |
| 132 | 132 |
| 133 StringOrCanvasGradientOrCanvasPattern m_opaqueGradient; | 133 StringOrCanvasGradientOrCanvasPattern m_opaqueGradient; |
| 134 StringOrCanvasGradientOrCanvasPattern m_alphaGradient; | 134 StringOrCanvasGradientOrCanvasPattern m_alphaGradient; |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // TODO(Oilpan): avoid tedious part-object wrapper by supporting on-heap ::tes
ting::Tests. | 137 // TODO(Oilpan): avoid tedious part-object wrapper by supporting on-heap |
| 138 // ::testing::Tests. |
| 138 Persistent<WrapGradients> m_wrapGradients; | 139 Persistent<WrapGradients> m_wrapGradients; |
| 139 | 140 |
| 140 protected: | 141 protected: |
| 141 // Pre-canned objects for testing | 142 // Pre-canned objects for testing |
| 142 Persistent<ImageData> m_fullImageData; | 143 Persistent<ImageData> m_fullImageData; |
| 143 Persistent<ImageData> m_partialImageData; | 144 Persistent<ImageData> m_partialImageData; |
| 144 FakeImageSource m_opaqueBitmap; | 145 FakeImageSource m_opaqueBitmap; |
| 145 FakeImageSource m_alphaBitmap; | 146 FakeImageSource m_alphaBitmap; |
| 146 | 147 |
| 147 StringOrCanvasGradientOrCanvasPattern& opaqueGradient() { | 148 StringOrCanvasGradientOrCanvasPattern& opaqueGradient() { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 TEST_OVERDRAW_3(1, rect(0, 0, 5, 5), clip(), | 475 TEST_OVERDRAW_3(1, rect(0, 0, 5, 5), clip(), |
| 475 putImageData(m_fullImageData.get(), 0, 0, | 476 putImageData(m_fullImageData.get(), 0, 0, |
| 476 exceptionState)); // ignores clip | 477 exceptionState)); // ignores clip |
| 477 EXPECT_FALSE(exceptionState.hadException()); | 478 EXPECT_FALSE(exceptionState.hadException()); |
| 478 } | 479 } |
| 479 | 480 |
| 480 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithCompositeOperations) { | 481 TEST_F(CanvasRenderingContext2DTest, detectOverdrawWithCompositeOperations) { |
| 481 createContext(NonOpaque); | 482 createContext(NonOpaque); |
| 482 | 483 |
| 483 // Test composite operators with an opaque rect that covers the entire canvas | 484 // Test composite operators with an opaque rect that covers the entire canvas |
| 484 // Note: all the untested composite operations take the same code path as sour
ce-in, | 485 // Note: all the untested composite operations take the same code path as |
| 485 // which assumes that the destination may not be overwritten | 486 // source-in, which assumes that the destination may not be overwritten |
| 486 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("clear")), | 487 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("clear")), |
| 487 fillRect(0, 0, 10, 10)); | 488 fillRect(0, 0, 10, 10)); |
| 488 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), | 489 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), |
| 489 fillRect(0, 0, 10, 10)); | 490 fillRect(0, 0, 10, 10)); |
| 490 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("source-over")), | 491 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("source-over")), |
| 491 fillRect(0, 0, 10, 10)); | 492 fillRect(0, 0, 10, 10)); |
| 492 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), | 493 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), |
| 493 fillRect(0, 0, 10, 10)); | 494 fillRect(0, 0, 10, 10)); |
| 494 // Test composite operators with a transparent rect that covers the entire can
vas | 495 // Test composite operators with a transparent rect that covers the entire |
| 496 // canvas |
| 495 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), | 497 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), |
| 496 setGlobalCompositeOperation(String("clear")), | 498 setGlobalCompositeOperation(String("clear")), |
| 497 fillRect(0, 0, 10, 10)); | 499 fillRect(0, 0, 10, 10)); |
| 498 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), | 500 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), |
| 499 setGlobalCompositeOperation(String("copy")), | 501 setGlobalCompositeOperation(String("copy")), |
| 500 fillRect(0, 0, 10, 10)); | 502 fillRect(0, 0, 10, 10)); |
| 501 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), | 503 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), |
| 502 setGlobalCompositeOperation(String("source-over")), | 504 setGlobalCompositeOperation(String("source-over")), |
| 503 fillRect(0, 0, 10, 10)); | 505 fillRect(0, 0, 10, 10)); |
| 504 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), | 506 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), |
| 505 setGlobalCompositeOperation(String("source-in")), | 507 setGlobalCompositeOperation(String("source-in")), |
| 506 fillRect(0, 0, 10, 10)); | 508 fillRect(0, 0, 10, 10)); |
| 507 // Test composite operators with an opaque rect that does not cover the entire
canvas | 509 // Test composite operators with an opaque rect that does not cover the entire |
| 510 // canvas |
| 508 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("clear")), | 511 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("clear")), |
| 509 fillRect(0, 0, 5, 5)); | 512 fillRect(0, 0, 5, 5)); |
| 510 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), | 513 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), |
| 511 fillRect(0, 0, 5, 5)); | 514 fillRect(0, 0, 5, 5)); |
| 512 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), | 515 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), |
| 513 fillRect(0, 0, 5, 5)); | 516 fillRect(0, 0, 5, 5)); |
| 514 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), | 517 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), |
| 515 fillRect(0, 0, 5, 5)); | 518 fillRect(0, 0, 5, 5)); |
| 516 } | 519 } |
| 517 | 520 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 createContext(NonOpaque); | 890 createContext(NonOpaque); |
| 888 | 891 |
| 889 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 892 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
| 890 fakeAccelerateSurface = | 893 fakeAccelerateSurface = |
| 891 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 894 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
| 892 IntSize(10, 10), NonOpaque)); | 895 IntSize(10, 10), NonOpaque)); |
| 893 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = | 896 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = |
| 894 fakeAccelerateSurface.get(); | 897 fakeAccelerateSurface.get(); |
| 895 canvasElement().createImageBufferUsingSurfaceForTesting( | 898 canvasElement().createImageBufferUsingSurfaceForTesting( |
| 896 std::move(fakeAccelerateSurface)); | 899 std::move(fakeAccelerateSurface)); |
| 897 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per pix
el per buffer, | 900 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per |
| 898 // and 2 is an estimate of num of gpu buffers required | 901 // pixel per buffer, and 2 is an estimate of num of gpu buffers required |
| 899 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 902 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 900 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 903 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
| 901 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 904 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 902 | 905 |
| 903 // Switching accelerated mode to non-accelerated mode | 906 // Switching accelerated mode to non-accelerated mode |
| 904 fakeAccelerateSurfacePtr->setIsAccelerated(false); | 907 fakeAccelerateSurfacePtr->setIsAccelerated(false); |
| 905 canvasElement().buffer()->updateGPUMemoryUsage(); | 908 canvasElement().buffer()->updateGPUMemoryUsage(); |
| 906 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 909 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
| 907 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 910 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 908 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 911 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 createContext(NonOpaque); | 1105 createContext(NonOpaque); |
| 1103 | 1106 |
| 1104 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 1107 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
| 1105 fakeAccelerateSurface = | 1108 fakeAccelerateSurface = |
| 1106 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 1109 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
| 1107 IntSize(10, 10), NonOpaque)); | 1110 IntSize(10, 10), NonOpaque)); |
| 1108 canvasElement().createImageBufferUsingSurfaceForTesting( | 1111 canvasElement().createImageBufferUsingSurfaceForTesting( |
| 1109 std::move(fakeAccelerateSurface)); | 1112 std::move(fakeAccelerateSurface)); |
| 1110 CanvasRenderingContext2D* context = context2d(); | 1113 CanvasRenderingContext2D* context = context2d(); |
| 1111 | 1114 |
| 1112 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per pix
el per buffer, | 1115 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per |
| 1113 // and 2 is an estimate of num of gpu buffers required | 1116 // pixel per buffer, and 2 is an estimate of num of gpu buffers required |
| 1114 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 1117 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 1115 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 1118 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
| 1116 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 1119 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 1117 | 1120 |
| 1118 context->fillRect(10, 10, 100, 100); | 1121 context->fillRect(10, 10, 100, 100); |
| 1119 EXPECT_TRUE(canvasElement().buffer()->isAccelerated()); | 1122 EXPECT_TRUE(canvasElement().buffer()->isAccelerated()); |
| 1120 | 1123 |
| 1121 canvasElement().buffer()->disableAcceleration(); | 1124 canvasElement().buffer()->disableAcceleration(); |
| 1122 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); | 1125 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); |
| 1123 | 1126 |
| 1124 context->fillRect(10, 10, 100, 100); | 1127 context->fillRect(10, 10, 100, 100); |
| 1125 | 1128 |
| 1126 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 1129 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
| 1127 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 1130 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 1128 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 1131 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
| 1129 } | 1132 } |
| 1130 | 1133 |
| 1131 } // namespace blink | 1134 } // namespace blink |
| OLD | NEW |