From f8376a43d37e4a2651d1801d993d58d88c317697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 30 May 2022 23:16:16 +0200 Subject: [PATCH] Always queue MetaLater via compositor instance The "later" API is used to queue actions in relation to compositing, thus is owned by the MetaCompositor instance. Make users of this functionality get MetaLaters instance from the compositor, and stop using the global meta_later() API. display: Use non-singleton MetaLater API tests: Use non-singleton MetaLater API meta/common: Make docs refer to context aware MetaLater API Part-of: --- src/core/display.c | 33 +++++++++++++++++--------- src/meta/common.h | 2 +- src/tests/meta-test-utils.c | 12 ++++++---- src/tests/monitor-unit-tests.c | 11 +++++---- src/tests/test-runner.c | 11 +++++---- src/tests/unit-tests.c | 43 +++++++++++++++++++++------------- 6 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/core/display.c b/src/core/display.c index 73583828e..81267d161 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -1143,7 +1143,8 @@ void meta_display_close (MetaDisplay *display, guint32 timestamp) { - g_assert (display != NULL); + MetaCompositor *compositor; + MetaLaters *laters; if (display->closing != 0) { @@ -1169,10 +1170,12 @@ meta_display_close (MetaDisplay *display, g_clear_handle_id (&display->focus_timeout_id, g_source_remove); g_clear_handle_id (&display->tile_preview_timeout_id, g_source_remove); + compositor = meta_display_get_compositor (display); + laters = meta_compositor_get_laters (compositor); if (display->work_area_later != 0) - meta_later_remove (display->work_area_later); + meta_laters_remove (laters, display->work_area_later); if (display->check_fullscreen_later != 0) - meta_later_remove (display->check_fullscreen_later); + meta_laters_remove (laters, display->check_fullscreen_later); /* Stop caring about events */ meta_display_free_events (display); @@ -3468,13 +3471,15 @@ meta_display_queue_workarea_recalc (MetaDisplay *display) /* Recompute work area later before redrawing */ if (display->work_area_later == 0) { + MetaLaters *laters = meta_compositor_get_laters (display->compositor); + meta_topic (META_DEBUG_WORKAREA, "Adding work area hint computation function"); display->work_area_later = - meta_later_add (META_LATER_BEFORE_REDRAW, - (GSourceFunc) set_work_area_later_func, - display, - NULL); + meta_laters_add (laters, META_LATER_BEFORE_REDRAW, + (GSourceFunc) set_work_area_later_func, + display, + NULL); } } @@ -3589,10 +3594,16 @@ check_fullscreen_func (gpointer data) void meta_display_queue_check_fullscreen (MetaDisplay *display) { - if (!display->check_fullscreen_later) - display->check_fullscreen_later = meta_later_add (META_LATER_CHECK_FULLSCREEN, - check_fullscreen_func, - display, NULL); + MetaLaters *laters; + + if (display->check_fullscreen_later) + return; + + laters = meta_compositor_get_laters (display->compositor); + display->check_fullscreen_later = meta_laters_add (laters, + META_LATER_CHECK_FULLSCREEN, + check_fullscreen_func, + display, NULL); } int diff --git a/src/meta/common.h b/src/meta/common.h index 2c516a70d..edadd74fd 100644 --- a/src/meta/common.h +++ b/src/meta/common.h @@ -462,7 +462,7 @@ void meta_frame_borders_clear (MetaFrameBorders *self); * coalesce multiple things together, the appropriate place to * do it is usually META_PRIORITY_BEFORE_REDRAW. * - * Note that its usually better to use meta_later_add() rather + * Note that its usually better to use meta_laters_add() rather * than calling g_idle_add() directly; this will make sure things * get run when added from a clutter event handler without * waiting for another repaint cycle. diff --git a/src/tests/meta-test-utils.c b/src/tests/meta-test-utils.c index a52f92b77..ebeb95758 100644 --- a/src/tests/meta-test-utils.c +++ b/src/tests/meta-test-utils.c @@ -447,14 +447,18 @@ void meta_test_client_wait_for_window_shown (MetaTestClient *client, MetaWindow *window) { + MetaDisplay *display = meta_window_get_display (window); + MetaCompositor *compositor = meta_display_get_compositor (display); + MetaLaters *laters = meta_compositor_get_laters (compositor); + WaitForShownData data = { .loop = g_main_loop_new (NULL, FALSE), .window = window, }; - meta_later_add (META_LATER_BEFORE_REDRAW, - wait_for_showing_before_redraw, - &data, - NULL); + meta_laters_add (laters, META_LATER_BEFORE_REDRAW, + wait_for_showing_before_redraw, + &data, + NULL); g_main_loop_run (data.loop); g_clear_signal_handler (&data.shown_handler_id, window); g_main_loop_unref (data.loop); diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 91dc52fe4..5c027b968 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -8338,13 +8338,16 @@ quit_main_loop (gpointer data) static void dispatch (void) { + MetaDisplay *display = meta_context_get_display (test_context); + MetaCompositor *compositor = meta_display_get_compositor (display); + MetaLaters *laters = meta_compositor_get_laters (compositor); GMainLoop *loop; loop = g_main_loop_new (NULL, FALSE); - meta_later_add (META_LATER_BEFORE_REDRAW, - quit_main_loop, - loop, - NULL); + meta_laters_add (laters, META_LATER_BEFORE_REDRAW, + quit_main_loop, + loop, + NULL); g_main_loop_run (loop); } diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index 15d0a4b20..ec9e94a3c 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -113,16 +113,19 @@ test_case_dispatch (TestCase *test, { MetaBackend *backend = meta_context_get_backend (test->context); ClutterActor *stage = meta_backend_get_stage (backend); + MetaDisplay *display = meta_context_get_display (test->context); + MetaCompositor *compositor = meta_display_get_compositor (display); + MetaLaters *laters = meta_compositor_get_laters (compositor); /* Wait until we've done any outstanding queued up work. * Though we add this as BEFORE_REDRAW, the iteration that runs the * BEFORE_REDRAW idles will proceed on and do the redraw, so we're * waiting until after *all* frame processing. */ - meta_later_add (META_LATER_BEFORE_REDRAW, - test_case_loop_quit, - test, - NULL); + meta_laters_add (laters, META_LATER_BEFORE_REDRAW, + test_case_loop_quit, + test, + NULL); clutter_stage_schedule_update (CLUTTER_STAGE (stage)); g_main_loop_run (test->loop); diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c index 0fefb8d55..75c65b21f 100644 --- a/src/tests/unit-tests.c +++ b/src/tests/unit-tests.c @@ -28,7 +28,9 @@ #include #include "core/boxes-private.h" +#include "core/display-private.h" #include "meta-test/meta-context-test.h" +#include "meta/compositor.h" #include "meta/meta-context.h" #include "tests/boxes-tests.h" #include "tests/monitor-config-migration-unit-tests.h" @@ -64,6 +66,9 @@ test_later_order_callback (gpointer user_data) static void meta_test_util_later_order (void) { + MetaDisplay *display = meta_context_get_display (test_context); + MetaCompositor *compositor = meta_display_get_compositor (display); + MetaLaters *laters = meta_compositor_get_laters (compositor); GMainLoop *loop; int expected_callback_num; int i; @@ -82,10 +87,10 @@ meta_test_util_later_order (void) .callback_num = i, .expected_callback_num = &expected_callback_num, }; - meta_later_add (META_LATER_BEFORE_REDRAW, - test_later_order_callback, - &callback_data[i], - NULL); + meta_laters_add (laters, META_LATER_BEFORE_REDRAW, + test_later_order_callback, + &callback_data[i], + NULL); } /* Check that the callbacks are invoked in the opposite order that they were @@ -119,13 +124,16 @@ static gboolean test_later_schedule_from_later_calc_showing_callback (gpointer user_data) { MetaTestLaterScheduleFromLaterData *data = user_data; + MetaDisplay *display = meta_context_get_display (test_context); + MetaCompositor *compositor = meta_display_get_compositor (display); + MetaLaters *laters = meta_compositor_get_laters (compositor); g_assert_cmpint (data->state, ==, META_TEST_LATER_EXPECT_CALC_SHOWING); - meta_later_add (META_LATER_SYNC_STACK, - test_later_schedule_from_later_sync_stack_callback, - data, - NULL); + meta_laters_add (laters, META_LATER_SYNC_STACK, + test_later_schedule_from_later_sync_stack_callback, + data, + NULL); data->state = META_TEST_LATER_EXPECT_SYNC_STACK; @@ -160,6 +168,9 @@ static void meta_test_util_later_schedule_from_later (void) { MetaTestLaterScheduleFromLaterData data; + MetaDisplay *display = meta_context_get_display (test_context); + MetaCompositor *compositor = meta_display_get_compositor (display); + MetaLaters *laters = meta_compositor_get_laters (compositor); data.loop = g_main_loop_new (NULL, FALSE); @@ -170,14 +181,14 @@ meta_test_util_later_schedule_from_later (void) * The first and last callback is queued here. The one to be invoked in * between is invoked in test_later_schedule_from_later_calc_showing_callback. */ - meta_later_add (META_LATER_CALC_SHOWING, - test_later_schedule_from_later_calc_showing_callback, - &data, - NULL); - meta_later_add (META_LATER_BEFORE_REDRAW, - test_later_schedule_from_later_before_redraw_callback, - &data, - NULL); + meta_laters_add (laters, META_LATER_CALC_SHOWING, + test_later_schedule_from_later_calc_showing_callback, + &data, + NULL); + meta_laters_add (laters, META_LATER_BEFORE_REDRAW, + test_later_schedule_from_later_before_redraw_callback, + &data, + NULL); data.state = META_TEST_LATER_EXPECT_CALC_SHOWING;