third_party/cairo/src/cairo-xcb-surface.c
cairo_surface_t *
cairo_xcb_surface_create (xcb_connection_t  *connection,
			  xcb_drawable_t     drawable,
			  xcb_visualtype_t  *visual,
			  int		     width,
			  int		     height)
{
    cairo_xcb_screen_t *screen;
    xcb_screen_t *xcb_screen;
    cairo_format_masks_t image_masks;
    pixman_format_code_t pixman_format;
    xcb_render_pictformat_t xrender_format;
    int depth;

    if (xcb_connection_has_error (connection))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR));

    if (unlikely (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
    if (unlikely (width <= 0 || height <= 0))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));

    xcb_screen = _cairo_xcb_screen_from_visual (connection, visual, &depth);
    if (unlikely (xcb_screen == NULL))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL));

    image_masks.alpha_mask = 0;
    image_masks.red_mask   = visual->red_mask;
    image_masks.green_mask = visual->green_mask;
    image_masks.blue_mask  = visual->blue_mask;
    if (depth == 32) /* XXX visuals have no alpha! */
	image_masks.alpha_mask =
	    0xffffffff & ~(visual->red_mask | visual->green_mask | visual->blue_mask);
    if (depth > 16)
	image_masks.bpp = 32;
    else if (depth > 8)
	image_masks.bpp = 16;
    else if (depth > 1)
	image_masks.bpp = 8;
    else
	image_masks.bpp = 1;

    if (! _pixman_format_from_masks (&image_masks, &pixman_format))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));

    screen = _cairo_xcb_screen_get (connection, xcb_screen);
    if (unlikely (screen == NULL))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));

    xrender_format =
	_cairo_xcb_connection_get_xrender_format_for_visual (screen->connection,
							     visual->visual_id);

    return _cairo_xcb_surface_create_internal (screen, drawable, FALSE,
					       pixman_format,
					       xrender_format,
					       width, height);
}
/**
 * cairo_xcb_surface_create:
 * @connection: an XCB connection
 * @drawable: an XCB drawable
 * @visual: the visual to use for drawing to @drawable. The depth
 *          of the visual must match the depth of the drawable.
 *          Currently, only TrueColor visuals are fully supported.
 * @width: the current width of @drawable
 * @height: the current height of @drawable
 *
 * Creates an XCB surface that draws to the given drawable.
 * The way that colors are represented in the drawable is specified
 * by the provided visual.
 *
 * Note: If @drawable is a Window, then the function
 * cairo_xcb_surface_set_size() must be called whenever the size of the
 * window changes.
 *
 * When @drawable is a Window containing child windows then drawing to
 * the created surface will be clipped by those child windows.  When
 * the created surface is used as a source, the contents of the
 * children will be included.
 *
 * Return value: a pointer to the newly created surface. The caller
 * owns the surface and should call cairo_surface_destroy() when done
 * with it.
 *
 * This function always returns a valid pointer, but it will return a
 * pointer to a "nil" surface if an error such as out of memory
 * occurs. You can use cairo_surface_status() to check for this.
 *
 * Since: 1.12
 **/
@connection: an XCB connection
@drawable: an XCB drawable
@visual: the visual to use for drawing to @drawable. The depth
of the visual must match the depth of the drawable.
Currently, only TrueColor visuals are fully supported.
@width: the current width of @drawable
@height: the current height of @drawable

Creates an XCB surface that draws to the given drawable.
The way that colors are represented in the drawable is specified
by the provided visual.

If @drawable is a Window, then the function
cairo_xcb_surface_set_size() must be called whenever the size of the
window changes.

When @drawable is a Window containing child windows then drawing to
the created surface will be clipped by those child windows.  When
the created surface is used as a source, the contents of the
children will be included.

Return value: a pointer to the newly created surface. The caller
owns the surface and should call cairo_surface_destroy() when done
with it.

This function always returns a valid pointer, but it will return a
pointer to a "nil" surface if an error such as out of memory
occurs. You can use cairo_surface_status() to check for this.


@connection : an XCB connection @drawable : an XCB drawable @visual : the visual to use for drawing to @drawable . The depth of the visual must match the depth of the drawable . Currently only TrueColor visuals are fully supported . @width : the current width of @drawable @height : the current height of @drawable Creates an XCB surface that draws to the given drawable . The way that colors are represented in the drawable is specified by the provided visual . If @drawable is a Window then the function cairo_xcb_surface_set_size () must be called whenever the size of the window changes . When @drawable is a Window containing child windows then drawing to the created surface will be clipped by those child windows . When the created surface is used as a source the contents of the children will be included . Return value : a pointer to the newly created surface . The caller owns the surface and should call cairo_surface_destroy () when done with it . This function always returns a valid pointer but it will return a pointer to a " nil " surface if an error such as out of memory occurs . You can use cairo_surface_status () to check for this .
cairo_surface_t *
cairo_xcb_surface_create (xcb_connection_t  *connection,
			  xcb_drawable_t     drawable,
			  xcb_visualtype_t  *visual,
			  int		     width,
			  int		     height)
{
    cairo_xcb_screen_t *screen;
    xcb_screen_t *xcb_screen;
    cairo_format_masks_t image_masks;
    pixman_format_code_t pixman_format;
    xcb_render_pictformat_t xrender_format;
    int depth;
    if (xcb_connection_has_error (connection))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR));
    if (unlikely (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
    if (unlikely (width <= 0 || height <= 0))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
    xcb_screen = _cairo_xcb_screen_from_visual (connection, visual, &depth);
    if (unlikely (xcb_screen == NULL))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL));
    image_masks.alpha_mask = 0;
    image_masks.red_mask   = visual->red_mask;
    image_masks.green_mask = visual->green_mask;
    image_masks.blue_mask  = visual->blue_mask;
    if (depth == 32) 
	image_masks.alpha_mask =
	    0xffffffff & ~(visual->red_mask | visual->green_mask | visual->blue_mask);
    if (depth > 16)
	image_masks.bpp = 32;
    else if (depth > 8)
	image_masks.bpp = 16;
    else if (depth > 1)
	image_masks.bpp = 8;
    else
	image_masks.bpp = 1;
    if (! _pixman_format_from_masks (&image_masks, &pixman_format))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
    screen = _cairo_xcb_screen_get (connection, xcb_screen);
    if (unlikely (screen == NULL))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
    xrender_format =
	_cairo_xcb_connection_get_xrender_format_for_visual (screen->connection,
							     visual->visual_id);
    return _cairo_xcb_surface_create_internal (screen, drawable, FALSE,
					       pixman_format,
					       xrender_format,
					       width, height);
}
cairo_surface_t * cairo_xcb_surface_create ( xcb_connection_t * connection , xcb_drawable_t drawable , xcb_visualtype_t * visual , int width , int height ) { cairo_xcb_screen_t * screen ; xcb_screen_t * xcb_screen ; cairo_format_masks_t image_masks ; pixman_format_code_t pixman_format ; xcb_render_pictformat_t xrender_format ; int depth ; if ( xcb_connection_has_error ( connection ) ) return _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_WRITE_ERROR ) ) ; if ( unlikely ( width > XLIB_COORD_MAX || height > XLIB_COORD_MAX ) ) return _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_INVALID_SIZE ) ) ; if ( unlikely ( width <= 0 || height <= 0 ) ) return _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_INVALID_SIZE ) ) ; xcb_screen = _cairo_xcb_screen_from_visual ( connection , visual , & depth ) ; if ( unlikely ( xcb_screen == NULL ) ) return _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_INVALID_VISUAL ) ) ; image_masks . alpha_mask = 0 ; image_masks . red_mask = visual -> red_mask ; image_masks . green_mask = visual -> green_mask ; image_masks . blue_mask = visual -> blue_mask ; if ( depth == 32 ) image_masks . alpha_mask = 0xffffffff & ~ ( visual -> red_mask | visual -> green_mask | visual -> blue_mask ) ; if ( depth > 16 ) image_masks . bpp = 32 ; else if ( depth > 8 ) image_masks . bpp = 16 ; else if ( depth > 1 ) image_masks . bpp = 8 ; else image_masks . bpp = 1 ; if ( ! _pixman_format_from_masks ( & image_masks , & pixman_format ) ) return _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_INVALID_FORMAT ) ) ; screen = _cairo_xcb_screen_get ( connection , xcb_screen ) ; if ( unlikely ( screen == NULL ) ) return _cairo_surface_create_in_error ( _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ) ; xrender_format = _cairo_xcb_connection_get_xrender_format_for_visual ( screen -> connection , visual -> visual_id ) ; return _cairo_xcb_surface_create_internal ( screen , drawable , FALSE , pixman_format , xrender_format , width , height ) ; }
cairo_xcb_surface_create:
 @connection: an XCB connection
 @drawable: an XCB drawable
 @visual: the visual to use for drawing to @drawable.
cairo_xcb_surface_create : @connection : an XCB connection @drawable : an XCB drawable @visual : the visual to use for drawing to @drawable .
/* XXX visuals have no alpha! */