Bug 1667851 [Wayland] Rework mozcontainer wl_subsurface creation, r=jhorak
authorstransky <stransky@redhat.com>
Wed, 10 Feb 2021 16:01:13 +0000
changeset 566840 068c880bac2f6797e1ac9f7ece8dfde781fc1414
parent 566839 b0615d0577ae4f0ca373b122b74c8da14cb7dc3a
child 566841 239817dfb372cd95c03b1e969af3fc79449479c2
push id38191
push userbtara@mozilla.com
push dateThu, 11 Feb 2021 05:02:45 +0000
treeherdermozilla-central@5cbcb80f72bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1667851
milestone87.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 1667851 [Wayland] Rework mozcontainer wl_subsurface creation, r=jhorak Rework wl_subsurface creation in these steps: 1) moz_container_wayland_size_allocate() handler is called when mContainer size/position is known. It calls moz_container_wayland_surface_create_locked(), registers a frame callback handler (moz_container_wayland_frame_callback_handler()). 2) moz_container_wayland_frame_callback_handler() is called when wl_surface owned by mozContainer is ready. We call initial_draw_cbs() handler and we can create our wl_subsurface on top of wl_surface owned by mozContainer. Also size wl_buffer at WindowSurfaceWayland according to mozcontainer size, don't use nsWindow bounds for it. Differential Revision: https://phabricator.services.mozilla.com/D104549
widget/gtk/MozContainerWayland.cpp
widget/gtk/MozContainerWayland.h
widget/gtk/WindowSurfaceWayland.cpp
--- a/widget/gtk/MozContainerWayland.cpp
+++ b/widget/gtk/MozContainerWayland.cpp
@@ -1,14 +1,52 @@
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=4:tabstop=4:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+/*
+ * MozContainerWayland is a wrapper over MozContainer which provides
+ * wl_surface for MozContainer widget.
+ *
+ * The widget scheme looks like:
+ *
+ *   ---------------------------------------------------------
+ *  |  mShell Gtk widget (contains wl_surface owned by Gtk+)  |
+ *  |                                                         |
+ *  |  ---------------------------------------------------    |
+ *  | | mContainer (contains wl_surface owned by Gtk+)    |   |
+ *  | |                                                   |   |
+ *  | |  ---------------------------------------------    |   |
+ *  | | | wl_subsurface (attached to wl_surface       |   |   |
+ *  | | |                of mContainer)               |   |   |
+ *  | | |                                             |   |   |
+ *  | | |                                             |   |   |
+ *  | |  ---------------------------------------------    |   |
+ *  |  ---------------------------------------------------    |
+ *   ---------------------------------------------------------
+ *
+ *  We draw to wl_subsurface owned by MozContainerWayland.
+ *  We need to wait until wl_surface of mContainer is created
+ *  and then we create and attach our wl_subsurface to it.
+ *
+ *  wl_subsurface creation has these steps:
+ *
+ *  1) moz_container_wayland_size_allocate() handler is called when
+ *     mContainer size/position is known.
+ *     It calls moz_container_wayland_surface_create_locked(), registers
+ *     a frame callback handler
+ * (moz_container_wayland_frame_callback_handler()).
+ *
+ *  2) moz_container_wayland_frame_callback_handler() is called
+ *     when wl_surface owned by mozContainer is ready.
+ *     We call initial_draw_cbs() handler and we can create our wl_subsurface
+ *     on top of wl_surface owned by mozContainer.
+ */
 
 #include "MozContainer.h"
 
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include "nsWaylandDisplay.h"
 #include "gfxPlatformGtk.h"
@@ -33,64 +71,56 @@ extern mozilla::LazyLogModule gWidgetWay
 using namespace mozilla;
 using namespace mozilla::widget;
 
 /* init methods */
 static void moz_container_wayland_destroy(GtkWidget* widget);
 
 /* widget class methods */
 static void moz_container_wayland_map(GtkWidget* widget);
-static gboolean moz_container_wayland_map_event(GtkWidget* widget,
-                                                GdkEventAny* event);
 static void moz_container_wayland_unmap(GtkWidget* widget);
 static void moz_container_wayland_size_allocate(GtkWidget* widget,
                                                 GtkAllocation* allocation);
+static bool moz_container_wayland_surface_create_locked(
+    MozContainer* container);
+static void moz_container_wayland_set_scale_factor_locked(
+    MozContainer* container);
+static void moz_container_wayland_set_opaque_region_locked(
+    MozContainer* container);
 
 // Imlemented in MozContainer.cpp
 void moz_container_realize(GtkWidget* widget);
 
 static void moz_container_wayland_move_locked(MozContainer* container, int dx,
                                               int dy) {
-  LOGWAYLAND(("moz_container_wayland_move_locked [%p] %d,%d\n",
-              (void*)container, dx, dy));
+  LOGWAYLAND(
+      ("moz_container_wayland_move [%p] %d,%d\n", (void*)container, dx, dy));
 
   MozContainerWayland* wl_container = &container->wl_container;
 
+  if (wl_container->subsurface_dx == dx && wl_container->subsurface_dy == dy) {
+    return;
+  }
+
   wl_container->subsurface_dx = dx;
   wl_container->subsurface_dy = dy;
-  wl_container->surface_position_needs_update = true;
-
-  // Wayland subsurface is not created yet.
-  if (!wl_container->subsurface) {
-    return;
-  }
-
-  // wl_subsurface_set_position is actually property of parent surface
-  // which is effective when parent surface is commited.
   wl_subsurface_set_position(wl_container->subsurface,
                              wl_container->subsurface_dx,
                              wl_container->subsurface_dy);
-  wl_container->surface_position_needs_update = false;
 
   GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
   if (window) {
     GdkRectangle rect = (GdkRectangle){0, 0, gdk_window_get_width(window),
                                        gdk_window_get_height(window)};
-    gdk_window_invalidate_rect(window, &rect, false);
+    // wl_subsurface_set_position is actually property of parent surface
+    // which is effective when parent surface is commited.
+    gdk_window_invalidate_rect(window, &rect, true);
   }
 }
 
-static void moz_container_wayland_move(MozContainer* container, int dx,
-                                       int dy) {
-  MutexAutoLock lock(*container->wl_container.container_lock);
-  LOGWAYLAND(
-      ("moz_container_wayland_move [%p] %d,%d\n", (void*)container, dx, dy));
-  moz_container_wayland_move_locked(container, dx, dy);
-}
-
 // 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_wayland_egl_window_set_size(MozContainer* container,
                                                int width, int height) {
   MozContainerWayland* wl_container = &container->wl_container;
   MutexAutoLock lock(*wl_container->container_lock);
@@ -100,36 +130,33 @@ void moz_container_wayland_egl_window_se
 }
 
 void moz_container_wayland_class_init(MozContainerClass* klass) {
   /*GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
     GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
   GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass);
 
   widget_class->map = moz_container_wayland_map;
-  widget_class->map_event = moz_container_wayland_map_event;
   widget_class->destroy = moz_container_wayland_destroy;
   widget_class->unmap = moz_container_wayland_unmap;
   widget_class->realize = moz_container_realize;
   widget_class->size_allocate = moz_container_wayland_size_allocate;
 }
 
 void moz_container_wayland_init(MozContainerWayland* container) {
   container->surface = nullptr;
   container->subsurface = nullptr;
   container->eglwindow = nullptr;
   container->frame_callback_handler = nullptr;
-  container->frame_callback_handler_surface_id = -1;
   container->ready_to_draw = false;
-  container->opaque_region_needs_update = false;
+  container->opaque_region_updates = false;
   container->opaque_region_subtract_corners = false;
   container->surface_needs_clear = true;
   container->subsurface_dx = 0;
   container->subsurface_dy = 0;
-  container->surface_position_needs_update = 0;
   container->initial_draw_cbs.clear();
   container->container_lock = new mozilla::Mutex("MozContainer lock");
 }
 
 static void moz_container_wayland_destroy(GtkWidget* widget) {
   MozContainerWayland* container = &MOZ_CONTAINER(widget)->wl_container;
   delete container->container_lock;
   container->container_lock = nullptr;
@@ -158,113 +185,59 @@ static void moz_container_wayland_frame_
   LOGWAYLAND(
       ("%s [%p] frame_callback_handler %p ready_to_draw %d (set to true)"
        " initial_draw callback %zd\n",
        __FUNCTION__, (void*)MOZ_CONTAINER(data),
        (void*)wl_container->frame_callback_handler, wl_container->ready_to_draw,
        wl_container->initial_draw_cbs.size()));
 
   g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
-  wl_container->frame_callback_handler_surface_id = -1;
 
   if (!wl_container->ready_to_draw) {
     wl_container->ready_to_draw = true;
     for (auto const& cb : wl_container->initial_draw_cbs) {
       cb();
     }
     wl_container->initial_draw_cbs.clear();
   }
 }
 
 static const struct wl_callback_listener moz_container_frame_listener = {
     moz_container_wayland_frame_callback_handler};
 
-static void moz_container_wayland_request_parent_frame_callback(
-    MozContainer* container) {
-  MozContainerWayland* wl_container = &container->wl_container;
-
-  wl_surface* gtk_container_surface =
-      moz_gtk_widget_get_wl_surface(GTK_WIDGET(container));
-  int gtk_container_surface_id =
-      gtk_container_surface
-          ? wl_proxy_get_id((struct wl_proxy*)gtk_container_surface)
-          : -1;
-
-  LOGWAYLAND(
-      ("%s [%p] frame_callback_handler %p "
-       "frame_callback_handler_surface_id %d\n",
-       __FUNCTION__, (void*)container, wl_container->frame_callback_handler,
-       wl_container->frame_callback_handler_surface_id));
-
-  if (wl_container->frame_callback_handler &&
-      wl_container->frame_callback_handler_surface_id ==
-          gtk_container_surface_id) {
-    return;
-  }
-
-  // If there's pending frame callback, delete it.
-  if (wl_container->frame_callback_handler) {
-    g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
-  }
-
-  if (gtk_container_surface) {
-    wl_container->frame_callback_handler_surface_id = gtk_container_surface_id;
-    wl_container->frame_callback_handler =
-        wl_surface_frame(gtk_container_surface);
-    wl_callback_add_listener(wl_container->frame_callback_handler,
-                             &moz_container_frame_listener, container);
-  } else {
-    wl_container->frame_callback_handler_surface_id = -1;
-  }
-}
-
-static gboolean moz_container_wayland_map_event(GtkWidget* widget,
-                                                GdkEventAny* event) {
-  MozContainerWayland* wl_container = &MOZ_CONTAINER(widget)->wl_container;
-
-  LOGWAYLAND(("%s begin [%p] ready_to_draw %d\n", __FUNCTION__,
-              (void*)MOZ_CONTAINER(widget), wl_container->ready_to_draw));
-
-  if (wl_container->ready_to_draw) {
-    return FALSE;
-  }
-
-  moz_container_wayland_request_parent_frame_callback(MOZ_CONTAINER(widget));
-  return FALSE;
-}
-
 static void moz_container_wayland_unmap_internal(MozContainer* container) {
   MozContainerWayland* wl_container = &container->wl_container;
   MutexAutoLock lock(*wl_container->container_lock);
 
   g_clear_pointer(&wl_container->eglwindow, wl_egl_window_destroy);
   g_clear_pointer(&wl_container->subsurface, wl_subsurface_destroy);
   g_clear_pointer(&wl_container->surface, wl_surface_destroy);
   g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
-  wl_container->frame_callback_handler_surface_id = -1;
 
   wl_container->surface_needs_clear = true;
   wl_container->ready_to_draw = false;
 
   LOGWAYLAND(("%s [%p]\n", __FUNCTION__, (void*)container));
 }
 
 void moz_container_wayland_map(GtkWidget* widget) {
+  LOGWAYLAND(("%s [%p]\n", __FUNCTION__, (void*)widget));
+
   g_return_if_fail(IS_MOZ_CONTAINER(widget));
   gtk_widget_set_mapped(widget, TRUE);
 
   if (gtk_widget_get_has_window(widget)) {
     gdk_window_show(gtk_widget_get_window(widget));
-    moz_container_wayland_map_event(widget, nullptr);
   }
 }
 
 void moz_container_wayland_unmap(GtkWidget* widget) {
+  LOGWAYLAND(("%s [%p]\n", __FUNCTION__, (void*)widget));
+
   g_return_if_fail(IS_MOZ_CONTAINER(widget));
-
   gtk_widget_set_mapped(widget, FALSE);
 
   if (gtk_widget_get_has_window(widget)) {
     gdk_window_hide(gtk_widget_get_window(widget));
     moz_container_wayland_unmap_internal(MOZ_CONTAINER(widget));
   }
 }
 
@@ -283,29 +256,36 @@ void moz_container_wayland_size_allocate
   container = MOZ_CONTAINER(widget);
   gtk_widget_get_allocation(widget, &tmp_allocation);
   if (!container->children && tmp_allocation.x == allocation->x &&
       tmp_allocation.y == allocation->y &&
       tmp_allocation.width == allocation->width &&
       tmp_allocation.height == allocation->height) {
     return;
   }
-
   gtk_widget_set_allocation(widget, allocation);
 
   if (gtk_widget_get_has_window(widget) && gtk_widget_get_realized(widget)) {
     gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x,
                            allocation->y, allocation->width,
                            allocation->height);
     // We need to position our subsurface according to GdkWindow
     // when offset changes (GdkWindow is maximized for instance).
     // see gtk-clutter-embed.c for reference.
     if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
-      moz_container_wayland_move(MOZ_CONTAINER(widget), allocation->x,
-                                 allocation->y);
+      MutexAutoLock lock(*container->wl_container.container_lock);
+      if (!container->wl_container.surface) {
+        if (!moz_container_wayland_surface_create_locked(container)) {
+          return;
+        }
+      }
+      moz_container_wayland_set_scale_factor_locked(container);
+      moz_container_wayland_set_opaque_region_locked(container);
+      moz_container_wayland_move_locked(container, allocation->x,
+                                        allocation->y);
     }
   }
 }
 
 static wl_region* moz_container_wayland_create_opaque_region(
     int aX, int aY, int aWidth, int aHeight, bool aSubtractCorners) {
   struct wl_compositor* compositor = WaylandDisplayGet()->GetCompositor();
   wl_region* region = wl_compositor_create_region(compositor);
@@ -318,192 +298,181 @@ static wl_region* moz_container_wayland_
   }
   return region;
 }
 
 static void moz_container_wayland_set_opaque_region_locked(
     MozContainer* container) {
   MozContainerWayland* wl_container = &container->wl_container;
 
-  if (!wl_container->opaque_region_needs_update || !wl_container->surface) {
+  if (!wl_container->opaque_region_updates) {
     return;
   }
 
   GtkAllocation allocation;
   gtk_widget_get_allocation(GTK_WIDGET(container), &allocation);
 
   wl_region* region = moz_container_wayland_create_opaque_region(
       0, 0, allocation.width, allocation.height,
       wl_container->opaque_region_subtract_corners);
   wl_surface_set_opaque_region(wl_container->surface, region);
   wl_region_destroy(region);
-
-  wl_container->opaque_region_needs_update = false;
 }
 
 static void moz_container_wayland_set_opaque_region(MozContainer* container) {
-  MutexAutoLock lock(*container->wl_container.container_lock);
-  moz_container_wayland_set_opaque_region_locked(container);
+  MozContainerWayland* wl_container = &container->wl_container;
+  MutexAutoLock lock(*wl_container->container_lock);
+  if (wl_container->surface) {
+    moz_container_wayland_set_opaque_region_locked(container);
+  }
 }
 
 static void moz_container_wayland_set_scale_factor_locked(
     MozContainer* container) {
-  if (!container->wl_container.surface) {
-    return;
-  }
   gpointer user_data = g_object_get_data(G_OBJECT(container), "nsWindow");
   nsWindow* wnd = static_cast<nsWindow*>(user_data);
 
   int scale = 1;
   if (wnd) {
     scale = wnd->GdkScaleFactor();
   }
   wl_surface_set_buffer_scale(container->wl_container.surface, scale);
 }
 
 void moz_container_wayland_set_scale_factor(MozContainer* container) {
   MutexAutoLock lock(*container->wl_container.container_lock);
-  moz_container_wayland_set_scale_factor_locked(container);
+  if (container->wl_container.surface) {
+    moz_container_wayland_set_scale_factor_locked(container);
+  }
 }
 
-static struct wl_surface* moz_container_wayland_get_surface_locked(
-    MozContainer* container, nsWaylandDisplay* aWaylandDisplay) {
+static bool moz_container_wayland_surface_create_locked(
+    MozContainer* container) {
   MozContainerWayland* wl_container = &container->wl_container;
 
   LOGWAYLAND(("%s [%p] surface %p ready_to_draw %d\n", __FUNCTION__,
               (void*)container, (void*)wl_container->surface,
               wl_container->ready_to_draw));
 
-  if (!wl_container->surface) {
-    if (!wl_container->ready_to_draw) {
-      moz_container_wayland_request_parent_frame_callback(container);
-      return nullptr;
-    }
-    wl_surface* parent_surface =
-        moz_gtk_widget_get_wl_surface(GTK_WIDGET(container));
-    if (!parent_surface) {
-      return nullptr;
-    }
-
-    // Available as of GTK 3.8+
-    struct wl_compositor* compositor = aWaylandDisplay->GetCompositor();
-    wl_container->surface = wl_compositor_create_surface(compositor);
-    if (!wl_container->surface) {
-      return nullptr;
-    }
+  wl_surface* parent_surface =
+      moz_gtk_widget_get_wl_surface(GTK_WIDGET(container));
+  if (!parent_surface) {
+    NS_WARNING(
+        "moz_container_wayland_surface_create_locked(): Missing parent "
+        "surface!");
+    return false;
+  }
 
-    wl_container->subsurface =
-        wl_subcompositor_get_subsurface(aWaylandDisplay->GetSubcompositor(),
-                                        wl_container->surface, parent_surface);
-    if (!wl_container->subsurface) {
-      g_clear_pointer(&wl_container->surface, wl_surface_destroy);
-      return nullptr;
-    }
-
-    GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
-    gint x, y;
-    gdk_window_get_position(window, &x, &y);
-    moz_container_wayland_move_locked(container, x, y);
-    wl_subsurface_set_desync(wl_container->subsurface);
-
-    // Route input to parent wl_surface owned by Gtk+ so we get input
-    // events from Gtk+.
-    wl_region* region = wl_compositor_create_region(compositor);
-    wl_surface_set_input_region(wl_container->surface, region);
-    wl_region_destroy(region);
-
-    wl_surface_commit(wl_container->surface);
-    wl_display_flush(aWaylandDisplay->GetDisplay());
-
-    LOGWAYLAND(("%s [%p] created surface %p\n", __FUNCTION__, (void*)container,
-                (void*)wl_container->surface));
+  // Available as of GTK 3.8+
+  struct wl_compositor* compositor = WaylandDisplayGet()->GetCompositor();
+  wl_container->surface = wl_compositor_create_surface(compositor);
+  if (!wl_container->surface) {
+    NS_WARNING(
+        "moz_container_wayland_surface_create_locked(): can't create surface!");
+    return false;
   }
 
-  if (wl_container->surface_position_needs_update) {
-    moz_container_wayland_move_locked(container, wl_container->subsurface_dx,
-                                      wl_container->subsurface_dy);
+  wl_container->subsurface =
+      wl_subcompositor_get_subsurface(WaylandDisplayGet()->GetSubcompositor(),
+                                      wl_container->surface, parent_surface);
+  if (!wl_container->subsurface) {
+    g_clear_pointer(&wl_container->surface, wl_surface_destroy);
+    NS_WARNING(
+        "moz_container_wayland_surface_create_locked(): can't create "
+        "sub-surface!");
+    return false;
   }
+  wl_subsurface_set_desync(wl_container->subsurface);
 
-  moz_container_wayland_set_opaque_region_locked(container);
-  moz_container_wayland_set_scale_factor_locked(container);
+  // Route input to parent wl_surface owned by Gtk+ so we get input
+  // events from Gtk+.
+  wl_region* region = wl_compositor_create_region(compositor);
+  wl_surface_set_input_region(wl_container->surface, region);
+  wl_region_destroy(region);
 
-  return wl_container->surface;
+  // If there's pending frame callback it's for wrong parent surface,
+  // so delete it.
+  if (wl_container->frame_callback_handler) {
+    g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
+  }
+  wl_container->frame_callback_handler = wl_surface_frame(parent_surface);
+  wl_callback_add_listener(wl_container->frame_callback_handler,
+                           &moz_container_frame_listener, container);
+
+  wl_surface_commit(wl_container->surface);
+  wl_display_flush(WaylandDisplayGet()->GetDisplay());
+
+  LOGWAYLAND(("%s [%p] created surface %p\n", __FUNCTION__, (void*)container,
+              (void*)wl_container->surface));
+  return true;
 }
 
 struct wl_surface* moz_container_wayland_surface_lock(MozContainer* container) {
-  GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(container));
-  RefPtr<nsWaylandDisplay> waylandDisplay = WaylandDisplayGet(display);
+  LOGWAYLAND(("%s [%p] surface %p ready_to_draw %d\n", __FUNCTION__,
+              (void*)container, (void*)container->wl_container.surface,
+              container->wl_container.ready_to_draw));
 
-  LOGWAYLAND(("%s [%p] surface %p\n", __FUNCTION__, (void*)container,
-              (void*)container->wl_container.surface));
+  if (!container->wl_container.surface ||
+      !container->wl_container.ready_to_draw) {
+    return nullptr;
+  }
 
   container->wl_container.container_lock->Lock();
-  struct wl_surface* surface =
-      moz_container_wayland_get_surface_locked(container, waylandDisplay);
-  if (surface == nullptr) {
-    container->wl_container.container_lock->Unlock();
-  }
-  return surface;
+
+  moz_container_wayland_set_scale_factor_locked(container);
+  return container->wl_container.surface;
 }
 
 void moz_container_wayland_surface_unlock(MozContainer* container,
                                           struct wl_surface** surface) {
   LOGWAYLAND(("%s [%p] surface %p\n", __FUNCTION__, (void*)container,
               (void*)container->wl_container.surface));
   if (*surface) {
     container->wl_container.container_lock->Unlock();
     *surface = nullptr;
   }
 }
 
 struct wl_egl_window* moz_container_wayland_get_egl_window(
     MozContainer* container, int scale) {
-  GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(container));
-  RefPtr<nsWaylandDisplay> waylandDisplay = WaylandDisplayGet(display);
   MozContainerWayland* wl_container = &container->wl_container;
 
   LOGWAYLAND(("%s [%p] eglwindow %p\n", __FUNCTION__, (void*)container,
               (void*)wl_container->eglwindow));
 
   MutexAutoLock lock(*wl_container->container_lock);
-
-  // Always call moz_container_get_wl_surface() to ensure underlying
-  // container->surface has correct scale and position.
-  wl_surface* surface =
-      moz_container_wayland_get_surface_locked(container, waylandDisplay);
-  if (!surface) {
+  if (!wl_container->surface || !wl_container->ready_to_draw) {
     return nullptr;
   }
   if (!wl_container->eglwindow) {
     GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
-    wl_container->eglwindow =
-        wl_egl_window_create(surface, gdk_window_get_width(window) * scale,
-                             gdk_window_get_height(window) * scale);
+    wl_container->eglwindow = wl_egl_window_create(
+        wl_container->surface, gdk_window_get_width(window) * scale,
+        gdk_window_get_height(window) * scale);
 
     LOGWAYLAND(("%s [%p] created eglwindow %p\n", __FUNCTION__,
                 (void*)container, (void*)wl_container->eglwindow));
   }
-
   return wl_container->eglwindow;
 }
 
 gboolean moz_container_wayland_has_egl_window(MozContainer* container) {
   return container->wl_container.eglwindow ? true : false;
 }
 
 gboolean moz_container_wayland_surface_needs_clear(MozContainer* container) {
   int ret = container->wl_container.surface_needs_clear;
   container->wl_container.surface_needs_clear = false;
   return ret;
 }
 
 void moz_container_wayland_update_opaque_region(MozContainer* container,
                                                 bool aSubtractCorners) {
   MozContainerWayland* wl_container = &container->wl_container;
-  wl_container->opaque_region_needs_update = true;
+  wl_container->opaque_region_updates = true;
   wl_container->opaque_region_subtract_corners = aSubtractCorners;
 
   // When GL compositor / WebRender is used,
   // moz_container_wayland_get_egl_window() is called only once when window
   // is created or resized so update opaque region now.
   if (moz_container_wayland_has_egl_window(container)) {
     moz_container_wayland_set_opaque_region(container);
   }
--- a/widget/gtk/MozContainerWayland.h
+++ b/widget/gtk/MozContainerWayland.h
@@ -32,21 +32,19 @@ struct wl_surface;
 struct wl_subsurface;
 
 struct MozContainerWayland {
   struct wl_surface* surface;
   struct wl_subsurface* subsurface;
   int subsurface_dx, subsurface_dy;
   struct wl_egl_window* eglwindow;
   struct wl_callback* frame_callback_handler;
-  int frame_callback_handler_surface_id;
-  gboolean opaque_region_needs_update;
+  gboolean opaque_region_updates;
   gboolean opaque_region_subtract_corners;
   gboolean opaque_region_fullscreen;
-  gboolean surface_position_needs_update;
   gboolean surface_needs_clear;
   gboolean ready_to_draw;
   std::vector<std::function<void(void)>> initial_draw_cbs;
   // mozcontainer is used from Compositor and Rendering threads
   // so we need to control access to mozcontainer where wayland internals
   // are used directly.
   mozilla::Mutex* container_lock;
 };
@@ -63,18 +61,16 @@ struct wl_surface* moz_container_wayland
 void moz_container_wayland_surface_unlock(MozContainer* container,
                                           struct wl_surface** surface);
 
 struct wl_egl_window* moz_container_wayland_get_egl_window(
     MozContainer* container, int scale);
 
 gboolean moz_container_wayland_has_egl_window(MozContainer* container);
 gboolean moz_container_wayland_surface_needs_clear(MozContainer* container);
-void moz_container_wayland_move_resize(MozContainer* container, int dx, int dy,
-                                       int width, int height);
 void moz_container_wayland_egl_window_set_size(MozContainer* container,
                                                int width, int height);
 void moz_container_wayland_set_scale_factor(MozContainer* container);
 void moz_container_wayland_add_initial_draw_callback(
     MozContainer* container, const std::function<void(void)>& initial_draw_cb);
 wl_surface* moz_gtk_widget_get_wl_surface(GtkWidget* aWidget);
 void moz_container_wayland_update_opaque_region(MozContainer* container,
                                                 bool aSubtractCorners);
--- a/widget/gtk/WindowSurfaceWayland.cpp
+++ b/widget/gtk/WindowSurfaceWayland.cpp
@@ -656,20 +656,18 @@ WindowBackBuffer* WindowSurfaceWayland::
       ("    Buffer size does not match, requested %d x %d got %d x%d, return "
        "null.\n",
        mWaylandBuffer->GetWidth(), mWaylandBuffer->GetHeight(),
        mWLBufferRect.width, mWLBufferRect.height));
   return nullptr;
 }
 
 already_AddRefed<gfx::DrawTarget> WindowSurfaceWayland::LockWaylandBuffer() {
-  // Allocated wayland buffer can't be bigger than mozilla widget size.
-  LayoutDeviceIntRegion region;
-  region.And(mLockedScreenRect, mWindow->GetMozContainerSize());
-  mWLBufferRect = LayoutDeviceIntRect(region.GetBounds());
+  // Allocated wayland buffer must match mozcontainer widget size.
+  mWLBufferRect = mWindow->GetMozContainerSize();
 
   LOGWAYLAND(
       ("WindowSurfaceWayland::LockWaylandBuffer [%p] Requesting buffer %d x "
        "%d\n",
        (void*)this, mWLBufferRect.width, mWLBufferRect.height));
 
   WindowBackBuffer* buffer = GetWaylandBuffer();
   LOGWAYLAND(("WindowSurfaceWayland::LockWaylandBuffer [%p] Got buffer %p\n",
@@ -746,17 +744,17 @@ already_AddRefed<gfx::DrawTarget> Window
   // Lock the surface *after* WaitForSyncEnd() call as is can fire
   // FlushPendingCommits().
   MutexAutoLock lock(mSurfaceLock);
 
   // Disable all commits (from potential frame callback/delayed handlers)
   // until next WindowSurfaceWayland::Commit() call.
   mBufferCommitAllowed = false;
 
-  LayoutDeviceIntRect lockedScreenRect = mWindow->GetBounds();
+  LayoutDeviceIntRect lockedScreenRect = mWindow->GetMozContainerSize();
   // The window bounds of popup windows contains relative position to
   // the transient window. We need to remove that effect because by changing
   // position of the popup window the buffer has not changed its size.
   lockedScreenRect.x = lockedScreenRect.y = 0;
   gfx::IntRect lockSize = aRegion.GetBounds().ToUnknownRect();
 
   bool isTransparentPopup =
       mWindow->IsWaylandPopup() &&
@@ -821,30 +819,24 @@ already_AddRefed<gfx::DrawTarget> Window
       // This should not happen. Screen size changed but we got only
       // partal screen update instead of whole screen. Discard this painting
       // as it produces artifacts.
       return nullptr;
     }
     mLockedScreenRect = lockedScreenRect;
   }
 
-  // We can draw directly only when widget has the same size as wl_buffer
-  LayoutDeviceIntRect size = mWindow->GetMozContainerSize();
-  mDrawToWaylandBufferDirectly = (size.width >= mLockedScreenRect.width &&
-                                  size.height >= mLockedScreenRect.height);
-
   // We can draw directly only when we redraw significant part of the window
   // to avoid flickering or do only fullscreen updates in smooth mode.
-  if (mDrawToWaylandBufferDirectly) {
-    mDrawToWaylandBufferDirectly =
-        mSmoothRendering
-            ? windowRedraw
-            : (windowRedraw || (lockSize.width * 2 > lockedScreenRect.width &&
-                                lockSize.height * 2 > lockedScreenRect.height));
-  }
+  mDrawToWaylandBufferDirectly =
+      mSmoothRendering
+          ? windowRedraw
+          : (windowRedraw || (lockSize.width * 2 > lockedScreenRect.width &&
+                              lockSize.height * 2 > lockedScreenRect.height));
+
   if (!mDrawToWaylandBufferDirectly) {
     // Don't switch wl_buffers when we cache drawings.
     mCanSwitchWaylandBuffer = false;
     LOGWAYLAND(("   Indirect drawing, mCanSwitchWaylandBuffer = %d\n",
                 mCanSwitchWaylandBuffer));
   }
 
   if (mDrawToWaylandBufferDirectly) {