Bug 1477967 - Fix the popup menu sizes and redrawing on Wayland/hidpi monitor, r?stransky draft
authorJan Horak <jhorak@redhat.com>
Tue, 24 Jul 2018 12:51:34 +0200
changeset 821922 71f34d8039040bd847b2a405f3c7ece6b010d03c
parent 820343 183ee39bf309cd8463d8db5b5c8eb232cd0dac53
push id117226
push userbmo:jhorak@redhat.com
push dateTue, 24 Jul 2018 10:52:18 +0000
reviewersstransky
bugs1477967
milestone63.0a1
Bug 1477967 - Fix the popup menu sizes and redrawing on Wayland/hidpi monitor, r?stransky This patch fixes redrawing of the popup element by removing the scale factor from the invalid regions because the wl_surface_damage multiplies it with the scale factor too. Also we set scaling factor of the wl_surface right after we create it to avoid flickering when the compositor switches from unscaled to scaled surface. MozReview-Commit-ID: 1eGoFu87wtF
widget/gtk/WindowSurfaceWayland.cpp
widget/gtk/mozcontainer.cpp
--- a/widget/gtk/WindowSurfaceWayland.cpp
+++ b/widget/gtk/WindowSurfaceWayland.cpp
@@ -788,19 +788,23 @@ WindowSurfaceWayland::Commit(const Layou
     CommitImageSurface(aInvalidRegion);
   }
 
   if (mFullScreenDamage) {
     LayoutDeviceIntRect rect = mWindow->GetBounds();
     wl_surface_damage(waylandSurface, 0, 0, rect.width, rect.height);
     mFullScreenDamage = false;
   } else {
+    gint scaleFactor = mWindow->GdkScaleFactor();
     for (auto iter = aInvalidRegion.RectIter(); !iter.Done(); iter.Next()) {
       const mozilla::LayoutDeviceIntRect &r = iter.Get();
-      wl_surface_damage(waylandSurface, r.x, r.y, r.width, r.height);
+      // We need to remove the scale factor because the wl_surface_damage
+      // also multiplies by current  scale factor.
+      wl_surface_damage(waylandSurface, r.x/scaleFactor, r.y/scaleFactor,
+                        r.width/scaleFactor, r.height/scaleFactor);
     }
   }
 
   // Frame callback is always connected to actual wl_surface. When the surface
   // is unmapped/deleted the frame callback is never called. Unfortunatelly
   // we don't know if the frame callback is not going to be called.
   // But our mozcontainer code deletes wl_surface when the GdkWindow is hidden
   // creates a new one when is visible.
--- a/widget/gtk/mozcontainer.cpp
+++ b/widget/gtk/mozcontainer.cpp
@@ -600,16 +600,25 @@ struct wl_surface*
 moz_container_get_wl_surface(MozContainer *container)
 {
     if (!container->subsurface || !container->surface) {
         GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
         if (!gdk_window_is_visible(window))
             return nullptr;
 
         moz_container_map_surface(container);
+        // Set the scale factor for the buffer right after we create it.
+        if (container->surface) {
+            static auto sGdkWindowGetScaleFactorPtr = (gint (*)(GdkWindow*))
+            dlsym(RTLD_DEFAULT, "gdk_window_get_scale_factor");
+            if (sGdkWindowGetScaleFactorPtr && window) {
+              gint scaleFactor = (*sGdkWindowGetScaleFactorPtr)(window);
+              wl_surface_set_buffer_scale(container->surface, scaleFactor);
+            }
+        }
     }
 
     return container->surface;
 }
 
 struct wl_egl_window *
 moz_container_get_wl_egl_window(MozContainer *container)
 {