Too much duplicated code in LayerTreeHosts implementations
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Jun 2016 12:16:41 +0000 (12:16 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Jun 2016 12:16:41 +0000 (12:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159144

Reviewed by Žan Doberšek.

There's some code common and duplicated in all current LayerTreeHosts implementations (Gtk, Coordinated, and
ThreadedCoordinated). The thing is even worse in the case of ThreadedCoordinated and Coordinated, where the
former is actually a special case of the later, and it seems like code was copy pasted and then modified to add
ThreadedCoordinated specific code. The problem of that approach, apart from the code duplication, is that common
parts end up diverging too. This patch moves the common parts to the base class LayerTreeHost and makes
ThreadedCoordinatedLayerTreeHost inherit from CoordinatedLayerTreeHost, to share the common code and simply add
the specific one.

* PlatformGTK.cmake:
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.h:
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
(WebKit::CoordinatedLayerTreeHost::CoordinatedLayerTreeHost):
(WebKit::CoordinatedLayerTreeHost::scheduleLayerFlush):
(WebKit::CoordinatedLayerTreeHost::setViewOverlayRootLayer):
(WebKit::CoordinatedLayerTreeHost::setRootCompositingLayer):
(WebKit::CoordinatedLayerTreeHost::invalidate):
(WebKit::CoordinatedLayerTreeHost::sizeDidChange):
(WebKit::CoordinatedLayerTreeHost::layerFlushTimerFired):
(WebKit::CoordinatedLayerTreeHost::commitSceneState):
(WebKit::CoordinatedLayerTreeHost::createCoordinatedSurface):
(WebKit::CoordinatedLayerTreeHost::cancelPendingLayerFlush): Deleted.
(WebKit::CoordinatedLayerTreeHost::forceRepaint): Deleted.
(WebKit::CoordinatedLayerTreeHost::forceRepaintAsync): Deleted.
(WebKit::CoordinatedLayerTreeHost::didFlushRootLayer): Deleted.
(WebKit::CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged): Deleted.
(WebKit::CoordinatedLayerTreeHost::pageBackgroundTransparencyChanged): Deleted.
(WebKit::CoordinatedLayerTreeHost::graphicsLayerFactory): Deleted.
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:
(WebKit::ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost):
(WebKit::ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged):
(WebKit::ThreadedCoordinatedLayerTreeHost::sizeDidChange):
(WebKit::ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect):
(WebKit::ThreadedCoordinatedLayerTreeHost::commitSceneState):
(WebKit::ThreadedCoordinatedLayerTreeHost::create): Deleted.
(WebKit::ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents): Deleted.
(WebKit::ThreadedCoordinatedLayerTreeHost::contentsSizeChanged): Deleted.
(WebKit::ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties): Deleted.
(WebKit::ThreadedCoordinatedLayerTreeHost::didScaleFactorChanged): Deleted.
(WebKit::ThreadedCoordinatedLayerTreeHost::setNativeSurfaceHandleForCompositing): Deleted.
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:
* WebProcess/WebPage/DrawingArea.h:
(WebKit::DrawingArea::layerHostDidFlushLayers):
* WebProcess/WebPage/DrawingAreaImpl.h:
* WebProcess/WebPage/LayerTreeHost.cpp:
(WebKit::LayerTreeHost::~LayerTreeHost):
(WebKit::LayerTreeHost::setLayerFlushSchedulingEnabled):
(WebKit::LayerTreeHost::pauseRendering):
(WebKit::LayerTreeHost::resumeRendering):
(WebKit::LayerTreeHost::invalidate):
* WebProcess/WebPage/LayerTreeHost.h:
(WebKit::LayerTreeHost::layerTreeContext):
(WebKit::LayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush):
(WebKit::LayerTreeHost::setNonCompositedContentsNeedDisplay):
(WebKit::LayerTreeHost::setNonCompositedContentsNeedDisplayInRect):
(WebKit::LayerTreeHost::scrollNonCompositedContents):
(WebKit::LayerTreeHost::graphicsLayerFactory):
(WebKit::LayerTreeHost::contentsSizeChanged):
(WebKit::LayerTreeHost::didChangeViewportProperties):
(WebKit::LayerTreeHost::setNativeSurfaceHandleForCompositing):
(WebKit::LayerTreeHost::setViewOverlayRootLayer):
(WebKit::LayerTreeHost::forceRepaintAsync): Deleted.
* WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
(WebKit::LayerTreeHostGtk::invalidate):
(WebKit::LayerTreeHostGtk::setViewOverlayRootLayer):
(WebKit::LayerTreeHostGtk::LayerTreeHostGtk): Deleted.
(WebKit::LayerTreeHostGtk::setRootCompositingLayer): Deleted.
(WebKit::LayerTreeHostGtk::setNonCompositedContentsNeedDisplay): Deleted.
(WebKit::LayerTreeHostGtk::scrollNonCompositedContents): Deleted.
(WebKit::LayerTreeHostGtk::setNativeSurfaceHandleForCompositing): Deleted.
* WebProcess/WebPage/gtk/LayerTreeHostGtk.h:

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

14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.cpp
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.h
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h
Source/WebKit2/WebProcess/WebPage/DrawingArea.h
Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h
Source/WebKit2/WebProcess/WebPage/LayerTreeHost.cpp
Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h
Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp
Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h

index f724b82..19c4d4c 100644 (file)
@@ -1,3 +1,82 @@
+2016-06-29  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        Too much duplicated code in LayerTreeHosts implementations
+        https://bugs.webkit.org/show_bug.cgi?id=159144
+
+        Reviewed by Žan Doberšek.
+
+        There's some code common and duplicated in all current LayerTreeHosts implementations (Gtk, Coordinated, and
+        ThreadedCoordinated). The thing is even worse in the case of ThreadedCoordinated and Coordinated, where the
+        former is actually a special case of the later, and it seems like code was copy pasted and then modified to add
+        ThreadedCoordinated specific code. The problem of that approach, apart from the code duplication, is that common
+        parts end up diverging too. This patch moves the common parts to the base class LayerTreeHost and makes
+        ThreadedCoordinatedLayerTreeHost inherit from CoordinatedLayerTreeHost, to share the common code and simply add
+        the specific one.
+
+        * PlatformGTK.cmake:
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.h:
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
+        (WebKit::CoordinatedLayerTreeHost::CoordinatedLayerTreeHost):
+        (WebKit::CoordinatedLayerTreeHost::scheduleLayerFlush):
+        (WebKit::CoordinatedLayerTreeHost::setViewOverlayRootLayer):
+        (WebKit::CoordinatedLayerTreeHost::setRootCompositingLayer):
+        (WebKit::CoordinatedLayerTreeHost::invalidate):
+        (WebKit::CoordinatedLayerTreeHost::sizeDidChange):
+        (WebKit::CoordinatedLayerTreeHost::layerFlushTimerFired):
+        (WebKit::CoordinatedLayerTreeHost::commitSceneState):
+        (WebKit::CoordinatedLayerTreeHost::createCoordinatedSurface):
+        (WebKit::CoordinatedLayerTreeHost::cancelPendingLayerFlush): Deleted.
+        (WebKit::CoordinatedLayerTreeHost::forceRepaint): Deleted.
+        (WebKit::CoordinatedLayerTreeHost::forceRepaintAsync): Deleted.
+        (WebKit::CoordinatedLayerTreeHost::didFlushRootLayer): Deleted.
+        (WebKit::CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged): Deleted.
+        (WebKit::CoordinatedLayerTreeHost::pageBackgroundTransparencyChanged): Deleted.
+        (WebKit::CoordinatedLayerTreeHost::graphicsLayerFactory): Deleted.
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
+        * WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:
+        (WebKit::ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::sizeDidChange):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::commitSceneState):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::create): Deleted.
+        (WebKit::ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents): Deleted.
+        (WebKit::ThreadedCoordinatedLayerTreeHost::contentsSizeChanged): Deleted.
+        (WebKit::ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties): Deleted.
+        (WebKit::ThreadedCoordinatedLayerTreeHost::didScaleFactorChanged): Deleted.
+        (WebKit::ThreadedCoordinatedLayerTreeHost::setNativeSurfaceHandleForCompositing): Deleted.
+        * WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:
+        * WebProcess/WebPage/DrawingArea.h:
+        (WebKit::DrawingArea::layerHostDidFlushLayers):
+        * WebProcess/WebPage/DrawingAreaImpl.h:
+        * WebProcess/WebPage/LayerTreeHost.cpp:
+        (WebKit::LayerTreeHost::~LayerTreeHost):
+        (WebKit::LayerTreeHost::setLayerFlushSchedulingEnabled):
+        (WebKit::LayerTreeHost::pauseRendering):
+        (WebKit::LayerTreeHost::resumeRendering):
+        (WebKit::LayerTreeHost::invalidate):
+        * WebProcess/WebPage/LayerTreeHost.h:
+        (WebKit::LayerTreeHost::layerTreeContext):
+        (WebKit::LayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush):
+        (WebKit::LayerTreeHost::setNonCompositedContentsNeedDisplay):
+        (WebKit::LayerTreeHost::setNonCompositedContentsNeedDisplayInRect):
+        (WebKit::LayerTreeHost::scrollNonCompositedContents):
+        (WebKit::LayerTreeHost::graphicsLayerFactory):
+        (WebKit::LayerTreeHost::contentsSizeChanged):
+        (WebKit::LayerTreeHost::didChangeViewportProperties):
+        (WebKit::LayerTreeHost::setNativeSurfaceHandleForCompositing):
+        (WebKit::LayerTreeHost::setViewOverlayRootLayer):
+        (WebKit::LayerTreeHost::forceRepaintAsync): Deleted.
+        * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
+        (WebKit::LayerTreeHostGtk::invalidate):
+        (WebKit::LayerTreeHostGtk::setViewOverlayRootLayer):
+        (WebKit::LayerTreeHostGtk::LayerTreeHostGtk): Deleted.
+        (WebKit::LayerTreeHostGtk::setRootCompositingLayer): Deleted.
+        (WebKit::LayerTreeHostGtk::setNonCompositedContentsNeedDisplay): Deleted.
+        (WebKit::LayerTreeHostGtk::scrollNonCompositedContents): Deleted.
+        (WebKit::LayerTreeHostGtk::setNativeSurfaceHandleForCompositing): Deleted.
+        * WebProcess/WebPage/gtk/LayerTreeHostGtk.h:
+
 2016-06-28  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r202586 and r202595.
index ac02e4c..4f5591a 100644 (file)
@@ -826,6 +826,7 @@ if (ENABLE_THREADED_COMPOSITOR)
         Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp
         Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp
 
+        WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
         WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp
     )
     list(APPEND WebKit2_INCLUDE_DIRECTORIES
index ca11084..09b72ef 100644 (file)
@@ -348,8 +348,7 @@ void CoordinatedDrawingArea::attachViewOverlayGraphicsLayer(WebCore::Frame* fram
     if (!frame->isMainFrame())
         return;
 
-    CoordinatedLayerTreeHost* coordinatedLayerTreeHost = static_cast<CoordinatedLayerTreeHost*>(m_layerTreeHost.get());
-    coordinatedLayerTreeHost->setViewOverlayRootLayer(viewOverlayRootLayer);
+    m_layerTreeHost->setViewOverlayRootLayer(viewOverlayRootLayer);
 }
 
 } // namespace WebKit
index d0b9f3e..dd0d638 100644 (file)
@@ -41,8 +41,6 @@ public:
     CoordinatedDrawingArea(WebPage&, const WebPageCreationParameters&);
     virtual ~CoordinatedDrawingArea();
 
-    void layerHostDidFlushLayers();
-
 private:
     // DrawingArea
     void setNeedsDisplay() override;
@@ -69,6 +67,8 @@ private:
     void viewStateDidChange(WebCore::ViewState::Flags, bool /* wantsDidUpdateViewState */, const Vector<uint64_t>& /* callbackIDs */) override;
     void attachViewOverlayGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) override;
 
+    void layerHostDidFlushLayers() override;
+
     // IPC message handlers.
     void updateBackingStoreState(uint64_t backingStoreStateID, bool respondImmediately, float deviceScaleFactor, const WebCore::IntSize&, const WebCore::IntSize& scrollOffset) override;
     virtual void suspendPainting();
index b68dc40..da2ae83 100644 (file)
 #if USE(COORDINATED_GRAPHICS)
 #include "CoordinatedLayerTreeHost.h"
 
-#include "CoordinatedDrawingArea.h"
-#include "CoordinatedGraphicsArgumentCoders.h"
-#include "CoordinatedLayerTreeHostProxyMessages.h"
-#include "GraphicsContext.h"
+#include "DrawingArea.h"
 #include "WebCoordinatedSurface.h"
-#include "WebCoreArgumentCoders.h"
 #include "WebPage.h"
 #include "WebPageProxyMessages.h"
-#include <WebCore/Frame.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/MainFrame.h>
 #include <WebCore/PageOverlayController.h>
-#include <WebCore/Settings.h>
-#include <wtf/CurrentTime.h>
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include "ThreadSafeCoordinatedSurface.h"
+#elif USE(COORDINATED_GRAPHICS_MULTIPROCESS)
+#include "CoordinatedGraphicsArgumentCoders.h"
+#include "CoordinatedLayerTreeHostProxyMessages.h"
+#include "WebCoreArgumentCoders.h"
+#endif
 
 using namespace WebCore;
 
@@ -60,46 +61,24 @@ CoordinatedLayerTreeHost::~CoordinatedLayerTreeHost()
 
 CoordinatedLayerTreeHost::CoordinatedLayerTreeHost(WebPage& webPage)
     : LayerTreeHost(webPage)
-    , m_notifyAfterScheduledLayerFlush(false)
-    , m_isValid(true)
-    , m_isSuspended(false)
-    , m_isWaitingForRenderer(true)
-    , m_layerFlushTimer(*this, &CoordinatedLayerTreeHost::layerFlushTimerFired)
-    , m_layerFlushSchedulingEnabled(true)
-    , m_forceRepaintAsyncCallbackID(0)
-    , m_viewOverlayRootLayer(nullptr)
+    , m_coordinator(std::make_unique<CompositingCoordinator>(webPage.corePage(), this))
+    , m_layerFlushTimer(RunLoop::main(), this, &CoordinatedLayerTreeHost::layerFlushTimerFired)
 {
-    m_coordinator = std::make_unique<CompositingCoordinator>(m_webPage.corePage(), this);
-
     m_coordinator->createRootLayer(m_webPage.size());
+#if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
     m_layerTreeContext.contextID = toCoordinatedGraphicsLayer(m_coordinator->rootLayer())->id();
+#endif
 
     CoordinatedSurface::setFactory(createCoordinatedSurface);
-
     scheduleLayerFlush();
 }
 
-void CoordinatedLayerTreeHost::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
-{
-    if (m_layerFlushSchedulingEnabled == layerFlushingEnabled)
-        return;
-
-    m_layerFlushSchedulingEnabled = layerFlushingEnabled;
-
-    if (m_layerFlushSchedulingEnabled) {
-        scheduleLayerFlush();
-        return;
-    }
-
-    cancelPendingLayerFlush();
-}
-
 void CoordinatedLayerTreeHost::scheduleLayerFlush()
 {
     if (!m_layerFlushSchedulingEnabled)
         return;
 
-    if (!m_layerFlushTimer.isActive() || m_layerFlushTimer.nextFireInterval() > 0)
+    if (!m_layerFlushTimer.isActive())
         m_layerFlushTimer.startOneShot(0);
 }
 
@@ -108,18 +87,13 @@ void CoordinatedLayerTreeHost::cancelPendingLayerFlush()
     m_layerFlushTimer.stop();
 }
 
-void CoordinatedLayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush)
-{
-    m_notifyAfterScheduledLayerFlush = notifyAfterScheduledLayerFlush;
-}
-
-void CoordinatedLayerTreeHost::setViewOverlayRootLayer(WebCore::GraphicsLayer* viewOverlayRootLayer)
+void CoordinatedLayerTreeHost::setViewOverlayRootLayer(GraphicsLayer* viewOverlayRootLayer)
 {
-    m_viewOverlayRootLayer = viewOverlayRootLayer;
+    LayerTreeHost::setViewOverlayRootLayer(viewOverlayRootLayer);
     m_coordinator->setViewOverlayRootLayer(viewOverlayRootLayer);
 }
 
-void CoordinatedLayerTreeHost::setRootCompositingLayer(WebCore::GraphicsLayer* graphicsLayer)
+void CoordinatedLayerTreeHost::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
 {
     m_coordinator->setRootCompositingLayer(graphicsLayer);
 }
@@ -128,9 +102,8 @@ void CoordinatedLayerTreeHost::invalidate()
 {
     cancelPendingLayerFlush();
 
-    ASSERT(m_isValid);
     m_coordinator->clearRootLayer();
-    m_isValid = false;
+    LayerTreeHost::invalidate();
 }
 
 void CoordinatedLayerTreeHost::forceRepaint()
@@ -158,7 +131,7 @@ bool CoordinatedLayerTreeHost::forceRepaintAsync(uint64_t callbackID)
     return true;
 }
 
-void CoordinatedLayerTreeHost::sizeDidChange(const WebCore::IntSize& newSize)
+void CoordinatedLayerTreeHost::sizeDidChange(const IntSize& newSize)
 {
     m_coordinator->sizeDidChange(newSize);
     scheduleLayerFlush();
@@ -189,7 +162,7 @@ void CoordinatedLayerTreeHost::didFlushRootLayer(const FloatRect& visibleContent
         m_viewOverlayRootLayer->flushCompositingState(visibleContentRect,  m_webPage.mainFrame()->view()->viewportIsStable());
 }
 
-void CoordinatedLayerTreeHost::performScheduledLayerFlush()
+void CoordinatedLayerTreeHost::layerFlushTimerFired()
 {
     if (m_isSuspended || m_isWaitingForRenderer)
         return;
@@ -207,29 +180,34 @@ void CoordinatedLayerTreeHost::performScheduledLayerFlush()
     }
 
     if (m_notifyAfterScheduledLayerFlush && didSync) {
-        static_cast<CoordinatedDrawingArea*>(m_webPage.drawingArea())->layerHostDidFlushLayers();
+        m_webPage.drawingArea()->layerHostDidFlushLayers();
         m_notifyAfterScheduledLayerFlush = false;
     }
 }
 
-void CoordinatedLayerTreeHost::layerFlushTimerFired()
-{
-    performScheduledLayerFlush();
-}
-
 void CoordinatedLayerTreeHost::paintLayerContents(const GraphicsLayer*, GraphicsContext&, const IntRect&)
 {
 }
 
-void CoordinatedLayerTreeHost::commitSceneState(const WebCore::CoordinatedGraphicsState& state)
+void CoordinatedLayerTreeHost::commitSceneState(const CoordinatedGraphicsState& state)
 {
+#if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
     m_webPage.send(Messages::CoordinatedLayerTreeHostProxy::CommitCoordinatedGraphicsState(state));
+#endif
     m_isWaitingForRenderer = true;
 }
 
 RefPtr<CoordinatedSurface> CoordinatedLayerTreeHost::createCoordinatedSurface(const IntSize& size, CoordinatedSurface::Flags flags)
 {
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    return ThreadSafeCoordinatedSurface::create(size, flags);
+#elif USE(COORDINATED_GRAPHICS_MULTIPROCESS)
     return WebCoordinatedSurface::create(size, flags);
+#else
+    UNUSED_PARAM(size);
+    UNUSED_PARAM(flags);
+    return nullptr;
+#endif
 }
 
 void CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged()
index 4d88599..8a08dfc 100644 (file)
 
 #if USE(COORDINATED_GRAPHICS)
 
-#include "LayerTreeContext.h"
 #include "LayerTreeHost.h"
 #include <WebCore/CompositingCoordinator.h>
-#include <WebCore/GraphicsLayerFactory.h>
-#include <wtf/HashSet.h>
+#include <wtf/RunLoop.h>
 
 namespace WebCore {
 class CoordinatedSurface;
+class GraphicsLayerFactory;
 }
 
 namespace WebKit {
@@ -43,28 +42,27 @@ public:
     static Ref<CoordinatedLayerTreeHost> create(WebPage&);
     virtual ~CoordinatedLayerTreeHost();
 
-    const LayerTreeContext& layerTreeContext() override { return m_layerTreeContext; }
-    void setLayerFlushSchedulingEnabled(bool) override;
+protected:
+    explicit CoordinatedLayerTreeHost(WebPage&);
+
     void scheduleLayerFlush() override;
-    void setShouldNotifyAfterNextScheduledLayerFlush(bool) override;
+    void cancelPendingLayerFlush() override;
     void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
     void invalidate() override;
 
-    void setNonCompositedContentsNeedDisplay() override { }
-    void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) override { }
-    void scrollNonCompositedContents(const WebCore::IntRect&) override { }
     void forceRepaint() override;
     bool forceRepaintAsync(uint64_t callbackID) override;
     void sizeDidChange(const WebCore::IntSize& newSize) override;
 
-    void pauseRendering() override { m_isSuspended = true; }
-    void resumeRendering() override { m_isSuspended = false; scheduleLayerFlush(); }
     void deviceOrPageScaleFactorChanged() override;
     void pageBackgroundTransparencyChanged() override;
 
-    void didReceiveCoordinatedLayerTreeHostMessage(IPC::Connection&, IPC::MessageDecoder&) override;
+    void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
+    void renderNextFrame();
+    void purgeBackingStores();
+    void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
+
     WebCore::GraphicsLayerFactory* graphicsLayerFactory() override;
-    WebCore::CoordinatedGraphicsLayer* mainContentsLayer();
 
 #if ENABLE(REQUEST_ANIMATION_FRAME)
     void scheduleAnimation() override;
@@ -72,42 +70,25 @@ public:
 
     void setViewOverlayRootLayer(WebCore::GraphicsLayer*) override;
 
-    static RefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
-
-protected:
-    explicit CoordinatedLayerTreeHost(WebPage&);
-
-private:
-    // CoordinatedLayerTreeHost
-    void cancelPendingLayerFlush();
-    void performScheduledLayerFlush();
-    void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
-    void renderNextFrame();
-    void purgeBackingStores();
-    void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
-
-    void layerFlushTimerFired();
-
     // CompositingCoordinator::Client
     void didFlushRootLayer(const WebCore::FloatRect& visibleContentRect) override;
     void notifyFlushRequired() override { scheduleLayerFlush(); };
     void commitSceneState(const WebCore::CoordinatedGraphicsState&) override;
     void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) override;
 
-    std::unique_ptr<WebCore::CompositingCoordinator> m_coordinator;
-
-    bool m_notifyAfterScheduledLayerFlush;
-    bool m_isValid;
-    bool m_isSuspended;
-    bool m_isWaitingForRenderer;
+private:
+    void layerFlushTimerFired();
 
-    LayerTreeContext m_layerTreeContext;
+#if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
+    void didReceiveCoordinatedLayerTreeHostMessage(IPC::Connection&, IPC::MessageDecoder&) override;
+#endif
 
-    WebCore::Timer m_layerFlushTimer;
-    bool m_layerFlushSchedulingEnabled;
-    uint64_t m_forceRepaintAsyncCallbackID;
+    static RefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
 
-    WebCore::GraphicsLayer* m_viewOverlayRootLayer;
+    std::unique_ptr<WebCore::CompositingCoordinator> m_coordinator;
+    bool m_isWaitingForRenderer { true };
+    uint64_t m_forceRepaintAsyncCallbackID { 0 };
+    RunLoop::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer;
 };
 
 } // namespace WebKit
index 6317da3..9a03c25 100644 (file)
 #include "ThreadedCoordinatedLayerTreeHost.h"
 
 #if USE(COORDINATED_GRAPHICS_THREADED)
-
-#include "DrawingAreaImpl.h"
-#include "NotImplemented.h"
-#include "ThreadSafeCoordinatedSurface.h"
 #include "WebPage.h"
-#include <WebCore/CoordinatedGraphicsLayer.h>
-#include <WebCore/CoordinatedGraphicsState.h>
-#include <WebCore/Frame.h>
 #include <WebCore/FrameView.h>
-#include <WebCore/GraphicsContext.h>
 #include <WebCore/MainFrame.h>
-#include <WebCore/Page.h>
-#include <wtf/CurrentTime.h>
 
 using namespace WebCore;
 
@@ -58,66 +48,10 @@ ThreadedCoordinatedLayerTreeHost::~ThreadedCoordinatedLayerTreeHost()
 }
 
 ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost(WebPage& webPage)
-    : LayerTreeHost(webPage)
-    , m_forceRepaintAsyncCallbackID(0)
-    , m_notifyAfterScheduledLayerFlush(false)
-    , m_isSuspended(false)
-    , m_isWaitingForRenderer(false)
-    , m_layerFlushTimer(RunLoop::main(), this, &ThreadedCoordinatedLayerTreeHost::performScheduledLayerFlush)
-    , m_layerFlushSchedulingEnabled(true)
-{
-    m_coordinator = std::make_unique<CompositingCoordinator>(m_webPage.corePage(), this);
-
-    m_coordinator->createRootLayer(m_webPage.size());
-
-    CoordinatedSurface::setFactory(createCoordinatedSurface);
-
-    m_compositor = ThreadedCompositor::create(this);
-    scheduleLayerFlush();
-}
-
-RefPtr<CoordinatedSurface> ThreadedCoordinatedLayerTreeHost::createCoordinatedSurface(const IntSize& size, CoordinatedSurface::Flags flags)
-{
-    return ThreadSafeCoordinatedSurface::create(size, flags);
-}
-
-void ThreadedCoordinatedLayerTreeHost::scheduleLayerFlush()
-{
-    if (!m_layerFlushSchedulingEnabled)
-        return;
-
-    if (!m_layerFlushTimer.isActive())
-        m_layerFlushTimer.startOneShot(0);
-}
-
-void ThreadedCoordinatedLayerTreeHost::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
-{
-    if (m_layerFlushSchedulingEnabled == layerFlushingEnabled)
-        return;
-
-    m_layerFlushSchedulingEnabled = layerFlushingEnabled;
-
-    if (m_layerFlushSchedulingEnabled) {
-        scheduleLayerFlush();
-        return;
-    }
-
-    cancelPendingLayerFlush();
-}
-
-void ThreadedCoordinatedLayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush)
+    : CoordinatedLayerTreeHost(webPage)
+    , m_compositorClient(*this)
+    , m_compositor(ThreadedCompositor::create(&m_compositorClient))
 {
-    m_notifyAfterScheduledLayerFlush = notifyAfterScheduledLayerFlush;
-}
-
-void ThreadedCoordinatedLayerTreeHost::setRootCompositingLayer(WebCore::GraphicsLayer* graphicsLayer)
-{
-    m_coordinator->setRootCompositingLayer(graphicsLayer);
-}
-
-void ThreadedCoordinatedLayerTreeHost::invalidate()
-{
-    notImplemented();
 }
 
 void ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents(const WebCore::IntRect& rect)
@@ -126,20 +60,6 @@ void ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents(const WebCore
     scheduleLayerFlush();
 }
 
-void ThreadedCoordinatedLayerTreeHost::forceRepaint()
-{
-    notImplemented();
-}
-
-bool ThreadedCoordinatedLayerTreeHost::forceRepaintAsync(uint64_t callbackID)
-{
-    // We expect the UI process to not require a new repaint until the previous one has finished.
-    ASSERT(!m_forceRepaintAsyncCallbackID);
-    m_forceRepaintAsyncCallbackID = callbackID;
-    scheduleLayerFlush();
-    return true;
-}
-
 void ThreadedCoordinatedLayerTreeHost::contentsSizeChanged(const WebCore::IntSize& newSize)
 {
     m_compositor->didChangeContentsSize(newSize);
@@ -147,29 +67,13 @@ void ThreadedCoordinatedLayerTreeHost::contentsSizeChanged(const WebCore::IntSiz
 
 void ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged()
 {
-    m_coordinator->deviceOrPageScaleFactorChanged();
+    CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged();
     m_compositor->setDeviceScaleFactor(m_webPage.deviceScaleFactor());
 }
 
-void ThreadedCoordinatedLayerTreeHost::pauseRendering()
-{
-    m_isSuspended = true;
-}
-
-void ThreadedCoordinatedLayerTreeHost::resumeRendering()
-{
-    m_isSuspended = false;
-    scheduleLayerFlush();
-}
-
-GraphicsLayerFactory* ThreadedCoordinatedLayerTreeHost::graphicsLayerFactory()
-{
-    return m_coordinator.get();
-}
-
-void ThreadedCoordinatedLayerTreeHost::sizeDidChange(const WebCore::IntSize& size)
+void ThreadedCoordinatedLayerTreeHost::sizeDidChange(const IntSize& size)
 {
-    m_coordinator->sizeDidChange(size);
+    CoordinatedLayerTreeHost::sizeDidChange(size);
     m_compositor->didChangeViewportSize(size);
 }
 
@@ -178,21 +82,11 @@ void ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties(const WebCore
     m_compositor->didChangeViewportAttribute(attr);
 }
 
-void ThreadedCoordinatedLayerTreeHost::compositorDidFlushLayers()
-{
-    static_cast<DrawingAreaImpl*>(m_webPage.drawingArea())->layerHostDidFlushLayers();
-}
-
 void ThreadedCoordinatedLayerTreeHost::didScaleFactorChanged(float scale, const IntPoint& origin)
 {
     m_webPage.scalePage(scale, origin);
 }
 
-void ThreadedCoordinatedLayerTreeHost::setViewOverlayRootLayer(GraphicsLayer* graphicsLayer)
-{
-    m_coordinator->setViewOverlayRootLayer(graphicsLayer);
-}
-
 #if PLATFORM(GTK)
 void ThreadedCoordinatedLayerTreeHost::setNativeSurfaceHandleForCompositing(uint64_t handle)
 {
@@ -202,23 +96,9 @@ void ThreadedCoordinatedLayerTreeHost::setNativeSurfaceHandleForCompositing(uint
 }
 #endif
 
-#if ENABLE(REQUEST_ANIMATION_FRAME)
-void ThreadedCoordinatedLayerTreeHost::scheduleAnimation()
-{
-    if (m_isWaitingForRenderer)
-        return;
-
-    if (m_layerFlushTimer.isActive())
-        return;
-
-    m_layerFlushTimer.startOneShot(m_coordinator->nextAnimationServiceTime());
-    scheduleLayerFlush();
-}
-#endif
-
 void ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector, float scale)
 {
-    m_coordinator->setVisibleContentsRect(rect, trajectoryVector);
+    CoordinatedLayerTreeHost::setVisibleContentsRect(rect, trajectoryVector);
     if (m_lastScrollPosition != roundedIntPoint(rect.location())) {
         m_lastScrollPosition = roundedIntPoint(rect.location());
 
@@ -230,61 +110,14 @@ void ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect(const FloatRect& r
         m_lastScaleFactor = scale;
         didScaleFactorChanged(m_lastScaleFactor, m_lastScrollPosition);
     }
-
-    scheduleLayerFlush();
-}
-
-void ThreadedCoordinatedLayerTreeHost::cancelPendingLayerFlush()
-{
-    m_layerFlushTimer.stop();
-}
-
-void ThreadedCoordinatedLayerTreeHost::performScheduledLayerFlush()
-{
-    if (m_isSuspended || m_isWaitingForRenderer)
-        return;
-
-    m_coordinator->syncDisplayState();
-    bool didSync = m_coordinator->flushPendingLayerChanges();
-
-    if (m_notifyAfterScheduledLayerFlush && didSync) {
-        compositorDidFlushLayers();
-        m_notifyAfterScheduledLayerFlush = false;
-    }
-}
-
-void ThreadedCoordinatedLayerTreeHost::purgeBackingStores()
-{
-    m_coordinator->purgeBackingStores();
-}
-
-void ThreadedCoordinatedLayerTreeHost::renderNextFrame()
-{
-    m_isWaitingForRenderer = false;
-    m_coordinator->renderNextFrame();
-    scheduleLayerFlush();
-}
-
-void ThreadedCoordinatedLayerTreeHost::commitScrollOffset(uint32_t layerID, const IntSize& offset)
-{
-    m_coordinator->commitScrollOffset(layerID, offset);
-}
-
-void ThreadedCoordinatedLayerTreeHost::notifyFlushRequired()
-{
-    scheduleLayerFlush();
 }
 
 void ThreadedCoordinatedLayerTreeHost::commitSceneState(const CoordinatedGraphicsState& state)
 {
-    m_isWaitingForRenderer = true;
+    CoordinatedLayerTreeHost::commitSceneState(state);
     m_compositor->updateSceneState(state);
 }
 
-void ThreadedCoordinatedLayerTreeHost::paintLayerContents(const GraphicsLayer*, GraphicsContext&, const IntRect&)
-{
-}
-
 } // namespace WebKit
 
 #endif // USE(COORDINATED_GRAPHICS)
index 54dc214..924b730 100644 (file)
 
 #if USE(COORDINATED_GRAPHICS_THREADED)
 
-#include "LayerTreeContext.h"
-#include "LayerTreeHost.h"
+#include "CoordinatedLayerTreeHost.h"
 #include "ThreadedCompositor.h"
-#include <WebCore/CompositingCoordinator.h>
-#include <WebCore/FloatPoint.h>
-#include <WebCore/FloatRect.h>
-#include <WebCore/IntPoint.h>
-#include <WebCore/IntRect.h>
-#include <WebCore/IntSize.h>
-#include <WebCore/PageOverlay.h>
-#include <WebCore/Timer.h>
-#include <wtf/RunLoop.h>
-#include <wtf/Threading.h>
 
 namespace WebCore {
-class CoordinatedSurface;
 class GraphicsContext;
 class GraphicsLayer;
-class GraphicsLayerFactory;
-class GraphicsLayerFactory;
-struct CoordinatedGraphicsLayerState;
 struct CoordinatedGraphicsState;
 }
 
@@ -58,34 +43,18 @@ namespace WebKit {
 
 class WebPage;
 
-class ThreadedCoordinatedLayerTreeHost : public LayerTreeHost, public WebCore::CompositingCoordinator::Client, public ThreadedCompositor::Client {
-    WTF_MAKE_NONCOPYABLE(ThreadedCoordinatedLayerTreeHost); WTF_MAKE_FAST_ALLOCATED;
+class ThreadedCoordinatedLayerTreeHost final : public CoordinatedLayerTreeHost {
 public:
     static Ref<ThreadedCoordinatedLayerTreeHost> create(WebPage&);
     virtual ~ThreadedCoordinatedLayerTreeHost();
 
-    const LayerTreeContext& layerTreeContext() override { return m_layerTreeContext; };
-
-    void scheduleLayerFlush() override;
-    void setLayerFlushSchedulingEnabled(bool) override;
-    void setShouldNotifyAfterNextScheduledLayerFlush(bool) override;
-    void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
-    void invalidate() override;
+private:
+    explicit ThreadedCoordinatedLayerTreeHost(WebPage&);
 
-    void setNonCompositedContentsNeedDisplay() override { };
-    void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) override { };
     void scrollNonCompositedContents(const WebCore::IntRect& scrollRect) override;
-    void forceRepaint() override;
-    bool forceRepaintAsync(uint64_t /*callbackID*/) override;
     void sizeDidChange(const WebCore::IntSize&) override;
     void deviceOrPageScaleFactorChanged() override;
 
-    void pauseRendering() override;
-    void resumeRendering() override;
-
-    WebCore::GraphicsLayerFactory* graphicsLayerFactory() override;
-    void pageBackgroundTransparencyChanged() override { };
-
     void contentsSizeChanged(const WebCore::IntSize&) override;
     void didChangeViewportProperties(const WebCore::ViewportAttributes&) override;
 
@@ -93,55 +62,51 @@ public:
     void setNativeSurfaceHandleForCompositing(uint64_t) override;
 #endif
 
-#if ENABLE(REQUEST_ANIMATION_FRAME)
-    void scheduleAnimation() override;
-#endif
-
-    void setViewOverlayRootLayer(WebCore::GraphicsLayer*) override;
-    static RefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
-
-protected:
-    explicit ThreadedCoordinatedLayerTreeHost(WebPage&);
-
-private:
+    class CompositorClient final : public ThreadedCompositor::Client {
+        WTF_MAKE_NONCOPYABLE(CompositorClient);
+    public:
+        CompositorClient(ThreadedCoordinatedLayerTreeHost& layerTreeHost)
+            : m_layerTreeHost(layerTreeHost)
+        {
+        }
+
+    private:
+        void setVisibleContentsRect(const WebCore::FloatRect& rect, const WebCore::FloatPoint& trajectoryVector, float scale) override
+        {
+            m_layerTreeHost.setVisibleContentsRect(rect, trajectoryVector, scale);
+        }
+
+        void purgeBackingStores() override
+        {
+            m_layerTreeHost.purgeBackingStores();
+        }
+
+        void renderNextFrame() override
+        {
+            m_layerTreeHost.renderNextFrame();
+        }
+
+        void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) override
+        {
+            m_layerTreeHost.commitScrollOffset(layerID, offset);
+        }
+
+        ThreadedCoordinatedLayerTreeHost& m_layerTreeHost;
+    };
 
-    void compositorDidFlushLayers();
     void didScaleFactorChanged(float scale, const WebCore::IntPoint& origin);
 
-    void cancelPendingLayerFlush();
-    void performScheduledLayerFlush();
-
-    WebCore::GraphicsLayer* rootLayer() { return m_coordinator->rootLayer(); }
-
-    // ThreadedCompositor::Client
-    void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&, float) override;
-    void purgeBackingStores() override;
-    void renderNextFrame() override;
-    void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) override;
+    void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&, float);
 
     // CompositingCoordinator::Client
     void didFlushRootLayer(const WebCore::FloatRect&) override { }
-    void notifyFlushRequired() override;
     void commitSceneState(const WebCore::CoordinatedGraphicsState&) override;
-    void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) override;
-
-    LayerTreeContext m_layerTreeContext;
-    uint64_t m_forceRepaintAsyncCallbackID;
 
     WebCore::IntPoint m_prevScrollPosition;
-
-    std::unique_ptr<WebCore::CompositingCoordinator> m_coordinator;
+    CompositorClient m_compositorClient;
     RefPtr<ThreadedCompositor> m_compositor;
-
-    bool m_notifyAfterScheduledLayerFlush;
-    bool m_isSuspended;
-    bool m_isWaitingForRenderer;
-
-    float m_lastScaleFactor;
+    float m_lastScaleFactor { 1 };
     WebCore::IntPoint m_lastScrollPosition;
-
-    RunLoop::Timer<ThreadedCoordinatedLayerTreeHost> m_layerFlushTimer;
-    bool m_layerFlushSchedulingEnabled;
 };
 
 } // namespace WebKit
index b432bbd..c29d4d2 100644 (file)
@@ -138,6 +138,8 @@ public:
     virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition, bool flushSynchronously, const WebCore::MachSendRight& fencePort) { }
 #endif
 
+    virtual void layerHostDidFlushLayers() { };
+
 protected:
     DrawingArea(DrawingAreaType, WebPage&);
 
index 6f1f874..e7b636b 100644 (file)
@@ -45,8 +45,6 @@ public:
     DrawingAreaImpl(WebPage&, const WebPageCreationParameters&);
     virtual ~DrawingAreaImpl();
 
-    void layerHostDidFlushLayers();
-
 private:
     // DrawingArea
     void setNeedsDisplay() override;
@@ -75,6 +73,8 @@ private:
     void destroyNativeSurfaceHandleForCompositing(bool&) override;
 #endif
 
+    void layerHostDidFlushLayers() override;
+
     // IPC message handlers.
     void updateBackingStoreState(uint64_t backingStoreStateID, bool respondImmediately, float deviceScaleFactor, const WebCore::IntSize&, const WebCore::IntSize& scrollOffset) override;
     void didUpdate() override;
index d2a14f8..11dd136 100644 (file)
@@ -62,6 +62,39 @@ LayerTreeHost::LayerTreeHost(WebPage& webPage)
 
 LayerTreeHost::~LayerTreeHost()
 {
+    ASSERT(!m_isValid);
+}
+
+void LayerTreeHost::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
+{
+    if (m_layerFlushSchedulingEnabled == layerFlushingEnabled)
+        return;
+
+    m_layerFlushSchedulingEnabled = layerFlushingEnabled;
+
+    if (m_layerFlushSchedulingEnabled) {
+        scheduleLayerFlush();
+        return;
+    }
+
+    cancelPendingLayerFlush();
+}
+
+void LayerTreeHost::pauseRendering()
+{
+    m_isSuspended = true;
+}
+
+void LayerTreeHost::resumeRendering()
+{
+    m_isSuspended = false;
+    scheduleLayerFlush();
+}
+
+void LayerTreeHost::invalidate()
+{
+    ASSERT(m_isValid);
+    m_isValid = false;
 }
 
 } // namespace WebKit
index 21bf919..baee4af 100644 (file)
@@ -29,8 +29,7 @@
 #if USE(COORDINATED_GRAPHICS) || USE(TEXTURE_MAPPER)
 
 #include "LayerTreeContext.h"
-#include <WebCore/Color.h>
-#include <wtf/PassRefPtr.h>
+#include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
 
 namespace IPC {
@@ -39,8 +38,6 @@ class MessageDecoder;
 }
 
 namespace WebCore {
-class FloatPoint;
-class FloatRect;
 class IntRect;
 class IntSize;
 class GraphicsLayer;
@@ -52,7 +49,6 @@ struct ViewportAttributes;
 
 namespace WebKit {
 
-class UpdateInfo;
 class WebPage;
 
 class LayerTreeHost : public RefCounted<LayerTreeHost> {
@@ -60,34 +56,36 @@ public:
     static RefPtr<LayerTreeHost> create(WebPage&);
     virtual ~LayerTreeHost();
 
-    virtual const LayerTreeContext& layerTreeContext() = 0;
+    const LayerTreeContext& layerTreeContext() const { return m_layerTreeContext; }
+    void setLayerFlushSchedulingEnabled(bool);
+    void setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush) { m_notifyAfterScheduledLayerFlush = notifyAfterScheduledLayerFlush; }
+
     virtual void scheduleLayerFlush() = 0;
-    virtual void setLayerFlushSchedulingEnabled(bool) = 0;
-    virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool) = 0;
+    virtual void cancelPendingLayerFlush() = 0;
     virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) = 0;
-    virtual void invalidate() = 0;
+    virtual void invalidate();
 
-    virtual void setNonCompositedContentsNeedDisplay() = 0;
-    virtual void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) = 0;
-    virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect) = 0;
+    virtual void setNonCompositedContentsNeedDisplay() { };
+    virtual void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) { };
+    virtual void scrollNonCompositedContents(const WebCore::IntRect&) { };
     virtual void forceRepaint() = 0;
     virtual bool forceRepaintAsync(uint64_t /*callbackID*/) { return false; }
     virtual void sizeDidChange(const WebCore::IntSize& newSize) = 0;
     virtual void deviceOrPageScaleFactorChanged() = 0;
     virtual void pageBackgroundTransparencyChanged() = 0;
 
-    virtual void pauseRendering() { }
-    virtual void resumeRendering() { }
+    virtual void pauseRendering();
+    virtual void resumeRendering();
 
-    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() { return 0; }
+    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() { return nullptr; }
 
 #if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
     virtual void didReceiveCoordinatedLayerTreeHostMessage(IPC::Connection&, IPC::MessageDecoder&) = 0;
 #endif
 
 #if USE(COORDINATED_GRAPHICS_THREADED)
-    virtual void contentsSizeChanged(const WebCore::IntSize&) = 0;
-    virtual void didChangeViewportProperties(const WebCore::ViewportAttributes&) = 0;
+    virtual void contentsSizeChanged(const WebCore::IntSize&) { };
+    virtual void didChangeViewportProperties(const WebCore::ViewportAttributes&) { };
 #endif
 
 #if USE(COORDINATED_GRAPHICS) && ENABLE(REQUEST_ANIMATION_FRAME)
@@ -95,15 +93,21 @@ public:
 #endif
 
 #if USE(TEXTURE_MAPPER) && PLATFORM(GTK)
-    virtual void setNativeSurfaceHandleForCompositing(uint64_t) = 0;
+    virtual void setNativeSurfaceHandleForCompositing(uint64_t) { };
 #endif
 
-    virtual void setViewOverlayRootLayer(WebCore::GraphicsLayer*) = 0;
+    virtual void setViewOverlayRootLayer(WebCore::GraphicsLayer* viewOverlayRootLayer) { m_viewOverlayRootLayer = viewOverlayRootLayer; }
 
 protected:
     explicit LayerTreeHost(WebPage&);
 
     WebPage& m_webPage;
+    LayerTreeContext m_layerTreeContext;
+    bool m_layerFlushSchedulingEnabled { true };
+    bool m_notifyAfterScheduledLayerFlush { false };
+    bool m_isSuspended { false };
+    bool m_isValid { true };
+    WebCore::GraphicsLayer* m_viewOverlayRootLayer { nullptr };
 };
 
 } // namespace WebKit
index 552a762..44e5e08 100644 (file)
@@ -133,10 +133,6 @@ Ref<LayerTreeHostGtk> LayerTreeHostGtk::create(WebPage& webPage)
 
 LayerTreeHostGtk::LayerTreeHostGtk(WebPage& webPage)
     : LayerTreeHost(webPage)
-    , m_isValid(true)
-    , m_notifyAfterScheduledLayerFlush(false)
-    , m_layerFlushSchedulingEnabled(true)
-    , m_viewOverlayRootLayer(nullptr)
     , m_renderFrameScheduler(std::bind(&LayerTreeHostGtk::renderFrame, this))
 {
     m_rootLayer = GraphicsLayer::create(graphicsLayerFactory(), *this);
@@ -183,21 +179,10 @@ bool LayerTreeHostGtk::makeContextCurrent()
 
 LayerTreeHostGtk::~LayerTreeHostGtk()
 {
-    ASSERT(!m_isValid);
     ASSERT(!m_rootLayer);
     cancelPendingLayerFlush();
 }
 
-const LayerTreeContext& LayerTreeHostGtk::layerTreeContext()
-{
-    return m_layerTreeContext;
-}
-
-void LayerTreeHostGtk::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush)
-{
-    m_notifyAfterScheduledLayerFlush = notifyAfterScheduledLayerFlush;
-}
-
 void LayerTreeHostGtk::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
 {
     m_nonCompositedContentLayer->removeAllChildren();
@@ -211,8 +196,6 @@ void LayerTreeHostGtk::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
 
 void LayerTreeHostGtk::invalidate()
 {
-    ASSERT(m_isValid);
-
     // This can trigger destruction of GL objects so let's make sure that
     // we have the right active context
     if (m_context)
@@ -224,7 +207,7 @@ void LayerTreeHostGtk::invalidate()
     m_textureMapper = nullptr;
 
     m_context = nullptr;
-    m_isValid = false;
+    LayerTreeHost::invalidate();
 }
 
 void LayerTreeHostGtk::setNonCompositedContentsNeedDisplay()
@@ -365,7 +348,7 @@ void LayerTreeHostGtk::flushAndRenderLayers()
 
     if (m_notifyAfterScheduledLayerFlush) {
         // Let the drawing area know that we've done a flush of the layer changes.
-        static_cast<DrawingAreaImpl*>(m_webPage.drawingArea())->layerHostDidFlushLayers();
+        m_webPage.drawingArea()->layerHostDidFlushLayers();
         m_notifyAfterScheduledLayerFlush = false;
     }
 }
@@ -378,21 +361,6 @@ void LayerTreeHostGtk::scheduleLayerFlush()
     m_renderFrameScheduler.start();
 }
 
-void LayerTreeHostGtk::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
-{
-    if (m_layerFlushSchedulingEnabled == layerFlushingEnabled)
-        return;
-
-    m_layerFlushSchedulingEnabled = layerFlushingEnabled;
-
-    if (m_layerFlushSchedulingEnabled) {
-        scheduleLayerFlush();
-        return;
-    }
-
-    cancelPendingLayerFlush();
-}
-
 void LayerTreeHostGtk::pageBackgroundTransparencyChanged()
 {
     m_nonCompositedContentLayer->setContentsOpaque(m_webPage.drawsBackground());
@@ -403,9 +371,9 @@ void LayerTreeHostGtk::cancelPendingLayerFlush()
     m_renderFrameScheduler.stop();
 }
 
-void LayerTreeHostGtk::setViewOverlayRootLayer(WebCore::GraphicsLayer* viewOverlayRootLayer)
+void LayerTreeHostGtk::setViewOverlayRootLayer(GraphicsLayer* viewOverlayRootLayer)
 {
-    m_viewOverlayRootLayer = viewOverlayRootLayer;
+    LayerTreeHost::setViewOverlayRootLayer(viewOverlayRootLayer);
     if (m_viewOverlayRootLayer)
         m_rootLayer->addChild(m_viewOverlayRootLayer);
 }
index bbfb321..c15b86f 100644 (file)
@@ -51,7 +51,7 @@ private:
 
     // LayerTreeHost
     void scheduleLayerFlush() override;
-    void setLayerFlushSchedulingEnabled(bool layerFlushingEnabled) override;
+    void cancelPendingLayerFlush() override;
     void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
     void invalidate() override;
 
@@ -60,6 +60,11 @@ private:
     void deviceOrPageScaleFactorChanged() override;
     void pageBackgroundTransparencyChanged() override;
 
+    void setNonCompositedContentsNeedDisplay() override;
+    void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) override;
+    void scrollNonCompositedContents(const WebCore::IntRect& scrollRect) override;
+    void setViewOverlayRootLayer(WebCore::GraphicsLayer*) override;
+
     void setNativeSurfaceHandleForCompositing(uint64_t) override;
 
     class RenderFrameScheduler {
@@ -80,15 +85,6 @@ private:
         double m_lastImmediateFlushTime { 0 };
     };
 
-    // LayerTreeHost
-    const LayerTreeContext& layerTreeContext() override;
-    void setShouldNotifyAfterNextScheduledLayerFlush(bool) override;
-
-    void setNonCompositedContentsNeedDisplay() override;
-    void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) override;
-    void scrollNonCompositedContents(const WebCore::IntRect& scrollRect) override;
-    void setViewOverlayRootLayer(WebCore::GraphicsLayer*) override;
-
     // GraphicsLayerClient
     void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::FloatRect& clipRect) override;
     float deviceScaleFactor() const override;
@@ -100,21 +96,13 @@ private:
     void compositeLayersToContext(CompositePurpose = NotForResize);
 
     void flushAndRenderLayers();
-    void cancelPendingLayerFlush();
-
     bool renderFrame();
-
     bool makeContextCurrent();
 
-    LayerTreeContext m_layerTreeContext;
-    bool m_isValid;
-    bool m_notifyAfterScheduledLayerFlush;
     std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
     std::unique_ptr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
     std::unique_ptr<WebCore::TextureMapper> m_textureMapper;
     std::unique_ptr<WebCore::GLContext> m_context;
-    bool m_layerFlushSchedulingEnabled;
-    WebCore::GraphicsLayer* m_viewOverlayRootLayer;
     WebCore::TransformationMatrix m_scaleMatrix;
     RenderFrameScheduler m_renderFrameScheduler;
 };