wayland: Destroy pending frame callbacks when destroying a surface

MetaWaylandFrameCallback has been added a surface field, which is then
checked when destroying the surfaces. This prevents unintended callbacks
to run after a surface has been destroyed.

https://bugzilla.gnome.org/show_bug.cgi?id=745163
This commit is contained in:
Carlos Garnacho 2015-02-25 16:26:01 +01:00
parent dd0cb55997
commit d3988c04d6
4 changed files with 28 additions and 0 deletions

View File

@ -37,6 +37,7 @@ typedef struct
{ {
struct wl_list link; struct wl_list link;
struct wl_resource *resource; struct wl_resource *resource;
MetaWaylandSurface *surface;
} MetaWaylandFrameCallback; } MetaWaylandFrameCallback;
typedef struct typedef struct

View File

@ -523,6 +523,7 @@ wl_surface_frame (struct wl_client *client,
return; return;
callback = g_slice_new0 (MetaWaylandFrameCallback); callback = g_slice_new0 (MetaWaylandFrameCallback);
callback->surface = surface;
callback->resource = wl_resource_create (client, &wl_callback_interface, META_WL_CALLBACK_VERSION, callback_id); callback->resource = wl_resource_create (client, &wl_callback_interface, META_WL_CALLBACK_VERSION, callback_id);
wl_resource_set_implementation (callback->resource, NULL, callback, destroy_frame_callback); wl_resource_set_implementation (callback->resource, NULL, callback, destroy_frame_callback);
@ -679,6 +680,8 @@ wl_surface_destructor (struct wl_resource *resource)
g_object_unref (surface->surface_actor); g_object_unref (surface->surface_actor);
meta_wayland_compositor_destroy_frame_callbacks (compositor, surface);
if (surface->resource) if (surface->resource)
wl_resource_set_user_data (surface->resource, NULL); wl_resource_set_user_data (surface->resource, NULL);
g_slice_free (MetaWaylandSurface, surface); g_slice_free (MetaWaylandSurface, surface);
@ -739,6 +742,8 @@ xdg_surface_destructor (struct wl_resource *resource)
{ {
MetaWaylandSurface *surface = wl_resource_get_user_data (resource); MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
meta_wayland_compositor_destroy_frame_callbacks (surface->compositor,
surface);
destroy_window (surface); destroy_window (surface);
surface->xdg_surface = NULL; surface->xdg_surface = NULL;
} }
@ -1006,6 +1011,8 @@ xdg_popup_destructor (struct wl_resource *resource)
{ {
MetaWaylandSurface *surface = wl_resource_get_user_data (resource); MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
meta_wayland_compositor_destroy_frame_callbacks (surface->compositor,
surface);
if (surface->popup.parent) if (surface->popup.parent)
{ {
wl_list_remove (&surface->popup.parent_destroy_listener.link); wl_list_remove (&surface->popup.parent_destroy_listener.link);
@ -1194,6 +1201,8 @@ wl_shell_surface_destructor (struct wl_resource *resource)
{ {
MetaWaylandSurface *surface = wl_resource_get_user_data (resource); MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
meta_wayland_compositor_destroy_frame_callbacks (surface->compositor,
surface);
surface->wl_shell_surface = NULL; surface->wl_shell_surface = NULL;
} }
@ -1593,6 +1602,8 @@ wl_subsurface_destructor (struct wl_resource *resource)
{ {
MetaWaylandSurface *surface = wl_resource_get_user_data (resource); MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
meta_wayland_compositor_destroy_frame_callbacks (surface->compositor,
surface);
if (surface->sub.parent) if (surface->sub.parent)
{ {
wl_list_remove (&surface->sub.parent_destroy_listener.link); wl_list_remove (&surface->sub.parent_destroy_listener.link);

View File

@ -207,6 +207,19 @@ meta_wayland_compositor_handle_event (MetaWaylandCompositor *compositor,
return meta_wayland_seat_handle_event (compositor->seat, event); return meta_wayland_seat_handle_event (compositor->seat, event);
} }
void
meta_wayland_compositor_destroy_frame_callbacks (MetaWaylandCompositor *compositor,
MetaWaylandSurface *surface)
{
MetaWaylandFrameCallback *callback, *next;
wl_list_for_each_safe (callback, next, &compositor->frame_callbacks, link)
{
if (callback->surface == surface)
wl_resource_destroy (callback->resource);
}
}
static void static void
set_gnome_env (const char *name, set_gnome_env (const char *name,
const char *value) const char *value)

View File

@ -46,6 +46,9 @@ void meta_wayland_compositor_set_input_focus (MetaWaylandComp
void meta_wayland_compositor_paint_finished (MetaWaylandCompositor *compositor); void meta_wayland_compositor_paint_finished (MetaWaylandCompositor *compositor);
void meta_wayland_compositor_destroy_frame_callbacks (MetaWaylandCompositor *compositor,
MetaWaylandSurface *surface);
const char *meta_wayland_get_wayland_display_name (MetaWaylandCompositor *compositor); const char *meta_wayland_get_wayland_display_name (MetaWaylandCompositor *compositor);
const char *meta_wayland_get_xwayland_display_name (MetaWaylandCompositor *compositor); const char *meta_wayland_get_xwayland_display_name (MetaWaylandCompositor *compositor);