Stop using LayerFlushScheduler in WK2
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 09:56:48 +0000 (09:56 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 09:56:48 +0000 (09:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191065

Reviewed by Tim Horton.

Code gets more understandable when TiledCoreAnimationDrawingArea simply uses RunLoopObserver
directly for flush scheduling. LayerFlushScheduler can be later moved to WK1.

* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::TiledCoreAnimationDrawingArea):
(WebKit::TiledCoreAnimationDrawingArea::~TiledCoreAnimationDrawingArea):
(WebKit::TiledCoreAnimationDrawingArea::setLayerTreeStateIsFrozen):
(WebKit::TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlush):
(WebKit::TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition):
(WebKit::TiledCoreAnimationDrawingArea::layerFlushRunLoopCallback):
(WebKit::TiledCoreAnimationDrawingArea::invalidateLayerFlushRunLoopObserver):
(WebKit::TiledCoreAnimationDrawingArea::scheduleLayerFlushRunLoopObserver):

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

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h
Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm

index 8bc3f2c..9b403f2 100644 (file)
@@ -1,3 +1,24 @@
+2018-10-31  Antti Koivisto  <antti@apple.com>
+
+        Stop using LayerFlushScheduler in WK2
+        https://bugs.webkit.org/show_bug.cgi?id=191065
+
+        Reviewed by Tim Horton.
+
+        Code gets more understandable when TiledCoreAnimationDrawingArea simply uses RunLoopObserver
+        directly for flush scheduling. LayerFlushScheduler can be later moved to WK1.
+
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+        (WebKit::TiledCoreAnimationDrawingArea::TiledCoreAnimationDrawingArea):
+        (WebKit::TiledCoreAnimationDrawingArea::~TiledCoreAnimationDrawingArea):
+        (WebKit::TiledCoreAnimationDrawingArea::setLayerTreeStateIsFrozen):
+        (WebKit::TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlush):
+        (WebKit::TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition):
+        (WebKit::TiledCoreAnimationDrawingArea::layerFlushRunLoopCallback):
+        (WebKit::TiledCoreAnimationDrawingArea::invalidateLayerFlushRunLoopObserver):
+        (WebKit::TiledCoreAnimationDrawingArea::scheduleLayerFlushRunLoopObserver):
+
 2018-10-31  Claudio Saavedra  <csaavedra@igalia.com>
 
         [WPE][GTK] Certificates loaded from the cache don't include the certificate chain
index b190a67..4dc35ae 100644 (file)
@@ -31,8 +31,6 @@
 #include "DrawingArea.h"
 #include "LayerTreeContext.h"
 #include <WebCore/FloatRect.h>
-#include <WebCore/LayerFlushScheduler.h>
-#include <WebCore/LayerFlushSchedulerClient.h>
 #include <WebCore/TransformationMatrix.h>
 #include <wtf/HashMap.h>
 #include <wtf/RetainPtr.h>
@@ -43,6 +41,7 @@ OBJC_CLASS CALayer;
 namespace WebCore {
 class FrameView;
 class PlatformCALayer;
+class RunLoopObserver;
 class TiledBacking;
 }
 
@@ -50,7 +49,7 @@ namespace WebKit {
 
 class LayerHostingContext;
 
-class TiledCoreAnimationDrawingArea : public DrawingArea, WebCore::LayerFlushSchedulerClient {
+class TiledCoreAnimationDrawingArea : public DrawingArea {
 public:
     TiledCoreAnimationDrawingArea(WebPage&, const WebPageCreationParameters&);
     virtual ~TiledCoreAnimationDrawingArea();
@@ -88,8 +87,7 @@ private:
 
     bool dispatchDidReachLayoutMilestone(WebCore::LayoutMilestones) override;
 
-    // WebCore::LayerFlushSchedulerClient
-    bool flushLayers() override;
+    bool flushLayers();
 
     // Message handlers.
     void updateGeometry(const WebCore::IntSize& viewSize, bool flushSynchronously, const WTF::MachSendRight& fencePort) override;
@@ -127,8 +125,11 @@ private:
 
     void sendPendingNewlyReachedLayoutMilestones();
 
+    void layerFlushRunLoopCallback();
+    void invalidateLayerFlushRunLoopObserver();
+    void scheduleLayerFlushRunLoopObserver();
+
     bool m_layerTreeStateIsFrozen;
-    WebCore::LayerFlushScheduler m_layerFlushScheduler;
 
     std::unique_ptr<LayerHostingContext> m_layerHostingContext;
 
@@ -164,6 +165,8 @@ private:
 
     WebCore::LayoutMilestones m_pendingNewlyReachedLayoutMilestones { 0 };
     Vector<CallbackID> m_pendingCallbackIDs;
+
+    std::unique_ptr<WebCore::RunLoopObserver> m_layerFlushRunLoopObserver;
 };
 
 } // namespace WebKit
index 17bdb26..669df30 100644 (file)
@@ -51,6 +51,7 @@
 #import <WebCore/RenderLayerBacking.h>
 #import <WebCore/RenderLayerCompositor.h>
 #import <WebCore/RenderView.h>
+#import <WebCore/RunLoopObserver.h>
 #import <WebCore/ScrollbarTheme.h>
 #import <WebCore/Settings.h>
 #import <WebCore/TiledBacking.h>
@@ -75,7 +76,6 @@ using namespace WebCore;
 TiledCoreAnimationDrawingArea::TiledCoreAnimationDrawingArea(WebPage& webPage, const WebPageCreationParameters& parameters)
     : DrawingArea(DrawingAreaTypeTiledCoreAnimation, webPage)
     , m_layerTreeStateIsFrozen(false)
-    , m_layerFlushScheduler(this)
     , m_isPaintingSuspended(!(parameters.activityState & ActivityState::IsVisible))
     , m_transientZoomScale(1)
     , m_sendDidUpdateActivityStateTimer(RunLoop::main(), this, &TiledCoreAnimationDrawingArea::didUpdateActivityStateTimerFired)
@@ -89,6 +89,10 @@ TiledCoreAnimationDrawingArea::TiledCoreAnimationDrawingArea(WebPage& webPage, c
     [m_hostingLayer setOpaque:YES];
     [m_hostingLayer setGeometryFlipped:YES];
 
+    m_layerFlushRunLoopObserver = std::make_unique<WebCore::RunLoopObserver>(static_cast<CFIndex>(RunLoopObserver::WellKnownRunLoopOrders::LayerFlush), [this]() {
+        this->layerFlushRunLoopCallback();
+    });
+
     updateLayerHostingContext();
     setColorSpace(parameters.colorSpace);
 
@@ -98,10 +102,9 @@ TiledCoreAnimationDrawingArea::TiledCoreAnimationDrawingArea(WebPage& webPage, c
 
 TiledCoreAnimationDrawingArea::~TiledCoreAnimationDrawingArea()
 {
-    m_layerFlushScheduler.invalidate();
+    invalidateLayerFlushRunLoopObserver();
 }
 
-
 void TiledCoreAnimationDrawingArea::attach()
 {
     LayerTreeContext layerTreeContext;
@@ -170,10 +173,11 @@ void TiledCoreAnimationDrawingArea::setLayerTreeStateIsFrozen(bool layerTreeStat
         return;
 
     m_layerTreeStateIsFrozen = layerTreeStateIsFrozen;
+
     if (m_layerTreeStateIsFrozen)
-        m_layerFlushScheduler.suspend();
+        invalidateLayerFlushRunLoopObserver();
     else
-        m_layerFlushScheduler.resume();
+        scheduleLayerFlushRunLoopObserver();
 }
 
 bool TiledCoreAnimationDrawingArea::layerTreeStateIsFrozen() const
@@ -183,7 +187,10 @@ bool TiledCoreAnimationDrawingArea::layerTreeStateIsFrozen() const
 
 void TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlush()
 {
-    m_layerFlushScheduler.schedule();
+    if (m_layerTreeStateIsFrozen)
+        return;
+
+    scheduleLayerFlushRunLoopObserver();
 }
 
 void TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlushImmediately()
@@ -374,7 +381,7 @@ void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(W
     m_webPage.corePage()->scrollingCoordinator()->commitTreeStateIfNeeded();
 
     if (!m_layerTreeStateIsFrozen)
-        m_layerFlushScheduler.suspend();
+        invalidateLayerFlushRunLoopObserver();
 
     // It is possible for the drawing area to be destroyed before the bound block
     // is invoked, so grab a reference to the web page here so we can access the drawing area through it.
@@ -389,7 +396,7 @@ void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(W
         function();
 
         if (!m_layerTreeStateIsFrozen)
-            m_layerFlushScheduler.resume();
+            scheduleLayerFlushRunLoopObserver();
 
         webPage->deref();
     });
@@ -415,7 +422,8 @@ void TiledCoreAnimationDrawingArea::addTransactionCallbackID(CallbackID callback
 
 bool TiledCoreAnimationDrawingArea::flushLayers()
 {
-    ASSERT(!m_layerTreeStateIsFrozen);
+    if (layerTreeStateIsFrozen())
+        return false;
 
     @autoreleasepool {
         scaleViewToFitDocumentIfNeeded();
@@ -567,8 +575,7 @@ void TiledCoreAnimationDrawingArea::updateGeometry(const IntSize& viewSize, bool
         size = contentSize;
     }
 
-    if (!m_layerTreeStateIsFrozen)
-        flushLayers();
+    flushLayers();
 
     [CATransaction begin];
     [CATransaction setDisableActions:YES];
@@ -889,6 +896,22 @@ bool TiledCoreAnimationDrawingArea::dispatchDidReachLayoutMilestone(WebCore::Lay
     return true;
 }
 
+void TiledCoreAnimationDrawingArea::layerFlushRunLoopCallback()
+{
+    if (flushLayers())
+        invalidateLayerFlushRunLoopObserver();
+}
+
+void TiledCoreAnimationDrawingArea::invalidateLayerFlushRunLoopObserver()
+{
+    m_layerFlushRunLoopObserver->invalidate();
+}
+
+void TiledCoreAnimationDrawingArea::scheduleLayerFlushRunLoopObserver()
+{
+    m_layerFlushRunLoopObserver->schedule(CFRunLoopGetCurrent());
+}
+
 } // namespace WebKit
 
 #endif // !PLATFORM(IOS_FAMILY)