[cairo-commit] cairo-perl Cairo.xs, 1.9, 1.10 CairoFont.xs, 1.5,
1.6 CairoMatrix.xs, 1.6, 1.7 CairoPattern.xs, 1.7,
1.8 CairoSurface.xs, 1.9, 1.10 ChangeLog, 1.19, 1.20 TODO, 1.3,
1.4 cairo-perl-private.h, 1.1, 1.2
Torsten Schoenfeld
commit at pdx.freedesktop.org
Sun May 14 06:43:12 PDT 2006
Committed by: tsch
Update of /cvs/cairo/cairo-perl
In directory kemper:/tmp/cvs-serv17130
Modified Files:
Cairo.xs CairoFont.xs CairoMatrix.xs CairoPattern.xs
CairoSurface.xs ChangeLog TODO cairo-perl-private.h
Log Message:
* t/CairoSurface.t, CairoSurface.xs: Remove
Cairo::Surface::finish; it's memory management related and not
needed, as far as I can tell. Scream if you used it.
* t/CairoSurface.t, CairoSurface.xs: Bind and test
cairo_surface_write_to_png_stream,
cairo_image_surface_create_from_png_stream,
cairo_pdf_surface_create_for_stream, and
cairo_ps_surface_create_for_stream.
* CairoSurface.xs: Don't leak cairo_surface_create_similar's
return value.
* cairo-perl-private.h: Remove CAIRO_PERL_UNUSED.
* cairo-perl-private.h, Cairo.xs, CairoFont.xs, CairoMatrix.xs,
CairoPattern.xs: Rename pcairo_copy_matrix to
cairo_perl_copy_matrix.
* TODO: Update.
Index: Cairo.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/Cairo.xs,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Cairo.xs 7 May 2006 14:17:39 -0000 1.9
+++ Cairo.xs 14 May 2006 13:43:10 -0000 1.10
@@ -376,7 +376,7 @@
cairo_matrix_t matrix;
CODE:
cairo_get_font_matrix (cr, &matrix);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
@@ -489,7 +489,7 @@
cairo_matrix_t matrix;
CODE:
cairo_get_matrix (cr, &matrix);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
Index: CairoFont.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/CairoFont.xs,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CairoFont.xs 7 May 2006 14:17:39 -0000 1.5
+++ CairoFont.xs 14 May 2006 13:43:10 -0000 1.6
@@ -75,7 +75,7 @@
cairo_matrix_t font_matrix;
CODE:
cairo_scaled_font_get_font_matrix (scaled_font, &font_matrix);
- RETVAL = pcairo_copy_matrix (&font_matrix);
+ RETVAL = cairo_perl_copy_matrix (&font_matrix);
OUTPUT:
RETVAL
@@ -85,7 +85,7 @@
cairo_matrix_t ctm;
CODE:
cairo_scaled_font_get_ctm (scaled_font, &ctm);
- RETVAL = pcairo_copy_matrix (&ctm);
+ RETVAL = cairo_perl_copy_matrix (&ctm);
OUTPUT:
RETVAL
Index: CairoMatrix.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/CairoMatrix.xs,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- CairoMatrix.xs 7 May 2006 14:17:39 -0000 1.6
+++ CairoMatrix.xs 14 May 2006 13:43:10 -0000 1.7
@@ -9,7 +9,7 @@
#include <cairo-perl.h>
cairo_matrix_t *
-pcairo_copy_matrix (cairo_matrix_t *src)
+cairo_perl_copy_matrix (cairo_matrix_t *src)
{
cairo_matrix_t *dst = malloc (sizeof (cairo_matrix_t));
@@ -31,7 +31,7 @@
cairo_matrix_t matrix;
CODE:
cairo_matrix_init (&matrix, xx, yx, xy, yy, x0, y0);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
@@ -41,7 +41,7 @@
cairo_matrix_t matrix;
CODE:
cairo_matrix_init_identity (&matrix);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
@@ -51,7 +51,7 @@
cairo_matrix_t matrix;
CODE:
cairo_matrix_init_translate (&matrix, tx, ty);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
@@ -61,7 +61,7 @@
cairo_matrix_t matrix;
CODE:
cairo_matrix_init_scale (&matrix, sx, sy);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
@@ -71,7 +71,7 @@
cairo_matrix_t matrix;
CODE:
cairo_matrix_init_rotate (&matrix, radians);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
@@ -89,7 +89,7 @@
cairo_matrix_t matrix;
CODE:
cairo_matrix_multiply (&matrix, a, b);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
Index: CairoPattern.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/CairoPattern.xs,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- CairoPattern.xs 7 May 2006 14:17:39 -0000 1.7
+++ CairoPattern.xs 14 May 2006 13:43:10 -0000 1.8
@@ -64,7 +64,7 @@
cairo_matrix_t matrix;
CODE:
cairo_pattern_get_matrix (pattern, &matrix);
- RETVAL = pcairo_copy_matrix (&matrix);
+ RETVAL = cairo_perl_copy_matrix (&matrix);
OUTPUT:
RETVAL
Index: CairoSurface.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/CairoSurface.xs,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- CairoSurface.xs 7 May 2006 14:17:39 -0000 1.9
+++ CairoSurface.xs 14 May 2006 13:43:10 -0000 1.10
@@ -56,18 +56,145 @@
return sv;
}
+/* -------------------------------------------------------------------------- */
+
+typedef struct {
+ SV *func;
+ SV *data;
+ void *context;
+} CairoPerlCallback;
+
+#ifdef PERL_IMPLICIT_CONTEXT
+# define dCAIRO_PERL_CALLBACK_MARSHAL_SP \
+ SV ** sp;
+# define CAIRO_PERL_CALLBACK_MARSHAL_INIT(callback) \
+ PERL_SET_CONTEXT (callback->context); \
+ SPAGAIN;
+#else
+# define dCAIRO_PERL_CALLBACK_MARSHAL_SP \
+ dSP;
+# define CAIRO_PERL_CALLBACK_MARSHAL_INIT(callback) \
+ /* nothing to do */
+#endif
+
+static CairoPerlCallback *
+cairo_perl_callback_new (SV *func, SV *data)
+{
+ CairoPerlCallback *callback;
+
+ callback = calloc (sizeof (CairoPerlCallback), 1);
+
+ callback->func = newSVsv (func);
+ if (data)
+ callback->data = newSVsv (data);
+
+#ifdef PERL_IMPLICIT_CONTEXT
+ callback->context = aTHX;
+#endif
+
+ return callback;
+}
+
+static void
+cairo_perl_callback_free (CairoPerlCallback *callback)
+{
+ SvREFCNT_dec (callback->func);
+ if (callback->data)
+ SvREFCNT_dec (callback->data);
+ free (callback);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static cairo_status_t
+write_func_marshaller (void *closure,
+ const unsigned char *data,
+ unsigned int length)
+{
+ CairoPerlCallback *callback;
+ cairo_status_t status;
+ dCAIRO_PERL_CALLBACK_MARSHAL_SP;
+
+ callback = (CairoPerlCallback *) closure;
+
+ CAIRO_PERL_CALLBACK_MARSHAL_INIT (callback);
+
+ ENTER;
+ SAVETMPS;
+ PUSHMARK (SP);
+
+ EXTEND (SP, 2);
+ PUSHs (callback->data ? callback->data : &PL_sv_undef);
+ PUSHs (sv_2mortal (newSVpv ((const char *) data, length)));
+
+ PUTBACK;
+ call_sv (callback->func, G_DISCARD | G_EVAL);
+ SPAGAIN;
+
+ status = SvTRUE (ERRSV) ? SvCairoStatus (ERRSV) : CAIRO_STATUS_SUCCESS;
+
+ PUTBACK;
+ FREETMPS;
+ LEAVE;
+
+ return status;
+}
+
+/* -------------------------------------------------------------------------- */
+
+static cairo_status_t
+read_func_marshaller (void *closure,
+ unsigned char *data,
+ unsigned int length)
+{
+ CairoPerlCallback *callback;
+ cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ dCAIRO_PERL_CALLBACK_MARSHAL_SP;
+
+ callback = (CairoPerlCallback *) closure;
+
+ CAIRO_PERL_CALLBACK_MARSHAL_INIT (callback);
+
+ ENTER;
+ SAVETMPS;
+ PUSHMARK (SP);
+
+ EXTEND (SP, 2);
+ PUSHs (callback->data ? callback->data : &PL_sv_undef);
+ PUSHs (sv_2mortal (newSVuv (length)));
+
+ PUTBACK;
+ call_sv (callback->func, G_SCALAR | G_EVAL);
+ SPAGAIN;
+
+ if (SvTRUE (ERRSV)) {
+ status = SvCairoStatus (ERRSV);
+ } else {
+ STRLEN n_a;
+ char *retval;
+ retval = POPpx;
+ memcpy (data, retval, n_a);
+ }
+
+ PUTBACK;
+ FREETMPS;
+ LEAVE;
+
+ return status;
+}
+
+/* -------------------------------------------------------------------------- */
+
MODULE = Cairo::Surface PACKAGE = Cairo::Surface PREFIX = cairo_surface_
void DESTROY (cairo_surface_t * surface);
CODE:
cairo_surface_destroy (surface);
-cairo_surface_t * cairo_surface_create_similar (cairo_surface_t * other, cairo_content_t content, int width, int height);
+cairo_surface_t_noinc * cairo_surface_create_similar (cairo_surface_t * other, cairo_content_t content, int width, int height);
cairo_status_t cairo_surface_status (cairo_surface_t *surface);
-void cairo_surface_finish (cairo_surface_t *surface);
-
void cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, double y_offset);
##void cairo_surface_get_device_offset (cairo_surface_t *surface, double *x_offset, double *y_offset);
@@ -102,8 +229,19 @@
cairo_status_t cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename);
-# FIXME
##cairo_status_t cairo_surface_write_to_png_stream (cairo_surface_t *surface, cairo_write_func_t write_func, void *closure);
+cairo_status_t
+cairo_surface_write_to_png_stream (cairo_surface_t *surface, SV *func, SV *data=NULL)
+ PREINIT:
+ CairoPerlCallback *callback;
+ CODE:
+ callback = cairo_perl_callback_new (func, data);
+ RETVAL = cairo_surface_write_to_png_stream (surface,
+ write_func_marshaller,
+ callback);
+ cairo_perl_callback_free (callback);
+ OUTPUT:
+ RETVAL
#endif
@@ -132,8 +270,18 @@
C_ARGS:
filename
-# FIXME
##cairo_surface_t * cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, void *closure);
+cairo_surface_t_noinc *
+cairo_image_surface_create_from_png_stream (class, SV *func, SV *data=NULL)
+ PREINIT:
+ CairoPerlCallback *callback;
+ CODE:
+ callback = cairo_perl_callback_new (func, data);
+ RETVAL = cairo_image_surface_create_from_png_stream (
+ read_func_marshaller, callback);
+ cairo_perl_callback_free (callback);
+ OUTPUT:
+ RETVAL
#endif
@@ -148,8 +296,22 @@
C_ARGS:
filename, width_in_points, height_in_points
-# FIXME
##cairo_surface_t * cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
+cairo_surface_t_noinc *
+cairo_pdf_surface_create_for_stream (class, SV *func, SV *data, double width_in_points, double height_in_points)
+ PREINIT:
+ CairoPerlCallback *callback;
+ CODE:
+ callback = cairo_perl_callback_new (func, data);
+ RETVAL = cairo_pdf_surface_create_for_stream (write_func_marshaller,
+ callback,
+ width_in_points,
+ height_in_points);
+ cairo_surface_set_user_data (
+ RETVAL, (const cairo_user_data_key_t *) &callback, callback,
+ (cairo_destroy_func_t) cairo_perl_callback_free);
+ OUTPUT:
+ RETVAL
void cairo_pdf_surface_set_dpi (cairo_surface_t *surface, double x_dpi, double y_dpi);
@@ -168,8 +330,22 @@
C_ARGS:
filename, width_in_points, height_in_points
-# FIXME
##cairo_surface_t * cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
+cairo_surface_t_noinc *
+cairo_ps_surface_create_for_stream (class, SV *func, SV *data, double width_in_points, double height_in_points)
+ PREINIT:
+ CairoPerlCallback *callback;
+ CODE:
+ callback = cairo_perl_callback_new (func, data);
+ RETVAL = cairo_ps_surface_create_for_stream (write_func_marshaller,
+ callback,
+ width_in_points,
+ height_in_points);
+ cairo_surface_set_user_data (
+ RETVAL, (const cairo_user_data_key_t *) &callback, callback,
+ (cairo_destroy_func_t) cairo_perl_callback_free);
+ OUTPUT:
+ RETVAL
void cairo_ps_surface_set_dpi (cairo_surface_t *surface, double x_dpi, double y_dpi);
Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-perl/ChangeLog,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ChangeLog 7 May 2006 14:18:57 -0000 1.19
+++ ChangeLog 14 May 2006 13:43:10 -0000 1.20
@@ -1,3 +1,26 @@
+2006/05/14 tsch
+
+ * t/CairoSurface.t, CairoSurface.xs: Remove
+ Cairo::Surface::finish; it's memory management related and not
+ needed, as far as I can tell. Scream if you used it.
+
+ * t/CairoSurface.t, CairoSurface.xs: Bind and test
+ cairo_surface_write_to_png_stream,
+ cairo_image_surface_create_from_png_stream,
+ cairo_pdf_surface_create_for_stream, and
+ cairo_ps_surface_create_for_stream.
+
+ * CairoSurface.xs: Don't leak cairo_surface_create_similar's
+ return value.
+
+ * cairo-perl-private.h: Remove CAIRO_PERL_UNUSED.
+
+ * cairo-perl-private.h, Cairo.xs, CairoFont.xs, CairoMatrix.xs,
+ CairoPattern.xs: Rename pcairo_copy_matrix to
+ cairo_perl_copy_matrix.
+
+ * TODO: Update.
+
2006/05/07 tsch
* .cvsignore, MANIFEST.SKIP: Update.
Index: TODO
===================================================================
RCS file: /cvs/cairo/cairo-perl/TODO,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- TODO 15 Aug 2005 18:59:17 -0000 1.3
+++ TODO 14 May 2006 13:43:10 -0000 1.4
@@ -1,2 +1 @@
-TODO's
- - the stream stuff in CairoSurface.xs
+* Write examples.
Index: cairo-perl-private.h
===================================================================
RCS file: /cvs/cairo/cairo-perl/cairo-perl-private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cairo-perl-private.h 7 May 2006 14:17:39 -0000 1.1
+++ cairo-perl-private.h 14 May 2006 13:43:10 -0000 1.2
@@ -10,8 +10,6 @@
#ifndef _CAIRO_PERL_PRIVATE_H_
#define _CAIRO_PERL_PRIVATE_H_
-#define CAIRO_PERL_UNUSED(var) if (0) { (var) = (var); }
-
-cairo_matrix_t * pcairo_copy_matrix (cairo_matrix_t *matrix);
+cairo_matrix_t * cairo_perl_copy_matrix (cairo_matrix_t *matrix);
#endif /* _CAIRO_PERL_PRIVATE_H_ */
More information about the cairo-commit
mailing list