<!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>[287155] branches/safari-612-branch/Source/WebCore</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/287155">287155</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2021-12-16 13:20:10 -0800 (Thu, 16 Dec 2021)</dd>
</dl>
<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/287079">r287079</a>. rdar://problem/85892959
This reverts <a href="http://trac.webkit.org/projects/webkit/changeset/287150">r287150</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari612branchSourceWebCoreChangeLog">branches/safari-612-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceWebCoreSourcesCocoatxt">branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt</a></li>
<li><a href="#branchessafari612branchSourceWebCoreWebCorexcodeprojprojectpbxproj">branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagescrollingScrollingTreeh">branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingTree.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="#branchessafari612branchSourceWebCorepagescrollingmacScrollingTreeMach">branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.h</a></li>
<li><a href="#branchessafari612branchSourceWebCorepagescrollingmacScrollingTreeMacmm">branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.mm</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscaGraphicsLayerCAcpp">branches/safari-612-branch/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscaPlatformCALayercpp">branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscaPlatformCALayerh">branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.h</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerCocoah">branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerCocoamm">branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerContentsDelayedReleaserh">branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.h</a></li>
<li><a href="#branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerContentsDelayedReleasermm">branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.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 (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/ChangeLog 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -1,3 +1,123 @@
</span><ins>+2021-12-15 Alan Coon <alancoon@apple.com>
+
+ Cherry-pick r287079. rdar://problem/85892959
+
+ Twitter scroll stutter: ensure that CA backing store is always deallocated on the main thread
+ https://bugs.webkit.org/show_bug.cgi?id=234328
+ <rdar://85892959>
+
+ Reviewed by Tim Horton.
+
+ When scrolling pages like Twitter and Facebook we observed CoreAnimation commits on the
+ scrolling thread taking longer than they should because CABackingStore objects were being
+ released in those transactions.
+
+ Work around this issue by extending the lifetime of CABackingStore objects if we detect that
+ they might be entrained into a scrolling tree commit, by virtue of having overlapping main
+ thread and scrolling thread commits.
+
+ The logic is contained in PlatformCALayerContentsDelayedReleaser, which puts layer contents
+ into a retaining vector when they are being cleared on the layer. They are released at the
+ end of a main thread commit; if we detected overlapping commits, then we release on a
+ dispatch to extend the lifetime slightly.
+
+ The remaining changes are plumbing to get commit willBegin/didEnd messages to PlatformCALayerContentsDelayedReleaser
+ for main and scrolling threads.
+
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * page/scrolling/ScrollingTree.h:
+ * page/scrolling/ThreadedScrollingTree.h:
+ * page/scrolling/mac/ScrollingCoordinatorMac.h:
+ * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+ (WebCore::ScrollingCoordinatorMac::willStartPlatformRenderingUpdate):
+ (WebCore::ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate):
+ * page/scrolling/mac/ScrollingTreeMac.h:
+ * page/scrolling/mac/ScrollingTreeMac.mm:
+ (ScrollingTreeMac::applyLayerPositionsInternal):
+ (ScrollingTreeMac::registerForPlatformRenderingUpdateCallback):
+ * platform/graphics/ca/GraphicsLayerCA.cpp:
+ (WebCore::GraphicsLayerCA::updateContentsVisibility):
+ (WebCore::GraphicsLayerCA::updateDrawsContent):
+ * platform/graphics/ca/PlatformCALayer.cpp:
+ (WebCore::PlatformCALayer::clearContents):
+ * platform/graphics/ca/PlatformCALayer.h:
+ * platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
+ * platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
+ (WebCore::PlatformCALayerCocoa::setBackingStoreAttached):
+ (WebCore::PlatformCALayerCocoa::clearContents):
+ * platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.h: Added.
+ (WebCore::PlatformCALayerContentsDelayedReleaser::WTF_GUARDED_BY_LOCK):
+ * platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.mm: Added.
+ (WebCore::PlatformCALayerContentsDelayedReleaser::singleton):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::takeLayerContents):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::mainThreadCommitWillStart):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::mainThreadCommitDidEnd):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::scrollingThreadCommitWillStart):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::scrollingThreadCommitDidEnd):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::updateSawOverlappingCommit):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::clearRetainedContents):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-12-15 Simon Fraser <simon.fraser@apple.com>
+
+ Twitter scroll stutter: ensure that CA backing store is always deallocated on the main thread
+ https://bugs.webkit.org/show_bug.cgi?id=234328
+ <rdar://85892959>
+
+ Reviewed by Tim Horton.
+
+ When scrolling pages like Twitter and Facebook we observed CoreAnimation commits on the
+ scrolling thread taking longer than they should because CABackingStore objects were being
+ released in those transactions.
+
+ Work around this issue by extending the lifetime of CABackingStore objects if we detect that
+ they might be entrained into a scrolling tree commit, by virtue of having overlapping main
+ thread and scrolling thread commits.
+
+ The logic is contained in PlatformCALayerContentsDelayedReleaser, which puts layer contents
+ into a retaining vector when they are being cleared on the layer. They are released at the
+ end of a main thread commit; if we detected overlapping commits, then we release on a
+ dispatch to extend the lifetime slightly.
+
+ The remaining changes are plumbing to get commit willBegin/didEnd messages to PlatformCALayerContentsDelayedReleaser
+ for main and scrolling threads.
+
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * page/scrolling/ScrollingTree.h:
+ * page/scrolling/ThreadedScrollingTree.h:
+ * page/scrolling/mac/ScrollingCoordinatorMac.h:
+ * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+ (WebCore::ScrollingCoordinatorMac::willStartPlatformRenderingUpdate):
+ (WebCore::ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate):
+ * page/scrolling/mac/ScrollingTreeMac.h:
+ * page/scrolling/mac/ScrollingTreeMac.mm:
+ (ScrollingTreeMac::applyLayerPositionsInternal):
+ (ScrollingTreeMac::registerForPlatformRenderingUpdateCallback):
+ * platform/graphics/ca/GraphicsLayerCA.cpp:
+ (WebCore::GraphicsLayerCA::updateContentsVisibility):
+ (WebCore::GraphicsLayerCA::updateDrawsContent):
+ * platform/graphics/ca/PlatformCALayer.cpp:
+ (WebCore::PlatformCALayer::clearContents):
+ * platform/graphics/ca/PlatformCALayer.h:
+ * platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
+ * platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
+ (WebCore::PlatformCALayerCocoa::setBackingStoreAttached):
+ (WebCore::PlatformCALayerCocoa::clearContents):
+ * platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.h: Added.
+ (WebCore::PlatformCALayerContentsDelayedReleaser::WTF_GUARDED_BY_LOCK):
+ * platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.mm: Added.
+ (WebCore::PlatformCALayerContentsDelayedReleaser::singleton):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::takeLayerContents):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::mainThreadCommitWillStart):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::mainThreadCommitDidEnd):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::scrollingThreadCommitWillStart):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::scrollingThreadCommitDidEnd):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::updateSawOverlappingCommit):
+ (WebCore::PlatformCALayerContentsDelayedReleaser::clearRetainedContents):
+
</ins><span class="cx"> 2021-12-16 Alan Coon <alancoon@apple.com>
</span><span class="cx">
</span><span class="cx"> Apply patch. rdar://problem/86505382
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreSourcesCocoatxt"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -331,6 +331,7 @@
</span><span class="cx"> platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm
</span><span class="cx"> platform/graphics/ca/cocoa/PlatformCAFiltersCocoa.mm
</span><span class="cx"> platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm
</span><ins>+platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.mm
</ins><span class="cx"> platform/graphics/ca/cocoa/WebSystemBackdropLayer.mm
</span><span class="cx"> platform/graphics/ca/cocoa/WebTiledBackingLayer.mm
</span><span class="cx"> platform/graphics/ca/cocoa/WebVideoContainerLayer.mm
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -6291,6 +6291,8 @@
</span><span class="cx"> 0FA0A0E523AEAA35000EEB94 /* dialog.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = dialog.css; sourceTree = "<group>"; };
</span><span class="cx"> 0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsLayerUpdater.cpp; sourceTree = "<group>"; };
</span><span class="cx"> 0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsLayerUpdater.h; sourceTree = "<group>"; };
</span><ins>+ 0FA2B233276817540020C7C1 /* PlatformCALayerContentsDelayedReleaser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformCALayerContentsDelayedReleaser.h; sourceTree = "<group>"; };
+ 0FA2B235276817550020C7C1 /* PlatformCALayerContentsDelayedReleaser.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformCALayerContentsDelayedReleaser.mm; sourceTree = "<group>"; };
</ins><span class="cx"> 0FB0689425243B90001E8E75 /* DisplayTextBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayTextBox.cpp; sourceTree = "<group>"; };
</span><span class="cx"> 0FB0689625243B90001E8E75 /* DisplayTextBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayTextBox.h; sourceTree = "<group>"; };
</span><span class="cx"> 0FB6252C18DE1B1500A07C05 /* GeometryUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeometryUtilities.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -20068,6 +20070,8 @@
</span><span class="cx"> 0F13163F16ED0CDE0035CC04 /* PlatformCAFiltersCocoa.mm */,
</span><span class="cx"> 2D70BA1218074DDF0001908A /* PlatformCALayerCocoa.h */,
</span><span class="cx"> 4958782012A57DDF007238AC /* PlatformCALayerCocoa.mm */,
</span><ins>+ 0FA2B233276817540020C7C1 /* PlatformCALayerContentsDelayedReleaser.h */,
+ 0FA2B235276817550020C7C1 /* PlatformCALayerContentsDelayedReleaser.mm */,
</ins><span class="cx"> 31DEA4541B39F4D900F77178 /* WebSystemBackdropLayer.h */,
</span><span class="cx"> 31DEA4531B39F4D900F77178 /* WebSystemBackdropLayer.mm */,
</span><span class="cx"> 0F580FA11496939100FB5BD8 /* WebTiledBackingLayer.h */,
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingScrollingTreeh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingTree.h (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingTree.h 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/ScrollingTree.h 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -259,7 +259,7 @@
</span><span class="cx"> void setGestureState(std::optional<WheelScrollGestureState>);
</span><span class="cx"> std::optional<WheelScrollGestureState> gestureState();
</span><span class="cx">
</span><del>- void applyLayerPositionsInternal() WTF_REQUIRES_LOCK(m_treeLock);
</del><ins>+ WEBCORE_EXPORT virtual void applyLayerPositionsInternal() WTF_REQUIRES_LOCK(m_treeLock);
</ins><span class="cx"> void removeAllNodes() WTF_REQUIRES_LOCK(m_treeLock);
</span><span class="cx">
</span><span class="cx"> Lock m_treeLock; // Protects the scrolling tree.
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingmacScrollingCoordinatorMach"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.h (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.h 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.h 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -50,6 +50,7 @@
</span><span class="cx"> void willStartRenderingUpdate() final;
</span><span class="cx"> void didCompleteRenderingUpdate() final;
</span><span class="cx">
</span><ins>+ void willStartPlatformRenderingUpdate() final;
</ins><span class="cx"> void didCompletePlatformRenderingUpdate() final;
</span><span class="cx">
</span><span class="cx"> void updateTiledScrollingIndicator();
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingmacScrollingCoordinatorMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import "FrameView.h"
</span><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "Page.h"
</span><ins>+#import "PlatformCALayerContentsDelayedReleaser.h"
</ins><span class="cx"> #import "PlatformWheelEvent.h"
</span><span class="cx"> #import "Region.h"
</span><span class="cx"> #import "ScrollingStateTree.h"
</span><span class="lines">@@ -135,9 +136,15 @@
</span><span class="cx"> downcast<ThreadedScrollingTree>(scrollingTree())->didCompleteRenderingUpdate();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void ScrollingCoordinatorMac::willStartPlatformRenderingUpdate()
+{
+ PlatformCALayerContentsDelayedReleaser::singleton().mainThreadCommitWillStart();
+}
+
</ins><span class="cx"> void ScrollingCoordinatorMac::didCompletePlatformRenderingUpdate()
</span><span class="cx"> {
</span><span class="cx"> downcast<ThreadedScrollingTree>(scrollingTree())->didCompletePlatformRenderingUpdate();
</span><ins>+ PlatformCALayerContentsDelayedReleaser::singleton().mainThreadCommitDidEnd();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void ScrollingCoordinatorMac::updateTiledScrollingIndicator()
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingmacScrollingTreeMach"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.h (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.h 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.h 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -55,6 +55,9 @@
</span><span class="cx"> void deferWheelEventTestCompletionForReason(WheelEventTestMonitor::ScrollableAreaIdentifier, WheelEventTestMonitor::DeferReason) final;
</span><span class="cx"> void removeWheelEventTestCompletionDeferralForReason(WheelEventTestMonitor::ScrollableAreaIdentifier, WheelEventTestMonitor::DeferReason) final;
</span><span class="cx">
</span><ins>+ void registerForPlatformRenderingUpdateCallback();
+ void applyLayerPositionsInternal() final WTF_REQUIRES_LOCK(m_treeLock);
+
</ins><span class="cx"> void lockLayersForHitTesting() final WTF_ACQUIRES_LOCK(m_layerHitTestMutex);
</span><span class="cx"> void unlockLayersForHitTesting() final WTF_RELEASES_LOCK(m_layerHitTestMutex);
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCorepagescrollingmacScrollingTreeMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.mm (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.mm 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.mm 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx">
</span><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "PlatformCALayer.h"
</span><ins>+#import "PlatformCALayerContentsDelayedReleaser.h"
</ins><span class="cx"> #import "ScrollingTreeFixedNode.h"
</span><span class="cx"> #import "ScrollingTreeFrameHostingNode.h"
</span><span class="cx"> #import "ScrollingTreeFrameScrollingNodeMac.h"
</span><span class="lines">@@ -38,6 +39,7 @@
</span><span class="cx"> #import "WebCoreCALayerExtras.h"
</span><span class="cx"> #import "WebLayer.h"
</span><span class="cx"> #import "WheelEventTestMonitor.h"
</span><ins>+#import <pal/spi/cocoa/QuartzCoreSPI.h>
</ins><span class="cx"> #import <wtf/text/TextStream.h>
</span><span class="cx">
</span><span class="cx"> #if ENABLE(ASYNC_SCROLLING) && ENABLE(SCROLLING_THREAD)
</span><span class="lines">@@ -240,6 +242,25 @@
</span><span class="cx"> m_layerHitTestMutex.unlock();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void ScrollingTreeMac::applyLayerPositionsInternal()
+{
+ if (ScrollingThread::isCurrentThread())
+ registerForPlatformRenderingUpdateCallback();
+
+ ThreadedScrollingTree::applyLayerPositionsInternal();
+}
+
+void ScrollingTreeMac::registerForPlatformRenderingUpdateCallback()
+{
+ [CATransaction addCommitHandler:[] {
+ PlatformCALayerContentsDelayedReleaser::singleton().scrollingThreadCommitWillStart();
+ } forPhase:kCATransactionPhasePreLayout];
+
+ [CATransaction addCommitHandler:[] {
+ PlatformCALayerContentsDelayedReleaser::singleton().scrollingThreadCommitDidEnd();
+ } forPhase:kCATransactionPhasePostCommit];
+}
+
</ins><span class="cx"> void ScrollingTreeMac::setWheelEventTestMonitor(RefPtr<WheelEventTestMonitor>&& monitor)
</span><span class="cx"> {
</span><span class="cx"> m_wheelEventTestMonitor = WTFMove(monitor);
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscaGraphicsLayerCAcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -2278,7 +2278,7 @@
</span><span class="cx"> if (m_backdropLayer)
</span><span class="cx"> m_backdropLayer->setHidden(false);
</span><span class="cx"> } else {
</span><del>- m_layer->setContents(nullptr);
</del><ins>+ m_layer->clearContents();
</ins><span class="cx">
</span><span class="cx"> if (m_layerClones) {
</span><span class="cx"> for (auto& layer : m_layerClones->primaryLayerClones.values())
</span><span class="lines">@@ -2593,7 +2593,7 @@
</span><span class="cx"> m_layer->setNeedsDisplay();
</span><span class="cx"> m_hasEverPainted = false;
</span><span class="cx"> } else {
</span><del>- m_layer->setContents(nullptr);
</del><ins>+ m_layer->clearContents();
</ins><span class="cx"> if (m_layerClones) {
</span><span class="cx"> for (auto& layer : m_layerClones->primaryLayerClones.values())
</span><span class="cx"> layer->setContents(nullptr);
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscaPlatformCALayercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -199,6 +199,11 @@
</span><span class="cx"> return *sharedPool;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void PlatformCALayer::clearContents()
+{
+ setContents(nullptr);
+}
+
</ins><span class="cx"> void PlatformCALayer::dumpAdditionalProperties(TextStream&, OptionSet<PlatformLayerTreeAsTextFlags>)
</span><span class="cx"> {
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscaPlatformCALayerh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.h (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.h 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ca/PlatformCALayer.h 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -189,6 +189,7 @@
</span><span class="cx"> virtual bool hasContents() const = 0;
</span><span class="cx"> virtual CFTypeRef contents() const = 0;
</span><span class="cx"> virtual void setContents(CFTypeRef) = 0;
</span><ins>+ virtual void clearContents();
</ins><span class="cx">
</span><span class="cx"> virtual void setContentsRect(const FloatRect&) = 0;
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerCocoah"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -120,6 +120,7 @@
</span><span class="cx"> bool hasContents() const override;
</span><span class="cx"> CFTypeRef contents() const override;
</span><span class="cx"> void setContents(CFTypeRef) override;
</span><ins>+ void clearContents() override;
</ins><span class="cx">
</span><span class="cx"> void setContentsRect(const FloatRect&) override;
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerCocoamm"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm (287154 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm 2021-12-16 21:05:43 UTC (rev 287154)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #import "Model.h"
</span><span class="cx"> #import "PlatformCAAnimationCocoa.h"
</span><span class="cx"> #import "PlatformCAFilters.h"
</span><ins>+#import "PlatformCALayerContentsDelayedReleaser.h"
</ins><span class="cx"> #import "ScrollbarThemeMac.h"
</span><span class="cx"> #import "TileController.h"
</span><span class="cx"> #import "TiledBacking.h"
</span><span class="lines">@@ -684,7 +685,7 @@
</span><span class="cx"> if (attached)
</span><span class="cx"> setNeedsDisplay();
</span><span class="cx"> else
</span><del>- setContents(nullptr);
</del><ins>+ clearContents();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool PlatformCALayerCocoa::backingStoreAttached() const
</span><span class="lines">@@ -790,6 +791,15 @@
</span><span class="cx"> return (__bridge CFTypeRef)[m_layer contents];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void PlatformCALayerCocoa::clearContents()
+{
+#if PLATFORM(MAC)
+ PlatformCALayerContentsDelayedReleaser::singleton().takeLayerContents(*this);
+#else
+ setContents(nullptr);
+#endif
+}
+
</ins><span class="cx"> void PlatformCALayerCocoa::setContents(CFTypeRef value)
</span><span class="cx"> {
</span><span class="cx"> BEGIN_BLOCK_OBJC_EXCEPTIONS
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerContentsDelayedReleaserh"></a>
<div class="addfile"><h4>Added: branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.h (0 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.h (rev 0)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.h 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -0,0 +1,70 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(MAC)
+
+#include <wtf/Lock.h>
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebCore {
+
+class PlatformCALayer;
+
+// This class exists to work around rdar://85892959, where CABackingStore objects would get released on the ScrollingThread
+// during scrolling commits, which can take long enough to cause scrolling frame drops.
+class PlatformCALayerContentsDelayedReleaser : ThreadSafeRefCounted<PlatformCALayerContentsDelayedReleaser> {
+ WTF_MAKE_NONCOPYABLE(PlatformCALayerContentsDelayedReleaser);
+public:
+ static PlatformCALayerContentsDelayedReleaser& singleton();
+
+ void takeLayerContents(PlatformCALayer&);
+
+ void mainThreadCommitWillStart();
+ void mainThreadCommitDidEnd();
+
+ void scrollingThreadCommitWillStart();
+ void scrollingThreadCommitDidEnd();
+
+private:
+ friend LazyNeverDestroyed<PlatformCALayerContentsDelayedReleaser>;
+
+ PlatformCALayerContentsDelayedReleaser();
+
+ void updateSawOverlappingCommit() WTF_REQUIRES_LOCK(m_lock);
+ void clearRetainedContents();
+
+ Vector<RetainPtr<CFTypeRef>> m_retainedContents;
+
+ Lock m_lock;
+ unsigned m_inMainThreadCommitEntryCount WTF_GUARDED_BY_LOCK(m_lock) { 0 };
+ unsigned m_scrollingThreadCommitEntryCount WTF_GUARDED_BY_LOCK(m_lock) { 0 };
+ bool m_hadOverlappingCommit WTF_GUARDED_BY_LOCK(m_lock) { false };
+};
+
+} // namespace WebCore
+
+#endif // PLATFORM(MAC)
</ins></span></pre></div>
<a id="branchessafari612branchSourceWebCoreplatformgraphicscacocoaPlatformCALayerContentsDelayedReleasermm"></a>
<div class="addfile"><h4>Added: branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.mm (0 => 287155)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.mm (rev 0)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerContentsDelayedReleaser.mm 2021-12-16 21:20:10 UTC (rev 287155)
</span><span class="lines">@@ -0,0 +1,130 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "PlatformCALayerContentsDelayedReleaser.h"
+
+#if PLATFORM(MAC)
+
+#import "PlatformCALayer.h"
+#import <wtf/RunLoop.h>
+
+namespace WebCore {
+
+PlatformCALayerContentsDelayedReleaser& PlatformCALayerContentsDelayedReleaser::singleton()
+{
+ static LazyNeverDestroyed<PlatformCALayerContentsDelayedReleaser> delayedReleaser;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+ delayedReleaser.construct();
+ });
+
+ return delayedReleaser;
+}
+
+PlatformCALayerContentsDelayedReleaser::PlatformCALayerContentsDelayedReleaser() = default;
+
+void PlatformCALayerContentsDelayedReleaser::takeLayerContents(PlatformCALayer& layer)
+{
+ ASSERT(isMainThread());
+
+ auto retainedContents = RetainPtr { layer.contents() };
+ if (retainedContents)
+ m_retainedContents.append(WTFMove(retainedContents));
+ layer.setContents(nullptr);
+}
+
+void PlatformCALayerContentsDelayedReleaser::mainThreadCommitWillStart()
+{
+ Locker locker { m_lock };
+ ++m_inMainThreadCommitEntryCount;
+ updateSawOverlappingCommit();
+}
+
+void PlatformCALayerContentsDelayedReleaser::mainThreadCommitDidEnd()
+{
+ bool bothCommitsDone;
+ bool hadOverlappingCommit;
+ {
+ Locker locker { m_lock };
+ ASSERT(m_inMainThreadCommitEntryCount);
+ --m_inMainThreadCommitEntryCount;
+ bothCommitsDone = !m_scrollingThreadCommitEntryCount && !m_inMainThreadCommitEntryCount;
+ hadOverlappingCommit = m_hadOverlappingCommit;
+ }
+
+ if (bothCommitsDone) {
+ if (hadOverlappingCommit && m_retainedContents.size()) {
+ RunLoop::main().dispatch([] {
+ PlatformCALayerContentsDelayedReleaser::singleton().clearRetainedContents();
+ });
+ return;
+ }
+
+ clearRetainedContents();
+ }
+}
+
+void PlatformCALayerContentsDelayedReleaser::scrollingThreadCommitWillStart()
+{
+ ASSERT(!isMainThread());
+ Locker locker { m_lock };
+ ++m_scrollingThreadCommitEntryCount;
+ updateSawOverlappingCommit();
+}
+
+void PlatformCALayerContentsDelayedReleaser::scrollingThreadCommitDidEnd()
+{
+ ASSERT(!isMainThread());
+ Locker locker { m_lock };
+
+ ASSERT(m_scrollingThreadCommitEntryCount);
+ --m_scrollingThreadCommitEntryCount;
+ if (!m_scrollingThreadCommitEntryCount && !m_inMainThreadCommitEntryCount) {
+ if (m_hadOverlappingCommit) {
+ // m_retainedContents might be empty (it's not protected by the lock so we can't check it here),
+ // so this might be a pointless dispatch, but m_hadOverlappingCommit is rare.
+ RunLoop::main().dispatch([] {
+ PlatformCALayerContentsDelayedReleaser::singleton().clearRetainedContents();
+ });
+ }
+ }
+}
+
+void PlatformCALayerContentsDelayedReleaser::updateSawOverlappingCommit()
+{
+ m_hadOverlappingCommit |= (m_inMainThreadCommitEntryCount && m_scrollingThreadCommitEntryCount);
+}
+
+void PlatformCALayerContentsDelayedReleaser::clearRetainedContents()
+{
+ ASSERT(isMainThread());
+ m_retainedContents.clear();
+}
+
+} // namespace WebCore
+
+#endif
+
</ins></span></pre>
</div>
</div>
</body>
</html>