Bug 588690 - Part 2: Clear cached resources when a windows becomes inactive. r=roc a=blocking-beta5+
authorBas Schouten <bschouten@mozilla.com>
Fri, 20 Aug 2010 05:40:51 +0200
changeset 51000 2f75f983440c2084e3da3cbe5a9d54a3b52af91e
parent 50999 8c767b9503818763af4ad69a0b75bff8df900236
child 51001 9976121e4d31118e7126767d0c5cef2d57f958e0
push idunknown
push userunknown
push dateunknown
reviewersroc, blocking-beta5
bugs588690
milestone2.0b5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 588690 - Part 2: Clear cached resources when a windows becomes inactive. r=roc a=blocking-beta5+
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -674,19 +674,19 @@ NS_METHOD nsWindow::Destroy()
    * On windows the LayerManagerOGL destructor wants the widget to be around for
    * cleanup. It also would like to have the HWND intact, so we NULL it here.
    */
   if (mLayerManager) {
     mLayerManager->Destroy();
   }
   mLayerManager = nsnull;
 
-  /* We should clear our D2D window surface now and not wait for the GC to
+  /* We should clear our cached resources now and not wait for the GC to
    * delete the nsWindow. */
-  mD2DWindowSurface = nsnull;
+  ClearCachedResources();
 
   // The DestroyWindow function destroys the specified window. The function sends WM_DESTROY
   // and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus
   // from it. The function also destroys the window's menu, flushes the thread message queue,
   // destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain (if
   // the window is at the top of the viewer chain).
   //
   // If the specified window is a parent or owner window, DestroyWindow automatically destroys
@@ -1162,21 +1162,19 @@ NS_METHOD nsWindow::Show(PRBool bState)
   }
 #endif
 
   PRBool wasVisible = mIsVisible;
   // Set the status now so that anyone asking during ShowWindow or
   // SetWindowPos would get the correct answer.
   mIsVisible = bState;
 
-#ifdef CAIRO_HAS_D2D_SURFACE
   if (!mIsVisible && wasVisible) {
-      ClearD2DSurface();
-  }
-#endif
+      ClearCachedResources();
+  }
 
   if (mWnd) {
     if (bState) {
       if (!wasVisible && mWindowType == eWindowType_toplevel) {
         switch (mSizeMode) {
 #ifdef WINCE
           case nsSizeMode_Fullscreen:
             ::SetForegroundWindow(mWnd);
@@ -7931,40 +7929,38 @@ VOID CALLBACK nsWindow::HookTimerForPopu
     nsAutoRollup autoRollup;
     DealWithPopups(sRollupMsgWnd, sRollupMsgId, 0, 0, &popupHandlingResult);
     sRollupMsgId = 0;
     sRollupMsgWnd = NULL;
   }
 }
 #endif // WinCE
 
-#ifdef CAIRO_HAS_D2D_SURFACE
-BOOL CALLBACK nsWindow::ClearD2DSurfaceCallback(HWND aWnd, LPARAM aMsg)
+BOOL CALLBACK nsWindow::ClearResourcesCallback(HWND aWnd, LPARAM aMsg)
 {
     nsWindow *window = nsWindow::GetNSWindowPtr(aWnd);
     if (window) {
-        window->ClearD2DSurface();
+        window->ClearCachedResources();
     }  
     return TRUE;
 }
 
 void
-nsWindow::ClearD2DSurface()
-{
+nsWindow::ClearCachedResources()
+{
+#ifdef CAIRO_HAS_D2D_SURFACE
     mD2DWindowSurface = nsnull;
-    if (gfxWindowsPlatform::GetPlatform()->GetRenderMode() ==
-        gfxWindowsPlatform::RENDER_DIRECT2D) {
-        // The layer manager holds onto a bunch of buffers created with create
-        // similar surface. This can consume quite a bit of VMEM for each tab,
-        // if a window is hidden we clear the layer manager to conserve VRAM.
-        mLayerManager = nsnull;
-    }
-    ::EnumChildWindows(mWnd, nsWindow::ClearD2DSurfaceCallback, NULL);
-}
-#endif
+#endif
+    if (mLayerManager &&
+        mLayerManager->GetBackendType() == LayerManager::LAYERS_BASIC) {
+      static_cast<BasicLayerManager*>(mLayerManager.get())->
+        ClearCachedResources();
+    }
+    ::EnumChildWindows(mWnd, nsWindow::ClearResourcesCallback, NULL);
+}
 
 static PRBool IsDifferentThreadWindow(HWND aWnd)
 {
   return ::GetCurrentThreadId() != ::GetWindowThreadProcessId(aWnd, NULL);
 }
 
 PRBool
 nsWindow::EventIsInsideWindow(UINT Msg, nsWindow* aWindow)
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -286,19 +286,17 @@ protected:
 #if !defined(WINCE)
   static BOOL CALLBACK    RegisterTouchForDescendants(HWND aTopWindow, LPARAM aMsg);
   static BOOL CALLBACK    UnregisterTouchForDescendants(HWND aTopWindow, LPARAM aMsg);
 #endif
   static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam, LPARAM lParam);
   static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam, LPARAM lParam);
   static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam, LPARAM lParam);
   static VOID    CALLBACK HookTimerForPopups( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime );
-#ifdef CAIRO_HAS_D2D_SURFACE
-  static BOOL    CALLBACK ClearD2DSurfaceCallback(HWND aChild, LPARAM aParam);
-#endif
+  static BOOL    CALLBACK ClearResourcesCallback(HWND aChild, LPARAM aParam);
 
   /**
    * Window utilities
    */
   static BOOL             SetNSWindowPtr(HWND aWnd, nsWindow * ptr);
   LPARAM                  lParamToScreen(LPARAM lParam);
   LPARAM                  lParamToClient(LPARAM lParam);
   virtual void            SubclassWindow(BOOL bState);
@@ -450,19 +448,17 @@ protected:
                                            PAINTSTRUCT ps, HDC aDC);
 #if !defined(WINCE)
   static void             ActivateOtherWindowHelper(HWND aWnd);
   static PRUint16         GetMouseInputSource();
 #endif
 #ifdef ACCESSIBILITY
   static STDMETHODIMP_(LRESULT) LresultFromObject(REFIID riid, WPARAM wParam, LPUNKNOWN pAcc);
 #endif // ACCESSIBILITY
-#ifdef CAIRO_HAS_D2D_SURFACE
-  void                    ClearD2DSurface();
-#endif
+  void                    ClearCachedResources();
 
 protected:
   nsCOMPtr<nsIWidget>   mParent;
   nsIntSize             mLastSize;
   nsIntPoint            mLastPoint;
   HWND                  mWnd;
   WNDPROC               mPrevWndProc;
   HBRUSH                mBrush;