Store the PangoContext inside the main context
authorEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 23 Dec 2008 14:27:41 +0000 (14:27 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 23 Dec 2008 14:27:41 +0000 (14:27 +0000)
The PangoContext should be stored once, and inside the main
Clutter context. Each actor for which clutter_actor_get_pango_context()
has been called will hold a reference on the Pango context as well.

This makes it possible to update the text rendering for Clutter
by using only public API.

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

index 7b550e9..50ea17b 100644 (file)
@@ -7613,6 +7613,7 @@ clutter_actor_get_pango_context (ClutterActor *self)
 
   ctx = CLUTTER_CONTEXT ();
   priv->pango_context = _clutter_context_create_pango_context (ctx);
+  g_object_ref (priv->pango_context);
 
   return priv->pango_context;
 }
index 9edbce8..5b6a8d3 100644 (file)
@@ -408,16 +408,21 @@ _clutter_context_create_pango_context (ClutterMainContext *self)
   gdouble resolution;
   cairo_font_options_t *font_options;
 
+  if (G_LIKELY (self->pango_context != NULL))
+    context = self->pango_context;
+  else
+    {
+      context = cogl_pango_font_map_create_context (self->font_map);
+      self->pango_context = context;
+    }
+
+  font_options = clutter_backend_get_font_options (self->backend);
   resolution = clutter_backend_get_resolution (self->backend);
   if (resolution < 0)
     resolution = 96.0; /* fall back */
 
-  context = cogl_pango_font_map_create_context (self->font_map);
-
-  pango_cairo_context_set_resolution (context, resolution);
-
-  font_options = clutter_backend_get_font_options (self->backend);
   pango_cairo_context_set_font_options (context, font_options);
+  pango_cairo_context_set_resolution (context, resolution);
 
   return context;
 }
index fb8aea9..383b7df 100644 (file)
@@ -126,10 +126,11 @@ struct _ClutterMainContext
   gint fb_r_mask, fb_g_mask, fb_b_mask;
   gint fb_r_mask_used, fb_g_mask_used, fb_b_mask_used;
 
-  CoglPangoFontMap *font_map;       /* Global font map */
+  PangoContext     *pango_context;      /* Global Pango context */
+  CoglPangoFontMap *font_map;           /* Global font map */
 
-  GSList              *input_devices; /* For extra input devices, i.e
-                                         MultiTouch */
+  GSList              *input_devices;   /* For extra input devices, i.e
+                                           MultiTouch */
 };
 
 #define CLUTTER_CONTEXT()      (clutter_context_get_default ())