third_party/cairo/src/cairo-xcb-surface.c
cairo_surface_t *
_cairo_xcb_surface_create_similar (void			*abstract_other,
				   cairo_content_t	 content,
				   int			 width,
				   int			 height)
{
    cairo_xcb_surface_t *other = abstract_other;
    cairo_xcb_surface_t *surface;
    cairo_xcb_connection_t *connection;
    xcb_pixmap_t pixmap;
    cairo_status_t status;

    if (unlikely(width  > XLIB_COORD_MAX ||
		 height > XLIB_COORD_MAX ||
		 width  <= 0 ||
		 height <= 0))
	return cairo_image_surface_create (_cairo_format_from_content (content),
					   width, height);

    if ((other->connection->flags & CAIRO_XCB_HAS_RENDER) == 0)
	return _cairo_xcb_surface_create_similar_image (other,
							_cairo_format_from_content (content),
							width, height);

    connection = other->connection;
    status = _cairo_xcb_connection_acquire (connection);
    if (unlikely (status))
	return _cairo_surface_create_in_error (status);

    if (content == other->base.content) {
	pixmap = _cairo_xcb_connection_create_pixmap (connection,
						      other->depth,
						      other->drawable,
						      width, height);

	surface = (cairo_xcb_surface_t *)
	    _cairo_xcb_surface_create_internal (other->screen,
						pixmap, TRUE,
						other->pixman_format,
						other->xrender_format,
						width, height);
    } else {
	cairo_format_t format;
	pixman_format_code_t pixman_format;

	/* XXX find a compatible xrender format */
	switch (content) {
	case CAIRO_CONTENT_ALPHA:
	    pixman_format = PIXMAN_a8;
	    format = CAIRO_FORMAT_A8;
	    break;
	case CAIRO_CONTENT_COLOR:
	    pixman_format = PIXMAN_x8r8g8b8;
	    format = CAIRO_FORMAT_RGB24;
	    break;
	default:
	    ASSERT_NOT_REACHED;
	case CAIRO_CONTENT_COLOR_ALPHA:
	    pixman_format = PIXMAN_a8r8g8b8;
	    format = CAIRO_FORMAT_ARGB32;
	    break;
	}

	pixmap = _cairo_xcb_connection_create_pixmap (connection,
						      PIXMAN_FORMAT_DEPTH (pixman_format),
						      other->drawable,
						      width, height);

	surface = (cairo_xcb_surface_t *)
	    _cairo_xcb_surface_create_internal (other->screen,
						pixmap, TRUE,
						pixman_format,
						connection->standard_formats[format],
						width, height);
    }

    if (unlikely (surface->base.status))
	xcb_free_pixmap (connection->xcb_connection, pixmap);

    _cairo_xcb_connection_release (connection);

    return &surface->base;
}
/**
 * CAIRO_HAS_XCB_SURFACE:
 *
 * Defined if the xcb surface backend is available.
 * This macro can be used to conditionally compile backend-specific code.
 *
 * Since: 1.12
 **/
Defined if the xcb surface backend is available.
This macro can be used to conditionally compile backend-specific code.


Defined if the xcb surface backend is available . This macro can be used to conditionally compile backend - specific code .
cairo_surface_t *
_cairo_xcb_surface_create_similar (void			*abstract_other,
				   cairo_content_t	 content,
				   int			 width,
				   int			 height)
{
    cairo_xcb_surface_t *other = abstract_other;
    cairo_xcb_surface_t *surface;
    cairo_xcb_connection_t *connection;
    xcb_pixmap_t pixmap;
    cairo_status_t status;
    if (unlikely(width  > XLIB_COORD_MAX ||
		 height > XLIB_COORD_MAX ||
		 width  <= 0 ||
		 height <= 0))
	return cairo_image_surface_create (_cairo_format_from_content (content),
					   width, height);
    if ((other->connection->flags & CAIRO_XCB_HAS_RENDER) == 0)
	return _cairo_xcb_surface_create_similar_image (other,
							_cairo_format_from_content (content),
							width, height);
    connection = other->connection;
    status = _cairo_xcb_connection_acquire (connection);
    if (unlikely (status))
	return _cairo_surface_create_in_error (status);
    if (content == other->base.content) {
	pixmap = _cairo_xcb_connection_create_pixmap (connection,
						      other->depth,
						      other->drawable,
						      width, height);
	surface = (cairo_xcb_surface_t *)
	    _cairo_xcb_surface_create_internal (other->screen,
						pixmap, TRUE,
						other->pixman_format,
						other->xrender_format,
						width, height);
    } else {
	cairo_format_t format;
	pixman_format_code_t pixman_format;
	switch (content) {
	case CAIRO_CONTENT_ALPHA:
	    pixman_format = PIXMAN_a8;
	    format = CAIRO_FORMAT_A8;
	    break;
	case CAIRO_CONTENT_COLOR:
	    pixman_format = PIXMAN_x8r8g8b8;
	    format = CAIRO_FORMAT_RGB24;
	    break;
	default:
	    ASSERT_NOT_REACHED;
	case CAIRO_CONTENT_COLOR_ALPHA:
	    pixman_format = PIXMAN_a8r8g8b8;
	    format = CAIRO_FORMAT_ARGB32;
	    break;
	}
	pixmap = _cairo_xcb_connection_create_pixmap (connection,
						      PIXMAN_FORMAT_DEPTH (pixman_format),
						      other->drawable,
						      width, height);
	surface = (cairo_xcb_surface_t *)
	    _cairo_xcb_surface_create_internal (other->screen,
						pixmap, TRUE,
						pixman_format,
						connection->standard_formats[format],
						width, height);
    }
    if (unlikely (surface->base.status))
	xcb_free_pixmap (connection->xcb_connection, pixmap);
    _cairo_xcb_connection_release (connection);
    return &surface->base;
}
cairo_surface_t * _cairo_xcb_surface_create_similar ( void * abstract_other , cairo_content_t content , int width , int height ) { cairo_xcb_surface_t * other = abstract_other ; cairo_xcb_surface_t * surface ; cairo_xcb_connection_t * connection ; xcb_pixmap_t pixmap ; cairo_status_t status ; if ( unlikely ( width > XLIB_COORD_MAX || height > XLIB_COORD_MAX || width <= 0 || height <= 0 ) ) return cairo_image_surface_create ( _cairo_format_from_content ( content ) , width , height ) ; if ( ( other -> connection -> flags & CAIRO_XCB_HAS_RENDER ) == 0 ) return _cairo_xcb_surface_create_similar_image ( other , _cairo_format_from_content ( content ) , width , height ) ; connection = other -> connection ; status = _cairo_xcb_connection_acquire ( connection ) ; if ( unlikely ( status ) ) return _cairo_surface_create_in_error ( status ) ; if ( content == other -> base . content ) { pixmap = _cairo_xcb_connection_create_pixmap ( connection , other -> depth , other -> drawable , width , height ) ; surface = ( cairo_xcb_surface_t * ) _cairo_xcb_surface_create_internal ( other -> screen , pixmap , TRUE , other -> pixman_format , other -> xrender_format , width , height ) ; } else { cairo_format_t format ; pixman_format_code_t pixman_format ; switch ( content ) { case CAIRO_CONTENT_ALPHA : pixman_format = PIXMAN_a8 ; format = CAIRO_FORMAT_A8 ; break ; case CAIRO_CONTENT_COLOR : pixman_format = PIXMAN_x8r8g8b8 ; format = CAIRO_FORMAT_RGB24 ; break ; default : ASSERT_NOT_REACHED ; case CAIRO_CONTENT_COLOR_ALPHA : pixman_format = PIXMAN_a8r8g8b8 ; format = CAIRO_FORMAT_ARGB32 ; break ; } pixmap = _cairo_xcb_connection_create_pixmap ( connection , PIXMAN_FORMAT_DEPTH ( pixman_format ) , other -> drawable , width , height ) ; surface = ( cairo_xcb_surface_t * ) _cairo_xcb_surface_create_internal ( other -> screen , pixmap , TRUE , pixman_format , connection -> standard_formats [ format ] , width , height ) ; } if ( unlikely ( surface -> base . status ) ) xcb_free_pixmap ( connection -> xcb_connection , pixmap ) ; _cairo_xcb_connection_release ( connection ) ; return & surface -> base ; }
CAIRO_HAS_XCB_SURFACE:
 Defined if the xcb surface backend is available.
CAIRO_HAS_XCB_SURFACE : Defined if the xcb surface backend is available .
/* XXX find a compatible xrender format */