clutter/threads: Remove helper functions

See previous commit

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4077>
This commit is contained in:
Bilal Elmoussaoui 2024-10-12 13:02:07 +02:00
parent d92893b6f3
commit 696dfaa124
24 changed files with 42 additions and 213 deletions

View File

@ -230,10 +230,9 @@ click_action_query_long_press (ClutterClickAction *action)
if (result)
{
g_clear_handle_id (&priv->long_press_id, g_source_remove);
priv->long_press_id =
clutter_threads_add_timeout (timeout,
click_action_emit_long_press,
action);
priv->long_press_id = g_timeout_add (timeout,
click_action_emit_long_press,
action);
}
}

View File

@ -193,7 +193,7 @@ start_secondary_click_timeout (ClutterInputDevice *device)
ClutterSeat *seat = clutter_input_device_get_seat (device);
device->ptr_a11y_data->secondary_click_timer =
clutter_threads_add_timeout (delay, trigger_secondary_click, device);
g_timeout_add (delay, trigger_secondary_click, device);
g_signal_emit_by_name (seat,
"ptr-a11y-timeout-started",
@ -448,7 +448,7 @@ trigger_dwell_gesture (gpointer data)
/* Do not clear the gesture right away, otherwise we'll start another one */
device->ptr_a11y_data->dwell_timer =
clutter_threads_add_timeout (delay, trigger_clear_dwell_gesture, device);
g_timeout_add (delay, trigger_clear_dwell_gesture, device);
g_signal_emit_by_name (seat,
"ptr-a11y-timeout-stopped",
@ -466,7 +466,7 @@ start_dwell_gesture_timeout (ClutterInputDevice *device)
ClutterSeat *seat = clutter_input_device_get_seat (device);
device->ptr_a11y_data->dwell_timer =
clutter_threads_add_timeout (delay, trigger_dwell_gesture, device);
g_timeout_add (delay, trigger_dwell_gesture, device);
device->ptr_a11y_data->dwell_gesture_started = TRUE;
g_signal_emit_by_name (seat,
@ -513,7 +513,7 @@ start_dwell_timeout (ClutterInputDevice *device)
ClutterSeat *seat = clutter_input_device_get_seat (device);
device->ptr_a11y_data->dwell_timer =
clutter_threads_add_timeout (delay, trigger_dwell_click, device);
g_timeout_add (delay, trigger_dwell_click, device);
g_signal_emit_by_name (seat,
"ptr-a11y-timeout-started",
@ -560,7 +560,7 @@ static void
start_dwell_position_timeout (ClutterInputDevice *device)
{
device->ptr_a11y_data->dwell_position_timer =
clutter_threads_add_timeout (100, trigger_dwell_position_timeout, device);
g_timeout_add (100, trigger_dwell_position_timeout, device);
}
static void

View File

@ -43,13 +43,6 @@
#include "cogl/cogl.h"
typedef struct
{
GSourceFunc func;
gpointer data;
} ClutterThreadsDispatch;
G_DEFINE_QUARK (clutter_pipeline_capability, clutter_pipeline_capability)
/* main context */
@ -65,162 +58,6 @@ guint clutter_pick_debug_flags = 0;
*/
int clutter_max_render_time_constant_us = 1000;
static gboolean
_clutter_threads_dispatch (gpointer data)
{
ClutterThreadsDispatch *dispatch = data;
gboolean ret = FALSE;
if (!g_source_is_destroyed (g_main_current_source ()))
ret = dispatch->func (dispatch->data);
return ret;
}
static void
_clutter_threads_dispatch_free (gpointer data)
{
ClutterThreadsDispatch *dispatch = data;
g_free (dispatch);
}
/**
* clutter_threads_add_idle: (skip)
* @func: function to call
* @data: data to pass to the function
*
* Adds a function to be called whenever there are no higher priority
* events pending. If the function returns %FALSE it is automatically
* removed from the list of event sources and will not be called again.
*
* This function can be considered a thread-safe variant of g_idle_add_full():
* it will call @function while holding the Clutter lock. It is logically
* equivalent to the following implementation:
*
* ```c
* static gboolean
* idle_safe_callback (gpointer data)
* {
* SafeClosure *closure = data;
* gboolean res = FALSE;
*
* // the callback does not need to acquire the Clutter
* / lock itself, as it is held by the this proxy handler
* //
* res = closure->callback (closure->data);
*
* return res;
* }
* static gulong
* add_safe_idle (GSourceFunc callback,
* gpointer data)
* {
* SafeClosure *closure = g_new0 (SafeClosure, 1);
*
* closure->callback = callback;
* closure->data = data;
*
* return g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
* idle_safe_callback,
* closure,
* g_free)
* }
* ```
*
* This function should be used by threaded applications to make sure
* that @func is emitted under the Clutter threads lock and invoked
* from the same thread that started the Clutter main loop. For instance,
* it can be used to update the UI using the results from a worker
* thread:
*
* ```c
* static gboolean
* update_ui (gpointer data)
* {
* SomeClosure *closure = data;
*
* // it is safe to call Clutter API from this function because
* / it is invoked from the same thread that started the main
* / loop and under the Clutter thread lock
* //
* clutter_label_set_text (CLUTTER_LABEL (closure->label),
* closure->text);
*
* g_object_unref (closure->label);
* g_free (closure);
*
* return FALSE;
* }
*
* // within another thread //
* closure = g_new0 (SomeClosure, 1);
* // always take a reference on GObject instances //
* closure->label = g_object_ref (my_application->label);
* closure->text = g_strdup (processed_text_to_update_the_label);
*
* clutter_threads_add_idle (update_ui,
* closure);
* ```
*
* Return value: the ID (greater than 0) of the event source.
*/
guint
clutter_threads_add_idle (GSourceFunc func,
gpointer data)
{
ClutterThreadsDispatch *dispatch;
g_return_val_if_fail (func != NULL, 0);
dispatch = g_new0 (ClutterThreadsDispatch, 1);
dispatch->func = func;
dispatch->data = data;
return g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
_clutter_threads_dispatch, dispatch,
_clutter_threads_dispatch_free);
}
/**
* clutter_threads_add_timeout: (skip)
* @interval: the time between calls to the function, in milliseconds
* @func: function to call
* @data: data to pass to the function
*
* Sets a function to be called at regular intervals holding the Clutter
* threads lock, with the given priority. The function is called repeatedly
* until it returns %FALSE, at which point the timeout is automatically
* removed and the function will not be called again. The @notify function
* is called when the timeout is removed.
*
* The first call to the function will be at the end of the first @interval.
*
* It is important to note that, due to how the Clutter main loop is
* implemented, the timing will not be accurate and it will not try to
* "keep up" with the interval.
*
* Return value: the ID (greater than 0) of the event source.
*/
guint
clutter_threads_add_timeout (guint interval,
GSourceFunc func,
gpointer data)
{
ClutterThreadsDispatch *dispatch;
g_return_val_if_fail (func != NULL, 0);
dispatch = g_new0 (ClutterThreadsDispatch, 1);
dispatch->func = func;
dispatch->data = data;
return g_timeout_add_full (G_PRIORITY_DEFAULT,
interval,
_clutter_threads_dispatch, dispatch,
_clutter_threads_dispatch_free);
}
ClutterContext *
_clutter_context_get_default (void)

View File

@ -109,13 +109,6 @@ gboolean clutter_get_accessibility_enabled (void);
/* Threading functions */
CLUTTER_EXPORT
guint clutter_threads_add_idle (GSourceFunc func,
gpointer data);
CLUTTER_EXPORT
guint clutter_threads_add_timeout (guint interval,
GSourceFunc func,
gpointer data);
CLUTTER_EXPORT
guint clutter_threads_add_repaint_func (ClutterRepaintFlags flags,
GSourceFunc func,
gpointer data,

View File

@ -1598,8 +1598,7 @@ _cally_text_insert_text_cb (ClutterText *clutter_text,
* or in an idle handler if it not updated.
*/
if (self->insert_idle_handler == 0)
self->insert_idle_handler = clutter_threads_add_idle (_idle_notify_insert,
self);
self->insert_idle_handler = g_idle_add (_idle_notify_insert, self);
}
/***** atkeditabletext.h ******/

View File

@ -2561,9 +2561,9 @@ clutter_text_key_press (ClutterActor *actor,
priv->password_hint_visible = TRUE;
priv->password_hint_id =
clutter_threads_add_timeout (priv->password_hint_timeout,
clutter_text_remove_password_hint,
self);
g_timeout_add (priv->password_hint_timeout,
clutter_text_remove_password_hint,
self);
}
return CLUTTER_EVENT_STOP;

View File

@ -35,8 +35,7 @@
*
* It is important to note that #ClutterTimeline is not a generic API for
* calling closures after an interval; each Timeline is tied into a frame
* clock used to drive the frame cycle. If you need to schedule a closure
* after an interval, see [func@threads_add_timeout] instead.
* clock used to drive the frame cycle.
*
* Users of #ClutterTimeline should connect to the [signal@Timeline::new-frame]
* signal, which is emitted each time a timeline is advanced during the maste
@ -1259,9 +1258,11 @@ clutter_timeline_start (ClutterTimeline *timeline)
priv->frame_clock);
if (priv->delay)
priv->delay_id = clutter_threads_add_timeout (priv->delay,
delay_timeout_func,
timeline);
{
priv->delay_id = g_timeout_add (priv->delay,
delay_timeout_func,
timeline);
}
else
{
priv->msecs_delta = 0;

View File

@ -480,7 +480,7 @@ meta_input_device_x11_get_pointer_location (ClutterInputDevice *device,
device_xi2->query_status =
meta_input_device_x11_query_pointer_location (device_xi2);
device_xi2->inhibit_pointer_query_timer =
clutter_threads_add_idle (clear_inhibit_pointer_query_cb, device_xi2);
g_idle_add (clear_inhibit_pointer_query_cb, device_xi2);
}
*x = device_xi2->current_x;

View File

@ -665,9 +665,9 @@ meta_stage_x11_handle_event (MetaStageX11 *stage_x11,
g_source_remove);
stage_x11->clipped_redraws_cool_off =
clutter_threads_add_timeout (1000,
clipped_redraws_cool_off_cb,
stage_x11);
g_timeout_add (1000,
clipped_redraws_cool_off_cb,
stage_x11);
/* Queue a relayout - we want glViewport to be called
* with the correct values, and this is done in ClutterStage

View File

@ -203,7 +203,7 @@ actor_pick (void)
clutter_actor_show (state.stage);
clutter_threads_add_idle (on_timeout, &state);
g_idle_add (on_timeout, &state);
clutter_test_main ();

View File

@ -314,7 +314,7 @@ cally_text (void)
data.next = &data1;
clutter_actor_show (data.stage);
clutter_threads_add_idle ((GSourceFunc) do_tests, &data);
g_idle_add ((GSourceFunc) do_tests, &data);
clutter_test_main ();
clutter_actor_destroy (data.stage);

View File

@ -277,7 +277,7 @@ text_cache (void)
clutter_actor_show (data.stage);
clutter_threads_add_idle ((GSourceFunc) do_tests, &data);
g_idle_add ((GSourceFunc) do_tests, &data);
clutter_test_main ();

View File

@ -82,9 +82,9 @@ timeline_rewind (void)
&state);
g_test_message ("Installing a watchdog timeout "
"to determine if this test hangs");
clutter_threads_add_timeout (TEST_WATCHDOG_KICK_IN_SECONDS * 1000,
watchdog_timeout,
&state);
g_timeout_add (TEST_WATCHDOG_KICK_IN_SECONDS * 1000,
watchdog_timeout,
&state);
state.rewind_count = 0;
clutter_actor_show (stage);

View File

@ -176,7 +176,7 @@ delay_cb (gpointer data)
static gboolean
add_timeout_idle (gpointer user_data)
{
clutter_threads_add_timeout (2000, timeout_cb, NULL);
g_timeout_add (2000, timeout_cb, NULL);
return G_SOURCE_REMOVE;
}
@ -295,8 +295,8 @@ timeline_base (void)
clutter_timeline_start (timeline_2);
clutter_timeline_start (timeline_3);
clutter_threads_add_timeout (2000, timeout_cb, NULL);
delay_tag = clutter_threads_add_timeout (99, delay_cb, NULL);
g_timeout_add (2000, timeout_cb, NULL);
delay_tag = g_timeout_add (99, delay_cb, NULL);
clutter_test_main ();

View File

@ -268,7 +268,7 @@ test_cogl_point_sprites_main (int argc, char *argv[])
clutter_actor_show (stage);
clutter_threads_add_idle (idle_cb, stage);
g_idle_add (idle_cb, stage);
clutter_test_main ();

View File

@ -347,9 +347,9 @@ test_cogl_shader_glsl_main (int argc, char *argv[])
g_signal_connect (stage, "delete-event",
G_CALLBACK (destroy_window_cb), NULL);
timeout_id = clutter_threads_add_timeout (1000, timeout_cb, NULL);
timeout_id = g_timeout_add (1000, timeout_cb, NULL);
clutter_threads_add_idle (idle_cb, stage);
g_idle_add (idle_cb, stage);
clutter_actor_show (stage);

View File

@ -142,7 +142,7 @@ main (int argc, char *argv[])
&COGL_COLOR_INIT (255, 255, 255, 255));
/* We want continuous redrawing of the stage... */
clutter_threads_add_idle (queue_redraw, stage);
g_idle_add (queue_redraw, stage);
g_signal_connect (actor, "paint", G_CALLBACK (on_paint), &state);

View File

@ -109,7 +109,7 @@ main (int argc, char **argv)
clutter_actor_show (stage);
clutter_threads_add_idle (queue_redraw, stage);
g_idle_add (queue_redraw, stage);
g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL);

View File

@ -94,7 +94,7 @@ main (int argc, char *argv[])
clutter_actor_show (stage);
clutter_threads_add_idle (on_idle, stage);
g_idle_add (on_idle, stage);
clutter_test_main ();

View File

@ -183,7 +183,7 @@ main (int argc, char *argv[])
clutter_actor_show (stage);
clutter_threads_add_idle (queue_redraw, stage);
g_idle_add (queue_redraw, stage);
clutter_test_main ();

View File

@ -64,7 +64,7 @@ main (int argc, char *argv[])
clutter_actor_set_size (group, STAGE_WIDTH, STAGE_WIDTH);
clutter_actor_add_child (stage, group);
clutter_threads_add_idle (queue_redraw, stage);
g_idle_add (queue_redraw, stage);
g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL);

View File

@ -43,7 +43,7 @@ clutter_perf_fps_start (ClutterStage *stage)
static inline void
clutter_perf_fake_mouse (ClutterStage *stage)
{
clutter_threads_add_timeout (1000/60, perf_fake_mouse_cb, stage);
g_timeout_add (1000/60, perf_fake_mouse_cb, stage);
}
static inline void

View File

@ -102,7 +102,7 @@ main (int argc, char **argv)
clutter_actor_show (stage);
clutter_perf_fps_start (CLUTTER_STAGE (stage));
clutter_threads_add_idle (queue_redraw, stage);
g_idle_add (queue_redraw, stage);
clutter_test_main ();
clutter_perf_fps_report ("test-picking");

View File

@ -157,7 +157,7 @@ main (int argc, char *argv[])
clutter_actor_show (stage);
clutter_perf_fps_start (CLUTTER_STAGE (stage));
clutter_threads_add_idle (queue_redraw, stage);
g_idle_add (queue_redraw, stage);
clutter_test_main ();
clutter_perf_fps_report ("test-text-perf");