third_party/cairo/src/win32/cairo-win32-display-surface.c
cairo_surface_t *
cairo_win32_surface_create_with_ddb (HDC hdc,
				     cairo_format_t format,
				     int width,
				     int height)
{
    cairo_win32_display_surface_t *new_surf;
    HBITMAP ddb;
    HDC screen_dc, ddb_dc;
    HBITMAP saved_dc_bitmap;

    switch (format) {
    default:
/* XXX handle these eventually */
    case CAIRO_FORMAT_A8:
    case CAIRO_FORMAT_A1:
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
    case CAIRO_FORMAT_ARGB32:
    case CAIRO_FORMAT_RGB24:
	break;
    }

    if (!hdc) {
	screen_dc = GetDC (NULL);
	hdc = screen_dc;
    } else {
	screen_dc = NULL;
    }

    ddb_dc = CreateCompatibleDC (hdc);
    if (ddb_dc == NULL) {
	new_surf = (cairo_win32_display_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
	goto FINISH;
    }

    ddb = CreateCompatibleBitmap (hdc, width, height);
    if (ddb == NULL) {
	DeleteDC (ddb_dc);

	/* Note that if an app actually does hit this out of memory
	 * condition, it's going to have lots of other issues, as
	 * video memory is probably exhausted.  However, it can often
	 * continue using DIBs instead of DDBs.
	 */
	new_surf = (cairo_win32_display_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
	goto FINISH;
    }

    saved_dc_bitmap = SelectObject (ddb_dc, ddb);

    new_surf = (cairo_win32_display_surface_t*) cairo_win32_surface_create (ddb_dc);
    new_surf->bitmap = ddb;
    new_surf->saved_dc_bitmap = saved_dc_bitmap;
    new_surf->is_dib = FALSE;

FINISH:
    if (screen_dc)
	ReleaseDC (NULL, screen_dc);

    return &new_surf->win32.base;
}
/**
 * cairo_win32_surface_create_with_ddb:
 * @hdc: a DC compatible with the surface to create
 * @format: format of pixels in the surface to create
 * @width: width of the surface, in pixels
 * @height: height of the surface, in pixels
 *
 * Creates a device-dependent-bitmap surface not associated with
 * any particular existing surface or device context. The created
 * bitmap will be uninitialized.
 *
 * Return value: the newly created surface
 *
 * Since: 1.4
 **/
@hdc: a DC compatible with the surface to create
@format: format of pixels in the surface to create
@width: width of the surface, in pixels
@height: height of the surface, in pixels

Creates a device-dependent-bitmap surface not associated with
any particular existing surface or device context. The created
bitmap will be uninitialized.

Return value: the newly created surface


@hdc : a DC compatible with the surface to create @format : format of pixels in the surface to create @width : width of the surface in pixels @height : height of the surface in pixels Creates a device - dependent - bitmap surface not associated with any particular existing surface or device context . The created bitmap will be uninitialized . Return value : the newly created surface
cairo_surface_t *
cairo_win32_surface_create_with_ddb (HDC hdc,
				     cairo_format_t format,
				     int width,
				     int height)
{
    cairo_win32_display_surface_t *new_surf;
    HBITMAP ddb;
    HDC screen_dc, ddb_dc;
    HBITMAP saved_dc_bitmap;
    switch (format) {
    default:
    case CAIRO_FORMAT_A8:
    case CAIRO_FORMAT_A1:
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
    case CAIRO_FORMAT_ARGB32:
    case CAIRO_FORMAT_RGB24:
	break;
    }
    if (!hdc) {
	screen_dc = GetDC (NULL);
	hdc = screen_dc;
    } else {
	screen_dc = NULL;
    }
    ddb_dc = CreateCompatibleDC (hdc);
    if (ddb_dc == NULL) {
	new_surf = (cairo_win32_display_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
	goto FINISH;
    }
    ddb = CreateCompatibleBitmap (hdc, width, height);
    if (ddb == NULL) {
	DeleteDC (ddb_dc);
	new_surf = (cairo_win32_display_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
	goto FINISH;
    }
    saved_dc_bitmap = SelectObject (ddb_dc, ddb);
    new_surf = (cairo_win32_display_surface_t*) cairo_win32_surface_create (ddb_dc);
    new_surf->bitmap = ddb;
    new_surf->saved_dc_bitmap = saved_dc_bitmap;
    new_surf->is_dib = FALSE;
FINISH:
    if (screen_dc)
	ReleaseDC (NULL, screen_dc);
    return &new_surf->win32.base;
}
cairo_surface_t * cairo_win32_surface_create_with_ddb ( HDC hdc , cairo_format_t format , int width , int height ) { cairo_win32_display_surface_t * new_surf ; HBITMAP ddb ; HDC screen_dc , ddb_dc ; HBITMAP saved_dc_bitmap ; switch ( format ) { default : case CAIRO_FORMAT_A8 : case CAIRO_FORMAT_A1 : return _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_INVALID_FORMAT ) ) ; case CAIRO_FORMAT_ARGB32 : case CAIRO_FORMAT_RGB24 : break ; } if ( ! hdc ) { screen_dc = GetDC ( NULL ) ; hdc = screen_dc ; } else { screen_dc = NULL ; } ddb_dc = CreateCompatibleDC ( hdc ) ; if ( ddb_dc == NULL ) { new_surf = ( cairo_win32_display_surface_t * ) _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ) ; goto FINISH ; } ddb = CreateCompatibleBitmap ( hdc , width , height ) ; if ( ddb == NULL ) { DeleteDC ( ddb_dc ) ; new_surf = ( cairo_win32_display_surface_t * ) _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ) ; goto FINISH ; } saved_dc_bitmap = SelectObject ( ddb_dc , ddb ) ; new_surf = ( cairo_win32_display_surface_t * ) cairo_win32_surface_create ( ddb_dc ) ; new_surf -> bitmap = ddb ; new_surf -> saved_dc_bitmap = saved_dc_bitmap ; new_surf -> is_dib = FALSE ; FINISH : if ( screen_dc ) ReleaseDC ( NULL , screen_dc ) ; return & new_surf -> win32 . base ; }
cairo_win32_surface_create_with_ddb:
 @hdc: a DC compatible with the surface to create
 @format: format of pixels in the surface to create
 @width: width of the surface, in pixels
 @height: height of the surface, in pixels
cairo_win32_surface_create_with_ddb : @hdc : a DC compatible with the surface to create @format : format of pixels in the surface to create @width : width of the surface in pixels @height : height of the surface in pixels
/* XXX handle these eventually */ /* Note that if an app actually does hit this out of memory
	 * condition, it's going to have lots of other issues, as
	 * video memory is probably exhausted.  However, it can often
	 * continue using DIBs instead of DDBs.
	 */