[gtk+/wip/cssvalue: 137/164] stylecontext: Remove theming_engine cache variable



commit e28ed3fa77fa0851462fa5d06bb4f9bffbbe0125
Author: Benjamin Otte <otte redhat com>
Date:   Sat Apr 7 11:08:23 2012 +0200

    stylecontext: Remove theming_engine cache variable
    
    Instead, look up the variable upon use. This is more correct (for when
    the engine changes due to save/restore() shenanigans.
    
    And it removes code that doesn't use the standard code paths.

 gtk/gtkstylecontext.c |  173 +++++++++++++++++++++++--------------------------
 1 files changed, 80 insertions(+), 93 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 21e981c..80bf78e 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -356,8 +356,6 @@ struct _GtkStyleContextPrivate
   GHashTable *style_data;
   GSList *info_stack;
 
-  GtkThemingEngine *theming_engine;
-
   GtkTextDirection direction;
 
   GtkCssChange relevant_changes;
@@ -616,7 +614,6 @@ gtk_style_context_init (GtkStyleContext *style_context)
                                             style_info_equal,
                                             (GDestroyNotify) style_info_free,
                                             (GDestroyNotify) style_data_free);
-  priv->theming_engine = g_object_ref ((gpointer) gtk_theming_engine_load (NULL));
 
   priv->direction = GTK_TEXT_DIR_LTR;
 
@@ -653,9 +650,6 @@ gtk_style_context_finalize (GObject *object)
 
   g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
 
-  if (priv->theming_engine)
-    g_object_unref (priv->theming_engine);
-
   G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
 }
 
@@ -813,13 +807,6 @@ style_data_lookup (GtkStyleContext *context)
       gtk_widget_path_free (path);
     }
 
-  if (priv->theming_engine)
-    g_object_unref (priv->theming_engine);
-
-  priv->theming_engine = g_object_ref (
-                           _gtk_css_engine_value_get_engine (
-                             _gtk_css_computed_values_get_value (info->data->store, GTK_CSS_PROPERTY_ENGINE)));
-
   return info->data;
 }
 
@@ -3257,8 +3244,8 @@ gtk_render_check (GtkStyleContext *context,
                   gdouble          width,
                   gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3266,14 +3253,14 @@ gtk_render_check (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_check (priv->theming_engine, cr,
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_check (engine, cr,
                               x, y, width, height);
 
   cairo_restore (cr);
@@ -3307,8 +3294,8 @@ gtk_render_option (GtkStyleContext *context,
                    gdouble          width,
                    gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3316,13 +3303,13 @@ gtk_render_option (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_option (priv->theming_engine, cr,
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_option (engine, cr,
                                x, y, width, height);
 
   cairo_restore (cr);
@@ -3354,8 +3341,8 @@ gtk_render_arrow (GtkStyleContext *context,
                   gdouble          y,
                   gdouble          size)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3363,16 +3350,16 @@ gtk_render_arrow (GtkStyleContext *context,
   if (size <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
   gtk_style_context_save (context);
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_arrow (priv->theming_engine, cr,
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_arrow (engine, cr,
                               angle, x, y, size);
 
   gtk_style_context_restore (context);
@@ -3408,8 +3395,8 @@ gtk_render_background (GtkStyleContext *context,
                        gdouble          width,
                        gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3417,13 +3404,13 @@ gtk_render_background (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_background (engine, cr, x, y, width, height);
 
   cairo_restore (cr);
 }
@@ -3459,8 +3446,8 @@ gtk_render_frame (GtkStyleContext *context,
                   gdouble          width,
                   gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3468,13 +3455,13 @@ gtk_render_frame (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_frame (engine, cr, x, y, width, height);
 
   cairo_restore (cr);
 }
@@ -3507,8 +3494,8 @@ gtk_render_expander (GtkStyleContext *context,
                      gdouble          width,
                      gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3516,13 +3503,13 @@ gtk_render_expander (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_expander (engine, cr, x, y, width, height);
 
   cairo_restore (cr);
 }
@@ -3552,8 +3539,8 @@ gtk_render_focus (GtkStyleContext *context,
                   gdouble          width,
                   gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3561,13 +3548,13 @@ gtk_render_focus (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_focus (engine, cr, x, y, width, height);
 
   cairo_restore (cr);
 }
@@ -3591,23 +3578,23 @@ gtk_render_layout (GtkStyleContext *context,
                    gdouble          y,
                    PangoLayout     *layout)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
   PangoRectangle extents;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (PANGO_IS_LAYOUT (layout));
   g_return_if_fail (cr != NULL);
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
   pango_layout_get_extents (layout, &extents, NULL);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_layout (engine, cr, x, y, layout);
 
   cairo_restore (cr);
 }
@@ -3633,19 +3620,19 @@ gtk_render_line (GtkStyleContext *context,
                  gdouble          x1,
                  gdouble          y1)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_line (engine, cr, x0, y0, x1, y1);
 
   cairo_restore (cr);
 }
@@ -3680,8 +3667,8 @@ gtk_render_slider (GtkStyleContext *context,
                    gdouble          height,
                    GtkOrientation   orientation)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3689,13 +3676,13 @@ gtk_render_slider (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_slider (engine, cr, x, y, width, height, orientation);
 
   cairo_restore (cr);
 }
@@ -3735,8 +3722,8 @@ gtk_render_frame_gap (GtkStyleContext *context,
                       gdouble          xy0_gap,
                       gdouble          xy1_gap)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3752,13 +3739,13 @@ gtk_render_frame_gap (GtkStyleContext *context,
   else
     g_return_if_fail (xy1_gap <= width);
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_frame_gap (priv->theming_engine, cr,
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_frame_gap (engine, cr,
                                   x, y, width, height, gap_side,
                                   xy0_gap, xy1_gap);
 
@@ -3795,8 +3782,8 @@ gtk_render_extension (GtkStyleContext *context,
                       gdouble          height,
                       GtkPositionType  gap_side)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3804,13 +3791,13 @@ gtk_render_extension (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
 
   cairo_restore (cr);
 }
@@ -3843,8 +3830,8 @@ gtk_render_handle (GtkStyleContext *context,
                    gdouble          width,
                    gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3852,13 +3839,13 @@ gtk_render_handle (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_handle (engine, cr, x, y, width, height);
 
   cairo_restore (cr);
 }
@@ -3886,8 +3873,8 @@ gtk_render_activity (GtkStyleContext *context,
                      gdouble          width,
                      gdouble          height)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
@@ -3895,13 +3882,13 @@ gtk_render_activity (GtkStyleContext *context,
   if (width <= 0 || height <= 0)
     return;
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_activity (engine, cr, x, y, width, height);
 
   cairo_restore (cr);
 }
@@ -3925,18 +3912,18 @@ gtk_render_icon_pixbuf (GtkStyleContext     *context,
                         const GtkIconSource *source,
                         GtkIconSize          size)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
   g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
   g_return_val_if_fail (source != NULL, NULL);
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
+  _gtk_theming_engine_set_context (engine, context);
+  return engine_class->render_icon_pixbuf (engine, source, size);
 }
 
 /**
@@ -3958,19 +3945,19 @@ gtk_render_icon (GtkStyleContext *context,
                  gdouble          x,
                  gdouble          y)
 {
-  GtkStyleContextPrivate *priv;
   GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
 
-  priv = context->priv;
-  engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
 
   cairo_save (cr);
 
-  _gtk_theming_engine_set_context (priv->theming_engine, context);
-  engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_icon (engine, cr, pixbuf, x, y);
 
   cairo_restore (cr);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]