Title: [209736] trunk/Source/WebKit2
Revision
209736
Author
[email protected]
Date
2016-12-12 16:07:11 -0800 (Mon, 12 Dec 2016)

Log Message

Provide SPI to avoid blocking on painting when coming into view
https://bugs.webkit.org/show_bug.cgi?id=165780
<rdar://problem/29009559>

Reviewed by Simon Fraser.

By default, when parenting a WKWebView which was previously in-window,
we block on painting to ensure that we don't flash stale content.
We added SPI to disable this behavior to WKWebViewConfiguration, but
some clients might want the behavior most of the time, but sometimes
instead want to not block the UI process main thread, but instead do
their own work (e.g. removing a snapshot) when painting eventually occurs.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _doAfterNextPresentationUpdateWithoutWaitingForPainting:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
Tell WebPageProxy not to block on painting next time we are parented,
and use doAfterNextPresentationUpdate to call the block when the painting
does eventually happen. This SPI must be called before - but in the same
runloop cycle - the WKWebView is brought back in-window to work correctly.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::dispatchActivityStateChange):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::skipWaitingForPaintAfterNextViewDidMoveToWindow):
If we would block because we're coming in-window, but the bit to skip
blocking the next time we get brought in-window is set, reset the bit, 
and avoid blocking.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (209735 => 209736)


--- trunk/Source/WebKit2/ChangeLog	2016-12-12 23:56:41 UTC (rev 209735)
+++ trunk/Source/WebKit2/ChangeLog	2016-12-13 00:07:11 UTC (rev 209736)
@@ -1,3 +1,34 @@
+2016-12-12  Tim Horton  <[email protected]>
+
+        Provide SPI to avoid blocking on painting when coming into view
+        https://bugs.webkit.org/show_bug.cgi?id=165780
+        <rdar://problem/29009559>
+
+        Reviewed by Simon Fraser.
+
+        By default, when parenting a WKWebView which was previously in-window,
+        we block on painting to ensure that we don't flash stale content.
+        We added SPI to disable this behavior to WKWebViewConfiguration, but
+        some clients might want the behavior most of the time, but sometimes
+        instead want to not block the UI process main thread, but instead do
+        their own work (e.g. removing a snapshot) when painting eventually occurs.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _doAfterNextPresentationUpdateWithoutWaitingForPainting:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        Tell WebPageProxy not to block on painting next time we are parented,
+        and use doAfterNextPresentationUpdate to call the block when the painting
+        does eventually happen. This SPI must be called before - but in the same
+        runloop cycle - the WKWebView is brought back in-window to work correctly.
+        
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::dispatchActivityStateChange):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::skipWaitingForPaintAfterNextViewDidMoveToWindow):
+        If we would block because we're coming in-window, but the bit to skip
+        blocking the next time we get brought in-window is set, reset the bit, 
+        and avoid blocking.
+
 2016-12-12  Chris Dumez  <[email protected]>
 
         Document.visibilityState should use an IDL string enumeration

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (209735 => 209736)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-12-12 23:56:41 UTC (rev 209735)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-12-13 00:07:11 UTC (rev 209736)
@@ -4835,6 +4835,12 @@
     });
 }
 
+- (void)_doAfterNextPresentationUpdateWithoutWaitingForPainting:(void (^)(void))updateBlock
+{
+    _page->setShouldSkipWaitingForPaintAfterNextViewDidMoveToWindow(true);
+    [self _doAfterNextPresentationUpdate:updateBlock];
+}
+
 - (void)_disableBackForwardSnapshotVolatilityForTesting
 {
     WebKit::ViewSnapshotStore::singleton().setDisableSnapshotVolatilityForTesting(true);

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (209735 => 209736)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-12-12 23:56:41 UTC (rev 209735)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-12-13 00:07:11 UTC (rev 209736)
@@ -315,6 +315,7 @@
 - (CGFloat)_pageScale WK_API_AVAILABLE(ios(WK_IOS_TBA));
 
 - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_API_AVAILABLE(macosx(10.12), ios(10.0));
+- (void)_doAfterNextPresentationUpdateWithoutWaitingForPainting:(void (^)(void))updateBlock WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 - (void)_disableBackForwardSnapshotVolatilityForTesting WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (209735 => 209736)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-12-12 23:56:41 UTC (rev 209735)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-12-13 00:07:11 UTC (rev 209736)
@@ -1550,8 +1550,11 @@
 
     bool isNowInWindow = (changed & ActivityState::IsInWindow) && isInWindow();
     // We always want to wait for the Web process to reply if we've been in-window before and are coming back in-window.
-    if (m_viewWasEverInWindow && isNowInWindow && m_drawingArea->hasVisibleContent() && m_waitsForPaintAfterViewDidMoveToWindow)
-        m_activityStateChangeWantsSynchronousReply = true;
+    if (m_viewWasEverInWindow && isNowInWindow) {
+        if (m_drawingArea->hasVisibleContent() && m_waitsForPaintAfterViewDidMoveToWindow && !m_shouldSkipWaitingForPaintAfterNextViewDidMoveToWindow)
+            m_activityStateChangeWantsSynchronousReply = true;
+        m_shouldSkipWaitingForPaintAfterNextViewDidMoveToWindow = false;
+    }
 
     // Don't wait synchronously if the view state is not visible. (This matters in particular on iOS, where a hidden page may be suspended.)
     if (!(m_activityState & ActivityState::IsVisible))

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (209735 => 209736)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-12-12 23:56:41 UTC (rev 209735)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-12-13 00:07:11 UTC (rev 209736)
@@ -1176,6 +1176,8 @@
 
     void clearUserMediaState();
 
+    void setShouldSkipWaitingForPaintAfterNextViewDidMoveToWindow(bool shouldSkip) { m_shouldSkipWaitingForPaintAfterNextViewDidMoveToWindow = shouldSkip; }
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     void platformInitialize();
@@ -1711,6 +1713,7 @@
     bool m_maintainsInactiveSelection;
 
     bool m_waitsForPaintAfterViewDidMoveToWindow;
+    bool m_shouldSkipWaitingForPaintAfterNextViewDidMoveToWindow { false };
 
     String m_toolTip;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to