Title: [290085] trunk/Source/WebKit
Revision
290085
Author
[email protected]
Date
2022-02-17 15:48:45 -0800 (Thu, 17 Feb 2022)

Log Message

Move setting RemoteLayerBackingStore surfaces volatile into the GPU Process
https://bugs.webkit.org/show_bug.cgi?id=236791

Reviewed by Tim Horton.

Setting RemoteLayerBackingStore IOSurfaces volatile has to happen in the GPU process with
DOM rendering enabled. Add overrides in RemoteLayerWithRemoteRenderingBackingStoreCollection
to handle this, sending batches of buffer identifiers to RemoteRenderingBackend. Because
surface in-use counts can cause this to fail, we return a list of identifiers that we failed
to mark volatile. A future patch will use these to maintain web process-side buffer volatile
status.

* GPUProcess/graphics/RemoteRenderingBackend.cpp:
(WebKit::RemoteRenderingBackend::markSurfacesVolatile):
* GPUProcess/graphics/RemoteRenderingBackend.h:
* GPUProcess/graphics/RemoteRenderingBackend.messages.in:
* Platform/Logging.h:
* Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
* Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h:
(WebKit::RemoteLayerBackingStoreCollection::markBackingStoreVolatile):
* Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm:
(WebKit::RemoteLayerBackingStoreCollection::backingStoreBecameUnreachable):
(WebKit::RemoteLayerBackingStoreCollection::markBackingStoreVolatileAfterReachabilityChange):
(WebKit::RemoteLayerBackingStoreCollection::markAllBackingStoreVolatileFromTimer):
(WebKit::RemoteLayerBackingStoreCollection::volatilityTimerFired):
* Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h:
* Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm:
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::collectBackingStoreBufferIdentifiersToMarkVolatile):
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::collectAllBufferIdentifiersToMarkVolatile):
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::markBackingStoreVolatileAfterReachabilityChange):
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::tryMarkAllBackingStoreVolatile):
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::markAllBackingStoreVolatileFromTimer):
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::sendMarkBuffersVolatile):
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::markSurfacesVolatile):
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290084 => 290085)


--- trunk/Source/WebKit/ChangeLog	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/ChangeLog	2022-02-17 23:48:45 UTC (rev 290085)
@@ -1,3 +1,42 @@
+2022-02-17  Simon Fraser  <[email protected]>
+
+        Move setting RemoteLayerBackingStore surfaces volatile into the GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=236791
+
+        Reviewed by Tim Horton.
+        
+        Setting RemoteLayerBackingStore IOSurfaces volatile has to happen in the GPU process with
+        DOM rendering enabled. Add overrides in RemoteLayerWithRemoteRenderingBackingStoreCollection
+        to handle this, sending batches of buffer identifiers to RemoteRenderingBackend. Because
+        surface in-use counts can cause this to fail, we return a list of identifiers that we failed
+        to mark volatile. A future patch will use these to maintain web process-side buffer volatile
+        status.
+
+        * GPUProcess/graphics/RemoteRenderingBackend.cpp:
+        (WebKit::RemoteRenderingBackend::markSurfacesVolatile):
+        * GPUProcess/graphics/RemoteRenderingBackend.h:
+        * GPUProcess/graphics/RemoteRenderingBackend.messages.in:
+        * Platform/Logging.h:
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
+        * Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h:
+        (WebKit::RemoteLayerBackingStoreCollection::markBackingStoreVolatile):
+        * Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm:
+        (WebKit::RemoteLayerBackingStoreCollection::backingStoreBecameUnreachable):
+        (WebKit::RemoteLayerBackingStoreCollection::markBackingStoreVolatileAfterReachabilityChange):
+        (WebKit::RemoteLayerBackingStoreCollection::markAllBackingStoreVolatileFromTimer):
+        (WebKit::RemoteLayerBackingStoreCollection::volatilityTimerFired):
+        * Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h:
+        * Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm:
+        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::collectBackingStoreBufferIdentifiersToMarkVolatile):
+        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::collectAllBufferIdentifiersToMarkVolatile):
+        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::markBackingStoreVolatileAfterReachabilityChange):
+        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::tryMarkAllBackingStoreVolatile):
+        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::markAllBackingStoreVolatileFromTimer):
+        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::sendMarkBuffersVolatile):
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
+        (WebKit::RemoteRenderingBackendProxy::markSurfacesVolatile):
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
+
 2022-02-17  Diego Pino Garcia  <[email protected]>
 
         [macOS] Non-unified build fixes

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (290084 => 290085)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-02-17 23:48:45 UTC (rev 290085)
@@ -451,6 +451,30 @@
     completionHandler({ bufferIdentifer(frontBuffer), bufferIdentifer(backBuffer), bufferIdentifer(secondaryBackBuffer) }, WTFMove(frontBufferHandle), frontBufferWasEmpty);
 }
 
+void RemoteRenderingBackend::markSurfacesVolatile(const Vector<WebCore::RenderingResourceIdentifier>& identifiers, CompletionHandler<void(const Vector<WebCore::RenderingResourceIdentifier>& inUseBufferIdentifiers)>&& completionHandler)
+{
+    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "GPU Process: RemoteRenderingBackend::markSurfacesVolatile " << identifiers);
+
+    auto makeVolatile = [](ImageBuffer& imageBuffer) {
+        imageBuffer.releaseGraphicsContext();
+        return imageBuffer.setVolatile();
+    };
+
+    Vector<WebCore::RenderingResourceIdentifier> inUseBufferIdentifiers;
+    for (auto identifier : identifiers) {
+        auto imageBuffer = m_remoteResourceCache.cachedImageBuffer({ identifier, m_gpuConnectionToWebProcess->webProcessIdentifier() });
+        if (imageBuffer) {
+            if (!makeVolatile(*imageBuffer))
+                inUseBufferIdentifiers.append(identifier);
+        } else
+            LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << " failed to find ImageBuffer for identifier " << identifier);
+    }
+
+    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "GPU Process: markSurfacesVolatile - in-use surfaces " << inUseBufferIdentifiers);
+
+    completionHandler(inUseBufferIdentifiers);
+}
+
 void RemoteRenderingBackend::finalizeRenderingUpdate(RenderingUpdateID renderingUpdateID)
 {
     send(Messages::RemoteRenderingBackendProxy::DidFinalizeRenderingUpdate(renderingUpdateID), m_renderingBackendIdentifier);

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h (290084 => 290085)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h	2022-02-17 23:48:45 UTC (rev 290085)
@@ -118,6 +118,7 @@
     void deleteAllFonts();
     void releaseRemoteResource(WebCore::RenderingResourceIdentifier);
     void finalizeRenderingUpdate(RenderingUpdateID);
+    void markSurfacesVolatile(const Vector<WebCore::RenderingResourceIdentifier>&, CompletionHandler<void(const Vector<WebCore::RenderingResourceIdentifier>& inUseBufferIdentifiers)>&&);
 
     void markSurfaceNonVolatile(WebCore::RenderingResourceIdentifier, CompletionHandler<void(std::optional<ImageBufferBackendHandle>, bool bufferWasEmpty)>&&);
     void swapToValidFrontBuffer(const BufferIdentifierSet& bufferSet, CompletionHandler<void(const BufferIdentifierSet& swappedBufferSet, std::optional<ImageBufferBackendHandle>&& frontBufferHandle, bool frontBufferWasEmpty)>&&);

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in (290084 => 290085)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in	2022-02-17 23:48:45 UTC (rev 290085)
@@ -40,6 +40,8 @@
     MarkSurfaceNonVolatile(WebCore::RenderingResourceIdentifier renderingResourceIdentifier) -> (std::optional<WebKit::ImageBufferBackendHandle> backendHandle, bool bufferWasEmpty) Synchronous NotStreamEncodableReply
     SwapToValidFrontBuffer(struct WebKit::BufferIdentifierSet bufferSet) -> (struct WebKit::BufferIdentifierSet swappedBufferSet, std::optional<WebKit::ImageBufferBackendHandle> frontBufferHandle, bool frontBufferWasEmpty) Synchronous NotStreamEncodableReply
 
+    MarkSurfacesVolatile(Vector<WebCore::RenderingResourceIdentifier> renderingResourceIdentifiers) -> (Vector<WebCore::RenderingResourceIdentifier> inUseBufferIdentifiers) Synchronous
+
     FinalizeRenderingUpdate(WebKit::RenderingUpdateID renderingUpdateID)
 }
 

Modified: trunk/Source/WebKit/Platform/Logging.h (290084 => 290085)


--- trunk/Source/WebKit/Platform/Logging.h	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/Platform/Logging.h	2022-02-17 23:48:45 UTC (rev 290085)
@@ -89,6 +89,7 @@
     M(ProcessSwapping) \
     M(ProximityNetworking) \
     M(Push) \
+    M(RemoteRenderingBufferVolatility) \
     M(RemoteLayerTree) \
     M(Resize) \
     M(ResourceLoadStatistics) \

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h (290084 => 290085)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h	2022-02-17 23:48:45 UTC (rev 290085)
@@ -124,6 +124,8 @@
 #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
         RefPtr<WebCore::ImageBuffer> displayListImageBuffer;
 #endif
+        // FIXME: This flag needs to be part of ImageBuffer[Backend]. Currently it's not correctly maintained
+        // in the GPU Process code path.
         bool isVolatile = false;
 
         explicit operator bool() const

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h (290084 => 290085)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h	2022-02-17 23:48:45 UTC (rev 290085)
@@ -29,6 +29,7 @@
 #import <wtf/HashSet.h>
 #import <wtf/Noncopyable.h>
 #import <wtf/OptionSet.h>
+#import <wtf/WeakPtr.h>
 
 namespace WebCore {
 class ImageBuffer;
@@ -40,7 +41,7 @@
 class RemoteLayerTreeContext;
 class RemoteLayerTreeTransaction;
 
-class RemoteLayerBackingStoreCollection {
+class RemoteLayerBackingStoreCollection : public CanMakeWeakPtr<RemoteLayerBackingStoreCollection> {
     WTF_MAKE_NONCOPYABLE(RemoteLayerBackingStoreCollection);
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -61,7 +62,7 @@
     void willCommitLayerTree(RemoteLayerTreeTransaction&);
     void didFlushLayers();
 
-    void tryMarkAllBackingStoreVolatile(CompletionHandler<void(bool)>&&);
+    virtual void tryMarkAllBackingStoreVolatile(CompletionHandler<void(bool)>&&);
 
     void scheduleVolatilityTimer();
 
@@ -70,16 +71,24 @@
 protected:
     RemoteLayerTreeContext& layerTreeContext() const { return m_layerTreeContext; }
 
-private:
     enum class VolatilityMarkingBehavior : uint8_t {
         IgnoreReachability              = 1 << 0,
         ConsiderTimeSinceLastDisplay    = 1 << 1,
     };
+
+    virtual void markBackingStoreVolatileAfterReachabilityChange(RemoteLayerBackingStore&);
+    virtual void markAllBackingStoreVolatileFromTimer();
+
+private:
     bool markBackingStoreVolatile(RemoteLayerBackingStore&, OptionSet<VolatilityMarkingBehavior> = { }, MonotonicTime = { });
+    bool markAllBackingStoreVolatile(OptionSet<VolatilityMarkingBehavior> liveBackingStoreMarkingBehavior, OptionSet<VolatilityMarkingBehavior> unparentedBackingStoreMarkingBehavior);
 
-    bool markAllBackingStoreVolatile(OptionSet<VolatilityMarkingBehavior> liveBackingStoreMarkingBehavior, OptionSet<VolatilityMarkingBehavior> unparentedBackingStoreMarkingBehavior);
     void volatilityTimerFired();
 
+protected:
+    static constexpr auto volatileBackingStoreAgeThreshold = 1_s;
+    static constexpr auto volatileSecondaryBackingStoreAgeThreshold = 200_ms;
+
     RemoteLayerTreeContext& m_layerTreeContext;
 
     HashSet<RemoteLayerBackingStore*> m_liveBackingStore;

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm (290084 => 290085)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm	2022-02-17 23:48:45 UTC (rev 290085)
@@ -26,14 +26,14 @@
 #import "config.h"
 #import "RemoteLayerBackingStoreCollection.h"
 
+#import "Logging.h"
 #import "PlatformCALayerRemote.h"
 #import "PlatformImageBufferShareableBackend.h"
 #import "RemoteLayerBackingStore.h"
 #import "RemoteLayerTreeContext.h"
 #import <WebCore/ConcreteImageBuffer.h>
+#import <wtf/text/TextStream.h>
 
-const Seconds volatileBackingStoreAgeThreshold = 1_s;
-const Seconds volatileSecondaryBackingStoreAgeThreshold = 200_ms;
 const Seconds volatilityTimerInterval = 200_ms;
 
 namespace WebKit {
@@ -159,6 +159,11 @@
 
     // This will not succeed in marking all buffers as volatile, because the commit unparenting the layer hasn't
     // made it to the UI process yet. The volatility timer will finish marking the remaining buffers later.
+    markBackingStoreVolatileAfterReachabilityChange(backingStore);
+}
+
+void RemoteLayerBackingStoreCollection::markBackingStoreVolatileAfterReachabilityChange(RemoteLayerBackingStore& backingStore)
+{
     markBackingStoreVolatile(backingStore);
 }
 
@@ -182,13 +187,20 @@
     completionHandler(successfullyMadeBackingStoreVolatile);
 }
 
-void RemoteLayerBackingStoreCollection::volatilityTimerFired()
+void RemoteLayerBackingStoreCollection::markAllBackingStoreVolatileFromTimer()
 {
     bool successfullyMadeBackingStoreVolatile = markAllBackingStoreVolatile(VolatilityMarkingBehavior::ConsiderTimeSinceLastDisplay, { });
+    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStoreCollection::markAllBackingStoreVolatileFromTimer() - live " << m_liveBackingStore.size() << ", unparented " << m_unparentedBackingStore.size() << "; successfullyMadeBackingStoreVolatile " << successfullyMadeBackingStoreVolatile);
+
     if (successfullyMadeBackingStoreVolatile)
         m_volatilityTimer.stop();
 }
 
+void RemoteLayerBackingStoreCollection::volatilityTimerFired()
+{
+    markAllBackingStoreVolatileFromTimer();
+}
+
 void RemoteLayerBackingStoreCollection::scheduleVolatilityTimer()
 {
     if (m_volatilityTimer.isActive())

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h (290084 => 290085)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h	2022-02-17 23:48:45 UTC (rev 290085)
@@ -45,6 +45,16 @@
 
     void makeFrontBufferNonVolatile(RemoteLayerBackingStore&) final;
     void swapToValidFrontBuffer(RemoteLayerBackingStore&) final;
+
+    bool collectBackingStoreBufferIdentifiersToMarkVolatile(RemoteLayerBackingStore&, OptionSet<VolatilityMarkingBehavior>, MonotonicTime now, Vector<WebCore::RenderingResourceIdentifier>&);
+
+    bool collectAllBufferIdentifiersToMarkVolatile(OptionSet<VolatilityMarkingBehavior> liveBackingStoreMarkingBehavior, OptionSet<VolatilityMarkingBehavior> unparentedBackingStoreMarkingBehavior, Vector<WebCore::RenderingResourceIdentifier>&);
+
+    void markBackingStoreVolatileAfterReachabilityChange(RemoteLayerBackingStore&) final;
+    void tryMarkAllBackingStoreVolatile(CompletionHandler<void(bool)>&&) final;
+    void markAllBackingStoreVolatileFromTimer() final;
+    
+    void sendMarkBuffersVolatile(Vector<WebCore::RenderingResourceIdentifier>&&, CompletionHandler<void(bool)>&&);
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm (290084 => 290085)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm	2022-02-17 23:48:45 UTC (rev 290085)
@@ -26,8 +26,10 @@
 #import "config.h"
 #import "RemoteLayerWithRemoteRenderingBackingStoreCollection.h"
 
+#import "Logging.h"
 #import "RemoteLayerTreeContext.h"
 #import "RemoteRenderingBackendProxy.h"
+#import <wtf/text/TextStream.h>
 
 namespace WebKit {
 
@@ -71,4 +73,119 @@
     return remoteRenderingBackendProxy().createImageBuffer(backingStore.size(), renderingMode, backingStore.scale(), WebCore::DestinationColorSpace::SRGB(), backingStore.pixelFormat());
 }
 
+bool RemoteLayerWithRemoteRenderingBackingStoreCollection::collectBackingStoreBufferIdentifiersToMarkVolatile(RemoteLayerBackingStore& backingStore, OptionSet<VolatilityMarkingBehavior> markingBehavior, MonotonicTime now, Vector<WebCore::RenderingResourceIdentifier>& identifiers)
+{
+    ASSERT(!m_inLayerFlush);
+
+    // FIXME: This doesn't consult RemoteLayerBackingStore::Buffer::isVolatile, so we may redundantly request volatility.
+    auto collectBuffer = [&](RemoteLayerBackingStore::BufferType bufferType) {
+        auto buffer = backingStore.bufferForType(bufferType);
+        if (!buffer)
+            return;
+
+        backingStore.willMakeBufferVolatile(bufferType);
+        identifiers.append(buffer->renderingResourceIdentifier());
+    };
+
+    if (markingBehavior.contains(VolatilityMarkingBehavior::ConsiderTimeSinceLastDisplay)) {
+        auto timeSinceLastDisplay = now - backingStore.lastDisplayTime();
+        if (timeSinceLastDisplay < volatileBackingStoreAgeThreshold) {
+            if (timeSinceLastDisplay >= volatileSecondaryBackingStoreAgeThreshold)
+                collectBuffer(RemoteLayerBackingStore::BufferType::SecondaryBack);
+
+            return false;
+        }
+    }
+
+    collectBuffer(RemoteLayerBackingStore::BufferType::SecondaryBack);
+    collectBuffer(RemoteLayerBackingStore::BufferType::Back);
+
+    if (!m_reachableBackingStoreInLatestFlush.contains(&backingStore) || markingBehavior.contains(VolatilityMarkingBehavior::IgnoreReachability))
+        collectBuffer(RemoteLayerBackingStore::BufferType::Front);
+
+    return true;
+}
+
+bool RemoteLayerWithRemoteRenderingBackingStoreCollection::collectAllBufferIdentifiersToMarkVolatile(OptionSet<VolatilityMarkingBehavior> liveBackingStoreMarkingBehavior, OptionSet<VolatilityMarkingBehavior> unparentedBackingStoreMarkingBehavior, Vector<WebCore::RenderingResourceIdentifier>& identifiers)
+{
+    bool completed = true;
+    auto now = MonotonicTime::now();
+
+    for (const auto& backingStore : m_liveBackingStore)
+        completed &= collectBackingStoreBufferIdentifiersToMarkVolatile(*backingStore, liveBackingStoreMarkingBehavior, now, identifiers);
+
+    for (const auto& backingStore : m_unparentedBackingStore)
+        completed &= collectBackingStoreBufferIdentifiersToMarkVolatile(*backingStore, unparentedBackingStoreMarkingBehavior, now, identifiers);
+
+    return completed;
+}
+
+void RemoteLayerWithRemoteRenderingBackingStoreCollection::markBackingStoreVolatileAfterReachabilityChange(RemoteLayerBackingStore& backingStore)
+{
+    Vector<WebCore::RenderingResourceIdentifier> identifiers;
+    collectBackingStoreBufferIdentifiersToMarkVolatile(backingStore, { }, { }, identifiers);
+
+    if (identifiers.isEmpty())
+        return;
+
+    sendMarkBuffersVolatile(WTFMove(identifiers), [](bool succeeded) {
+        LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerWithRemoteRenderingBackingStoreCollection::markBackingStoreVolatileAfterReachabilityChange - succeeded " << succeeded);
+    });
+}
+
+void RemoteLayerWithRemoteRenderingBackingStoreCollection::tryMarkAllBackingStoreVolatile(CompletionHandler<void(bool)>&& completionHandler)
+{
+    Vector<WebCore::RenderingResourceIdentifier> identifiers;
+    bool completed = collectAllBufferIdentifiersToMarkVolatile(VolatilityMarkingBehavior::IgnoreReachability, VolatilityMarkingBehavior::IgnoreReachability, identifiers);
+
+    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerWithRemoteRenderingBackingStoreCollection::tryMarkAllBackingStoreVolatile pid " << getpid() << " - live " << m_liveBackingStore.size() << ", unparented " << m_unparentedBackingStore.size() << " " << identifiers);
+
+    if (identifiers.isEmpty()) {
+        completionHandler(true);
+        return;
+    }
+
+    sendMarkBuffersVolatile(WTFMove(identifiers), [completed, completionHandler = WTFMove(completionHandler)](bool succeeded) mutable {
+        LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerWithRemoteRenderingBackingStoreCollection::tryMarkAllBackingStoreVolatile - completed " << completed << ", succeeded " << succeeded);
+        completionHandler(completed && succeeded);
+    });
+}
+
+void RemoteLayerWithRemoteRenderingBackingStoreCollection::markAllBackingStoreVolatileFromTimer()
+{
+    Vector<WebCore::RenderingResourceIdentifier> identifiers;
+    bool completed = collectAllBufferIdentifiersToMarkVolatile(VolatilityMarkingBehavior::ConsiderTimeSinceLastDisplay, { }, identifiers);
+
+    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerWithRemoteRenderingBackingStoreCollection::markAllBackingStoreVolatileFromTimer pid " << getpid() << " - live " << m_liveBackingStore.size() << ", unparented " << m_unparentedBackingStore.size() << ", " << identifiers.size() << " buffers to set volatile: " << identifiers);
+
+    if (identifiers.isEmpty()) {
+        if (completed)
+            m_volatilityTimer.stop();
+        return;
+    }
+
+    sendMarkBuffersVolatile(WTFMove(identifiers), [completed, weakThis = WeakPtr { *this }](bool succeeded) {
+        LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "sendMarkBuffersVolatile complete - completed " << completed << ", succeeded " << succeeded);
+        if (!weakThis)
+            return;
+
+        if (completed && succeeded)
+            weakThis->m_volatilityTimer.stop();
+    });
+}
+
+void RemoteLayerWithRemoteRenderingBackingStoreCollection::sendMarkBuffersVolatile(Vector<WebCore::RenderingResourceIdentifier>&& identifiers, CompletionHandler<void(bool)>&& completionHandler)
+{
+    auto& remoteRenderingBackend = m_layerTreeContext.ensureRemoteRenderingBackendProxy();
+    
+    Vector<WebCore::RenderingResourceIdentifier> inUseBufferIdentifiers;
+    remoteRenderingBackend.markSurfacesVolatile(WTFMove(identifiers), [&inUseBufferIdentifiers](Vector<WebCore::RenderingResourceIdentifier>&& inUseBuffers) {
+        inUseBufferIdentifiers = WTFMove(inUseBuffers);
+    });
+
+    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerWithRemoteRenderingBackingStoreCollection::sendMarkBuffersVolatile: " << inUseBufferIdentifiers.size() << " buffers still in-use");
+    // FIXME: inUseBufferIdentifiers will be used to map back to an ImageBuffer and maintain its "isVolatile" flag.
+    completionHandler(inUseBufferIdentifiers.isEmpty());
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp (290084 => 290085)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2022-02-17 23:48:45 UTC (rev 290085)
@@ -38,6 +38,7 @@
 #include "WebPage.h"
 #include "WebProcess.h"
 #include <_javascript_Core/TypedArrayInlines.h>
+#include <wtf/text/TextStream.h>
 
 namespace WebKit {
 
@@ -333,6 +334,15 @@
     return bufferWasEmpty ? VolatilityState::Empty : VolatilityState::Valid;
 }
 
+void RemoteRenderingBackendProxy::markSurfacesVolatile(Vector<WebCore::RenderingResourceIdentifier>&& identifiers, CompletionHandler<void(Vector<WebCore::RenderingResourceIdentifier>&&)>&& completionHandler)
+{
+    Vector<WebCore::RenderingResourceIdentifier> inUseBufferIdentifiers;
+    // FIXME: This should become async when webkit.org/b/235965 is fixed.
+    sendSyncToStream(Messages::RemoteRenderingBackend::MarkSurfacesVolatile(identifiers), Messages::RemoteRenderingBackend::MarkSurfacesVolatile::Reply(inUseBufferIdentifiers));
+
+    completionHandler(WTFMove(inUseBufferIdentifiers));
+}
+
 void RemoteRenderingBackendProxy::finalizeRenderingUpdate()
 {
     sendToStream(Messages::RemoteRenderingBackend::FinalizeRenderingUpdate(m_renderingUpdateID));

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h (290084 => 290085)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2022-02-17 23:39:21 UTC (rev 290084)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2022-02-17 23:48:45 UTC (rev 290085)
@@ -93,6 +93,7 @@
     void cacheFont(Ref<WebCore::Font>&&);
     void deleteAllFonts();
     void releaseRemoteResource(WebCore::RenderingResourceIdentifier);
+    void markSurfacesVolatile(Vector<WebCore::RenderingResourceIdentifier>&&, CompletionHandler<void(Vector<WebCore::RenderingResourceIdentifier>&& inUseBufferIdentifiers)>&&);
 
     WebCore::VolatilityState markSurfaceNonVolatile(WebCore::RenderingResourceIdentifier);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to