summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-05-05 13:59:07 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-05-05 21:17:11 +0100
commitc488b336449a1a7ca4d3f90785afeec9e21784c3 (patch)
tree58ae561a9b54ac97a01d5a1a6888572d90ee2f62
parent1d609d672273da494fd596606b59ab1c0010ae6d (diff)
[test] Create a new fallback surface to exercise 16-bit paths.
Add a variation of test-fallback-surface that forces the use of a 16-bit pixman format code instead of the standard 32-bit types. This creates an image surface akin to the fallbacks used with low bit-depth xservers.
-rw-r--r--boilerplate/cairo-boilerplate-test-surfaces-private.h11
-rw-r--r--boilerplate/cairo-boilerplate-test-surfaces.c16
-rw-r--r--boilerplate/cairo-boilerplate.c18
-rw-r--r--src/Makefile.sources2
-rw-r--r--src/test-fallback16-surface.c234
-rw-r--r--src/test-fallback16-surface.h52
-rw-r--r--test/Makefile.am4
-rw-r--r--test/Makefile.sources3
-rw-r--r--test/test-fallback16-surface-source.c43
-rw-r--r--test/test-fallback16-surface-source.ref.pngbin0 -> 268 bytes
10 files changed, 383 insertions, 0 deletions
diff --git a/boilerplate/cairo-boilerplate-test-surfaces-private.h b/boilerplate/cairo-boilerplate-test-surfaces-private.h
index 481b531e7..24a1ae81a 100644
--- a/boilerplate/cairo-boilerplate-test-surfaces-private.h
+++ b/boilerplate/cairo-boilerplate-test-surfaces-private.h
@@ -38,6 +38,17 @@ _cairo_boilerplate_test_fallback_create_surface (const char *name,
int id,
void **closure);
+cairo_surface_t *
+_cairo_boilerplate_test_fallback16_create_surface (const char *name,
+ cairo_content_t content,
+ int width,
+ int height,
+ int max_width,
+ int max_height,
+ cairo_boilerplate_mode_t mode,
+ int id,
+ void **closure);
+
cairo_surface_t *
_cairo_boilerplate_test_meta_create_surface (const char *name,
diff --git a/boilerplate/cairo-boilerplate-test-surfaces.c b/boilerplate/cairo-boilerplate-test-surfaces.c
index f6fd63af8..644b2787b 100644
--- a/boilerplate/cairo-boilerplate-test-surfaces.c
+++ b/boilerplate/cairo-boilerplate-test-surfaces.c
@@ -28,6 +28,7 @@
#include "cairo-boilerplate-test-surfaces-private.h"
#include <test-fallback-surface.h>
+#include <test-fallback16-surface.h>
#include <test-meta-surface.h>
#include <test-paginated-surface.h>
@@ -49,6 +50,21 @@ _cairo_boilerplate_test_fallback_create_surface (const char *name,
}
cairo_surface_t *
+_cairo_boilerplate_test_fallback16_create_surface (const char *name,
+ cairo_content_t content,
+ int width,
+ int height,
+ int max_width,
+ int max_height,
+ cairo_boilerplate_mode_t mode,
+ int id,
+ void **closure)
+{
+ *closure = NULL;
+ return _cairo_test_fallback16_surface_create (content, width, height);
+}
+
+cairo_surface_t *
_cairo_boilerplate_test_meta_create_surface (const char *name,
cairo_content_t content,
int width,
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index fcc05b877..da2a61816 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -311,6 +311,24 @@ static cairo_boilerplate_target_t targets[] =
cairo_surface_write_to_png
},
{
+ "test-fallback16", "image", NULL,
+ CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
+ CAIRO_CONTENT_COLOR_ALPHA, 0,
+ _cairo_boilerplate_test_fallback16_create_surface, NULL,
+ NULL,
+ _cairo_boilerplate_get_image_surface,
+ cairo_surface_write_to_png
+ },
+ {
+ "test-fallback16", "image", NULL,
+ CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
+ CAIRO_CONTENT_COLOR, 0,
+ _cairo_boilerplate_test_fallback16_create_surface, NULL,
+ NULL,
+ _cairo_boilerplate_get_image_surface,
+ cairo_surface_write_to_png
+ },
+ {
"test-meta", "image", NULL,
CAIRO_INTERNAL_SURFACE_TYPE_TEST_META,
CAIRO_CONTENT_COLOR_ALPHA, 0,
diff --git a/src/Makefile.sources b/src/Makefile.sources
index c1df770cc..534feec93 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -190,11 +190,13 @@ cairo_ft_sources = cairo-ft-font.c
# These are private, even though they look like public headers
cairo_test_surfaces_private = \
test-fallback-surface.h \
+ test-fallback16-surface.h \
test-meta-surface.h \
test-paginated-surface.h \
$(NULL)
cairo_test_surfaces_sources = \
test-fallback-surface.c \
+ test-fallback16-surface.c \
test-meta-surface.c \
test-paginated-surface.c \
$(NULL)
diff --git a/src/test-fallback16-surface.c b/src/test-fallback16-surface.c
new file mode 100644
index 000000000..7974c1f91
--- /dev/null
+++ b/src/test-fallback16-surface.c
@@ -0,0 +1,234 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2005 Red Hat, Inc
+ * Copyright © 2009 Chris Wilson
+ *
+ * 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>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+/* This isn't a "real" surface, but just something to be used by the
+ * test suite to force use of a non-standard pixman image fallback - as
+ * may be exposed by xlib fallbacks with weird xservers, for example.
+ */
+
+#include "cairoint.h"
+
+#include "test-fallback16-surface.h"
+
+typedef struct _test_fallback16_surface {
+ cairo_surface_t base;
+
+ /* This is a cairo_image_surface to hold the actual contents. */
+ cairo_surface_t *backing;
+} test_fallback16_surface_t;
+
+static const cairo_surface_backend_t test_fallback16_surface_backend;
+
+slim_hidden_proto (_cairo_test_fallback16_surface_create);
+
+cairo_surface_t *
+_cairo_test_fallback16_surface_create (cairo_content_t content,
+ int width,
+ int height)
+{
+ test_fallback16_surface_t *surface;
+ cairo_surface_t *backing;
+ pixman_format_code_t format;
+
+ format = content & CAIRO_CONTENT_ALPHA ? PIXMAN_a1r5g5b5: PIXMAN_r5g6b5;
+
+ backing = _cairo_image_surface_create_with_pixman_format (NULL, format,
+ width, height,
+ -1);
+ if (cairo_surface_status (backing))
+ return backing;
+
+ surface = malloc (sizeof (test_fallback16_surface_t));
+ if (unlikely (surface == NULL)) {
+ cairo_surface_destroy (backing);
+ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+ }
+
+ _cairo_surface_init (&surface->base,
+ &test_fallback16_surface_backend,
+ content);
+
+ surface->backing = backing;
+
+ return &surface->base;
+}
+slim_hidden_def (_cairo_test_fallback16_surface_create);
+
+static cairo_surface_t *
+_test_fallback16_surface_create_similar (void *abstract_surface,
+ cairo_content_t content,
+ int width,
+ int height)
+{
+ assert (CAIRO_CONTENT_VALID (content));
+
+ return _cairo_test_fallback16_surface_create (content, width, height);
+}
+
+static cairo_status_t
+_test_fallback16_surface_finish (void *abstract_surface)
+{
+ test_fallback16_surface_t *surface = abstract_surface;
+
+ cairo_surface_destroy (surface->backing);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
+_test_fallback16_surface_acquire_source_image (void *abstract_surface,
+ cairo_image_surface_t **image_out,
+ void **image_extra)
+{
+ test_fallback16_surface_t *surface = abstract_surface;
+
+ return _cairo_surface_acquire_source_image (surface->backing,
+ image_out, image_extra);
+}
+
+static void
+_test_fallback16_surface_release_source_image (void *abstract_surface,
+ cairo_image_surface_t *image,
+ void *image_extra)
+{
+ test_fallback16_surface_t *surface = abstract_surface;
+
+ _cairo_surface_release_source_image (surface->backing,
+ image, image_extra);
+}
+
+static cairo_status_t
+_test_fallback16_surface_acquire_dest_image (void *abstract_surface,
+ cairo_rectangle_int_t *interest_rect,
+ cairo_image_surface_t **image_out,
+ cairo_rectangle_int_t *image_rect_out,
+ void **image_extra)
+{
+ test_fallback16_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_fallback16_surface_release_dest_image (void *abstract_surface,
+ cairo_rectangle_int_t *interest_rect,
+ cairo_image_surface_t *image,
+ cairo_rectangle_int_t *image_rect,
+ void *image_extra)
+{
+ test_fallback16_surface_t *surface = abstract_surface;
+
+ _cairo_surface_release_dest_image (surface->backing,
+ interest_rect,
+ image,
+ image_rect,
+ image_extra);
+}
+
+static cairo_status_t
+_test_fallback16_surface_clone_similar (void *abstract_surface,
+ cairo_surface_t *src,
+ int src_x,
+ int src_y,
+ int width,
+ int height,
+ int *clone_offset_x,
+ int *clone_offset_y,
+ cairo_surface_t **clone_out)
+{
+ test_fallback16_surface_t *surface = abstract_surface;
+
+ if (src->backend == surface->base.backend) {
+ *clone_offset_x = 0;
+ *clone_offset_y = 0;
+ *clone_out = cairo_surface_reference (src);
+
+ return CAIRO_STATUS_SUCCESS;
+ } else {
+ return _cairo_surface_clone_similar (surface->backing, src,
+ src_x, src_y,
+ width, height,
+ clone_offset_x, clone_offset_y,
+ clone_out);
+ }
+}
+
+static cairo_int_status_t
+_test_fallback16_surface_get_extents (void *abstract_surface,
+ cairo_rectangle_int_t *rectangle)
+{
+ test_fallback16_surface_t *surface = abstract_surface;
+
+ return _cairo_surface_get_extents (surface->backing, rectangle);
+}
+
+static const cairo_surface_backend_t test_fallback16_surface_backend = {
+ CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
+ _test_fallback16_surface_create_similar,
+ _test_fallback16_surface_finish,
+ _test_fallback16_surface_acquire_source_image,
+ _test_fallback16_surface_release_source_image,
+ _test_fallback16_surface_acquire_dest_image,
+ _test_fallback16_surface_release_dest_image,
+ _test_fallback16_surface_clone_similar,
+ NULL, /* composite */
+ NULL, /* fill_rectangles */
+ NULL, /* composite_trapezoids */
+ NULL, /* create_span_renderer */
+ NULL, /* check_span_renderer */
+ NULL, /* copy_page */
+ NULL, /* show_page */
+ NULL, /* set_clip_region */
+ NULL, /* intersect_clip_path */
+ _test_fallback16_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 */
+};
diff --git a/src/test-fallback16-surface.h b/src/test-fallback16-surface.h
new file mode 100644
index 000000000..2c5b2ca74
--- /dev/null
+++ b/src/test-fallback16-surface.h
@@ -0,0 +1,52 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2005 Red Hat, Inc
+ * Copyright © 2009 Chris Wilson
+ *
+ * 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>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef TEST_FALLBACK16_SURFACE_H
+#define TEST_FALLBACK16_SURFACE_H
+
+#include "cairo.h"
+
+CAIRO_BEGIN_DECLS
+
+cairo_surface_t *
+_cairo_test_fallback16_surface_create (cairo_content_t content,
+ int width,
+ int height);
+
+CAIRO_END_DECLS
+
+#endif /* TEST_FALLBACK16_SURFACE_H */
diff --git a/test/Makefile.am b/test/Makefile.am
index 2a1d93bc8..efac53f7c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -37,6 +37,10 @@ if CAIRO_HAS_SVG_SURFACE
test_sources += $(svg_surface_test_sources)
endif
+if CAIRO_HAS_TEST_SURFACES
+test_sources += $(test_fallback16_surface_test_sources)
+endif
+
if CAIRO_HAS_XLIB_SURFACE
test_sources += $(xlib_surface_test_sources)
endif
diff --git a/test/Makefile.sources b/test/Makefile.sources
index f8c19fd33..eeb9294e5 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -229,6 +229,9 @@ svg_surface_test_sources = \
svg-clip.c \
svg-surface-source.c
+test_fallback16_surface_test_sources = \
+ test-fallback16-surface-source.c
+
xlib_surface_test_sources = \
xlib-expose-event.c \
xlib-surface.c \
diff --git a/test/test-fallback16-surface-source.c b/test/test-fallback16-surface-source.c
new file mode 100644
index 000000000..7e9f920fe
--- /dev/null
+++ b/test/test-fallback16-surface-source.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2009 Chris Wilson
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+#include <test-fallback16-surface.h>
+
+#include "surface-source.c"
+
+static cairo_surface_t *
+create_source_surface (int size)
+{
+ return _cairo_test_fallback16_surface_create (CAIRO_CONTENT_COLOR_ALPHA,
+ size, size);
+}
+
+CAIRO_TEST (test_fallback16_surface_source,
+ "Test using a 16-bit image (e.g. a low bit-depth XServer) surface as the source",
+ "source", /* keywords */
+ NULL, /* requirements */
+ SIZE, SIZE,
+ preamble, draw)
diff --git a/test/test-fallback16-surface-source.ref.png b/test/test-fallback16-surface-source.ref.png
new file mode 100644
index 000000000..3fa8bbe55
--- /dev/null
+++ b/test/test-fallback16-surface-source.ref.png
Binary files differ