| 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 |
| 486 // source-in, |
| 485 // which assumes that the destination may not be overwritten | 487 // which assumes that the destination may not be overwritten |
| 486 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("clear")), | 488 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("clear")), |
| 487 fillRect(0, 0, 10, 10)); | 489 fillRect(0, 0, 10, 10)); |
| 488 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), | 490 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), |
| 489 fillRect(0, 0, 10, 10)); | 491 fillRect(0, 0, 10, 10)); |
| 490 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("source-over")), | 492 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("source-over")), |
| 491 fillRect(0, 0, 10, 10)); | 493 fillRect(0, 0, 10, 10)); |
| 492 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), | 494 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), |
| 493 fillRect(0, 0, 10, 10)); | 495 fillRect(0, 0, 10, 10)); |
| 494 // Test composite operators with a transparent rect that covers the entire can
vas | 496 // Test composite operators with a transparent rect that covers the entire |
| 497 // canvas |
| 495 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), | 498 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), |
| 496 setGlobalCompositeOperation(String("clear")), | 499 setGlobalCompositeOperation(String("clear")), |
| 497 fillRect(0, 0, 10, 10)); | 500 fillRect(0, 0, 10, 10)); |
| 498 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), | 501 TEST_OVERDRAW_3(1, setGlobalAlpha(0.5f), |
| 499 setGlobalCompositeOperation(String("copy")), | 502 setGlobalCompositeOperation(String("copy")), |
| 500 fillRect(0, 0, 10, 10)); | 503 fillRect(0, 0, 10, 10)); |
| 501 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), | 504 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), |
| 502 setGlobalCompositeOperation(String("source-over")), | 505 setGlobalCompositeOperation(String("source-over")), |
| 503 fillRect(0, 0, 10, 10)); | 506 fillRect(0, 0, 10, 10)); |
| 504 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), | 507 TEST_OVERDRAW_3(0, setGlobalAlpha(0.5f), |
| 505 setGlobalCompositeOperation(String("source-in")), | 508 setGlobalCompositeOperation(String("source-in")), |
| 506 fillRect(0, 0, 10, 10)); | 509 fillRect(0, 0, 10, 10)); |
| 507 // Test composite operators with an opaque rect that does not cover the entire
canvas | 510 // Test composite operators with an opaque rect that does not cover the entire |
| 511 // canvas |
| 508 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("clear")), | 512 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("clear")), |
| 509 fillRect(0, 0, 5, 5)); | 513 fillRect(0, 0, 5, 5)); |
| 510 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), | 514 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), |
| 511 fillRect(0, 0, 5, 5)); | 515 fillRect(0, 0, 5, 5)); |
| 512 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), | 516 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), |
| 513 fillRect(0, 0, 5, 5)); | 517 fillRect(0, 0, 5, 5)); |
| 514 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), | 518 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), |
| 515 fillRect(0, 0, 5, 5)); | 519 fillRect(0, 0, 5, 5)); |
| 516 } | 520 } |
| 517 | 521 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 createContext(NonOpaque); | 891 createContext(NonOpaque); |
| 888 | 892 |
| 889 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 893 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
| 890 fakeAccelerateSurface = | 894 fakeAccelerateSurface = |
| 891 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 895 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
| 892 IntSize(10, 10), NonOpaque)); | 896 IntSize(10, 10), NonOpaque)); |
| 893 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = | 897 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = |
| 894 fakeAccelerateSurface.get(); | 898 fakeAccelerateSurface.get(); |
| 895 canvasElement().createImageBufferUsingSurfaceForTesting( | 899 canvasElement().createImageBufferUsingSurfaceForTesting( |
| 896 std::move(fakeAccelerateSurface)); | 900 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, | 901 // 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 | 902 // pixel per buffer, and 2 is an estimate of num of gpu buffers required |
| 899 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 903 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 900 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 904 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
| 901 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 905 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 902 | 906 |
| 903 // Switching accelerated mode to non-accelerated mode | 907 // Switching accelerated mode to non-accelerated mode |
| 904 fakeAccelerateSurfacePtr->setIsAccelerated(false); | 908 fakeAccelerateSurfacePtr->setIsAccelerated(false); |
| 905 canvasElement().buffer()->updateGPUMemoryUsage(); | 909 canvasElement().buffer()->updateGPUMemoryUsage(); |
| 906 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 910 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
| 907 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 911 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 908 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 912 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 createContext(NonOpaque); | 1106 createContext(NonOpaque); |
| 1103 | 1107 |
| 1104 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> | 1108 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> |
| 1105 fakeAccelerateSurface = | 1109 fakeAccelerateSurface = |
| 1106 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( | 1110 wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting( |
| 1107 IntSize(10, 10), NonOpaque)); | 1111 IntSize(10, 10), NonOpaque)); |
| 1108 canvasElement().createImageBufferUsingSurfaceForTesting( | 1112 canvasElement().createImageBufferUsingSurfaceForTesting( |
| 1109 std::move(fakeAccelerateSurface)); | 1113 std::move(fakeAccelerateSurface)); |
| 1110 CanvasRenderingContext2D* context = context2d(); | 1114 CanvasRenderingContext2D* context = context2d(); |
| 1111 | 1115 |
| 1112 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per pix
el per buffer, | 1116 // 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 | 1117 // pixel per buffer, and 2 is an estimate of num of gpu buffers required |
| 1114 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 1118 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 1115 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 1119 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
| 1116 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 1120 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 1117 | 1121 |
| 1118 context->fillRect(10, 10, 100, 100); | 1122 context->fillRect(10, 10, 100, 100); |
| 1119 EXPECT_TRUE(canvasElement().buffer()->isAccelerated()); | 1123 EXPECT_TRUE(canvasElement().buffer()->isAccelerated()); |
| 1120 | 1124 |
| 1121 canvasElement().buffer()->disableAcceleration(); | 1125 canvasElement().buffer()->disableAcceleration(); |
| 1122 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); | 1126 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); |
| 1123 | 1127 |
| 1124 context->fillRect(10, 10, 100, 100); | 1128 context->fillRect(10, 10, 100, 100); |
| 1125 | 1129 |
| 1126 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 1130 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
| 1127 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 1131 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 1128 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 1132 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
| 1129 } | 1133 } |
| 1130 | 1134 |
| 1131 } // namespace blink | 1135 } // namespace blink |
| OLD | NEW |