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

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

Issue 2104053004: Revert of Make 2D canvas disable gpu acceleration when getImageData is called (patchset #6 id:10000… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2782
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 HTMLDocument& document() const { return *m_document; } 83 HTMLDocument& document() const { return *m_document; }
87 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } 84 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; }
88 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); } 85 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende ringContext2D*>(canvasElement().renderingContext()); }
89 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM emoryUsage(); } 86 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM emoryUsage(); }
90 unsigned getGlobalAcceleratedImageBufferCount() const { return ImageBuffer:: getGlobalAcceleratedImageBufferCount(); } 87 unsigned getGlobalAcceleratedImageBufferCount() const { return ImageBuffer:: getGlobalAcceleratedImageBufferCount(); }
91 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()- >getGPUMemoryUsage(); } 88 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()- >getGPUMemoryUsage(); }
92 89
93 void createContext(OpacityMode); 90 void createContext(OpacityMode);
94 void TearDown(); 91 void TearDown();
95 void unrefCanvas(); 92 void unrefCanvas();
96 PassRefPtr<Canvas2DLayerBridge> makeBridge(std::unique_ptr<FakeWebGraphicsCo ntext3DProvider>, const IntSize&, Canvas2DLayerBridge::AccelerationMode);
97 93
98 private: 94 private:
99 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 95 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
100 Persistent<HTMLDocument> m_document; 96 Persistent<HTMLDocument> m_document;
101 Persistent<HTMLCanvasElement> m_canvasElement; 97 Persistent<HTMLCanvasElement> m_canvasElement;
102 Persistent<MemoryCache> m_globalMemoryCache; 98 Persistent<MemoryCache> m_globalMemoryCache;
103 99
104 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients> { 100 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients> {
105 public: 101 public:
106 static WrapGradients* create() 102 static WrapGradients* create()
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 173
178 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()); 174 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create());
179 } 175 }
180 176
181 void CanvasRenderingContext2DTest::TearDown() 177 void CanvasRenderingContext2DTest::TearDown()
182 { 178 {
183 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC); 179 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC);
184 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); 180 replaceMemoryCacheForTesting(m_globalMemoryCache.release());
185 } 181 }
186 182
187 PassRefPtr<Canvas2DLayerBridge> CanvasRenderingContext2DTest::makeBridge(std::un ique_ptr<FakeWebGraphicsContext3DProvider> provider, const IntSize& size, Canvas 2DLayerBridge::AccelerationMode accelerationMode)
188 {
189 return adoptRef(new Canvas2DLayerBridge(std::move(provider), size, 0, NonOpa que, accelerationMode));
190 }
191
192 //============================================================================ 183 //============================================================================
193 184
194 class FakeAcceleratedImageBufferSurfaceForTesting : public UnacceleratedImageBuf ferSurface { 185 class FakeAcceleratedImageBufferSurfaceForTesting : public UnacceleratedImageBuf ferSurface {
195 public: 186 public:
196 FakeAcceleratedImageBufferSurfaceForTesting(const IntSize& size, OpacityMode mode) 187 FakeAcceleratedImageBufferSurfaceForTesting(const IntSize& size, OpacityMode mode)
197 : UnacceleratedImageBufferSurface(size, mode) 188 : UnacceleratedImageBufferSurface(size, mode)
198 , m_isAccelerated(true) { } 189 , m_isAccelerated(true) { }
199 ~FakeAcceleratedImageBufferSurfaceForTesting() override { } 190 ~FakeAcceleratedImageBufferSurfaceForTesting() override { }
200 bool isAccelerated() const override { return m_isAccelerated; } 191 bool isAccelerated() const override { return m_isAccelerated; }
201 void setIsAccelerated(bool isAccelerated) 192 void setIsAccelerated(bool isAccelerated)
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 } 746 }
756 747
757 TEST_F(CanvasRenderingContext2DTest, ContextDisposedBeforeCanvas) 748 TEST_F(CanvasRenderingContext2DTest, ContextDisposedBeforeCanvas)
758 { 749 {
759 createContext(NonOpaque); 750 createContext(NonOpaque);
760 751
761 canvasElement().detachContext(); 752 canvasElement().detachContext();
762 // Passes by not crashing later during teardown 753 // Passes by not crashing later during teardown
763 } 754 }
764 755
765 TEST_F(CanvasRenderingContext2DTest, GetImageDataDisablesAcceleration)
766 {
767 bool savedFixedRenderingMode = RuntimeEnabledFeatures::canvas2dFixedRenderin gModeEnabled();
768 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(false);
769
770 createContext(NonOpaque);
771 FakeGLES2Interface gl;
772 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider(new FakeWe bGraphicsContext3DProvider(&gl));
773 IntSize size(300, 300);
774 RefPtr<Canvas2DLayerBridge> bridge = makeBridge(std::move(contextProvider), size, Canvas2DLayerBridge::EnableAcceleration);
775 std::unique_ptr<Canvas2DImageBufferSurface> surface(new Canvas2DImageBufferS urface(bridge, size));
776 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface));
777
778 EXPECT_TRUE(bridge->isAccelerated());
779 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount());
780 EXPECT_EQ(720000, getGlobalGPUMemoryUsage());
781
782 TrackExceptionState exceptionState;
783 context2d()->getImageData(0, 0, 1, 1, exceptionState);
784
785 EXPECT_FALSE(exceptionState.hadException());
786 EXPECT_FALSE(bridge->isAccelerated());
787 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount());
788 EXPECT_EQ(0, getGlobalGPUMemoryUsage());
789
790 // Restore global state to prevent side-effects on other tests
791 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende ringMode);
792 }
793
794 } // namespace blink 756 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698