Bug 1529713 - [Titlebar] Use Window manager decorations on GNOME again, r=lsalzman a=lizzard
authorMartin Stransky <stransky@redhat.com>
Fri, 22 Feb 2019 14:01:50 +0000
changeset 513340 e91e23e30d4b
parent 513339 ff2c3fd26b15
child 513341 d8af25e59ccf
push id10810
push userdvarga@mozilla.com
push dateSat, 02 Mar 2019 00:29:41 +0000
treeherdermozilla-beta@bdc420ea17d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman, lizzard
bugs1529713
milestone66.0
Bug 1529713 - [Titlebar] Use Window manager decorations on GNOME again, r=lsalzman a=lizzard This patch enables the shape mask in CSD and Window manager decorations mode when we're runnin on composited screen and mozilla.widget.use-argb-visuals is not set. Also don't use shape mask with Wayland and GL backend. When shape mask is set, advertise toplevel window transparency but don't advertise it as alpha to GtkCompositorWidget. Differential Revision: https://phabricator.services.mozilla.com/D20726
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -684,19 +684,25 @@ nsresult nsLookAndFeel::GetIntImpl(IntID
     case eIntID_GTKCSDMinimizeButton:
       EnsureInit();
       aResult = mCSDMinimizeButton;
       break;
     case eIntID_GTKCSDCloseButton:
       EnsureInit();
       aResult = mCSDCloseButton;
       break;
-    case eIntID_GTKCSDTransparentBackground:
-      aResult = nsWindow::TopLevelWindowUseARGBVisual();
+    case eIntID_GTKCSDTransparentBackground: {
+      // Enable transparent titlebar corners for titlebar mode.
+      GdkScreen* screen = gdk_screen_get_default();
+      aResult = gdk_screen_is_composited(screen)
+                    ? (nsWindow::GetSystemCSDSupportLevel() !=
+                       nsWindow::CSD_SUPPORT_NONE)
+                    : false;
       break;
+    }
     case eIntID_GTKCSDReversedPlacement:
       EnsureInit();
       aResult = mCSDReversedPlacement;
       break;
     case eIntID_PrefersReducedMotion: {
       GtkSettings* settings;
       gboolean enableAnimations;
 
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -3277,38 +3277,41 @@ nsresult nsWindow::Create(nsIWidget *aPa
 
       bool shouldAccelerate = ComputeShouldAccelerate();
       MOZ_ASSERT(shouldAccelerate | !useWebRender);
 
       if (mWindowType == eWindowType_toplevel) {
         // We enable titlebar rendering for toplevel windows only.
         mCSDSupportLevel = GetSystemCSDSupportLevel();
 
-        // Some Gtk+ themes use non-rectangular toplevel windows. To fully
-        // support such themes we need to make toplevel window transparent
-        // with ARGB visual.
-        // It may cause performanance issue so make it configurable
-        // and enable it by default for selected window managers.
-        needsAlphaVisual = TopLevelWindowUseARGBVisual();
-        if (needsAlphaVisual && mIsX11Display && !shouldAccelerate) {
-          // We want to draw a transparent titlebar but we can't use
-          // ARGB visual due to Bug 1516224.
-          // We use ARGB visual for mShell only and shape mask
-          // for mContainer where is all our content drawn.
-          mTransparencyBitmapForTitlebar = true;
-        }
-
-        // When mozilla.widget.use-argb-visuals is set don't use shape mask.
-        if (mTransparencyBitmapForTitlebar &&
-            Preferences::GetBool("mozilla.widget.use-argb-visuals", false)) {
-          mTransparencyBitmapForTitlebar = false;
-        }
-
-        if (mTransparencyBitmapForTitlebar) {
-          mCSDSupportLevel = CSD_SUPPORT_CLIENT;
+        // There's no point to configure transparency
+        // on non-composited screens.
+        GdkScreen *screen = gdk_screen_get_default();
+        if (gdk_screen_is_composited(screen)) {
+          // Some Gtk+ themes use non-rectangular toplevel windows. To fully
+          // support such themes we need to make toplevel window transparent
+          // with ARGB visual.
+          // It may cause performanance issue so make it configurable
+          // and enable it by default for selected window managers.
+          if (Preferences::HasUserValue("mozilla.widget.use-argb-visuals")) {
+            // argb visual is explicitly required so use it
+            needsAlphaVisual =
+                Preferences::GetBool("mozilla.widget.use-argb-visuals");
+          } else if (!mIsX11Display) {
+            // Wayland uses ARGB visual by default
+            needsAlphaVisual = true;
+          } else if (mCSDSupportLevel != CSD_SUPPORT_NONE) {
+            if (shouldAccelerate) {
+              needsAlphaVisual = true;
+            } else {
+              // We want to draw a transparent titlebar but we can't use
+              // ARGB visual due to Bug 1516224.
+              mTransparencyBitmapForTitlebar = true;
+            }
+          }
         }
       }
 
       bool isSetVisual = false;
       // If using WebRender on X11, we need to select a visual with a depth
       // buffer, as well as an alpha channel if transparency is requested. This
       // must be done before the widget is realized.
 
@@ -3341,17 +3344,18 @@ nsresult nsWindow::Create(nsIWidget *aPa
             mHasAlphaVisual = true;
           }
         }
       }
 
       // We have a toplevel window with transparency. Mark it as transparent
       // now as nsWindow::SetTransparencyMode() can't be called after
       // nsWindow is created (Bug 1344839).
-      if (mWindowType == eWindowType_toplevel && mHasAlphaVisual) {
+      if (mWindowType == eWindowType_toplevel &&
+          (mHasAlphaVisual || mTransparencyBitmapForTitlebar)) {
         mIsTransparent = true;
       }
 
       // We only move a general managed toplevel window if someone has
       // actually placed the window somewhere.  If no placement has taken
       // place, we just let the window manager Do The Right Thing.
       NativeResize();
 
@@ -6506,59 +6510,31 @@ bool nsWindow::HideTitlebarByDefault() {
     hideTitlebar =
         (strstr(currentDesktop, "GNOME-Flashback:GNOME") != nullptr ||
          strstr(currentDesktop, "GNOME") != nullptr);
   }
 
   return hideTitlebar;
 }
 
-bool nsWindow::TopLevelWindowUseARGBVisual() {
-  static int useARGBVisual = -1;
-  if (useARGBVisual != -1) {
-    return useARGBVisual;
-  }
-
-  GdkScreen *screen = gdk_screen_get_default();
-  if (!gdk_screen_is_composited(screen)) {
-    useARGBVisual = false;
-  }
-
-  if (Preferences::HasUserValue("mozilla.widget.use-argb-visuals")) {
-    useARGBVisual =
-        Preferences::GetBool("mozilla.widget.use-argb-visuals", false);
-  } else {
-    const char *currentDesktop = getenv("XDG_CURRENT_DESKTOP");
-    useARGBVisual =
-        (currentDesktop && GetSystemCSDSupportLevel() != CSD_SUPPORT_NONE);
-
-    if (useARGBVisual) {
-      useARGBVisual =
-          (strstr(currentDesktop, "GNOME-Flashback:GNOME") != nullptr ||
-           strstr(currentDesktop, "GNOME") != nullptr);
-    }
-  }
-
-  return useARGBVisual;
-}
-
 int32_t nsWindow::RoundsWidgetCoordinatesTo() { return GdkScaleFactor(); }
 
 void nsWindow::GetCompositorWidgetInitData(
     mozilla::widget::CompositorWidgetInitData *aInitData) {
   // Make sure the window XID is propagated to X server, we can fail otherwise
   // in GPU process (Bug 1401634).
   if (mXDisplay && mXWindow != X11None) {
     XFlush(mXDisplay);
   }
 
   *aInitData = mozilla::widget::GtkCompositorWidgetInitData(
       (mXWindow != X11None) ? mXWindow : (uintptr_t) nullptr,
       mXDisplay ? nsCString(XDisplayString(mXDisplay)) : nsCString(),
-      mIsTransparent && !mHasAlphaVisual, GetClientSize());
+      mIsTransparent && !mHasAlphaVisual && !mTransparencyBitmapForTitlebar,
+      GetClientSize());
 }
 
 #ifdef MOZ_WAYLAND
 wl_surface *nsWindow::GetWaylandSurface() {
   if (mContainer)
     return moz_container_get_wl_surface(MOZ_CONTAINER(mContainer));
 
   NS_WARNING(
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -380,17 +380,16 @@ class nsWindow final : public nsBaseWidg
   } CSDSupportLevel;
   /**
    * Get the support of Client Side Decoration by checking
    * the XDG_CURRENT_DESKTOP environment variable.
    */
   static CSDSupportLevel GetSystemCSDSupportLevel();
 
   static bool HideTitlebarByDefault();
-  static bool TopLevelWindowUseARGBVisual();
   static bool GetTopLevelWindowActiveState(nsIFrame* aFrame);
 
  protected:
   virtual ~nsWindow();
 
   // event handling code
   void DispatchActivateEvent(void);
   void DispatchDeactivateEvent(void);