/** * cairo_xcb_surface_create_for_bitmap: * @connection: an XCB connection * @screen: the XCB screen associated with @bitmap * @bitmap: an XCB drawable (a Pixmap with depth 1) * @width: the current width of @bitmap * @height: the current height of @bitmap * * Creates an XCB surface that draws to the given bitmap. * This will be drawn to as a %CAIRO_FORMAT_A1 object. * * 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_for_bitmap (xcb_connection_t *connection, xcb_screen_t *screen, xcb_pixmap_t bitmap, int width, int height) { cairo_xcb_screen_t *cairo_xcb_screen; if (xcb_connection_has_error (connection)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); if (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)); cairo_xcb_screen = _cairo_xcb_screen_get (connection, screen); if (unlikely (cairo_xcb_screen == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); return _cairo_xcb_surface_create_internal (cairo_xcb_screen, bitmap, FALSE, PIXMAN_a1, cairo_xcb_screen->connection->standard_formats[CAIRO_FORMAT_A1], 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. **/ 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_with_xrender_format: * @connection: an XCB connection * @drawable: an XCB drawable * @screen: the XCB screen associated with @drawable * @format: the picture format to use for drawing to @drawable. The * depth of @format mush match the depth of the drawable. * @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 picture format. * * 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. **/ cairo_surface_t * cairo_xcb_surface_create_with_xrender_format (xcb_connection_t *connection, xcb_screen_t *screen, xcb_drawable_t drawable, xcb_render_pictforminfo_t *format, int width, int height) { cairo_xcb_screen_t *cairo_xcb_screen; cairo_format_masks_t image_masks; pixman_format_code_t pixman_format; if (xcb_connection_has_error (connection)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); if (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)); image_masks.alpha_mask = (unsigned long) format->direct.alpha_mask << format->direct.alpha_shift; image_masks.red_mask = (unsigned long) format->direct.red_mask << format->direct.red_shift; image_masks.green_mask = (unsigned long) format->direct.green_mask << format->direct.green_shift; image_masks.blue_mask = (unsigned long) format->direct.blue_mask << format->direct.blue_shift; #if 0 image_masks.bpp = format->depth; #else if (format->depth > 16) image_masks.bpp = 32; else if (format->depth > 8) image_masks.bpp = 16; else if (format->depth > 1) image_masks.bpp = 8; else image_masks.bpp = 1; #endif if (! _pixman_format_from_masks (&image_masks, &pixman_format)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); cairo_xcb_screen = _cairo_xcb_screen_get (connection, screen); if (unlikely (cairo_xcb_screen == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); return _cairo_xcb_surface_create_internal (cairo_xcb_screen, drawable, FALSE, pixman_format, format->id, width, height); }
/** * cairo_xcb_surface_create_with_xrender_format: * @c: an XCB connection * @drawable: an XCB drawable * @screen: the XCB screen associated with @drawable * @format: the picture format to use for drawing to @drawable. The * depth of @format mush match the depth of the drawable. * @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 picture format. * * NOTE: If @drawable is a Window, then the function * cairo_xcb_surface_set_size must be called whenever the size of the * window changes. * * Return value: the newly created surface. **/ cairo_surface_t * cairo_xcb_surface_create_with_xrender_format (XCBConnection *c, XCBDRAWABLE drawable, XCBSCREEN *screen, XCBRenderPICTFORMINFO *format, int width, int height) { return _cairo_xcb_surface_create_internal (c, drawable, screen, NULL, format, width, height, 0); }
/** * cairo_xcb_surface_create_for_bitmap: * @c: an XCB connection * @bitmap: an XCB Pixmap (a depth-1 pixmap) * @screen: an XCB Screen * @width: the current width of @bitmap * @height: the current height of @bitmap * * Creates an XCB surface that draws to the given bitmap. * This will be drawn to as a CAIRO_FORMAT_A1 object. * * Return value: the newly created surface **/ cairo_surface_t * cairo_xcb_surface_create_for_bitmap (XCBConnection *c, XCBPIXMAP bitmap, XCBSCREEN *screen, int width, int height) { XCBDRAWABLE drawable; drawable.pixmap = bitmap; return _cairo_xcb_surface_create_internal (c, drawable, screen, NULL, NULL, width, height, 1); }
/** * cairo_xcb_surface_create: * @c: 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. * * Return value: the newly created surface **/ cairo_surface_t * cairo_xcb_surface_create (XCBConnection *c, XCBDRAWABLE drawable, XCBVISUALTYPE *visual, int width, int height) { XCBSCREEN *screen = _cairo_xcb_screen_from_visual (c, visual); if (screen == NULL) { _cairo_error (CAIRO_STATUS_INVALID_VISUAL); return (cairo_surface_t*) &_cairo_surface_nil; } return _cairo_xcb_surface_create_internal (c, drawable, screen, visual, NULL, width, height, 0); }
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)) _cairo_xcb_connection_free_pixmap (connection, pixmap); _cairo_xcb_connection_release (connection); return &surface->base; }