Bug 76438 - Cairo does not expose all Pixman surface formats
Summary: Cairo does not expose all Pixman surface formats
Alias: None
Product: cairo
Classification: Unclassified
Component: image backend (show other bugs)
Version: 1.12.16
Hardware: All All
: medium enhancement
Assignee: Chris Wilson
QA Contact: cairo-bugs mailing list
Depends on:
Reported: 2014-03-21 10:25 UTC by Tal
Modified: 2018-08-25 13:31 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Description Tal 2014-03-21 10:25:18 UTC
For a reason unknown to me, cairo_format_t is much more limited than the many options Pixman supports.

The _cairo_image_surface_create_with_pixman_format function does let the user choose a format, but it is not normally exposed.

I can think of many use cases. In particular, my issue was interaction with OpenGL ES 2.0: I am using Cairo to write to byte arrays which I later turn into GL textures. However, OpenGL ES 2.0 only support GL_RGBA, whereas Cairo's CAIRO_FORMAT_ARGB32 is equivalent to PIXMAN_a8r8g8b8. What I really need is PIXMAN_a8b8g8r8.

Can this API be made public?
Comment 1 Tal 2014-03-21 10:50:45 UTC
My simple patch, for those needing this feature:

Edit cairo-image-surface.c, and add the following:

cairo_surface_t *cairo_image_surface_create_with_pixman_format(unsigned char *data, pixman_format_code_t pixman_format, int width, int height, int stride) {
	return _cairo_image_surface_create_with_pixman_format(data, pixman_format, width, height, stride);

An example of calling the newly-exposed API:

#include "cairo/cairo.h"
#include "pixman.h"

cairo_surface_t *cairo_image_surface_create_with_pixman_format(unsigned char *data, pixman_format_code_t pixman_format, int width, int height, int stride);

cairo_surface_t *surface = cairo_image_surface_create_with_pixman_format(NULL, PIXMAN_a8b8g8r8, width, height, -1);
Comment 2 Uli Schlachter 2014-03-21 11:04:53 UTC
Patch from 2012 available at (but also look at the following discussion!):

Comment 3 Tal 2014-03-21 11:10:56 UTC
I'm confused as to why exposing the internal APIs is a problem. If it's a matter of hiding Pixman from Cairo users, then these "advanced" features could potentially be enabled by including an extra header file, "cairo/cairopixman.h" or something of the sort.

Is there any roadmap for solving this? In the meantime, I have to patch Cairo.
Comment 4 GitLab Migration User 2018-08-25 13:31:09 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/45.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.