| 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/fetch/MemoryCache.h" | 7 #include "core/fetch/MemoryCache.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/ImageBitmap.h" | 9 #include "core/frame/ImageBitmap.h" |
| 10 #include "core/html/HTMLCanvasElement.h" | 10 #include "core/html/HTMLCanvasElement.h" |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 807 |
| 808 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
10), NonOpaque)); | 808 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
10), NonOpaque)); |
| 809 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); | 809 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); |
| 810 | 810 |
| 811 NonThrowableExceptionState exceptionState; | 811 NonThrowableExceptionState exceptionState; |
| 812 | 812 |
| 813 CanvasRenderingContext2D* context = context2d(); | 813 CanvasRenderingContext2D* context = context2d(); |
| 814 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); | 814 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); |
| 815 | 815 |
| 816 context->fillRect(10, 10, 100, 100); | 816 context->fillRect(10, 10, 100, 100); |
| 817 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); | |
| 818 | |
| 819 context->drawImage(canvasElement().getExecutionContext(), &m_opaqueBitmap, 0
, 0, 1, 1, 0, 0, 10, 10, exceptionState); | |
| 820 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); | 817 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); |
| 821 | 818 |
| 822 int numReps = 100; | 819 int numReps = 100; |
| 823 for (int i = 0; i < numReps; i++) { | 820 for (int i = 0; i < numReps; i++) { |
| 824 context->fillRect(10, 10, 100, 100); | 821 context->fillText("Text", 10, 10, 1); // faster with no acceleration |
| 822 } |
| 823 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); |
| 824 |
| 825 for (int i = 0; i < numReps; i++) { |
| 826 context->fillRect(10, 10, 200, 200); // faster with acceleration |
| 827 } |
| 828 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); |
| 829 |
| 830 for (int i = 0; i < numReps * 100; i++) { |
| 831 context->strokeText("Text", 10, 10, 1); // faster with no acceleration |
| 825 } | 832 } |
| 826 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); | 833 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); |
| 827 } | 834 } |
| 828 | 835 |
| 829 TEST_F(CanvasRenderingContext2DTest, DisableAcceleration) | 836 TEST_F(CanvasRenderingContext2DTest, DisableAcceleration) |
| 830 { | 837 { |
| 831 createContext(NonOpaque); | 838 createContext(NonOpaque); |
| 832 | 839 |
| 833 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
10), NonOpaque)); | 840 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
10), NonOpaque)); |
| 834 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); | 841 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 847 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); | 854 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); |
| 848 | 855 |
| 849 context->fillRect(10, 10, 100, 100); | 856 context->fillRect(10, 10, 100, 100); |
| 850 | 857 |
| 851 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 858 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
| 852 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 859 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 853 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 860 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
| 854 } | 861 } |
| 855 | 862 |
| 856 } // namespace blink | 863 } // namespace blink |
| OLD | NEW |