[chromium] Move check for threaded compositing from WebCompositorSupport to Platform
authorjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2013 23:15:23 +0000 (23:15 +0000)
committerjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2013 23:15:23 +0000 (23:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=111386

Reviewed by Adrienne Walker.

Source/Platform:

This moves the query for if threaded compositing is enabled from WebCompositorSupport
to Platform. This is part of an effort to remove statefulness on WebCompositorSupport
and because it's much easier to override Platform functions for different tests.

* chromium/public/Platform.h:
(WebKit::Platform::isThreadedCompositingEnabled):
(Platform):
* chromium/public/WebCompositorSupport.h:

Source/WebCore:

This moves checks for whether threaded compositing is enabled from WebCompositorSupport
to Platform. In the case of Canvas2DLayerBridge, the check is moved completely out of
the class to make it easier for tests to specify the threaded configuration to use in the test.

* platform/graphics/chromium/Canvas2DLayerBridge.cpp:
(WebCore::Canvas2DLayerBridge::Canvas2DLayerBridge):
* platform/graphics/chromium/Canvas2DLayerBridge.h:
(WebCore::Canvas2DLayerBridge::create):
(Canvas2DLayerBridge):
* platform/graphics/chromium/DrawingBufferChromium.cpp:
(WebCore::DrawingBuffer::DrawingBuffer):
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::createAcceleratedCanvas):

Source/WebKit/chromium:

* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::composite):
(WebKit::WebViewImpl::scheduleAnimation):
(WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
(WebKit::WebViewImpl::scheduleComposite):
* tests/Canvas2DLayerBridgeTest.cpp:
(Canvas2DLayerBridgeTest::fullLifecycleTest):
* tests/Canvas2DLayerManagerTest.cpp:
(FakeCanvas2DLayerBridge::FakeCanvas2DLayerBridge):

Tools:

* DumpRenderTree/chromium/TestShell.cpp:
(TestShell::initialize):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@144827 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/Platform/ChangeLog
Source/Platform/chromium/public/Platform.h
Source/Platform/chromium/public/WebCompositorSupport.h
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.cpp
Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.h
Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp
Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebViewImpl.cpp
Source/WebKit/chromium/tests/Canvas2DLayerBridgeTest.cpp
Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/TestShell.cpp

index 5fdadbd..6d3ccdf 100644 (file)
@@ -1,3 +1,19 @@
+2013-03-04  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Move check for threaded compositing from WebCompositorSupport to Platform
+        https://bugs.webkit.org/show_bug.cgi?id=111386
+
+        Reviewed by Adrienne Walker.
+
+        This moves the query for if threaded compositing is enabled from WebCompositorSupport
+        to Platform. This is part of an effort to remove statefulness on WebCompositorSupport
+        and because it's much easier to override Platform functions for different tests.
+
+        * chromium/public/Platform.h:
+        (WebKit::Platform::isThreadedCompositingEnabled):
+        (Platform):
+        * chromium/public/WebCompositorSupport.h:
+
 2013-03-05  James Robinson  <jamesr@chromium.org>
 
         [chromium] Clean up WebWidget / WebLayerTreeView interactions
index d2c4d3a..f2a9113 100644 (file)
@@ -478,6 +478,8 @@ public:
     // This value must be checked again after a context loss event as the platform's capabilities may have changed.
     virtual bool canAccelerate2dCanvas() { return false; }
 
+    virtual bool isThreadedCompositingEnabled() { return false; }
+
     virtual WebCompositorSupport* compositorSupport() { return 0; }
 
     virtual WebFlingAnimator* createFlingAnimator() { return 0; }
index 4371758..a1d1c40 100644 (file)
@@ -61,9 +61,6 @@ public:
     // prior to calling initialize.
     virtual void initialize(WebThread*) { }
 
-    // Returns whether the compositor was initialized with threading enabled.
-    virtual bool isThreadingEnabled() { return false; }
-
     // Shuts down the compositor. This must be called when all compositor data
     // types have been deleted. No compositor classes or methods should be used
     // after shutdown.
index 0c3db21..bf6a79f 100644 (file)
@@ -1,3 +1,24 @@
+2013-03-04  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Move check for threaded compositing from WebCompositorSupport to Platform
+        https://bugs.webkit.org/show_bug.cgi?id=111386
+
+        Reviewed by Adrienne Walker.
+
+        This moves checks for whether threaded compositing is enabled from WebCompositorSupport
+        to Platform. In the case of Canvas2DLayerBridge, the check is moved completely out of
+        the class to make it easier for tests to specify the threaded configuration to use in the test.
+
+        * platform/graphics/chromium/Canvas2DLayerBridge.cpp:
+        (WebCore::Canvas2DLayerBridge::Canvas2DLayerBridge):
+        * platform/graphics/chromium/Canvas2DLayerBridge.h:
+        (WebCore::Canvas2DLayerBridge::create):
+        (Canvas2DLayerBridge):
+        * platform/graphics/chromium/DrawingBufferChromium.cpp:
+        (WebCore::DrawingBuffer::DrawingBuffer):
+        * platform/graphics/skia/ImageBufferSkia.cpp:
+        (WebCore::createAcceleratedCanvas):
+
 2013-03-05  Anders Carlsson  <andersca@apple.com>
 
         Split up the storage event dispatch functions further
index b89d995..66272fd 100644 (file)
@@ -43,7 +43,7 @@ using WebKit::WebTextureUpdater;
 
 namespace WebCore {
 
-Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode, unsigned textureId)
+Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode, ThreadMode threadMode, unsigned textureId)
     : m_deferralMode(deferralMode)
     , m_frontBufferTexture(0)
     , m_backBufferTexture(textureId)
@@ -59,12 +59,11 @@ Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context,
     // Used by browser tests to detect the use of a Canvas2DLayerBridge.
     TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation");
 
-    bool compositorThreadingEnabled = WebKit::Platform::current()->compositorSupport()->isThreadingEnabled();
     // FIXME: We currently turn off double buffering when canvas rendering is
     // deferred. What we should be doing is to use a smarter heuristic based
     // on GPU resource monitoring and other factors to chose between single
     // and double buffering.
-    m_useDoubleBuffering = compositorThreadingEnabled && deferralMode == NonDeferred;
+    m_useDoubleBuffering = threadMode == Threaded && deferralMode == NonDeferred;
 
     if (m_useDoubleBuffering) {
         m_context->makeContextCurrent();
@@ -83,7 +82,7 @@ Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context,
 
     m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createExternalTextureLayer(this));
     m_layer->setTextureId(textureId);
-    m_layer->setRateLimitContext(!compositorThreadingEnabled || m_useDoubleBuffering);
+    m_layer->setRateLimitContext(threadMode == SingleThread || m_useDoubleBuffering);
     GraphicsLayerChromium::registerContentsLayer(m_layer->layer());
 }
 
index 95ebf5d..8e442fd 100644 (file)
@@ -45,9 +45,14 @@ namespace WebCore {
 class Canvas2DLayerBridge : public WebKit::WebExternalTextureLayerClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayerBridge> {
     WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge);
 public:
-    static PassOwnPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode, unsigned textureId)
+    enum ThreadMode {
+        SingleThread,
+        Threaded
+    };
+
+    static PassOwnPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode, ThreadMode threading, unsigned textureId)
     {
-        return adoptPtr(new Canvas2DLayerBridge(context, size, deferralMode, textureId));
+        return adoptPtr(new Canvas2DLayerBridge(context, size, deferralMode, threading, textureId));
     }
 
     virtual ~Canvas2DLayerBridge();
@@ -76,7 +81,7 @@ public:
     unsigned backBufferTexture();
 
 protected:
-    Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, const IntSize&, DeferralMode, unsigned textureId);
+    Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, const IntSize&, DeferralMode, ThreadMode, unsigned textureId);
     SkDeferredCanvas* deferredCanvas();
 
     DeferralMode m_deferralMode;
index 453061d..8fe69ee 100644 (file)
@@ -96,7 +96,7 @@ DrawingBuffer::DrawingBuffer(GraphicsContext3D* context,
 
     // We need a separate front and back textures if ...
     m_separateFrontTexture = m_preserveDrawingBuffer == Preserve // ... we have to preserve contents after compositing, which is done with a copy or ...
-                             || WebKit::Platform::current()->compositorSupport()->isThreadingEnabled(); // ... if we're in threaded mode and need to double buffer.
+                             || WebKit::Platform::current()->isThreadedCompositingEnabled(); // ... if we're in threaded mode and need to double buffer.
     initialize(size);
 }
 
index 783e2ca..742b011 100644 (file)
@@ -50,6 +50,7 @@
 #include "SkGpuDevice.h"
 #include "SkiaUtils.h"
 #include "WEBPImageEncoder.h"
+#include <public/Platform.h>
 
 #if USE(ACCELERATED_COMPOSITING)
 #include "Canvas2DLayerBridge.h"
@@ -92,7 +93,8 @@ static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* d
     SkCanvas* canvas;
     SkAutoTUnref<SkDevice> device(new SkGpuDevice(gr, texture.get()));
 #if USE(ACCELERATED_COMPOSITING)
-    data->m_layerBridge = Canvas2DLayerBridge::create(context3D.release(), size, deferralMode, texture.get()->getTextureHandle());
+    Canvas2DLayerBridge::ThreadMode threadMode = WebKit::Platform::current()->isThreadedCompositingEnabled() ? Canvas2DLayerBridge::Threaded : Canvas2DLayerBridge::SingleThread;
+    data->m_layerBridge = Canvas2DLayerBridge::create(context3D.release(), size, deferralMode, threadMode, texture.get()->getTextureHandle());
     canvas = data->m_layerBridge->skCanvas(device.get());
 #else
     canvas = new SkCanvas(device.get());
index 565db90..4040429 100644 (file)
@@ -1,3 +1,20 @@
+2013-03-04  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Move check for threaded compositing from WebCompositorSupport to Platform
+        https://bugs.webkit.org/show_bug.cgi?id=111386
+
+        Reviewed by Adrienne Walker.
+
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::composite):
+        (WebKit::WebViewImpl::scheduleAnimation):
+        (WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
+        (WebKit::WebViewImpl::scheduleComposite):
+        * tests/Canvas2DLayerBridgeTest.cpp:
+        (Canvas2DLayerBridgeTest::fullLifecycleTest):
+        * tests/Canvas2DLayerManagerTest.cpp:
+        (FakeCanvas2DLayerBridge::FakeCanvas2DLayerBridge):
+
 2013-03-05  James Weatherall  <wez@chromium.org>
 
         keydown and keyup events have zero keycode for some numeric pad keys under Chromium on Linux
index acb0626..770a6b0 100644 (file)
@@ -4067,7 +4067,7 @@ WebCore::GraphicsLayer* WebViewImpl::rootGraphicsLayer()
 void WebViewImpl::scheduleAnimation()
 {
     if (isAcceleratedCompositingActive()) {
-        if (Platform::current()->compositorSupport()->isThreadingEnabled()) {
+        if (Platform::current()->isThreadedCompositingEnabled()) {
             ASSERT(m_layerTreeView);
             m_layerTreeView->setNeedsAnimate();
         } else
@@ -4110,7 +4110,7 @@ void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
             m_layerTreeView->finishAllRendering();
         m_client->didDeactivateCompositor();
         if (!m_layerTreeViewCommitsDeferred
-            && WebKit::Platform::current()->compositorSupport()->isThreadingEnabled()) {
+            && WebKit::Platform::current()->isThreadedCompositingEnabled()) {
             ASSERT(m_layerTreeView);
             // In threaded compositing mode, force compositing mode is always on so setIsAcceleratedCompositingActive(false)
             // means that we're transitioning to a new page. Suppress commits until WebKit generates invalidations so
index 509aa2e..c44f330 100644 (file)
@@ -61,13 +61,9 @@ public:
 
 } // namespace
 
-enum ThreadMode {
-    SingleThreaded, Threaded
-};
-
 class Canvas2DLayerBridgeTest : public Test {
 protected:
-    void fullLifecycleTest(ThreadMode threadMode, DeferralMode deferralMode)
+    void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode, DeferralMode deferralMode)
     {
         RefPtr<GraphicsContext3D> mainContext = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext));
 
@@ -77,33 +73,28 @@ protected:
 
         const IntSize size(300, 150);
 
-        OwnPtr<WebThread> thread;
-        if (threadMode == Threaded)
-            thread = adoptPtr(WebKit::Platform::current()->createThread("Canvas2DLayerBridgeTest"));
-        WebKitTests::WebCompositorInitializer initializer(thread.get());
-
         WebGLId backTextureId = 1;
         WebGLId frontTextureId = 1;
 
         // Threaded and non deferred canvases are double buffered.
-        if (threadMode == Threaded && deferralMode == NonDeferred) {
+        if (threadMode == Canvas2DLayerBridge::Threaded && deferralMode == NonDeferred) {
             frontTextureId = 2;
             // Create texture (on the main thread) and do the copy (on the impl thread).
             EXPECT_CALL(mainMock, createTexture()).WillOnce(Return(frontTextureId));
         }
 
-        OwnPtr<Canvas2DLayerBridge> bridge = Canvas2DLayerBridge::create(mainContext.get(), size, deferralMode, backTextureId);
+        OwnPtr<Canvas2DLayerBridge> bridge = Canvas2DLayerBridge::create(mainContext.get(), size, deferralMode, threadMode, backTextureId);
 
         ::testing::Mock::VerifyAndClearExpectations(&mainMock);
 
         EXPECT_CALL(mainMock, flush());
-        if (threadMode == Threaded && deferralMode == NonDeferred)
+        if (threadMode == Canvas2DLayerBridge::Threaded && deferralMode == NonDeferred)
             EXPECT_CALL(updater, appendCopy(backTextureId, frontTextureId, WebSize(300, 150)));
         EXPECT_EQ(frontTextureId, bridge->prepareTexture(updater));
         ::testing::Mock::VerifyAndClearExpectations(&mainMock);
         ::testing::Mock::VerifyAndClearExpectations(&updater);
 
-        if (threadMode == Threaded && deferralMode == NonDeferred) {
+        if (threadMode == Canvas2DLayerBridge::Threaded && deferralMode == NonDeferred) {
             EXPECT_CALL(mainMock, deleteTexture(frontTextureId));
             EXPECT_CALL(mainMock, flush());
         }
@@ -115,22 +106,22 @@ namespace {
 
 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreadedDeferred)
 {
-    fullLifecycleTest(SingleThreaded, NonDeferred);
+    fullLifecycleTest(Canvas2DLayerBridge::SingleThread, NonDeferred);
 }
 
 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreadedNonDeferred)
 {
-    fullLifecycleTest(SingleThreaded, Deferred);
+    fullLifecycleTest(Canvas2DLayerBridge::SingleThread, Deferred);
 }
 
 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreadedNonDeferred)
 {
-    fullLifecycleTest(Threaded, NonDeferred);
+    fullLifecycleTest(Canvas2DLayerBridge::Threaded, NonDeferred);
 }
 
 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreadedDeferred)
 {
-    fullLifecycleTest(Threaded, Deferred);
+    fullLifecycleTest(Canvas2DLayerBridge::Threaded, Deferred);
 }
 
 } // namespace
index 79e5703..feb31b2 100644 (file)
@@ -42,7 +42,7 @@ using testing::Test;
 class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge {
 public:
     FakeCanvas2DLayerBridge() 
-        : Canvas2DLayerBridge(GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)), IntSize(1, 1), Deferred, 0)
+        : Canvas2DLayerBridge(GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new WebKit::FakeWebGraphicsContext3D)), IntSize(1, 1), Deferred, SingleThread, 0)
         , m_freeableBytes(0)
         , m_freeMemoryIfPossibleCount(0)
         , m_flushCount(0)
index 4719033..4468f97 100644 (file)
@@ -1,3 +1,13 @@
+2013-03-04  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Move check for threaded compositing from WebCompositorSupport to Platform
+        https://bugs.webkit.org/show_bug.cgi?id=111386
+
+        Reviewed by Adrienne Walker.
+
+        * DumpRenderTree/chromium/TestShell.cpp:
+        (TestShell::initialize):
+
 2013-03-05  Min Qin  <qinmin@chromium.org>
 
         Copy dictionary to the external storage before running layout test on android
index 3137df5..37f0319 100644 (file)
@@ -145,6 +145,7 @@ void TestShell::initialize(MockPlatform* platformSupport)
 
     if (m_threadedCompositingEnabled)
         m_webCompositorThread = adoptPtr(WebKit::Platform::current()->createThread("Compositor"));
+    webkit_support::SetThreadedCompositorEnabled(m_threadedCompositingEnabled);
 
     createMainWindow();
 }