kms/page-flip-listener: Make object reference counted

The _ref() variant will be added later, when it gets a user, to avoid
a unused compiler warning.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2854>
This commit is contained in:
Jonas Ådahl 2022-06-05 21:16:11 +02:00 committed by Marge Bot
parent 7253ac501d
commit dcbe32f39f
2 changed files with 9 additions and 3 deletions

View File

@ -104,6 +104,8 @@ typedef struct _MetaKmsConnectorUpdate
typedef struct _MetaKmsPageFlipListener
{
gatomicrefcount ref_count;
MetaKmsCrtc *crtc;
const MetaKmsPageFlipListenerVtable *vtable;
MetaKmsPageFlipListenerFlag flags;

View File

@ -171,8 +171,11 @@ meta_kms_mode_set_free (MetaKmsModeSet *mode_set)
}
static void
meta_kms_page_flip_listener_free (MetaKmsPageFlipListener *listener)
meta_kms_page_flip_listener_unref (MetaKmsPageFlipListener *listener)
{
if (!g_atomic_ref_count_dec (&listener->ref_count))
return;
g_clear_pointer (&listener->user_data, listener->destroy_notify);
g_free (listener);
}
@ -453,6 +456,7 @@ meta_kms_update_add_page_flip_listener (MetaKmsUpdate *upd
.user_data = user_data,
.destroy_notify = destroy_notify,
};
g_atomic_ref_count_init (&listener->ref_count);
update->page_flip_listeners = g_list_prepend (update->page_flip_listeners,
listener);
@ -471,7 +475,7 @@ meta_kms_update_drop_defunct_page_flip_listeners (MetaKmsUpdate *update)
if (listener->flags & META_KMS_PAGE_FLIP_LISTENER_FLAG_DROP_ON_ERROR)
{
meta_kms_page_flip_listener_free (listener);
meta_kms_page_flip_listener_unref (listener);
update->page_flip_listeners =
g_list_delete_link (update->page_flip_listeners, l);
}
@ -902,7 +906,7 @@ meta_kms_update_free (MetaKmsUpdate *update)
g_list_free_full (update->mode_sets,
(GDestroyNotify) meta_kms_mode_set_free);
g_list_free_full (update->page_flip_listeners,
(GDestroyNotify) meta_kms_page_flip_listener_free);
(GDestroyNotify) meta_kms_page_flip_listener_unref);
g_list_free_full (update->connector_updates, g_free);
g_list_free_full (update->crtc_color_updates,
(GDestroyNotify) meta_kms_crtc_color_updates_free);