Title: [233479] trunk/Source
Revision
233479
Author
[email protected]
Date
2018-07-03 14:04:10 -0700 (Tue, 03 Jul 2018)

Log Message

Clean up the layer volatility code and logging
https://bugs.webkit.org/show_bug.cgi?id=187286

Reviewed by Tim Horton.
Source/WebCore:

Export a function.

* platform/graphics/cocoa/IOSurface.h:

Source/WebKit:

Fix the layer volatility logging so it doesn't say "succeeded" when it actually failed
and gave up.

Use a couple of lambda functions in RemoteLayerBackingStore::setBufferVolatility() to
make the code easier to read.

* Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
* Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::setBufferVolatility):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::callVolatilityCompletionHandlers):
(WebKit::WebPage::layerVolatilityTimerFired):
(WebKit::WebPage::markLayersVolatile):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::markLayersVolatile):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::actualPrepareToSuspend):
(WebKit::WebProcess::markAllLayersVolatile):
* WebProcess/WebProcess.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (233478 => 233479)


--- trunk/Source/WebCore/ChangeLog	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebCore/ChangeLog	2018-07-03 21:04:10 UTC (rev 233479)
@@ -1,3 +1,14 @@
+2018-07-02  Simon Fraser  <[email protected]>
+
+        Clean up the layer volatility code and logging
+        https://bugs.webkit.org/show_bug.cgi?id=187286
+
+        Reviewed by Tim Horton.
+
+        Export a function.
+
+        * platform/graphics/cocoa/IOSurface.h:
+
 2018-07-03  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r233112.

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (233478 => 233479)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2018-07-03 21:04:10 UTC (rev 233479)
@@ -130,7 +130,7 @@
 
     CGColorSpaceRef colorSpace() const { return m_colorSpace.get(); }
     WEBCORE_EXPORT Format format() const;
-    IOSurfaceID surfaceID() const;
+    WEBCORE_EXPORT IOSurfaceID surfaceID() const;
     size_t bytesPerRow() const;
 
     WEBCORE_EXPORT bool isInUse() const;

Modified: trunk/Source/WebKit/ChangeLog (233478 => 233479)


--- trunk/Source/WebKit/ChangeLog	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebKit/ChangeLog	2018-07-03 21:04:10 UTC (rev 233479)
@@ -1,3 +1,30 @@
+2018-07-02  Simon Fraser  <[email protected]>
+
+        Clean up the layer volatility code and logging
+        https://bugs.webkit.org/show_bug.cgi?id=187286
+
+        Reviewed by Tim Horton.
+        
+        Fix the layer volatility logging so it doesn't say "succeeded" when it actually failed
+        and gave up.
+        
+        Use a couple of lambda functions in RemoteLayerBackingStore::setBufferVolatility() to
+        make the code easier to read.
+
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
+        (WebKit::RemoteLayerBackingStore::setBufferVolatility):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::callVolatilityCompletionHandlers):
+        (WebKit::WebPage::layerVolatilityTimerFired):
+        (WebKit::WebPage::markLayersVolatile):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::markLayersVolatile):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::actualPrepareToSuspend):
+        (WebKit::WebProcess::markAllLayersVolatile):
+        * WebProcess/WebProcess.h:
+
 2018-07-03  John Wilander  <[email protected]>
 
         Resource Load Statistics: Make WebsiteDataStore::getAllStorageAccessEntries() call the right network process instead of iterating over the process pools

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h (233478 => 233479)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h	2018-07-03 21:04:10 UTC (rev 233479)
@@ -90,6 +90,7 @@
         SecondaryBack
     };
 
+    // Returns true if it was able to fulfill the request. This can fail when trying to mark an in-use surface as volatile.
     bool setBufferVolatility(BufferType, bool isVolatile);
 
     MonotonicTime lastDisplayTime() const { return m_lastDisplayTime; }

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm (233478 => 233479)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm	2018-07-03 21:04:10 UTC (rev 233479)
@@ -430,43 +430,53 @@
 #if HAVE(IOSURFACE)
 bool RemoteLayerBackingStore::setBufferVolatility(BufferType type, bool isVolatile)
 {
+    // Return value is true if we succeeded in making volatile.
+    auto makeVolatile = [] (Buffer& buffer) -> bool {
+        if (!buffer.surface || buffer.isVolatile)
+            return true;
+
+        buffer.surface->releaseGraphicsContext();
+
+        if (!buffer.surface->isInUse()) {
+            buffer.surface->setIsVolatile(true);
+            buffer.isVolatile = true;
+            return true;
+        }
+    
+        return false;
+    };
+
+    // Return value is true if we need to repaint.
+    auto makeNonVolatile = [] (Buffer& buffer) -> bool {
+        if (!buffer.surface || !buffer.isVolatile)
+            return false;
+
+        auto previousState = buffer.surface->setIsVolatile(false);
+        buffer.isVolatile = false;
+
+        return previousState == WebCore::IOSurface::SurfaceState::Empty;
+    };
+
     switch (type) {
     case BufferType::Front:
-        if (m_frontBuffer.surface && m_frontBuffer.isVolatile != isVolatile) {
-            if (isVolatile)
-                m_frontBuffer.surface->releaseGraphicsContext();
-            if (!isVolatile || !m_frontBuffer.surface->isInUse()) {
-                auto previousState = m_frontBuffer.surface->setIsVolatile(isVolatile);
-                m_frontBuffer.isVolatile = isVolatile;
-
-                // Becoming non-volatile and the front buffer was purged, so we need to repaint.
-                if (!isVolatile && (previousState == WebCore::IOSurface::SurfaceState::Empty))
-                    setNeedsDisplay();
-            } else
-                return false;
-        }
+        if (isVolatile)
+            return makeVolatile(m_frontBuffer);
+        
+        // Becoming non-volatile and the front buffer was purged, so we need to repaint.
+        if (makeNonVolatile(m_frontBuffer))
+            setNeedsDisplay();
         break;
     case BufferType::Back:
-        if (m_backBuffer.surface && m_backBuffer.isVolatile != isVolatile) {
-            if (isVolatile)
-                m_backBuffer.surface->releaseGraphicsContext();
-            if (!isVolatile || !m_backBuffer.surface->isInUse()) {
-                m_backBuffer.surface->setIsVolatile(isVolatile);
-                m_backBuffer.isVolatile = isVolatile;
-            } else
-                return false;
-        }
+        if (isVolatile)
+            return makeVolatile(m_backBuffer);
+    
+        makeNonVolatile(m_backBuffer);
         break;
     case BufferType::SecondaryBack:
-        if (m_secondaryBackBuffer.surface && m_secondaryBackBuffer.isVolatile != isVolatile) {
-            if (isVolatile)
-                m_secondaryBackBuffer.surface->releaseGraphicsContext();
-            if (!isVolatile || !m_secondaryBackBuffer.surface->isInUse()) {
-                m_secondaryBackBuffer.surface->setIsVolatile(isVolatile);
-                m_secondaryBackBuffer.isVolatile = isVolatile;
-            } else
-                return false;
-        }
+        if (isVolatile)
+            return makeVolatile(m_secondaryBackBuffer);
+    
+        makeNonVolatile(m_secondaryBackBuffer);
         break;
     }
     return true;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (233478 => 233479)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-07-03 21:04:10 UTC (rev 233479)
@@ -2219,11 +2219,11 @@
     drawingArea->setLayerTreeStateIsFrozen(frozen);
 }
 
-void WebPage::callVolatilityCompletionHandlers()
+void WebPage::callVolatilityCompletionHandlers(bool succeeded)
 {
     auto completionHandlers = WTFMove(m_markLayersAsVolatileCompletionHandlers);
     for (auto& completionHandler : completionHandlers)
-        completionHandler();
+        completionHandler(succeeded);
 }
 
 void WebPage::layerVolatilityTimerFired()
@@ -2232,12 +2232,15 @@
     bool didSucceed = markLayersVolatileImmediatelyIfPossible();
     if (didSucceed || newInterval > maximumLayerVolatilityTimerInterval) {
         m_layerVolatilityTimer.stop();
-        RELEASE_LOG_IF_ALLOWED("%p - WebPage - Attempted to mark layers as volatile, success? %d", this, didSucceed);
-        callVolatilityCompletionHandlers();
+        if (didSucceed)
+            RELEASE_LOG_IF_ALLOWED("%p - WebPage - Succeeded in marking layers as volatile", this);
+        else
+            RELEASE_LOG_IF_ALLOWED("%p - WebPage - Failed to mark layers as volatile within %gms", this, maximumLayerVolatilityTimerInterval.milliseconds());
+        callVolatilityCompletionHandlers(didSucceed);
         return;
     }
 
-    RELEASE_LOG_ERROR_IF_ALLOWED("%p - WebPage - Failed to mark all layers as volatile, will retry in %g ms", this, newInterval.value() * 1000);
+    RELEASE_LOG_ERROR_IF_ALLOWED("%p - WebPage - Failed to mark all layers as volatile, will retry in %g ms", this, newInterval.milliseconds());
     m_layerVolatilityTimer.startRepeating(newInterval);
 }
 
@@ -2246,7 +2249,7 @@
     return !drawingArea() || drawingArea()->markLayersVolatileImmediatelyIfPossible();
 }
 
-void WebPage::markLayersVolatile(WTF::Function<void ()>&& completionHandler)
+void WebPage::markLayersVolatile(WTF::Function<void (bool)>&& completionHandler)
 {
     RELEASE_LOG_IF_ALLOWED("%p - WebPage::markLayersVolatile()", this);
 
@@ -2264,11 +2267,11 @@
             // If we get suspended when locking the screen, it is expected that some IOSurfaces cannot be marked as purgeable so we do not keep retrying.
             RELEASE_LOG_IF_ALLOWED("%p - WebPage - Did what we could to mark IOSurfaces as purgeable after locking the screen", this);
         }
-        callVolatilityCompletionHandlers();
+        callVolatilityCompletionHandlers(didSucceed);
         return;
     }
 
-    RELEASE_LOG_IF_ALLOWED("%p - Failed to mark all layers as volatile, will retry in %g ms", this, initialLayerVolatilityTimerInterval.value() * 1000);
+    RELEASE_LOG_IF_ALLOWED("%p - Failed to mark all layers as volatile, will retry in %g ms", this, initialLayerVolatilityTimerInterval.milliseconds());
     m_layerVolatilityTimer.startRepeating(initialLayerVolatilityTimerInterval);
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (233478 => 233479)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-07-03 21:04:10 UTC (rev 233479)
@@ -669,7 +669,7 @@
     bool hasRichlyEditableSelection() const;
 
     void setLayerTreeStateIsFrozen(bool);
-    void markLayersVolatile(WTF::Function<void ()>&& completionHandler = { });
+    void markLayersVolatile(WTF::Function<void (bool)>&& completionHandler = { });
     void cancelMarkLayersVolatile();
 
     NotificationPermissionRequestManager* notificationPermissionRequestManager();
@@ -1146,7 +1146,7 @@
 
     bool markLayersVolatileImmediatelyIfPossible();
     void layerVolatilityTimerFired();
-    void callVolatilityCompletionHandlers();
+    void callVolatilityCompletionHandlers(bool succeeded);
 
     String sourceForFrame(WebFrame*);
 
@@ -1669,7 +1669,7 @@
 #endif
 
     WebCore::Timer m_layerVolatilityTimer;
-    Vector<WTF::Function<void ()>> m_markLayersAsVolatileCompletionHandlers;
+    Vector<WTF::Function<void (bool)>> m_markLayersAsVolatileCompletionHandlers;
     bool m_isSuspendedUnderLock { false };
 
     HashSet<String, ASCIICaseInsensitiveHash> m_mimeTypesWithCustomContentProviders;

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (233478 => 233479)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-07-03 21:04:10 UTC (rev 233479)
@@ -1375,8 +1375,11 @@
     accessibilityProcessSuspendedNotification(true);
 #endif
 
-    markAllLayersVolatile([this, shouldAcknowledgeWhenReadyToSuspend] {
-        RELEASE_LOG(ProcessSuspension, "%p - WebProcess::markAllLayersVolatile() Successfuly marked all layers as volatile", this);
+    markAllLayersVolatile([this, shouldAcknowledgeWhenReadyToSuspend](bool success) {
+        if (success)
+            RELEASE_LOG(ProcessSuspension, "%p - WebProcess::markAllLayersVolatile() Successfuly marked all layers as volatile", this);
+        else
+            RELEASE_LOG(ProcessSuspension, "%p - WebProcess::markAllLayersVolatile() Failed to mark all layers as volatile", this);
 
         if (shouldAcknowledgeWhenReadyToSuspend == ShouldAcknowledgeWhenReadyToSuspend::Yes) {
             RELEASE_LOG(ProcessSuspension, "%p - WebProcess::actualPrepareToSuspend() Sending ProcessReadyToSuspend IPC message", this);
@@ -1427,20 +1430,25 @@
     parentProcessConnection()->send(Messages::WebProcessProxy::DidCancelProcessSuspension(), 0);
 }
 
-void WebProcess::markAllLayersVolatile(WTF::Function<void()>&& completionHandler)
+void WebProcess::markAllLayersVolatile(WTF::Function<void(bool)>&& completionHandler)
 {
     RELEASE_LOG(ProcessSuspension, "%p - WebProcess::markAllLayersVolatile()", this);
     ASSERT(!m_pageMarkingLayersAsVolatileCounter);
+    m_countOfPagesFailingToMarkVolatile = 0;
+
     m_pageMarkingLayersAsVolatileCounter = std::make_unique<PageMarkingLayersAsVolatileCounter>([this, completionHandler = WTFMove(completionHandler)] (RefCounterEvent) {
         if (m_pageMarkingLayersAsVolatileCounter->value())
             return;
 
-        completionHandler();
+        completionHandler(m_countOfPagesFailingToMarkVolatile == 0);
         m_pageMarkingLayersAsVolatileCounter = nullptr;
     });
     auto token = m_pageMarkingLayersAsVolatileCounter->count();
     for (auto& page : m_pageMap.values())
-        page->markLayersVolatile([token] { });
+        page->markLayersVolatile([token, this] (bool succeeded) {
+            if (!succeeded)
+                ++m_countOfPagesFailingToMarkVolatile;
+        });
 }
 
 void WebProcess::cancelMarkAllLayersVolatile()

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (233478 => 233479)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2018-07-03 21:02:10 UTC (rev 233478)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2018-07-03 21:04:10 UTC (rev 233479)
@@ -252,7 +252,7 @@
     void registerWithStateDumper();
 #endif
 
-    void markAllLayersVolatile(WTF::Function<void()>&& completionHandler);
+    void markAllLayersVolatile(WTF::Function<void(bool)>&& completionHandler);
     void cancelMarkAllLayersVolatile();
     void setAllLayerTreeStatesFrozen(bool);
     void processSuspensionCleanupTimerFired();
@@ -448,6 +448,7 @@
     enum PageMarkingLayersAsVolatileCounterType { };
     using PageMarkingLayersAsVolatileCounter = RefCounter<PageMarkingLayersAsVolatileCounterType>;
     std::unique_ptr<PageMarkingLayersAsVolatileCounter> m_pageMarkingLayersAsVolatileCounter;
+    unsigned m_countOfPagesFailingToMarkVolatile { 0 };
 
     bool m_suppressMemoryPressureHandler { false };
 #if PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to