4 * An OpenGL based 'interactive canvas' library.
6 * Authored By Matthew Allum <mallum@openedhand.com>
8 * Copyright (C) 2006 OpenedHand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
26 * SECTION:clutter-main
27 * @short_description: Various 'global' clutter functions.
29 * Functions to retrieve various global Clutter resources and other utility
30 * functions for mainloops, events and threads
38 #include <glib/gi18n-lib.h>
41 #include "clutter-event.h"
42 #include "clutter-backend.h"
43 #include "clutter-main.h"
44 #include "clutter-master-clock.h"
45 #include "clutter-feature.h"
46 #include "clutter-actor.h"
47 #include "clutter-stage.h"
48 #include "clutter-private.h"
49 #include "clutter-debug.h"
50 #include "clutter-version.h" /* For flavour define */
51 #include "clutter-frame-source.h"
53 #include "cogl/cogl.h"
54 #include "pango/cogl-pango.h"
57 static ClutterMainContext *ClutterCntx = NULL;
59 /* main lock and locking/unlocking functions */
60 static GMutex *clutter_threads_mutex = NULL;
61 static GCallback clutter_threads_lock = NULL;
62 static GCallback clutter_threads_unlock = NULL;
64 /* command line options */
65 static gboolean clutter_is_initialized = FALSE;
66 static gboolean clutter_show_fps = FALSE;
67 static gboolean clutter_fatal_warnings = FALSE;
68 static gboolean clutter_disable_mipmap_text = FALSE;
69 static gboolean clutter_use_fuzzy_picking = FALSE;
71 static guint clutter_default_fps = 60;
73 static PangoDirection clutter_text_direction = PANGO_DIRECTION_LTR;
75 static guint clutter_main_loop_level = 0;
76 static GSList *main_loops = NULL;
78 guint clutter_debug_flags = 0; /* global clutter debug flag */
80 #ifdef CLUTTER_ENABLE_DEBUG
81 static const GDebugKey clutter_debug_keys[] = {
82 { "misc", CLUTTER_DEBUG_MISC },
83 { "actor", CLUTTER_DEBUG_ACTOR },
84 { "texture", CLUTTER_DEBUG_TEXTURE },
85 { "event", CLUTTER_DEBUG_EVENT },
86 { "paint", CLUTTER_DEBUG_PAINT },
87 { "gl", CLUTTER_DEBUG_GL },
88 { "alpha", CLUTTER_DEBUG_ALPHA },
89 { "behaviour", CLUTTER_DEBUG_BEHAVIOUR },
90 { "pango", CLUTTER_DEBUG_PANGO },
91 { "backend", CLUTTER_DEBUG_BACKEND },
92 { "scheduler", CLUTTER_DEBUG_SCHEDULER },
93 { "script", CLUTTER_DEBUG_SCRIPT },
94 { "shader", CLUTTER_DEBUG_SHADER },
95 { "multistage", CLUTTER_DEBUG_MULTISTAGE },
96 { "animation", CLUTTER_DEBUG_ANIMATION },
97 { "layout", CLUTTER_DEBUG_LAYOUT }
99 #endif /* CLUTTER_ENABLE_DEBUG */
102 * clutter_get_show_fps:
104 * Returns whether Clutter should print out the frames per second on the
105 * console. You can enable this setting either using the
106 * <literal>CLUTTER_SHOW_FPS</literal> environment variable or passing
107 * the <literal>--clutter-show-fps</literal> command line argument. *
109 * Return value: %TRUE if Clutter should show the FPS.
114 clutter_get_show_fps (void)
116 return clutter_show_fps;
120 _clutter_stage_maybe_relayout (ClutterActor *stage)
122 gfloat natural_width, natural_height;
123 ClutterActorBox box = { 0, };
125 /* avoid reentrancy */
126 if (!(CLUTTER_PRIVATE_FLAGS (stage) & CLUTTER_ACTOR_IN_RELAYOUT))
128 CLUTTER_NOTE (ACTOR, "Recomputing layout");
130 CLUTTER_SET_PRIVATE_FLAGS (stage, CLUTTER_ACTOR_IN_RELAYOUT);
132 natural_width = natural_height = 0;
133 clutter_actor_get_preferred_size (stage,
135 &natural_width, &natural_height);
139 box.x2 = natural_width;
140 box.y2 = natural_height;
142 CLUTTER_NOTE (ACTOR, "Allocating (0, 0 - %d, %d) for the stage",
144 (int) natural_height);
146 clutter_actor_allocate (stage, &box, CLUTTER_ALLOCATION_NONE);
148 CLUTTER_UNSET_PRIVATE_FLAGS (stage, CLUTTER_ACTOR_IN_RELAYOUT);
153 _clutter_stage_maybe_setup_viewport (ClutterStage *stage)
155 if (CLUTTER_PRIVATE_FLAGS (stage) & CLUTTER_ACTOR_SYNC_MATRICES)
157 ClutterPerspective perspective;
158 gfloat width, height;
160 clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
161 clutter_stage_get_perspective (stage, &perspective);
164 "Setting up the viewport { w:%.2f, h:%.2f }",
167 _cogl_setup_viewport (width, height,
173 CLUTTER_UNSET_PRIVATE_FLAGS (stage, CLUTTER_ACTOR_SYNC_MATRICES);
178 _clutter_do_redraw (ClutterStage *stage)
180 ClutterMainContext *ctx;
181 ClutterMasterClock *master_clock;
182 static GTimer *timer = NULL;
183 static guint timer_n_frames = 0;
185 ctx = clutter_context_get_default ();
186 master_clock = _clutter_master_clock_get_default ();
188 /* Before we can paint, we have to be sure we have the latest layout */
189 _clutter_stage_maybe_relayout (CLUTTER_ACTOR (stage));
191 _clutter_backend_ensure_context (ctx->backend, stage);
193 /* Setup FPS count - not currently across *all* stages rather than per */
194 if (G_UNLIKELY (clutter_get_show_fps ()))
197 timer = g_timer_new ();
200 /* The code below can't go in stage paint as base actor_paint
201 * will get called before it (and break picking, etc)
203 _clutter_stage_maybe_setup_viewport (stage);
205 /* Call through to the actual backend to do the painting down from
206 * the stage. It will likely need to swap buffers, vblank sync etc
207 * which will be windowing system dependent
209 _clutter_backend_redraw (ctx->backend, stage);
211 /* Complete FPS info */
212 if (G_UNLIKELY (clutter_get_show_fps ()))
216 if (g_timer_elapsed (timer, NULL) >= 1.0)
218 g_print ("*** FPS: %i ***\n", timer_n_frames);
220 g_timer_start (timer);
224 CLUTTER_TIMESTAMP (SCHEDULER, "Redraw finish for stage:%p", stage);
230 * Forces a redraw of the entire stage. Applications should never use this
231 * function, but queue a redraw using clutter_actor_queue_redraw().
233 * This function should only be used by libraries integrating Clutter from
234 * within another toolkit.
237 clutter_redraw (ClutterStage *stage)
239 g_return_if_fail (CLUTTER_IS_STAGE (stage));
241 clutter_stage_ensure_redraw (stage);
245 * clutter_set_motion_events_enabled:
246 * @enable: %TRUE to enable per-actor motion events
248 * Sets whether per-actor motion events should be enabled or not (the
249 * default is to enable them).
251 * If @enable is %FALSE the following events will not work:
253 * <listitem><para>ClutterActor::motion-event, unless on the
254 * #ClutterStage</para></listitem>
255 * <listitem><para>ClutterActor::enter-event</para></listitem>
256 * <listitem><para>ClutterActor::leave-event</para></listitem>
262 clutter_set_motion_events_enabled (gboolean enable)
264 ClutterMainContext *context = clutter_context_get_default ();
266 context->motion_events_per_actor = enable;
270 * clutter_get_motion_events_enabled:
272 * Gets whether the per-actor motion events are enabled.
274 * Return value: %TRUE if the motion events are enabled
279 clutter_get_motion_events_enabled (void)
281 ClutterMainContext *context = clutter_context_get_default ();
283 return context->motion_events_per_actor;
286 guint _clutter_pix_to_id (guchar pixel[4]);
288 static inline void init_bits (void)
290 ClutterMainContext *ctx;
292 static gboolean done = FALSE;
296 ctx = clutter_context_get_default ();
302 _clutter_id_to_color (guint id, ClutterColor *col)
304 ClutterMainContext *ctx;
305 gint red, green, blue;
306 ctx = clutter_context_get_default ();
308 /* compute the numbers we'll store in the components */
309 red = (id >> (ctx->fb_g_mask_used+ctx->fb_b_mask_used))
310 & (0xff >> (8-ctx->fb_r_mask_used));
311 green = (id >> ctx->fb_b_mask_used) & (0xff >> (8-ctx->fb_g_mask_used));
312 blue = (id) & (0xff >> (8-ctx->fb_b_mask_used));
314 /* shift left bits a bit and add one, this circumvents
315 * at least some potential rounding errors in GL/GLES
316 * driver / hw implementation.
318 if (ctx->fb_r_mask_used != ctx->fb_r_mask)
320 if (ctx->fb_g_mask_used != ctx->fb_g_mask)
322 if (ctx->fb_b_mask_used != ctx->fb_b_mask)
325 /* shift up to be full 8bit values */
326 red = (red << (8 - ctx->fb_r_mask)) | (0x7f >> (ctx->fb_r_mask_used));
327 green = (green << (8 - ctx->fb_g_mask)) | (0x7f >> (ctx->fb_g_mask_used));
328 blue = (blue << (8 - ctx->fb_b_mask)) | (0x7f >> (ctx->fb_b_mask_used));
337 _clutter_pixel_to_id (guchar pixel[4])
339 ClutterMainContext *ctx;
340 gint red, green, blue;
343 ctx = clutter_context_get_default ();
345 /* reduce the pixel components to the number of bits actually used of the
348 red = pixel[0] >> (8 - ctx->fb_r_mask);
349 green = pixel[1] >> (8 - ctx->fb_g_mask);
350 blue = pixel[2] >> (8 - ctx->fb_b_mask);
352 /* divide potentially by two if 'fuzzy' */
353 red = red >> (ctx->fb_r_mask - ctx->fb_r_mask_used);
354 green = green >> (ctx->fb_g_mask - ctx->fb_g_mask_used);
355 blue = blue >> (ctx->fb_b_mask - ctx->fb_b_mask_used);
357 /* combine the correct per component values into the final id */
358 id = blue + (green << ctx->fb_b_mask_used)
359 + (red << (ctx->fb_b_mask_used + ctx->fb_g_mask_used));
365 _clutter_do_pick (ClutterStage *stage,
368 ClutterPickMode mode)
370 ClutterMainContext *context;
375 GLboolean dither_was_on;
377 context = clutter_context_get_default ();
379 _clutter_backend_ensure_context (context->backend, stage);
381 /* needed for when a context switch happens */
382 _clutter_stage_maybe_setup_viewport (stage);
384 cogl_clip_push_window_rect (x, y, 1, 1);
385 cogl_color_set_from_4ub (&white, 255, 255, 255, 255);
388 COGL_BUFFER_BIT_COLOR |
389 COGL_BUFFER_BIT_DEPTH);
391 /* Disable dithering (if any) when doing the painting in pick mode */
392 dither_was_on = glIsEnabled (GL_DITHER);
394 glDisable (GL_DITHER);
396 /* Render the entire scence in pick mode - just single colored silhouette's
397 * are drawn offscreen (as we never swap buffers)
399 context->pick_mode = mode;
400 clutter_actor_paint (CLUTTER_ACTOR (stage));
401 context->pick_mode = CLUTTER_PICK_NONE;
404 /* Calls should work under both GL and GLES, note GLES needs RGBA */
405 glGetIntegerv(GL_VIEWPORT, viewport);
407 /* Read the color of the screen co-ords pixel */
408 glReadPixels (x, viewport[3] - y -1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
410 /* Restore whether GL_DITHER was enabled */
412 glEnable (GL_DITHER);
414 if (pixel[0] == 0xff && pixel[1] == 0xff && pixel[2] == 0xff)
415 return CLUTTER_ACTOR (stage);
417 id = _clutter_pixel_to_id (pixel);
419 return clutter_get_actor_by_gid (id);
422 static PangoDirection
423 clutter_get_text_direction (void)
425 PangoDirection dir = PANGO_DIRECTION_LTR;
426 const gchar *direction;
428 direction = g_getenv ("CLUTTER_TEXT_DIRECTION");
429 if (direction && *direction != '\0')
431 if (strcmp (direction, "rtl") == 0)
432 dir = PANGO_DIRECTION_RTL;
433 else if (strcmp (direction, "ltr") == 0)
434 dir = PANGO_DIRECTION_LTR;
438 /* Translate to default:RTL if you want your widgets
439 * to be RTL, otherwise translate to default:LTR.
441 * Do *not* translate it to "predefinito:LTR": if it
442 * it isn't default:LTR or default:RTL it will not work
444 char *e = _("default:LTR");
446 if (strcmp (e, "default:RTL") == 0)
447 dir = PANGO_DIRECTION_RTL;
448 else if (strcmp (e, "default:LTR") == 0)
449 dir = PANGO_DIRECTION_LTR;
451 g_warning ("Whoever translated default:LTR did so wrongly.");
458 update_pango_context (ClutterBackend *backend,
459 PangoContext *context)
461 PangoFontDescription *font_desc;
462 const cairo_font_options_t *font_options;
463 const gchar *font_name;
466 /* update the text direction */
467 pango_context_set_base_dir (context, clutter_text_direction);
469 /* get the configuration for the PangoContext from the backend */
470 font_name = clutter_backend_get_font_name (backend);
471 font_options = clutter_backend_get_font_options (backend);
472 resolution = clutter_backend_get_resolution (backend);
474 font_desc = pango_font_description_from_string (font_name);
477 resolution = 96.0; /* fall back */
479 pango_context_set_font_description (context, font_desc);
480 pango_cairo_context_set_font_options (context, font_options);
481 pango_cairo_context_set_resolution (context, resolution);
483 pango_font_description_free (font_desc);
487 _clutter_context_get_pango_context (ClutterMainContext *self)
489 if (G_UNLIKELY (self->pango_context == NULL))
491 PangoContext *context;
493 context = cogl_pango_font_map_create_context (self->font_map);
494 self->pango_context = context;
496 g_signal_connect (self->backend, "resolution-changed",
497 G_CALLBACK (update_pango_context),
498 self->pango_context);
499 g_signal_connect (self->backend, "font-changed",
500 G_CALLBACK (update_pango_context),
501 self->pango_context);
504 update_pango_context (self->backend, self->pango_context);
506 return self->pango_context;
510 _clutter_context_create_pango_context (ClutterMainContext *self)
512 PangoContext *context;
514 context = cogl_pango_font_map_create_context (self->font_map);
515 update_pango_context (self->backend, context);
523 * Terminates the Clutter mainloop.
526 clutter_main_quit (void)
528 g_return_if_fail (main_loops != NULL);
530 g_main_loop_quit (main_loops->data);
534 * clutter_main_level:
536 * Retrieves the depth of the Clutter mainloop.
538 * Return value: The level of the mainloop.
541 clutter_main_level (void)
543 return clutter_main_loop_level;
549 * Starts the Clutter mainloop.
556 /* Make sure there is a context */
559 if (!clutter_is_initialized)
561 g_warning ("Called clutter_main() but Clutter wasn't initialised. "
562 "You must call clutter_init() first.");
568 clutter_main_loop_level++;
570 loop = g_main_loop_new (NULL, TRUE);
571 main_loops = g_slist_prepend (main_loops, loop);
573 #ifdef HAVE_CLUTTER_FRUITY
574 /* clutter fruity creates an application that forwards events and manually
577 clutter_fruity_main ();
579 if (g_main_loop_is_running (main_loops->data))
581 clutter_threads_leave ();
582 g_main_loop_run (loop);
583 clutter_threads_enter ();
587 main_loops = g_slist_remove (main_loops, loop);
589 g_main_loop_unref (loop);
591 clutter_main_loop_level--;
597 clutter_threads_impl_lock (void)
599 if (clutter_threads_mutex)
600 g_mutex_lock (clutter_threads_mutex);
604 clutter_threads_impl_unlock (void)
606 if (clutter_threads_mutex)
607 g_mutex_unlock (clutter_threads_mutex);
611 * clutter_threads_init:
613 * Initialises the Clutter threading mechanism, so that Clutter API can be
614 * called by multiple threads, using clutter_threads_enter() and
615 * clutter_threads_leave() to mark the critical sections.
617 * You must call g_thread_init() before this function.
619 * This function must be called before clutter_init().
624 clutter_threads_init (void)
626 if (!g_thread_supported ())
627 g_error ("g_thread_init() must be called before clutter_threads_init()");
629 clutter_threads_mutex = g_mutex_new ();
631 if (!clutter_threads_lock)
632 clutter_threads_lock = clutter_threads_impl_lock;
634 if (!clutter_threads_unlock)
635 clutter_threads_unlock = clutter_threads_impl_unlock;
639 * clutter_threads_set_lock_functions:
640 * @enter_fn: function called when aquiring the Clutter main lock
641 * @leave_fn: function called when releasing the Clutter main lock
643 * Allows the application to replace the standard method that
644 * Clutter uses to protect its data structures. Normally, Clutter
645 * creates a single #GMutex that is locked by clutter_threads_enter(),
646 * and released by clutter_threads_leave(); using this function an
647 * application provides, instead, a function @enter_fn that is
648 * called by clutter_threads_enter() and a function @leave_fn that is
649 * called by clutter_threads_leave().
651 * The functions must provide at least same locking functionality
652 * as the default implementation, but can also do extra application
653 * specific processing.
655 * As an example, consider an application that has its own recursive
656 * lock that when held, holds the Clutter lock as well. When Clutter
657 * unlocks the Clutter lock when entering a recursive main loop, the
658 * application must temporarily release its lock as well.
660 * Most threaded Clutter apps won't need to use this method.
662 * This method must be called before clutter_threads_init(), and cannot
663 * be called multiple times.
668 clutter_threads_set_lock_functions (GCallback enter_fn,
671 g_return_if_fail (clutter_threads_lock == NULL &&
672 clutter_threads_unlock == NULL);
674 clutter_threads_lock = enter_fn;
675 clutter_threads_unlock = leave_fn;
682 GDestroyNotify notify;
683 } ClutterThreadsDispatch;
686 clutter_threads_dispatch (gpointer data)
688 ClutterThreadsDispatch *dispatch = data;
689 gboolean ret = FALSE;
691 clutter_threads_enter ();
693 if (!g_source_is_destroyed (g_main_current_source ()))
694 ret = dispatch->func (dispatch->data);
696 clutter_threads_leave ();
702 clutter_threads_dispatch_free (gpointer data)
704 ClutterThreadsDispatch *dispatch = data;
706 /* XXX - we cannot hold the thread lock here because the main loop
707 * might destroy a source while still in the dispatcher function; so
708 * knowing whether the lock is being held or not is not known a priori.
710 * see bug: http://bugzilla.gnome.org/show_bug.cgi?id=459555
712 if (dispatch->notify)
713 dispatch->notify (dispatch->data);
715 g_slice_free (ClutterThreadsDispatch, dispatch);
719 * clutter_threads_add_idle_full:
720 * @priority: the priority of the timeout source. Typically this will be in the
721 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE
722 * @func: function to call
723 * @data: data to pass to the function
724 * @notify: functio to call when the idle source is removed
726 * Adds a function to be called whenever there are no higher priority
727 * events pending. If the function returns %FALSE it is automatically
728 * removed from the list of event sources and will not be called again.
730 * This function can be considered a thread-safe variant of g_idle_add_full():
731 * it will call @function while holding the Clutter lock. It is logically
732 * equivalent to the following implementation:
736 * idle_safe_callback (gpointer data)
738 * SafeClosure *closure = data;
739 * gboolean res = FALSE;
741 * /* mark the critical section */
743 * clutter_threads_enter();
745 * /* the callback does not need to acquire the Clutter
746 * * lock itself, as it is held by the this proxy handler
748 * res = closure->callback (closure->data);
750 * clutter_threads_leave();
755 * add_safe_idle (GSourceFunc callback,
758 * SafeClosure *closure = g_new0 (SafeClosure, 1);
760 * closure->callback = callback;
761 * closure->data = data;
763 * return g_add_idle_full (G_PRIORITY_DEFAULT_IDLE,
764 * idle_safe_callback,
770 * This function should be used by threaded applications to make sure
771 * that @func is emitted under the Clutter threads lock and invoked
772 * from the same thread that started the Clutter main loop. For instance,
773 * it can be used to update the UI using the results from a worker
778 * update_ui (gpointer data)
780 * SomeClosure *closure = data;
782 * /* it is safe to call Clutter API from this function because
783 * * it is invoked from the same thread that started the main
784 * * loop and under the Clutter thread lock
786 * clutter_label_set_text (CLUTTER_LABEL (closure->label),
789 * g_object_unref (closure->label);
795 * /* within another thread */
796 * closure = g_new0 (SomeClosure, 1);
797 * /* always take a reference on GObject instances */
798 * closure->label = g_object_ref (my_application->label);
799 * closure->text = g_strdup (processed_text_to_update_the_label);
801 * clutter_threads_add_idle_full (G_PRIORITY_HIGH_IDLE,
807 * Return value: the ID (greater than 0) of the event source.
812 clutter_threads_add_idle_full (gint priority,
815 GDestroyNotify notify)
817 ClutterThreadsDispatch *dispatch;
819 g_return_val_if_fail (func != NULL, 0);
821 dispatch = g_slice_new (ClutterThreadsDispatch);
822 dispatch->func = func;
823 dispatch->data = data;
824 dispatch->notify = notify;
826 return g_idle_add_full (priority,
827 clutter_threads_dispatch, dispatch,
828 clutter_threads_dispatch_free);
832 * clutter_threads_add_idle:
833 * @func: function to call
834 * @data: data to pass to the function
836 * Simple wrapper around clutter_threads_add_idle_full() using the
839 * Return value: the ID (greater than 0) of the event source.
844 clutter_threads_add_idle (GSourceFunc func,
847 g_return_val_if_fail (func != NULL, 0);
849 return clutter_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE,
855 * clutter_threads_add_timeout_full:
856 * @priority: the priority of the timeout source. Typically this will be in the
857 * range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
858 * @interval: the time between calls to the function, in milliseconds
859 * @func: function to call
860 * @data: data to pass to the function
861 * @notify: function to call when the timeout source is removed
863 * Sets a function to be called at regular intervals holding the Clutter
864 * threads lock, with the given priority. The function is called repeatedly
865 * until it returns %FALSE, at which point the timeout is automatically
866 * removed and the function will not be called again. The @notify function
867 * is called when the timeout is removed.
869 * The first call to the function will be at the end of the first @interval.
871 * It is important to note that, due to how the Clutter main loop is
872 * implemented, the timing will not be accurate and it will not try to
873 * "keep up" with the interval. A more reliable source is available
874 * using clutter_threads_add_frame_source_full(), which is also internally
875 * used by #ClutterTimeline.
877 * See also clutter_threads_add_idle_full().
879 * Return value: the ID (greater than 0) of the event source.
884 clutter_threads_add_timeout_full (gint priority,
888 GDestroyNotify notify)
890 ClutterThreadsDispatch *dispatch;
892 g_return_val_if_fail (func != NULL, 0);
894 dispatch = g_slice_new (ClutterThreadsDispatch);
895 dispatch->func = func;
896 dispatch->data = data;
897 dispatch->notify = notify;
899 return g_timeout_add_full (priority,
901 clutter_threads_dispatch, dispatch,
902 clutter_threads_dispatch_free);
906 * clutter_threads_add_timeout:
907 * @interval: the time between calls to the function, in milliseconds
908 * @func: function to call
909 * @data: data to pass to the function
911 * Simple wrapper around clutter_threads_add_timeout_full().
913 * Return value: the ID (greater than 0) of the event source.
918 clutter_threads_add_timeout (guint interval,
922 g_return_val_if_fail (func != NULL, 0);
924 return clutter_threads_add_timeout_full (G_PRIORITY_DEFAULT,
931 * clutter_threads_add_frame_source_full:
932 * @priority: the priority of the frame source. Typically this will be in the
933 * range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
934 * @fps: the number of times per second to call the function
935 * @func: function to call
936 * @data: data to pass to the function
937 * @notify: function to call when the timeout source is removed
939 * Sets a function to be called at regular intervals holding the Clutter
940 * threads lock, with the given priority. The function is called repeatedly
941 * until it returns %FALSE, at which point the timeout is automatically
942 * removed and the function will not be called again. The @notify function
943 * is called when the timeout is removed.
945 * This function is similar to clutter_threads_add_timeout_full()
946 * except that it will try to compensate for delays. For example, if
947 * @func takes half the interval time to execute then the function
948 * will be called again half the interval time after it finished. In
949 * contrast clutter_threads_add_timeout_full() would not fire until a
950 * full interval after the function completes so the delay between
951 * calls would be @interval * 1.5. This function does not however try
952 * to invoke the function multiple times to catch up missing frames if
953 * @func takes more than @interval ms to execute.
955 * See also clutter_threads_add_idle_full().
957 * Return value: the ID (greater than 0) of the event source.
962 clutter_threads_add_frame_source_full (gint priority,
966 GDestroyNotify notify)
968 ClutterThreadsDispatch *dispatch;
970 g_return_val_if_fail (func != NULL, 0);
972 dispatch = g_slice_new (ClutterThreadsDispatch);
973 dispatch->func = func;
974 dispatch->data = data;
975 dispatch->notify = notify;
977 return clutter_frame_source_add_full (priority,
979 clutter_threads_dispatch, dispatch,
980 clutter_threads_dispatch_free);
984 * clutter_threads_add_frame_source:
985 * @fps: the number of times per second to call the function
986 * @func: function to call
987 * @data: data to pass to the function
989 * Simple wrapper around clutter_threads_add_frame_source_full().
991 * Return value: the ID (greater than 0) of the event source.
996 clutter_threads_add_frame_source (guint fps,
1000 g_return_val_if_fail (func != NULL, 0);
1002 return clutter_threads_add_frame_source_full (G_PRIORITY_DEFAULT,
1009 * clutter_threads_enter:
1011 * Locks the Clutter thread lock.
1016 clutter_threads_enter (void)
1018 if (clutter_threads_lock)
1019 (* clutter_threads_lock) ();
1023 * clutter_threads_leave:
1025 * Unlocks the Clutter thread lock.
1030 clutter_threads_leave (void)
1032 if (clutter_threads_unlock)
1033 (* clutter_threads_unlock) ();
1038 * clutter_get_debug_enabled:
1040 * Check if clutter has debugging turned on.
1042 * Return value: TRUE if debugging is turned on, FALSE otherwise.
1045 clutter_get_debug_enabled (void)
1047 #ifdef CLUTTER_ENABLE_DEBUG
1048 return clutter_debug_flags != 0;
1054 ClutterMainContext *
1055 clutter_context_get_default (void)
1057 if (G_UNLIKELY(!ClutterCntx))
1059 ClutterMainContext *ctx;
1061 ClutterCntx = ctx = g_new0 (ClutterMainContext, 1);
1062 ctx->backend = g_object_new (_clutter_backend_impl_get_type (), NULL);
1064 ctx->is_initialized = FALSE;
1065 ctx->motion_events_per_actor = TRUE;
1067 ctx->master_clock = _clutter_master_clock_get_default ();
1069 #ifdef CLUTTER_ENABLE_DEBUG
1070 ctx->timer = g_timer_new ();
1071 g_timer_start (ctx->timer);
1079 * clutter_get_timestamp:
1081 * Returns the approximate number of microseconds passed since clutter was
1084 * Return value: Number of microseconds since clutter_init() was called.
1087 clutter_get_timestamp (void)
1089 #ifdef CLUTTER_ENABLE_DEBUG
1090 ClutterMainContext *ctx;
1093 ctx = clutter_context_get_default ();
1095 /* FIXME: may need a custom timer for embedded setups */
1096 seconds = g_timer_elapsed (ctx->timer, NULL);
1098 return (gulong)(seconds / 1.0e-6);
1105 clutter_arg_direction_cb (const char *key,
1109 clutter_text_direction =
1110 (strcmp (value, "rtl") == 0) ? PANGO_DIRECTION_RTL
1111 : PANGO_DIRECTION_LTR;
1116 #ifdef CLUTTER_ENABLE_DEBUG
1118 clutter_arg_debug_cb (const char *key,
1122 clutter_debug_flags |=
1123 g_parse_debug_string (value,
1125 G_N_ELEMENTS (clutter_debug_keys));
1130 clutter_arg_no_debug_cb (const char *key,
1134 clutter_debug_flags &=
1135 ~g_parse_debug_string (value,
1137 G_N_ELEMENTS (clutter_debug_keys));
1140 #endif /* CLUTTER_ENABLE_DEBUG */
1143 clutter_init_error_quark (void)
1145 return g_quark_from_static_string ("clutter-init-error-quark");
1148 static ClutterInitError
1149 clutter_init_real (GError **error)
1151 ClutterMainContext *ctx;
1152 ClutterActor *stage;
1154 ClutterBackend *backend;
1156 /* Note, creates backend if not already existing, though parse args will
1157 * have likely created it
1159 ctx = clutter_context_get_default ();
1160 backend = ctx->backend;
1162 if (!ctx->options_parsed)
1164 g_set_error (error, CLUTTER_INIT_ERROR,
1165 CLUTTER_INIT_ERROR_INTERNAL,
1166 "When using clutter_get_option_group_without_init() "
1167 "you must parse options before calling clutter_init()");
1169 return CLUTTER_INIT_ERROR_INTERNAL;
1173 * Call backend post parse hooks.
1175 if (!_clutter_backend_post_parse (backend, error))
1176 return CLUTTER_INIT_ERROR_BACKEND;
1178 /* Stage will give us a GL Context etc */
1179 stage = clutter_stage_get_default ();
1183 g_set_error (error, CLUTTER_INIT_ERROR,
1184 CLUTTER_INIT_ERROR_INTERNAL,
1185 "Unable to create the default stage");
1187 g_critical ("Unable to create the default stage");
1189 return CLUTTER_INIT_ERROR_INTERNAL;
1192 clutter_stage_set_title (CLUTTER_STAGE (stage), g_get_prgname ());
1194 clutter_actor_realize (stage);
1196 if (!CLUTTER_ACTOR_IS_REALIZED (stage))
1199 g_set_error (error, CLUTTER_INIT_ERROR,
1200 CLUTTER_INIT_ERROR_INTERNAL,
1201 "Unable to realize the default stage");
1203 g_critical ("Unable to realize the default stage");
1205 return CLUTTER_INIT_ERROR_INTERNAL;
1208 /* Now we can safely assume we have a valid GL context and can
1209 * start issueing cogl commands
1213 * Resolution requires display to be open, so can only be queried after
1214 * the post_parse hooks run.
1216 * NB: cogl_pango requires a Cogl context.
1218 ctx->font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new ());
1220 resolution = clutter_backend_get_resolution (ctx->backend);
1221 cogl_pango_font_map_set_resolution (ctx->font_map, resolution);
1223 if (G_LIKELY (!clutter_disable_mipmap_text))
1224 cogl_pango_font_map_set_use_mipmapping (ctx->font_map, TRUE);
1226 clutter_text_direction = clutter_get_text_direction ();
1229 /* Figure out framebuffer masks used for pick */
1230 cogl_get_bitmasks (&ctx->fb_r_mask, &ctx->fb_g_mask, &ctx->fb_b_mask, NULL);
1232 ctx->fb_r_mask_used = ctx->fb_r_mask;
1233 ctx->fb_g_mask_used = ctx->fb_g_mask;
1234 ctx->fb_b_mask_used = ctx->fb_b_mask;
1236 /* XXX - describe what "fuzzy picking" is */
1237 if (clutter_use_fuzzy_picking)
1239 ctx->fb_r_mask_used--;
1240 ctx->fb_g_mask_used--;
1241 ctx->fb_b_mask_used--;
1244 /* Initiate event collection */
1245 _clutter_backend_init_events (ctx->backend);
1247 /* finally features - will call to backend and cogl */
1248 _clutter_feature_init ();
1250 clutter_is_initialized = TRUE;
1251 ctx->is_initialized = TRUE;
1253 return CLUTTER_INIT_SUCCESS;
1256 static GOptionEntry clutter_args[] = {
1257 { "clutter-show-fps", 0, 0, G_OPTION_ARG_NONE, &clutter_show_fps,
1258 N_("Show frames per second"), NULL },
1259 { "clutter-default-fps", 0, 0, G_OPTION_ARG_INT, &clutter_default_fps,
1260 N_("Default frame rate"), "FPS" },
1261 { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &clutter_fatal_warnings,
1262 N_("Make all warnings fatal"), NULL },
1263 { "clutter-text-direction", 0, 0, G_OPTION_ARG_CALLBACK,
1264 clutter_arg_direction_cb,
1265 N_("Direction for the text"), "DIRECTION" },
1266 { "clutter-disable-mipmapped-text", 0, 0, G_OPTION_ARG_NONE,
1267 &clutter_disable_mipmap_text,
1268 N_("Disable mipmapping on text"), NULL },
1269 { "clutter-use-fuzzy-picking", 0, 0, G_OPTION_ARG_NONE,
1270 &clutter_use_fuzzy_picking,
1271 N_("Use 'fuzzy' picking"), NULL },
1272 #ifdef CLUTTER_ENABLE_DEBUG
1273 { "clutter-debug", 0, 0, G_OPTION_ARG_CALLBACK, clutter_arg_debug_cb,
1274 N_("Clutter debugging flags to set"), "FLAGS" },
1275 { "clutter-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, clutter_arg_no_debug_cb,
1276 N_("Clutter debugging flags to unset"), "FLAGS" },
1277 #endif /* CLUTTER_ENABLE_DEBUG */
1281 /* pre_parse_hook: initialise variables depending on environment
1282 * variables; these variables might be overridden by the command
1283 * line arguments that are going to be parsed after.
1286 pre_parse_hook (GOptionContext *context,
1287 GOptionGroup *group,
1291 ClutterMainContext *clutter_context;
1292 ClutterBackend *backend;
1293 const char *env_string;
1295 if (clutter_is_initialized)
1298 if (setlocale (LC_ALL, "") == NULL)
1299 g_warning ("Locale not supported by C library.\n"
1300 "Using the fallback 'C' locale.");
1302 clutter_context = clutter_context_get_default ();
1304 clutter_context->id_pool = clutter_id_pool_new (256);
1306 backend = clutter_context->backend;
1307 g_assert (CLUTTER_IS_BACKEND (backend));
1309 #ifdef CLUTTER_ENABLE_DEBUG
1310 env_string = g_getenv ("CLUTTER_DEBUG");
1311 if (env_string != NULL)
1313 clutter_debug_flags =
1314 g_parse_debug_string (env_string,
1316 G_N_ELEMENTS (clutter_debug_keys));
1319 #endif /* CLUTTER_ENABLE_DEBUG */
1321 env_string = g_getenv ("CLUTTER_SHOW_FPS");
1323 clutter_show_fps = TRUE;
1325 env_string = g_getenv ("CLUTTER_DEFAULT_FPS");
1328 gint default_fps = g_ascii_strtoll (env_string, NULL, 10);
1330 clutter_default_fps = CLAMP (default_fps, 1, 1000);
1333 env_string = g_getenv ("CLUTTER_DISABLE_MIPMAPPED_TEXT");
1335 clutter_disable_mipmap_text = TRUE;
1337 #ifdef HAVE_CLUTTER_FRUITY
1338 /* we always enable fuzzy picking in the "fruity" backend */
1339 clutter_use_fuzzy_picking = TRUE;
1341 env_string = g_getenv ("CLUTTER_FUZZY_PICK");
1343 clutter_use_fuzzy_picking = TRUE;
1344 #endif /* HAVE_CLUTTER_FRUITY */
1346 return _clutter_backend_pre_parse (backend, error);
1349 /* post_parse_hook: initialise the context and data structures
1350 * and opens the X display
1353 post_parse_hook (GOptionContext *context,
1354 GOptionGroup *group,
1358 ClutterMainContext *clutter_context;
1359 ClutterBackend *backend;
1361 if (clutter_is_initialized)
1364 clutter_context = clutter_context_get_default ();
1365 backend = clutter_context->backend;
1366 g_assert (CLUTTER_IS_BACKEND (backend));
1368 if (clutter_fatal_warnings)
1370 GLogLevelFlags fatal_mask;
1372 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
1373 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
1374 g_log_set_always_fatal (fatal_mask);
1377 clutter_context->frame_rate = clutter_default_fps;
1378 clutter_context->options_parsed = TRUE;
1381 * If not asked to defer display setup, call clutter_init_real(),
1382 * which in turn calls the backend post parse hooks.
1384 if (!clutter_context->defer_display_setup)
1385 return clutter_init_real (error);
1391 * clutter_get_option_group:
1393 * Returns a #GOptionGroup for the command line arguments recognized
1394 * by Clutter. You should add this group to your #GOptionContext with
1395 * g_option_context_add_group(), if you are using g_option_context_parse()
1396 * to parse your commandline arguments.
1398 * Calling g_option_context_parse() with Clutter's #GOptionGroup will result
1399 * in Clutter's initialization. That is, the following code:
1402 * g_option_context_set_main_group (context, clutter_get_option_group ());
1403 * res = g_option_context_parse (context, &argc, &argc, NULL);
1406 * is functionally equivalent to:
1409 * clutter_init (&argc, &argv);
1412 * After g_option_context_parse() on a #GOptionContext containing the
1413 * Clutter #GOptionGroup has returned %TRUE, Clutter is guaranteed to be
1416 * Return value: (transfer full): a #GOptionGroup for the commandline arguments
1417 * recognized by Clutter
1422 clutter_get_option_group (void)
1424 ClutterMainContext *context;
1425 GOptionGroup *group;
1427 clutter_base_init ();
1429 context = clutter_context_get_default ();
1431 group = g_option_group_new ("clutter",
1432 _("Clutter Options"),
1433 _("Show Clutter Options"),
1437 g_option_group_set_parse_hooks (group, pre_parse_hook, post_parse_hook);
1438 g_option_group_add_entries (group, clutter_args);
1439 g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
1441 /* add backend-specific options */
1442 _clutter_backend_add_options (context->backend, group);
1448 * clutter_get_option_group_without_init:
1450 * Returns a #GOptionGroup for the command line arguments recognized
1451 * by Clutter. You should add this group to your #GOptionContext with
1452 * g_option_context_add_group(), if you are using g_option_context_parse()
1453 * to parse your commandline arguments. Unlike clutter_get_option_group(),
1454 * calling g_option_context_parse() with the #GOptionGroup returned by this
1455 * function requires a subsequent explicit call to clutter_init(); use this
1456 * function when needing to set foreign display connection with
1457 * clutter_x11_set_display(), or with gtk_clutter_init().
1459 * Return value: (transfer full): a #GOptionGroup for the commandline arguments
1460 * recognized by Clutter
1465 clutter_get_option_group_without_init (void)
1467 ClutterMainContext *context;
1468 GOptionGroup *group;
1470 clutter_base_init ();
1472 context = clutter_context_get_default ();
1473 context->defer_display_setup = TRUE;
1475 group = clutter_get_option_group ();
1480 /* Note that the gobject-introspection annotations for the argc/argv
1481 * parameters do not produce the right result; however, they do
1482 * allow the common case of argc=NULL, argv=NULL to work.
1486 * clutter_init_with_args:
1487 * @argc: (inout): a pointer to the number of command line arguments
1488 * @argv: (array length=argc) (inout): a pointer to the array of command line arguments
1489 * @parameter_string: a string which is displayed in the
1490 * first line of <option>--help</option> output, after
1491 * <literal><replaceable>programname</replaceable> [OPTION...]</literal>
1492 * @entries: a %NULL terminated array of #GOptionEntry<!-- -->s
1493 * describing the options of your program
1494 * @translation_domain: a translation domain to use for translating
1495 * the <option>--help</option> output for the options in @entries
1496 * with gettext(), or %NULL
1497 * @error: a return location for a #GError
1499 * This function does the same work as clutter_init(). Additionally,
1500 * it allows you to add your own command line options, and it
1501 * automatically generates nicely formatted <option>--help</option>
1502 * output. Note that your program will be terminated after writing
1503 * out the help output. Also note that, in case of error, the
1504 * error message will be placed inside @error instead of being
1505 * printed on the display.
1507 * Return value: %CLUTTER_INIT_SUCCESS if Clutter has been successfully
1508 * initialised, or other values or #ClutterInitError in case of
1514 clutter_init_with_args (int *argc,
1516 const char *parameter_string,
1517 GOptionEntry *entries,
1518 const char *translation_domain,
1521 GOptionContext *context;
1522 GOptionGroup *group;
1524 ClutterMainContext *ctx;
1526 if (clutter_is_initialized)
1527 return CLUTTER_INIT_SUCCESS;
1529 clutter_base_init ();
1531 ctx = clutter_context_get_default ();
1533 if (!ctx->defer_display_setup)
1535 if (argc && *argc > 0 && *argv)
1536 g_set_prgname ((*argv)[0]);
1538 context = g_option_context_new (parameter_string);
1540 group = clutter_get_option_group ();
1541 g_option_context_add_group (context, group);
1543 group = cogl_get_option_group ();
1544 g_option_context_add_group (context, group);
1547 g_option_context_add_main_entries (context, entries, translation_domain);
1549 res = g_option_context_parse (context, argc, argv, error);
1550 g_option_context_free (context);
1552 /* if res is FALSE, the error is filled for
1553 * us by g_option_context_parse()
1557 /* if there has been an error in the initialization, the
1558 * error id will be preserved inside the GError code
1560 if (error && *error)
1561 return (*error)->code;
1563 return CLUTTER_INIT_ERROR_INTERNAL;
1566 return CLUTTER_INIT_SUCCESS;
1569 return clutter_init_real (error);
1573 clutter_parse_args (int *argc,
1576 GOptionContext *option_context;
1577 GOptionGroup *clutter_group, *cogl_group;
1578 GError *error = NULL;
1579 gboolean ret = TRUE;
1581 if (clutter_is_initialized)
1584 option_context = g_option_context_new (NULL);
1585 g_option_context_set_ignore_unknown_options (option_context, TRUE);
1586 g_option_context_set_help_enabled (option_context, FALSE);
1588 /* Initiate any command line options from the backend */
1590 clutter_group = clutter_get_option_group ();
1591 g_option_context_set_main_group (option_context, clutter_group);
1593 cogl_group = cogl_get_option_group ();
1594 g_option_context_add_group (option_context, cogl_group);
1596 if (!g_option_context_parse (option_context, argc, argv, &error))
1600 g_warning ("%s", error->message);
1601 g_error_free (error);
1607 g_option_context_free (option_context);
1614 * @argc: (inout): The number of arguments in @argv
1615 * @argv: (array length=argc) (inout): A pointer to an array of arguments.
1617 * It will initialise everything needed to operate with Clutter and
1618 * parses some standard command line options. @argc and @argv are
1619 * adjusted accordingly so your own code will never see those standard
1622 * Return value: 1 on success, < 0 on failure.
1625 clutter_init (int *argc,
1628 ClutterMainContext *ctx;
1629 GError *error = NULL;
1631 if (clutter_is_initialized)
1632 return CLUTTER_INIT_SUCCESS;
1634 clutter_base_init ();
1636 ctx = clutter_context_get_default ();
1638 if (!ctx->defer_display_setup)
1640 if (argc && *argc > 0 && *argv)
1641 g_set_prgname ((*argv)[0]);
1643 /* parse_args will trigger backend creation and things like
1644 * DISPLAY connection etc.
1646 if (clutter_parse_args (argc, argv) == FALSE)
1648 CLUTTER_NOTE (MISC, "failed to parse arguments.");
1649 return CLUTTER_INIT_ERROR_INTERNAL;
1652 return CLUTTER_INIT_SUCCESS;
1655 return clutter_init_real (&error);
1659 _clutter_boolean_handled_accumulator (GSignalInvocationHint *ihint,
1660 GValue *return_accu,
1661 const GValue *handler_return,
1664 gboolean continue_emission;
1665 gboolean signal_handled;
1667 signal_handled = g_value_get_boolean (handler_return);
1668 g_value_set_boolean (return_accu, signal_handled);
1669 continue_emission = !signal_handled;
1671 return continue_emission;
1675 event_click_count_generate (ClutterEvent *event)
1677 /* multiple button click detection */
1678 static gint click_count = 0;
1679 static gint previous_x = -1;
1680 static gint previous_y = -1;
1681 static guint32 previous_time = 0;
1682 static gint previous_button_number = -1;
1684 ClutterBackend *backend;
1685 guint double_click_time;
1686 guint double_click_distance;
1688 backend = clutter_context_get_default ()->backend;
1689 double_click_distance = clutter_backend_get_double_click_distance (backend);
1690 double_click_time = clutter_backend_get_double_click_time (backend);
1692 if (event->button.device != NULL)
1694 click_count = event->button.device->click_count;
1695 previous_x = event->button.device->previous_x;
1696 previous_y = event->button.device->previous_y;
1697 previous_time = event->button.device->previous_time;
1698 previous_button_number = event->button.device->previous_button_number;
1701 switch (event->type)
1703 case CLUTTER_BUTTON_PRESS:
1704 case CLUTTER_SCROLL:
1705 /* check if we are in time and within distance to increment an
1706 * existing click count
1708 if (event->button.time < previous_time + double_click_time &&
1709 (ABS (event->button.x - previous_x) <= double_click_distance) &&
1710 (ABS (event->button.y - previous_y) <= double_click_distance)
1711 && event->button.button == previous_button_number)
1715 else /* start a new click count*/
1718 previous_button_number = event->button.button;
1721 /* store time and position for this click for comparison with
1724 previous_time = event->button.time;
1725 previous_x = event->button.x;
1726 previous_y = event->button.y;
1729 case CLUTTER_BUTTON_RELEASE:
1730 event->button.click_count=click_count;
1736 if (event->button.device != NULL)
1738 event->button.device->click_count = click_count;
1739 event->button.device->previous_x = previous_x;
1740 event->button.device->previous_y = previous_y;
1741 event->button.device->previous_time = previous_time;
1742 event->button.device->previous_button_number = previous_button_number;
1748 emit_event (ClutterEvent *event,
1749 gboolean is_key_event)
1751 static gboolean lock = FALSE;
1753 GPtrArray *event_tree = NULL;
1754 ClutterActor *actor;
1757 if (!event->any.source)
1759 CLUTTER_NOTE (EVENT, "No source set, discarding event");
1763 /* reentrancy check */
1766 g_warning ("Tried emitting event during event delivery, bailing out.n");
1772 event_tree = g_ptr_array_sized_new (64);
1774 actor = event->any.source;
1776 /* Build 'tree' of emitters for the event */
1779 ClutterActor *parent;
1781 parent = clutter_actor_get_parent (actor);
1783 if (clutter_actor_get_reactive (actor) ||
1784 parent == NULL || /* stage gets all events */
1785 is_key_event) /* keyboard events are always emitted */
1787 g_ptr_array_add (event_tree, g_object_ref (actor));
1794 for (i = event_tree->len - 1; i >= 0; i--)
1795 if (clutter_actor_event (g_ptr_array_index (event_tree, i), event, TRUE))
1799 for (i = 0; i < event_tree->len; i++)
1800 if (clutter_actor_event (g_ptr_array_index (event_tree, i), event, FALSE))
1804 for (i = 0; i < event_tree->len; i++)
1805 g_object_unref (g_ptr_array_index (event_tree, i));
1807 g_ptr_array_free (event_tree, TRUE);
1813 * Emits a pointer event after having prepared the event for delivery (setting
1814 * source, computing click_count, generating enter/leave etc.).
1818 emit_pointer_event (ClutterEvent *event,
1819 ClutterInputDevice *device)
1821 /* Using the global variable directly, since it has to be initialized
1824 ClutterMainContext *context = ClutterCntx;
1826 if (G_UNLIKELY (context->pointer_grab_actor != NULL &&
1830 clutter_actor_event (context->pointer_grab_actor, event, FALSE);
1832 else if (G_UNLIKELY (device != NULL &&
1833 device->pointer_grab_actor != NULL))
1835 /* per device grab */
1836 clutter_actor_event (device->pointer_grab_actor, event, FALSE);
1840 /* no grab, time to capture and bubble */
1841 emit_event (event, FALSE);
1846 emit_keyboard_event (ClutterEvent *event)
1848 ClutterMainContext *context = ClutterCntx;
1850 if (G_UNLIKELY (context->keyboard_grab_actor != NULL))
1851 clutter_actor_event (context->keyboard_grab_actor, event, FALSE);
1853 emit_event (event, TRUE);
1857 unset_motion_last_actor (ClutterActor *actor, ClutterInputDevice *dev)
1859 ClutterMainContext *context = ClutterCntx;
1862 context->motion_last_actor = NULL;
1864 dev->motion_last_actor = NULL;
1867 static ClutterInputDevice * clutter_event_get_device (ClutterEvent *event);
1869 /* This function should perhaps be public and in clutter-event.c ?
1871 static ClutterInputDevice *
1872 clutter_event_get_device (ClutterEvent *event)
1874 g_return_val_if_fail (event != NULL, NULL);
1876 switch (event->type)
1878 case CLUTTER_NOTHING:
1879 case CLUTTER_STAGE_STATE:
1880 case CLUTTER_DESTROY_NOTIFY:
1881 case CLUTTER_CLIENT_MESSAGE:
1882 case CLUTTER_DELETE:
1887 case CLUTTER_BUTTON_PRESS:
1888 case CLUTTER_BUTTON_RELEASE:
1889 return event->button.device;
1890 case CLUTTER_MOTION:
1891 return event->motion.device;
1892 case CLUTTER_SCROLL:
1893 return event->scroll.device;
1895 case CLUTTER_KEY_PRESS:
1896 case CLUTTER_KEY_RELEASE:
1903 set_motion_last_actor (ClutterActor *motion_current_actor,
1904 ClutterInputDevice *device)
1906 ClutterMainContext *context = ClutterCntx;
1907 ClutterActor *last_actor = context->motion_last_actor;
1910 last_actor = device->motion_last_actor;
1912 if (last_actor && last_actor != motion_current_actor)
1914 g_signal_handlers_disconnect_by_func
1916 G_CALLBACK (unset_motion_last_actor),
1920 if (motion_current_actor && last_actor != motion_current_actor)
1922 g_signal_connect (motion_current_actor, "destroy",
1923 G_CALLBACK (unset_motion_last_actor),
1928 device->motion_last_actor = motion_current_actor;
1930 context->motion_last_actor = motion_current_actor;
1934 generate_enter_leave_events (ClutterEvent *event)
1936 ClutterMainContext *context = ClutterCntx;
1937 ClutterActor *motion_current_actor = event->motion.source;
1938 ClutterActor *last_actor = context->motion_last_actor;
1939 ClutterInputDevice *device = clutter_event_get_device (event);
1942 last_actor = device->motion_last_actor;
1944 if (last_actor != motion_current_actor)
1946 if (motion_current_actor)
1951 cev.crossing.device = device;
1952 clutter_event_get_coords (event, &x, &y);
1954 if (context->motion_last_actor)
1956 cev.crossing.type = CLUTTER_LEAVE;
1957 cev.crossing.time = event->any.time;
1958 cev.crossing.flags = 0;
1961 cev.crossing.source = last_actor;
1962 cev.crossing.stage = event->any.stage;
1963 cev.crossing.related = motion_current_actor;
1965 emit_pointer_event (&cev, device);
1968 cev.crossing.type = CLUTTER_ENTER;
1969 cev.crossing.time = event->any.time;
1970 cev.crossing.flags = 0;
1973 cev.crossing.source = motion_current_actor;
1974 cev.crossing.stage = event->any.stage;
1976 if (context->motion_last_actor)
1977 cev.crossing.related = last_actor;
1979 cev.crossing.related = NULL;
1981 emit_pointer_event (&cev, device);
1985 set_motion_last_actor (motion_current_actor, device);
1990 * @event: a #ClutterEvent.
1992 * Processes an event. This function should never be called by applications.
1997 clutter_do_event (ClutterEvent *event)
1999 if (!event->any.stage)
2002 /* Instead of processing events when received, we queue them up to
2003 * handle per-frame before animations, layout, and drawing.
2005 * This gives us the chance to reliably compress motion events
2006 * because we've "looked ahead" and know all motion events that
2007 * will occur before drawing the frame.
2009 _clutter_stage_queue_event (event->any.stage, event);
2013 * _clutter_process_event
2014 * @event: a #ClutterEvent.
2016 * Does the actual work of processing an event that was queued earlier
2017 * out of clutter_do_event().
2020 _clutter_process_event (ClutterEvent *event)
2022 /* FIXME: This should probably be clutter_cook_event() - it would
2023 * take a raw event from the backend and 'cook' it so its more tasty.
2026 ClutterMainContext *context;
2027 ClutterBackend *backend;
2028 ClutterActor *stage;
2029 ClutterInputDevice *device = NULL;
2031 context = clutter_context_get_default ();
2032 backend = context->backend;
2033 stage = CLUTTER_ACTOR(event->any.stage);
2038 CLUTTER_TIMESTAMP (EVENT, "Event received");
2040 context->last_event_time = clutter_event_get_time (event);
2042 switch (event->type)
2044 case CLUTTER_NOTHING:
2045 event->any.source = stage;
2049 /* The source is set for generated events, not for events
2050 * resulting from the cursor leaving the stage
2052 if (event->any.source == NULL)
2054 ClutterActor *last_actor = context->motion_last_actor;
2056 if (event->crossing.device != NULL)
2057 last_actor = event->crossing.device->motion_last_actor;
2059 event->any.source = last_actor;
2061 set_motion_last_actor (NULL, event->crossing.device);
2065 emit_pointer_event (event, event->crossing.device);
2068 case CLUTTER_DESTROY_NOTIFY:
2069 case CLUTTER_DELETE:
2070 event->any.source = stage;
2071 /* the stage did not handle the event, so we just quit */
2072 if (!clutter_stage_event (CLUTTER_STAGE (stage), event))
2074 if (stage == clutter_stage_get_default())
2075 clutter_main_quit ();
2077 clutter_actor_destroy (stage);
2082 case CLUTTER_KEY_PRESS:
2083 case CLUTTER_KEY_RELEASE:
2085 ClutterActor *actor = NULL;
2087 /* check that we're not a synthetic event with source set */
2088 if (event->any.source == NULL)
2090 actor = clutter_stage_get_key_focus (CLUTTER_STAGE (stage));
2091 event->any.source = actor;
2092 if (G_UNLIKELY (actor == NULL))
2094 g_warning ("No key focus set, discarding");
2099 emit_keyboard_event (event);
2103 case CLUTTER_MOTION:
2104 device = event->motion.device;
2106 /* Only stage gets motion events if clutter_set_motion_events is TRUE,
2107 * and the event is not a synthetic event with source set.
2109 if (!context->motion_events_per_actor &&
2110 event->any.source == NULL)
2112 /* Only stage gets motion events */
2113 event->any.source = stage;
2116 if (context->pointer_grab_actor != NULL)
2118 clutter_actor_event (context->pointer_grab_actor,
2122 else if (device != NULL && device->pointer_grab_actor != NULL)
2124 clutter_actor_event (device->pointer_grab_actor,
2129 /* Trigger handlers on stage in both capture .. */
2130 if (!clutter_actor_event (stage, event, TRUE))
2132 /* and bubbling phase */
2133 clutter_actor_event (stage, event, FALSE);
2140 case CLUTTER_BUTTON_PRESS:
2141 case CLUTTER_BUTTON_RELEASE:
2142 case CLUTTER_SCROLL:
2144 ClutterActor *actor;
2147 clutter_event_get_coords (event, &x, &y);
2149 /* Only do a pick to find the source if source is not already set
2150 * (as it could be in a synthetic event)
2152 if (event->any.source == NULL)
2154 /* Handle release off stage */
2155 if ((x >= clutter_actor_get_width (stage) ||
2156 y >= clutter_actor_get_height (stage) ||
2159 if (event->type == CLUTTER_BUTTON_RELEASE)
2161 CLUTTER_NOTE (EVENT,
2162 "Release off stage received at %.2f, %.2f",
2165 event->button.source = stage;
2166 emit_pointer_event (event, event->button.device);
2171 /* Map the event to a reactive actor */
2172 actor = _clutter_do_pick (CLUTTER_STAGE (stage),
2174 CLUTTER_PICK_REACTIVE);
2176 event->any.source = actor;
2182 /* use the source already set in the synthetic event */
2183 actor = event->any.source;
2187 /* FIXME: for an optimisation should check if there are
2188 * actually any reactive actors and avoid the pick all together
2189 * (signalling just the stage). Should be big help for gles.
2192 CLUTTER_NOTE (EVENT,
2193 "Reactive event received at %.2f, %.2f - actor: %p",
2197 /* Create, enter/leave events if needed */
2198 generate_enter_leave_events (event);
2200 if (event->type != CLUTTER_MOTION)
2202 /* Generate click count */
2203 event_click_count_generate (event);
2208 switch (event->type)
2210 case CLUTTER_BUTTON_PRESS:
2211 case CLUTTER_BUTTON_RELEASE:
2212 device = event->button.device;
2214 case CLUTTER_SCROLL:
2215 device = event->scroll.device;
2217 case CLUTTER_MOTION:
2218 /* already handled in the MOTION case of the switch */
2224 emit_pointer_event (event, device);
2228 case CLUTTER_STAGE_STATE:
2229 /* fullscreen / focus - forward to stage */
2230 event->any.source = stage;
2231 clutter_stage_event (CLUTTER_STAGE (stage), event);
2234 case CLUTTER_CLIENT_MESSAGE:
2240 * clutter_get_actor_by_gid
2241 * @id: a #ClutterActor ID.
2243 * Retrieves the #ClutterActor with @id.
2245 * Return value: (transfer none): the actor with the passed id or %NULL.
2246 * The returned actor does not have its reference count increased.
2251 clutter_get_actor_by_gid (guint32 id)
2253 ClutterMainContext *context;
2255 context = clutter_context_get_default ();
2257 g_return_val_if_fail (context != NULL, NULL);
2259 return CLUTTER_ACTOR (clutter_id_pool_lookup (context->id_pool, id));
2263 clutter_base_init (void)
2265 static gboolean initialised = FALSE;
2269 GType foo; /* Quiet gcc */
2273 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
2274 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2276 /* initialise GLib type system */
2279 /* CLUTTER_TYPE_ACTOR */
2280 foo = clutter_actor_get_type ();
2285 * clutter_get_default_frame_rate:
2287 * Retrieves the default frame rate. See clutter_set_default_frame_rate().
2289 * Return value: the default frame rate
2294 clutter_get_default_frame_rate (void)
2296 ClutterMainContext *context;
2298 context = clutter_context_get_default ();
2300 return context->frame_rate;
2304 * clutter_set_default_frame_rate:
2305 * @frames_per_sec: the new default frame rate
2307 * Sets the default frame rate. This frame rate will be used to limit
2308 * the number of frames drawn if Clutter is not able to synchronize
2309 * with the vertical refresh rate of the display. When synchronization
2310 * is possible, this value is ignored.
2315 clutter_set_default_frame_rate (guint frames_per_sec)
2317 ClutterMainContext *context;
2319 context = clutter_context_get_default ();
2321 if (context->frame_rate != frames_per_sec)
2322 context->frame_rate = frames_per_sec;
2327 on_pointer_grab_weak_notify (gpointer data,
2328 GObject *where_the_object_was)
2330 ClutterInputDevice *dev = (ClutterInputDevice *)data;
2331 ClutterMainContext *context;
2333 context = clutter_context_get_default ();
2337 dev->pointer_grab_actor = NULL;
2338 clutter_ungrab_pointer_for_device (dev->id);
2342 context->pointer_grab_actor = NULL;
2343 clutter_ungrab_pointer ();
2348 * clutter_grab_pointer:
2349 * @actor: a #ClutterActor
2351 * Grabs pointer events, after the grab is done all pointer related events
2352 * (press, motion, release, enter, leave and scroll) are delivered to this
2353 * actor directly without passing through both capture and bubble phases of
2354 * the event delivery chain. The source set in the event will be the actor
2355 * that would have received the event if the pointer grab was not in effect.
2357 * <note><para>Grabs completely override the entire event delivery chain
2358 * done by Clutter. Pointer grabs should only be used as a last resource;
2359 * using the #ClutterActor::captured-event signal should always be the
2360 * preferred way to intercept event delivery to reactive actors.</para></note>
2362 * If you wish to grab all the pointer events for a specific input device,
2363 * you should use clutter_grab_pointer_for_device().
2368 clutter_grab_pointer (ClutterActor *actor)
2370 ClutterMainContext *context;
2372 g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
2374 context = clutter_context_get_default ();
2376 if (context->pointer_grab_actor == actor)
2379 if (context->pointer_grab_actor)
2381 g_object_weak_unref (G_OBJECT (context->pointer_grab_actor),
2382 on_pointer_grab_weak_notify,
2384 context->pointer_grab_actor = NULL;
2389 context->pointer_grab_actor = actor;
2391 g_object_weak_ref (G_OBJECT (actor),
2392 on_pointer_grab_weak_notify,
2398 * clutter_grab_pointer_for_device:
2399 * @actor: a #ClutterActor
2400 * @id: a device id, or -1
2402 * Grabs all the pointer events coming from the device @id for @actor.
2404 * If @id is -1 then this function is equivalent to clutter_grab_pointer().
2409 clutter_grab_pointer_for_device (ClutterActor *actor,
2412 ClutterInputDevice *dev;
2414 g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
2416 /* essentially a global grab */
2419 clutter_grab_pointer (actor);
2423 dev = clutter_get_input_device_for_id (id);
2428 if (dev->pointer_grab_actor == actor)
2431 if (dev->pointer_grab_actor)
2433 g_object_weak_unref (G_OBJECT (dev->pointer_grab_actor),
2434 on_pointer_grab_weak_notify,
2436 dev->pointer_grab_actor = NULL;
2441 dev->pointer_grab_actor = actor;
2443 g_object_weak_ref (G_OBJECT (actor),
2444 on_pointer_grab_weak_notify,
2451 * clutter_ungrab_pointer:
2453 * Removes an existing grab of the pointer.
2458 clutter_ungrab_pointer (void)
2460 clutter_grab_pointer (NULL);
2464 * clutter_ungrab_pointer_for_device:
2467 * Removes an existing grab of the pointer events for device @id.
2472 clutter_ungrab_pointer_for_device (gint id)
2474 clutter_grab_pointer_for_device (NULL, id);
2479 * clutter_get_pointer_grab:
2481 * Queries the current pointer grab of clutter.
2483 * Return value: (transfer none): the actor currently holding the pointer grab, or NULL if there is no grab.
2488 clutter_get_pointer_grab (void)
2490 ClutterMainContext *context;
2491 context = clutter_context_get_default ();
2493 return context->pointer_grab_actor;
2498 on_keyboard_grab_weak_notify (gpointer data,
2499 GObject *where_the_object_was)
2501 ClutterMainContext *context;
2503 context = clutter_context_get_default ();
2504 context->keyboard_grab_actor = NULL;
2506 clutter_ungrab_keyboard ();
2510 * clutter_grab_keyboard:
2511 * @actor: a #ClutterActor
2513 * Grabs keyboard events, after the grab is done keyboard
2514 * events (#ClutterActor::key-press-event and #ClutterActor::key-release-event)
2515 * are delivered to this actor directly. The source set in the event will be
2516 * the actor that would have received the event if the keyboard grab was not
2519 * Like pointer grabs, keyboard grabs should only be used as a last
2522 * See also clutter_stage_set_key_focus() and clutter_actor_grab_key_focus()
2523 * to perform a "soft" key grab and assign key focus to a specific actor.
2528 clutter_grab_keyboard (ClutterActor *actor)
2530 ClutterMainContext *context;
2532 g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
2534 context = clutter_context_get_default ();
2536 if (context->keyboard_grab_actor == actor)
2539 if (context->keyboard_grab_actor)
2541 g_object_weak_unref (G_OBJECT (context->keyboard_grab_actor),
2542 on_keyboard_grab_weak_notify,
2544 context->keyboard_grab_actor = NULL;
2549 context->keyboard_grab_actor = actor;
2551 g_object_weak_ref (G_OBJECT (actor),
2552 on_keyboard_grab_weak_notify,
2558 * clutter_ungrab_keyboard:
2560 * Removes an existing grab of the keyboard.
2565 clutter_ungrab_keyboard (void)
2567 clutter_grab_keyboard (NULL);
2571 * clutter_get_keyboard_grab:
2573 * Queries the current keyboard grab of clutter.
2575 * Return value: (transfer none): the actor currently holding the keyboard grab, or NULL if there is no grab.
2580 clutter_get_keyboard_grab (void)
2582 ClutterMainContext *context;
2583 context = clutter_context_get_default ();
2585 return context->keyboard_grab_actor;
2589 * clutter_clear_glyph_cache:
2591 * Clears the internal cache of glyphs used by the Pango
2592 * renderer. This will free up some memory and GL texture
2593 * resources. The cache will be automatically refilled as more text is
2599 clutter_clear_glyph_cache (void)
2601 if (CLUTTER_CONTEXT ()->font_map)
2602 cogl_pango_font_map_clear_glyph_cache (CLUTTER_CONTEXT ()->font_map);
2606 * clutter_set_font_flags:
2607 * @flags: The new flags
2609 * Sets the font quality options for subsequent text rendering
2612 * Using mipmapped textures will improve the quality for scaled down
2613 * text but will use more texture memory.
2615 * Enabling hinting improves text quality for static text but may
2616 * introduce some artifacts if the text is animated.
2621 clutter_set_font_flags (ClutterFontFlags flags)
2623 ClutterFontFlags old_flags, changed_flags;
2624 const cairo_font_options_t *font_options;
2625 cairo_font_options_t *new_font_options;
2626 ClutterBackend *backend;
2628 backend = clutter_get_default_backend ();
2630 if (CLUTTER_CONTEXT ()->font_map)
2631 cogl_pango_font_map_set_use_mipmapping (CLUTTER_CONTEXT ()->font_map,
2633 & CLUTTER_FONT_MIPMAPPING) != 0);
2635 old_flags = clutter_get_font_flags ();
2637 font_options = clutter_backend_get_font_options (backend);
2638 new_font_options = cairo_font_options_copy (font_options);
2640 /* Only set the font options that have actually changed so we don't
2641 override a detailed setting from the backend */
2642 changed_flags = old_flags ^ flags;
2644 if ((changed_flags & CLUTTER_FONT_HINTING))
2645 cairo_font_options_set_hint_style (new_font_options,
2646 (flags & CLUTTER_FONT_HINTING)
2647 ? CAIRO_HINT_STYLE_FULL
2648 : CAIRO_HINT_STYLE_NONE);
2650 clutter_backend_set_font_options (backend, new_font_options);
2652 cairo_font_options_destroy (new_font_options);
2654 if (CLUTTER_CONTEXT ()->pango_context)
2655 update_pango_context (backend, CLUTTER_CONTEXT ()->pango_context);
2659 * clutter_get_font_flags:
2661 * Gets the current font flags for rendering text. See
2662 * clutter_set_font_flags().
2664 * Return value: The font flags
2669 clutter_get_font_flags (void)
2671 ClutterMainContext *ctxt = CLUTTER_CONTEXT ();
2672 CoglPangoFontMap *font_map = NULL;
2673 const cairo_font_options_t *font_options;
2674 ClutterFontFlags flags = 0;
2676 font_map = CLUTTER_CONTEXT ()->font_map;
2678 if (G_LIKELY (font_map)
2679 && cogl_pango_font_map_get_use_mipmapping (font_map))
2680 flags |= CLUTTER_FONT_MIPMAPPING;
2682 font_options = clutter_backend_get_font_options (ctxt->backend);
2684 if ((cairo_font_options_get_hint_style (font_options)
2685 != CAIRO_HINT_STYLE_DEFAULT)
2686 && (cairo_font_options_get_hint_style (font_options)
2687 != CAIRO_HINT_STYLE_NONE))
2688 flags |= CLUTTER_FONT_HINTING;
2694 * clutter_get_input_device_for_id:
2697 * Retrieves the #ClutterInputDevice from its id.
2699 * Return value: (transfer none): a #ClutterInputDevice, or %NULL
2703 ClutterInputDevice *
2704 clutter_get_input_device_for_id (gint id)
2707 ClutterInputDevice *device = NULL;
2708 ClutterMainContext *context;
2710 context = clutter_context_get_default ();
2712 for (item = context->input_devices;
2716 device = item->data;
2718 if (device->id == id)
2726 * clutter_get_font_map:
2728 * Retrieves the #PangoFontMap instance used by Clutter.
2729 * You can use the global font map object with the COGL
2732 * Return value: (transfer none): the #PangoFontMap instance. The returned
2733 * value is owned by Clutter and it should never be unreferenced.
2738 clutter_get_font_map (void)
2740 if (CLUTTER_CONTEXT ()->font_map)
2741 return PANGO_FONT_MAP (CLUTTER_CONTEXT ()->font_map);
2746 typedef struct _ClutterRepaintFunction
2751 GDestroyNotify notify;
2752 } ClutterRepaintFunction;
2755 * clutter_threads_remove_repaint_func:
2756 * @handle_id: an unsigned integer greater than zero
2758 * Removes the repaint function with @handle_id as its id
2763 clutter_threads_remove_repaint_func (guint handle_id)
2765 ClutterRepaintFunction *repaint_func;
2766 ClutterMainContext *context;
2769 g_return_if_fail (handle_id > 0);
2771 context = CLUTTER_CONTEXT ();
2772 l = context->repaint_funcs;
2775 repaint_func = l->data;
2777 if (repaint_func->id == handle_id)
2779 context->repaint_funcs =
2780 g_list_remove_link (context->repaint_funcs, l);
2784 if (repaint_func->notify)
2785 repaint_func->notify (repaint_func->data);
2787 g_slice_free (ClutterRepaintFunction, repaint_func);
2797 * clutter_threads_add_repaint_func:
2798 * @func: the function to be called within the paint cycle
2799 * @data: data to be passed to the function, or %NULL
2800 * @notify: function to be called when removing the repaint
2801 * function, or %NULL
2803 * Adds a function to be called whenever Clutter is repainting a Stage.
2804 * If the function returns %FALSE it is automatically removed from the
2805 * list of repaint functions and will not be called again.
2807 * This function is guaranteed to be called from within the same thread
2808 * that called clutter_main(), and while the Clutter lock is being held.
2810 * A repaint function is useful to ensure that an update of the scenegraph
2811 * is performed before the scenegraph is repainted; for instance, uploading
2812 * a frame from a video into a #ClutterTexture.
2814 * When the repaint function is removed (either because it returned %FALSE
2815 * or because clutter_threads_remove_repaint_func() has been called) the
2816 * @notify function will be called, if any is set.
2818 * Return value: the ID (greater than 0) of the repaint function. You
2819 * can use the returned integer to remove the repaint function by
2820 * calling clutter_threads_remove_repaint_func().
2825 clutter_threads_add_repaint_func (GSourceFunc func,
2827 GDestroyNotify notify)
2829 static guint repaint_id = 1;
2830 ClutterMainContext *context;
2831 ClutterRepaintFunction *repaint_func;
2833 g_return_val_if_fail (func != NULL, 0);
2835 context = CLUTTER_CONTEXT ();
2837 /* XXX lock the context */
2839 repaint_func = g_slice_new (ClutterRepaintFunction);
2841 repaint_func->id = repaint_id++;
2842 repaint_func->func = func;
2843 repaint_func->data = data;
2844 repaint_func->notify = notify;
2846 context->repaint_funcs = g_list_prepend (context->repaint_funcs,
2849 /* XXX unlock the context */
2851 return repaint_func->id;
2855 * _clutter_run_repaint_functions:
2857 * Executes the repaint functions added using the
2858 * clutter_threads_add_repaint_func() function.
2860 * Must be called before calling clutter_redraw() and
2861 * with the Clutter thread lock held.
2864 _clutter_run_repaint_functions (void)
2866 ClutterMainContext *context = CLUTTER_CONTEXT ();
2867 ClutterRepaintFunction *repaint_func;
2868 GList *reinvoke_list, *l;
2870 if (context->repaint_funcs == NULL)
2873 reinvoke_list = NULL;
2875 /* consume the whole list while we execute the functions */
2876 while (context->repaint_funcs)
2878 gboolean res = FALSE;
2880 repaint_func = context->repaint_funcs->data;
2882 l = context->repaint_funcs;
2883 context->repaint_funcs =
2884 g_list_remove_link (context->repaint_funcs, context->repaint_funcs);
2888 res = repaint_func->func (repaint_func->data);
2891 reinvoke_list = g_list_prepend (reinvoke_list, repaint_func);
2894 if (repaint_func->notify)
2895 repaint_func->notify (repaint_func->data);
2897 g_slice_free (ClutterRepaintFunction, repaint_func);
2902 context->repaint_funcs = reinvoke_list;