[cairo-commit] goocanvas/demo .cvsignore, 1.2, 1.3 Makefile.am, 1.3, 1.4 scalability-demo.c, NONE, 1.1

Damon Chaplin commit at pdx.freedesktop.org
Sun Aug 27 05:20:43 PDT 2006


Committed by: damon

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

Modified Files:
	.cvsignore Makefile.am 
Added Files:
	scalability-demo.c 
Log Message:
2006-08-27  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasview.c (goo_canvas_view_class_init): 
	* src/goocanvasitemviewsimple.c (goo_canvas_item_view_simple_class_init) 
	* src/goocanvasgroupview.c (goo_canvas_group_view_class_init): only
	register the accessible factories if accessibility is enabled (i.e.
	GtkWidget has registered a factory).

	* src/goocanvasitemviewsimple.c (goo_canvas_item_view_simple_setup_accessibility): 
	* src/goocanvasgroupview.c (goo_canvas_group_view_set_group): only
	set the accessible title & description and connect the signal handlers
	if accessibility is enabled. (It would be better to not call
	atk_gobject_accessible_for_object() at all, as it isn't useful.)

	* demo/scalability-demo.c: start of new demo/test for scalability.
	We are currently hitting the cairo 16-bit limit (transformed coords
	can't be larger than 16-bit ints). A workaround would be nice.
	I also want to profile it and see if there are any major bottlenecks.
	(Creating canvases with thousands of items is very slow, though
	scrolling etc. is OK as long as the canvas is split into groups.)



Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/.cvsignore,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- .cvsignore	16 Apr 2006 21:00:54 -0000	1.2
+++ .cvsignore	27 Aug 2006 12:20:40 -0000	1.3
@@ -7,3 +7,4 @@
 *.loT
 demo
 simple-demo
+scalability-demo

Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile.am	22 Apr 2006 19:17:28 -0000	1.3
+++ Makefile.am	27 Aug 2006 12:20:40 -0000	1.4
@@ -7,7 +7,7 @@
 	-I$(top_srcdir)/src \
 	@PACKAGE_CFLAGS@
 
-noinst_PROGRAMS = demo simple-demo
+noinst_PROGRAMS = demo simple-demo scalability-demo
 
 demo_SOURCES = \
 	demo.c demo-fifteen.c demo-scalability.c demo-grabs.c \
@@ -21,5 +21,10 @@
 
 simple_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 
+scalability_demo_SOURCES = \
+	scalability-demo.c
+
+scalability_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
+
 EXTRA_DIST = flower.png toroid.png
 

--- NEW FILE: scalability-demo.c ---
#include <stdlib.h>
#include <goocanvas.h>

#define N_GROUP_COLS 30
#define N_GROUP_ROWS 30
#define N_COLS 10
#define N_ROWS 10
#define PADDING 10

#if 0
#define USE_PIXMAP 
#endif

double total_width, total_height;
double left_offset, top_offset;


static gboolean
on_motion_notify (GooCanvasItemView *view,
		  GooCanvasItemView *target,
		  GdkEventMotion *event,
		  gpointer data)
{
  g_print ("item received 'motion-notify' signal\n");

  return FALSE;
}


static void
on_item_view_created (GooCanvasView     *view,
		      GooCanvasItemView *item_view,
		      GooCanvasItem     *item,
		      gpointer           data)
{
  if (GOO_IS_CANVAS_RECT (item))
    {
      g_signal_connect (item_view, "motion_notify_event",
			(GtkSignalFunc) on_motion_notify, NULL);
    }
}


GooCanvasModel*
create_model (void)
{
  GooCanvasModelSimple *canvas_model;
  GooCanvasItem *root, *group, *item;
  GdkPixbuf *pixbuf;
  int group_i, group_j, i, j;
  double item_width, item_height;
  double cell_width, cell_height;
  double group_width, group_height;

  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
  item_width = gdk_pixbuf_get_width (pixbuf);
  item_height = gdk_pixbuf_get_height (pixbuf);
#else
  item_width = 400/*80*/;
  item_height = 19;
#endif
	
  cell_width = item_width + PADDING * 2;
  cell_height = item_height + PADDING * 2;

  group_width = N_COLS * cell_width;
  group_height = N_ROWS * cell_height;

  total_width = N_GROUP_COLS * group_width;
  total_height = N_GROUP_ROWS * group_height;

  /* We use -ve offsets to test if -ve coords are handled correctly. */
  left_offset = -total_width / 2;
  top_offset = -total_height / 2;

  for (group_i = 0; group_i < N_GROUP_COLS; group_i++)
    {
      for (group_j = 0; group_j < N_GROUP_ROWS; group_j++)
	{
	  double group_x = left_offset + (group_i * group_width);
	  double group_y = top_offset + (group_j * group_height);

	  group = goo_canvas_group_new (root);
	  goo_canvas_item_translate (group, group_x, group_y);

	  for (i = 0; i < N_COLS; i++)
	    {
	      for (j = 0; j < N_ROWS; j++)
		{
		  double item_x = (i * cell_width) + PADDING;
		  double item_y = (j * cell_height) + PADDING;
		  char buffer[256];

#ifdef USE_PIXMAP
		  item = goo_canvas_image_new (group, pixbuf, item_x, item_y, NULL);
#else
		  item = goo_canvas_rect_new (group, item_x, item_y,
					      item_width, item_height,
					      "fill-color", (j % 2) ? "mediumseagreen" : "steelblue",
					      NULL);
#endif

		  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);
		}
	    }
	}
    }

  return (GooCanvasModel*) canvas_model;
}


GtkWidget *
create_canvas (void)
{
  GtkWidget *canvas;
  GooCanvasModel *canvas_model;
  clock_t start;

  /* Create the canvas. */
  canvas = goo_canvas_view_new ();
  gtk_widget_set_size_request (canvas, 600, 450);
  g_signal_connect (canvas, "item_view_created",
		    (GtkSignalFunc) on_item_view_created,
		    NULL);

  start = clock();
  canvas_model = create_model ();
  printf ("Create Model Time Used: %g\n",
	  (double) (clock() - start) / CLOCKS_PER_SEC);

  start = clock();
  goo_canvas_view_set_model (GOO_CANVAS_VIEW (canvas), canvas_model);
  printf ("Create Views Time Used: %g\n",
	  (double) (clock() - start) / CLOCKS_PER_SEC);

  g_object_unref (canvas_model);

  goo_canvas_view_set_bounds (GOO_CANVAS_VIEW (canvas),
			      left_offset, top_offset,
			      left_offset + total_width,
			      top_offset + total_height);
  gtk_widget_show (canvas);

  return canvas;
}


static gboolean
on_delete_event (GtkWidget *window,
		 GdkEvent  *event,
		 gpointer   unused_data)
{
  exit (0);
}


int
main (int argc, char *argv[])
{
  GtkWidget *window, *scrolled_win, *canvas;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
  gtk_widget_show (window);
  g_signal_connect (window, "delete_event", (GtkSignalFunc) on_delete_event,
		    NULL);

  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (scrolled_win);
  gtk_container_add (GTK_CONTAINER (window), scrolled_win);

  canvas = create_canvas ();
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  gtk_main ();

  return 0;
}





More information about the cairo-commit mailing list