[gedit-cossa] previewer: ensure only the current sample is invalidated on CSS changes



commit 620e0bf6f90ca4724f9d4fd0709e978f55a05b22
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun May 29 15:11:55 2011 +0200

    previewer: ensure only the current sample is invalidated on CSS changes

 src/cossa-previewer.c |   74 ++++++++++++++++++++++++++++++------------------
 1 files changed, 46 insertions(+), 28 deletions(-)
---
diff --git a/src/cossa-previewer.c b/src/cossa-previewer.c
index 4fc4d36..2d3a4fb 100644
--- a/src/cossa-previewer.c
+++ b/src/cossa-previewer.c
@@ -32,11 +32,17 @@
 typedef struct _CossaPreviewerPrivate CossaPreviewerPrivate;
 typedef struct _SampleData SampleData;
 
+enum {
+  INVALIDATE_NONE  = 0,
+  INVALIDATE_STYLE = 1 << 0,
+  INVALIDATE_IMAGE = 1 << 1
+};
+
 struct _SampleData
 {
   GtkWidget *widget;
   cairo_surface_t *surface;
-  CossaZoomLevel cur_zoom;
+  guint invalidation;
 };
 
 struct _CossaPreviewerPrivate
@@ -136,6 +142,7 @@ sample_data_new (GtkWidget *widget)
 
   data = g_slice_new0 (SampleData);
   data->widget = g_object_ref (widget);
+  data->invalidation = INVALIDATE_IMAGE;
 
   return data;
 }
@@ -279,9 +286,15 @@ update_sample_surface (SampleData     *sample,
   GtkRequisition req;
   cairo_t *cr;
 
+  if (sample->invalidation == INVALIDATE_NONE)
+    return;
+
   if (sample->surface)
     cairo_surface_destroy (sample->surface);
 
+  if (sample->invalidation & INVALIDATE_STYLE)
+    gtk_widget_reset_style (sample->widget);
+
   gtk_widget_get_preferred_size (sample->widget, NULL, &req);
 
   allocation.width = req.width;
@@ -297,7 +310,7 @@ update_sample_surface (SampleData     *sample,
   gtk_widget_draw (sample->widget, cr);
   cairo_destroy (cr);
 
-  sample->cur_zoom = zoom;
+  sample->invalidation = INVALIDATE_NONE;
 }
 
 static void
@@ -394,30 +407,48 @@ cossa_previewer_select_sample (CossaPreviewer *previewer,
   gtk_widget_queue_draw (GTK_WIDGET (previewer));
 }
 
-void
-cossa_previewer_set_zoom_level (CossaPreviewer *previewer,
-                                CossaZoomLevel  zoom)
+static void
+cossa_previewer_invalidate_samples (CossaPreviewer *previewer,
+				    guint           invalidation)
 {
   CossaPreviewerPrivate *priv;
   GtkWidget *widget;
-
-  g_return_if_fail (COSSA_IS_PREVIEWER (previewer));
+  GList *l;
 
   priv = previewer->priv;
   widget = GTK_WIDGET (previewer);
 
-  if (priv->zoom_level != zoom)
+  for (l = priv->samples; l; l = l->next)
     {
-      priv->zoom_level = zoom;
+      SampleData *data = l->data;
 
-      if (priv->cur_sample)
-        update_sample_surface (priv->cur_sample->data, priv->zoom_level);
+      data->invalidation |= invalidation;
+    }
 
-      if (gtk_widget_is_drawable (widget))
-        gtk_widget_queue_resize (widget);
+  if (priv->cur_sample)
+    {
+      update_sample_surface (priv->cur_sample->data, priv->zoom_level);
+      gtk_widget_queue_resize (widget);
     }
 }
 
+void
+cossa_previewer_set_zoom_level (CossaPreviewer *previewer,
+                                CossaZoomLevel  zoom)
+{
+  CossaPreviewerPrivate *priv;
+
+  g_return_if_fail (COSSA_IS_PREVIEWER (previewer));
+
+  priv = previewer->priv;
+
+  if (priv->zoom_level == zoom)
+    return;
+
+  priv->zoom_level = zoom;
+  cossa_previewer_invalidate_samples (previewer, INVALIDATE_IMAGE);
+}
+
 CossaZoomLevel
 cossa_previewer_get_zoom_level (CossaPreviewer *previewer)
 {
@@ -432,25 +463,12 @@ cossa_previewer_get_zoom_level (CossaPreviewer *previewer)
 void
 cossa_previewer_update_samples (CossaPreviewer *previewer)
 {
-  CossaPreviewerPrivate *priv;
-  GList *l;
-
   g_return_if_fail (COSSA_IS_PREVIEWER (previewer));
 
-  priv = previewer->priv;
-
-  for (l = priv->samples; l; l = l->next)
-    {
-      SampleData *data = l->data;
-
-      gtk_widget_reset_style (data->widget);
-      update_sample_surface (data, priv->zoom_level);
-    }
-
-  if (priv->cur_sample)
-    gtk_widget_queue_draw (GTK_WIDGET (previewer));
+  cossa_previewer_invalidate_samples (previewer, INVALIDATE_STYLE);
 }
 
+
 GtkCssProvider *
 cossa_previewer_get_style (CossaPreviewer *previewer)
 {



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