[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.
This commit is contained in:
Vladimir Vukicevic 2006-09-09 18:56:58 -07:00 committed by U-CYCLONE\Vladimir Vukicevic
parent 9735cb9a24
commit dfe3e20a4a

46
boilerplate/cairo-boilerplate.c Normal file → Executable file
View file

@ -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,