diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-06-16 16:15:08 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-06-16 17:14:15 +0100 |
commit | 3360d645bb8a91397d8bb3080c2431edeac47572 (patch) | |
tree | d22533e61f1876f1685525bd492efbc49ee6b39f | |
parent | 5bb2f28214f7a532a99a1b36ddb12c4b849a5e95 (diff) | |
download | clutter-3360d645bb8a91397d8bb3080c2431edeac47572.tar.gz |
[2.0] Remove FrameSource and TimeoutPool
-rw-r--r-- | clutter/Makefile.am | 10 | ||||
-rw-r--r-- | clutter/clutter-frame-source.c | 263 | ||||
-rw-r--r-- | clutter/clutter-frame-source.h | 51 | ||||
-rw-r--r-- | clutter/clutter-main.c | 5 | ||||
-rw-r--r-- | clutter/clutter-main.h | 11 | ||||
-rw-r--r-- | clutter/clutter-timeout-interval.c | 140 | ||||
-rw-r--r-- | clutter/clutter-timeout-interval.h | 58 | ||||
-rw-r--r-- | clutter/clutter-timeout-pool.c | 497 | ||||
-rw-r--r-- | clutter/clutter-timeout-pool.h | 69 | ||||
-rw-r--r-- | clutter/clutter.h | 2 |
10 files changed, 3 insertions, 1103 deletions
diff --git a/clutter/Makefile.am b/clutter/Makefile.am index e90d3afce..9da0d26b8 100644 --- a/clutter/Makefile.am +++ b/clutter/Makefile.am @@ -84,8 +84,7 @@ source_h = \ $(srcdir)/clutter-fixed.h \ $(srcdir)/clutter-fixed-layout.h \ $(srcdir)/clutter-flow-layout.h \ - $(srcdir)/clutter-frame-source.h \ - $(srcdir)/clutter-gesture-action.h \ + $(srcdir)/clutter-gesture-action.h \ $(srcdir)/clutter-group.h \ $(srcdir)/clutter-input-device.h \ $(srcdir)/clutter-interval.h \ @@ -118,7 +117,6 @@ source_h = \ $(srcdir)/clutter-texture.h \ $(srcdir)/clutter-text.h \ $(srcdir)/clutter-timeline.h \ - $(srcdir)/clutter-timeout-pool.h \ $(srcdir)/clutter-types.h \ $(srcdir)/clutter-units.h \ $(srcdir)/clutter-util.h \ @@ -161,8 +159,7 @@ source_c = \ $(srcdir)/clutter-fixed-layout.c \ $(srcdir)/clutter-flatten-effect.c \ $(srcdir)/clutter-flow-layout.c \ - $(srcdir)/clutter-frame-source.c \ - $(srcdir)/clutter-gesture-action.c \ + $(srcdir)/clutter-gesture-action.c \ $(srcdir)/clutter-group.c \ $(srcdir)/clutter-input-device.c \ $(srcdir)/clutter-interval.c \ @@ -196,7 +193,6 @@ source_c = \ $(srcdir)/clutter-texture.c \ $(srcdir)/clutter-text.c \ $(srcdir)/clutter-timeline.c \ - $(srcdir)/clutter-timeout-pool.c \ $(srcdir)/clutter-units.c \ $(srcdir)/clutter-util.c \ $(srcdir)/clutter-paint-volume.c \ @@ -224,7 +220,6 @@ source_h_priv = \ $(srcdir)/clutter-script-private.h \ $(srcdir)/clutter-stage-manager-private.h \ $(srcdir)/clutter-stage-private.h \ - $(srcdir)/clutter-timeout-interval.h \ $(NULL) # private source code; these should not be introspected @@ -232,7 +227,6 @@ source_c_priv = \ $(srcdir)/clutter-event-translator.c \ $(srcdir)/clutter-id-pool.c \ $(srcdir)/clutter-profile.c \ - $(srcdir)/clutter-timeout-interval.c \ $(NULL) # built sources diff --git a/clutter/clutter-frame-source.c b/clutter/clutter-frame-source.c deleted file mode 100644 index 8f5f46b11..000000000 --- a/clutter/clutter-frame-source.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Neil Roberts <neil@linux.intel.com> - * - * Copyright (C) 2008 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 - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "clutter-frame-source.h" -#include "clutter-timeout-interval.h" -#include "clutter-private.h" - -typedef struct _ClutterFrameSource ClutterFrameSource; - -struct _ClutterFrameSource -{ - GSource source; - - ClutterTimeoutInterval timeout; -}; - -static gboolean clutter_frame_source_prepare (GSource *source, - gint *timeout); -static gboolean clutter_frame_source_check (GSource *source); -static gboolean clutter_frame_source_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data); - -static GSourceFuncs clutter_frame_source_funcs = -{ - clutter_frame_source_prepare, - clutter_frame_source_check, - clutter_frame_source_dispatch, - NULL -}; - -/** - * clutter_frame_source_add_full: - * @priority: the priority of the frame source. Typically this will be in the - * range between %G_PRIORITY_DEFAULT and %G_PRIORITY_HIGH. - * @fps: the number of times per second to call the function - * @func: function to call - * @data: data to pass to the function - * @notify: function to call when the timeout source is removed - * - * Sets a function to be called at regular intervals with the given - * priority. The function is called repeatedly until it returns - * %FALSE, at which point the timeout is automatically destroyed and - * the function will not be called again. The @notify function is - * called when the timeout is destroyed. The first call to the - * function will be at the end of the first @interval. - * - * This function is similar to g_timeout_add_full() except that it - * will try to compensate for delays. For example, if @func takes half - * the interval time to execute then the function will be called again - * half the interval time after it finished. In contrast - * g_timeout_add_full() would not fire until a full interval after the - * function completes so the delay between calls would be 1.0 / @fps * - * 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. - * - * Rename to: clutter_frame_source_add - * - * Return value: the ID (greater than 0) of the event source. - * - * Since: 0.8 - * - * Deprecated: 1.6 - */ -guint -clutter_frame_source_add_full (gint priority, - guint fps, - GSourceFunc func, - gpointer data, - GDestroyNotify notify) -{ - guint ret; - GSource *source = g_source_new (&clutter_frame_source_funcs, - sizeof (ClutterFrameSource)); - ClutterFrameSource *frame_source = (ClutterFrameSource *) source; - - _clutter_timeout_interval_init (&frame_source->timeout, fps); - - if (priority != G_PRIORITY_DEFAULT) - g_source_set_priority (source, priority); - - g_source_set_name (source, "Clutter frame timeout"); - g_source_set_callback (source, func, data, notify); - - ret = g_source_attach (source, NULL); - - g_source_unref (source); - - return ret; -} - -/** - * clutter_frame_source_add: (skip) - * @fps: the number of times per second to call the function - * @func: function to call - * @data: data to pass to the function - * - * Simple wrapper around clutter_frame_source_add_full(). - * - * Return value: the ID (greater than 0) of the event source. - * - * Since: 0.8 - * - * Deprecated: 1.6 - */ -guint -clutter_frame_source_add (guint fps, - GSourceFunc func, - gpointer data) -{ - return clutter_frame_source_add_full (G_PRIORITY_DEFAULT, - fps, func, data, NULL); -} - -static gboolean -clutter_frame_source_prepare (GSource *source, - gint *delay) -{ - ClutterFrameSource *frame_source = (ClutterFrameSource *) source; - gint64 current_time; - -#if GLIB_CHECK_VERSION (2, 27, 3) - current_time = g_source_get_time (source) / 1000; -#else - { - GTimeVal source_time; - g_source_get_current_time (source, &source_time); - current_time = source_time.tv_sec * 1000 + source_time.tv_usec / 1000; - } -#endif - - return _clutter_timeout_interval_prepare (current_time, - &frame_source->timeout, - delay); -} - -static gboolean -clutter_frame_source_check (GSource *source) -{ - return clutter_frame_source_prepare (source, NULL); -} - -static gboolean -clutter_frame_source_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data) -{ - ClutterFrameSource *frame_source = (ClutterFrameSource *) source; - - return _clutter_timeout_interval_dispatch (&frame_source->timeout, - callback, user_data); -} - -/** - * clutter_threads_add_frame_source_full: - * @priority: the priority of the frame source. Typically this will be in the - * range between %G_PRIORITY_DEFAULT and %G_PRIORITY_HIGH. - * @fps: the number of times per second to call the function - * @func: function to call - * @data: data to pass to the function - * @notify: function to call when the timeout source is removed - * - * 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. - * - * This function is similar to clutter_threads_add_timeout_full() - * except that it will try to compensate for delays. For example, if - * @func takes half the interval time to execute then the function - * will be called again half the interval time after it finished. In - * contrast clutter_threads_add_timeout_full() 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. - * - * See also clutter_threads_add_idle_full(). - * - * Rename to: clutter_threads_add_frame_source - * - * Return value: the ID (greater than 0) of the event source. - * - * Since: 0.8 - * - * Deprecated: 1.6 - */ -guint -clutter_threads_add_frame_source_full (gint priority, - guint fps, - GSourceFunc func, - gpointer data, - GDestroyNotify notify) -{ - ClutterThreadsDispatch *dispatch; - - g_return_val_if_fail (func != NULL, 0); - - dispatch = g_slice_new (ClutterThreadsDispatch); - dispatch->func = func; - dispatch->data = data; - dispatch->notify = notify; - - return clutter_frame_source_add_full (priority, - fps, - _clutter_threads_dispatch, dispatch, - _clutter_threads_dispatch_free); -} - -/** - * clutter_threads_add_frame_source: (skip) - * @fps: the number of times per second to call the function - * @func: function to call - * @data: data to pass to the function - * - * Simple wrapper around clutter_threads_add_frame_source_full(). - * - * Return value: the ID (greater than 0) of the event source. - * - * Since: 0.8 - * - * Deprecated: 1.6 - */ -guint -clutter_threads_add_frame_source (guint fps, - GSourceFunc func, - gpointer data) -{ - g_return_val_if_fail (func != NULL, 0); - - return clutter_threads_add_frame_source_full (G_PRIORITY_DEFAULT, - fps, - func, data, - NULL); -} diff --git a/clutter/clutter-frame-source.h b/clutter/clutter-frame-source.h deleted file mode 100644 index a8a40cc45..000000000 --- a/clutter/clutter-frame-source.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum <mallum@openedhand.com> - * - * Copyright (C) 2008 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 - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only <clutter/clutter.h> can be included directly." -#endif - -#ifndef __CLUTTER_FRAME_SOURCE_H__ -#define __CLUTTER_FRAME_SOURCE_H__ - -#include <glib.h> - -G_BEGIN_DECLS - -#if !defined(CLUTTER_DISABLE_DEPRECATED) || defined(CLUTTER_COMPILATION) - -guint clutter_frame_source_add (guint fps, - GSourceFunc func, - gpointer data); - -guint clutter_frame_source_add_full (gint priority, - guint fps, - GSourceFunc func, - gpointer data, - GDestroyNotify notify); - -#endif /* CLUTTER_DISABLE_DEPRECATED */ - -G_END_DECLS - -#endif /* __CLUTTER_FRAME_SOURCE_H__ */ diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index b7a63f472..58c0b551b 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -100,7 +100,6 @@ #include "clutter-device-manager-private.h" #include "clutter-event.h" #include "clutter-feature.h" -#include "clutter-frame-source.h" #include "clutter-main.h" #include "clutter-master-clock.h" #include "clutter-private.h" @@ -960,9 +959,7 @@ clutter_threads_add_idle (GSourceFunc func, * * 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. A more reliable source is available - * using clutter_threads_add_frame_source_full(), which is also internally - * used by #ClutterTimeline. + * "keep up" with the interval. * * See also clutter_threads_add_idle_full(). * diff --git a/clutter/clutter-main.h b/clutter/clutter-main.h index 7e7f56c9d..d42c9f36b 100644 --- a/clutter/clutter-main.h +++ b/clutter/clutter-main.h @@ -127,17 +127,6 @@ guint clutter_threads_add_timeout_full (gint priority, gpointer data, GDestroyNotify notify); -#ifndef CLUTTER_DISABLE_DEPRECATED -guint clutter_threads_add_frame_source (guint fps, - GSourceFunc func, - gpointer data); -guint clutter_threads_add_frame_source_full (gint priority, - guint fps, - GSourceFunc func, - gpointer data, - GDestroyNotify notify); -#endif /* CLUTTER_DISABLE_DEPRECATED */ - guint clutter_threads_add_repaint_func (GSourceFunc func, gpointer data, GDestroyNotify notify); diff --git a/clutter/clutter-timeout-interval.c b/clutter/clutter-timeout-interval.c deleted file mode 100644 index ac0ad44d1..000000000 --- a/clutter/clutter-timeout-interval.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Neil Roberts <neil@linux.intel.com> - * - * Copyright (C) 2009 Intel Corporation. - * - * 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 - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* This file contains the common code to check whether an interval has - expired used in clutter-frame-source and clutter-timeout-pool. */ - -#include "clutter-timeout-interval.h" - -void -_clutter_timeout_interval_init (ClutterTimeoutInterval *interval, - guint fps) -{ -#if GLIB_CHECK_VERSION (2, 27, 3) - interval->start_time = g_get_monotonic_time () / 1000; -#else - { - GTimeVal start_time; - g_get_current_time (&start_time); - interval->start_time = start_time.tv_sec * 1000 - + start_time.tv_usec / 1000; - } -#endif - - interval->fps = fps; - interval->frame_count = 0; -} - -static gint64 -_clutter_timeout_interval_get_ticks (gint64 current_time, - ClutterTimeoutInterval *interval) -{ - return MAX (current_time - interval->start_time, 0); -} - -gboolean -_clutter_timeout_interval_prepare (gint64 current_time, - ClutterTimeoutInterval *interval, - gint *delay) -{ - gint elapsed_time, new_frame_num; - - elapsed_time = _clutter_timeout_interval_get_ticks (current_time, interval); - new_frame_num = elapsed_time * interval->fps / 1000; - - /* If time has gone backwards or the time since the last frame is - greater than the two frames worth then reset the time and do a - frame now */ - if (new_frame_num < interval->frame_count || - new_frame_num - interval->frame_count > 2) - { - /* Get the frame time rounded up to the nearest ms */ - guint frame_time = (1000 + interval->fps - 1) / interval->fps; - - /* Reset the start time */ - interval->start_time = current_time; - - /* Move the start time as if one whole frame has elapsed */ - interval->start_time -= frame_time; - - interval->frame_count = 0; - - if (delay) - *delay = 0; - - return TRUE; - } - else if (new_frame_num > interval->frame_count) - { - if (delay) - *delay = 0; - - return TRUE; - } - else - { - if (delay) - *delay = ((interval->frame_count + 1) * 1000 / interval->fps - - elapsed_time); - - return FALSE; - } -} - -gboolean -_clutter_timeout_interval_dispatch (ClutterTimeoutInterval *interval, - GSourceFunc callback, - gpointer user_data) -{ - if ((* callback) (user_data)) - { - interval->frame_count++; - - return TRUE; - } - - return FALSE; -} - -gint -_clutter_timeout_interval_compare_expiration (const ClutterTimeoutInterval *a, - const ClutterTimeoutInterval *b) -{ - guint a_delay = 1000 / a->fps; - guint b_delay = 1000 / b->fps; - gint64 b_difference; - gint comparison; - - b_difference = a->start_time - b->start_time; - - comparison = ((gint) ((a->frame_count + 1) * a_delay) - - (gint) ((b->frame_count + 1) * b_delay + b_difference)); - - return (comparison < 0 ? -1 - : comparison > 0 ? 1 - : 0); -} diff --git a/clutter/clutter-timeout-interval.h b/clutter/clutter-timeout-interval.h deleted file mode 100644 index 57df959a8..000000000 --- a/clutter/clutter-timeout-interval.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Neil Roberts <neil@linux.intel.com> - * - * Copyright (C) 2009 Intel Corporation. - * - * 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 - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __CLUTTER_TIMEOUT_INTERVAL_H__ -#define __CLUTTER_TIMEOUT_INTERVAL_H__ - -#include <glib.h> - -G_BEGIN_DECLS - -typedef struct _ClutterTimeoutInterval ClutterTimeoutInterval; - -struct _ClutterTimeoutInterval -{ - /* milliseconds */ - gint64 start_time; - - guint frame_count; - guint fps; -}; - -void _clutter_timeout_interval_init (ClutterTimeoutInterval *interval, - guint fps); - -gboolean _clutter_timeout_interval_prepare (gint64 current_time, - ClutterTimeoutInterval *interval, - gint *delay); - -gboolean _clutter_timeout_interval_dispatch (ClutterTimeoutInterval *interval, - GSourceFunc callback, - gpointer user_data); - -gint _clutter_timeout_interval_compare_expiration (const ClutterTimeoutInterval *a, - const ClutterTimeoutInterval *b); - -G_END_DECLS - -#endif /* __CLUTTER_TIMEOUT_INTERVAL_H__ */ diff --git a/clutter/clutter-timeout-pool.c b/clutter/clutter-timeout-pool.c deleted file mode 100644 index 6ef839b8e..000000000 --- a/clutter/clutter-timeout-pool.c +++ /dev/null @@ -1,497 +0,0 @@ -/* - * 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 - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - * - * - * 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 - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "clutter-timeout-pool.h" - -#include "clutter-debug.h" -#include "clutter-timeout-interval.h" - -typedef struct _ClutterTimeout ClutterTimeout; -typedef enum { - CLUTTER_TIMEOUT_NONE = 0, - CLUTTER_TIMEOUT_READY = 1 << 1 -} ClutterTimeoutFlags; - -struct _ClutterTimeout -{ - guint id; - ClutterTimeoutFlags flags; - gint refcount; - - ClutterTimeoutInterval interval; - - GSourceFunc func; - gpointer data; - GDestroyNotify notify; -}; - -struct _ClutterTimeoutPool -{ - GSource source; - - guint next_id; - - GList *timeouts; - GList *dispatched_timeouts; - - gint ready; - - guint id; -}; - -#define TIMEOUT_READY(timeout) (timeout->flags & CLUTTER_TIMEOUT_READY) - -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); -static void clutter_timeout_pool_finalize (GSource *source); - -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; - - /* Keep 'ready' timeouts at the front */ - if (TIMEOUT_READY (t_a)) - return -1; - - if (TIMEOUT_READY (t_b)) - return 1; - - return _clutter_timeout_interval_compare_expiration (&t_a->interval, - &t_b->interval); -} - -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; -} - -static ClutterTimeout * -clutter_timeout_new (guint fps) -{ - ClutterTimeout *timeout; - - timeout = g_slice_new0 (ClutterTimeout); - _clutter_timeout_interval_init (&timeout->interval, fps); - timeout->flags = CLUTTER_TIMEOUT_NONE; - timeout->refcount = 1; - - return timeout; -} - -static gboolean -clutter_timeout_prepare (ClutterTimeoutPool *pool, - ClutterTimeout *timeout, - gint *next_timeout) -{ - GSource *source = (GSource *) pool; - gint64 now; - -#if GLIB_CHECK_VERSION (2, 27, 3) - now = g_source_get_time (source) / 1000; -#else - { - GTimeVal source_time; - g_source_get_current_time (source, &source_time); - now = source_time.tv_sec * 1000 + source_time.tv_usec / 1000; - } -#endif - - return _clutter_timeout_interval_prepare (now, - &timeout->interval, - next_timeout); -} - -/* 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); - } -} - -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; - - /* the pool is ready if the first timeout is ready */ - if (l && l->data) - { - ClutterTimeout *timeout = l->data; - return clutter_timeout_prepare (pool, timeout, next_timeout); - } - else - { - *next_timeout = -1; - return FALSE; - } -} - -static gboolean -clutter_timeout_pool_check (GSource *source) -{ - ClutterTimeoutPool *pool = (ClutterTimeoutPool *) source; - GList *l; - - clutter_threads_enter (); - - for (l = pool->timeouts; l; l = l->next) - { - ClutterTimeout *timeout = l->data; - - /* 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 - */ - if (clutter_timeout_prepare (pool, timeout, NULL)) - { - timeout->flags |= CLUTTER_TIMEOUT_READY; - pool->ready += 1; - } - else - break; - } - - clutter_threads_leave (); - - return (pool->ready > 0); -} - -static gboolean -clutter_timeout_pool_dispatch (GSource *source, - GSourceFunc func, - gpointer data) -{ - ClutterTimeoutPool *pool = (ClutterTimeoutPool *) source; - GList *dispatched_timeouts; - - /* the main loop might have predicted this, so we repeat the - * check for ready timeouts. - */ - if (!pool->ready) - clutter_timeout_pool_check (source); - - clutter_threads_enter (); - - /* 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) - { - ClutterTimeout *timeout = pool->timeouts->data; - GList *l; - - /* 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); - - timeout->flags &= ~CLUTTER_TIMEOUT_READY; - - /* Move the list node to a list of dispatched timeouts */ - l = pool->timeouts; - if (l->next) - l->next->prev = NULL; - - pool->timeouts = l->next; - - if (pool->dispatched_timeouts) - pool->dispatched_timeouts->prev = l; - - l->prev = NULL; - l->next = pool->dispatched_timeouts; - pool->dispatched_timeouts = l; - - if (!_clutter_timeout_interval_dispatch (&timeout->interval, - timeout->func, timeout->data)) - { - /* 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); - } - } - - clutter_timeout_unref (timeout); - } - - /* Re-insert the dispatched timeouts in sorted order */ - dispatched_timeouts = pool->dispatched_timeouts; - while (dispatched_timeouts) - { - ClutterTimeout *timeout = dispatched_timeouts->data; - GList *next = dispatched_timeouts->next; - - if (timeout) - pool->timeouts = g_list_insert_sorted (pool->timeouts, timeout, - clutter_timeout_sort); - - dispatched_timeouts = next; - } - - g_list_free (pool->dispatched_timeouts); - pool->dispatched_timeouts = NULL; - - pool->ready = 0; - - clutter_threads_leave (); - - return TRUE; -} - -static void -clutter_timeout_pool_finalize (GSource *source) -{ - ClutterTimeoutPool *pool = (ClutterTimeoutPool *) source; - - /* force destruction */ - g_list_foreach (pool->timeouts, (GFunc) clutter_timeout_free, NULL); - g_list_free (pool->timeouts); -} - -/** - * clutter_timeout_pool_new: - * @priority: the priority of the timeout pool. Typically this will - * be #G_PRIORITY_DEFAULT - * - * 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. - * - * Return value: the newly created #ClutterTimeoutPool. The created pool - * 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() - * - * Since: 0.4 - * - * Deprecated: 1.6 - */ -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; - - g_source_set_name (source, "Clutter timeout pool"); - - if (priority != G_PRIORITY_DEFAULT) - g_source_set_priority (source, priority); - - pool = (ClutterTimeoutPool *) source; - pool->next_id = 1; - pool->id = g_source_attach (source, NULL); - - /* let the default GLib context manage the pool */ - g_source_unref (source); - - return pool; -} - -/** - * clutter_timeout_pool_add: - * @pool: a #ClutterTimeoutPool - * @fps: the time between calls to the function, in frames per second - * @func: function to call - * @data: data to pass to the function, or %NULL - * @notify: function to call when the timeout is removed, or %NULL - * - * 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. - * - * Since Clutter 0.8 this will try to compensate for delays. For - * 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. - * - * Return value: the ID (greater than 0) of the timeout inside the pool. - * Use clutter_timeout_pool_remove() to stop the timeout. - * - * Since: 0.4 - * - * Deprecated: 1.6 - */ -guint -clutter_timeout_pool_add (ClutterTimeoutPool *pool, - guint fps, - GSourceFunc func, - gpointer data, - GDestroyNotify notify) -{ - ClutterTimeout *timeout; - guint retval = 0; - - timeout = clutter_timeout_new (fps); - - 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 - * @id_: the id of the timeout to remove - * - * 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(). - * - * Since: 0.4 - * - * Deprecated: 1.6 - */ -void -clutter_timeout_pool_remove (ClutterTimeoutPool *pool, - guint id_) -{ - GList *l; - - if ((l = g_list_find_custom (pool->timeouts, GUINT_TO_POINTER (id_), - clutter_timeout_find_by_id))) - { - clutter_timeout_unref (l->data); - pool->timeouts = g_list_delete_link (pool->timeouts, l); - } - else if ((l = g_list_find_custom (pool->dispatched_timeouts, - GUINT_TO_POINTER (id_), - clutter_timeout_find_by_id))) - { - clutter_timeout_unref (l->data); - - pool->dispatched_timeouts = - g_list_delete_link (pool->dispatched_timeouts, l); - } -} diff --git a/clutter/clutter-timeout-pool.h b/clutter/clutter-timeout-pool.h deleted file mode 100644 index 0268ab833..000000000 --- a/clutter/clutter-timeout-pool.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - * 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 - */ - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only <clutter/clutter.h> can be included directly." -#endif - -#ifndef __CLUTTER_TIMEOUT_POOL_H__ -#define __CLUTTER_TIMEOUT_POOL_H__ - -#include <glib.h> - -G_BEGIN_DECLS - -#if !defined(CLUTTER_DISABLE_DEPRECATED) || defined(CLUTTER_COMPILATION) - -/** - * ClutterTimeoutPool: (skip) - * - * <structname>ClutterTimeoutPool</structname> is an opaque structure - * whose members cannot be directly accessed. - * - * Since: 0.6 - * - * Deprecated: 1.6 - */ -typedef struct _ClutterTimeoutPool ClutterTimeoutPool; - -ClutterTimeoutPool *clutter_timeout_pool_new (gint priority); -guint clutter_timeout_pool_add (ClutterTimeoutPool *pool, - guint fps, - GSourceFunc func, - gpointer data, - GDestroyNotify notify); -void clutter_timeout_pool_remove (ClutterTimeoutPool *pool, - guint id_); - -#endif /* CLUTTER_DISABLE_DEPRECATED */ - -G_END_DECLS - -#endif /* __CLUTTER_TIMEOUT_POOL_H__ */ diff --git a/clutter/clutter.h b/clutter/clutter.h index ae354dca5..bc59edf94 100644 --- a/clutter/clutter.h +++ b/clutter/clutter.h @@ -65,7 +65,6 @@ #include "clutter-feature.h" #include "clutter-fixed-layout.h" #include "clutter-flow-layout.h" -#include "clutter-frame-source.h" #include "clutter-gesture-action.h" #include "clutter-group.h" #include "clutter-input-device.h" @@ -98,7 +97,6 @@ #include "clutter-texture.h" #include "clutter-text.h" #include "clutter-timeline.h" -#include "clutter-timeout-pool.h" #include "clutter-types.h" #include "clutter-units.h" #include "clutter-util.h" |