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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
This commit is contained in:
Jonas Ådahl 2022-12-21 18:17:33 +01:00
parent f97f0f2781
commit 17a78303d0
8 changed files with 80 additions and 41 deletions

View File

@ -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); G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRendererNative, meta_cursor_renderer_native, META_TYPE_CURSOR_RENDERER);
static void static void
on_kms_update_result (const MetaKmsFeedback *kms_feedback, kms_update_feedback_result (const MetaKmsFeedback *kms_feedback,
gpointer user_data); gpointer user_data);
static void static void
realize_cursor_sprite (MetaCursorRenderer *renderer, realize_cursor_sprite (MetaCursorRenderer *renderer,
@ -281,6 +281,10 @@ ensure_crtc_cursor_data (MetaCrtcKms *crtc_kms)
return crtc_cursor_data; return crtc_cursor_data;
} }
static const MetaKmsResultListenerVtable kms_update_listener_vtable = {
.feedback = kms_update_feedback_result,
};
static void static void
assign_cursor_plane (MetaCursorRendererNative *native, assign_cursor_plane (MetaCursorRendererNative *native,
ClutterFrame *frame, ClutterFrame *frame,
@ -361,8 +365,8 @@ assign_cursor_plane (MetaCursorRendererNative *native,
cursor_hotspot_y); cursor_hotspot_y);
meta_kms_update_add_result_listener (kms_update, meta_kms_update_add_result_listener (kms_update,
&kms_update_listener_vtable,
NULL, NULL,
on_kms_update_result,
native); native);
crtc_cursor_data->buffer = buffer; crtc_cursor_data->buffer = buffer;
@ -1019,8 +1023,8 @@ calculate_cursor_sprite_gpus (MetaCursorRenderer *renderer,
} }
static void static void
on_kms_update_result (const MetaKmsFeedback *kms_feedback, kms_update_feedback_result (const MetaKmsFeedback *kms_feedback,
gpointer user_data) gpointer user_data)
{ {
MetaCursorRendererNative *cursor_renderer_native = user_data; MetaCursorRendererNative *cursor_renderer_native = user_data;
MetaCursorRenderer *cursor_renderer = MetaCursorRenderer *cursor_renderer =

View File

@ -129,7 +129,7 @@ typedef struct _MetaKmsPageFlipListener
struct _MetaKmsResultListener struct _MetaKmsResultListener
{ {
GMainContext *main_context; GMainContext *main_context;
MetaKmsResultListenerFunc func; const MetaKmsResultListenerVtable *vtable;
gpointer user_data; gpointer user_data;
MetaKmsFeedback *feedback; MetaKmsFeedback *feedback;

View File

@ -596,17 +596,17 @@ meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane_assi
} }
void void
meta_kms_update_add_result_listener (MetaKmsUpdate *update, meta_kms_update_add_result_listener (MetaKmsUpdate *update,
GMainContext *main_context, const MetaKmsResultListenerVtable *vtable,
MetaKmsResultListenerFunc func, GMainContext *main_context,
gpointer user_data) gpointer user_data)
{ {
MetaKmsResultListener *listener; MetaKmsResultListener *listener;
listener = g_new0 (MetaKmsResultListener, 1); listener = g_new0 (MetaKmsResultListener, 1);
*listener = (MetaKmsResultListener) { *listener = (MetaKmsResultListener) {
.main_context = main_context, .main_context = main_context,
.func = func, .vtable = vtable,
.user_data = user_data, .user_data = user_data,
}; };
@ -640,7 +640,8 @@ meta_kms_result_listener_notify (MetaKmsResultListener *listener)
{ {
g_return_if_fail (listener->feedback); 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 void

View File

@ -78,8 +78,11 @@ typedef struct _MetaKmsPlaneFeedback
GError *error; GError *error;
} MetaKmsPlaneFeedback; } MetaKmsPlaneFeedback;
typedef void (* MetaKmsResultListenerFunc) (const MetaKmsFeedback *feedback, typedef struct _MetaKmsResultListenerVtable
gpointer user_data); {
void (* feedback) (const MetaKmsFeedback *feedback,
gpointer user_data);
} MetaKmsResultListenerVtable;
MetaKmsFeedback * meta_kms_feedback_ref (MetaKmsFeedback *feedback); MetaKmsFeedback * meta_kms_feedback_ref (MetaKmsFeedback *feedback);
@ -183,10 +186,10 @@ void meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane
int y); int y);
META_EXPORT_TEST META_EXPORT_TEST
void meta_kms_update_add_result_listener (MetaKmsUpdate *update, void meta_kms_update_add_result_listener (MetaKmsUpdate *update,
GMainContext *main_context, const MetaKmsResultListenerVtable *vtable,
MetaKmsResultListenerFunc func, GMainContext *main_context,
gpointer user_data); gpointer user_data);
META_EXPORT_TEST META_EXPORT_TEST
void meta_kms_update_merge_from (MetaKmsUpdate *update, void meta_kms_update_merge_from (MetaKmsUpdate *update,

View File

@ -1017,8 +1017,8 @@ ensure_crtc_modes (CoglOnscreen *onscreen,
} }
static void static void
on_swap_buffer_update_result (const MetaKmsFeedback *kms_feedback, swap_buffer_result_feedback (const MetaKmsFeedback *kms_feedback,
gpointer user_data) gpointer user_data)
{ {
CoglOnscreen *onscreen = COGL_ONSCREEN (user_data); CoglOnscreen *onscreen = COGL_ONSCREEN (user_data);
const GError *error; const GError *error;
@ -1045,6 +1045,10 @@ on_swap_buffer_update_result (const MetaKmsFeedback *kms_feedback,
meta_onscreen_native_clear_next_fb (onscreen); meta_onscreen_native_clear_next_fb (onscreen);
} }
static const MetaKmsResultListenerVtable swap_buffer_result_listener_vtable = {
.feedback = swap_buffer_result_feedback,
};
static void static void
meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen, meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles, 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_update = meta_frame_native_ensure_kms_update (frame_native,
kms_device); kms_device);
meta_kms_update_add_result_listener (kms_update, meta_kms_update_add_result_listener (kms_update,
&swap_buffer_result_listener_vtable,
NULL, NULL,
on_swap_buffer_update_result,
onscreen_native); onscreen_native);
ensure_crtc_modes (onscreen, kms_update); ensure_crtc_modes (onscreen, kms_update);
@ -1294,8 +1298,8 @@ meta_onscreen_native_is_buffer_scanout_compatible (CoglOnscreen *onscreen,
} }
static void static void
on_scanout_update_result (const MetaKmsFeedback *kms_feedback, scanout_result_feedback (const MetaKmsFeedback *kms_feedback,
gpointer user_data) gpointer user_data)
{ {
MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (user_data); MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (user_data);
CoglOnscreen *onscreen = COGL_ONSCREEN (onscreen_native); 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); meta_onscreen_native_clear_next_fb (onscreen);
} }
static const MetaKmsResultListenerVtable scanout_result_listener_vtable = {
.feedback = scanout_result_feedback,
};
static gboolean static gboolean
meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen, meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen,
CoglScanout *scanout, 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); kms_update = meta_frame_native_ensure_kms_update (frame_native, kms_device);
meta_kms_update_add_result_listener (kms_update, meta_kms_update_add_result_listener (kms_update,
&scanout_result_listener_vtable,
NULL, NULL,
on_scanout_update_result,
onscreen_native); onscreen_native);
meta_onscreen_native_flip_crtc (onscreen, meta_onscreen_native_flip_crtc (onscreen,
@ -1498,8 +1506,8 @@ meta_onscreen_native_prepare_frame (CoglOnscreen *onscreen,
} }
static void static void
on_finish_frame_update_result (const MetaKmsFeedback *kms_feedback, finish_frame_result_feedback (const MetaKmsFeedback *kms_feedback,
gpointer user_data) gpointer user_data)
{ {
CoglOnscreen *onscreen = COGL_ONSCREEN (user_data); CoglOnscreen *onscreen = COGL_ONSCREEN (user_data);
const GError *error; const GError *error;
@ -1520,6 +1528,10 @@ on_finish_frame_update_result (const MetaKmsFeedback *kms_feedback,
meta_onscreen_native_notify_frame_complete (onscreen); meta_onscreen_native_notify_frame_complete (onscreen);
} }
static const MetaKmsResultListenerVtable finish_frame_result_listener_vtable = {
.feedback = finish_frame_result_feedback,
};
void void
meta_onscreen_native_finish_frame (CoglOnscreen *onscreen, meta_onscreen_native_finish_frame (CoglOnscreen *onscreen,
ClutterFrame *frame) ClutterFrame *frame)
@ -1539,8 +1551,8 @@ meta_onscreen_native_finish_frame (CoglOnscreen *onscreen,
} }
meta_kms_update_add_result_listener (kms_update, meta_kms_update_add_result_listener (kms_update,
&finish_frame_result_listener_vtable,
NULL, NULL,
on_finish_frame_update_result,
onscreen_native); onscreen_native);
meta_kms_update_add_page_flip_listener (kms_update, meta_kms_update_add_page_flip_listener (kms_update,

View File

@ -836,8 +836,8 @@ clear_detached_onscreens (MetaRendererNative *renderer_native)
} }
static void static void
on_mode_sets_update_result (const MetaKmsFeedback *kms_feedback, mode_sets_update_result_feedback (const MetaKmsFeedback *kms_feedback,
gpointer user_data) gpointer user_data)
{ {
const GError *feedback_error; 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); 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 static void
post_mode_set_updates (MetaRendererNative *renderer_native) post_mode_set_updates (MetaRendererNative *renderer_native)
{ {
@ -865,8 +869,8 @@ post_mode_set_updates (MetaRendererNative *renderer_native)
g_hash_table_iter_steal (&iter); g_hash_table_iter_steal (&iter);
meta_kms_update_add_result_listener (kms_update, meta_kms_update_add_result_listener (kms_update,
&mode_sets_result_listener_vtable,
NULL, NULL,
on_mode_sets_update_result,
NULL); NULL);
feedback = meta_kms_device_process_update_sync (kms_device, kms_update, feedback = meta_kms_device_process_update_sync (kms_device, kms_update,

View File

@ -330,8 +330,8 @@ needs_repainted_guard (gpointer user_data)
} }
static void static void
on_scanout_fallback_result (const MetaKmsFeedback *kms_feedback, scanout_fallback_result_feedback (const MetaKmsFeedback *kms_feedback,
gpointer user_data) gpointer user_data)
{ {
KmsRenderingTest *test = 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); 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 static void
on_scanout_fallback_before_paint (ClutterStage *stage, on_scanout_fallback_before_paint (ClutterStage *stage,
ClutterStageView *stage_view, 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); kms_update = meta_frame_native_ensure_kms_update (frame_native, kms_device);
meta_kms_update_add_result_listener (kms_update, meta_kms_update_add_result_listener (kms_update,
&scanout_fallback_result_listener_vtable,
NULL, NULL,
on_scanout_fallback_result, test); test);
test->scanout_fallback.scanout_failed_view = stage_view; test->scanout_fallback.scanout_failed_view = stage_view;
} }

View File

@ -777,23 +777,31 @@ off_thread_callback_thread_func (gpointer user_data)
} }
static void static void
on_main_thread_result (const MetaKmsFeedback *feedback, main_thread_result_feedback (const MetaKmsFeedback *feedback,
gpointer user_data) gpointer user_data)
{ {
CallbackData *data = user_data; CallbackData *data = user_data;
g_main_loop_quit (data->main_thread_loop); g_main_loop_quit (data->main_thread_loop);
} }
static const MetaKmsResultListenerVtable main_thread_result_listener_vtable = {
.feedback = main_thread_result_feedback,
};
static void static void
on_callback_thread_result (const MetaKmsFeedback *feedback, callback_thread_result_feedback (const MetaKmsFeedback *feedback,
gpointer user_data) gpointer user_data)
{ {
CallbackData *data = user_data; CallbackData *data = user_data;
g_main_loop_quit (data->thread_loop); g_main_loop_quit (data->thread_loop);
} }
static const MetaKmsResultListenerVtable callback_thread_result_listener_vtable = {
.feedback = callback_thread_result_feedback,
};
static void static void
meta_test_kms_update_feedback (void) meta_test_kms_update_feedback (void)
{ {
@ -819,11 +827,13 @@ meta_test_kms_update_feedback (void)
update = meta_kms_update_new (device); update = meta_kms_update_new (device);
populate_update (update, &buffer, POPULATE_UPDATE_FLAG_MODE); populate_update (update, &buffer, POPULATE_UPDATE_FLAG_MODE);
meta_kms_update_add_result_listener (update, NULL, meta_kms_update_add_result_listener (update,
on_main_thread_result, &main_thread_result_listener_vtable,
NULL,
&data); &data);
meta_kms_update_add_result_listener (update, data.thread_main_context, meta_kms_update_add_result_listener (update,
on_callback_thread_result, &callback_thread_result_listener_vtable,
data.thread_main_context,
&data); &data);
meta_kms_device_post_update (device, update, meta_kms_device_post_update (device, update,