- Revision
- 291599
- Author
- simon.fra...@apple.com
- Date
- 2022-03-21 20:33:18 -0700 (Mon, 21 Mar 2022)
Log Message
Do all RemoteLayerBackingStore buffer swapping in one batch
https://bugs.webkit.org/show_bug.cgi?id=238161
Reviewed by Tim Horton.
Previously, RemoteLayerBackingStore buffer swapping happened per-layer in
PlatformCALayerRemote::recursiveBuildTransaction().
To prepare for a single IPC for all buffer swapping, batch all the swapping under
prepareBackingStoresForDisplay() which is called from
RemoteLayerTreeContext::buildTransaction().
RemoteLayerBackingStoreCollection tracks m_backingStoresNeedingDisplay, and
RemoteLayerBackingStore implements needsDisplay() so we only add backing stores to this hash
set that need any buffer swapping.
* Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
* Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::layerWillBeDisplayed):
(WebKit::RemoteLayerBackingStore::needsDisplay const):
(WebKit::RemoteLayerBackingStore::prepareToDisplay):
(WebKit::RemoteLayerBackingStore::paintContents):
(WebKit::RemoteLayerBackingStore::takePendingFlushers):
* Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h:
* Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm:
(WebKit::RemoteLayerBackingStoreCollection::backingStoreNeedsDisplay):
(WebKit::RemoteLayerBackingStoreCollection::prepareBackingStoresForDisplay):
(WebKit::RemoteLayerBackingStoreCollection::paintReachableBackingStoreContents):
(WebKit::RemoteLayerBackingStoreCollection::willFlushLayers):
(WebKit::RemoteLayerBackingStoreCollection::backingStoreWillBeDisplayed):
* Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h:
* Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm:
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::backingStoreNeedsDisplay):
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoreBuffers):
* WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp:
(WebKit::PlatformCALayerRemote::recursiveBuildTransaction):
* WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::buildTransaction):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (291598 => 291599)
--- trunk/Source/WebKit/ChangeLog 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/ChangeLog 2022-03-22 03:33:18 UTC (rev 291599)
@@ -1,3 +1,44 @@
+2022-03-21 Simon Fraser <simon.fra...@apple.com>
+
+ Do all RemoteLayerBackingStore buffer swapping in one batch
+ https://bugs.webkit.org/show_bug.cgi?id=238161
+
+ Reviewed by Tim Horton.
+
+ Previously, RemoteLayerBackingStore buffer swapping happened per-layer in
+ PlatformCALayerRemote::recursiveBuildTransaction().
+
+ To prepare for a single IPC for all buffer swapping, batch all the swapping under
+ prepareBackingStoresForDisplay() which is called from
+ RemoteLayerTreeContext::buildTransaction().
+
+ RemoteLayerBackingStoreCollection tracks m_backingStoresNeedingDisplay, and
+ RemoteLayerBackingStore implements needsDisplay() so we only add backing stores to this hash
+ set that need any buffer swapping.
+
+ * Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
+ * Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
+ (WebKit::RemoteLayerBackingStore::layerWillBeDisplayed):
+ (WebKit::RemoteLayerBackingStore::needsDisplay const):
+ (WebKit::RemoteLayerBackingStore::prepareToDisplay):
+ (WebKit::RemoteLayerBackingStore::paintContents):
+ (WebKit::RemoteLayerBackingStore::takePendingFlushers):
+ * Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h:
+ * Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm:
+ (WebKit::RemoteLayerBackingStoreCollection::backingStoreNeedsDisplay):
+ (WebKit::RemoteLayerBackingStoreCollection::prepareBackingStoresForDisplay):
+ (WebKit::RemoteLayerBackingStoreCollection::paintReachableBackingStoreContents):
+ (WebKit::RemoteLayerBackingStoreCollection::willFlushLayers):
+ (WebKit::RemoteLayerBackingStoreCollection::backingStoreWillBeDisplayed):
+ * Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h:
+ * Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm:
+ (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::backingStoreNeedsDisplay):
+ (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoreBuffers):
+ * WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp:
+ (WebKit::PlatformCALayerRemote::recursiveBuildTransaction):
+ * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
+ (WebKit::RemoteLayerTreeContext::buildTransaction):
+
2022-03-21 Alex Christensen <achristen...@webkit.org>
Adjust when _setPrivacyProxyFailClosedForUnreachableNonMainHosts is called
Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h (291598 => 291599)
--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h 2022-03-22 03:33:18 UTC (rev 291599)
@@ -69,8 +69,11 @@
SwapBuffersDisplayRequirement prepareBuffers(bool hasEmptyDirtyRegion);
- // Returns true if the backing store changed.
- bool prepareToDisplay();
+ // Returns true if we need encode the buffer.
+ bool layerWillBeDisplayed();
+ bool needsDisplay() const;
+
+ void prepareToDisplay();
void paintContents();
WebCore::FloatSize size() const { return m_size; }
Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm (291598 => 291599)
--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm 2022-03-22 03:33:18 UTC (rev 291599)
@@ -182,6 +182,17 @@
return true;
}
+bool RemoteLayerBackingStore::layerWillBeDisplayed()
+{
+ auto* collection = backingStoreCollection();
+ if (!collection) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+
+ return collection->backingStoreWillBeDisplayed(*this);
+}
+
void RemoteLayerBackingStore::setNeedsDisplay(const WebCore::IntRect rect)
{
m_dirtyRegion.unite(rect);
@@ -273,28 +284,44 @@
}
#endif
-bool RemoteLayerBackingStore::prepareToDisplay()
+bool RemoteLayerBackingStore::needsDisplay() const
{
+ auto* collection = backingStoreCollection();
+ if (!collection) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+
+ if (m_layer->owner()->platformCALayerDelegatesDisplay(m_layer)) {
+ LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " needsDisplay() - delegates display");
+ return true;
+ }
+
+ bool needsDisplay = collection->backingStoreNeedsDisplay(*this);
+ LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " needsDisplay() - needsDisplay " << needsDisplay);
+ return needsDisplay;
+}
+
+void RemoteLayerBackingStore::prepareToDisplay()
+{
ASSERT(!m_frontBufferFlushers.size());
- m_lastDisplayTime = MonotonicTime::now();
-
auto* collection = backingStoreCollection();
if (!collection) {
ASSERT_NOT_REACHED();
- return false;
+ return;
}
+ ASSERT(collection->backingStoreNeedsDisplay(*this));
+
LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " prepareToDisplay()");
- bool needToEncodeBackingStore = collection->backingStoreWillBeDisplayed(*this);
-
auto& layerOwner = *m_layer->owner();
if (layerOwner.platformCALayerDelegatesDisplay(m_layer)) {
// This can call back to setContents(), setting m_contentsBufferHandle.
layerOwner.platformCALayerLayerDisplay(m_layer);
layerOwner.platformCALayerLayerDidDisplay(m_layer);
- return true;
+ return;
}
m_contentsBufferHandle = std::nullopt;
@@ -303,8 +330,7 @@
LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " prepareToDisplay() - " << displayRequirement);
- if (displayRequirement == SwapBuffersDisplayRequirement::NeedsNoDisplay)
- return needToEncodeBackingStore;
+ ASSERT(displayRequirement != SwapBuffersDisplayRequirement::NeedsNoDisplay);
if (displayRequirement == SwapBuffersDisplayRequirement::NeedsFullDisplay)
setNeedsDisplay();
@@ -322,8 +348,6 @@
m_frontBuffer.displayListImageBuffer = WebCore::ConcreteImageBuffer<CGDisplayListImageBufferBackend>::create(m_size, m_scale, WebCore::DestinationColorSpace::SRGB(), pixelFormat(), nullptr);
#endif
}
-
- return true;
}
SwapBuffersDisplayRequirement RemoteLayerBackingStore::prepareBuffers(bool hasEmptyDirtyRegion)
@@ -354,9 +378,12 @@
if (!m_frontBuffer.imageBuffer)
return;
- if (m_dirtyRegion.isEmpty() || m_size.isEmpty())
+ LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " paintContents() - has dirty region " << !hasEmptyDirtyRegion());
+ if (hasEmptyDirtyRegion())
return;
+ m_lastDisplayTime = MonotonicTime::now();
+
if (m_includeDisplayList == IncludeDisplayList::Yes) {
#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
auto& displayListContext = m_frontBuffer.displayListImageBuffer->context();
@@ -552,6 +579,7 @@
Vector<std::unique_ptr<WebCore::ThreadSafeImageBufferFlusher>> RemoteLayerBackingStore::takePendingFlushers()
{
+ LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " takePendingFlushers()");
return std::exchange(m_frontBufferFlushers, { });
}
Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h (291598 => 291599)
--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h 2022-03-22 03:33:18 UTC (rev 291599)
@@ -58,9 +58,12 @@
// Return value indicates whether the backing store needs to be included in the transaction.
bool backingStoreWillBeDisplayed(RemoteLayerBackingStore&);
void backingStoreBecameUnreachable(RemoteLayerBackingStore&);
-
+
+ virtual bool backingStoreNeedsDisplay(const RemoteLayerBackingStore&);
+
virtual SwapBuffersDisplayRequirement prepareBackingStoreBuffers(RemoteLayerBackingStore&);
+ void prepareBackingStoresForDisplay(RemoteLayerTreeTransaction&);
void paintReachableBackingStoreContents();
void willFlushLayers();
@@ -102,6 +105,7 @@
// Only used during a single flush.
HashSet<RemoteLayerBackingStore*> m_reachableBackingStoreInLatestFlush;
+ HashSet<RemoteLayerBackingStore*> m_backingStoresNeedingDisplay;
WebCore::Timer m_volatilityTimer;
Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm (291598 => 291599)
--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm 2022-03-22 03:33:18 UTC (rev 291599)
@@ -47,16 +47,40 @@
RemoteLayerBackingStoreCollection::~RemoteLayerBackingStoreCollection() = default;
+bool RemoteLayerBackingStoreCollection::backingStoreNeedsDisplay(const RemoteLayerBackingStore& backingStore)
+{
+ auto frontBuffer = backingStore.bufferForType(RemoteLayerBackingStore::BufferType::Front);
+ if (!frontBuffer)
+ return true;
+
+ if (frontBuffer->volatilityState() == WebCore::VolatilityState::Volatile)
+ return true;
+
+ return !backingStore.hasEmptyDirtyRegion();
+}
+
+void RemoteLayerBackingStoreCollection::prepareBackingStoresForDisplay(RemoteLayerTreeTransaction& transaction)
+{
+ for (auto* backingStore : m_backingStoresNeedingDisplay) {
+ backingStore->prepareToDisplay();
+ backingStore->layer()->properties().notePropertiesChanged(RemoteLayerTreeTransaction::BackingStoreChanged);
+ transaction.layerPropertiesChanged(*backingStore->layer());
+ }
+}
+
void RemoteLayerBackingStoreCollection::paintReachableBackingStoreContents()
{
- for (auto* backingStore : m_reachableBackingStoreInLatestFlush)
+ for (auto* backingStore : m_backingStoresNeedingDisplay)
backingStore->paintContents();
}
void RemoteLayerBackingStoreCollection::willFlushLayers()
{
+ LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "\nRemoteLayerBackingStoreCollection::willFlushLayers()");
+
m_inLayerFlush = true;
m_reachableBackingStoreInLatestFlush.clear();
+ m_backingStoresNeedingDisplay.clear();
}
void RemoteLayerBackingStoreCollection::willCommitLayerTree(RemoteLayerTreeTransaction& transaction)
@@ -127,6 +151,9 @@
ASSERT(m_inLayerFlush);
m_reachableBackingStoreInLatestFlush.add(&backingStore);
+ if (backingStore.needsDisplay())
+ m_backingStoresNeedingDisplay.add(&backingStore);
+
auto backingStoreIter = m_unparentedBackingStore.find(&backingStore);
if (backingStoreIter == m_unparentedBackingStore.end())
return false;
Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h (291598 => 291599)
--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h 2022-03-22 03:33:18 UTC (rev 291599)
@@ -43,6 +43,7 @@
RemoteRenderingBackendProxy& remoteRenderingBackendProxy();
+ bool backingStoreNeedsDisplay(const RemoteLayerBackingStore&) final;
SwapBuffersDisplayRequirement prepareBackingStoreBuffers(RemoteLayerBackingStore&) final;
bool collectBackingStoreBufferIdentifiersToMarkVolatile(RemoteLayerBackingStore&, OptionSet<VolatilityMarkingBehavior>, MonotonicTime now, Vector<WebCore::RenderingResourceIdentifier>&);
Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm (291598 => 291599)
--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm 2022-03-22 03:33:18 UTC (rev 291599)
@@ -44,36 +44,32 @@
return layerTreeContext().ensureRemoteRenderingBackendProxy();
}
-SwapBuffersDisplayRequirement RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoreBuffers(RemoteLayerBackingStore& backingStore)
+bool RemoteLayerWithRemoteRenderingBackingStoreCollection::backingStoreNeedsDisplay(const RemoteLayerBackingStore& backingStore)
{
auto frontBuffer = backingStore.bufferForType(RemoteLayerBackingStore::BufferType::Front);
+ if (!frontBuffer)
+ return true;
- auto needToFetchFrontBuffer = [](ImageBuffer* frontBuffer) {
- if (!frontBuffer)
- return true;
+ if (frontBuffer->volatilityState() == WebCore::VolatilityState::Volatile)
+ return true;
- if (frontBuffer->volatilityState() == WebCore::VolatilityState::Volatile)
- return true;
-
- if (auto* backend = frontBuffer->ensureBackendCreated()) {
- auto* sharing = backend->toBackendSharing();
- if (is<ImageBufferBackendHandleSharing>(sharing)) {
- if (!downcast<ImageBufferBackendHandleSharing>(*sharing).hasBackendHandle())
- return true;
- }
+ if (auto* backend = frontBuffer->ensureBackendCreated()) {
+ auto* sharing = backend->toBackendSharing();
+ if (is<ImageBufferBackendHandleSharing>(sharing)) {
+ if (!downcast<ImageBufferBackendHandleSharing>(*sharing).hasBackendHandle())
+ return true;
}
+ }
- return false;
- };
+ return !backingStore.hasEmptyDirtyRegion();
+}
- // Avoid IPC if not necessary.
- if (!needToFetchFrontBuffer(frontBuffer.get()) && backingStore.hasEmptyDirtyRegion())
- return SwapBuffersDisplayRequirement::NeedsNoDisplay;
-
+SwapBuffersDisplayRequirement RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoreBuffers(RemoteLayerBackingStore& backingStore)
+{
auto& remoteRenderingBackend = layerTreeContext().ensureRemoteRenderingBackendProxy();
auto identifiers = RemoteRenderingBackendProxy::BufferSet {
- frontBuffer,
+ backingStore.bufferForType(RemoteLayerBackingStore::BufferType::Front),
backingStore.bufferForType(RemoteLayerBackingStore::BufferType::Back),
backingStore.bufferForType(RemoteLayerBackingStore::BufferType::SecondaryBack)
};
Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp (291598 => 291599)
--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp 2022-03-22 03:33:18 UTC (rev 291599)
@@ -178,7 +178,8 @@
m_properties.backingStore = nullptr;
m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BackingStoreChanged);
}
- if (m_properties.backingStore && m_properties.backingStoreAttached && m_properties.backingStore->prepareToDisplay())
+
+ if (m_properties.backingStore && m_properties.backingStoreAttached && m_properties.backingStore->layerWillBeDisplayed())
m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BackingStoreChanged);
if (m_properties.changedProperties) {
Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm (291598 => 291599)
--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm 2022-03-22 03:28:05 UTC (rev 291598)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm 2022-03-22 03:33:18 UTC (rev 291599)
@@ -137,6 +137,7 @@
m_currentTransaction = &transaction;
rootLayerRemote.recursiveBuildTransaction(*this, transaction);
+ m_backingStoreCollection->prepareBackingStoresForDisplay(transaction);
m_currentTransaction = nullptr;
m_backingStoreCollection->paintReachableBackingStoreContents();