Bug 630346 - Use basic layers for windows with transparency r=karlt
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Mon, 24 Sep 2012 11:22:28 +1200
changeset 107991 e19ca9b2b5a9416c1ec121a88b689f932b81ef80
parent 107990 461384440ce3858dcdfa62cc555133d125f9d648
child 107992 9fb29b2cc63181dde1f2cf218b0b23972b1ddae5
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerskarlt
bugs630346
milestone18.0a1
Bug 630346 - Use basic layers for windows with transparency r=karlt
widget/gtk2/nsWindow.cpp
widget/gtk2/nsWindow.h
--- a/widget/gtk2/nsWindow.cpp
+++ b/widget/gtk2/nsWindow.cpp
@@ -3974,16 +3974,34 @@ nsWindow::GetSafeWindowSize(nsIntSize aS
 void
 nsWindow::EnsureGrabs(void)
 {
     if (mRetryPointerGrab)
         GrabPointer(sRetryGrabTime);
 }
 
 void
+nsWindow::CleanLayerManagerRecursive(void) {
+    if (mLayerManager) {
+        mLayerManager->Destroy();
+        mLayerManager = nullptr;
+    }
+
+    DestroyCompositor();
+
+    GList* children = gdk_window_peek_children(mGdkWindow);
+    for (GList* list = children; list; list = list->next) {
+        nsWindow* window = get_window_for_gdk_window(GDK_WINDOW(list->data));
+        if (window) {
+            window->CleanLayerManagerRecursive();
+        }
+    }
+}
+
+void
 nsWindow::SetTransparencyMode(nsTransparencyMode aMode)
 {
     if (!mShell) {
         // Pass the request to the toplevel window
         GtkWidget *topWidget = nullptr;
         GetToplevelWidget(&topWidget);
         if (!topWidget)
             return;
@@ -4011,16 +4029,20 @@ nsWindow::SetTransparencyMode(nsTranspar
 #else
             // GTK3 TODO
 #endif
         }
     } // else the new default alpha values are "all 1", so we don't
     // need to change anything yet
 
     mIsTransparent = isTransparent;
+
+    // Need to clean our LayerManager up while still alive because
+    // we don't want to use layers acceleration on shaped windows
+    CleanLayerManagerRecursive();
 }
 
 nsTransparencyMode
 nsWindow::GetTransparencyMode()
 {
     if (!mShell) {
         // Pass the request to the toplevel window
         GtkWidget *topWidget = nullptr;
@@ -6133,16 +6155,30 @@ nsWindow::BeginResizeDrag(nsGUIEvent* aE
 
     // tell the window manager to start the resize
     gdk_window_begin_resize_drag(gdk_window, window_edge, button,
                                  screenX, screenY, aEvent->time);
 
     return NS_OK;
 }
 
+nsIWidget::LayerManager*
+nsWindow::GetLayerManager(PLayersChild* aShadowManager,
+                          LayersBackend aBackendHint,
+                          LayerManagerPersistence aPersistence,
+                          bool* aAllowRetaining)
+{
+    if (!mLayerManager && eTransparencyTransparent == GetTransparencyMode()) {
+        mLayerManager = CreateBasicLayerManager();
+    }
+
+    return nsBaseWidget::GetLayerManager(aShadowManager, aBackendHint,
+                                         aPersistence, aAllowRetaining);
+}
+
 void
 nsWindow::ClearCachedResources()
 {
     if (mLayerManager &&
         mLayerManager->GetBackendType() == mozilla::layers::LAYERS_BASIC) {
         static_cast<mozilla::layers::BasicLayerManager*> (mLayerManager.get())->
             ClearCachedResources();
     }
--- a/widget/gtk2/nsWindow.h
+++ b/widget/gtk2/nsWindow.h
@@ -437,16 +437,24 @@ private:
     // Remember the last sizemode so that we can restore it when
     // leaving fullscreen
     nsSizeMode         mLastSizeMode;
 
     static bool DragInProgress(void);
 
     void DispatchMissedButtonReleases(GdkEventCrossing *aGdkEvent);
 
+    // nsBaseWidget
+    virtual LayerManager* GetLayerManager(PLayersChild* aShadowManager = nullptr,
+                                          LayersBackend aBackendHint = mozilla::layers::LAYERS_NONE,
+                                          LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
+                                          bool* aAllowRetaining = nullptr) MOZ_OVERRIDE;
+
+    void CleanLayerManagerRecursive();
+
     /**
      * |mIMModule| takes all IME related stuff.
      *
      * This is owned by the top-level nsWindow or the topmost child
      * nsWindow embedded in a non-Gecko widget.
      *
      * The instance is created when the top level widget is created.  And when
      * the widget is destroyed, it's released.  All child windows refer its