From 7253ac501d447272d4e824b7ac56942908cc3f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 10 Jan 2022 17:01:41 +0100 Subject: [PATCH] kms: Make KMS feedback struct ref counted It'll later be sent asynchronously; to prepare for that make it ref counted with an atomic ref counter. Part-of: --- src/backends/native/meta-kms-update-private.h | 2 ++ src/backends/native/meta-kms-update.c | 24 ++++++++++++++----- src/backends/native/meta-kms-update.h | 6 +++-- src/tests/native-kms-device.c | 6 ++--- src/tests/native-kms-updates.c | 4 ++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h index 7a48e3e41..36f7ef552 100644 --- a/src/backends/native/meta-kms-update-private.h +++ b/src/backends/native/meta-kms-update-private.h @@ -40,6 +40,8 @@ typedef struct _MetaKmsCrtcColorUpdate typedef struct _MetaKmsFeedback { + gatomicrefcount ref_count; + MetaKmsFeedbackResult result; GList *failed_planes; diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c index 09e42d3c7..4ad92cfb3 100644 --- a/src/backends/native/meta-kms-update.c +++ b/src/backends/native/meta-kms-update.c @@ -90,6 +90,7 @@ meta_kms_feedback_new_passed (GList *failed_planes) .result = META_KMS_FEEDBACK_PASSED, .failed_planes = failed_planes, }; + g_atomic_ref_count_init (&feedback->ref_count); return feedback; } @@ -106,17 +107,28 @@ meta_kms_feedback_new_failed (GList *failed_planes, .error = error, .failed_planes = failed_planes, }; + g_atomic_ref_count_init (&feedback->ref_count); return feedback; } -void -meta_kms_feedback_free (MetaKmsFeedback *feedback) +MetaKmsFeedback * +meta_kms_feedback_ref (MetaKmsFeedback *feedback) { - g_list_free_full (feedback->failed_planes, - (GDestroyNotify) meta_kms_plane_feedback_free); - g_clear_error (&feedback->error); - g_free (feedback); + g_atomic_ref_count_inc (&feedback->ref_count); + return feedback; +} + +void +meta_kms_feedback_unref (MetaKmsFeedback *feedback) +{ + if (g_atomic_ref_count_dec (&feedback->ref_count)) + { + g_list_free_full (feedback->failed_planes, + (GDestroyNotify) meta_kms_plane_feedback_free); + g_clear_error (&feedback->error); + g_free (feedback); + } } MetaKmsFeedbackResult diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h index 986eab636..0915d0fe1 100644 --- a/src/backends/native/meta-kms-update.h +++ b/src/backends/native/meta-kms-update.h @@ -81,8 +81,10 @@ typedef struct _MetaKmsPlaneFeedback typedef void (* MetaKmsResultListenerFunc) (const MetaKmsFeedback *feedback, gpointer user_data); +MetaKmsFeedback * meta_kms_feedback_ref (MetaKmsFeedback *feedback); + META_EXPORT_TEST -void meta_kms_feedback_free (MetaKmsFeedback *feedback); +void meta_kms_feedback_unref (MetaKmsFeedback *feedback); MetaKmsFeedbackResult meta_kms_feedback_get_result (const MetaKmsFeedback *feedback); @@ -202,7 +204,7 @@ meta_fixed_16_rectangle_to_rectangle (MetaFixed16Rectangle fixed_rect) meta_fixed_16_from_int (_w), \ meta_fixed_16_from_int (_h)) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaKmsFeedback, meta_kms_feedback_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaKmsFeedback, meta_kms_feedback_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaKmsUpdate, meta_kms_update_free) #endif /* META_KMS_UPDATE_H */ diff --git a/src/tests/native-kms-device.c b/src/tests/native-kms-device.c index 3cfcbeb37..6729fab66 100644 --- a/src/tests/native-kms-device.c +++ b/src/tests/native-kms-device.c @@ -284,7 +284,7 @@ meta_test_kms_device_mode_set (void) META_KMS_ASSIGN_PLANE_FLAG_NONE); feedback = meta_kms_device_process_update_sync (device, update, META_KMS_UPDATE_FLAG_NONE); - meta_kms_feedback_free (feedback); + meta_kms_feedback_unref (feedback); meta_kms_update_free (update); g_assert_nonnull (meta_kms_crtc_get_current_state (crtc)); @@ -349,7 +349,7 @@ meta_test_kms_device_power_save (void) META_KMS_ASSIGN_PLANE_FLAG_NONE); feedback = meta_kms_device_process_update_sync (device, update, META_KMS_UPDATE_FLAG_NONE); - meta_kms_feedback_free (feedback); + meta_kms_feedback_unref (feedback); meta_kms_update_free (update); g_assert_true (meta_kms_crtc_is_active (crtc)); @@ -387,7 +387,7 @@ meta_test_kms_device_power_save (void) META_KMS_ASSIGN_PLANE_FLAG_NONE); feedback = meta_kms_device_process_update_sync (device, update, META_KMS_UPDATE_FLAG_NONE); - meta_kms_feedback_free (feedback); + meta_kms_feedback_unref (feedback); meta_kms_update_free (update); g_assert_true (meta_kms_crtc_is_active (crtc)); diff --git a/src/tests/native-kms-updates.c b/src/tests/native-kms-updates.c index f253093dc..dc7a99c95 100644 --- a/src/tests/native-kms-updates.c +++ b/src/tests/native-kms-updates.c @@ -357,7 +357,7 @@ meta_test_kms_update_page_flip (void) feedback = meta_kms_device_process_update_sync (device, update, META_KMS_UPDATE_FLAG_NONE); - meta_kms_feedback_free (feedback); + meta_kms_feedback_unref (feedback); meta_kms_update_free (update); g_main_loop_run (data.loop); @@ -382,7 +382,7 @@ meta_test_kms_update_page_flip (void) feedback = meta_kms_device_process_update_sync (device, update, META_KMS_UPDATE_FLAG_NONE); - meta_kms_feedback_free (feedback); + meta_kms_feedback_unref (feedback); meta_kms_update_free (update); g_main_loop_run (data.loop);