Bug 1645677 [Wayland] Attach map/unmap signals to mContainer r=emilio

Map/Unmap signals creates and deletes mContainer wayland surface and EGL window.

As we need to call the handlers in correct order (mContainer::map -> nsWindow::map and nsWindow::unmap -> mContainer::unmap)
connect the signals to mContainer widget and call mContainer::unmap from nsWindow::unmap.

Then nsWindow::unmap can update compositor before wl_surface/EGL window is released by mContainer.

Differential Revision: https://phabricator.services.mozilla.com/D157357
This commit is contained in:
stransky 2022-09-21 10:32:44 +00:00
Родитель d7b6c906b3
Коммит 793e504659
4 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -88,7 +88,6 @@ static void moz_container_wayland_destroy(GtkWidget* widget);
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(
@ -182,7 +181,6 @@ void moz_container_wayland_class_init(MozContainerClass* 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;
}

Просмотреть файл

@ -71,6 +71,7 @@ class MozContainerSurfaceLock {
void moz_container_wayland_class_init(MozContainerClass* klass);
void moz_container_wayland_init(MozContainerWayland* container);
void moz_container_wayland_unmap(GtkWidget* widget);
struct wl_egl_window* moz_container_wayland_get_egl_window(
MozContainer* container, double scale);

Просмотреть файл

@ -191,6 +191,7 @@ static int is_parent_grab_leave(GdkEventCrossing* aEvent);
static gboolean expose_event_cb(GtkWidget* widget, cairo_t* cr);
static gboolean configure_event_cb(GtkWidget* widget, GdkEventConfigure* event);
static void widget_map_cb(GtkWidget* widget);
static void widget_unmap_cb(GtkWidget* widget);
static void widget_unrealize_cb(GtkWidget* widget);
static void size_allocate_cb(GtkWidget* widget, GtkAllocation* allocation);
static void toplevel_window_size_allocate_cb(GtkWidget* widget,
@ -4049,7 +4050,7 @@ gboolean nsWindow::OnConfigureEvent(GtkWidget* aWidget,
void nsWindow::OnMap() {
LOG("nsWindow::OnMap");
// Gtk mapped out widget to screen. Configure underlying GdkWindow properly
// Gtk mapped widget to screen. Configure underlying GdkWindow properly
// as our rendering target.
// This call means we have X11 (or Wayland) window we can render to by GL
// so we need to notify compositor about it.
@ -4057,6 +4058,11 @@ void nsWindow::OnMap() {
ConfigureGdkWindow();
}
void nsWindow::OnUnmap() {
LOG("nsWindow::OnUnmap");
moz_container_wayland_unmap(GTK_WIDGET(mContainer));
}
void nsWindow::OnUnrealize() {
// The GdkWindows are about to be destroyed (but not deleted), so remove
// their references back to their container widget while the GdkWindow
@ -6084,9 +6090,6 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
G_CALLBACK(widget_composited_changed_cb), nullptr);
g_signal_connect(mShell, "property-notify-event",
G_CALLBACK(property_notify_event_cb), nullptr);
g_signal_connect(mShell, "map", G_CALLBACK(widget_map_cb), nullptr);
g_signal_connect(mShell, "unrealize", G_CALLBACK(widget_unrealize_cb),
nullptr);
if (mWindowType == eWindowType_toplevel) {
g_signal_connect_after(mShell, "size_allocate",
@ -6118,6 +6121,10 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
G_CALLBACK(settings_xft_dpi_changed_cb), this);
// Widget signals
g_signal_connect(mContainer, "map", G_CALLBACK(widget_map_cb), nullptr);
g_signal_connect(mContainer, "unmap", G_CALLBACK(widget_unmap_cb), nullptr);
g_signal_connect(mContainer, "unrealize", G_CALLBACK(widget_unrealize_cb),
nullptr);
g_signal_connect_after(mContainer, "size_allocate",
G_CALLBACK(size_allocate_cb), nullptr);
g_signal_connect(mContainer, "hierarchy-changed",
@ -7841,6 +7848,14 @@ static void widget_map_cb(GtkWidget* widget) {
window->OnMap();
}
static void widget_unmap_cb(GtkWidget* widget) {
RefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
if (!window) {
return;
}
window->OnUnmap();
}
static void widget_unrealize_cb(GtkWidget* widget) {
RefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
if (!window) {

Просмотреть файл

@ -222,6 +222,7 @@ class nsWindow final : public nsBaseWidget {
gboolean OnExposeEvent(cairo_t* cr);
gboolean OnConfigureEvent(GtkWidget* aWidget, GdkEventConfigure* aEvent);
void OnMap();
void OnUnmap();
void OnUnrealize();
void OnSizeAllocate(GtkAllocation* aAllocation);
void OnDeleteEvent();