[gimp/soc-2011-seamless-clone2] app: update GimpTileHandlerProjection's max_z when a propertiy changes



commit 812d4052ade3054325d2d0e80db6dbf0891ac5c1
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 1 01:26:43 2013 +0200

    app: update GimpTileHandlerProjection's max_z when a propertiy changes
    
    not for each gimp_tile_handler_projection_invalidate() call.

 app/gegl/gimptilehandlerprojection.c |   35 ++++++++++++++++++++++++---------
 app/gegl/gimptilehandlerprojection.h |    1 +
 2 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/app/gegl/gimptilehandlerprojection.c b/app/gegl/gimptilehandlerprojection.c
index 07eac37..cc49d64 100644
--- a/app/gegl/gimptilehandlerprojection.c
+++ b/app/gegl/gimptilehandlerprojection.c
@@ -51,6 +51,8 @@ static gpointer gimp_tile_handler_projection_command      (GeglTileSource  *sour
                                                            gint             z,
                                                            gpointer         data);
 
+static void     gimp_tile_handler_projection_update_max_z (GimpTileHandlerProjection *projection);
+
 
 G_DEFINE_TYPE (GimpTileHandlerProjection, gimp_tile_handler_projection,
                GEGL_TYPE_TILE_HANDLER)
@@ -126,9 +128,11 @@ gimp_tile_handler_projection_set_property (GObject      *object,
       break;
     case PROP_TILE_WIDTH:
       projection->tile_width = g_value_get_int (value);
+      gimp_tile_handler_projection_update_max_z (projection);
       break;
     case PROP_TILE_HEIGHT:
       projection->tile_height = g_value_get_int (value);
+      gimp_tile_handler_projection_update_max_z (projection);
       break;
 
     default:
@@ -264,6 +268,24 @@ gimp_tile_handler_projection_command (GeglTileSource  *source,
   return retval;
 }
 
+static void
+gimp_tile_handler_projection_update_max_z (GimpTileHandlerProjection *projection)
+{
+  projection->max_z = 0;
+
+  if (projection->proj_width > 0 && projection->proj_height > 0 &&
+      projection->tile_width > 0 && projection->tile_height > 0)
+    {
+      gint n_tiles;
+
+      n_tiles = MAX (projection->proj_width  / projection->tile_width,
+                     projection->proj_height / projection->tile_height) + 1;
+
+      while (n_tiles >>= 1)
+        projection->max_z++;
+    }
+}
+
 GeglTileHandler *
 gimp_tile_handler_projection_new (GeglNode *graph,
                                   gint      proj_width,
@@ -304,20 +326,12 @@ gimp_tile_handler_projection_invalidate (GimpTileHandlerProjection *projection,
                                          gint                       height)
 {
   cairo_rectangle_int_t rect = { x, y, width, height };
-  gint                  n_tiles;
-  gint                  max_z = 0;
 
   g_return_if_fail (GIMP_IS_TILE_HANDLER_PROJECTION (projection));
 
   cairo_region_union_rectangle (projection->dirty_region, &rect);
 
-  n_tiles = MAX (projection->proj_width  / projection->tile_width,
-                 projection->proj_height / projection->tile_height) + 1;
-
-  while (n_tiles >>= 1)
-    max_z++;
-
-  if (max_z > 0)
+  if (projection->max_z > 0)
     {
       gint tile_x1 = x / projection->tile_width;
       gint tile_y1 = y / projection->tile_height;
@@ -333,7 +347,8 @@ gimp_tile_handler_projection_invalidate (GimpTileHandlerProjection *projection,
               gimp_tile_handler_projection_void_pyramid (GEGL_TILE_SOURCE (projection),
                                                          tile_x / 2,
                                                          tile_y / 2,
-                                                         1, max_z);
+                                                         1,
+                                                         projection->max_z);
             }
         }
     }
diff --git a/app/gegl/gimptilehandlerprojection.h b/app/gegl/gimptilehandlerprojection.h
index 3df269a..a72684c 100644
--- a/app/gegl/gimptilehandlerprojection.h
+++ b/app/gegl/gimptilehandlerprojection.h
@@ -49,6 +49,7 @@ struct _GimpTileHandlerProjection
   gint             tile_height;
   gint             proj_width;
   gint             proj_height;
+  gint             max_z;
 };
 
 struct _GimpTileHandlerProjectionClass


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