From 17a78303d0fe1b157a99e6be914de00923a3e68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 21 Dec 2022 18:17:33 +0100 Subject: [PATCH] kms: Make result listener take a vtable too As with the page flip listener, prepare to make result listeners more capable by allowing more vfuncs for the same listener instance in the future. Part-of: --- .../native/meta-cursor-renderer-native.c | 14 +++++---- src/backends/native/meta-kms-update-private.h | 2 +- src/backends/native/meta-kms-update.c | 13 ++++---- src/backends/native/meta-kms-update.h | 15 ++++++---- src/backends/native/meta-onscreen-native.c | 30 +++++++++++++------ src/backends/native/meta-renderer-native.c | 10 +++++-- src/tests/native-kms-render.c | 11 +++++-- src/tests/native-kms-updates.c | 26 +++++++++++----- 8 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/backends/native/meta-cursor-renderer-native.c b/src/backends/native/meta-cursor-renderer-native.c index f9dcee470..8404844dc 100644 --- a/src/backends/native/meta-cursor-renderer-native.c +++ b/src/backends/native/meta-cursor-renderer-native.c @@ -136,8 +136,8 @@ static GQuark quark_cursor_renderer_native_gpu_data = 0; G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRendererNative, meta_cursor_renderer_native, META_TYPE_CURSOR_RENDERER); static void -on_kms_update_result (const MetaKmsFeedback *kms_feedback, - gpointer user_data); +kms_update_feedback_result (const MetaKmsFeedback *kms_feedback, + gpointer user_data); static void realize_cursor_sprite (MetaCursorRenderer *renderer, @@ -281,6 +281,10 @@ ensure_crtc_cursor_data (MetaCrtcKms *crtc_kms) return crtc_cursor_data; } +static const MetaKmsResultListenerVtable kms_update_listener_vtable = { + .feedback = kms_update_feedback_result, +}; + static void assign_cursor_plane (MetaCursorRendererNative *native, ClutterFrame *frame, @@ -361,8 +365,8 @@ assign_cursor_plane (MetaCursorRendererNative *native, cursor_hotspot_y); meta_kms_update_add_result_listener (kms_update, + &kms_update_listener_vtable, NULL, - on_kms_update_result, native); crtc_cursor_data->buffer = buffer; @@ -1019,8 +1023,8 @@ calculate_cursor_sprite_gpus (MetaCursorRenderer *renderer, } static void -on_kms_update_result (const MetaKmsFeedback *kms_feedback, - gpointer user_data) +kms_update_feedback_result (const MetaKmsFeedback *kms_feedback, + gpointer user_data) { MetaCursorRendererNative *cursor_renderer_native = user_data; MetaCursorRenderer *cursor_renderer = diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h index fb3bde21d..8d7571343 100644 --- a/src/backends/native/meta-kms-update-private.h +++ b/src/backends/native/meta-kms-update-private.h @@ -129,7 +129,7 @@ typedef struct _MetaKmsPageFlipListener struct _MetaKmsResultListener { GMainContext *main_context; - MetaKmsResultListenerFunc func; + const MetaKmsResultListenerVtable *vtable; gpointer user_data; MetaKmsFeedback *feedback; diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c index 3145538cb..1d88a09e2 100644 --- a/src/backends/native/meta-kms-update.c +++ b/src/backends/native/meta-kms-update.c @@ -596,17 +596,17 @@ meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane_assi } void -meta_kms_update_add_result_listener (MetaKmsUpdate *update, - GMainContext *main_context, - MetaKmsResultListenerFunc func, - gpointer user_data) +meta_kms_update_add_result_listener (MetaKmsUpdate *update, + const MetaKmsResultListenerVtable *vtable, + GMainContext *main_context, + gpointer user_data) { MetaKmsResultListener *listener; listener = g_new0 (MetaKmsResultListener, 1); *listener = (MetaKmsResultListener) { .main_context = main_context, - .func = func, + .vtable = vtable, .user_data = user_data, }; @@ -640,7 +640,8 @@ meta_kms_result_listener_notify (MetaKmsResultListener *listener) { g_return_if_fail (listener->feedback); - listener->func (listener->feedback, listener->user_data); + if (listener->vtable->feedback) + listener->vtable->feedback (listener->feedback, listener->user_data); } void diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h index f98bcceaf..64ec925e4 100644 --- a/src/backends/native/meta-kms-update.h +++ b/src/backends/native/meta-kms-update.h @@ -78,8 +78,11 @@ typedef struct _MetaKmsPlaneFeedback GError *error; } MetaKmsPlaneFeedback; -typedef void (* MetaKmsResultListenerFunc) (const MetaKmsFeedback *feedback, - gpointer user_data); +typedef struct _MetaKmsResultListenerVtable +{ + void (* feedback) (const MetaKmsFeedback *feedback, + gpointer user_data); +} MetaKmsResultListenerVtable; MetaKmsFeedback * meta_kms_feedback_ref (MetaKmsFeedback *feedback); @@ -183,10 +186,10 @@ void meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane int y); META_EXPORT_TEST -void meta_kms_update_add_result_listener (MetaKmsUpdate *update, - GMainContext *main_context, - MetaKmsResultListenerFunc func, - gpointer user_data); +void meta_kms_update_add_result_listener (MetaKmsUpdate *update, + const MetaKmsResultListenerVtable *vtable, + GMainContext *main_context, + gpointer user_data); 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 4dd733858..c0db897aa 100644 --- a/src/backends/native/meta-onscreen-native.c +++ b/src/backends/native/meta-onscreen-native.c @@ -1017,8 +1017,8 @@ ensure_crtc_modes (CoglOnscreen *onscreen, } static void -on_swap_buffer_update_result (const MetaKmsFeedback *kms_feedback, - gpointer user_data) +swap_buffer_result_feedback (const MetaKmsFeedback *kms_feedback, + gpointer user_data) { CoglOnscreen *onscreen = COGL_ONSCREEN (user_data); const GError *error; @@ -1045,6 +1045,10 @@ on_swap_buffer_update_result (const MetaKmsFeedback *kms_feedback, meta_onscreen_native_clear_next_fb (onscreen); } +static const MetaKmsResultListenerVtable swap_buffer_result_listener_vtable = { + .feedback = swap_buffer_result_feedback, +}; + static void meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen, const int *rectangles, @@ -1170,8 +1174,8 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen, kms_update = meta_frame_native_ensure_kms_update (frame_native, kms_device); meta_kms_update_add_result_listener (kms_update, + &swap_buffer_result_listener_vtable, NULL, - on_swap_buffer_update_result, onscreen_native); ensure_crtc_modes (onscreen, kms_update); @@ -1294,8 +1298,8 @@ meta_onscreen_native_is_buffer_scanout_compatible (CoglOnscreen *onscreen, } static void -on_scanout_update_result (const MetaKmsFeedback *kms_feedback, - gpointer user_data) +scanout_result_feedback (const MetaKmsFeedback *kms_feedback, + gpointer user_data) { MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (user_data); CoglOnscreen *onscreen = COGL_ONSCREEN (onscreen_native); @@ -1327,6 +1331,10 @@ on_scanout_update_result (const MetaKmsFeedback *kms_feedback, meta_onscreen_native_clear_next_fb (onscreen); } +static const MetaKmsResultListenerVtable scanout_result_listener_vtable = { + .feedback = scanout_result_feedback, +}; + static gboolean meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen, CoglScanout *scanout, @@ -1387,8 +1395,8 @@ meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen, kms_update = meta_frame_native_ensure_kms_update (frame_native, kms_device); meta_kms_update_add_result_listener (kms_update, + &scanout_result_listener_vtable, NULL, - on_scanout_update_result, onscreen_native); meta_onscreen_native_flip_crtc (onscreen, @@ -1498,8 +1506,8 @@ meta_onscreen_native_prepare_frame (CoglOnscreen *onscreen, } static void -on_finish_frame_update_result (const MetaKmsFeedback *kms_feedback, - gpointer user_data) +finish_frame_result_feedback (const MetaKmsFeedback *kms_feedback, + gpointer user_data) { CoglOnscreen *onscreen = COGL_ONSCREEN (user_data); const GError *error; @@ -1520,6 +1528,10 @@ on_finish_frame_update_result (const MetaKmsFeedback *kms_feedback, meta_onscreen_native_notify_frame_complete (onscreen); } +static const MetaKmsResultListenerVtable finish_frame_result_listener_vtable = { + .feedback = finish_frame_result_feedback, +}; + void meta_onscreen_native_finish_frame (CoglOnscreen *onscreen, ClutterFrame *frame) @@ -1539,8 +1551,8 @@ meta_onscreen_native_finish_frame (CoglOnscreen *onscreen, } meta_kms_update_add_result_listener (kms_update, + &finish_frame_result_listener_vtable, NULL, - on_finish_frame_update_result, onscreen_native); meta_kms_update_add_page_flip_listener (kms_update, diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 10fb7bbba..a2cb6329a 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -836,8 +836,8 @@ clear_detached_onscreens (MetaRendererNative *renderer_native) } static void -on_mode_sets_update_result (const MetaKmsFeedback *kms_feedback, - gpointer user_data) +mode_sets_update_result_feedback (const MetaKmsFeedback *kms_feedback, + gpointer user_data) { const GError *feedback_error; @@ -849,6 +849,10 @@ on_mode_sets_update_result (const MetaKmsFeedback *kms_feedback, g_warning ("Failed to post KMS update: %s", feedback_error->message); } +static const MetaKmsResultListenerVtable mode_sets_result_listener_vtable = { + .feedback = mode_sets_update_result_feedback, +}; + static void post_mode_set_updates (MetaRendererNative *renderer_native) { @@ -865,8 +869,8 @@ post_mode_set_updates (MetaRendererNative *renderer_native) g_hash_table_iter_steal (&iter); meta_kms_update_add_result_listener (kms_update, + &mode_sets_result_listener_vtable, NULL, - on_mode_sets_update_result, NULL); feedback = meta_kms_device_process_update_sync (kms_device, kms_update, diff --git a/src/tests/native-kms-render.c b/src/tests/native-kms-render.c index b19035237..76010c131 100644 --- a/src/tests/native-kms-render.c +++ b/src/tests/native-kms-render.c @@ -330,8 +330,8 @@ needs_repainted_guard (gpointer user_data) } static void -on_scanout_fallback_result (const MetaKmsFeedback *kms_feedback, - gpointer user_data) +scanout_fallback_result_feedback (const MetaKmsFeedback *kms_feedback, + gpointer user_data) { KmsRenderingTest *test = user_data; @@ -342,6 +342,10 @@ on_scanout_fallback_result (const MetaKmsFeedback *kms_feedback, g_idle_add_full (G_PRIORITY_LOW, needs_repainted_guard, test, NULL); } +static const MetaKmsResultListenerVtable scanout_fallback_result_listener_vtable = { + .feedback = scanout_fallback_result_feedback, +}; + static void on_scanout_fallback_before_paint (ClutterStage *stage, ClutterStageView *stage_view, @@ -376,8 +380,9 @@ on_scanout_fallback_before_paint (ClutterStage *stage, kms_update = meta_frame_native_ensure_kms_update (frame_native, kms_device); meta_kms_update_add_result_listener (kms_update, + &scanout_fallback_result_listener_vtable, NULL, - on_scanout_fallback_result, test); + test); 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 d085e713d..5c779f507 100644 --- a/src/tests/native-kms-updates.c +++ b/src/tests/native-kms-updates.c @@ -777,23 +777,31 @@ off_thread_callback_thread_func (gpointer user_data) } static void -on_main_thread_result (const MetaKmsFeedback *feedback, - gpointer user_data) +main_thread_result_feedback (const MetaKmsFeedback *feedback, + gpointer user_data) { CallbackData *data = user_data; g_main_loop_quit (data->main_thread_loop); } +static const MetaKmsResultListenerVtable main_thread_result_listener_vtable = { + .feedback = main_thread_result_feedback, +}; + static void -on_callback_thread_result (const MetaKmsFeedback *feedback, - gpointer user_data) +callback_thread_result_feedback (const MetaKmsFeedback *feedback, + gpointer user_data) { CallbackData *data = user_data; g_main_loop_quit (data->thread_loop); } +static const MetaKmsResultListenerVtable callback_thread_result_listener_vtable = { + .feedback = callback_thread_result_feedback, +}; + static void meta_test_kms_update_feedback (void) { @@ -819,11 +827,13 @@ meta_test_kms_update_feedback (void) update = meta_kms_update_new (device); populate_update (update, &buffer, POPULATE_UPDATE_FLAG_MODE); - meta_kms_update_add_result_listener (update, NULL, - on_main_thread_result, + meta_kms_update_add_result_listener (update, + &main_thread_result_listener_vtable, + NULL, &data); - meta_kms_update_add_result_listener (update, data.thread_main_context, - on_callback_thread_result, + meta_kms_update_add_result_listener (update, + &callback_thread_result_listener_vtable, + data.thread_main_context, &data); meta_kms_device_post_update (device, update,