Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From f0f2f35fd9d5e5153b10c5a94ba890e7ef1f7dfa Mon Sep 17 00:00:00 2001
- From: Neil Roberts <neil@linux.intel.com>
- Date: Wed, 9 Jun 2010 10:54:23 +0100
- Subject: [PATCH] Make clutter_get_font_map lazily create the map and use it throughout
- A few function such as clutter_set_font_flags try to set data on the
- global font map but they first check if the font map has already been
- created. Therefore if the functions are called before the font map is
- created then the results will be ignored. It makes more sense to force
- the lazy creation of the font map in these functions instead of
- ignoring the call.
- This patches changes anything that needs the font map to call
- clutter_get_font_map instead. clutter_get_font_map now ensures that
- the map has been created. Previously the font map would be created in
- _clutter_context_create_pango_context but this is now changed to also
- call clutter_get_font_map.
- ---
- clutter/clutter-backend.c | 4 +++
- clutter/clutter-main.c | 54 ++++++++++++++++++++++----------------------
- 2 files changed, 31 insertions(+), 27 deletions(-)
- diff --git a/clutter/clutter-backend.c b/clutter/clutter-backend.c
- index e501336..af8c9ea 100644
- --- a/clutter/clutter-backend.c
- +++ b/clutter/clutter-backend.c
- @@ -626,6 +626,10 @@ clutter_backend_set_resolution (ClutterBackend *backend,
- priv->resolution = dpi;
- + /* We need to conditionally check for the font map rather than
- + enforcing the lazy creation here because this function is called
- + before the backend has been completely constructed. The font map
- + can't be instantiated until the GL context is setup */
- if (CLUTTER_CONTEXT ()->font_map)
- cogl_pango_font_map_set_resolution (CLUTTER_CONTEXT ()->font_map, dpi);
- diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
- index 59bf9d7..1ba9b6f 100644
- --- a/clutter/clutter-main.c
- +++ b/clutter/clutter-main.c
- @@ -775,21 +775,9 @@ PangoContext *
- _clutter_context_create_pango_context (ClutterMainContext *self)
- {
- PangoContext *context;
- + CoglPangoFontMap *font_map = COGL_PANGO_FONT_MAP (clutter_get_font_map ());
- - if (self->font_map == NULL)
- - {
- - gdouble resolution;
- -
- - self->font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new ());
- -
- - resolution = clutter_backend_get_resolution (self->backend);
- - cogl_pango_font_map_set_resolution (self->font_map, resolution);
- -
- - if (G_LIKELY (!clutter_disable_mipmap_text))
- - cogl_pango_font_map_set_use_mipmapping (self->font_map, TRUE);
- - }
- -
- - context = cogl_pango_font_map_create_context (self->font_map);
- + context = cogl_pango_font_map_create_context (font_map);
- update_pango_context (self->backend, context);
- pango_context_set_language (context, pango_language_get_default ());
- @@ -2860,8 +2848,8 @@ clutter_get_keyboard_grab (void)
- void
- clutter_clear_glyph_cache (void)
- {
- - if (CLUTTER_CONTEXT ()->font_map)
- - cogl_pango_font_map_clear_glyph_cache (CLUTTER_CONTEXT ()->font_map);
- + CoglPangoFontMap *font_map = COGL_PANGO_FONT_MAP (clutter_get_font_map ());
- + cogl_pango_font_map_clear_glyph_cache (font_map);
- }
- /**
- @@ -2886,13 +2874,14 @@ clutter_set_font_flags (ClutterFontFlags flags)
- const cairo_font_options_t *font_options;
- cairo_font_options_t *new_font_options;
- ClutterBackend *backend;
- + CoglPangoFontMap *font_map;
- backend = clutter_get_default_backend ();
- - if (CLUTTER_CONTEXT ()->font_map)
- - cogl_pango_font_map_set_use_mipmapping (CLUTTER_CONTEXT ()->font_map,
- - (flags
- - & CLUTTER_FONT_MIPMAPPING) != 0);
- + font_map = COGL_PANGO_FONT_MAP (clutter_get_font_map ());
- + cogl_pango_font_map_set_use_mipmapping (font_map,
- + (flags
- + & CLUTTER_FONT_MIPMAPPING) != 0);
- old_flags = clutter_get_font_flags ();
- @@ -2931,14 +2920,13 @@ ClutterFontFlags
- clutter_get_font_flags (void)
- {
- ClutterMainContext *ctxt = CLUTTER_CONTEXT ();
- - CoglPangoFontMap *font_map = NULL;
- + CoglPangoFontMap *font_map;
- const cairo_font_options_t *font_options;
- ClutterFontFlags flags = 0;
- - font_map = CLUTTER_CONTEXT ()->font_map;
- + font_map = COGL_PANGO_FONT_MAP (clutter_get_font_map ());
- - if (G_LIKELY (font_map)
- - && cogl_pango_font_map_get_use_mipmapping (font_map))
- + if (cogl_pango_font_map_get_use_mipmapping (font_map))
- flags |= CLUTTER_FONT_MIPMAPPING;
- font_options = clutter_backend_get_font_options (ctxt->backend);
- @@ -2997,10 +2985,22 @@ clutter_get_input_device_for_id (gint id)
- PangoFontMap *
- clutter_get_font_map (void)
- {
- - if (CLUTTER_CONTEXT ()->font_map)
- - return PANGO_FONT_MAP (CLUTTER_CONTEXT ()->font_map);
- + ClutterMainContext *self = CLUTTER_CONTEXT ();
- +
- + if (self->font_map == NULL)
- + {
- + gdouble resolution;
- +
- + self->font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new ());
- +
- + resolution = clutter_backend_get_resolution (self->backend);
- + cogl_pango_font_map_set_resolution (self->font_map, resolution);
- +
- + if (G_LIKELY (!clutter_disable_mipmap_text))
- + cogl_pango_font_map_set_use_mipmapping (self->font_map, TRUE);
- + }
- - return NULL;
- + return PANGO_FONT_MAP (self->font_map);
- }
- typedef struct _ClutterRepaintFunction
- --
- 1.7.1.87.g94e70
Add Comment
Please, Sign In to add comment