mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-15 08:00:34 +01:00
[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:
parent
9735cb9a24
commit
dfe3e20a4a
1 changed files with 11 additions and 35 deletions
46
boilerplate/cairo-boilerplate.c
Normal file → Executable file
46
boilerplate/cairo-boilerplate.c
Normal file → Executable 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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue