2005-08-05 15:07:45 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright © Jeff Muizelaar
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* JEFF MUIZELAAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. 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.
|
|
|
|
|
*
|
2008-01-28 14:29:36 -08:00
|
|
|
* Authors: Jeff Muizelaar <jeff@infidigm.net>
|
|
|
|
|
* Carl Worth <cworth@cworth.org>
|
2005-08-05 15:07:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cairo-test.h"
|
|
|
|
|
|
2008-01-26 23:12:14 -08:00
|
|
|
#define MASK_WIDTH 8
|
|
|
|
|
#define MASK_HEIGHT 8
|
|
|
|
|
|
|
|
|
|
static unsigned char mask[MASK_WIDTH * MASK_HEIGHT] = {
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
|
|
|
|
0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, 0x0,
|
2005-08-05 15:07:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static cairo_test_status_t
|
2008-08-11 21:12:45 +01:00
|
|
|
check_status (const cairo_test_context_t *ctx,
|
|
|
|
|
cairo_status_t status,
|
|
|
|
|
cairo_status_t expected)
|
2008-01-26 23:12:14 -08:00
|
|
|
{
|
|
|
|
|
if (status == expected)
|
|
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (ctx,
|
|
|
|
|
"Error: Expected status value %d (%s), received %d (%s)\n",
|
2008-01-26 23:12:14 -08:00
|
|
|
expected,
|
|
|
|
|
cairo_status_to_string (expected),
|
|
|
|
|
status,
|
|
|
|
|
cairo_status_to_string (status));
|
|
|
|
|
return CAIRO_TEST_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_test_status_t
|
2008-08-11 21:12:45 +01:00
|
|
|
test_surface_with_width_and_stride (const cairo_test_context_t *ctx,
|
|
|
|
|
int width, int stride,
|
2008-01-26 23:12:14 -08:00
|
|
|
cairo_status_t expected)
|
|
|
|
|
{
|
|
|
|
|
cairo_test_status_t status;
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
cairo_t *cr;
|
2008-02-28 16:04:08 +00:00
|
|
|
int len;
|
2008-01-26 23:12:14 -08:00
|
|
|
unsigned char *data;
|
|
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
cairo_test_log (ctx,
|
|
|
|
|
"Creating surface with width %d and stride %d\n",
|
2008-01-26 23:12:14 -08:00
|
|
|
width, stride);
|
|
|
|
|
|
2008-02-28 16:04:08 +00:00
|
|
|
len = stride;
|
|
|
|
|
if (len < 0)
|
|
|
|
|
len = -len;
|
|
|
|
|
data = xmalloc (len);
|
2008-01-26 23:12:14 -08:00
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_A8,
|
|
|
|
|
width, 1, stride);
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
status = check_status (ctx, cairo_surface_status (surface), expected);
|
2008-01-26 23:12:14 -08:00
|
|
|
if (status)
|
2008-01-30 15:20:50 +00:00
|
|
|
goto BAIL;
|
2008-01-26 23:12:14 -08:00
|
|
|
|
2008-08-11 21:12:45 +01:00
|
|
|
status = check_status (ctx, cairo_status (cr), expected);
|
2008-01-26 23:12:14 -08:00
|
|
|
if (status)
|
2008-01-30 15:20:50 +00:00
|
|
|
goto BAIL;
|
2008-01-26 23:12:14 -08:00
|
|
|
|
2008-01-30 15:20:50 +00:00
|
|
|
BAIL:
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
cairo_surface_destroy (surface);
|
2008-01-26 23:12:14 -08:00
|
|
|
free (data);
|
2008-01-30 15:20:50 +00:00
|
|
|
return status;
|
2008-01-26 23:12:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_test_status_t
|
|
|
|
|
draw (cairo_t *cr, int dst_width, int dst_height)
|
2005-08-05 15:07:45 +00:00
|
|
|
{
|
2008-04-14 20:32:29 +01:00
|
|
|
int stride, row;
|
2008-01-26 23:12:14 -08:00
|
|
|
unsigned char *src, *dst, *mask_aligned;
|
2005-08-05 15:48:42 +00:00
|
|
|
cairo_surface_t *surface;
|
2008-01-26 23:12:14 -08:00
|
|
|
|
|
|
|
|
/* Now test actually drawing through our mask data, allocating and
|
|
|
|
|
* copying with the proper stride. */
|
2008-01-28 14:29:36 -08:00
|
|
|
stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8,
|
|
|
|
|
MASK_WIDTH);
|
2008-01-26 23:12:14 -08:00
|
|
|
|
2008-01-30 15:20:50 +00:00
|
|
|
mask_aligned = xmalloc (stride * MASK_HEIGHT);
|
2008-01-26 23:12:14 -08:00
|
|
|
|
|
|
|
|
src = mask;
|
|
|
|
|
dst = mask_aligned;
|
|
|
|
|
for (row = 0; row < MASK_HEIGHT; row++) {
|
|
|
|
|
memcpy (dst, src, MASK_WIDTH);
|
|
|
|
|
src += MASK_WIDTH;
|
|
|
|
|
dst += stride;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-14 20:32:29 +01:00
|
|
|
surface = cairo_image_surface_create_for_data (mask_aligned,
|
2008-01-26 23:12:14 -08:00
|
|
|
CAIRO_FORMAT_A8,
|
|
|
|
|
MASK_WIDTH,
|
|
|
|
|
MASK_HEIGHT,
|
|
|
|
|
stride);
|
|
|
|
|
|
|
|
|
|
/* Paint background blue */
|
|
|
|
|
cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
|
2005-08-05 15:07:45 +00:00
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
2008-01-26 23:12:14 -08:00
|
|
|
/* Then paint red through our mask */
|
|
|
|
|
cairo_set_source_rgb (cr, 1, 0, 0); /* red */
|
2008-04-14 20:32:29 +01:00
|
|
|
cairo_mask_surface (cr, surface, 0, 0);
|
2005-08-05 15:48:42 +00:00
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
2008-01-26 23:12:14 -08:00
|
|
|
free (mask_aligned);
|
|
|
|
|
|
2005-08-05 15:07:45 +00:00
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
static cairo_test_status_t
|
|
|
|
|
preamble (cairo_test_context_t *ctx)
|
2005-08-05 15:07:45 +00:00
|
|
|
{
|
2008-09-03 16:38:03 +01:00
|
|
|
cairo_test_status_t status = CAIRO_TEST_SUCCESS;
|
2008-04-14 20:32:29 +01:00
|
|
|
int test_width;
|
|
|
|
|
|
|
|
|
|
for (test_width = 0; test_width < 40; test_width++) {
|
|
|
|
|
int stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8,
|
|
|
|
|
test_width);
|
|
|
|
|
cairo_status_t expected;
|
|
|
|
|
|
|
|
|
|
/* First create a surface using the width as the stride,
|
|
|
|
|
* (most of these should fail).
|
|
|
|
|
*/
|
|
|
|
|
expected = (stride == test_width) ?
|
|
|
|
|
CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
status = test_surface_with_width_and_stride (ctx,
|
2008-08-11 21:12:45 +01:00
|
|
|
test_width,
|
2008-04-14 20:32:29 +01:00
|
|
|
test_width,
|
|
|
|
|
expected);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
status = test_surface_with_width_and_stride (ctx,
|
2008-08-11 21:12:45 +01:00
|
|
|
test_width,
|
2008-04-14 20:32:29 +01:00
|
|
|
-test_width,
|
|
|
|
|
expected);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Then create a surface using the correct stride,
|
|
|
|
|
* (should always succeed).
|
|
|
|
|
*/
|
2008-09-03 16:38:03 +01:00
|
|
|
status = test_surface_with_width_and_stride (ctx,
|
2008-08-11 21:12:45 +01:00
|
|
|
test_width,
|
2008-04-14 20:32:29 +01:00
|
|
|
stride,
|
|
|
|
|
CAIRO_STATUS_SUCCESS);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
status = test_surface_with_width_and_stride (ctx,
|
2008-08-11 21:12:45 +01:00
|
|
|
test_width,
|
2008-04-14 20:32:29 +01:00
|
|
|
-stride,
|
|
|
|
|
CAIRO_STATUS_SUCCESS);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-03 16:38:03 +01:00
|
|
|
return status;
|
2005-08-05 15:07:45 +00:00
|
|
|
}
|
2008-09-03 16:38:03 +01:00
|
|
|
|
|
|
|
|
CAIRO_TEST (a8_mask,
|
|
|
|
|
"test masks of CAIRO_FORMAT_A8",
|
|
|
|
|
"alpha, mask", /* keywords */
|
|
|
|
|
NULL, /* requirements */
|
|
|
|
|
8, 8,
|
|
|
|
|
preamble, draw)
|