From 24c338cc0ee52b9dd235cf1c42b69c30bcb4e188 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Mon, 15 Jul 2024 23:09:36 +0200 Subject: [PATCH] cogl: Simplify poll_renderer_get_info As the only info we can pass now is whether we have any idle closures. Removes the timeout handling which is now is always set to either 0 or -1 based on whether we have idle closures Part-of: --- cogl/cogl/cogl-glib-source.c | 11 +++-------- cogl/cogl/cogl-glib-source.h | 12 ++---------- cogl/cogl/cogl-poll.c | 13 ++++--------- cogl/cogl/cogl-poll.h | 24 +++--------------------- 4 files changed, 12 insertions(+), 48 deletions(-) diff --git a/cogl/cogl/cogl-glib-source.c b/cogl/cogl/cogl-glib-source.c index 0631f75ac..fc87dc0c6 100644 --- a/cogl/cogl/cogl-glib-source.c +++ b/cogl/cogl/cogl-glib-source.c @@ -46,12 +46,8 @@ static gboolean cogl_glib_source_prepare (GSource *source, int *timeout) { CoglGLibSource *cogl_source = (CoglGLibSource *) source; - int64_t cogl_timeout; - cogl_poll_renderer_get_info (cogl_source->renderer, - &cogl_timeout); - - if (cogl_timeout == -1) + if (!cogl_poll_renderer_has_idle_closures (cogl_source->renderer)) { *timeout = -1; cogl_source->expiration_time = -1; @@ -59,9 +55,8 @@ cogl_glib_source_prepare (GSource *source, int *timeout) else { /* Round up to ensure that we don't try again too early */ - *timeout = (cogl_timeout + 999) / 1000; - cogl_source->expiration_time = (g_source_get_time (source) + - cogl_timeout); + *timeout = 999 / 1000; + cogl_source->expiration_time = g_source_get_time (source); } return *timeout == 0; diff --git a/cogl/cogl/cogl-glib-source.h b/cogl/cogl/cogl-glib-source.h index 01a0c2e1d..27b301f53 100644 --- a/cogl/cogl/cogl-glib-source.h +++ b/cogl/cogl/cogl-glib-source.h @@ -46,11 +46,7 @@ G_BEGIN_DECLS * @priority: The priority of the #GSource * * Creates a #GSource which handles Cogl's internal system event - * processing. This can be used as a convenience instead of - * cogl_poll_renderer_get_info() and cogl_poll_renderer_dispatch() in - * applications that are already using the GLib main loop. After this - * is called the #GSource should be attached to the main loop using - * g_source_attach(). + * processing. * * Applications that manually connect to a #CoglRenderer before they * create a #CoglContext should instead use @@ -74,11 +70,7 @@ cogl_glib_source_new (CoglContext *context, * @priority: The priority of the #GSource * * Creates a #GSource which handles Cogl's internal system event - * processing. This can be used as a convenience instead of - * cogl_poll_renderer_get_info() and cogl_poll_renderer_dispatch() in - * applications that are already using the GLib main loop. After this - * is called the #GSource should be attached to the main loop using - * g_source_attach(). + * processing * * Return value: a new #GSource */ diff --git a/cogl/cogl/cogl-poll.c b/cogl/cogl/cogl-poll.c index a3033f4ae..48eb11456 100644 --- a/cogl/cogl/cogl-poll.c +++ b/cogl/cogl/cogl-poll.c @@ -37,17 +37,12 @@ #include "cogl/cogl-renderer-private.h" #include "cogl/winsys/cogl-winsys-private.h" -void -cogl_poll_renderer_get_info (CoglRenderer *renderer, - int64_t *timeout) +gboolean +cogl_poll_renderer_has_idle_closures (CoglRenderer *renderer) { - g_return_if_fail (COGL_IS_RENDERER (renderer)); - g_return_if_fail (timeout != NULL); + g_return_val_if_fail (COGL_IS_RENDERER (renderer), FALSE); - *timeout = -1; - - if (!_cogl_list_empty (&renderer->idle_closures)) - *timeout = 0; + return !_cogl_list_empty (&renderer->idle_closures); } void diff --git a/cogl/cogl/cogl-poll.h b/cogl/cogl/cogl-poll.h index e28f55778..47a0cb6a3 100644 --- a/cogl/cogl/cogl-poll.h +++ b/cogl/cogl/cogl-poll.h @@ -65,29 +65,11 @@ G_BEGIN_DECLS /** - * cogl_poll_renderer_get_info: + * cogl_poll_renderer_has_idle_closures: * @renderer: A #CoglRenderer - * @timeout: A return location for the maximum length of time to wait - * in microseconds, or -1 to wait indefinitely. - * - * Is used to integrate Cogl with an application mainloop that is based - * on the unix poll(2) api (or select() or something equivalent). This - * api should be called whenever an application is about to go idle so - * that Cogl has a chance to describe what file descriptor events it - * needs to be woken up for. - * - * If your application is using the Glib mainloop then you - * should jump to the cogl_glib_source_new() api as a more convenient - * way of integrating Cogl with the mainloop. - * - * @timeout will contain a maximum amount of time to wait in - * microseconds before the application should wake up or -1 if the - * application should wait indefinitely. This can also be 0 if - * Cogl needs to be woken up immediately. */ -COGL_EXPORT void -cogl_poll_renderer_get_info (CoglRenderer *renderer, - int64_t *timeout); +COGL_EXPORT gboolean +cogl_poll_renderer_has_idle_closures (CoglRenderer *renderer); /** * cogl_poll_renderer_dispatch: