| 1 |
|
| 2 |
@c %start of fragment |
| 3 |
|
| 4 |
@node cairo_device_t |
| 5 |
@chapter cairo_device_t |
| 6 |
interface to underlying rendering system |
| 7 |
|
| 8 |
@section Overview |
| 9 |
Devices are the abstraction Cairo employs for the rendering system used |
| 10 |
by a @code{<cairo-surface>}. You can get the device of a surface using |
| 11 |
@code{cairo-surface-get-device}. |
| 12 |
|
| 13 |
Devices are created using custom functions specific to the rendering |
| 14 |
system you want to use. See the documentation for the surface types for |
| 15 |
those functions. |
| 16 |
|
| 17 |
An important function that devices fulfill is sharing access to the |
| 18 |
rendering system between Cairo and your application. If you want to |
| 19 |
access a device directly that you used to draw to with Cairo, you must |
| 20 |
first call @code{cairo-device-flush} to ensure that Cairo finishes all |
| 21 |
operations on the device and resets it to a clean state. |
| 22 |
|
| 23 |
Cairo also provides the functions @code{cairo-device-acquire} and |
| 24 |
@code{cairo-device-release} to synchronize access to the rendering |
| 25 |
system in a multithreaded environment. This is done internally, but can |
| 26 |
also be used by applications. |
| 27 |
|
| 28 |
Putting this all together, a function that works with devices should |
| 29 |
look something like this: |
| 30 |
|
| 31 |
@example |
| 32 |
|
| 33 |
void |
| 34 |
my_device_modifying_function (cairo_device_t *device) |
| 35 |
@{ |
| 36 |
cairo_status_t status; |
| 37 |
|
| 38 |
// Ensure the device is properly reset |
| 39 |
cairo_device_flush (device); |
| 40 |
// Try to acquire the device |
| 41 |
status = cairo_device_acquire (device); |
| 42 |
if (status != CAIRO_STATUS_SUCCESS) @{ |
| 43 |
printf ("Failed to acquire the device: %s\n", cairo_status_to_string (status)); |
| 44 |
return; |
| 45 |
@} |
| 46 |
|
| 47 |
// Do the custom operations on the device here. |
| 48 |
// But do not call any Cairo functions that might acquire devices. |
| 49 |
|
| 50 |
// Release the device when done. |
| 51 |
cairo_device_release (device); |
| 52 |
@} |
| 53 |
@end example |
| 54 |
|
| 55 |
Please refer to the documentation of each backend for additional usage |
| 56 |
requirements, guarantees provided, and interactions with existing |
| 57 |
surface API of the device functions for surfaces of that type. |
| 58 |
|
| 59 |
@section Usage |
| 60 |
@include defuns-cairo-device.xml.texi |
| 61 |
|
| 62 |
@c %end of fragment |