[cairo-commit] goocanvas/demo scalability-demo.c,1.1,1.2

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


Committed by: damon

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

Modified Files:
	scalability-demo.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: scalability-demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/scalability-demo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- scalability-demo.c	27 Aug 2006 12:20:40 -0000	1.1
+++ scalability-demo.c	30 Aug 2006 12:18:47 -0000	1.2
@@ -1,8 +1,8 @@
 #include <stdlib.h>
 #include <goocanvas.h>
 
-#define N_GROUP_COLS 30
-#define N_GROUP_ROWS 30
+#define N_GROUP_COLS 25
+#define N_GROUP_ROWS 20
 #define N_COLS 10
 #define N_ROWS 10
 #define PADDING 10
@@ -11,6 +11,10 @@
 #define USE_PIXMAP 
 #endif
 
+#if 0
+#define ONLY_ONE
+#endif
+
 double total_width, total_height;
 double left_offset, top_offset;
 
@@ -21,7 +25,10 @@
 		  GdkEventMotion *event,
 		  gpointer data)
 {
-  g_print ("item received 'motion-notify' signal\n");
+  GooCanvasItem *item = goo_canvas_item_view_get_item (target);
+  gchar *id = g_object_get_data (G_OBJECT (item), "id");
+
+  g_print ("%s item received 'motion-notify' signal\n", id ? id : "Unknown");
 
   return FALSE;
 }
@@ -33,7 +40,7 @@
 		      GooCanvasItem     *item,
 		      gpointer           data)
 {
-  if (GOO_IS_CANVAS_RECT (item))
+  if (GOO_IS_CANVAS_RECT (item) || GOO_IS_CANVAS_IMAGE (item))
     {
       g_signal_connect (item_view, "motion_notify_event",
 			(GtkSignalFunc) on_motion_notify, NULL);
@@ -46,20 +53,24 @@
 {
   GooCanvasModelSimple *canvas_model;
   GooCanvasItem *root, *group, *item;
-  GdkPixbuf *pixbuf;
+  GdkPixbuf *pixbuf = NULL;
+  cairo_pattern_t *pattern = NULL;
   int group_i, group_j, i, j;
   double item_width, item_height;
   double cell_width, cell_height;
   double group_width, group_height;
+  int total_items = 0;
 
   canvas_model = goo_canvas_model_simple_new ();
   root = goo_canvas_model_get_root_item (GOO_CANVAS_MODEL (canvas_model));
 
-  pixbuf = gdk_pixbuf_new_from_file("toroid.png", NULL);
 #ifdef USE_PIXMAP
+  pixbuf = gdk_pixbuf_new_from_file("toroid.png", NULL);
   item_width = gdk_pixbuf_get_width (pixbuf);
   item_height = gdk_pixbuf_get_height (pixbuf);
+  pattern = goo_canvas_cairo_pattern_from_pixbuf (pixbuf);
 #else
+  pixbuf = NULL;
   item_width = 400/*80*/;
   item_height = 19;
 #endif
@@ -85,6 +96,7 @@
 	  double group_y = top_offset + (group_j * group_height);
 
 	  group = goo_canvas_group_new (root);
+	  total_items++;
 	  goo_canvas_item_translate (group, group_x, group_y);
 
 	  for (i = 0; i < N_COLS; i++)
@@ -93,30 +105,63 @@
 		{
 		  double item_x = (i * cell_width) + PADDING;
 		  double item_y = (j * cell_height) + PADDING;
+		  double rotation = i % 10 * 2;
+		  double rotation_x = item_x + item_width / 2;
+		  double rotation_y = item_y + item_height / 2;
 		  char buffer[256];
 
+		  sprintf (buffer, "%g, %g",
+			   group_x + item_x, group_y + item_y);
+
 #ifdef USE_PIXMAP
-		  item = goo_canvas_image_new (group, pixbuf, item_x, item_y, NULL);
+		  item = goo_canvas_image_new (group, NULL, item_x, item_y,
+					       "pattern", pattern,
+					       "width", item_width,
+					       "height", item_height,
+					       NULL);
+		  total_items++;
 #else
 		  item = goo_canvas_rect_new (group, item_x, item_y,
 					      item_width, item_height,
 					      "fill-color", (j % 2) ? "mediumseagreen" : "steelblue",
 					      NULL);
+		  total_items++;
+		  goo_canvas_item_rotate (item, rotation, rotation_x, rotation_y);
 #endif
+		  g_object_set_data (G_OBJECT (item), "id", g_strdup (buffer));
 
-		  sprintf (buffer, "%g, %g",
-			   group_x + item_x, group_y + item_y);
 		  item = goo_canvas_text_new (group, buffer,
 					      item_x + item_width / 2,
 					      item_y + item_height / 2,
 					      -1, GTK_ANCHOR_CENTER,
 					      "font", "Sans 8",
 					      NULL);
+		  total_items++;
+		  goo_canvas_item_rotate (item, rotation, rotation_x, rotation_y);
+
+
+#ifdef ONLY_ONE
+		  break;
+#endif
 		}
+#ifdef ONLY_ONE
+	      break;
+#endif
 	    }
+#ifdef ONLY_ONE
+	  break;
+#endif
 	}
+#ifdef ONLY_ONE
+      break;
+#endif
     }
 
+  if (pattern)
+    cairo_pattern_destroy (pattern);
+
+  g_print ("Total items: %i\n", total_items);
+
   return (GooCanvasModel*) canvas_model;
 }
 



More information about the cairo-commit mailing list