[gimp] app: remove premature canvas item extents caching optimization again



commit d0f6846ff547ab2be6c75597ee11368c692a58f3
Author: Michael Natterer <mitch gimp org>
Date:   Wed Sep 22 10:33:41 2010 +0200

    app: remove premature canvas item extents caching optimization again

 app/display/gimpcanvashandle.c    |   35 ++++++++++++++++++++++++++++-------
 app/display/gimpcanvasitem.c      |   29 +----------------------------
 app/display/gimpcanvasitem.h      |    5 -----
 app/display/gimpcanvasline.c      |   21 +++++++++++++--------
 app/display/gimpcanvasrectangle.c |   37 +++++++++++++++++++++++++------------
 5 files changed, 67 insertions(+), 60 deletions(-)
---
diff --git a/app/display/gimpcanvashandle.c b/app/display/gimpcanvashandle.c
index 304c0e3..9c63df7 100644
--- a/app/display/gimpcanvashandle.c
+++ b/app/display/gimpcanvashandle.c
@@ -342,12 +342,6 @@ gimp_canvas_handle_draw (GimpCanvasItem   *item,
       cairo_move_to (cr, x, y - private->height / 2);
       cairo_line_to (cr, x, y + private->height / 2);
 
-      _gimp_canvas_item_set_extents (item,
-                                     x - private->width  / 2 - 1.5,
-                                     y - private->height / 2 - 1.5,
-                                     private->width  + 3.0,
-                                     private->height + 3.0);
-
       _gimp_canvas_item_stroke (item, shell, cr);
       break;
 
@@ -360,7 +354,34 @@ static GdkRegion *
 gimp_canvas_handle_get_extents (GimpCanvasItem   *item,
                                 GimpDisplayShell *shell)
 {
-  return GIMP_CANVAS_ITEM_CLASS (parent_class)->get_extents (item, shell);
+  GimpCanvasHandlePrivate *private = GET_PRIVATE (item);
+  GdkRectangle             rectangle;
+  gdouble                  x, y;
+
+  gimp_canvas_handle_transform (item, shell, &x, &y);
+
+  switch (private->type)
+    {
+    case GIMP_HANDLE_SQUARE:
+      break;
+
+    case GIMP_HANDLE_FILLED_SQUARE:
+      break;
+
+    case GIMP_HANDLE_CIRCLE:
+    case GIMP_HANDLE_FILLED_CIRCLE:
+    case GIMP_HANDLE_CROSS:
+      rectangle.x      = x - private->width  / 2 - 1.5;
+      rectangle.y      = y - private->height / 2 - 1.5;
+      rectangle.width  = private->width  + 3.0;
+      rectangle.height = private->height + 3.0;
+      break;
+
+    default:
+      break;
+    }
+
+  return gdk_region_rectangle (&rectangle);
 }
 
 GimpCanvasItem *
diff --git a/app/display/gimpcanvasitem.c b/app/display/gimpcanvasitem.c
index 9f96f9c..16f77df 100644
--- a/app/display/gimpcanvasitem.c
+++ b/app/display/gimpcanvasitem.c
@@ -36,10 +36,6 @@ typedef struct _GimpCanvasItemPrivate GimpCanvasItemPrivate;
 
 struct _GimpCanvasItemPrivate
 {
-  gdouble extents_x;
-  gdouble extents_y;
-  gdouble extents_width;
-  gdouble extents_height;
 };
 
 #define GET_PRIVATE(item) \
@@ -89,15 +85,7 @@ static GdkRegion *
 gimp_canvas_item_real_get_extents (GimpCanvasItem   *item,
                                    GimpDisplayShell *shell)
 {
-  GimpCanvasItemPrivate *private = GET_PRIVATE (item);
-  GdkRectangle           rectangle;
-
-  rectangle.x      = floor (private->extents_x);
-  rectangle.y      = floor (private->extents_y);
-  rectangle.width  = ceil (private->extents_width);
-  rectangle.height = ceil (private->extents_height);
-
-  return gdk_region_rectangle (&rectangle);
+  return NULL;
 }
 
 
@@ -133,21 +121,6 @@ gimp_canvas_item_get_extents (GimpCanvasItem   *item,
 /*  protexted functions  */
 
 void
-_gimp_canvas_item_set_extents (GimpCanvasItem *item,
-                               gdouble         x,
-                               gdouble         y,
-                               gdouble         width,
-                               gdouble         height)
-{
-  GimpCanvasItemPrivate *private = GET_PRIVATE (item);
-
-  private->extents_x      = x;
-  private->extents_y      = y;
-  private->extents_width  = width;
-  private->extents_height = height;
-}
-
-void
 _gimp_canvas_item_stroke (GimpCanvasItem   *item,
                           GimpDisplayShell *shell,
                           cairo_t          *cr)
diff --git a/app/display/gimpcanvasitem.h b/app/display/gimpcanvasitem.h
index 1c48cc1..f939ae8 100644
--- a/app/display/gimpcanvasitem.h
+++ b/app/display/gimpcanvasitem.h
@@ -64,11 +64,6 @@ GdkRegion * gimp_canvas_item_get_extents  (GimpCanvasItem   *item,
 
 /*  protected  */
 
-void        _gimp_canvas_item_set_extents (GimpCanvasItem   *item,
-                                           gdouble           x,
-                                           gdouble           y,
-                                           gdouble           width,
-                                           gdouble           height);
 void        _gimp_canvas_item_stroke      (GimpCanvasItem   *item,
                                            GimpDisplayShell *shell,
                                            cairo_t          *cr);
diff --git a/app/display/gimpcanvasline.c b/app/display/gimpcanvasline.c
index 78f79d1..4af0436 100644
--- a/app/display/gimpcanvasline.c
+++ b/app/display/gimpcanvasline.c
@@ -222,20 +222,25 @@ gimp_canvas_line_draw (GimpCanvasItem   *item,
   cairo_move_to (cr, x1, y1);
   cairo_line_to (cr, x2, y2);
 
-  _gimp_canvas_item_set_extents (item,
-                                 MIN (x1, x2) - 1.5,
-                                 MIN (y1, y2) - 1.5,
-                                 ABS (x2 - x1) + 3.0,
-                                 ABS (y2 - y1) + 3.0);
-
   _gimp_canvas_item_stroke (item, shell, cr);
 }
 
 static GdkRegion *
 gimp_canvas_line_get_extents (GimpCanvasItem   *item,
-                                   GimpDisplayShell *shell)
+                              GimpDisplayShell *shell)
 {
-  return GIMP_CANVAS_ITEM_CLASS (parent_class)->get_extents (item, shell);
+  GdkRectangle rectangle;
+  gdouble      x1, y1;
+  gdouble      x2, y2;
+
+  gimp_canvas_line_transform (item, shell, &x1, &y1, &x2, &y2);
+
+  rectangle.x      = MIN (x1, x2) - 1.5;
+  rectangle.y      = MIN (y1, y2) - 1.5;
+  rectangle.width  = ABS (x2 - x1) + 3.0;
+  rectangle.height = ABS (y2 - y1) + 3.0;
+
+  return gdk_region_rectangle (&rectangle);
 }
 
 GimpCanvasItem *
diff --git a/app/display/gimpcanvasrectangle.c b/app/display/gimpcanvasrectangle.c
index 6c66a8b..1b638c4 100644
--- a/app/display/gimpcanvasrectangle.c
+++ b/app/display/gimpcanvasrectangle.c
@@ -253,25 +253,38 @@ gimp_canvas_rectangle_draw (GimpCanvasItem   *item,
   cairo_rectangle (cr, x, y, w, h);
 
   if (private->filled)
-    {
-      _gimp_canvas_item_set_extents (item, x, y, w, h);
-      _gimp_canvas_item_fill (item, shell, cr);
-    }
+    _gimp_canvas_item_fill (item, shell, cr);
   else
-    {
-      _gimp_canvas_item_set_extents (item, x - 1.5, y - 1.5, w + 3.0, h + 3.0);
-      _gimp_canvas_item_stroke (item, shell, cr);
-    }
+    _gimp_canvas_item_stroke (item, shell, cr);
 }
 
 static GdkRegion *
 gimp_canvas_rectangle_get_extents (GimpCanvasItem   *item,
                                    GimpDisplayShell *shell)
 {
-  /*  TODO: for large unfilled rectangles, construct a region which
-   *  contains only the four sides
-   */
-  return GIMP_CANVAS_ITEM_CLASS (parent_class)->get_extents (item, shell);
+  GimpCanvasRectanglePrivate *private = GET_PRIVATE (item);
+  GdkRectangle                rectangle;
+  gdouble                     x, y;
+  gdouble                     w, h;
+
+  gimp_canvas_rectangle_transform (item, shell, &x, &y, &w, &h);
+
+  if (private->filled)
+    {
+      rectangle.x      = floor (x);
+      rectangle.y      = floor (y);
+      rectangle.width  = ceil (w);
+      rectangle.height = ceil (h);
+    }
+  else
+    {
+      rectangle.x      = floor (x - 1.5);
+      rectangle.y      = floor (y - 1.5);
+      rectangle.width  = ceil (w + 3.0);
+      rectangle.height = ceil (h + 3.0);
+    }
+
+  return gdk_region_rectangle (&rectangle);
 }
 
 GimpCanvasItem *



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