<!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>[279992] trunk/Source/WebKit</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/279992">279992</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2021-07-16 11:24:35 -0700 (Fri, 16 Jul 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adopt BifurcatedGraphicsContext for backing store + display list RemoteLayerBackingStore
https://bugs.webkit.org/show_bug.cgi?id=226425
<rdar://77929299>

Reviewed by Sam Weinig.

Instead of "display list backed RemoteLayerBackingStore" being its own
backing store type, we make "includes a display list" a separate bit.
This way, we can paint both a bitmap (IOSurface or CG bitmap, all
exactly as it normally is), and also carry a sidecar display list.

* Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
* Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::ensureBackingStore):
(WebKit::RemoteLayerBackingStore::encode const):
(WebKit::RemoteLayerBackingStore::decode):
(WebKit::RemoteLayerBackingStore::swapToValidFrontBuffer):
(WebKit::RemoteLayerBackingStore::supportsPartialRepaint):
We can't partially repaint the display list, and require its rendering
to match the painted backing store, so disable partial repaint entirely
if display lists are being used.

(WebKit::RemoteLayerBackingStore::display):
(WebKit::RemoteLayerBackingStore::drawInContext):
Adopt BifurcatedGraphicsContext in order to paint into the aforementioned
bitmap and display list simultaneously.
A future patch may abstract this into a new ImageBuffer type
instead of polluting RemoteLayerBackingStore with it.

Leave a temporary workaround for a CoreAnimation bug, which can be
disabled via `defaults write`, but is enabled by default.

(WebKit::layerContentsForBufferHandle):
(WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
(WebKit::RemoteLayerBackingStore::Buffer::discard):
* UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.h:
* UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.mm:
(-[WKCompositingLayer _setWKContents:withDisplayList:]):
(-[WKCompositingLayer _setWKContentsDisplayList:]): Deleted.
(-[WKCompositingLayer _wkContentsDisplayList]): Deleted.
Pass the display list data to CoreAnimation alongside the bitmap.

* WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp:
(WebKit::PlatformCALayerRemote::updateBackingStore):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedRemoteLayerTreeRemoteLayerBackingStoreh">trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h</a></li>
<li><a href="#trunkSourceWebKitSharedRemoteLayerTreeRemoteLayerBackingStoremm">trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessRemoteLayerTreecocoaRemoteLayerTreeLayersh">trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessRemoteLayerTreecocoaRemoteLayerTreeLayersmm">trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageRemoteLayerTreePlatformCALayerRemotecpp">trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageRemoteLayerTreeRemoteLayerTreeDrawingAreamm">trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (279991 => 279992)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-07-16 18:18:05 UTC (rev 279991)
+++ trunk/Source/WebKit/ChangeLog       2021-07-16 18:24:35 UTC (rev 279992)
</span><span class="lines">@@ -1,3 +1,50 @@
</span><ins>+2021-07-16  Tim Horton  <timothy_horton@apple.com>
+
+        Adopt BifurcatedGraphicsContext for backing store + display list RemoteLayerBackingStore
+        https://bugs.webkit.org/show_bug.cgi?id=226425
+        <rdar://77929299>
+
+        Reviewed by Sam Weinig.
+
+        Instead of "display list backed RemoteLayerBackingStore" being its own
+        backing store type, we make "includes a display list" a separate bit.
+        This way, we can paint both a bitmap (IOSurface or CG bitmap, all
+        exactly as it normally is), and also carry a sidecar display list.
+
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
+        (WebKit::RemoteLayerBackingStore::ensureBackingStore):
+        (WebKit::RemoteLayerBackingStore::encode const):
+        (WebKit::RemoteLayerBackingStore::decode):
+        (WebKit::RemoteLayerBackingStore::swapToValidFrontBuffer):
+        (WebKit::RemoteLayerBackingStore::supportsPartialRepaint):
+        We can't partially repaint the display list, and require its rendering
+        to match the painted backing store, so disable partial repaint entirely
+        if display lists are being used.
+
+        (WebKit::RemoteLayerBackingStore::display):
+        (WebKit::RemoteLayerBackingStore::drawInContext):
+        Adopt BifurcatedGraphicsContext in order to paint into the aforementioned
+        bitmap and display list simultaneously.
+        A future patch may abstract this into a new ImageBuffer type
+        instead of polluting RemoteLayerBackingStore with it.
+
+        Leave a temporary workaround for a CoreAnimation bug, which can be
+        disabled via `defaults write`, but is enabled by default.
+
+        (WebKit::layerContentsForBufferHandle):
+        (WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
+        (WebKit::RemoteLayerBackingStore::Buffer::discard):
+        * UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.h:
+        * UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.mm:
+        (-[WKCompositingLayer _setWKContents:withDisplayList:]):
+        (-[WKCompositingLayer _setWKContentsDisplayList:]): Deleted.
+        (-[WKCompositingLayer _wkContentsDisplayList]): Deleted.
+        Pass the display list data to CoreAnimation alongside the bitmap.
+
+        * WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp:
+        (WebKit::PlatformCALayerRemote::updateBackingStore):
+
</ins><span class="cx"> 2021-07-16  Megan Gardner  <megan_gardner@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Pipe App Highlight scrolling through UI Process in preparation for Note Overlay avoidance.
</span></span></pre></div>
<a id="trunkSourceWebKitSharedRemoteLayerTreeRemoteLayerBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h (279991 => 279992)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h     2021-07-16 18:18:05 UTC (rev 279991)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h        2021-07-16 18:24:35 UTC (rev 279992)
</span><span class="lines">@@ -54,13 +54,11 @@
</span><span class="cx"> 
</span><span class="cx">     enum class Type : uint8_t {
</span><span class="cx">         IOSurface,
</span><del>-        Bitmap,
-#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
-        CGDisplayList,
-#endif
</del><ins>+        Bitmap
</ins><span class="cx">     };
</span><span class="cx"> 
</span><del>-    void ensureBackingStore(Type, WebCore::FloatSize, float scale, bool deepColor, bool isOpaque);
</del><ins>+    enum class IncludeDisplayList : bool { No, Yes };
+    void ensureBackingStore(Type, WebCore::FloatSize, float scale, bool deepColor, bool isOpaque, IncludeDisplayList);
</ins><span class="cx"> 
</span><span class="cx">     void setNeedsDisplay(const WebCore::IntRect);
</span><span class="cx">     void setNeedsDisplay();
</span><span class="lines">@@ -88,7 +86,7 @@
</span><span class="cx">         return !!m_frontBuffer.imageBuffer;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher> takePendingFlusher();
</del><ins>+    Vector<std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher>> takePendingFlushers();
</ins><span class="cx"> 
</span><span class="cx">     enum class BufferType {
</span><span class="cx">         Front,
</span><span class="lines">@@ -120,6 +118,9 @@
</span><span class="cx"> 
</span><span class="cx">     struct Buffer {
</span><span class="cx">         RefPtr<WebCore::ImageBuffer> imageBuffer;
</span><ins>+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+        RefPtr<WebCore::ImageBuffer> displayListImageBuffer;
+#endif
</ins><span class="cx">         bool isVolatile = false;
</span><span class="cx"> 
</span><span class="cx">         explicit operator bool() const
</span><span class="lines">@@ -134,10 +135,14 @@
</span><span class="cx">     Buffer m_backBuffer;
</span><span class="cx">     Buffer m_secondaryBackBuffer;
</span><span class="cx">     std::optional<ImageBufferBackendHandle> m_bufferHandle;
</span><ins>+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+    std::optional<ImageBufferBackendHandle> m_displayListBufferHandle;
+#endif
</ins><span class="cx"> 
</span><del>-    std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher> m_frontBufferFlusher;
</del><ins>+    Vector<std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher>> m_frontBufferFlushers;
</ins><span class="cx"> 
</span><span class="cx">     Type m_type;
</span><ins>+    IncludeDisplayList m_includeDisplayList { IncludeDisplayList::No };
</ins><span class="cx">     bool m_deepColor { false };
</span><span class="cx"> 
</span><span class="cx">     WebCore::RepaintRectList m_paintingRects;
</span><span class="lines">@@ -151,13 +156,18 @@
</span><span class="cx"> 
</span><span class="cx"> template<> struct EnumTraits<WebKit::RemoteLayerBackingStore::Type> {
</span><span class="cx">     using values = EnumValues<
</span><del>-        WebKit::RemoteLayerBackingStore::Type
-        , WebKit::RemoteLayerBackingStore::Type::IOSurface
-        , WebKit::RemoteLayerBackingStore::Type::Bitmap
-#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
-        , WebKit::RemoteLayerBackingStore::Type::CGDisplayList
-#endif
</del><ins>+        WebKit::RemoteLayerBackingStore::Type,
+        WebKit::RemoteLayerBackingStore::Type::IOSurface,
+        WebKit::RemoteLayerBackingStore::Type::Bitmap
</ins><span class="cx">     >;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+template<> struct EnumTraits<WebKit::RemoteLayerBackingStore::IncludeDisplayList> {
+    using values = EnumValues<
+        WebKit::RemoteLayerBackingStore::IncludeDisplayList,
+        WebKit::RemoteLayerBackingStore::IncludeDisplayList::No,
+        WebKit::RemoteLayerBackingStore::IncludeDisplayList::Yes
+    >;
+};
+
</ins><span class="cx"> } // namespace WTF
</span></span></pre></div>
<a id="trunkSourceWebKitSharedRemoteLayerTreeRemoteLayerBackingStoremm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm (279991 => 279992)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm    2021-07-16 18:18:05 UTC (rev 279991)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm       2021-07-16 18:24:35 UTC (rev 279992)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>- /*
</del><ins>+/*
</ins><span class="cx">  * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #import "WebCoreArgumentCoders.h"
</span><span class="cx"> #import "WebProcess.h"
</span><span class="cx"> #import <QuartzCore/QuartzCore.h>
</span><ins>+#import <WebCore/BifurcatedGraphicsContext.h>
</ins><span class="cx"> #import <WebCore/GraphicsContextCG.h>
</span><span class="cx"> #import <WebCore/IOSurface.h>
</span><span class="cx"> #import <WebCore/ImageBuffer.h>
</span><span class="lines">@@ -75,9 +76,9 @@
</span><span class="cx">         context->backingStoreWillBeDestroyed(*this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RemoteLayerBackingStore::ensureBackingStore(Type type, WebCore::FloatSize size, float scale, bool deepColor, bool isOpaque)
</del><ins>+void RemoteLayerBackingStore::ensureBackingStore(Type type, WebCore::FloatSize size, float scale, bool deepColor, bool isOpaque, IncludeDisplayList includeDisplayList)
</ins><span class="cx"> {
</span><del>-    if (m_type == type && m_size == size && m_scale == scale && m_deepColor == deepColor && m_isOpaque == isOpaque)
</del><ins>+    if (m_type == type && m_size == size && m_scale == scale && m_deepColor == deepColor && m_isOpaque == isOpaque && m_includeDisplayList == includeDisplayList)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_type = type;
</span><span class="lines">@@ -85,6 +86,7 @@
</span><span class="cx">     m_scale = scale;
</span><span class="cx">     m_deepColor = deepColor;
</span><span class="cx">     m_isOpaque = isOpaque;
</span><ins>+    m_includeDisplayList = includeDisplayList;
</ins><span class="cx"> 
</span><span class="cx">     if (m_frontBuffer) {
</span><span class="cx">         // If we have a valid backing store, we need to ensure that it gets completely
</span><span class="lines">@@ -108,6 +110,7 @@
</span><span class="cx">     encoder << m_size;
</span><span class="cx">     encoder << m_scale;
</span><span class="cx">     encoder << m_isOpaque;
</span><ins>+    encoder << m_includeDisplayList;
</ins><span class="cx"> 
</span><span class="cx">     std::optional<ImageBufferBackendHandle> handle;
</span><span class="cx">     if (m_frontBuffer.imageBuffer) {
</span><span class="lines">@@ -121,15 +124,18 @@
</span><span class="cx">         case Type::Bitmap:
</span><span class="cx">             handle = static_cast<UnacceleratedImageBufferShareableBackend&>(*m_frontBuffer.imageBuffer->ensureBackendCreated()).createImageBufferBackendHandle();
</span><span class="cx">             break;
</span><del>-#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
-        case Type::CGDisplayList:
-            handle = static_cast<CGDisplayListImageBufferBackend&>(*m_frontBuffer.imageBuffer->ensureBackendCreated()).createImageBufferBackendHandle();
-            break;
-#endif
</del><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     encoder << handle;
</span><ins>+
+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+    std::optional<ImageBufferBackendHandle> displayListHandle;
+    if (m_frontBuffer.displayListImageBuffer)
+        displayListHandle = static_cast<CGDisplayListImageBufferBackend&>(*m_frontBuffer.displayListImageBuffer->ensureBackendCreated()).createImageBufferBackendHandle();
+
+    encoder << displayListHandle;
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RemoteLayerBackingStore::decode(IPC::Decoder& decoder, RemoteLayerBackingStore& result)
</span><span class="lines">@@ -146,9 +152,17 @@
</span><span class="cx">     if (!decoder.decode(result.m_isOpaque))
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><ins>+    if (!decoder.decode(result.m_includeDisplayList))
+        return false;
+
</ins><span class="cx">     if (!decoder.decode(result.m_bufferHandle))
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><ins>+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+    if (!decoder.decode(result.m_displayListBufferHandle))
+        return false;
+#endif
+
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -222,32 +236,24 @@
</span><span class="cx">         else
</span><span class="cx">             m_frontBuffer.imageBuffer = WebCore::ConcreteImageBuffer<UnacceleratedImageBufferShareableBackend>::create(m_size, m_scale, WebCore::DestinationColorSpace::SRGB(), pixelFormat(), nullptr);
</span><span class="cx">         break;
</span><ins>+    }
+
</ins><span class="cx"> #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
</span><del>-    case Type::CGDisplayList:
-        m_frontBuffer.imageBuffer = WebCore::ConcreteImageBuffer<CGDisplayListImageBufferBackend>::create(m_size, m_scale, WebCore::DestinationColorSpace::SRGB(), pixelFormat(), nullptr);
-        break;
</del><ins>+    if (m_includeDisplayList == IncludeDisplayList::Yes)
+        m_frontBuffer.displayListImageBuffer = WebCore::ConcreteImageBuffer<CGDisplayListImageBufferBackend>::create(m_size, m_scale, WebCore::DestinationColorSpace::SRGB(), pixelFormat(), nullptr);
</ins><span class="cx"> #endif
</span><del>-    }
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RemoteLayerBackingStore::supportsPartialRepaint()
</span><span class="cx"> {
</span><del>-    switch (m_type) {
-    case Type::IOSurface:
-    case Type::Bitmap:
-        return true;
-#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
-    case Type::CGDisplayList:
-        return false;
-#endif
-    }
-
-    return true;
</del><ins>+    // FIXME: Find a way to support partial repaint for backing store that
+    // includes a display list without allowing unbounded memory growth.
+    return m_includeDisplayList == IncludeDisplayList::No;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RemoteLayerBackingStore::display()
</span><span class="cx"> {
</span><del>-    ASSERT(!m_frontBufferFlusher);
</del><ins>+    ASSERT(!m_frontBufferFlushers.size());
</ins><span class="cx"> 
</span><span class="cx">     m_lastDisplayTime = MonotonicTime::now();
</span><span class="cx"> 
</span><span class="lines">@@ -274,7 +280,50 @@
</span><span class="cx">     if (!m_frontBuffer.imageBuffer)
</span><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    WebCore::GraphicsContext& context = m_frontBuffer.imageBuffer->context();
</del><ins>+
+    if (m_includeDisplayList == IncludeDisplayList::Yes) {
+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+        auto& displayListContext = m_frontBuffer.displayListImageBuffer->context();
+
+        // FIXME: Remove this when <rdar://problem/80487697> is fixed.
+        static std::optional<bool> needsMissingFlipWorkaround;
+        if (!needsMissingFlipWorkaround) {
+            id defaultValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKitNeedsWorkaroundFor80487697"];
+            needsMissingFlipWorkaround = defaultValue ? [defaultValue boolValue] : true;
+        }
+        if (needsMissingFlipWorkaround.value()) {
+            displayListContext.scale(WebCore::FloatSize(m_scale, -m_scale));
+            displayListContext.translate(0, -m_size.height());
+        }
+
+        WebCore::BifurcatedGraphicsContext context(m_frontBuffer.imageBuffer->context(), displayListContext);
+#else
+        WebCore::GraphicsContext& context = m_frontBuffer.imageBuffer->context();
+#endif
+        drawInContext(context);
+    } else {
+        WebCore::GraphicsContext& context = m_frontBuffer.imageBuffer->context();
+        drawInContext(context);    
+    }
+
+    m_dirtyRegion = WebCore::Region();
+    m_paintingRects.clear();
+
+    m_layer->owner()->platformCALayerLayerDidDisplay(m_layer);
+
+    m_frontBuffer.imageBuffer->flushDrawingContextAsync();
+
+    m_frontBufferFlushers.append(m_frontBuffer.imageBuffer->createFlusher());
+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+    if (m_includeDisplayList == IncludeDisplayList::Yes)
+        m_frontBufferFlushers.append(m_frontBuffer.displayListImageBuffer->createFlusher());
+#endif
+
+    return true;
+}
+
+void RemoteLayerBackingStore::drawInContext(WebCore::GraphicsContext& context)
+{
</ins><span class="cx">     WebCore::GraphicsContextStateSaver stateSaver(context);
</span><span class="cx"> 
</span><span class="cx">     // If we have less than webLayerMaxRectsToPaint rects to paint and they cover less
</span><span class="lines">@@ -297,6 +346,7 @@
</span><span class="cx">         m_paintingRects.append(scaledRect);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    WebCore::IntRect layerBounds(WebCore::IntPoint(), WebCore::expandedIntSize(m_size));
</ins><span class="cx">     if (!m_dirtyRegion.contains(layerBounds)) {
</span><span class="cx">         ASSERT(m_backBuffer.imageBuffer);
</span><span class="cx">         context.drawImageBuffer(*m_backBuffer.imageBuffer, { {0, 0}, m_size }, { {0, 0}, m_size }, { WebCore::CompositeOperator::Copy });
</span><span class="lines">@@ -354,17 +404,6 @@
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><span class="cx">         break;
</span><span class="cx">     };
</span><del>-
-    m_dirtyRegion = WebCore::Region();
-    m_paintingRects.clear();
-
-    m_layer->owner()->platformCALayerLayerDidDisplay(m_layer);
-
-    m_frontBuffer.imageBuffer->flushDrawingContextAsync();
-
-    m_frontBufferFlusher = m_frontBuffer.imageBuffer->createFlusher();
-
-    return true;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RemoteLayerBackingStore::enumerateRectsBeingDrawn(WebCore::GraphicsContext& context, void (^block)(WebCore::FloatRect))
</span><span class="lines">@@ -387,42 +426,51 @@
</span><span class="cx">     ASSERT(m_bufferHandle);
</span><span class="cx">     layer.contentsOpaque = m_isOpaque;
</span><span class="cx"> 
</span><ins>+    id contents = nil;
</ins><span class="cx">     WTF::switchOn(*m_bufferHandle,
</span><span class="cx">         [&] (ShareableBitmap::Handle& handle) {
</span><span class="cx">             ASSERT(m_type == Type::Bitmap);
</span><span class="cx">             auto bitmap = ShareableBitmap::create(handle);
</span><del>-            layer.contents = (__bridge id)bitmap->makeCGImageCopy().get();
</del><ins>+            contents = bitmap->makeCGImageCopy().bridgingAutorelease();
</ins><span class="cx">         },
</span><span class="cx">         [&] (MachSendRight& machSendRight) {
</span><span class="cx">             ASSERT(m_type == Type::IOSurface);
</span><span class="cx">             switch (contentsType) {
</span><del>-            case LayerContentsType::IOSurface: {
</del><ins>+            case RemoteLayerBackingStore::LayerContentsType::IOSurface: {
</ins><span class="cx">                 auto surface = WebCore::IOSurface::createFromSendRight(WTFMove(machSendRight), WebCore::DestinationColorSpace::SRGB());
</span><del>-                layer.contents = surface ? surface->asLayerContents() : nil;
</del><ins>+                contents = surface ? surface->asLayerContents() : nil;
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><del>-            case LayerContentsType::CAMachPort:
-                layer.contents = (__bridge id)adoptCF(CAMachPortCreate(machSendRight.leakSendRight())).get();
</del><ins>+            case RemoteLayerBackingStore::LayerContentsType::CAMachPort:
+                contents = adoptCF(CAMachPortCreate(machSendRight.leakSendRight())).bridgingAutorelease();
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
</span><span class="cx">         , [&] (IPC::SharedBufferCopy& buffer) {
</span><del>-            ASSERT(m_type == Type::CGDisplayList);
-            ASSERT([layer isKindOfClass:[WKCompositingLayer class]]);
-            if (![layer isKindOfClass:[WKCompositingLayer class]])
-                return;
-            [layer setValue:@1 forKeyPath:WKCGDisplayListEnabledKey];
-            auto data = buffer.buffer()->createCFData();
-            [(WKCompositingLayer *)layer _setWKContentsDisplayList:data.get()];
</del><ins>+            ASSERT_NOT_REACHED();
</ins><span class="cx">         }
</span><span class="cx"> #endif
</span><span class="cx">     );
</span><ins>+
+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+    if (m_displayListBufferHandle) {
+        ASSERT([layer isKindOfClass:[WKCompositingLayer class]]);
+        if (![layer isKindOfClass:[WKCompositingLayer class]])
+            return;
+        [layer setValue:@1 forKeyPath:WKCGDisplayListEnabledKey];
+        auto data = WTF::get<IPC::SharedBufferCopy>(*m_displayListBufferHandle).buffer()->createCFData();
+        [(WKCompositingLayer *)layer _setWKContents:contents withDisplayList:data.get()];
+        return;
+    }
+#endif
+
+    layer.contents = contents;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher> RemoteLayerBackingStore::takePendingFlusher()
</del><ins>+Vector<std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher>> RemoteLayerBackingStore::takePendingFlushers()
</ins><span class="cx"> {
</span><del>-    return std::exchange(m_frontBufferFlusher, nullptr);
</del><ins>+    return std::exchange(m_frontBufferFlushers, { });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RemoteLayerBackingStore::setBufferVolatility(BufferType bufferType, bool isVolatile)
</span><span class="lines">@@ -488,6 +536,9 @@
</span><span class="cx">     if (imageBuffer)
</span><span class="cx">         imageBuffer->releaseBufferToPool();
</span><span class="cx">     imageBuffer = nullptr;
</span><ins>+#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
+    displayListImageBuffer = nullptr;
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessRemoteLayerTreecocoaRemoteLayerTreeLayersh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.h (279991 => 279992)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.h      2021-07-16 18:18:05 UTC (rev 279991)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.h 2021-07-16 18:24:35 UTC (rev 279992)
</span><span class="lines">@@ -33,7 +33,7 @@
</span><span class="cx"> @interface WKCompositingLayer : CALayer
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
</span><del>-@property (nonatomic, retain, setter=_setWKContentsDisplayList:) __attribute__((NSObject)) CFDataRef _wkContentsDisplayList;
</del><ins>+- (void)_setWKContents:(id)contents withDisplayList:(CFDataRef)data;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessRemoteLayerTreecocoaRemoteLayerTreeLayersmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.mm (279991 => 279992)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.mm     2021-07-16 18:18:05 UTC (rev 279991)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/cocoa/RemoteLayerTreeLayers.mm        2021-07-16 18:24:35 UTC (rev 279992)
</span><span class="lines">@@ -36,11 +36,7 @@
</span><span class="cx"> #import <WebKitAdditions/CGDisplayListImageBufferAdditions.h>
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-@implementation WKCompositingLayer {
-#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
-    RetainPtr<CFDataRef> _contentsDisplayList;
-#endif
-}
</del><ins>+@implementation WKCompositingLayer
</ins><span class="cx"> 
</span><span class="cx"> - (NSString *)description
</span><span class="cx"> {
</span><span class="lines">@@ -48,23 +44,14 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
</span><del>-- (void)_setWKContentsDisplayList:(CFDataRef)data
</del><ins>+- (void)_setWKContents:(id)contents withDisplayList:(CFDataRef)data
</ins><span class="cx"> {
</span><del>-    _contentsDisplayList = data;
-    [self setNeedsDisplay];
</del><ins>+    self.contents = contents;
+    [self setValue:(id)data forKeyPath:WKCGDisplayListContentsKey];
+    
+    
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (CFDataRef)_wkContentsDisplayList
-{
-    return _contentsDisplayList.get();
-}
-
-- (void)drawInContext:(CGContextRef)context
-{
-    if (!_contentsDisplayList)
-        return;
-    WKCGContextDrawCGCommandsEncodedData(context, _contentsDisplayList.get(), nullptr);
-}
</del><span class="cx"> #endif // ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageRemoteLayerTreePlatformCALayerRemotecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp (279991 => 279992)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp 2021-07-16 18:18:05 UTC (rev 279991)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp    2021-07-16 18:24:35 UTC (rev 279992)
</span><span class="lines">@@ -234,11 +234,12 @@
</span><span class="cx">     ASSERT(m_properties.backingStoreAttached);
</span><span class="cx"> 
</span><span class="cx">     auto type = m_acceleratesDrawing ? RemoteLayerBackingStore::Type::IOSurface : RemoteLayerBackingStore::Type::Bitmap;
</span><ins>+    auto includeDisplayList = RemoteLayerBackingStore::IncludeDisplayList::No;
</ins><span class="cx"> #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
</span><span class="cx">     if (m_context->useCGDisplayListsForDOMRendering())
</span><del>-        type = RemoteLayerBackingStore::Type::CGDisplayList;
</del><ins>+        includeDisplayList = RemoteLayerBackingStore::IncludeDisplayList::Yes;
</ins><span class="cx"> #endif
</span><del>-    m_properties.backingStore->ensureBackingStore(type, m_properties.bounds.size(), m_properties.contentsScale, m_wantsDeepColorBackingStore, m_properties.opaque);
</del><ins>+    m_properties.backingStore->ensureBackingStore(type, m_properties.bounds.size(), m_properties.contentsScale, m_wantsDeepColorBackingStore, m_properties.opaque, includeDisplayList);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PlatformCALayerRemote::setNeedsDisplayInRect(const FloatRect& rect)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageRemoteLayerTreeRemoteLayerTreeDrawingAreamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm (279991 => 279992)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm     2021-07-16 18:18:05 UTC (rev 279991)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm        2021-07-16 18:24:35 UTC (rev 279992)
</span><span class="lines">@@ -387,10 +387,8 @@
</span><span class="cx">     for (auto& layer : layerTransaction.changedLayers()) {
</span><span class="cx">         if (layer->properties().changedProperties & RemoteLayerTreeTransaction::BackingStoreChanged) {
</span><span class="cx">             hadAnyChangedBackingStore = true;
</span><del>-            if (layer->properties().backingStore) {
-                if (auto pendingFlusher = layer->properties().backingStore->takePendingFlusher())
-                    flushers.append(WTFMove(pendingFlusher));
-            }
</del><ins>+            if (layer->properties().backingStore)
+                flushers.appendVector(layer->properties().backingStore->takePendingFlushers());
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         layer->didCommit();
</span></span></pre>
</div>
</div>

</body>
</html>