Allow checking initialization without side-effects
authorEmmanuele Bassi <ebassi@linux.intel.com>
Fri, 19 Jun 2009 13:09:42 +0000 (14:09 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Fri, 19 Jun 2009 13:09:42 +0000 (14:09 +0100)
The _clutter_context_get_default() function will automatically
create the main Clutter context; if we just want to check whether
Clutter has been initialized this will complicate matters, by
requiring a call to g_type_init() inside the client code.

Instead, we should simply provide an internal API that checks
whether the main Clutter context exists and if it has been
initialized, without any side effect.

clutter/clutter-main.c
clutter/clutter-private.h

index b70fb77..131a4a1 100644 (file)
@@ -1052,10 +1052,19 @@ clutter_get_debug_enabled (void)
 #endif
 }
 
+gboolean
+_clutter_context_is_initialized (void)
+{
+  if (ClutterCntx == NULL)
+    return FALSE;
+
+  return ClutterCntx->is_initialized;
+}
+
 ClutterMainContext *
 _clutter_context_get_default (void)
 {
-  if (G_UNLIKELY(!ClutterCntx))
+  if (G_UNLIKELY (ClutterCntx == NULL))
     {
       ClutterMainContext *ctx;
 
@@ -1067,7 +1076,7 @@ _clutter_context_get_default (void)
       ctx->motion_events_per_actor = TRUE;
 
 #ifdef CLUTTER_ENABLE_DEBUG
-      ctx->timer          =  g_timer_new ();
+      ctx->timer = g_timer_new ();
       g_timer_start (ctx->timer);
 #endif
     }
index ea81197..db2c0cd 100644 (file)
@@ -138,6 +138,7 @@ struct _ClutterMainContext
 
 #define CLUTTER_CONTEXT()      (_clutter_context_get_default ())
 ClutterMainContext *_clutter_context_get_default (void);
+gboolean            _clutter_context_is_initialized (void);
 PangoContext *_clutter_context_create_pango_context (ClutterMainContext *self);
 PangoContext *_clutter_context_get_pango_context    (ClutterMainContext *self);