[cairo-commit] goocanvas/src goocanvasitemviewsimple.c, 1.12, 1.13 goocanvaspolylineview.c, 1.17, 1.18 goocanvasview.c, 1.30, 1.31

Damon Chaplin commit at pdx.freedesktop.org
Wed Aug 30 05:18:50 PDT 2006


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv7123/src

Modified Files:
	goocanvasitemviewsimple.c goocanvaspolylineview.c 
	goocanvasview.c 
Log Message:
2006-08-30  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasitemviewsimple.c (goo_canvas_item_view_simple_update) 
	* src/goocanvaspolylineview.c (goo_canvas_polyline_view_update): 
	added a workaround for cairo limits. Cairo uses fixed point integer
	maths and is currently limited to 16-bits for the integer component.
	So we remove any current translation before calculating the bounds
	of the item, then add it back to the results. This means the 16-bit
	limit only applies to items' user space rather than the entire canvas.

	* src/goocanvasitemviewsimple.c
	(goo_canvas_item_view_simple_get_item_view_at): 
	* src/goocanvaspolylineview.c
	(goo_canvas_polyline_view_get_item_view_at): as above, remove any
	current translation before checking if the point is in the item.

	* demo/scalability-demo.c: updated to create ~100,000 items, either
	rectangles or images. For images it now reuses a single cairo pattern
	rather than passing the pixbuf to the GooCanvasImage (which created a
	new pattern for each one and ran out of memory). It takes about 10
	seconds to setup the canvas which is slower than I'd like, but once
	created it seems to work fast enough.



Index: goocanvasitemviewsimple.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemviewsimple.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- goocanvasitemviewsimple.c	27 Aug 2006 12:20:40 -0000	1.12
+++ goocanvasitemviewsimple.c	30 Aug 2006 12:18:48 -0000	1.13
@@ -247,6 +247,7 @@
   GooCanvasItemView *found_view = NULL;
   double user_x = x, user_y = y;
   GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;
+  cairo_matrix_t matrix;
 
   if (simple_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE)
     goo_canvas_item_view_ensure_updated (view);
@@ -274,6 +275,11 @@
 
   cairo_device_to_user (cr, &user_x, &user_y);
 
+  /* Remove any current translation, to avoid the 16-bit cairo limit. */
+  cairo_get_matrix (cr, &matrix);
+  matrix.x0 = matrix.y0 = 0.0;
+  cairo_set_matrix (cr, &matrix);
+
   /* Use the virtual method subclasses define to create the path. */
   GOO_CANVAS_ITEM_VIEW_SIMPLE_GET_CLASS (view)->create_path (simple, cr);
 
@@ -313,6 +319,8 @@
 {
   GooCanvasItemViewSimple *simple_view = (GooCanvasItemViewSimple*) view;
   GooCanvasItemSimple *simple = simple_view->item;
+  cairo_matrix_t matrix;
+  double x_offset, y_offset;
 
   if (entire_tree || (simple_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE))
     {
@@ -324,6 +332,13 @@
       if (simple_view->transform)
 	cairo_transform (cr, simple_view->transform);
 
+      /* Remove any current translation, to avoid the 16-bit cairo limit. */
+      cairo_get_matrix (cr, &matrix);
+      x_offset = matrix.x0;
+      y_offset = matrix.y0;
+      matrix.x0 = matrix.y0 = 0.0;
+      cairo_set_matrix (cr, &matrix);
+
       /* Request a redraw of the existing bounds. */
       goo_canvas_view_request_redraw (simple_view->canvas_view,
 				      &simple_view->bounds);
@@ -335,6 +350,12 @@
       goo_canvas_item_simple_get_path_bounds (simple, cr,
 					      &simple_view->bounds);
 
+      /* Add the translation back to the bounds. */
+      simple_view->bounds.x1 += x_offset;
+      simple_view->bounds.y1 += y_offset;
+      simple_view->bounds.x2 += x_offset;
+      simple_view->bounds.y2 += y_offset;
+
       /* Request a redraw of the new bounds. */
       goo_canvas_view_request_redraw (simple_view->canvas_view,
 				      &simple_view->bounds);

Index: goocanvaspolylineview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvaspolylineview.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- goocanvaspolylineview.c	24 Aug 2006 08:06:23 -0000	1.17
+++ goocanvaspolylineview.c	30 Aug 2006 12:18:48 -0000	1.18
@@ -187,6 +187,7 @@
   GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;
   GooCanvasStyle *style = simple->style;
   gboolean do_stroke = TRUE;
+  cairo_matrix_t matrix;
 
   if (simple_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE)
     goo_canvas_item_view_ensure_updated (view);
@@ -217,6 +218,11 @@
 
   cairo_device_to_user (cr, &user_x, &user_y);
 
+  /* Remove any current translation, to avoid the 16-bit cairo limit. */
+  cairo_get_matrix (cr, &matrix);
+  matrix.x0 = matrix.y0 = 0.0;
+  cairo_set_matrix (cr, &matrix);
+
   goo_canvas_polyline_view_create_path (polyline, cr);
   if (goo_canvas_item_simple_check_in_path (simple, user_x, user_y, cr,
 					    pointer_events))
@@ -313,6 +319,8 @@
   GooCanvasPolylineView *polyline_view = (GooCanvasPolylineView*) view;
   GooCanvasItemSimple *simple = simple_view->item;
   GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
+  cairo_matrix_t matrix;
+  double x_offset, y_offset;
 
   if (entire_tree || (simple_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE))
     {
@@ -327,6 +335,13 @@
       if (simple_view->transform)
 	cairo_transform (cr, simple_view->transform);
 
+      /* Remove any current translation, to avoid the 16-bit cairo limit. */
+      cairo_get_matrix (cr, &matrix);
+      x_offset = matrix.x0;
+      y_offset = matrix.y0;
+      matrix.x0 = matrix.y0 = 0.0;
+      cairo_set_matrix (cr, &matrix);
+
       /* Request a redraw of the existing bounds. */
       goo_canvas_view_request_redraw (simple_view->canvas_view,
 				      &simple_view->bounds);
@@ -335,6 +350,12 @@
       goo_canvas_polyline_view_compute_bounds (polyline_view, polyline, cr,
 					       &simple_view->bounds);
 
+      /* Add the translation back to the bounds. */
+      simple_view->bounds.x1 += x_offset;
+      simple_view->bounds.y1 += y_offset;
+      simple_view->bounds.x2 += x_offset;
+      simple_view->bounds.y2 += y_offset;
+
       /* Request a redraw of the new bounds. */
       goo_canvas_view_request_redraw (simple_view->canvas_view,
 				      &simple_view->bounds);

Index: goocanvasview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasview.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- goocanvasview.c	27 Aug 2006 12:20:40 -0000	1.30
+++ goocanvasview.c	30 Aug 2006 12:18:48 -0000	1.31
@@ -1519,7 +1519,8 @@
   bounds.x2 = (event->area.width / view->scale) + bounds.x1;
   bounds.y2 = (event->area.height / view->scale) + bounds.y1;
 
-  /* Translate it to use the canvas pixel offsets. */
+  /* Translate it to use the canvas pixel offsets (used when the canvas is
+     smaller than the window and the anchor isn't set to NORTH_WEST). */
   cairo_translate (cr, view->canvas_x_offset, view->canvas_y_offset);
 
   /* Scale it so we can use canvas coordinates. */



More information about the cairo-commit mailing list