From 9b228c59d57eb6cd307be0ddfe4c6cb8c94f66a9 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 23 Jul 2012 16:14:20 +0200 Subject: [PATCH] cssomputedvalues: Track dependencies We now track what values have dependencies on what other values so that we could in theory recompute them when we need to. --- gtk/gtkcssanimatedvalues.c | 9 +++++++++ gtk/gtkcsscomputedvalues.c | 33 ++++++++++++++++++++++++++++--- gtk/gtkcsscomputedvaluesprivate.h | 6 +++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gtk/gtkcssanimatedvalues.c b/gtk/gtkcssanimatedvalues.c index c5e4e3b43f..7617faa049 100644 --- a/gtk/gtkcssanimatedvalues.c +++ b/gtk/gtkcssanimatedvalues.c @@ -254,6 +254,15 @@ _gtk_css_animated_values_new (GtkCssComputedValues *computed, _gtk_css_computed_values_get_section (computed, i)); } + _gtk_bitmask_free (GTK_CSS_COMPUTED_VALUES (values)->depends_on_parent); + _gtk_bitmask_free (GTK_CSS_COMPUTED_VALUES (values)->equals_parent); + _gtk_bitmask_free (GTK_CSS_COMPUTED_VALUES (values)->depends_on_color); + _gtk_bitmask_free (GTK_CSS_COMPUTED_VALUES (values)->depends_on_font_size); + GTK_CSS_COMPUTED_VALUES (values)->depends_on_parent = _gtk_bitmask_copy (computed->depends_on_parent); + GTK_CSS_COMPUTED_VALUES (values)->equals_parent = _gtk_bitmask_copy (computed->equals_parent); + GTK_CSS_COMPUTED_VALUES (values)->depends_on_color = _gtk_bitmask_copy (computed->depends_on_color); + GTK_CSS_COMPUTED_VALUES (values)->depends_on_font_size = _gtk_bitmask_copy (computed->depends_on_font_size); + gtk_css_animated_values_start_animations (values, timestamp, source); ignore = _gtk_css_animated_values_advance (values, timestamp); diff --git a/gtk/gtkcsscomputedvalues.c b/gtk/gtkcsscomputedvalues.c index ad0353046d..63b0ee7a9f 100644 --- a/gtk/gtkcsscomputedvalues.c +++ b/gtk/gtkcsscomputedvalues.c @@ -46,18 +46,35 @@ gtk_css_computed_values_dispose (GObject *object) G_OBJECT_CLASS (_gtk_css_computed_values_parent_class)->dispose (object); } +static void +gtk_css_computed_values_finalize (GObject *object) +{ + GtkCssComputedValues *values = GTK_CSS_COMPUTED_VALUES (object); + + _gtk_bitmask_free (values->depends_on_parent); + _gtk_bitmask_free (values->equals_parent); + _gtk_bitmask_free (values->depends_on_color); + _gtk_bitmask_free (values->depends_on_font_size); + + G_OBJECT_CLASS (_gtk_css_computed_values_parent_class)->finalize (object); +} + static void _gtk_css_computed_values_class_init (GtkCssComputedValuesClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = gtk_css_computed_values_dispose; + object_class->finalize = gtk_css_computed_values_finalize; } static void -_gtk_css_computed_values_init (GtkCssComputedValues *computed_values) +_gtk_css_computed_values_init (GtkCssComputedValues *values) { - + values->depends_on_parent = _gtk_bitmask_new (); + values->equals_parent = _gtk_bitmask_new (); + values->depends_on_color = _gtk_bitmask_new (); + values->depends_on_font_size = _gtk_bitmask_new (); } GtkCssComputedValues * @@ -90,6 +107,7 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values, GtkCssValue *specified, GtkCssSection *section) { + GtkCssDependencies dependencies; g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values)); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); @@ -113,7 +131,16 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values, else _gtk_css_value_ref (specified); - g_ptr_array_index (values->values, id) = _gtk_css_value_compute (specified, id, context, NULL); + g_ptr_array_index (values->values, id) = _gtk_css_value_compute (specified, id, context, &dependencies); + + if (dependencies & (GTK_CSS_DEPENDS_ON_PARENT | GTK_CSS_EQUALS_PARENT)) + values->depends_on_parent = _gtk_bitmask_set (values->depends_on_parent, id, TRUE); + if (dependencies & (GTK_CSS_EQUALS_PARENT)) + values->equals_parent = _gtk_bitmask_set (values->equals_parent, id, TRUE); + if (dependencies & (GTK_CSS_DEPENDS_ON_COLOR)) + values->depends_on_color = _gtk_bitmask_set (values->depends_on_color, id, TRUE); + if (dependencies & (GTK_CSS_DEPENDS_ON_FONT_SIZE)) + values->depends_on_font_size = _gtk_bitmask_set (values->depends_on_font_size, id, TRUE); if (section) { diff --git a/gtk/gtkcsscomputedvaluesprivate.h b/gtk/gtkcsscomputedvaluesprivate.h index 64234ef371..239afca53a 100644 --- a/gtk/gtkcsscomputedvaluesprivate.h +++ b/gtk/gtkcsscomputedvaluesprivate.h @@ -43,8 +43,12 @@ struct _GtkCssComputedValues { GObject parent; - GPtrArray *values; + GPtrArray *values; GPtrArray *sections; + GtkBitmask *depends_on_parent; + GtkBitmask *equals_parent; + GtkBitmask *depends_on_color; + GtkBitmask *depends_on_font_size; }; struct _GtkCssComputedValuesClass