Skip to content

Commit

Permalink
Add CairoScript interpreter
Browse files Browse the repository at this point in the history
Add a CairoScript interpreter library and use it to replay the test output
for the CairoScript backend. The library is also used by the currently
standalone Sphinx debugger [git://anongit.freedesktop.org/~ickle/sphinx].
The syntax/operator semantics are not yet finalized, but are expected to
mature before the next stable release.
  • Loading branch information
Chris Wilson committed Nov 13, 2008
1 parent a856371 commit cdfffc7
Show file tree
Hide file tree
Showing 15 changed files with 10,801 additions and 33 deletions.
20 changes: 8 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,12 @@ CAIRO_ENABLE_SURFACE_BACKEND(directfb, directfb, no, [

dnl ===========================================================================

any2ppm_cs=no
CAIRO_ENABLE_SURFACE_BACKEND(script, script, no, [
test_script="yes"
csi_CFLAGS=
csi_LIBS=-lcairo-script-interpreter
if test "x$test_script" = "xyes"; then
AC_DEFINE([CAIRO_CAN_TEST_SCRIPT_SURFACE], 1,
[Define to 1 if the CairoScript backend can be tested])
else
AC_MSG_WARN([CairoScript backend will not be tested])
fi
AC_SUBST(csi_CFLAGS)
AC_SUBST(csi_LIBS)
test_script=yes
any2ppm_cs=yes
AC_DEFINE([CAIRO_CAN_TEST_SCRIPT_SURFACE], 1,
[Define to 1 if the CairoScript backend can be tested])
])

dnl ===========================================================================
Expand Down Expand Up @@ -494,7 +488,8 @@ dnl Build the external converter if we have any of the test backends
AM_CONDITIONAL(BUILD_ANY2PPM,
test "x$any2ppm_svg" = "xyes" \
-o "x$any2ppm_pdf" = "xyes" \
-o "x$any2ppm_ps" = "xyes")
-o "x$any2ppm_ps" = "xyes" \
-o "x$any2ppm_cs" = "xyes")

dnl ===========================================================================
dnl The tracing utility requires LD_PRELOAD, so only build it for systems
Expand Down Expand Up @@ -558,6 +553,7 @@ test/Makefile
test/pdiff/Makefile
perf/Makefile
util/Makefile
util/cairo-script/Makefile
util/cairo-trace/Makefile
util/cairo-trace/cairo-trace
doc/Makefile
Expand Down
4 changes: 2 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1170,10 +1170,10 @@ png_flatten_LDADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD)

if BUILD_ANY2PPM
check_PROGRAMS += any2ppm
any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS) $(LIBSPECTRE_CFLAGS) $(csi_CFLAGS)
any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS) $(LIBSPECTRE_CFLAGS)
# add LDADD, so poppler/librsvg uses "our" cairo
any2ppm_LDFLAGS = $(CAIRO_TEST_UNDEFINED_LDFLAGS)
any2ppm_LDADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS) $(LIBSPECTRE_LIBS) $(csi_LIBS)
any2ppm_LDADD = $(top_builddir)/util/cairo-script/libcairo-script-interpreter.la $(top_builddir)/src/libcairo.la $(CAIRO_LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS) $(LIBSPECTRE_LIBS)
endif

if CAIRO_CAN_TEST_PDF_SURFACE
Expand Down
41 changes: 23 additions & 18 deletions test/any2ppm.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ write_ppm (cairo_surface_t *surface, int fd)
format = cairo_image_surface_get_format (surface);
if (format == CAIRO_FORMAT_ARGB32) {
/* see if we can convert to a standard ppm type and trim a few bytes */
cairo_bool_t uses_alpha = FALSE;
const unsigned char *alpha = data;
for (j = height * stride; j-- && uses_alpha == FALSE; alpha += 4)
uses_alpha = *alpha != 0xff;
if (! uses_alpha)
format = CAIRO_FORMAT_RGB24;
for (j = height; j--; alpha += stride) {
for (i = 0; i < width; i++) {
if ((*(unsigned int *) (alpha+4*i) & 0xff000000) != 0xff000000)
goto done;
}
}
format = CAIRO_FORMAT_RGB24;
done: ;
}

switch (format) {
Expand Down Expand Up @@ -236,14 +239,12 @@ write_ppm (cairo_surface_t *surface, int fd)
#if CAIRO_CAN_TEST_SCRIPT_SURFACE
static cairo_surface_t *
_create_image (void *closure,
double width, double height,
csi_object_t *dictionary)
double width, double height)
//csi_object_t *dictionary)
{
cairo_surface_t **out = closure;
cairo_surface_t *surface;

surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
return *out = cairo_surface_reference (surface);
*out = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
return cairo_surface_reference (*out);
}

static const char *
Expand All @@ -253,17 +254,21 @@ _cairo_script_render_page (const char *filename,
cairo_script_interpreter_t *csi;
cairo_surface_t *surface = NULL;
cairo_status_t status;
const cairo_script_interpreter_hooks_t hooks = {
.closure = &surface,
.surface_create = _create_image,
};

csi = csi_create ();
csi_set_surface_create_function (csi, _create_image, &surface);
csi_run (csi, filename);
status = csi_destroy (csi);
if (status || surface == NULL) {
cairo_surface_destroy (surface);
csi = cairo_script_interpreter_create ();
cairo_script_interpreter_install_hooks (csi, &hooks);
cairo_script_interpreter_run (csi, filename);
status = cairo_script_interpreter_destroy (csi);
if (surface == NULL) {
return "cairo-script interpreter failed";
}

status = cairo_surface_status (surface);
if (status == CAIRO_STATUS_SUCCESS)
status = cairo_surface_status (surface);
if (status) {
cairo_surface_destroy (surface);
return cairo_status_to_string (status);
Expand Down
2 changes: 1 addition & 1 deletion util/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include $(top_srcdir)/build/Makefile.am.common

SUBDIRS = .
SUBDIRS = . cairo-script

if BUILD_TRACE
SUBDIRS += cairo-trace
Expand Down
17 changes: 17 additions & 0 deletions util/cairo-script/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Cairo is free software.

Every source file in the implementation of cairo is available to be
redistributed and/or modified under the terms of either the GNU Lesser
General Public License (LGPL) version 2.1 or the Mozilla Public
License (MPL) version 1.1. Some files are available under more
liberal terms, but we believe that in all cases, each file may be used
under either the LGPL or the MPL.

See the following files in this directory for the precise terms and
conditions of either license:

COPYING-LGPL-2.1
COPYING-MPL-1.1

Please see each file in the implementation for copyright and licensing
information, (in the opening comment of each file).
21 changes: 21 additions & 0 deletions util/cairo-script/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
lib_LTLIBRARIES = libcairo-script-interpreter.la

cairoincludedir=$(includedir)/cairo
cairoinclude_HEADERS = cairo-script-interpreter.h
libcairo_script_interpreter_la_SOURCES = \
cairo-script-private.h \
cairo-script-file.c \
cairo-script-hash.c \
cairo-script-interpreter.c \
cairo-script-objects.c \
cairo-script-operators.c \
cairo-script-scanner.c \
cairo-script-stack.c \
$(NULL)
libcairo_script_interpreter_la_CPPFLAGS = -I$(top_srcdir)/src
libcairo_script_interpreter_la_CFLAGS = $(CAIRO_CFLAGS)
libcairo_script_interpreter_la_LDFLAGS = -version-info $(CAIRO_LIBTOOL_VERSION_INFO) -no-undefined $(export_symbols)
libcairo_script_interpreter_la_LIBADD = -lz $(CAIRO_LIBS) -L$(top_builddir)/src -lcairo

EXTRA_DIST = \
COPYING
Loading

0 comments on commit cdfffc7

Please sign in to comment.