2008-09-23 Tomas Frydrych <tf@linux.intel.com>

* clutter/clutter-main.c:
	    * clutter/clutter-main.h:
	    * clutter/clutter-private.h:
	    * clutter/x11/clutter-backend-x11.c:
	    (clutter_get_option_group_without_init):
	    Function to obtain clutter option group without opening display
	    (for use with foreign display and gtk_clutter_init). Bug 1033.

	    Stripped trailing whitespace.
This commit is contained in:
Tomas Frydrych 2008-09-23 07:03:35 +00:00
parent 72c9f88019
commit 6b51ac4b77
5 changed files with 209 additions and 112 deletions

View File

@ -1,3 +1,15 @@
2008-09-23 Tomas Frydrych <tf@linux.intel.com>
* clutter/clutter-main.c:
* clutter/clutter-main.h:
* clutter/clutter-private.h:
* clutter/x11/clutter-backend-x11.c:
(clutter_get_option_group_without_init):
Function to obtain clutter option group without opening display
(for use with foreign display and gtk_clutter_init). Bug 1033.
Stripped trailing whitespace.
2008-09-22 Neil Roberts <neil@linux.intel.com>
Bug 856 - Teardown sequence is borked

View File

@ -956,7 +956,6 @@ clutter_context_get_default (void)
if (G_UNLIKELY(!ClutterCntx))
{
ClutterMainContext *ctx;
gdouble resolution;
ClutterCntx = ctx = g_new0 (ClutterMainContext, 1);
ctx->backend = g_object_new (_clutter_backend_impl_get_type (), NULL);
@ -968,13 +967,6 @@ clutter_context_get_default (void)
ctx->timer = g_timer_new ();
g_timer_start (ctx->timer);
#endif
ctx->font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
resolution = clutter_backend_get_resolution (ctx->backend);
pango_clutter_font_map_set_resolution (ctx->font_map, resolution);
pango_clutter_font_map_set_use_mipmapping (ctx->font_map, TRUE);
}
return ClutterCntx;
@ -1044,11 +1036,42 @@ clutter_init_real (GError **error)
{
ClutterMainContext *ctx;
ClutterActor *stage;
gdouble resolution;
ClutterBackend *backend;
/* Note, creates backend if not already existing, though parse args will
* have likely created it
*/
ctx = clutter_context_get_default ();
backend = ctx->backend;
if (!ctx->options_parsed)
{
g_set_error (error, CLUTTER_INIT_ERROR,
CLUTTER_INIT_ERROR_INTERNAL,
"When using clutter_get_option_group_without_init() "
"you must parse options before calling clutter_init()");
return CLUTTER_INIT_ERROR_INTERNAL;
}
/*
* Call backend post parse hooks.
*/
if (CLUTTER_BACKEND_GET_CLASS (backend)->post_parse)
if (!CLUTTER_BACKEND_GET_CLASS (backend)->post_parse (backend, error))
return CLUTTER_INIT_ERROR_BACKEND;
/*
* Resolution requires display to be open, so can only be queried after
* the post_parse hooks run.
*/
ctx->font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
resolution = clutter_backend_get_resolution (ctx->backend);
pango_clutter_font_map_set_resolution (ctx->font_map, resolution);
pango_clutter_font_map_set_use_mipmapping (ctx->font_map, TRUE);
/* Stage will give us a GL Context etc */
stage = clutter_stage_get_default ();
@ -1108,6 +1131,7 @@ clutter_init_real (GError **error)
clutter_stage_set_title (CLUTTER_STAGE (stage), g_get_prgname ());
clutter_is_initialized = TRUE;
ctx->is_initialized = TRUE;
return CLUTTER_INIT_SUCCESS;
}
@ -1197,7 +1221,6 @@ post_parse_hook (GOptionContext *context,
{
ClutterMainContext *clutter_context;
ClutterBackend *backend;
gboolean retval = FALSE;
if (clutter_is_initialized)
return TRUE;
@ -1216,16 +1239,16 @@ post_parse_hook (GOptionContext *context,
}
clutter_context->frame_rate = clutter_default_fps;
clutter_context->options_parsed = TRUE;
if (CLUTTER_BACKEND_GET_CLASS (backend)->post_parse)
retval = CLUTTER_BACKEND_GET_CLASS (backend)->post_parse (backend, error);
else
retval = TRUE;
/*
* If not asked to defer display setup, call clutter_init_real(),
* which in turn calls the backend post parse hooks.
*/
if (!clutter_context->defer_display_setup)
return clutter_init_real (error);
if (retval)
clutter_init_real (error);
return retval;
return TRUE;
}
/**
@ -1265,6 +1288,8 @@ clutter_get_option_group (void)
ClutterMainContext *context;
GOptionGroup *group;
clutter_base_init ();
context = clutter_context_get_default ();
group = g_option_group_new ("clutter",
@ -1282,6 +1307,39 @@ clutter_get_option_group (void)
return group;
}
/**
* clutter_get_option_group_without_init:
*
* Returns a #GOptionGroup for the command line arguments recognized
* by Clutter. You should add this group to your #GOptionContext with
* g_option_context_add_group(), if you are using g_option_context_parse()
* to parse your commandline arguments. Unlike clutter_get_option_group(),
* calling g_option_context_parse() with the #GOptionGroup returned by this
* function requires a subsequent explicit call to clutter_init(); use this
* function when needing to set foreign display connection with
* clutter_x11_set_display(), or with gtk_clutter_init().
*
* Return value: a #GOptionGroup for the commandline arguments
* recognized by Clutter
*
* Since: 0.8.2
*/
GOptionGroup *
clutter_get_option_group_without_init (void)
{
ClutterMainContext *context;
GOptionGroup *group;
clutter_base_init ();
context = clutter_context_get_default ();
context->defer_display_setup = TRUE;
group = clutter_get_option_group ();
return group;
}
/**
* clutter_init_with_args:
* @argc: a pointer to the number of command line arguments
@ -1321,12 +1379,17 @@ clutter_init_with_args (int *argc,
GOptionContext *context;
GOptionGroup *group;
gboolean res;
ClutterMainContext *ctx;
if (clutter_is_initialized)
return CLUTTER_INIT_SUCCESS;
clutter_base_init ();
ctx = clutter_context_get_default ();
if (!ctx->defer_display_setup)
{
if (argc && *argc > 0 && *argv)
g_set_prgname ((*argv)[0]);
@ -1356,6 +1419,9 @@ clutter_init_with_args (int *argc,
}
return CLUTTER_INIT_SUCCESS;
}
else
return clutter_init_real (error);
}
static gboolean
@ -1411,11 +1477,18 @@ ClutterInitError
clutter_init (int *argc,
char ***argv)
{
ClutterMainContext *ctx;
GError *error = NULL;
if (clutter_is_initialized)
return CLUTTER_INIT_SUCCESS;
clutter_base_init ();
ctx = clutter_context_get_default ();
if (!ctx->defer_display_setup)
{
if (argc && *argc > 0 && *argv)
g_set_prgname ((*argv)[0]);
@ -1429,6 +1502,9 @@ clutter_init (int *argc,
}
return CLUTTER_INIT_SUCCESS;
}
else
return clutter_init_real (&error);
}
gboolean

View File

@ -89,6 +89,7 @@ ClutterInitError clutter_init_with_args (int *argc,
char *translation_domain,
GError **error);
GOptionGroup * clutter_get_option_group (void);
GOptionGroup * clutter_get_option_group_without_init (void);
/* Mainloop */
void clutter_main (void);

View File

@ -93,12 +93,14 @@ struct _ClutterMainContext
GQueue *events_queue; /* the main event queue */
guint is_initialized : 1;
guint motion_events_per_actor : 1;/* set for enter/leave events */
guint defer_display_setup : 1;
guint options_parsed : 1;
GTimer *timer; /* Used for debugging scheduler */
ClutterPickMode pick_mode; /* Indicates pick render mode */
guint motion_events_per_actor : 1;/* set for enter/leave events */
guint motion_frequency; /* Motion events per second */
gint num_reactives; /* Num of reactive actors */

View File

@ -425,7 +425,9 @@ clutter_x11_get_default_display (void)
void
clutter_x11_set_display (Display *xdpy)
{
if (backend_singleton && backend_singleton->xdpy)
ClutterMainContext *ctx = clutter_context_get_default ();
if (ctx->is_initialized)
{
g_critical ("Display connection already exists. You can only call "
"clutter_x11_set_display() once before clutter_init()\n");
@ -450,7 +452,9 @@ clutter_x11_set_display (Display *xdpy)
void
clutter_x11_enable_xinput ()
{
if (backend_singleton != NULL)
ClutterMainContext *ctx = clutter_context_get_default ();
if (ctx->is_initialized)
{
g_warning ("clutter_x11_enable_xinput should "
"be called before clutter_init");
@ -473,7 +477,9 @@ clutter_x11_enable_xinput ()
void
clutter_x11_disable_event_retrieval (void)
{
if (backend_singleton != NULL)
ClutterMainContext *ctx = clutter_context_get_default ();
if (ctx->is_initialized)
{
g_warning ("clutter_x11_disable_event_retrieval should "
"be called before clutter_init");