Add a new option --enable-test-surfaces.

New surface backend for testing only. It has as many NULL backend entries as possible.
Add support to test the new test_fallback backend.
This commit is contained in:
Carl Worth 2005-12-16 11:31:10 +00:00
parent 79eee2c303
commit c75232f8ab
8 changed files with 374 additions and 15 deletions

View file

@ -1,3 +1,25 @@
2005-12-16 Carl Worth <cworth@cworth.org>
* configure.in: Add a new option --enable-test-surfaces.
* src/Makefile.am:
* src/test-fallback-surface.h:
* src/test-fallback-surface.c: (_test_fallback_surface_create),
(_test_fallback_surface_create_for_data),
(_test_fallback_surface_create_similar),
(_test_fallback_surface_finish),
(_test_fallback_surface_acquire_source_image),
(_test_fallback_surface_release_source_image),
(_test_fallback_surface_acquire_dest_image),
(_test_fallback_surface_release_dest_image),
(_test_fallback_surface_get_extents): New surface backend for
testing only. It has as many NULL backend entries as possible.
* test/Makefile.am:
* test/cairo-test.c: (create_test_fallback_surface),
(cleanup_test_fallback), (cairo_test_expecting): Add support to
test the new test_fallback backend.
2005-12-16 Carl Worth <cworth@cworth.org>
* src/cairoint.h: Don't export cairo_image_surface_set_clip_region.

View file

@ -581,8 +581,8 @@ AM_CONDITIONAL(USE_MMX, test $have_mmx_intrinsics = yes)
dnl ===========================================================================
AC_ARG_ENABLE(gcov,
[ --enable-gcov Enable gcov],
[use_gcov=$enableval], [use_gcov=no])
[ --enable-gcov Enable gcov],
[use_gcov=$enableval], [use_gcov=no])
if test "x$use_gcov" = "xyes"; then
dnl we need gcc:
@ -645,6 +645,17 @@ fi
dnl ===========================================================================
AC_ARG_ENABLE(test-surfaces,
[ --enable-test-surfaces Add backends for more test suite coverage (no additional public functionality)],
[use_test_surfaces=$enableval], [use_test_surfaces=no])
AM_CONDITIONAL(CAIRO_HAS_TEST_SURFACES, test "x$use_test_surfaces" = "xyes")
if test "x$use_test_surfaces" = "xyes"; then
AC_DEFINE(CAIRO_HAS_TEST_SURFACES, 1, [define in the extra test surface have been built into cairo for the test suite])
fi
dnl ===========================================================================
AC_OUTPUT([
cairo.pc
Makefile
@ -662,6 +673,7 @@ dnl ===========================================================================
echo ""
echo "cairo will be compiled with the following surface backends:"
echo " image: yes (always builtin)"
echo " Xlib: $use_xlib"
echo " Quartz: $use_quartz"
echo " XCB: $use_xcb"
@ -681,8 +693,11 @@ echo " PNG functions: $use_png"
echo ""
echo "and the following debug options:"
echo " gcov support: $use_gcov"
echo " test surfaces: $use_test_surfaces"
echo ""
echo "using CFLAGS:"
echo $CAIRO_CFLAGS
echo ""
if test x"$use_freetype" != "xyes" && \
test x"$use_win32" != "xyes" && \

View file

@ -11,13 +11,17 @@ libcairo_pdf_sources = cairo-pdf-surface.c
libcairo_font_subset_sources = cairo-font-subset.c cairo-font-subset-private.h
endif
if CAIRO_HAS_PNG_FUNCTIONS
libcairo_png_sources = cairo-png.c
endif
if CAIRO_HAS_SVG_SURFACE
libcairo_svg_headers = cairo-svg.h
libcairo_svg_sources = cairo-svg-surface.c
endif
if CAIRO_HAS_PNG_FUNCTIONS
libcairo_png_sources = cairo-png.c
if CAIRO_HAS_TEST_SURFACES
libcairo_test_sources = test-fallback-surface.c test-fallback-surface.h
endif
if CAIRO_HAS_XLIB_SURFACE
@ -154,9 +158,10 @@ libcairo_la_SOURCES = \
$(libcairo_ft_sources) \
$(libcairo_ps_sources) \
$(libcairo_pdf_sources) \
$(libcairo_svg_sources) \
$(libcairo_font_subset_sources) \
$(libcairo_png_sources) \
$(libcairo_svg_sources) \
$(libcairo_test_sources) \
$(libcairo_font_subset_sources) \
$(libcairo_xlib_sources) \
$(libcairo_quartz_sources) \
$(libcairo_xcb_sources) \

225
src/test-fallback-surface.c Normal file
View file

@ -0,0 +1,225 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2005 Red Hat, Inc
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is Red Hat, Inc.
*
* Contributor(s):
* Carl Worth <cworth@cworth.org>
*/
/* This isn't a "real" surface, but just something to be used by the
* test suite to test a mythical backend that uses nothing but
* fallbacks.
*
* It's possible that this code might serve as a good starting point
* for someone working on bringing up a new backend, starting with the
* minimal all-fallbacks approach and working up gradually from
* there.
*/
#include "test-fallback-surface.h"
#include "cairoint.h"
typedef struct _test_fallback_surface {
cairo_surface_t base;
/* This is a cairo_image_surface to hold the actual contents. */
cairo_surface_t *backing;
} test_fallback_surface_t;
const cairo_private cairo_surface_backend_t test_fallback_surface_backend;
cairo_surface_t *
_test_fallback_surface_create (cairo_format_t format,
int width,
int height)
{
test_fallback_surface_t *surface;
cairo_surface_t *backing;
backing = cairo_image_surface_create (format, width, height);
if (cairo_surface_status (backing))
return (cairo_surface_t*) &_cairo_surface_nil;
surface = malloc (sizeof (test_fallback_surface_t));
if (surface == NULL) {
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_surface_t*) &_cairo_surface_nil;
}
_cairo_surface_init (&surface->base, &test_fallback_surface_backend);
surface->backing = backing;
return &surface->base;
}
cairo_surface_t *
_test_fallback_surface_create_for_data (unsigned char *data,
cairo_format_t format,
int width,
int height,
int stride)
{
test_fallback_surface_t *surface;
cairo_surface_t *backing;
backing = cairo_image_surface_create_for_data (data, format,
width, height, stride);
if (cairo_surface_status (backing))
return (cairo_surface_t*) &_cairo_surface_nil;
surface = malloc (sizeof (test_fallback_surface_t));
if (surface == NULL) {
_cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_surface_t*) &_cairo_surface_nil;
}
_cairo_surface_init (&surface->base, &test_fallback_surface_backend);
surface->backing = backing;
return &surface->base;
}
static cairo_surface_t *
_test_fallback_surface_create_similar (void *abstract_surface,
cairo_content_t content,
int width,
int height)
{
test_fallback_surface_t *surface = abstract_surface;
return cairo_surface_create_similar (surface->backing, content,
width, height);
}
static cairo_status_t
_test_fallback_surface_finish (void *abstract_surface)
{
test_fallback_surface_t *surface = abstract_surface;
cairo_surface_destroy (surface->backing);
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
_test_fallback_surface_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
void **image_extra)
{
test_fallback_surface_t *surface = abstract_surface;
return _cairo_surface_acquire_source_image (surface->backing,
image_out, image_extra);
}
static void
_test_fallback_surface_release_source_image (void *abstract_surface,
cairo_image_surface_t *image,
void *image_extra)
{
test_fallback_surface_t *surface = abstract_surface;
_cairo_surface_release_source_image (surface->backing,
image, image_extra);
}
static cairo_status_t
_test_fallback_surface_acquire_dest_image (void *abstract_surface,
cairo_rectangle_t *interest_rect,
cairo_image_surface_t**image_out,
cairo_rectangle_t *image_rect_out,
void **image_extra)
{
test_fallback_surface_t *surface = abstract_surface;
return _cairo_surface_acquire_dest_image (surface->backing,
interest_rect,
image_out,
image_rect_out,
image_extra);
}
static void
_test_fallback_surface_release_dest_image (void *abstract_surface,
cairo_rectangle_t *interest_rect,
cairo_image_surface_t*image,
cairo_rectangle_t *image_rect,
void *image_extra)
{
test_fallback_surface_t *surface = abstract_surface;
_cairo_surface_release_dest_image (surface->backing,
interest_rect,
image,
image_rect,
image_extra);
}
static cairo_int_status_t
_test_fallback_surface_get_extents (void *abstract_surface,
cairo_rectangle_t *rectangle)
{
test_fallback_surface_t *surface = abstract_surface;
return _cairo_surface_get_extents (surface->backing, rectangle);
}
const cairo_surface_backend_t test_fallback_surface_backend = {
_test_fallback_surface_create_similar,
_test_fallback_surface_finish,
_test_fallback_surface_acquire_source_image,
_test_fallback_surface_release_source_image,
_test_fallback_surface_acquire_dest_image,
_test_fallback_surface_release_dest_image,
NULL, /* clone_similar */
NULL, /* composite */
NULL, /* fill_rectangles */
NULL, /* composite_trapezoids */
NULL, /* copy_page */
NULL, /* show_page */
NULL, /* set_clip_region */
NULL, /* intersect_clip_path */
_test_fallback_surface_get_extents,
NULL, /* old_show_glyphs */
NULL, /* get_font_options */
NULL, /* flush */
NULL, /* mark_dirty_rectangle */
NULL, /* scaled_font_fini */
NULL, /* scaled_glyph_fini */
NULL, /* paint */
NULL, /* mask */
NULL, /* stroke */
NULL, /* fill */
NULL, /* show_glyphs */
NULL /* snapshot */
};

View file

@ -0,0 +1,57 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2005 Red Hat, Inc
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is Red Hat, Inc.
*
* Contributor(s):
* Carl Worth <cworth@cworth.org>
*/
#ifndef TEST_FALLBACK_SURFACE_H
#define TEST_FALLBACK_SURFACE_H
#include "cairo.h"
CAIRO_BEGIN_DECLS
cairo_surface_t *
_test_fallback_surface_create (cairo_format_t format,
int width,
int height);
cairo_surface_t *
_test_fallback_surface_create_for_data (unsigned char *data,
cairo_format_t format,
int width,
int height,
int stride);
CAIRO_END_DECLS
#endif /* TEST_FALLBACK_SURFACE_H */

View file

@ -85,6 +85,7 @@ xlib-surface
*-pdf-rgb24-out.pdf
*-ps-rgb24-out.png
*-ps-rgb24-out.ps
*-test-fallback-argb32-out.png
*-xcb-out.png
*-xcb-argb32-out.png
*-xcb-rgb24-out.png

View file

@ -241,15 +241,15 @@ INCLUDES = \
noinst_LTLIBRARIES = libcairotest.la
libcairotest_la_SOURCES =\
buffer-diff.c \
buffer-diff.h \
cairo-test.c \
cairo-test.h \
read-png.c \
read-png.h \
write-png.c \
write-png.h \
xmalloc.c \
buffer-diff.c \
buffer-diff.h \
cairo-test.c \
cairo-test.h \
read-png.c \
read-png.h \
write-png.c \
write-png.h \
xmalloc.c \
xmalloc.h
LDADDS = libcairotest.la $(top_builddir)/src/libcairo.la

View file

@ -199,6 +199,35 @@ cleanup_image (void *closure)
free (buf);
}
#ifdef CAIRO_HAS_TEST_SURFACES
#include "test-fallback-surface.h"
static cairo_surface_t *
create_test_fallback_surface (cairo_test_t *test, cairo_format_t format,
void **closure)
{
int stride = 4 * test->width;
unsigned char *data;
*closure = data = xcalloc (stride * test->height, 1);
return _test_fallback_surface_create_for_data (data, format,
test->width,
test->height,
stride);
}
static void
cleanup_test_fallback (void *closure)
{
unsigned char *data = closure;
free (data);
}
#endif
#ifdef CAIRO_HAS_GLITZ_SURFACE
#include <glitz.h>
#include <cairo-glitz.h>
@ -1215,6 +1244,11 @@ cairo_test_expecting (cairo_test_t *test, cairo_test_draw_function_t draw,
{ "image", CAIRO_FORMAT_RGB24,
create_image_surface, cairo_surface_write_to_png,
cleanup_image },
#ifdef CAIRO_HAS_TEST_SURFACES
{ "test-fallback", CAIRO_FORMAT_ARGB32,
create_test_fallback_surface, cairo_surface_write_to_png,
cleanup_test_fallback },
#endif
#ifdef CAIRO_HAS_GLITZ_SURFACE
#if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
{ "glitz-glx", CAIRO_FORMAT_ARGB32,