[cairo-commit] cairo/src cairo-private.h, 1.2, 1.3 cairo.c, 1.106,
1.107 cairo.h, 1.129, 1.130
Carl Worth
commit at pdx.freedesktop.org
Thu Jun 16 12:20:48 PDT 2005
Committed by: cworth
Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv4064/src
Modified Files:
cairo-private.h cairo.c cairo.h
Log Message:
* src/cairo-private.h: Reorder fields of cairo_private_t to match
initialization order.
* src/cairo.c: (_cairo_error): Call error_notify callback if set.
(cairo_create): Initialize error_notify callback to NULL.
(cairo_set_error_notify): New function to allow the user to set
an error notify callback.
* src/cairo.h: New cairo_set_error_notify prototye.
* test/.cvsignore:
* test/Makefile.am:
* test/error-notify.c: (toggle_status), (do_test), (main): New
test for cairo_set_error_notify.
Index: cairo-private.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-private.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cairo-private.h 26 Apr 2005 19:38:06 -0000 1.2
+++ cairo-private.h 16 Jun 2005 19:20:46 -0000 1.3
@@ -42,10 +42,14 @@
struct _cairo {
unsigned int ref_count;
- cairo_gstate_t *gstate;
+ cairo_status_t status;
+
+ cairo_error_notify_func_t error_notify;
+ void *error_notify_closure;
+
cairo_path_fixed_t path;
- cairo_status_t status;
+ cairo_gstate_t *gstate;
};
#endif /* CAIRO_PRIVATE_H */
Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- cairo.c 15 Jun 2005 17:52:01 -0000 1.106
+++ cairo.c 16 Jun 2005 19:20:46 -0000 1.107
@@ -45,7 +45,9 @@
static const cairo_t cairo_nil = {
(unsigned int)-1, /* ref_count */
- NULL, /* gstate */
+ CAIRO_STATUS_NO_MEMORY, /* status */
+ NULL, /* error_notify */
+ NULL, /* error_notify_closure */
{ /* path */
NULL, NULL, /* op_buf_head, op_buf_tail */
NULL, NULL, /* arg_buf_head, arg_buf_tail */
@@ -53,7 +55,7 @@
{ 0, 0 }, /* current point */
FALSE, /* has_current_point */
},
- CAIRO_STATUS_NO_MEMORY /* status */
+ NULL /* gstate */
};
#include <assert.h>
@@ -87,6 +89,9 @@
status <= CAIRO_STATUS_LAST_STATUS);
cr->status = status;
+
+ if (cr->error_notify)
+ (cr->error_notify) (cr->error_notify_closure, status);
}
/**
@@ -131,9 +136,13 @@
if (cr == NULL)
return (cairo_t *) &cairo_nil;
- cr->status = CAIRO_STATUS_SUCCESS;
cr->ref_count = 1;
+ cr->status = CAIRO_STATUS_SUCCESS;
+
+ cr->error_notify = NULL;
+ cr->error_notify_closure = NULL;
+
_cairo_path_fixed_init (&cr->path);
if (target == NULL) {
@@ -2321,6 +2330,30 @@
return "<unknown error status>";
}
+/**
+ * cairo_set_error_notify:
+ * @cr: a cairo context
+ * @error_notify: an function to be called when an error occurs
+ * @closure: a closure argument to be passed to @error_notify
+ *
+ * Installs an error notifier within @cr. If an error is set within
+ * @cr, (eg. such that cairo_status(@cr) would return something other
+ * than CAIRO_STATUS_SUCCESS), then @error_notify will be called with
+ * the given @closure value as well as the #cairo_status_t value of
+ * the error.
+ *
+ * An error notifier can be cleared by passing NULL for @error_notify
+ * and for @closure.
+ **/
+void
+cairo_set_error_notify (cairo_t *cr,
+ cairo_error_notify_func_t error_notify,
+ void *closure)
+{
+ cr->error_notify = error_notify;
+ cr->error_notify_closure = closure;
+}
+
void
_cairo_restrict_value (double *value, double min, double max)
{
Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- cairo.h 15 Jun 2005 17:52:01 -0000 1.129
+++ cairo.h 16 Jun 2005 19:20:46 -0000 1.130
@@ -884,6 +884,20 @@
const char *
cairo_status_to_string (cairo_status_t status);
+/**
+ * cairo_error_notify_func_t
+ *
+ * #cairo_error_notify_func_t the type of function which is called
+ * when an error is detected by cairo. It is passed a closure and the
+ * #cairo_status_t value of the error.
+ */
+typedef void (*cairo_error_notify_func_t) (void *closure, cairo_status_t status);
+
+void
+cairo_set_error_notify (cairo_t *cr,
+ cairo_error_notify_func_t error_notify,
+ void *closure);
+
/* Surface manipulation */
/**
More information about the cairo-commit
mailing list