Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp

Issue 2141793002: Improving canvas 2D performance by switching graphics rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 784
785 EXPECT_FALSE(exceptionState.hadException()); 785 EXPECT_FALSE(exceptionState.hadException());
786 EXPECT_FALSE(bridge->isAccelerated()); 786 EXPECT_FALSE(bridge->isAccelerated());
787 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); 787 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount());
788 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); 788 EXPECT_EQ(0, getGlobalGPUMemoryUsage());
789 789
790 // Restore global state to prevent side-effects on other tests 790 // Restore global state to prevent side-effects on other tests
791 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende ringMode); 791 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende ringMode);
792 } 792 }
793 793
794 TEST_F(CanvasRenderingContext2DTest, ShouldAccelerateHeuristic)
795 {
796 createContext(NonOpaque);
797
798 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10, 10), NonOpaque));
799 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele rateSurface));
800
801 NonThrowableExceptionState exceptionState;
802
803 CanvasRenderingContext2D* context = context2d();
804 EXPECT_EQ(true, context->shouldAccelerate());
805
806 context->fillRect(10, 10, 100, 100);
807 EXPECT_EQ(false, context->shouldAccelerate());
808
809 context->drawImage(canvasElement().getExecutionContext(), &m_opaqueBitmap, 0 , 0, 1, 1, 0, 0, 10, 10, exceptionState);
810 EXPECT_EQ(true, context->shouldAccelerate());
811
812 int numReps = 100;
813 for (int i = 0; i < numReps; i++) {
814 context->fillRect(10, 10, 100, 100);
815 }
816 EXPECT_EQ(false, context->shouldAccelerate());
817 }
818
819 TEST_F(CanvasRenderingContext2DTest, DisableAcceleration)
820 {
821 createContext(NonOpaque);
822
823 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10, 10), NonOpaque));
824 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele rateSurface));
825 CanvasRenderingContext2D* context = context2d();
826
827 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per p ixel per buffer,
828 // and 2 is an estimate of num of gpu buffers required
829 EXPECT_EQ(800, getCurrentGPUMemoryUsage());
830 EXPECT_EQ(800, getGlobalGPUMemoryUsage());
831 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount());
832
833 context->fillRect(10, 10, 100, 100);
834 EXPECT_EQ(true, canvasElement().buffer()->isAccelerated());
Justin Novosad 2016/07/12 19:31:24 use EXPECT_TRUE
sebastienlc 2016/07/13 19:51:02 Done.
835
836 canvasElement().buffer()->disableAcceleration();
837 EXPECT_EQ(false, canvasElement().buffer()->isAccelerated());
Justin Novosad 2016/07/12 19:31:24 use EXPECT_FALSE
sebastienlc 2016/07/13 19:51:02 Done.
838
839 context->fillRect(10, 10, 100, 100);
840
841 EXPECT_EQ(0, getCurrentGPUMemoryUsage());
842 EXPECT_EQ(0, getGlobalGPUMemoryUsage());
843 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount());
844 }
845
794 } // namespace blink 846 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698