Title: [146956] trunk
Revision
146956
Author
timothy_hor...@apple.com
Date
2013-03-26 18:20:42 -0700 (Tue, 26 Mar 2013)

Log Message

[ca] Tell CA to clean up unused resources if a given WebProcess won't be drawing
https://bugs.webkit.org/show_bug.cgi?id=107539
<rdar://problem/13032692>

Reviewed by Simon Fraser.

* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface): Update WebCoreSystemInterface.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage): Initially move the Page out of the window if necessary;
Page defaults to in-window, which is wrong in many cases - we depend on
Page::isInWindow being accurate to decide whether WebPage::setIsInWindow is actually
a state change or not.
(WebKit::WebPage::setIsInWindow):
* WebProcess/WebProcess.cpp: Inform WebProcess when we go on/off screen.
(WebKit::WebProcess::WebProcess):
(WebKit::WebProcess::pageDidMoveOnscreen): Keep track of the number of on-screen pages in this process.
(WebKit::WebProcess::pageWillMoveOffscreen): If the number of on-screen pages drops to zero,  clean up unused rendering resources.
* WebProcess/WebProcess.h:

Update WebSystemInterface.

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):

* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (146955 => 146956)


--- trunk/Source/WebCore/ChangeLog	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebCore/ChangeLog	2013-03-27 01:20:42 UTC (rev 146956)
@@ -1,3 +1,16 @@
+2013-03-26  Tim Horton  <timothy_hor...@apple.com>
+
+        [ca] Tell CA to clean up unused resources if a given WebProcess won't be drawing
+        https://bugs.webkit.org/show_bug.cgi?id=107539
+        <rdar://problem/13032692>
+
+        Reviewed by Simon Fraser.
+
+        Update WebCoreSystemInterface.
+
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+
 2013-03-26  Antti Koivisto  <an...@apple.com>
 
         Test if non-immediate descendants obscure background

Modified: trunk/Source/WebCore/WebCore.exp.in (146955 => 146956)


--- trunk/Source/WebCore/WebCore.exp.in	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-03-27 01:20:42 UTC (rev 146956)
@@ -1615,6 +1615,7 @@
 __ZN7WebCore15ResourceRequest13partitionNameERKN3WTF6StringE
 _wkCachePartitionKey
 #endif
+_wkDestroyRenderingResources
 _wkCGContextGetShouldSmoothFonts
 _wkCGContextResetClip
 #if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080

Modified: trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h (146955 => 146956)


--- trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h	2013-03-27 01:20:42 UTC (rev 146956)
@@ -307,6 +307,8 @@
 extern CFStringRef (*wkCopyCFURLResponseSuggestedFilename)(CFURLResponseRef);
 extern void (*wkSetCFURLResponseMIMEType)(CFURLResponseRef, CFStringRef mimeType);
 
+extern void(*wkDestroyRenderingResources)(void);
+
 #if USE(CFNETWORK)
 extern CFHTTPCookieStorageRef (*wkGetDefaultHTTPCookieStorage)();
 extern WKCFURLCredentialRef (*wkCopyCredentialFromCFPersistentStorage)(CFURLProtectionSpaceRef protectionSpace);

Modified: trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm (146955 => 146956)


--- trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm	2013-03-27 01:20:42 UTC (rev 146956)
@@ -192,6 +192,8 @@
 void (*wkSetCFURLResponseMIMEType)(CFURLResponseRef, CFStringRef mimeType);
 void (*wkSetMetadataURL)(NSString *urlString, NSString *referrer, NSString *path);
 
+void(*wkDestroyRenderingResources)(void);
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 dispatch_source_t (*wkCreateVMPressureDispatchOnMainQueue)(void);
 #endif

Modified: trunk/Source/WebKit/mac/ChangeLog (146955 => 146956)


--- trunk/Source/WebKit/mac/ChangeLog	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebKit/mac/ChangeLog	2013-03-27 01:20:42 UTC (rev 146956)
@@ -1,3 +1,16 @@
+2013-03-26  Tim Horton  <timothy_hor...@apple.com>
+
+        [ca] Tell CA to clean up unused resources if a given WebProcess won't be drawing
+        https://bugs.webkit.org/show_bug.cgi?id=107539
+        <rdar://problem/13032692>
+
+        Reviewed by Simon Fraser.
+
+        Update WebSystemInterface.
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+
 2013-03-26  Sergio Villar Senin  <svil...@igalia.com>
 
         Implement overtype mode for editable content

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm (146955 => 146956)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm	2013-03-27 01:20:42 UTC (rev 146956)
@@ -186,6 +186,8 @@
 
     INIT(SetMetadataURL);
 
+    INIT(DestroyRenderingResources);
+
 #if PLATFORM(MAC)
     // FIXME: We should stop using this file in Chromium.
 

Modified: trunk/Source/WebKit2/ChangeLog (146955 => 146956)


--- trunk/Source/WebKit2/ChangeLog	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-27 01:20:42 UTC (rev 146956)
@@ -1,3 +1,25 @@
+2013-03-26  Tim Horton  <timothy_hor...@apple.com>
+
+        [ca] Tell CA to clean up unused resources if a given WebProcess won't be drawing
+        https://bugs.webkit.org/show_bug.cgi?id=107539
+        <rdar://problem/13032692>
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface): Update WebCoreSystemInterface.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage): Initially move the Page out of the window if necessary;
+        Page defaults to in-window, which is wrong in many cases - we depend on
+        Page::isInWindow being accurate to decide whether WebPage::setIsInWindow is actually
+        a state change or not.
+        (WebKit::WebPage::setIsInWindow):
+        * WebProcess/WebProcess.cpp: Inform WebProcess when we go on/off screen.
+        (WebKit::WebProcess::WebProcess):
+        (WebKit::WebProcess::pageDidMoveOnscreen): Keep track of the number of on-screen pages in this process.
+        (WebKit::WebProcess::pageWillMoveOffscreen): If the number of on-screen pages drops to zero,  clean up unused rendering resources.
+        * WebProcess/WebProcess.h:
+
 2013-03-26  Dean Jackson  <d...@apple.com>
 
         When a primary plugin is restarted, also start similar plugins

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm (146955 => 146956)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm	2013-03-27 01:20:42 UTC (rev 146956)
@@ -161,6 +161,8 @@
 
         INIT(CreateVMPressureDispatchOnMainQueue);
 
+        INIT(DestroyRenderingResources);
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
         INIT(ExecutableWasLinkedOnOrBeforeLion);
 #endif

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (146955 => 146956)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2013-03-27 01:20:42 UTC (rev 146956)
@@ -365,6 +365,11 @@
 
     setActive(parameters.isActive);
     setFocused(parameters.isFocused);
+
+    // Page defaults to in-window, but setIsInWindow depends on it being a valid indicator of actually having been put into a window.
+    if (!parameters.isInWindow)
+        m_page->setIsInWindow(false);
+
     setIsInWindow(parameters.isInWindow);
 
     m_userAgent = parameters.userAgent;
@@ -1957,10 +1962,15 @@
 
 void WebPage::setIsInWindow(bool isInWindow)
 {
+    bool pageWasInWindow = m_page->isInWindow();
+    
     if (!isInWindow) {
         m_setCanStartMediaTimer.stop();
         m_page->setCanStartMedia(false);
         m_page->willMoveOffscreen();
+        
+        if (pageWasInWindow)
+            WebProcess::shared().pageWillLeaveWindow(this);
     } else {
         // Defer the call to Page::setCanStartMedia() since it ends up sending a synchronous message to the UI process
         // in order to get plug-in connections, and the UI process will be waiting for the Web process to update the backing
@@ -1969,6 +1979,9 @@
             m_setCanStartMediaTimer.startOneShot(0);
 
         m_page->didMoveOnscreen();
+        
+        if (!pageWasInWindow)
+            WebProcess::shared().pageDidEnterWindow(this);
     }
 
     m_page->setIsInWindow(isInWindow);

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (146955 => 146956)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2013-03-27 01:20:42 UTC (rev 146956)
@@ -131,6 +131,9 @@
 // This should be less than plugInAutoStartExpirationTimeThreshold in PlugInAutoStartProvider.
 static const double plugInAutoStartExpirationTimeUpdateThreshold = 29 * 24 * 60 * 60;
 
+// This should be greater than tileRevalidationTimeout in TileController.
+static const double nonVisibleProcessCleanupDelay = 10;
+
 namespace WebKit {
 
 WebProcess& WebProcess::shared()
@@ -173,6 +176,8 @@
 #if USE(SOUP)
     , m_soupRequestManager(this)
 #endif
+    , m_inWindowPageCount(0)
+    , m_nonVisibleProcessCleanupTimer(this, &WebProcess::nonVisibleProcessCleanupTimerFired)
 {
 #if USE(PLATFORM_STRATEGIES)
     // Initialize our platform strategies.
@@ -1098,5 +1103,31 @@
 {
 }
 #endif
+    
+void WebProcess::pageDidEnterWindow(WebPage*)
+{
+    m_inWindowPageCount++;
+    m_nonVisibleProcessCleanupTimer.stop();
+}
 
+void WebProcess::pageWillLeaveWindow(WebPage*)
+{
+    ASSERT(m_inWindowPageCount > 0);
+    if (m_inWindowPageCount <= 0)
+        return;
+
+    m_inWindowPageCount--;
+
+    if (!m_inWindowPageCount)
+        m_nonVisibleProcessCleanupTimer.startOneShot(nonVisibleProcessCleanupDelay);
+}
+    
+void WebProcess::nonVisibleProcessCleanupTimerFired(Timer<WebProcess>*)
+{
+    ASSERT(!m_inWindowPageCount);
+#if PLATFORM(MAC)
+    wkDestroyRenderingResources();
+#endif
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (146955 => 146956)


--- trunk/Source/WebKit2/WebProcess/WebProcess.h	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h	2013-03-27 01:20:42 UTC (rev 146956)
@@ -36,6 +36,7 @@
 #include "TextCheckerState.h"
 #include "VisitedLinkTable.h"
 #include <WebCore/LinkHash.h>
+#include <WebCore/Timer.h>
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
@@ -178,6 +179,11 @@
 
     void ensurePrivateBrowsingSession();
     void destroyPrivateBrowsingSession();
+    
+    void pageDidEnterWindow(WebPage*);
+    void pageWillLeaveWindow(WebPage*);
+    
+    void nonVisibleProcessCleanupTimerFired(WebCore::Timer<WebProcess>*);
 
 private:
     WebProcess();
@@ -329,6 +335,9 @@
 #if USE(SOUP)
     WebSoupRequestManager m_soupRequestManager;
 #endif
+    
+    int m_inWindowPageCount;
+    WebCore::Timer<WebProcess> m_nonVisibleProcessCleanupTimer;
 };
 
 } // namespace WebKit

Modified: trunk/WebKitLibraries/WebKitSystemInterface.h (146955 => 146956)


--- trunk/WebKitLibraries/WebKitSystemInterface.h	2013-03-27 01:00:57 UTC (rev 146955)
+++ trunk/WebKitLibraries/WebKitSystemInterface.h	2013-03-27 01:20:42 UTC (rev 146956)
@@ -351,7 +351,7 @@
 CALayer *WKCAContextGetLayer(WKCAContextRef);
 void WKCAContextSetColorSpace(WKCAContextRef, CGColorSpaceRef);
 CGColorSpaceRef WKCAContextGetColorSpace(WKCAContextRef);
-void WKCABackingStoreCollectBlocking(void);
+void WKDestroyRenderingResources(void);
 
 void WKCALayerEnumerateRectsBeingDrawnWithBlock(CALayer *layer, CGContextRef context, void (^block)(CGRect rect));
 

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceLion.a


(Binary files differ)

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a


(Binary files differ)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to