Avoid potential longer than expected layer flush delays
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2018 09:02:25 +0000 (09:02 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2018 09:02:25 +0000 (09:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191833

Reviewed by Dean Jackson.

Layer flush throttling also stops style recalcs and layouts. Layouts schedule layer flushes. Especially
on a slow network we can in principle end up in situation where layer flush timer fires but there is no
flush scheduled and so nothing happens. However there is a pending style recalc or layout that would
actually schedule a flush (in practice various things force style recalcs and this doesn't occur
commonly).

To avoid this we should flush unconditionally when the flush timer fires. This performs any pending
style recalc and layout too. If there is nothing to do the flush will be cheap.

PLT doesn't appear to hit cases affected by this patch and there shouldn't be any impact.

* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:

Remove now unnecessary m_hasPendingFlush bit, simplifying the logic.

* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::setLayerTreeStateIsFrozen):

Schedule unconditionally when unfreezing.

(WebKit::TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlush):

Remove branch that starts the flush timer. It is not needed as either it was already running
or immediate flush is already scheduled and will start the timer anyway.

(WebKit::TiledCoreAnimationDrawingArea::flushLayers):
(WebKit::TiledCoreAnimationDrawingArea::adjustLayerFlushThrottling):
(WebKit::TiledCoreAnimationDrawingArea::layerFlushThrottlingTimerFired):

Flush unconditionally.

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

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

index 7aa7384..98f5456 100644 (file)
@@ -1,3 +1,41 @@
+2018-11-20  Antti Koivisto  <antti@apple.com>
+
+        Avoid potential longer than expected layer flush delays
+        https://bugs.webkit.org/show_bug.cgi?id=191833
+
+        Reviewed by Dean Jackson.
+
+        Layer flush throttling also stops style recalcs and layouts. Layouts schedule layer flushes. Especially
+        on a slow network we can in principle end up in situation where layer flush timer fires but there is no
+        flush scheduled and so nothing happens. However there is a pending style recalc or layout that would
+        actually schedule a flush (in practice various things force style recalcs and this doesn't occur
+        commonly).
+
+        To avoid this we should flush unconditionally when the flush timer fires. This performs any pending
+        style recalc and layout too. If there is nothing to do the flush will be cheap.
+
+        PLT doesn't appear to hit cases affected by this patch and there shouldn't be any impact.
+
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
+
+        Remove now unnecessary m_hasPendingFlush bit, simplifying the logic.
+
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+        (WebKit::TiledCoreAnimationDrawingArea::setLayerTreeStateIsFrozen):
+
+        Schedule unconditionally when unfreezing.
+
+        (WebKit::TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlush):
+
+        Remove branch that starts the flush timer. It is not needed as either it was already running
+        or immediate flush is already scheduled and will start the timer anyway.
+
+        (WebKit::TiledCoreAnimationDrawingArea::flushLayers):
+        (WebKit::TiledCoreAnimationDrawingArea::adjustLayerFlushThrottling):
+        (WebKit::TiledCoreAnimationDrawingArea::layerFlushThrottlingTimerFired):
+
+        Flush unconditionally.
+
 2018-11-19  Don Olmstead  <don.olmstead@sony.com>
 
         Simplify platform check in WebEditorClient
index d1eb193..b1ed5c1 100644 (file)
@@ -177,7 +177,6 @@ private:
 
     bool m_isThrottlingLayerFlushes { false };
     bool m_isLayerFlushThrottlingTemporarilyDisabledForInteraction { false };
-    bool m_hasPendingFlush { false };
 
     WebCore::Timer m_layerFlushThrottlingTimer;
 };
index a791e93..358f967 100644 (file)
@@ -180,8 +180,7 @@ void TiledCoreAnimationDrawingArea::setLayerTreeStateIsFrozen(bool layerTreeStat
         m_layerFlushThrottlingTimer.stop();
     } else {
         // Immediate flush as any delay in unfreezing can result in flashes.
-        if (m_hasPendingFlush)
-            scheduleLayerFlushRunLoopObserver();
+        scheduleLayerFlushRunLoopObserver();
     }
 }
 
@@ -196,8 +195,6 @@ void TiledCoreAnimationDrawingArea::scheduleInitialDeferredPaint()
 
 void TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlush()
 {
-    m_hasPendingFlush = true;
-
     if (m_layerTreeStateIsFrozen) {
         m_isLayerFlushThrottlingTemporarilyDisabledForInteraction = false;
         return;
@@ -215,11 +212,6 @@ void TiledCoreAnimationDrawingArea::scheduleCompositingLayerFlush()
         return;
     }
 
-    if (m_isThrottlingLayerFlushes) {
-        startLayerFlushThrottlingTimer();
-        return;
-    }
-
     scheduleLayerFlushRunLoopObserver();
 }
 
@@ -487,7 +479,7 @@ void TiledCoreAnimationDrawingArea::flushLayers()
                 drawingArea->sendPendingNewlyReachedLayoutMilestones();
         } forPhase:kCATransactionPhasePostCommit];
 
-        m_hasPendingFlush = !m_webPage.mainFrameView()->flushCompositingStateIncludingSubframes();
+        bool didFlushAllFrames = m_webPage.mainFrameView()->flushCompositingStateIncludingSubframes();
 
 #if ENABLE(ASYNC_SCROLLING)
         if (ScrollingCoordinator* scrollingCoordinator = m_webPage.corePage()->scrollingCoordinator())
@@ -504,7 +496,7 @@ void TiledCoreAnimationDrawingArea::flushLayers()
             m_pendingCallbackIDs.clear();
         }
 
-        if (!m_hasPendingFlush)
+        if (didFlushAllFrames)
             invalidateLayerFlushRunLoopObserver();
 
         if (m_isThrottlingLayerFlushes)
@@ -965,7 +957,7 @@ bool TiledCoreAnimationDrawingArea::adjustLayerFlushThrottling(WebCore::LayerFlu
     if (m_isThrottlingLayerFlushes) {
         invalidateLayerFlushRunLoopObserver();
         startLayerFlushThrottlingTimer();
-    } else if (m_hasPendingFlush)
+    } else
         scheduleLayerFlushRunLoopObserver();
 
     return true;
@@ -988,8 +980,6 @@ void TiledCoreAnimationDrawingArea::layerFlushThrottlingTimerFired()
 {
     if (m_layerTreeStateIsFrozen)
         return;
-    if (!m_hasPendingFlush)
-        return;
     scheduleLayerFlushRunLoopObserver();
 }