stage: Create the default stage on demand
authorEmmanuele Bassi <ebassi@linux.intel.com>
Thu, 3 Dec 2009 21:07:45 +0000 (21:07 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 3 Feb 2010 16:34:27 +0000 (16:34 +0000)
Instead of creating the default stage during initialization we can
now safely create it whenever clutter_stage_get_default() is called.

To maintain the invariant, the default stage is immediately realized
by Clutter itself.

clutter/clutter-main.c
clutter/clutter-stage.c

index 3a74a07..6347031 100644 (file)
@@ -1492,7 +1492,6 @@ static ClutterInitError
 clutter_init_real (GError **error)
 {
   ClutterMainContext *ctx;
-  ClutterActor *stage;
   ClutterBackend *backend;
 
   /* Note, creates backend if not already existing, though parse args will
@@ -1558,33 +1557,6 @@ clutter_init_real (GError **error)
   /* Initiate event collection */
   _clutter_backend_init_events (ctx->backend);
 
-  /* Create the default stage and realize it */
-  stage = clutter_stage_get_default ();
-  if (!stage)
-    {
-      if (error)
-        g_set_error (error, CLUTTER_INIT_ERROR,
-                     CLUTTER_INIT_ERROR_INTERNAL,
-                     "Unable to create the default stage");
-      else
-        g_critical ("Unable to create the default stage");
-
-      return CLUTTER_INIT_ERROR_INTERNAL;
-    }
-
-  clutter_actor_realize (stage);
-  if (!CLUTTER_ACTOR_IS_REALIZED (stage))
-    {
-      if (error)
-        g_set_error (error, CLUTTER_INIT_ERROR,
-                     CLUTTER_INIT_ERROR_INTERNAL,
-                     "Unable to realize the default stage");
-      else
-        g_critical ("Unable to realize the default stage");
-
-      return CLUTTER_INIT_ERROR_INTERNAL;
-    }
-
   clutter_is_initialized = TRUE;
   ctx->is_initialized = TRUE;
 
index b164e50..c67056d 100644 (file)
@@ -1215,11 +1215,16 @@ clutter_stage_get_default (void)
 
   stage = clutter_stage_manager_get_default_stage (stage_manager);
   if (G_UNLIKELY (stage == NULL))
-    /* This will take care of automatically adding the stage to the
-     * stage manager and setting it as the default. Its floating
-     * reference will be claimed by the stage manager.
-     */
-    stage = g_object_new (CLUTTER_TYPE_STAGE, NULL);
+    {
+      /* This will take care of automatically adding the stage to the
+       * stage manager and setting it as the default. Its floating
+       * reference will be claimed by the stage manager.
+       */
+      stage = g_object_new (CLUTTER_TYPE_STAGE, NULL);
+
+      /* the default stage is realized by default */
+      clutter_actor_realize (CLUTTER_ACTOR (stage));
+    }
 
   return CLUTTER_ACTOR (stage);
 }