Bug 1593408 [Wayland] Position mozcontainer wayland subsurface at moz_container_move(), r=jhorak
authorMartin Stransky <stransky@redhat.com>
Fri, 08 Nov 2019 14:28:39 +0000
changeset 501301 19188ca451132c3c547238c737a575f199b89a73
parent 501300 6fb4aa1b817d5995c11f0507b6273b373fedb02e
child 501302 43dbad71664bb2c5779b54decd5133db076ec6a0
push id114168
push userdluca@mozilla.com
push dateSun, 10 Nov 2019 03:08:55 +0000
treeherdermozilla-inbound@33f64c1ef3e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1593408
milestone72.0a1
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 1593408 [Wayland] Position mozcontainer wayland subsurface at moz_container_move(), r=jhorak WebRender does not call moz_container_get_wl_egl_window() before each frame so mozcontainer is not positioned properly here. As a fix position mozcontainer directly at moz_container_move() if there are resources for it. Also always call moz_container_get_wl_surface() at moz_container_get_wl_egl_window() to make sure an underlying mozcontainer surface is properly positioned. Differential Revision: https://phabricator.services.mozilla.com/D52362
widget/gtk/mozcontainer.cpp
--- a/widget/gtk/mozcontainer.cpp
+++ b/widget/gtk/mozcontainer.cpp
@@ -72,16 +72,20 @@ struct _MozContainerChild {
   gint x;
   gint y;
 };
 
 static void moz_container_allocate_child(MozContainer* container,
                                          MozContainerChild* child);
 static MozContainerChild* moz_container_get_child(MozContainer* container,
                                                   GtkWidget* child);
+#ifdef MOZ_WAYLAND
+static wl_surface* moz_container_get_gtk_container_surface(
+    MozContainer* container);
+#endif
 
 /* public methods */
 
 GType moz_container_get_type(void) {
   static GType moz_container_type = 0;
 
   if (!moz_container_type) {
     static GTypeInfo moz_container_info = {
@@ -143,16 +147,32 @@ void moz_container_put(MozContainer* con
 
 #if defined(MOZ_WAYLAND)
 void moz_container_move(MozContainer* container, int dx, int dy) {
   LOGWAYLAND(("moz_container_move [%p] %d,%d\n", (void*)container, dx, dy));
 
   container->subsurface_dx = dx;
   container->subsurface_dy = dy;
   container->surface_position_needs_update = true;
+
+  // Wayland subsurface is not created yet.
+  if (!container->subsurface) {
+    return;
+  }
+
+  // wl_subsurface_set_position is actually property of parent surface
+  // which is effective when parent surface is commited.
+  wl_surface* parent_surface =
+      moz_container_get_gtk_container_surface(container);
+  if (parent_surface) {
+    wl_subsurface_set_position(container->subsurface, container->subsurface_dx,
+                               container->subsurface_dy);
+    wl_surface_commit(parent_surface);
+    container->surface_position_needs_update = false;
+  }
 }
 
 // This is called from layout/compositor code only with
 // size equal to GL rendering context. Otherwise there are
 // rendering artifacts as wl_egl_window size does not match
 // GL rendering pipeline setup.
 void moz_container_egl_window_set_size(MozContainer* container, int width,
                                        int height) {
@@ -581,45 +601,38 @@ struct wl_surface* moz_container_get_wl_
 
     wl_surface_commit(container->surface);
     wl_display_flush(waylandDisplay->GetDisplay());
 
     LOGWAYLAND(("%s [%p] created surface %p\n", __FUNCTION__, (void*)container,
                 (void*)container->surface));
   }
 
-  // wl_subsurface_set_position is actually property of parent surface
-  // which is effective when parent surface is commited.
   if (container->surface_position_needs_update) {
-    wl_surface* parent_surface =
-        moz_container_get_gtk_container_surface(container);
-    if (parent_surface) {
-      wl_subsurface_set_position(container->subsurface,
-                                 container->subsurface_dx,
-                                 container->subsurface_dy);
-      wl_surface_commit(parent_surface);
-      container->surface_position_needs_update = false;
-    }
+    moz_container_move(container, container->subsurface_dx,
+                       container->subsurface_dy);
   }
 
   wl_surface_set_buffer_scale(container->surface, scale);
   return container->surface;
 }
 
 struct wl_egl_window* moz_container_get_wl_egl_window(MozContainer* container,
                                                       int scale) {
   LOGWAYLAND(("%s [%p] eglwindow %p\n", __FUNCTION__, (void*)container,
               (void*)container->eglwindow));
 
+  // Always call moz_container_get_wl_surface() to ensure underlying
+  // container->surface has correct scale and position.
+  wl_surface* surface = moz_container_get_wl_surface(container, scale);
+  if (!surface) {
+    return nullptr;
+  }
+
   if (!container->eglwindow) {
-    wl_surface* surface = moz_container_get_wl_surface(container, scale);
-    if (!surface) {
-      return nullptr;
-    }
-
     GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
     container->eglwindow =
         wl_egl_window_create(surface, gdk_window_get_width(window) * scale,
                              gdk_window_get_height(window) * scale);
 
     LOGWAYLAND(("%s [%p] created eglwindow %p\n", __FUNCTION__,
                 (void*)container, (void*)container->eglwindow));
   }