Aros/Developer/Cairo

There are currently two ports (1.5 and 1.12) of the Cairo graphics library. Both are located in the Aros contrib sources.

You'll find a quite recent version in "contrib/development/libs/cairo". It is a patch to Cairo version 1.12.0. This version builds into a static link library.

To compile the link library run the following commands in your Aros source directory:

make development-fontconfig

fc-cache

make development-cairo

This will build the dependencies and the Cairo and Pixman library.

Cairo 1.12 examples
Cairo 1.12, using directly the image surface (that processes everything in system memory) gives much faster results, say probably about 60% faster than the old 1.5.

Using the image surface, blit the rgba data to your custom area class in draw method, using cairo_image_get_data.

Cairo 1.5 examples
The Cairo version (1.5) in "contrib/gfx/libs/cairo/" is rather old. But in contrast to the other version it has the great advantage that it support Aros as a native backend. This means it comes with a function "cairo_aros_surface_create" that can render to Intuition RastPorts. First parameter was the pointer to the RastPort, the other parameters specified X/Y-offset, width and height. Also this port builds into a Aros shared library. In the Aros-Exec Archives you'll also find a static link library of Cairo that supports "cairo_aros_surface_create".

The old 1.5 version was entirely software-driven and it involved reads from the bitmap in video ram, which is highly inefficient.

The second example below shows a simple example of how native Aros surfaces are created and used.

Simple Cairo example that creates a PNG image

Compile with: gcc test.c -lcairo -lpixman -lfreetype2 -lfontconfig -liconv -lxml2 -lz -lpng

Simple Cairo example using Aros native RastPort backend

Direct Access Functions
cairo_image_get_data and other direct access functions are often misused by applications because they don't call cairo_surface_flush and/or cairo_surface_mark_dirty around the code which accesses the surface data directly. You must call cairo_surface_flush before reading from or writing to the surface and that you must use cairo_surface_mark_dirty after modifying it.

void modify_image_surface (cairo_surface_t *surface) { unsigned char *data; int width, height, stride;

// flush to ensure all writing to the image was done cairo_surface_flush (surface);

// modify the image data = cairo_image_surface_get_data (surface); width = cairo_image_surface_get_width (surface); height = cairo_image_surface_get_height (surface); stride = cairo_image_surface_get_stride (surface); modify_image_data (data, width, height, stride);

// mark the image dirty so Cairo clears its caches. cairo_surface_mark_dirty (surface); }

Cairo Library Calls

Surface
cairo_surface_create_similar cairo_surface_create_similar_image cairo_surface_create_for_rectangle cairo_surface_reference cairo_surface_destroy cairo_surface_status cairo_surface_finish cairo_surface_flush cairo_surface_get_device cairo_surface_get_font_options cairo_surface_get_content cairo_surface_mark_dirty cairo_surface_mark_dirty_rectangle cairo_surface_set_device_offset cairo_surface_get_device_offset cairo_surface_set_fallback_resolution cairo_surface_get_fallback_resolution cairo_surface_get_type cairo_surface_get_reference_count cairo_surface_set_user_data cairo_surface_get_user_data cairo_surface_copy_page cairo_surface_show_page cairo_surface_has_show_text_glyphs cairo_surface_set_mime_data cairo_surface_get_mime_data cairo_surface_supports_mime_type cairo_surface_map_to_image cairo_surface_unmap_image

Devices
cairo_device_reference cairo_device_destroy cairo_device_status cairo_device_finish cairo_device_flush cairo_device_get_type cairo_device_get_reference_count cairo_device_set_user_data cairo_device_get_user_data cairo_device_acquire cairo_device_release