| 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 } else { | 790 } else { |
| 791 EXPECT_TRUE(bridge->isAccelerated()); | 791 EXPECT_TRUE(bridge->isAccelerated()); |
| 792 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 792 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 793 EXPECT_EQ(720000, getGlobalGPUMemoryUsage()); | 793 EXPECT_EQ(720000, getGlobalGPUMemoryUsage()); |
| 794 } | 794 } |
| 795 | 795 |
| 796 // Restore global state to prevent side-effects on other tests | 796 // Restore global state to prevent side-effects on other tests |
| 797 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende
ringMode); | 797 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende
ringMode); |
| 798 } | 798 } |
| 799 | 799 |
| 800 TEST_F(CanvasRenderingContext2DTest, IsAccelerationOptimalForCanvasContentHeuris
tic) |
| 801 { |
| 802 createContext(NonOpaque); |
| 803 |
| 804 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
10), NonOpaque)); |
| 805 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); |
| 806 |
| 807 NonThrowableExceptionState exceptionState; |
| 808 |
| 809 CanvasRenderingContext2D* context = context2d(); |
| 810 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); |
| 811 |
| 812 context->fillRect(10, 10, 100, 100); |
| 813 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); |
| 814 |
| 815 context->drawImage(canvasElement().getExecutionContext(), &m_opaqueBitmap, 0
, 0, 1, 1, 0, 0, 10, 10, exceptionState); |
| 816 EXPECT_TRUE(context->isAccelerationOptimalForCanvasContent()); |
| 817 |
| 818 int numReps = 100; |
| 819 for (int i = 0; i < numReps; i++) { |
| 820 context->fillRect(10, 10, 100, 100); |
| 821 } |
| 822 EXPECT_FALSE(context->isAccelerationOptimalForCanvasContent()); |
| 823 } |
| 824 |
| 825 TEST_F(CanvasRenderingContext2DTest, DisableAcceleration) |
| 826 { |
| 827 createContext(NonOpaque); |
| 828 |
| 829 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
10), NonOpaque)); |
| 830 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); |
| 831 CanvasRenderingContext2D* context = context2d(); |
| 832 |
| 833 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per p
ixel per buffer, |
| 834 // and 2 is an estimate of num of gpu buffers required |
| 835 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 836 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
| 837 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 838 |
| 839 context->fillRect(10, 10, 100, 100); |
| 840 EXPECT_TRUE(canvasElement().buffer()->isAccelerated()); |
| 841 |
| 842 canvasElement().buffer()->disableAcceleration(); |
| 843 EXPECT_FALSE(canvasElement().buffer()->isAccelerated()); |
| 844 |
| 845 context->fillRect(10, 10, 100, 100); |
| 846 |
| 847 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
| 848 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 849 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
| 850 } |
| 851 |
| 800 } // namespace blink | 852 } // namespace blink |
| OLD | NEW |