Testing output from each backend (was: [cairo] State of Win32
backend?)
Tor Lillqvist
tml at iki.fi
Fri May 6 06:49:47 PDT 2005
Carl Worth writes:
> One thing that would help those people who want to work on the win32
> (or almost any other backend) is to tweak the test suite so that it
> will test these backends.
OK, here is the (trivial) patch that adds support for the Win32
backend to cairo-test.c. BTW, if I used CAIRO_FORMAT_RGB24, the tests
all fail, the win32 pngs were mostly black. Apparently there is some
mismatch between Cairo's RGB24 format pixmaps and those in Windows, or
something.
(I also had to rework the stderr acrobatics. stderr isn't an lvalue in
Microsoft's C library. Instead I manipulate fileno(stderr), which
hopefully is more portable?)
Index: test/cairo-test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.c,v
retrieving revision 1.25
diff -u -2 -r1.25 cairo-test.c
--- test/cairo-test.c 3 May 2005 15:33:32 -0000 1.25
+++ test/cairo-test.c 6 May 2005 13:05:39 -0000
@@ -29,4 +29,5 @@
#include <unistd.h>
#include <errno.h>
+#include <fcntl.h>
#include <string.h>
@@ -168,5 +169,19 @@
set_win32_target (cairo_t *cr, int width, int height, void **closure)
{
-#error Not yet implemented
+ cairo_surface_t *surface;
+ cairo_surface_t *_cairo_win32_surface_create_dib (cairo_format_t format,
+ int width,
+ int height);
+
+ if (width == 0)
+ width = 1;
+ if (height == 0)
+ height = 1;
+
+ *closure = surface = _cairo_win32_surface_create_dib (CAIRO_FORMAT_ARGB32, width, height);
+
+ cairo_set_target_surface (cr, surface);
+
+ return CAIRO_TEST_SUCCESS;
}
@@ -174,5 +189,5 @@
cleanup_win32_target (void *closure)
{
-#error Not yet implemented
+ /* Not yet implemented */
}
#endif
@@ -327,5 +342,6 @@
{
int i;
- FILE *stderr_saved = stderr;
+ int stderr_saved = fileno (stderr);
+ int log_fd;
cairo_test_status_t status, ret;
cairo_test_target_t targets[] =
@@ -353,5 +369,7 @@
xunlink (log_name);
- stderr = fopen (log_name, "a");
+ fflush (stderr);
+ log_fd = open (log_name, O_WRONLY|O_CREAT|O_APPEND, 0666);
+ fileno (stderr) = log_fd;
ret = CAIRO_TEST_SUCCESS;
@@ -369,6 +387,7 @@
}
- fclose (stderr);
- stderr = stderr_saved;
+ fflush (stderr);
+ fileno (stderr) = stderr_saved;
+ close (log_fd);
return ret;
After fixing the rowstride calculation in _create_dc_and_bitmap (see
below), "make check" passes.
--tml
Index: src/cairo-win32-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-win32-surface.c,v
retrieving revision 1.19
diff -u -2 -r1.19 cairo-win32-surface.c
--- src/cairo-win32-surface.c 26 Apr 2005 02:38:44 -0000 1.19
+++ src/cairo-win32-surface.c 6 May 2005 13:47:33 -0000
@@ -195,5 +195,5 @@
if (rowstride_out) {
- /* Windows bitmaps are padded to 16-bit (word) boundaries */
+ /* DIB section rows are padded to 32-bit (DWORD) boundaries */
switch (format) {
case CAIRO_FORMAT_ARGB32:
@@ -203,9 +203,9 @@
case CAIRO_FORMAT_A8:
- *rowstride_out = (width + 1) & -2;
+ *rowstride_out = ((width - 1)/4 + 1) * 4;
break;
case CAIRO_FORMAT_A1:
- *rowstride_out = ((width + 15) & -16) / 8;
+ *rowstride_out = ((width - 1)/32 + 1) * 4;
break;
}
More information about the cairo
mailing list