From dfe3e20a4a44db71270dd50b2e4bac84ff97dbb8 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sat, 9 Sep 2006 18:56:58 -0700 Subject: [PATCH] [win32] Fix boilerplate for win32 surfaces to use new _with_dib function Create test surfaces for win32 using _with_dib instead of creating the dib locally; also test CONTENT_COLOR and CONTENT_COLOR_ALPHA. --- boilerplate/cairo-boilerplate.c | 46 ++++++++------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) mode change 100644 => 100755 boilerplate/cairo-boilerplate.c diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c old mode 100644 new mode 100755 index 0137f6ebe..b8cad0309 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -708,12 +708,6 @@ cleanup_quartz (void *closure) */ #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 (const char *name, cairo_content_t content, @@ -721,42 +715,22 @@ create_win32_surface (const char *name, int height, void **closure) { - BITMAPINFO bmpInfo; - unsigned char *bits = NULL; - win32_target_closure_t *data = malloc(sizeof(win32_target_closure_t)); - *closure = data; + cairo_format_t format; - data->dc = CreateCompatibleDC(NULL); + if (content == CAIRO_CONTENT_COLOR) + format = CAIRO_FORMAT_RGB24; + else if (content == CAIRO_CONTENT_COLOR_ALPHA) + format = CAIRO_FORMAT_ARGB32; + else + return 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); + *closure = NULL; + return cairo_win32_surface_create_with_dib (format, width, height); } static void cleanup_win32 (void *closure) { - win32_target_closure_t *data = (win32_target_closure_t*)closure; - DeleteObject(data->bmp); - DeleteDC(data->dc); - - free(closure); } #endif @@ -1407,6 +1381,8 @@ cairo_boilerplate_target_t targets[] = #if CAIRO_HAS_WIN32_SURFACE { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 0, create_win32_surface, cairo_surface_write_to_png, cleanup_win32 }, + { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR_ALPHA, 0, + create_win32_surface, cairo_surface_write_to_png, cleanup_win32 }, #endif #if CAIRO_HAS_XCB_SURFACE { "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 0,