summaryrefslogtreecommitdiff
path: root/boilerplate/cairo-boilerplate-test-surfaces.c
diff options
context:
space:
mode:
Diffstat (limited to 'boilerplate/cairo-boilerplate-test-surfaces.c')
-rw-r--r--boilerplate/cairo-boilerplate-test-surfaces.c113
1 files changed, 53 insertions, 60 deletions
diff --git a/boilerplate/cairo-boilerplate-test-surfaces.c b/boilerplate/cairo-boilerplate-test-surfaces.c
index 849627fd3..501866bad 100644
--- a/boilerplate/cairo-boilerplate-test-surfaces.c
+++ b/boilerplate/cairo-boilerplate-test-surfaces.c
@@ -33,6 +33,7 @@
#include <test-paginated-surface.h>
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,3)
#include <test-null-surface.h>
+#include <test-wrapping-surface.h>
#endif
#include <cairo-types-private.h>
@@ -49,7 +50,8 @@ _cairo_boilerplate_test_fallback_create_surface (const char *name,
void **closure)
{
*closure = NULL;
- return _cairo_test_fallback_surface_create (content, width, height);
+ return _cairo_test_fallback_surface_create (content,
+ ceil (width), ceil (height));
}
static cairo_surface_t *
@@ -64,7 +66,8 @@ _cairo_boilerplate_test_fallback16_create_surface (const char *name,
void **closure)
{
*closure = NULL;
- return _cairo_test_fallback16_surface_create (content, width, height);
+ return _cairo_test_fallback16_surface_create (content,
+ ceil (width), ceil (height));
}
static cairo_surface_t *
@@ -89,11 +92,7 @@ _cairo_boilerplate_test_null_create_surface (const char *name,
static const cairo_user_data_key_t test_paginated_closure_key;
typedef struct {
- unsigned char *data;
- cairo_content_t content;
- int width;
- int height;
- int stride;
+ cairo_surface_t *target;
} test_paginated_closure_t;
static cairo_surface_t *
@@ -115,18 +114,10 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
*closure = tpc = xmalloc (sizeof (test_paginated_closure_t));
format = cairo_boilerplate_format_from_content (content);
+ tpc->target = cairo_image_surface_create (format,
+ ceil (width), ceil (height));
- tpc->content = content;
- tpc->width = width;
- tpc->height = height;
- tpc->stride = cairo_format_stride_for_width (format, width);
- tpc->data = xcalloc (tpc->stride, height);
-
- surface = _cairo_test_paginated_surface_create_for_data (tpc->data,
- tpc->content,
- tpc->width,
- tpc->height,
- tpc->stride);
+ surface = _cairo_test_paginated_surface_create (tpc->target);
if (cairo_surface_status (surface))
goto CLEANUP;
@@ -139,8 +130,9 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
cairo_surface_destroy (surface);
surface = cairo_boilerplate_surface_create_in_error (status);
+ cairo_surface_destroy (tpc->target);
+
CLEANUP:
- free (tpc->data);
free (tpc);
return surface;
}
@@ -160,8 +152,6 @@ static cairo_status_t
_cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface,
const char *filename)
{
- cairo_surface_t *image;
- cairo_format_t format;
test_paginated_closure_t *tpc;
cairo_status_t status;
@@ -172,19 +162,7 @@ _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface
return status;
tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key);
-
- format = cairo_boilerplate_format_from_content (tpc->content);
-
- image = cairo_image_surface_create_for_data (tpc->data,
- format,
- tpc->width,
- tpc->height,
- tpc->stride);
-
- status = cairo_surface_write_to_png (image, filename);
- cairo_surface_destroy (image);
-
- return status;
+ return cairo_surface_write_to_png (tpc->target, filename);
}
static cairo_surface_t *
@@ -193,7 +171,6 @@ _cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface,
int width,
int height)
{
- cairo_format_t format;
test_paginated_closure_t *tpc;
cairo_status_t status;
@@ -208,30 +185,7 @@ _cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface,
return cairo_boilerplate_surface_create_in_error (status);
tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key);
-
- format = cairo_boilerplate_format_from_content (tpc->content);
-
- if (0) {
- return cairo_image_surface_create_for_data (tpc->data + tpc->stride * (tpc->height - height) + 4 * (tpc->width - width), /* hide the device offset */
- format,
- width,
- height,
- tpc->stride);
- } else {
- cairo_surface_t *image, *surface;
-
- image = cairo_image_surface_create_for_data (tpc->data,
- format,
- tpc->width,
- tpc->height,
- tpc->stride);
- cairo_surface_set_device_offset (image,
- tpc->width - width,
- tpc->height - height);
- surface = _cairo_boilerplate_get_image_surface (image, 0, width, height);
- cairo_surface_destroy (image);
- return surface;
- }
+ return _cairo_boilerplate_get_image_surface (tpc->target, 0, width, height);
}
static void
@@ -239,10 +193,40 @@ _cairo_boilerplate_test_paginated_cleanup (void *closure)
{
test_paginated_closure_t *tpc = closure;
- free (tpc->data);
+ cairo_surface_destroy (tpc->target);
free (tpc);
}
+static cairo_surface_t *
+_cairo_boilerplate_test_wrapping_create_surface (const char *name,
+ cairo_content_t content,
+ double width,
+ double height,
+ double max_width,
+ double max_height,
+ cairo_boilerplate_mode_t mode,
+ int id,
+ void **closure)
+{
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,3)
+ cairo_surface_t *target;
+ cairo_surface_t *surface;
+ cairo_format_t format;
+
+ *closure = NULL;
+
+ format = cairo_boilerplate_format_from_content (content);
+ target = cairo_image_surface_create (format, ceil (width), ceil (height));
+ surface = _cairo_test_wrapping_surface_create (target);
+ cairo_surface_destroy (target);
+
+ return surface;
+#else
+ *closure = NULL;
+ return NULL;
+#endif
+}
+
static const cairo_boilerplate_target_t targets[] = {
{
"test-fallback", "image", NULL, NULL,
@@ -305,6 +289,15 @@ static const cairo_boilerplate_target_t targets[] = {
FALSE, TRUE
},
{
+ "test-wrapping", "image", NULL, NULL,
+ CAIRO_INTERNAL_SURFACE_TYPE_TEST_WRAPPING,
+ CAIRO_CONTENT_COLOR_ALPHA, 0,
+ _cairo_boilerplate_test_wrapping_create_surface,
+ NULL, NULL,
+ _cairo_boilerplate_get_image_surface,
+ cairo_surface_write_to_png,
+ },
+ {
"null", "image", NULL, NULL,
CAIRO_INTERNAL_SURFACE_TYPE_NULL,
CAIRO_CONTENT_COLOR_ALPHA, 0,