[ca] Tell CA to clean up unused resources if a given WebProcess won't be drawing
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Mar 2013 01:20:42 +0000 (01:20 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Mar 2013 01:20:42 +0000 (01:20 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@146956 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceLion.a
WebKitLibraries/libWebKitSystemInterfaceMountainLion.a

index a66a7fa..761d7ae 100644 (file)
@@ -1,3 +1,16 @@
+2013-03-26  Tim Horton  <timothy_horton@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  <antti@apple.com>
 
         Test if non-immediate descendants obscure background
index a60e4b4..b25534b 100644 (file)
@@ -1615,6 +1615,7 @@ _suggestedFilenameWithMIMEType
 __ZN7WebCore15ResourceRequest13partitionNameERKN3WTF6StringE
 _wkCachePartitionKey
 #endif
+_wkDestroyRenderingResources
 _wkCGContextGetShouldSmoothFonts
 _wkCGContextResetClip
 #if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
index fb30ccb..1ceb86f 100644 (file)
@@ -307,6 +307,8 @@ extern CFHTTPMessageRef (*wkGetCFURLResponseHTTPResponse)(CFURLResponseRef);
 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);
index c6ebb49..2944c62 100644 (file)
@@ -192,6 +192,8 @@ CFStringRef (*wkCopyCFURLResponseSuggestedFilename)(CFURLResponseRef);
 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
index fdb6b5e..1675245 100644 (file)
@@ -1,3 +1,16 @@
+2013-03-26  Tim Horton  <timothy_horton@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  <svillar@igalia.com>
 
         Implement overtype mode for editable content
index 5b19ef7..c83aa5a 100644 (file)
@@ -186,6 +186,8 @@ void InitWebCoreSystemInterface(void)
 
     INIT(SetMetadataURL);
 
+    INIT(DestroyRenderingResources);
+
 #if PLATFORM(MAC)
     // FIXME: We should stop using this file in Chromium.
 
index ebf216a..baa902b 100644 (file)
@@ -1,3 +1,25 @@
+2013-03-26  Tim Horton  <timothy_horton@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  <dino@apple.com>
 
         When a primary plugin is restarted, also start similar plugins
index 6d41fe6..c844f4b 100644 (file)
@@ -161,6 +161,8 @@ void InitWebCoreSystemInterface(void)
 
         INIT(CreateVMPressureDispatchOnMainQueue);
 
+        INIT(DestroyRenderingResources);
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
         INIT(ExecutableWasLinkedOnOrBeforeLion);
 #endif
index 8acadfa..876f92d 100644 (file)
@@ -365,6 +365,11 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
 
     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 @@ inline bool WebPage::canHandleUserEvents() const
 
 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 @@ void WebPage::setIsInWindow(bool isInWindow)
             m_setCanStartMediaTimer.startOneShot(0);
 
         m_page->didMoveOnscreen();
+        
+        if (!pageWasInWindow)
+            WebProcess::shared().pageDidEnterWindow(this);
     }
 
     m_page->setIsInWindow(isInWindow);
index 1029dd7..d15c318 100644 (file)
@@ -131,6 +131,9 @@ using namespace WebCore;
 // 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 @@ WebProcess::WebProcess()
 #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 @@ void WebProcess::platformInitializeProcess(const ChildProcessInitializationParam
 {
 }
 #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
index 1597686..ec372bc 100644 (file)
@@ -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 @@ public:
 
     void ensurePrivateBrowsingSession();
     void destroyPrivateBrowsingSession();
+    
+    void pageDidEnterWindow(WebPage*);
+    void pageWillLeaveWindow(WebPage*);
+    
+    void nonVisibleProcessCleanupTimerFired(WebCore::Timer<WebProcess>*);
 
 private:
     WebProcess();
@@ -329,6 +335,9 @@ private:
 #if USE(SOUP)
     WebSoupRequestManager m_soupRequestManager;
 #endif
+    
+    int m_inWindowPageCount;
+    WebCore::Timer<WebProcess> m_nonVisibleProcessCleanupTimer;
 };
 
 } // namespace WebKit
index 5cf2ac2..9cfc38e 100644 (file)
@@ -351,7 +351,7 @@ void WKCAContextSetLayer(WKCAContextRef, CALayer *);
 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));
 
index a315c1c..9db40f6 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLion.a and b/WebKitLibraries/libWebKitSystemInterfaceLion.a differ
index 437a8c1..25fc2be 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a and b/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a differ