[CoordinatedGraphics] The compositing loop is still running even after exiting AC...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 18:06:18 +0000 (18:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 18:06:18 +0000 (18:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195270

Patch by Carlos Garcia Campos <cgarcia@igalia.com> on 2019-03-04
Reviewed by Don Olmstead.

Suspend the threaded compositor when the painting is paused or layer flush disabled, and resume it again when
painting is resumed and layer flush enabled.

* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
(WebKit::ThreadedCompositor::suspend): Increment the suspend counter and mark the scene as inactive if it was suspended.
(WebKit::ThreadedCompositor::resume): Decrement the suspend counter and mark the scene as active if it's now resumed.
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
* WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
(WebKit::DrawingAreaCoordinatedGraphics::forceRepaint): Return early if layer tree state is frozen.
(WebKit::DrawingAreaCoordinatedGraphics::forceRepaintAsync): Ditto.
* WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp:
(WebKit::LayerTreeHost::setLayerFlushSchedulingEnabled): Call ThreadedCompositor::suspend()/resume().
(WebKit::LayerTreeHost::pauseRendering): Call ThreadedCompositor::suspend.
(WebKit::LayerTreeHost::resumeRendering): Call ThreadedCompositor::resume().

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

Source/WebKit/ChangeLog
Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp
Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp

index 2f9cf09..06070b2 100644 (file)
@@ -1,3 +1,25 @@
+2019-03-04  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [CoordinatedGraphics] The compositing loop is still running even after exiting AC mode
+        https://bugs.webkit.org/show_bug.cgi?id=195270
+
+        Reviewed by Don Olmstead.
+
+        Suspend the threaded compositor when the painting is paused or layer flush disabled, and resume it again when
+        painting is resumed and layer flush enabled.
+
+        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
+        (WebKit::ThreadedCompositor::suspend): Increment the suspend counter and mark the scene as inactive if it was suspended.
+        (WebKit::ThreadedCompositor::resume): Decrement the suspend counter and mark the scene as active if it's now resumed.
+        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
+        * WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
+        (WebKit::DrawingAreaCoordinatedGraphics::forceRepaint): Return early if layer tree state is frozen.
+        (WebKit::DrawingAreaCoordinatedGraphics::forceRepaintAsync): Ditto.
+        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp:
+        (WebKit::LayerTreeHost::setLayerFlushSchedulingEnabled): Call ThreadedCompositor::suspend()/resume().
+        (WebKit::LayerTreeHost::pauseRendering): Call ThreadedCompositor::suspend.
+        (WebKit::LayerTreeHost::resumeRendering): Call ThreadedCompositor::resume().
+
 2019-03-04  Simon Fraser  <simon.fraser@apple.com>
 
         Share more code between overflow and frame scrolling nodes, fixing overflow scrollbar display
index c1e6b7b..fd4aaf5 100644 (file)
@@ -116,6 +116,28 @@ void ThreadedCompositor::invalidate()
     m_compositingRunLoop = nullptr;
 }
 
+void ThreadedCompositor::suspend()
+{
+    if (++m_suspendedCount > 1)
+        return;
+
+    m_compositingRunLoop->stopUpdates();
+    m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this)] {
+        m_scene->setActive(false);
+    });
+}
+
+void ThreadedCompositor::resume()
+{
+    ASSERT(m_suspendedCount > 0);
+    if (--m_suspendedCount > 0)
+        return;
+
+    m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this)] {
+        m_scene->setActive(true);
+    });
+}
+
 void ThreadedCompositor::setNativeSurfaceHandleForCompositing(uint64_t handle)
 {
     m_compositingRunLoop->stopUpdates();
index 74d1684..d2f0931 100644 (file)
@@ -84,6 +84,9 @@ public:
 
     void frameComplete();
 
+    void suspend();
+    void resume();
+
 private:
     ThreadedCompositor(Client&, ThreadedDisplayRefreshMonitor::Client&, WebCore::PlatformDisplayID, const WebCore::IntSize&, float scaleFactor, ShouldDoFrameSync, WebCore::TextureMapper::PaintFlags);
 
@@ -103,6 +106,7 @@ private:
     ShouldDoFrameSync m_doFrameSync;
     WebCore::TextureMapper::PaintFlags m_paintFlags { 0 };
     bool m_inForceRepaint { false };
+    unsigned m_suspendedCount { 0 };
 
     std::unique_ptr<CompositingRunLoop> m_compositingRunLoop;
 
index 8c2a7e5..c97e253 100644 (file)
@@ -175,6 +175,9 @@ void DrawingAreaCoordinatedGraphics::forceRepaint()
         return;
     }
 
+    if (m_layerTreeStateIsFrozen)
+        return;
+
     setNeedsDisplay();
     m_webPage.layoutIfNeeded();
     if (!m_layerTreeHost)
@@ -195,6 +198,9 @@ void DrawingAreaCoordinatedGraphics::forceRepaint()
 
 bool DrawingAreaCoordinatedGraphics::forceRepaintAsync(CallbackID callbackID)
 {
+    if (m_layerTreeStateIsFrozen)
+        return false;
+
     return m_layerTreeHost && m_layerTreeHost->forceRepaintAsync(callbackID);
 }
 
index aa2a033..ad16b6c 100644 (file)
@@ -106,11 +106,13 @@ void LayerTreeHost::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
     m_layerFlushSchedulingEnabled = layerFlushingEnabled;
 
     if (m_layerFlushSchedulingEnabled) {
+        m_compositor->resume();
         scheduleLayerFlush();
         return;
     }
 
     cancelPendingLayerFlush();
+    m_compositor->suspend();
 }
 
 void LayerTreeHost::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush)
@@ -248,11 +250,13 @@ void LayerTreeHost::sizeDidChange(const IntSize& size)
 void LayerTreeHost::pauseRendering()
 {
     m_isSuspended = true;
+    m_compositor->suspend();
 }
 
 void LayerTreeHost::resumeRendering()
 {
     m_isSuspended = false;
+    m_compositor->resume();
     scheduleLayerFlush();
 }