2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: Chris Wilson <chris@chris-wilson.co.uk>
27 #include "cairo-test.h"
32 /* A single, black pixel */
33 static const uint32_t black_pixel_argb = 0xff000000;
34 static const uint32_t black_pixel = 0x00000000;
37 set_pixel_black(uint8_t *data, int stride,
38 cairo_format_t format, int x, int y)
41 case CAIRO_FORMAT_ARGB32:
42 case CAIRO_FORMAT_RGB24:
43 *(uint32_t *)(data + y * stride + 4*x) = black_pixel_argb;
45 case CAIRO_FORMAT_RGB16_565:
46 *(uint16_t *)(data + y * stride + 2*x) = black_pixel;
48 case CAIRO_FORMAT_RGB30:
51 case CAIRO_FORMAT_INVALID:
58 static cairo_test_status_t
59 all (cairo_t *cr, int width, int height)
61 cairo_surface_t *surface;
64 cairo_format_t format;
67 /* Fill background white */
68 cairo_set_source_rgb (cr, 1, 1, 1);
71 surface = cairo_surface_map_to_image (cairo_get_target (cr), NULL);
72 cairo_surface_flush (surface);
73 format = cairo_image_surface_get_format (surface);
74 stride = cairo_image_surface_get_stride (surface);
75 data = cairo_image_surface_get_data (surface);
77 for (j = 0; j < HEIGHT; j++)
78 for (i = 0; i < WIDTH; i++)
79 if (! set_pixel_black (data, stride, format, i, j))
80 return CAIRO_TEST_FAILURE;
82 cairo_surface_mark_dirty (surface);
83 cairo_surface_unmap_image (cairo_get_target (cr), surface);
85 return CAIRO_TEST_SUCCESS;
88 static cairo_test_status_t
89 bit (cairo_t *cr, int width, int height)
91 cairo_surface_t *surface;
92 cairo_rectangle_int_t extents;
93 cairo_format_t format;
96 extents.x = extents.y = extents.width = extents.height = 1;
98 /* Fill background white */
99 cairo_set_source_rgb (cr, 1, 1, 1);
102 surface = cairo_surface_map_to_image (cairo_get_target (cr), &extents);
103 cairo_surface_flush (surface);
104 data = cairo_image_surface_get_data (surface);
105 format = cairo_image_surface_get_format (surface);
107 if (! set_pixel_black (data, 0, format, 0, 0))
108 return CAIRO_TEST_FAILURE;
110 cairo_surface_mark_dirty (surface);
111 cairo_surface_unmap_image (cairo_get_target (cr), surface);
113 return CAIRO_TEST_SUCCESS;
116 static cairo_test_status_t
117 fill (cairo_t *cr, int width, int height)
119 cairo_surface_t *surface;
120 cairo_rectangle_int_t extents;
123 extents.x = extents.y = extents.width = extents.height = 1;
125 /* Fill background white */
126 cairo_set_source_rgb (cr, 1, 1, 1);
129 surface = cairo_surface_map_to_image (cairo_get_target (cr), &extents);
130 cr2 = cairo_create (surface);
131 cairo_set_source_rgb (cr2, 1, 0, 0);
134 cairo_surface_unmap_image (cairo_get_target (cr), surface);
136 return CAIRO_TEST_SUCCESS;
139 CAIRO_TEST (map_all_to_image,
140 "Test maping a surface to an image and modifying it externally",
141 "image", /* keywords */
142 "target=raster", /* requirements */
145 CAIRO_TEST (map_bit_to_image,
146 "Test maping a surface to an image and modifying it externally",
147 "image", /* keywords */
148 "target=raster", /* requirements */
151 CAIRO_TEST (map_to_image_fill,
152 "Test maping a surface to an image and modifying it externally",
153 "image", /* keywords */
154 "target=raster", /* requirements */