[cairo-commit] cairo/test cairo-test.c,1.62,1.63

Stuart Parmenter commit at pdx.freedesktop.org
Thu Nov 17 11:55:23 PST 2005


Committed by: pavlov

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv20884/test

Modified Files:
	cairo-test.c 
Log Message:
2005-11-17  Stuart Parmenter <pavlov at pavlov.net>

       * test/cairo-test.c: (create_win32_surface),
       (cleanup_win32), (cairo_test_expecting):
       Hooked up tests to run on Windows with a Windows surface


Index: cairo-test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- cairo-test.c	9 Nov 2005 01:43:14 -0000	1.62
+++ cairo-test.c	17 Nov 2005 19:55:21 -0000	1.63
@@ -230,17 +230,57 @@
 /* Testing the win32 surface isn't interesting, since for
  * ARGB images it just chains to the image backend
  */
-#if 0 && CAIRO_HAS_WIN32_SURFACE
+#if CAIRO_HAS_WIN32_SURFACE
+#include "cairo-win32.h"
+typedef struct _win32_target_closure
+{
+  HDC dc;
+  HBITMAP bmp;
+} win32_target_closure_t;
+
 static cairo_surface_t *
-create_win32_surface (int width, int height, void **closure)
+create_win32_surface (cairo_test_t *test, cairo_format_t format,
+		      void **closure)
 {
-#error Not yet implemented
+    int width = test->width;
+    int height = test->height;
+
+    BITMAPINFO bmpInfo;
+    unsigned char *bits = NULL;
+    win32_target_closure_t *data = malloc(sizeof(win32_target_closure_t));
+    *closure = data;
+
+    data->dc = CreateCompatibleDC(NULL);
+
+    /* initialize the bitmapinfoheader */
+    memset(&bmpInfo.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
+    bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
+    bmpInfo.bmiHeader.biWidth = width;
+    bmpInfo.bmiHeader.biHeight = -height;
+    bmpInfo.bmiHeader.biPlanes = 1;
+    bmpInfo.bmiHeader.biBitCount = 24;
+    bmpInfo.bmiHeader.biCompression = BI_RGB;
+
+    /* create a DIBSection */
+    data->bmp = CreateDIBSection(data->dc, &bmpInfo, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
+
+    /* Flush GDI to make sure the DIBSection is actually created */
+    GdiFlush();
+
+    /* Select the bitmap in to the DC */
+    SelectObject(data->dc, data->bmp);
+
+    return cairo_win32_surface_create(data->dc);
 }
 
 static void
 cleanup_win32 (void *closure)
 {
-#error Not yet implemented
+  win32_target_closure_t *data = (win32_target_closure_t*)closure;
+  DeleteObject(data->bmp);
+  DeleteDC(data->dc);
+
+  free(closure);
 }
 #endif
 
@@ -665,10 +705,9 @@
 		create_quartz_surface, cairo_surface_write_to_png,
 		cleanup_quartz },
 #endif
-#if 0 && CAIRO_HAS_WIN32_SURFACE
+#if CAIRO_HAS_WIN32_SURFACE
 	    { "win32", CAIRO_FORMAT_RGB24,
-		create_win32_surface, cairo_surface_write_to_png,
-		cleanup_win32 },
+		create_win32_surface, cairo_surface_write_to_png, cleanup_win32 },
 #endif
 #if CAIRO_HAS_XCB_SURFACE
 	    { "xcb", CAIRO_FORMAT_ARGB32,



More information about the cairo-commit mailing list