From 3b2f95cb1f0c0463de6b372d2aee7753411b2cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 20 Apr 2023 16:32:41 +0200 Subject: [PATCH] kms/update: Add destroy-notify to result listener user data No thread guarantees, users need to handle it themselves. Part-of: --- src/backends/native/meta-cursor-renderer-native.c | 3 ++- src/backends/native/meta-kms-update-private.h | 1 + src/backends/native/meta-kms-update.c | 6 +++++- src/backends/native/meta-kms-update.h | 3 ++- src/backends/native/meta-onscreen-native.c | 9 ++++++--- src/backends/native/meta-renderer-native.c | 1 + src/tests/native-kms-render.c | 3 ++- src/tests/native-kms-updates.c | 6 ++++-- 8 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/backends/native/meta-cursor-renderer-native.c b/src/backends/native/meta-cursor-renderer-native.c index 8404844dc..b8cba20b3 100644 --- a/src/backends/native/meta-cursor-renderer-native.c +++ b/src/backends/native/meta-cursor-renderer-native.c @@ -367,7 +367,8 @@ assign_cursor_plane (MetaCursorRendererNative *native, meta_kms_update_add_result_listener (kms_update, &kms_update_listener_vtable, NULL, - native); + native, + NULL); crtc_cursor_data->buffer = buffer; diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h index 6e723fd83..e740fe664 100644 --- a/src/backends/native/meta-kms-update-private.h +++ b/src/backends/native/meta-kms-update-private.h @@ -131,6 +131,7 @@ struct _MetaKmsResultListener GMainContext *main_context; const MetaKmsResultListenerVtable *vtable; gpointer user_data; + GDestroyNotify destroy_notify; MetaKmsFeedback *feedback; }; diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c index f0e3eda8b..33968ee83 100644 --- a/src/backends/native/meta-kms-update.c +++ b/src/backends/native/meta-kms-update.c @@ -624,7 +624,8 @@ void meta_kms_update_add_result_listener (MetaKmsUpdate *update, const MetaKmsResultListenerVtable *vtable, GMainContext *main_context, - gpointer user_data) + gpointer user_data, + GDestroyNotify destroy_notify) { MetaKmsResultListener *listener; @@ -633,6 +634,7 @@ meta_kms_update_add_result_listener (MetaKmsUpdate *update, .main_context = main_context, .vtable = vtable, .user_data = user_data, + .destroy_notify = destroy_notify, }; update->result_listeners = g_list_append (update->result_listeners, @@ -672,6 +674,8 @@ meta_kms_result_listener_notify (MetaKmsResultListener *listener) void meta_kms_result_listener_free (MetaKmsResultListener *listener) { + if (listener->destroy_notify) + listener->destroy_notify (listener->user_data); g_clear_pointer (&listener->feedback, meta_kms_feedback_unref); g_free (listener); } diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h index 10db07b7d..b71f60a13 100644 --- a/src/backends/native/meta-kms-update.h +++ b/src/backends/native/meta-kms-update.h @@ -197,7 +197,8 @@ META_EXPORT_TEST void meta_kms_update_add_result_listener (MetaKmsUpdate *update, const MetaKmsResultListenerVtable *vtable, GMainContext *main_context, - gpointer user_data); + gpointer user_data, + GDestroyNotify destroy_notify); META_EXPORT_TEST void meta_kms_update_merge_from (MetaKmsUpdate *update, diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c index b85a8e474..3144862d2 100644 --- a/src/backends/native/meta-onscreen-native.c +++ b/src/backends/native/meta-onscreen-native.c @@ -1170,7 +1170,8 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen, meta_kms_update_add_result_listener (kms_update, &swap_buffer_result_listener_vtable, NULL, - onscreen_native); + onscreen_native, + NULL); ensure_crtc_modes (onscreen, kms_update); meta_onscreen_native_flip_crtc (onscreen, @@ -1391,7 +1392,8 @@ meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen, meta_kms_update_add_result_listener (kms_update, &scanout_result_listener_vtable, NULL, - onscreen_native); + onscreen_native, + NULL); meta_onscreen_native_flip_crtc (onscreen, onscreen_native->view, @@ -1570,7 +1572,8 @@ meta_onscreen_native_finish_frame (CoglOnscreen *onscreen, meta_kms_update_add_result_listener (kms_update, &finish_frame_result_listener_vtable, NULL, - onscreen_native); + onscreen_native, + NULL); meta_kms_update_add_page_flip_listener (kms_update, kms_crtc, diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index fd37d00b5..ef7369075 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -876,6 +876,7 @@ post_mode_set_updates (MetaRendererNative *renderer_native) meta_kms_update_add_result_listener (kms_update, &mode_sets_result_listener_vtable, NULL, + NULL, NULL); feedback = diff --git a/src/tests/native-kms-render.c b/src/tests/native-kms-render.c index 76010c131..8a6a45c52 100644 --- a/src/tests/native-kms-render.c +++ b/src/tests/native-kms-render.c @@ -382,7 +382,8 @@ on_scanout_fallback_before_paint (ClutterStage *stage, meta_kms_update_add_result_listener (kms_update, &scanout_fallback_result_listener_vtable, NULL, - test); + test, + NULL); test->scanout_fallback.scanout_failed_view = stage_view; } diff --git a/src/tests/native-kms-updates.c b/src/tests/native-kms-updates.c index 5c779f507..8240f8d96 100644 --- a/src/tests/native-kms-updates.c +++ b/src/tests/native-kms-updates.c @@ -830,11 +830,13 @@ meta_test_kms_update_feedback (void) meta_kms_update_add_result_listener (update, &main_thread_result_listener_vtable, NULL, - &data); + &data, + NULL); meta_kms_update_add_result_listener (update, &callback_thread_result_listener_vtable, data.thread_main_context, - &data); + &data, + NULL); meta_kms_device_post_update (device, update, META_KMS_UPDATE_FLAG_NONE);