<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[286977] branches/safari-612-branch/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/286977">286977</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2021-12-13 12:57:05 -0800 (Mon, 13 Dec 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/286905">r286905</a>. rdar://problem/86235740

    Scrolling can drop frames when CoreAnimation commits take a long time
    https://bugs.webkit.org/show_bug.cgi?id=234160
    <rdar://86235740>

    Reviewed by Tim Horton.

    In <a href="http://trac.webkit.org/projects/webkit/changeset/261985">r261985</a> I added a mechanism that has the scrolling thread wait for the main thread to
    finish a rendering update, and, if the main thread fails to complete in time, then the
    scrolling thread commits. This allows for scrolling synchronization when the main thread is
    responsive, but smooth scrolling when the main thread is busy.

    However, <a href="http://trac.webkit.org/projects/webkit/changeset/261985">r261985</a> only waits for WebKit work to finish; what we really care about is whether
    the main thread completes its CA commit in time (because that determines whether the scroll
    shows on the screen).

    So plumb through pre-/post-commit hooks from TiledCoreAnimationDrawingArea, which already
    had them for inspector instrumentation. Then have ThreadedScrollingTree notify
    m_stateCondition in didCompletePlatformRenderingUpdate(), instead of
    didCompleteRenderingUpdate().
    Source/WebCore:

    Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.

    * page/Page.cpp:
    (WebCore::Page::willStartPlatformRenderingUpdate):
    (WebCore::Page::didCompletePlatformRenderingUpdate):
    * page/Page.h:
    * page/scrolling/ScrollingCoordinator.h:
    (WebCore::ScrollingCoordinator::willStartPlatformRenderingUpdate):
    (WebCore::ScrollingCoordinator::didCompletePlatformRenderingUpdate):
    * page/scrolling/ThreadedScrollingTree.cpp:
    (WebCore::ThreadedScrollingTree::didCompletePlatformRenderingUpdate):
    (WebCore::ThreadedScrollingTree::didCompleteRenderingUpdate): Deleted.
    * page/scrolling/ThreadedScrollingTree.h:
    * page/scrolling/mac/ScrollingCoordinatorMac.h:
    * page/scrolling/mac/ScrollingCoordinatorMac.mm:
    (WebCore::ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate):

    Source/WebKit:

    Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.

    * WebProcess/WebPage/WebPage.cpp:
    (WebKit::WebPage::willStartPlatformRenderingUpdate):
    (WebKit::WebPage::didCompletePlatformRenderingUpdate):
    * WebProcess/WebPage/WebPage.h:
    * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
    (WebKit::TiledCoreAnimationDrawingArea::addCommitHandlers):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286905 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari612branchSourceWebCoreChangeLog">branches/safari-612-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagePagecpp">branches/safari-612-branch/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagePageh">branches/safari-612-branch/Source/WebCore/page/Page.h</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagescrollingScrollingCoordinatorh">branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingCoordinator.h</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagescrollingThreadedScrollingTreecpp">branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagescrollingThreadedScrollingTreeh">branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.h</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagescrollingmacScrollingCoordinatorMach">branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.h</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagescrollingmacScrollingCoordinatorMacmm">branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm</a></li>
<li><a href="#branchessafari612branchSourceWebKitChangeLog">branches/safari-612-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceWebKitWebProcessWebPageWebPagecpp">branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebKitWebProcessWebPageWebPageh">branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#branchessafari612branchSourceWebKitWebProcessWebPagemacTiledCoreAnimationDrawingAreamm">branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari612branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/ChangeLog      2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog 2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -1,5 +1,99 @@
</span><span class="cx"> 2021-12-13  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r286905. rdar://problem/86235740
+
+    Scrolling can drop frames when CoreAnimation commits take a long time
+    https://bugs.webkit.org/show_bug.cgi?id=234160
+    <rdar://86235740>
+    
+    Reviewed by Tim Horton.
+    
+    In r261985 I added a mechanism that has the scrolling thread wait for the main thread to
+    finish a rendering update, and, if the main thread fails to complete in time, then the
+    scrolling thread commits. This allows for scrolling synchronization when the main thread is
+    responsive, but smooth scrolling when the main thread is busy.
+    
+    However, r261985 only waits for WebKit work to finish; what we really care about is whether
+    the main thread completes its CA commit in time (because that determines whether the scroll
+    shows on the screen).
+    
+    So plumb through pre-/post-commit hooks from TiledCoreAnimationDrawingArea, which already
+    had them for inspector instrumentation. Then have ThreadedScrollingTree notify
+    m_stateCondition in didCompletePlatformRenderingUpdate(), instead of
+    didCompleteRenderingUpdate().
+    Source/WebCore:
+    
+    Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.
+    
+    * page/Page.cpp:
+    (WebCore::Page::willStartPlatformRenderingUpdate):
+    (WebCore::Page::didCompletePlatformRenderingUpdate):
+    * page/Page.h:
+    * page/scrolling/ScrollingCoordinator.h:
+    (WebCore::ScrollingCoordinator::willStartPlatformRenderingUpdate):
+    (WebCore::ScrollingCoordinator::didCompletePlatformRenderingUpdate):
+    * page/scrolling/ThreadedScrollingTree.cpp:
+    (WebCore::ThreadedScrollingTree::didCompletePlatformRenderingUpdate):
+    (WebCore::ThreadedScrollingTree::didCompleteRenderingUpdate): Deleted.
+    * page/scrolling/ThreadedScrollingTree.h:
+    * page/scrolling/mac/ScrollingCoordinatorMac.h:
+    * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+    (WebCore::ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate):
+    
+    Source/WebKit:
+    
+    Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.
+    
+    * WebProcess/WebPage/WebPage.cpp:
+    (WebKit::WebPage::willStartPlatformRenderingUpdate):
+    (WebKit::WebPage::didCompletePlatformRenderingUpdate):
+    * WebProcess/WebPage/WebPage.h:
+    * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+    (WebKit::TiledCoreAnimationDrawingArea::addCommitHandlers):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286905 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-10  Simon Fraser  <simon.fraser@apple.com>
+
+            Scrolling can drop frames when CoreAnimation commits take a long time
+            https://bugs.webkit.org/show_bug.cgi?id=234160
+            <rdar://86235740>
+
+            Reviewed by Tim Horton.
+
+            In r261985 I added a mechanism that has the scrolling thread wait for the main thread to
+            finish a rendering update, and, if the main thread fails to complete in time, then the
+            scrolling thread commits. This allows for scrolling synchronization when the main thread is
+            responsive, but smooth scrolling when the main thread is busy.
+
+            However, r261985 only waits for WebKit work to finish; what we really care about is whether
+            the main thread completes its CA commit in time (because that determines whether the scroll
+            shows on the screen).
+
+            So plumb through pre-/post-commit hooks from TiledCoreAnimationDrawingArea, which already
+            had them for inspector instrumentation. Then have ThreadedScrollingTree notify
+            m_stateCondition in didCompletePlatformRenderingUpdate(), instead of
+            didCompleteRenderingUpdate().
+
+            Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.
+
+            * page/Page.cpp:
+            (WebCore::Page::willStartPlatformRenderingUpdate):
+            (WebCore::Page::didCompletePlatformRenderingUpdate):
+            * page/Page.h:
+            * page/scrolling/ScrollingCoordinator.h:
+            (WebCore::ScrollingCoordinator::willStartPlatformRenderingUpdate):
+            (WebCore::ScrollingCoordinator::didCompletePlatformRenderingUpdate):
+            * page/scrolling/ThreadedScrollingTree.cpp:
+            (WebCore::ThreadedScrollingTree::didCompletePlatformRenderingUpdate):
+            (WebCore::ThreadedScrollingTree::didCompleteRenderingUpdate): Deleted.
+            * page/scrolling/ThreadedScrollingTree.h:
+            * page/scrolling/mac/ScrollingCoordinatorMac.h:
+            * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+            (WebCore::ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate):
+
+2021-12-13  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r286932. rdar://problem/86385697
</span><span class="cx"> 
</span><span class="cx">     Ensure that the scrolling thread always commits layer position changes to reduce scrolling stutters
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/Page.cpp (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/Page.cpp  2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/page/Page.cpp     2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -1765,6 +1765,24 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Page::willStartPlatformRenderingUpdate()
+{
+    // Inspector's use of "composite" is rather innacurate. On Apple platforms, the "composite" step happens
+    // in another process; these hooks wrap the non-WebKit CA commit time which is mostly painting-related.
+    m_inspectorController->willComposite(mainFrame());
+
+    if (m_scrollingCoordinator)
+        m_scrollingCoordinator->willStartPlatformRenderingUpdate();
+}
+
+void Page::didCompletePlatformRenderingUpdate()
+{
+    if (m_scrollingCoordinator)
+        m_scrollingCoordinator->didCompletePlatformRenderingUpdate();
+
+    m_inspectorController->didComposite(mainFrame());
+}
+
</ins><span class="cx"> void Page::prioritizeVisibleResources()
</span><span class="cx"> {
</span><span class="cx">     if (loadSchedulingMode() == LoadSchedulingMode::Direct)
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/Page.h (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/Page.h    2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/page/Page.h       2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -584,6 +584,11 @@
</span><span class="cx">     WEBCORE_EXPORT void startTrackingRenderingUpdates();
</span><span class="cx">     WEBCORE_EXPORT unsigned renderingUpdateCount() const;
</span><span class="cx"> 
</span><ins>+    // A "platform rendering update" here describes the work done by the system graphics framework before work is submitted to the system compositor.
+    // On macOS, this is a CoreAnimation commit.
+    WEBCORE_EXPORT void willStartPlatformRenderingUpdate();
+    WEBCORE_EXPORT void didCompletePlatformRenderingUpdate();
+
</ins><span class="cx">     WEBCORE_EXPORT void suspendScriptedAnimations();
</span><span class="cx">     WEBCORE_EXPORT void resumeScriptedAnimations();
</span><span class="cx">     bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingScrollingCoordinatorh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingCoordinator.h (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingCoordinator.h  2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingCoordinator.h     2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -102,6 +102,9 @@
</span><span class="cx">     virtual void willStartRenderingUpdate() { }
</span><span class="cx">     virtual void didCompleteRenderingUpdate() { }
</span><span class="cx"> 
</span><ins>+    virtual void willStartPlatformRenderingUpdate() { }
+    virtual void didCompletePlatformRenderingUpdate() { }
+
</ins><span class="cx"> #if ENABLE(KINETIC_SCROLLING)
</span><span class="cx">     // Dispatched by the scrolling tree during handleWheelEvent. This is required as long as scrollbars are painted on the main thread.
</span><span class="cx">     virtual void handleWheelEventPhase(ScrollingNodeID, PlatformWheelEventPhase) { }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingThreadedScrollingTreecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp       2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp  2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -310,7 +310,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // This code allows the main thread about half a frame to complete its rendering udpate. If the main thread
</span><del>-// is responsive (i.e. managing to render every frame), then we expect to get a didCompleteRenderingUpdate()
</del><ins>+// is responsive (i.e. managing to render every frame), then we expect to get a didCompletePlatformRenderingUpdate()
</ins><span class="cx"> // within 8ms of willStartRenderingUpdate(). We time this via m_stateCondition, which blocks the scrolling
</span><span class="cx"> // thread (with m_treeLock locked at the start and end) so that we don't handle wheel events while waiting.
</span><span class="cx"> // If the condition times out, we know the main thread is being slow, and allow the scrolling thread to
</span><span class="lines">@@ -351,7 +351,21 @@
</span><span class="cx"> 
</span><span class="cx"> void ThreadedScrollingTree::didCompleteRenderingUpdate()
</span><span class="cx"> {
</span><ins>+    // macOS needs to wait for the CA commit (the "platform rendering update").
+#if !PLATFORM(MAC)
+    renderingUpdateComplete();
+#endif
+}
+
+void ThreadedScrollingTree::didCompletePlatformRenderingUpdate()
+{
+    renderingUpdateComplete();
+}
+
+void ThreadedScrollingTree::renderingUpdateComplete()
+{
</ins><span class="cx">     ASSERT(isMainThread());
</span><ins>+
</ins><span class="cx">     Locker locker { m_treeLock };
</span><span class="cx"> 
</span><span class="cx">     if (m_state == SynchronizationState::InRenderingUpdate)
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingThreadedScrollingTreeh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.h (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.h 2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.h    2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -60,6 +60,8 @@
</span><span class="cx">     void willStartRenderingUpdate();
</span><span class="cx">     void didCompleteRenderingUpdate();
</span><span class="cx"> 
</span><ins>+    void didCompletePlatformRenderingUpdate();
+
</ins><span class="cx">     Lock& treeLock() WTF_RETURNS_LOCK(m_treeLock) { return m_treeLock; }
</span><span class="cx"> 
</span><span class="cx">     bool scrollAnimatorEnabled() const { return m_scrollAnimatorEnabled; }
</span><span class="lines">@@ -88,6 +90,7 @@
</span><span class="cx"> 
</span><span class="cx">     void displayDidRefreshOnScrollingThread();
</span><span class="cx">     void waitForRenderingUpdateCompletionOrTimeout() WTF_REQUIRES_LOCK(m_treeLock);
</span><ins>+    void renderingUpdateComplete();
</ins><span class="cx"> 
</span><span class="cx">     bool canUpdateLayersOnScrollingThread() const WTF_REQUIRES_LOCK(m_treeLock);
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingmacScrollingCoordinatorMach"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.h (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.h   2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.h      2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -50,6 +50,8 @@
</span><span class="cx">     void willStartRenderingUpdate() final;
</span><span class="cx">     void didCompleteRenderingUpdate() final;
</span><span class="cx"> 
</span><ins>+    void didCompletePlatformRenderingUpdate() final;
+
</ins><span class="cx">     void updateTiledScrollingIndicator();
</span><span class="cx"> 
</span><span class="cx">     void startMonitoringWheelEvents(bool clearLatchingState) final;
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingmacScrollingCoordinatorMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm  2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm     2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -135,6 +135,11 @@
</span><span class="cx">     downcast<ThreadedScrollingTree>(scrollingTree())->didCompleteRenderingUpdate();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate()
+{
+    downcast<ThreadedScrollingTree>(scrollingTree())->didCompletePlatformRenderingUpdate();
+}
+
</ins><span class="cx"> void ScrollingCoordinatorMac::updateTiledScrollingIndicator()
</span><span class="cx"> {
</span><span class="cx">     FrameView* frameView = m_page->mainFrame().view();
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/ChangeLog       2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog  2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -1,5 +1,91 @@
</span><span class="cx"> 2021-12-13  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r286905. rdar://problem/86235740
+
+    Scrolling can drop frames when CoreAnimation commits take a long time
+    https://bugs.webkit.org/show_bug.cgi?id=234160
+    <rdar://86235740>
+    
+    Reviewed by Tim Horton.
+    
+    In r261985 I added a mechanism that has the scrolling thread wait for the main thread to
+    finish a rendering update, and, if the main thread fails to complete in time, then the
+    scrolling thread commits. This allows for scrolling synchronization when the main thread is
+    responsive, but smooth scrolling when the main thread is busy.
+    
+    However, r261985 only waits for WebKit work to finish; what we really care about is whether
+    the main thread completes its CA commit in time (because that determines whether the scroll
+    shows on the screen).
+    
+    So plumb through pre-/post-commit hooks from TiledCoreAnimationDrawingArea, which already
+    had them for inspector instrumentation. Then have ThreadedScrollingTree notify
+    m_stateCondition in didCompletePlatformRenderingUpdate(), instead of
+    didCompleteRenderingUpdate().
+    Source/WebCore:
+    
+    Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.
+    
+    * page/Page.cpp:
+    (WebCore::Page::willStartPlatformRenderingUpdate):
+    (WebCore::Page::didCompletePlatformRenderingUpdate):
+    * page/Page.h:
+    * page/scrolling/ScrollingCoordinator.h:
+    (WebCore::ScrollingCoordinator::willStartPlatformRenderingUpdate):
+    (WebCore::ScrollingCoordinator::didCompletePlatformRenderingUpdate):
+    * page/scrolling/ThreadedScrollingTree.cpp:
+    (WebCore::ThreadedScrollingTree::didCompletePlatformRenderingUpdate):
+    (WebCore::ThreadedScrollingTree::didCompleteRenderingUpdate): Deleted.
+    * page/scrolling/ThreadedScrollingTree.h:
+    * page/scrolling/mac/ScrollingCoordinatorMac.h:
+    * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+    (WebCore::ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate):
+    
+    Source/WebKit:
+    
+    Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.
+    
+    * WebProcess/WebPage/WebPage.cpp:
+    (WebKit::WebPage::willStartPlatformRenderingUpdate):
+    (WebKit::WebPage::didCompletePlatformRenderingUpdate):
+    * WebProcess/WebPage/WebPage.h:
+    * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+    (WebKit::TiledCoreAnimationDrawingArea::addCommitHandlers):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286905 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-10  Simon Fraser  <simon.fraser@apple.com>
+
+            Scrolling can drop frames when CoreAnimation commits take a long time
+            https://bugs.webkit.org/show_bug.cgi?id=234160
+            <rdar://86235740>
+
+            Reviewed by Tim Horton.
+
+            In r261985 I added a mechanism that has the scrolling thread wait for the main thread to
+            finish a rendering update, and, if the main thread fails to complete in time, then the
+            scrolling thread commits. This allows for scrolling synchronization when the main thread is
+            responsive, but smooth scrolling when the main thread is busy.
+
+            However, r261985 only waits for WebKit work to finish; what we really care about is whether
+            the main thread completes its CA commit in time (because that determines whether the scroll
+            shows on the screen).
+
+            So plumb through pre-/post-commit hooks from TiledCoreAnimationDrawingArea, which already
+            had them for inspector instrumentation. Then have ThreadedScrollingTree notify
+            m_stateCondition in didCompletePlatformRenderingUpdate(), instead of
+            didCompleteRenderingUpdate().
+
+            Also, now we can call the inspector hooks from Page, rather than out in TiledCoreAnimationDrawingArea.
+
+            * WebProcess/WebPage/WebPage.cpp:
+            (WebKit::WebPage::willStartPlatformRenderingUpdate):
+            (WebKit::WebPage::didCompletePlatformRenderingUpdate):
+            * WebProcess/WebPage/WebPage.h:
+            * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+            (WebKit::TiledCoreAnimationDrawingArea::addCommitHandlers):
+
+2021-12-13  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r286834. rdar://problem/86235740
</span><span class="cx"> 
</span><span class="cx">     Inspector "composite" events are all very short
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitWebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp  2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp     2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -4244,6 +4244,20 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::willStartPlatformRenderingUpdate()
+{
+    if (m_isClosed)
+        return;
+    m_page->willStartPlatformRenderingUpdate();
+}
+
+void WebPage::didCompletePlatformRenderingUpdate()
+{
+    if (m_isClosed)
+        return;
+    m_page->didCompletePlatformRenderingUpdate();
+}
+
</ins><span class="cx"> void WebPage::releaseMemory(Critical)
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(GPU_PROCESS)
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.h (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.h    2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/WebPage.h       2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -659,6 +659,11 @@
</span><span class="cx"> 
</span><span class="cx">     void didUpdateRendering();
</span><span class="cx"> 
</span><ins>+    // A "platform rendering update" here describes the work done by the system graphics framework before work is submitted to the system compositor.
+    // On macOS, this is a CoreAnimation commit.
+    void willStartPlatformRenderingUpdate();
+    void didCompletePlatformRenderingUpdate();
+
</ins><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     void setTopOverhangImage(WebImage*);
</span><span class="cx">     void setBottomOverhangImage(WebImage*);
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitWebProcessWebPagemacTiledCoreAnimationDrawingAreamm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm (286976 => 286977)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm 2021-12-13 20:57:00 UTC (rev 286976)
+++ branches/safari-612-branch/Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm    2021-12-13 20:57:05 UTC (rev 286977)
</span><span class="lines">@@ -422,20 +422,15 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     [CATransaction addCommitHandler:[retainedPage = makeRefPtr(&m_webPage)] {
</span><del>-        if (Page* corePage = retainedPage->corePage()) {
-            if (Frame* coreFrame = retainedPage->mainFrame())
-                corePage->inspectorController().willComposite(*coreFrame);
-        }
</del><ins>+        retainedPage->willStartPlatformRenderingUpdate();
</ins><span class="cx">     } forPhase:kCATransactionPhasePreLayout];
</span><span class="cx"> 
</span><span class="cx">     [CATransaction addCommitHandler:[retainedPage = makeRefPtr(&m_webPage)] {
</span><del>-        if (Page* corePage = retainedPage->corePage()) {
-            if (Frame* coreFrame = retainedPage->mainFrame())
-                corePage->inspectorController().didComposite(*coreFrame);
-        }
</del><span class="cx">         if (auto drawingArea = static_cast<TiledCoreAnimationDrawingArea*>(retainedPage->drawingArea()))
</span><span class="cx">             drawingArea->sendPendingNewlyReachedPaintingMilestones();
</span><ins>+
</ins><span class="cx">         retainedPage->setFirstFlushAfterCommit(false);
</span><ins>+        retainedPage->didCompletePlatformRenderingUpdate();
</ins><span class="cx">     } forPhase:kCATransactionPhasePostCommit];
</span><span class="cx">     
</span><span class="cx">     m_webPage.setFirstFlushAfterCommit(true);
</span></span></pre>
</div>
</div>

</body>
</html>