[cairo-commit] cairo-5c ChangeLog, 1.15, 1.16 cairo-5c.h, 1.9, 1.10 cairo.5c, 1.7, 1.8 cairo.c, 1.1, 1.2 gtk.c, 1.5, 1.6 init.c, 1.10, 1.11 surface.c, 1.8, 1.9

Keith Packard commit at pdx.freedesktop.org
Fri Dec 24 01:00:12 PST 2004


Committed by: keithp

Update of /cvs/cairo/cairo-5c
In directory gabe:/tmp/cvs-serv20957

Modified Files:
	ChangeLog cairo-5c.h cairo.5c cairo.c gtk.c init.c surface.c 
Log Message:
2004-12-24  Keith Packard  <keithp at keithp.com>

	* cairo-5c.h:
	* cairo.5c:
	* cairo.c: (do_Cairo_set_target_surface):
	* gtk.c: (delete_drawing_area), (gtk_tool_free),
	(cairo_5c_tool_create), (cairo_5c_tool_destroy):
	* init.c: (nickle_init):
	* surface.c: (create_cairo_window), (cairo_5c_surface_get),
	(do_Cairo_Surface_create_window):
	Handle window delete more gracefully; report exception on drawing,
	report 'delete' event to event reader.
	Have default surface creation code re-create a surface when the old
	default surface has been destroyed.


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-5c/ChangeLog,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- ChangeLog	24 Dec 2004 00:09:24 -0000	1.15
+++ ChangeLog	24 Dec 2004 09:00:10 -0000	1.16
@@ -1,3 +1,18 @@
+2004-12-24  Keith Packard  <keithp at keithp.com>
+
+	* cairo-5c.h:
+	* cairo.5c:
+	* cairo.c: (do_Cairo_set_target_surface):
+	* gtk.c: (delete_drawing_area), (gtk_tool_free),
+	(cairo_5c_tool_create), (cairo_5c_tool_destroy):
+	* init.c: (nickle_init):
+	* surface.c: (create_cairo_window), (cairo_5c_surface_get),
+	(do_Cairo_Surface_create_window):
+	Handle window delete more gracefully; report exception on drawing,
+	report 'delete' event to event reader.
+	Have default surface creation code re-create a surface when the old
+	default surface has been destroyed.
+
 2004-12-23  Keith Packard  <keithp at keithp.com>
 
 	* examples/grid.5c:

Index: cairo-5c.h
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo-5c.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- cairo-5c.h	23 Dec 2004 22:39:40 -0000	1.9
+++ cairo-5c.h	24 Dec 2004 09:00:10 -0000	1.10
@@ -150,7 +150,7 @@
 cairo_5c_surface_get (Value av);
 
 Value
-do_Cairo_Surface_create_window (Value wv, Value hv);
+do_Cairo_Surface_create_window (Value namev, Value wv, Value hv);
 
 Value
 do_Cairo_Surface_create_png (Value fv, Value wv, Value hv);
@@ -446,7 +446,7 @@
 /* gtk.c */
 
 Bool
-cairo_5c_tool_create (cairo_5c_surface_t *c5s, int width, int height);
+cairo_5c_tool_create (cairo_5c_surface_t *c5s, char *name, int width, int height);
 
 Bool
 cairo_5c_tool_destroy (cairo_5c_surface_t *c5s);

Index: cairo.5c
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo.5c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cairo.5c	23 Dec 2004 22:39:40 -0000	1.7
+++ cairo.5c	24 Dec 2004 09:00:10 -0000	1.8
@@ -59,19 +59,43 @@
 	int w = dim(args) > 0 ? args[0] : 0;
 	int h = dim(args) > 1 ? args[1] : 0;
 
-	static surface_t    surface;
-	static bool	    been_here = false;
-	static mutex	    m = Mutex::new();
+	typedef union {
+	    void	none;
+	    surface_t	surface;
+	} surface_or_none_t;
+	
+	static surface_or_none_t    surface = surface_or_none_t.none;
+	static mutex		    m = Mutex::new();
 
-	Mutex::acquire (m);
-	if (!been_here) {
-	    been_here = true;
-	    surface = Surface::create_window (w, h);
+	/*
+	 * A local function to make sure the 'default' surface
+	 * exists
+	 */
+	void ensure_surface () 
+	{
+	    Mutex::acquire (m);
+	    union switch (surface) {
+	    case none:
+		string name = (dim (argv) > 0) ? argv[0] : "nickle";
+		surface.surface = Surface::create_window (name, w, h);
+		break;
+	    case surface:
+		break;
+	    }
+	    Mutex::release (m);
 	}
-	Mutex::release (m);
 
 	cairo_t	cr = create ();
-	set_target_surface (cr, surface);
+	
+	try 
+	{
+	    ensure_surface ();
+	    set_target_surface (cr, surface.surface);
+	} catch invalid_argument (string reason, int i, poly arg) {
+	    surface = surface_or_none_t.none;
+	    ensure_surface ();
+	    set_target_surface (cr, surface.surface);
+	}
 	set_rgb_color (cr, 1, 1, 1);
 	rectangle (cr, 0, 0, Cairo::width (cr), Cairo::height (cr));
 	fill (cr);

Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cairo.c	23 Dec 2004 22:39:40 -0000	1.1
+++ cairo.c	24 Dec 2004 09:00:10 -0000	1.2
@@ -216,11 +216,10 @@
     cairo_5c_t		*c5c = cairo_5c_get (cv);
     cairo_5c_surface_t	*c5s = cairo_5c_surface_get (sv);
 
-    if (!aborting)
-    {
-	cairo_set_target_surface (c5c->cr, c5s->surface);
-	c5c->surface = sv;
-    }
+    if (aborting)
+	RETURN (Void);
+    cairo_set_target_surface (c5c->cr, c5s->surface);
+    c5c->surface = sv;
     RETURN (Void);
 }
 

Index: gtk.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/gtk.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- gtk.c	24 Dec 2004 00:09:24 -0000	1.5
+++ gtk.c	24 Dec 2004 09:00:10 -0000	1.6
@@ -112,12 +112,21 @@
 delete_drawing_area (GtkWidget *widget, gpointer data)
 {			   
     cairo_5c_surface_t	*c5s = GTK_DRAWING_AREA (widget)->draw_data;
+    cairo_5c_tool_t	*tool = c5s->u.window.tool;
     
     if (c5s->u.window.send_events)
     {
 	fprintf (c5s->u.window.send_events, "%d delete\n", 0);
 	fflush (c5s->u.window.send_events);
     }
+    tool->drawing_area = NULL;
+    tool->window = NULL;
+    if (tool->pixmap)
+    {
+	gdk_drawable_unref (tool->pixmap);
+	tool->pixmap = NULL;
+    }
+    c5s->u.window.pixmap = None;
 }
 
 static gboolean
@@ -300,6 +309,7 @@
     {
 	gtk_widget_destroy (tool->window);
 	tool->window = NULL;
+	tool->drawing_area = NULL;
     }
     if (tool->pixmap)
     {
@@ -313,7 +323,7 @@
 static DataType gtk_tool_type = { gtk_tool_mark, gtk_tool_free, "GtkTool" };
 
 Bool
-cairo_5c_tool_create (cairo_5c_surface_t *c5s, int width, int height)
+cairo_5c_tool_create (cairo_5c_surface_t *c5s, char *name, int width, int height)
 {
     ENTER ();
     gtk_global_t    *gg = gtk_global ? gtk_global : create_gtk_global ();
@@ -348,6 +358,7 @@
     tool->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_window_set_default_size (GTK_WINDOW(tool->window),
 				 width, height);
+    gtk_window_set_title (GTK_WINDOW (tool->window), name);
     
     tool->drawing_area = gtk_drawing_area_new ();
     
@@ -393,20 +404,7 @@
 Bool
 cairo_5c_tool_destroy (cairo_5c_surface_t *c5s)
 {
-    cairo_5c_tool_t *tool = c5s->u.window.tool;
-
-    gdk_threads_enter ();
-    if (tool->window)
-    {
-	gtk_widget_destroy (tool->window);
-	tool->window = NULL;
-    }
-    if (tool->pixmap)
-    {
-	gdk_drawable_unref (tool->pixmap);
-	tool->pixmap = NULL;
-    }
-    gdk_threads_leave ();
+    /* let nickle allocator free it */
     return True;
 }
 

Index: init.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/init.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- init.c	23 Dec 2004 22:39:40 -0000	1.10
+++ init.c	24 Dec 2004 09:00:10 -0000	1.11
@@ -825,15 +825,11 @@
 	{ 0 }
     };
 
-    static const struct fbuiltin_2 surfuncs_2[] = {
-	{ do_Cairo_Surface_create_window, "create_window", SURFACE_S, "nn", "\n"
+    static const struct fbuiltin_3 surfuncs_3[] = {
+	{ do_Cairo_Surface_create_window, "create_window", SURFACE_S, "snn", "\n"
 	    " surface_t create_window (real width, real height)\n"
 	    "\n"
 	    " Create a window and return a surface pointer for it\n" },
-	{ 0 }
-    };
-
-    static const struct fbuiltin_3 surfuncs_3[] = {
 	{ do_Cairo_Surface_create_png, "create_png", SURFACE_S, "snn", "\n"
 	    " surface_t create_png (string filename, real width, real height)\n"
 	    "\n"
@@ -925,7 +921,6 @@
     BuiltinFuncs7 (&CairoNamespace, funcs_7);
 
     BuiltinFuncs1 (&CairoSurfaceNamespace, surfuncs_1);
-    BuiltinFuncs2 (&CairoSurfaceNamespace, surfuncs_2);
     BuiltinFuncs3 (&CairoSurfaceNamespace, surfuncs_3);
     BuiltinFuncs5 (&CairoSurfaceNamespace, surfuncs_5);
     

Index: surface.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/surface.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- surface.c	23 Dec 2004 22:39:40 -0000	1.8
+++ surface.c	24 Dec 2004 09:00:10 -0000	1.9
@@ -44,6 +44,13 @@
     
     if (c5s->surface)
 	cairo_surface_destroy (c5s->surface);
+    if (!c5s->u.window.pixmap)
+    {
+	RaiseStandardException (exception_invalid_argument,
+				"window destroyed",
+				2, NewInt (0), NewInt (0));
+	return False;
+    }
     c5s->surface = cairo_xlib_surface_create (dpy,
 					      c5s->u.window.pixmap,
 					      DefaultVisual (dpy, DefaultScreen (dpy)),
@@ -82,7 +89,8 @@
     switch (c5s->kind) {
     case CAIRO_5C_WINDOW:
 	if (c5s->u.window.curpix != c5s->u.window.pixmap)
-	    create_cairo_window (c5s);
+	    if (!create_cairo_window (c5s))
+		return 0;
 	break;
     case CAIRO_5C_PNG:
     case CAIRO_5C_PS:
@@ -156,11 +164,12 @@
 }
 
 Value
-do_Cairo_Surface_create_window (Value wv, Value hv)
+do_Cairo_Surface_create_window (Value namev, Value wv, Value hv)
 {
     ENTER ();
     cairo_5c_surface_t	*c5s;
     Value		ret;
+    char		*name = StrzPart (namev, "invalid name");
     int			width = IntPart (wv, "invalid width");
     int			height = IntPart (hv, "invalid height");
     
@@ -175,7 +184,7 @@
     c5s->dirty = False;
     c5s->recv_events = Void;
     
-    if (!cairo_5c_tool_create (c5s, width, height))
+    if (!cairo_5c_tool_create (c5s, name, width, height))
     {
 	RaiseStandardException (exception_open_error,
 				"Can't create window",




More information about the cairo-commit mailing list