2007-06-09 13:20:22 +00:00
|
|
|
/*
|
2007-06-09 13:20:06 +00:00
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2007-06-09 13:20:06 +00:00
|
|
|
*
|
|
|
|
* ClutterTimeoutPool: pool of timeout functions using the same slice of
|
|
|
|
* the GLib main loop
|
|
|
|
*
|
|
|
|
* Author: Emmanuele Bassi <ebassi@openedhand.com>
|
|
|
|
*
|
|
|
|
* Based on similar code by Tristan van Berkom
|
|
|
|
*/
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-06-09 13:19:52 +00:00
|
|
|
#include "config.h"
|
2007-10-12 08:17:00 +00:00
|
|
|
#endif
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2010-11-08 15:52:17 +00:00
|
|
|
#undef CLUTTER_DISABLE_DEPRECATED
|
2007-06-09 13:20:22 +00:00
|
|
|
#include "clutter-timeout-pool.h"
|
2010-11-08 15:52:17 +00:00
|
|
|
|
|
|
|
#include "clutter-debug.h"
|
2009-03-09 17:12:27 +00:00
|
|
|
#include "clutter-timeout-interval.h"
|
2007-06-09 13:19:52 +00:00
|
|
|
|
|
|
|
typedef struct _ClutterTimeout ClutterTimeout;
|
2007-06-14 12:00:31 +00:00
|
|
|
typedef enum {
|
|
|
|
CLUTTER_TIMEOUT_NONE = 0,
|
|
|
|
CLUTTER_TIMEOUT_READY = 1 << 1
|
|
|
|
} ClutterTimeoutFlags;
|
2007-06-09 13:19:52 +00:00
|
|
|
|
|
|
|
struct _ClutterTimeout
|
|
|
|
{
|
|
|
|
guint id;
|
2007-06-14 12:00:31 +00:00
|
|
|
ClutterTimeoutFlags flags;
|
2007-08-12 13:19:31 +00:00
|
|
|
gint refcount;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2009-03-09 17:12:27 +00:00
|
|
|
ClutterTimeoutInterval interval;
|
2007-06-09 13:19:52 +00:00
|
|
|
|
|
|
|
GSourceFunc func;
|
|
|
|
gpointer data;
|
|
|
|
GDestroyNotify notify;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _ClutterTimeoutPool
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
|
|
|
guint next_id;
|
|
|
|
|
2008-04-17 16:50:23 +00:00
|
|
|
GTimeVal start_time;
|
2007-08-12 13:19:31 +00:00
|
|
|
GList *timeouts, *dispatched_timeouts;
|
2007-06-09 13:19:52 +00:00
|
|
|
gint ready;
|
|
|
|
|
|
|
|
guint id;
|
|
|
|
};
|
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
#define TIMEOUT_READY(timeout) (timeout->flags & CLUTTER_TIMEOUT_READY)
|
2007-06-14 12:00:31 +00:00
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
static gboolean clutter_timeout_pool_prepare (GSource *source,
|
|
|
|
gint *next_timeout);
|
|
|
|
static gboolean clutter_timeout_pool_check (GSource *source);
|
|
|
|
static gboolean clutter_timeout_pool_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer data);
|
2007-08-12 13:19:31 +00:00
|
|
|
static void clutter_timeout_pool_finalize (GSource *source);
|
2007-06-09 13:19:52 +00:00
|
|
|
|
|
|
|
static GSourceFuncs clutter_timeout_pool_funcs =
|
|
|
|
{
|
|
|
|
clutter_timeout_pool_prepare,
|
|
|
|
clutter_timeout_pool_check,
|
|
|
|
clutter_timeout_pool_dispatch,
|
|
|
|
clutter_timeout_pool_finalize
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint
|
|
|
|
clutter_timeout_sort (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
const ClutterTimeout *t_a = a;
|
|
|
|
const ClutterTimeout *t_b = b;
|
2007-08-19 17:06:22 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
/* Keep 'ready' timeouts at the front */
|
2007-08-19 17:06:22 +00:00
|
|
|
if (TIMEOUT_READY (t_a))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (TIMEOUT_READY (t_b))
|
|
|
|
return 1;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2009-03-09 17:12:27 +00:00
|
|
|
return _clutter_timeout_interval_compare_expiration (&t_a->interval,
|
|
|
|
&t_b->interval);
|
2007-06-09 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
clutter_timeout_find_by_id (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
const ClutterTimeout *t_a = a;
|
|
|
|
|
|
|
|
return t_a->id == GPOINTER_TO_UINT (b) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2009-03-09 17:12:27 +00:00
|
|
|
static ClutterTimeout *
|
|
|
|
clutter_timeout_new (guint fps)
|
2007-06-09 13:19:52 +00:00
|
|
|
{
|
2009-03-09 17:12:27 +00:00
|
|
|
ClutterTimeout *timeout;
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2009-03-09 17:12:27 +00:00
|
|
|
timeout = g_slice_new0 (ClutterTimeout);
|
|
|
|
_clutter_timeout_interval_init (&timeout->interval, fps);
|
|
|
|
timeout->flags = CLUTTER_TIMEOUT_NONE;
|
|
|
|
timeout->refcount = 1;
|
|
|
|
|
|
|
|
return timeout;
|
2007-06-09 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-04-17 16:50:23 +00:00
|
|
|
clutter_timeout_prepare (ClutterTimeoutPool *pool,
|
|
|
|
ClutterTimeout *timeout,
|
|
|
|
gint *next_timeout)
|
2007-06-09 13:19:52 +00:00
|
|
|
{
|
2009-03-09 17:12:27 +00:00
|
|
|
GTimeVal now;
|
2007-08-08 10:20:14 +00:00
|
|
|
|
2009-03-09 17:12:27 +00:00
|
|
|
g_source_get_current_time (&pool->source, &now);
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2009-03-09 17:12:27 +00:00
|
|
|
return _clutter_timeout_interval_prepare (&now, &timeout->interval,
|
|
|
|
next_timeout);
|
2007-06-09 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
/* ref and unref are always called under the main Clutter lock, so there
|
|
|
|
* is not need for us to use g_atomic_int_* API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ClutterTimeout *
|
|
|
|
clutter_timeout_ref (ClutterTimeout *timeout)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (timeout != NULL, timeout);
|
|
|
|
g_return_val_if_fail (timeout->refcount > 0, timeout);
|
|
|
|
|
|
|
|
timeout->refcount += 1;
|
|
|
|
|
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_timeout_unref (ClutterTimeout *timeout)
|
|
|
|
{
|
|
|
|
g_return_if_fail (timeout != NULL);
|
|
|
|
g_return_if_fail (timeout->refcount > 0);
|
|
|
|
|
|
|
|
timeout->refcount -= 1;
|
|
|
|
|
|
|
|
if (timeout->refcount == 0)
|
|
|
|
{
|
|
|
|
if (timeout->notify)
|
|
|
|
timeout->notify (timeout->data);
|
|
|
|
|
|
|
|
g_slice_free (ClutterTimeout, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
static void
|
|
|
|
clutter_timeout_free (ClutterTimeout *timeout)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (timeout))
|
|
|
|
{
|
|
|
|
if (timeout->notify)
|
|
|
|
timeout->notify (timeout->data);
|
|
|
|
|
|
|
|
g_slice_free (ClutterTimeout, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_timeout_pool_prepare (GSource *source,
|
|
|
|
gint *next_timeout)
|
|
|
|
{
|
|
|
|
ClutterTimeoutPool *pool = (ClutterTimeoutPool *) source;
|
|
|
|
GList *l = pool->timeouts;
|
|
|
|
|
2007-06-14 12:00:31 +00:00
|
|
|
/* the pool is ready if the first timeout is ready */
|
|
|
|
if (l && l->data)
|
2007-06-09 13:19:52 +00:00
|
|
|
{
|
|
|
|
ClutterTimeout *timeout = l->data;
|
2008-04-17 16:50:23 +00:00
|
|
|
return clutter_timeout_prepare (pool, timeout, next_timeout);
|
2007-06-09 13:19:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*next_timeout = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_timeout_pool_check (GSource *source)
|
|
|
|
{
|
|
|
|
ClutterTimeoutPool *pool = (ClutterTimeoutPool *) source;
|
2010-02-11 15:20:25 +00:00
|
|
|
GList *l;
|
2007-06-14 12:00:31 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
for (l = pool->timeouts; l; l = l->next)
|
|
|
|
{
|
|
|
|
ClutterTimeout *timeout = l->data;
|
|
|
|
|
2007-06-14 12:00:31 +00:00
|
|
|
/* since the timeouts are sorted by expiration, as soon
|
|
|
|
* as we get a check returning FALSE we know that the
|
|
|
|
* following timeouts are not expiring, so we break as
|
|
|
|
* soon as possible
|
|
|
|
*/
|
2008-04-17 16:50:23 +00:00
|
|
|
if (clutter_timeout_prepare (pool, timeout, NULL))
|
2007-06-14 12:00:31 +00:00
|
|
|
{
|
|
|
|
timeout->flags |= CLUTTER_TIMEOUT_READY;
|
|
|
|
pool->ready += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
2007-06-09 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
return (pool->ready > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_timeout_pool_dispatch (GSource *source,
|
|
|
|
GSourceFunc func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ClutterTimeoutPool *pool = (ClutterTimeoutPool *) source;
|
2007-08-19 17:06:22 +00:00
|
|
|
GList *dispatched_timeouts;
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2007-06-14 12:00:31 +00:00
|
|
|
/* the main loop might have predicted this, so we repeat the
|
|
|
|
* check for ready timeouts.
|
|
|
|
*/
|
2007-06-09 13:19:52 +00:00
|
|
|
if (!pool->ready)
|
2007-06-14 19:57:36 +00:00
|
|
|
clutter_timeout_pool_check (source);
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
clutter_threads_enter ();
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
/* Iterate by moving the actual start of the list along so that it
|
|
|
|
* can cope with adds and removes while a timeout is being dispatched
|
|
|
|
*/
|
|
|
|
while (pool->timeouts && pool->timeouts->data && pool->ready-- > 0)
|
2007-06-09 13:19:52 +00:00
|
|
|
{
|
2007-08-12 13:19:31 +00:00
|
|
|
ClutterTimeout *timeout = pool->timeouts->data;
|
2007-08-19 17:06:22 +00:00
|
|
|
GList *l;
|
2007-08-12 13:19:31 +00:00
|
|
|
|
|
|
|
/* One of the ready timeouts may have been removed during dispatch,
|
|
|
|
* in which case pool->ready will be wrong, but the ready timeouts
|
|
|
|
* are always kept at the start of the list so we can stop once
|
|
|
|
* we've reached the first non-ready timeout
|
|
|
|
*/
|
|
|
|
if (!(TIMEOUT_READY (timeout)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Add a reference to the timeout so it can't disappear
|
|
|
|
* while it's being dispatched
|
|
|
|
*/
|
|
|
|
clutter_timeout_ref (timeout);
|
2007-06-14 12:00:31 +00:00
|
|
|
|
|
|
|
timeout->flags &= ~CLUTTER_TIMEOUT_READY;
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
/* Move the list node to a list of dispatched timeouts */
|
|
|
|
l = pool->timeouts;
|
|
|
|
if (l->next)
|
|
|
|
l->next->prev = NULL;
|
2007-06-14 12:00:31 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
pool->timeouts = l->next;
|
2007-06-14 12:00:31 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
if (pool->dispatched_timeouts)
|
|
|
|
pool->dispatched_timeouts->prev = l;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
l->prev = NULL;
|
|
|
|
l->next = pool->dispatched_timeouts;
|
|
|
|
pool->dispatched_timeouts = l;
|
2007-08-08 21:36:16 +00:00
|
|
|
|
2009-03-09 17:12:27 +00:00
|
|
|
if (!_clutter_timeout_interval_dispatch (&timeout->interval,
|
|
|
|
timeout->func, timeout->data))
|
2007-08-12 13:19:31 +00:00
|
|
|
{
|
|
|
|
/* The timeout may have already been removed, but nothing
|
|
|
|
* can be added to the dispatched_timeout list except in this
|
|
|
|
* function so it will always either be at the head of the
|
|
|
|
* dispatched list or have been removed
|
|
|
|
*/
|
|
|
|
if (pool->dispatched_timeouts &&
|
|
|
|
pool->dispatched_timeouts->data == timeout)
|
|
|
|
{
|
|
|
|
pool->dispatched_timeouts =
|
|
|
|
g_list_delete_link (pool->dispatched_timeouts,
|
|
|
|
pool->dispatched_timeouts);
|
|
|
|
|
|
|
|
/* Remove the reference that was held by it being in the list */
|
|
|
|
clutter_timeout_unref (timeout);
|
|
|
|
}
|
2007-08-08 21:36:16 +00:00
|
|
|
}
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
clutter_timeout_unref (timeout);
|
2007-06-09 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 21:36:16 +00:00
|
|
|
/* Re-insert the dispatched timeouts in sorted order */
|
2007-08-19 17:06:22 +00:00
|
|
|
dispatched_timeouts = pool->dispatched_timeouts;
|
|
|
|
while (dispatched_timeouts)
|
2007-08-08 21:36:16 +00:00
|
|
|
{
|
2007-08-19 17:06:22 +00:00
|
|
|
ClutterTimeout *timeout = dispatched_timeouts->data;
|
|
|
|
GList *next = dispatched_timeouts->next;
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
pool->timeouts = g_list_insert_sorted (pool->timeouts, timeout,
|
|
|
|
clutter_timeout_sort);
|
2007-08-12 13:19:31 +00:00
|
|
|
|
2007-08-19 17:06:22 +00:00
|
|
|
dispatched_timeouts = next;
|
2007-08-08 21:36:16 +00:00
|
|
|
}
|
2007-06-09 13:19:52 +00:00
|
|
|
|
2007-08-19 17:06:22 +00:00
|
|
|
g_list_free (pool->dispatched_timeouts);
|
|
|
|
pool->dispatched_timeouts = NULL;
|
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
pool->ready = 0;
|
|
|
|
|
2007-08-08 21:36:16 +00:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_timeout_pool_finalize (GSource *source)
|
|
|
|
{
|
|
|
|
ClutterTimeoutPool *pool = (ClutterTimeoutPool *) source;
|
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
/* force destruction */
|
2007-06-09 13:19:52 +00:00
|
|
|
g_list_foreach (pool->timeouts, (GFunc) clutter_timeout_free, NULL);
|
|
|
|
g_list_free (pool->timeouts);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeout_pool_new:
|
2007-06-09 13:20:13 +00:00
|
|
|
* @priority: the priority of the timeout pool. Typically this will
|
|
|
|
* be #G_PRIORITY_DEFAULT
|
2007-06-09 13:19:52 +00:00
|
|
|
*
|
2007-06-09 13:20:13 +00:00
|
|
|
* Creates a new timeout pool source. A timeout pool should be used when
|
|
|
|
* multiple timeout functions, running at the same priority, are needed and
|
|
|
|
* the g_timeout_add() API might lead to starvation of the time slice of
|
|
|
|
* the main loop. A timeout pool allocates a single time slice of the main
|
|
|
|
* loop and runs every timeout function inside it. The timeout pool is
|
|
|
|
* always sorted, so that the extraction of the next timeout function is
|
|
|
|
* a constant time operation.
|
|
|
|
*
|
2008-09-23 12:58:31 +00:00
|
|
|
* Return value: the newly created #ClutterTimeoutPool. The created pool
|
2008-09-23 13:25:31 +00:00
|
|
|
* is owned by the GLib default context and will be automatically
|
|
|
|
* destroyed when the context is destroyed. It is possible to force
|
|
|
|
* the destruction of the timeout pool using g_source_destroy()
|
2007-06-09 13:19:52 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2010-11-06 19:59:58 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.6
|
2007-06-09 13:19:52 +00:00
|
|
|
*/
|
|
|
|
ClutterTimeoutPool *
|
|
|
|
clutter_timeout_pool_new (gint priority)
|
|
|
|
{
|
|
|
|
ClutterTimeoutPool *pool;
|
|
|
|
GSource *source;
|
|
|
|
|
|
|
|
source = g_source_new (&clutter_timeout_pool_funcs,
|
|
|
|
sizeof (ClutterTimeoutPool));
|
|
|
|
if (!source)
|
|
|
|
return NULL;
|
|
|
|
|
2010-06-04 03:34:09 +00:00
|
|
|
g_source_set_name (source, "Clutter timeout pool");
|
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
if (priority != G_PRIORITY_DEFAULT)
|
|
|
|
g_source_set_priority (source, priority);
|
|
|
|
|
|
|
|
pool = (ClutterTimeoutPool *) source;
|
2008-09-23 12:58:31 +00:00
|
|
|
|
2008-04-17 16:50:23 +00:00
|
|
|
g_get_current_time (&pool->start_time);
|
2007-06-09 13:19:52 +00:00
|
|
|
pool->next_id = 1;
|
|
|
|
pool->id = g_source_attach (source, NULL);
|
2008-09-23 12:58:31 +00:00
|
|
|
|
|
|
|
/* let the default GLib context manage the pool */
|
2007-06-09 13:19:52 +00:00
|
|
|
g_source_unref (source);
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeout_pool_add:
|
|
|
|
* @pool: a #ClutterTimeoutPool
|
2009-03-16 16:54:58 +00:00
|
|
|
* @fps: the time between calls to the function, in frames per second
|
2007-06-09 13:20:13 +00:00
|
|
|
* @func: function to call
|
|
|
|
* @data: data to pass to the function, or %NULL
|
|
|
|
* @notify: function to call when the timeout is removed, or %NULL
|
2007-06-09 13:19:52 +00:00
|
|
|
*
|
2007-06-09 13:20:13 +00:00
|
|
|
* Sets a function to be called at regular intervals, and puts it inside
|
|
|
|
* the @pool. The function is repeatedly called until it returns %FALSE,
|
|
|
|
* at which point the timeout is automatically destroyed and the function
|
|
|
|
* won't be called again. If @notify is not %NULL, the @notify function
|
|
|
|
* will be called. The first call to @func will be at the end of @interval.
|
2007-06-09 13:19:52 +00:00
|
|
|
*
|
2010-01-27 21:14:43 +00:00
|
|
|
* Since Clutter 0.8 this will try to compensate for delays. For
|
2008-04-17 16:50:23 +00:00
|
|
|
* example, if @func takes half the interval time to execute then the
|
|
|
|
* function will be called again half the interval time after it
|
|
|
|
* finished. Before version 0.8 it would not fire until a full
|
|
|
|
* interval after the function completes so the delay between calls
|
|
|
|
* would be @interval * 1.5. This function does not however try to
|
|
|
|
* invoke the function multiple times to catch up missing frames if
|
|
|
|
* @func takes more than @interval ms to execute.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-06-09 13:20:13 +00:00
|
|
|
* Return value: the ID (greater than 0) of the timeout inside the pool.
|
|
|
|
* Use clutter_timeout_pool_remove() to stop the timeout.
|
2007-06-09 13:19:52 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2010-11-06 19:59:58 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.6
|
2007-06-09 13:19:52 +00:00
|
|
|
*/
|
|
|
|
guint
|
|
|
|
clutter_timeout_pool_add (ClutterTimeoutPool *pool,
|
2009-03-16 16:54:58 +00:00
|
|
|
guint fps,
|
2007-06-09 13:19:52 +00:00
|
|
|
GSourceFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
ClutterTimeout *timeout;
|
|
|
|
guint retval = 0;
|
|
|
|
|
2009-03-16 16:54:58 +00:00
|
|
|
timeout = clutter_timeout_new (fps);
|
2007-06-14 12:00:31 +00:00
|
|
|
|
2007-06-09 13:19:52 +00:00
|
|
|
retval = timeout->id = pool->next_id++;
|
|
|
|
|
|
|
|
timeout->func = func;
|
|
|
|
timeout->data = data;
|
|
|
|
timeout->notify = notify;
|
|
|
|
|
|
|
|
pool->timeouts = g_list_insert_sorted (pool->timeouts, timeout,
|
|
|
|
clutter_timeout_sort);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeout_pool_remove:
|
|
|
|
* @pool: a #ClutterTimeoutPool
|
2007-06-09 13:20:13 +00:00
|
|
|
* @id: the id of the timeout to remove
|
2007-06-09 13:19:52 +00:00
|
|
|
*
|
2007-06-09 13:20:13 +00:00
|
|
|
* Removes a timeout function with @id from the timeout pool. The id
|
|
|
|
* is the same returned when adding a function to the timeout pool with
|
|
|
|
* clutter_timeout_pool_add().
|
2007-06-09 13:19:52 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2010-11-06 19:59:58 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.6
|
2007-06-09 13:19:52 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeout_pool_remove (ClutterTimeoutPool *pool,
|
|
|
|
guint id)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
2007-08-12 13:19:31 +00:00
|
|
|
if ((l = g_list_find_custom (pool->timeouts, GUINT_TO_POINTER (id),
|
|
|
|
clutter_timeout_find_by_id)))
|
2007-06-09 13:19:52 +00:00
|
|
|
{
|
2007-08-12 13:19:31 +00:00
|
|
|
clutter_timeout_unref (l->data);
|
|
|
|
pool->timeouts = g_list_delete_link (pool->timeouts, l);
|
|
|
|
}
|
2008-04-17 16:50:23 +00:00
|
|
|
else if ((l = g_list_find_custom (pool->dispatched_timeouts,
|
|
|
|
GUINT_TO_POINTER (id),
|
2007-08-12 13:19:31 +00:00
|
|
|
clutter_timeout_find_by_id)))
|
|
|
|
{
|
|
|
|
clutter_timeout_unref (l->data);
|
2010-01-27 21:16:28 +00:00
|
|
|
|
|
|
|
pool->dispatched_timeouts =
|
|
|
|
g_list_delete_link (pool->dispatched_timeouts, l);
|
2007-06-09 13:19:52 +00:00
|
|
|
}
|
|
|
|
}
|