Title: [201519] trunk/Source/WebKit2
Revision
201519
Author
cdu...@apple.com
Date
2016-05-31 12:35:06 -0700 (Tue, 31 May 2016)

Log Message

[iOS] Better deal with WebProcess suspension due to screen locking
https://bugs.webkit.org/show_bug.cgi?id=158229
<rdar://problem/17665473>
<rdar://problem/26554699>

Reviewed by Tim Horton.

When locking the screen while MobileSafari is front-most, we would try keep
trying to mark IOSurfaces as volatile until the 30 seconds timeout was
reached. This patch deals more cleanly with this situation by only trying
to mark IOSurfaces as volatile once if the suspension is due to screen
locking. In such case, it is apparently expected that some IOSurfaces cannot
be marked as volatile so it is enough to try once and let ourselves get
suspended.

This patch also reduces the timeout from 30 seconds to ~3 seconds in the
other suspension cases (e.g. homing out of MobileSafari). If we fail to mark
them as purgeable for 3 seconds for a reason or another, it is no use in
retrying, it is simply not going to happen and there is no reason to delay
process suspension any further.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::callVolatilityCompletionHandlers):
(WebKit::WebPage::layerVolatilityTimerFired):
(WebKit::WebPage::markLayersVolatileImmediatelyIfPossible):
(WebKit::WebPage::markLayersVolatile):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::markLayersVolatile):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applicationDidEnterBackground):
(WebKit::WebPage::applicationWillEnterForeground):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (201518 => 201519)


--- trunk/Source/WebKit2/ChangeLog	2016-05-31 19:33:22 UTC (rev 201518)
+++ trunk/Source/WebKit2/ChangeLog	2016-05-31 19:35:06 UTC (rev 201519)
@@ -1,3 +1,37 @@
+2016-05-31  Chris Dumez  <cdu...@apple.com>
+
+        [iOS] Better deal with WebProcess suspension due to screen locking
+        https://bugs.webkit.org/show_bug.cgi?id=158229
+        <rdar://problem/17665473>
+        <rdar://problem/26554699>
+
+        Reviewed by Tim Horton.
+
+        When locking the screen while MobileSafari is front-most, we would try keep
+        trying to mark IOSurfaces as volatile until the 30 seconds timeout was
+        reached. This patch deals more cleanly with this situation by only trying
+        to mark IOSurfaces as volatile once if the suspension is due to screen
+        locking. In such case, it is apparently expected that some IOSurfaces cannot
+        be marked as volatile so it is enough to try once and let ourselves get
+        suspended.
+
+        This patch also reduces the timeout from 30 seconds to ~3 seconds in the
+        other suspension cases (e.g. homing out of MobileSafari). If we fail to mark
+        them as purgeable for 3 seconds for a reason or another, it is no use in
+        retrying, it is simply not going to happen and there is no reason to delay
+        process suspension any further.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::callVolatilityCompletionHandlers):
+        (WebKit::WebPage::layerVolatilityTimerFired):
+        (WebKit::WebPage::markLayersVolatileImmediatelyIfPossible):
+        (WebKit::WebPage::markLayersVolatile):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::markLayersVolatile):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::applicationDidEnterBackground):
+        (WebKit::WebPage::applicationWillEnterForeground):
+
 2016-05-31  Brady Eidson  <beid...@apple.com>
 
         Make createCrossThreadTask() functions return on the stack instead of the heap.

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (201518 => 201519)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2016-05-31 19:33:22 UTC (rev 201518)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2016-05-31 19:35:06 UTC (rev 201519)
@@ -248,7 +248,7 @@
 
 static const double pageScrollHysteresisSeconds = 0.3;
 static const std::chrono::milliseconds initialLayerVolatilityTimerInterval { 20 };
-static const std::chrono::seconds maximumLayerVolatilityTimerInterval { 10 };
+static const std::chrono::seconds maximumLayerVolatilityTimerInterval { 2 };
 
 #define WEBPAGE_LOG_ALWAYS(...) LOG_ALWAYS(isAlwaysOnLoggingAllowed(), __VA_ARGS__)
 #define WEBPAGE_LOG_ALWAYS_ERROR(...) LOG_ALWAYS_ERROR(isAlwaysOnLoggingAllowed(), __VA_ARGS__)
@@ -2037,32 +2037,34 @@
     drawingArea->setLayerTreeStateIsFrozen(frozen);
 }
 
+void WebPage::callVolatilityCompletionHandlers()
+{
+    auto completionHandlers = WTFMove(m_markLayersAsVolatileCompletionHandlers);
+    for (auto& completionHandler : completionHandlers)
+        completionHandler();
+}
+
 void WebPage::layerVolatilityTimerFired()
 {
-    if (markLayersVolatileImmediatelyIfPossible()) {
+    auto newInterval = 2 * m_layerVolatilityTimer.repeatIntervalMS();
+    bool didSucceed = markLayersVolatileImmediatelyIfPossible();
+    if (didSucceed || newInterval > maximumLayerVolatilityTimerInterval) {
         m_layerVolatilityTimer.stop();
+        WEBPAGE_LOG_ALWAYS("%p - WebPage - Attempted to mark surfaces as volatile, success? %d", this, didSucceed);
+        callVolatilityCompletionHandlers();
         return;
     }
 
-    auto newInterval = std::min(2 * m_layerVolatilityTimer.repeatIntervalMS(), std::chrono::duration_cast<std::chrono::milliseconds>(maximumLayerVolatilityTimerInterval));
     WEBPAGE_LOG_ALWAYS_ERROR("%p - WebPage - Failed to mark all layers as volatile, will retry in %lld ms", this, static_cast<long long>(newInterval.count()));
     m_layerVolatilityTimer.startRepeating(newInterval);
 }
 
 bool WebPage::markLayersVolatileImmediatelyIfPossible()
 {
-    bool success = !drawingArea() || drawingArea()->markLayersVolatileImmediatelyIfPossible();
-    if (success) {
-        WEBPAGE_LOG_ALWAYS("%p - WebPage - Successfully marked layers as volatile", this);
-        auto completionHandlers = WTFMove(m_markLayersAsVolatileCompletionHandlers);
-        for (auto& completionHandler : completionHandlers)
-            completionHandler();
-    }
-
-    return success;
+    return !drawingArea() || drawingArea()->markLayersVolatileImmediatelyIfPossible();
 }
 
-void WebPage::markLayersVolatile(std::function<void()> completionHandler)
+void WebPage::markLayersVolatile(std::function<void ()> completionHandler)
 {
     WEBPAGE_LOG_ALWAYS("%p - WebPage::markLayersVolatile()", this);
 
@@ -2072,8 +2074,17 @@
     if (completionHandler)
         m_markLayersAsVolatileCompletionHandlers.append(WTFMove(completionHandler));
 
-    if (markLayersVolatileImmediatelyIfPossible())
+    bool didSucceed = markLayersVolatileImmediatelyIfPossible();
+    if (didSucceed || m_isSuspendedUnderLock) {
+        if (didSucceed)
+            WEBPAGE_LOG_ALWAYS("%p - WebPage - Successfully marked layers as volatile", this);
+        else {
+            // 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.
+            WEBPAGE_LOG_ALWAYS("%p - WebPage - Did what we could to mark IOSurfaces as purgeable after locking the screen", this);
+        }
+        callVolatilityCompletionHandlers();
         return;
+    }
 
     WEBPAGE_LOG_ALWAYS("%p - Failed to mark all layers as volatile, will retry in %lld ms", this, initialLayerVolatilityTimerInterval.count());
     m_layerVolatilityTimer.startRepeating(initialLayerVolatilityTimerInterval);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (201518 => 201519)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2016-05-31 19:33:22 UTC (rev 201518)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2016-05-31 19:35:06 UTC (rev 201519)
@@ -582,7 +582,7 @@
 #endif
 
     void setLayerTreeStateIsFrozen(bool);
-    void markLayersVolatile(std::function<void()> completionHandler = {});
+    void markLayersVolatile(std::function<void ()> completionHandler = { });
     void cancelMarkLayersVolatile();
 
     NotificationPermissionRequestManager* notificationPermissionRequestManager();
@@ -992,6 +992,7 @@
 
     bool markLayersVolatileImmediatelyIfPossible();
     void layerVolatilityTimerFired();
+    void callVolatilityCompletionHandlers();
 
     String sourceForFrame(WebFrame*);
 
@@ -1426,7 +1427,8 @@
 #endif
 
     WebCore::Timer m_layerVolatilityTimer;
-    Vector<std::function<void()>> m_markLayersAsVolatileCompletionHandlers;
+    Vector<std::function<void ()>> m_markLayersAsVolatileCompletionHandlers;
+    bool m_isSuspendedUnderLock { false };
 
     HashSet<String, ASCIICaseInsensitiveHash> m_mimeTypesWithCustomContentProviders;
     WebCore::Color m_backgroundColor;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (201518 => 201519)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-05-31 19:33:22 UTC (rev 201518)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-05-31 19:35:06 UTC (rev 201519)
@@ -2973,12 +2973,14 @@
 {
     [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationDidEnterBackgroundNotification object:nil userInfo:@{@"isSuspendedUnderLock": [NSNumber numberWithBool:isSuspendedUnderLock]}];
 
+    m_isSuspendedUnderLock = isSuspendedUnderLock;
     setLayerTreeStateIsFrozen(true);
     markLayersVolatile();
 }
 
 void WebPage::applicationWillEnterForeground(bool isSuspendedUnderLock)
 {
+    m_isSuspendedUnderLock = false;
     cancelMarkLayersVolatile();
     setLayerTreeStateIsFrozen(false);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to