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

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

Issue 2101823002: Revert of Make 2D canvas disable gpu acceleration when getImageData is called (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"
11 #include "core/html/HTMLDocument.h" 11 #include "core/html/HTMLDocument.h"
12 #include "core/html/ImageData.h" 12 #include "core/html/ImageData.h"
13 #include "core/imagebitmap/ImageBitmapOptions.h" 13 #include "core/imagebitmap/ImageBitmapOptions.h"
14 #include "core/loader/EmptyClients.h" 14 #include "core/loader/EmptyClients.h"
15 #include "core/testing/DummyPageHolder.h" 15 #include "core/testing/DummyPageHolder.h"
16 #include "modules/canvas2d/CanvasGradient.h" 16 #include "modules/canvas2d/CanvasGradient.h"
17 #include "modules/canvas2d/CanvasPattern.h" 17 #include "modules/canvas2d/CanvasPattern.h"
18 #include "modules/webgl/WebGLRenderingContext.h" 18 #include "modules/webgl/WebGLRenderingContext.h"
19 #include "platform/graphics/Canvas2DImageBufferSurface.h"
20 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" 19 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
21 #include "platform/graphics/RecordingImageBufferSurface.h" 20 #include "platform/graphics/RecordingImageBufferSurface.h"
22 #include "platform/graphics/StaticBitmapImage.h" 21 #include "platform/graphics/StaticBitmapImage.h"
23 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 22 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
24 #include "platform/graphics/test/FakeGLES2Interface.h"
25 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h"
26 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
28 #include "third_party/skia/include/core/SkSurface.h" 25 #include "third_party/skia/include/core/SkSurface.h"
29 #include "wtf/PtrUtil.h" 26 #include "wtf/PtrUtil.h"
30 #include <memory> 27 #include <memory>
31 28
32 using ::testing::Mock; 29 using ::testing::Mock;
33 30
34 namespace blink { 31 namespace blink {
35 32
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 HTMLDocument& document() const { return *m_document; } 81 HTMLDocument& document() const { return *m_document; }
85 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } 82 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; }
86 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); } 83 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); }
87 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM emoryUsage(); } 84 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM emoryUsage(); }
88 unsigned getGlobalAcceleratedImageBufferCount() const { return ImageBuffer:: getGlobalAcceleratedImageBufferCount(); } 85 unsigned getGlobalAcceleratedImageBufferCount() const { return ImageBuffer:: getGlobalAcceleratedImageBufferCount(); }
89 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()- >getGPUMemoryUsage(); } 86 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()- >getGPUMemoryUsage(); }
90 87
91 void createContext(OpacityMode); 88 void createContext(OpacityMode);
92 void TearDown(); 89 void TearDown();
93 void unrefCanvas(); 90 void unrefCanvas();
94 PassRefPtr<Canvas2DLayerBridge> makeBridge(std::unique_ptr<FakeWebGraphicsCo ntext3DProvider>, const IntSize&, Canvas2DLayerBridge::AccelerationMode);
95 91
96 private: 92 private:
97 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 93 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
98 Persistent<HTMLDocument> m_document; 94 Persistent<HTMLDocument> m_document;
99 Persistent<HTMLCanvasElement> m_canvasElement; 95 Persistent<HTMLCanvasElement> m_canvasElement;
100 Persistent<MemoryCache> m_globalMemoryCache; 96 Persistent<MemoryCache> m_globalMemoryCache;
101 97
102 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients> { 98 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients> {
103 public: 99 public:
104 static WrapGradients* create() 100 static WrapGradients* create()
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 171
176 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()); 172 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create());
177 } 173 }
178 174
179 void CanvasRenderingContext2DTest::TearDown() 175 void CanvasRenderingContext2DTest::TearDown()
180 { 176 {
181 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC); 177 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC);
182 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); 178 replaceMemoryCacheForTesting(m_globalMemoryCache.release());
183 } 179 }
184 180
185 PassRefPtr<Canvas2DLayerBridge> CanvasRenderingContext2DTest::makeBridge(std::un ique_ptr<FakeWebGraphicsContext3DProvider> provider, const IntSize& size, Canvas 2DLayerBridge::AccelerationMode accelerationMode)
186 {
187 return adoptRef(new Canvas2DLayerBridge(std::move(provider), size, 0, NonOpa que, accelerationMode));
188 }
189
190 //============================================================================ 181 //============================================================================
191 182
192 class FakeAcceleratedImageBufferSurfaceForTesting : public UnacceleratedImageBuf ferSurface { 183 class FakeAcceleratedImageBufferSurfaceForTesting : public UnacceleratedImageBuf ferSurface {
193 public: 184 public:
194 FakeAcceleratedImageBufferSurfaceForTesting(const IntSize& size, OpacityMode mode) 185 FakeAcceleratedImageBufferSurfaceForTesting(const IntSize& size, OpacityMode mode)
195 : UnacceleratedImageBufferSurface(size, mode) 186 : UnacceleratedImageBufferSurface(size, mode)
196 , m_isAccelerated(true) { } 187 , m_isAccelerated(true) { }
197 ~FakeAcceleratedImageBufferSurfaceForTesting() override { } 188 ~FakeAcceleratedImageBufferSurfaceForTesting() override { }
198 bool isAccelerated() const override { return m_isAccelerated; } 189 bool isAccelerated() const override { return m_isAccelerated; }
199 void setIsAccelerated(bool isAccelerated) 190 void setIsAccelerated(bool isAccelerated)
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 } 744 }
754 745
755 TEST_F(CanvasRenderingContext2DTest, ContextDisposedBeforeCanvas) 746 TEST_F(CanvasRenderingContext2DTest, ContextDisposedBeforeCanvas)
756 { 747 {
757 createContext(NonOpaque); 748 createContext(NonOpaque);
758 749
759 canvasElement().detachContext(); 750 canvasElement().detachContext();
760 // Passes by not crashing later during teardown 751 // Passes by not crashing later during teardown
761 } 752 }
762 753
763 TEST_F(CanvasRenderingContext2DTest, GetImageDataDisablesAcceleration)
764 {
765 bool savedFixedRenderingMode = RuntimeEnabledFeatures::canvas2dFixedRenderin gModeEnabled();
766 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(false);
767
768 createContext(NonOpaque);
769 FakeGLES2Interface gl;
770 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider(new FakeWe bGraphicsContext3DProvider(&gl));
771 IntSize size(300, 300);
772 RefPtr<Canvas2DLayerBridge> bridge = makeBridge(std::move(contextProvider), size, Canvas2DLayerBridge::EnableAcceleration);
773 std::unique_ptr<Canvas2DImageBufferSurface> surface(new Canvas2DImageBufferS urface(bridge, size));
774 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface));
775
776 EXPECT_TRUE(bridge->isAccelerated());
777 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount());
778 EXPECT_EQ(720000, getGlobalGPUMemoryUsage());
779
780 TrackExceptionState exceptionState;
781 context2d()->getImageData(0, 0, 1, 1, exceptionState);
782
783 EXPECT_FALSE(exceptionState.hadException());
784 EXPECT_FALSE(bridge->isAccelerated());
785 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount());
786 EXPECT_EQ(0, getGlobalGPUMemoryUsage());
787
788 // Restore global state to prevent side-effects on other tests
789 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende ringMode);
790 }
791
792 } // namespace blink 754 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698