cairo::device+x86_64 +linux

Devices are the abstraction Cairo employs for the rendering system used by a cairo::surface_t. You can get the device of a surface using cairo::surface::get_device.

Devices are created using custom functions specific to the rendering system you want to use. See the documentation for the surface types for those functions.

An important function that devices fulfill is sharing access to the rendering system between Cairo and your application. If you want to access a device directly that you used to draw to with Cairo, you must first call flush to ensure that Cairo finishes all operations on the device and resets it to a clean state.

Cairo also provides the functions acquire and release to synchronize access to the rendering system in a multithreaded environment. This is done internally, but can also be used by applications.

Putting this all together, a function that works with devices should look something like this:

fn my_device_modifying_function(device: cairo::device_t) void = { // Ensure the device is properly reset cairo::device::flush(device); // Try to acquire the device match(cairo::device::acquire(device)) { case void => void; case let e: cairo::error => fmt::fatalf("Failed to acquire the device: {}", cairo::strerror(e)); }; // Release the device when done. defer cairo::device::release(device); // Do the custom operations on the device here. // But do not call any Cairo functions that might acquire devices. };

Please refer to the documentation of each backend for additional usage requirements, guarantees provided, and interactions with existing surface API of the device functions for surfaces of that type.

Index

Functions

fn acquire(device: *cairo::device_t) (void | cairo::error);
fn destroy(device: *cairo::device_t) void;
fn finish(device: *cairo::device_t) void;
fn flush(device: *cairo::device_t) void;
fn get_reference_count(device: *cairo::device_t) uint;
fn get_type(device: *cairo::device_t) cairo::device_type_t;
fn get_user_data(device: *cairo::device_t, key: *const cairo::user_data_key_t) *opaque;
fn reference(device: *cairo::device_t) *cairo::device_t;
fn release(device: *cairo::device_t) void;
fn set_user_data(device: *cairo::device_t, key: *const cairo::user_data_key_t, user_data: *opaque, destroy: cairo::destroy_func_t) (void | cairo::error);
fn status(device: *cairo::device_t) cairo::status_t;

Functions

fn acquire[link]

fn acquire(device: *cairo::device_t) (void | cairo::error);

Acquires the device for the current thread. This function will block until no other thread has acquired the device.

If the return value is void, you successfully acquired the device. From now on your thread owns the device and no other thread will be able to acquire it until a matching call to release. It is allowed to recursively acquire the device multiple times from the same thread.

You must never acquire two different devices at the same time unless this is explicitly allowed. Otherwise the possibility of deadlocks exist. As various Cairo functions can acquire devices when called, these functions may also cause deadlocks when you call them with an acquired device. So you must not have a device acquired when calling them. These functions are marked in the documentation.

Returns void on success or an cairo::error if the device is in an error state and could not be acquired. After a successful call to acquire, a matching call to release is required.

fn destroy[link]

fn destroy(device: *cairo::device_t) void;

Decreases the reference count on device by one. If the result is zero, then device and all associated resources are freed. See reference.

This function may acquire devices if the last reference was dropped.

fn finish[link]

fn finish(device: *cairo::device_t) void;

This function finishes the device and drops all references to external resources. All surfaces, fonts and other objects created for this device will be finished, too. Further operations on the device will not affect the device but will instead trigger a cairo::status_t::DEVICE_FINISHED error.

When the last call to destroy decreases the reference count to zero, cairo will call finish if it hasn't been called already, before freeing the resources associated with the device.

This function may acquire devices.

fn flush[link]

fn flush(device: *cairo::device_t) void;

Finish any pending operations for the device and also restore any temporary modifications cairo has made to the device's state. This function must be called before switching from using the device with Cairo to operating on it directly with native APIs. If the device doesn't support direct access, then this function does nothing.

This function may acquire devices.

fn get_reference_count[link]

fn get_reference_count(device: *cairo::device_t) uint;

Returns the current reference count of device. If the object is a nil object, 0 will be returned.

fn get_type[link]

fn get_type(device: *cairo::device_t) cairo::device_type_t;

This function returns the type of the device. See cairo::device_type_t for available types.

fn get_user_data[link]

fn get_user_data(device: *cairo::device_t, key: *const cairo::user_data_key_t) *opaque;

XXX: HAREFY. Return user data previously attached to device using the specified key. If no user data has been attached with the given key this function returns null.

Parameters

Returns the user data previously attached or null.

fn reference[link]

fn reference(device: *cairo::device_t) *cairo::device_t;

Increases the reference count on device by one. This prevents device from being destroyed until a matching call to destroy is made. Use get_reference_count to get the number of references to a cairo::device_t.

Returns the referenced cairo::device_t.

fn release[link]

fn release(device: *cairo::device_t) void;

Releases a device previously acquired using acquire. See that function for details.

fn set_user_data[link]

fn set_user_data(device: *cairo::device_t, key: *const cairo::user_data_key_t, user_data: *opaque, destroy: cairo::destroy_func_t) (void | cairo::error);

XXX: HAREFY. Attach user data to device. To remove user data from a surface, call this function with the key that was used to set it and null for data.

Parameters

Returns void or cairo::error if a slot could not be allocated for the user data.

fn status[link]

fn status(device: *cairo::device_t) cairo::status_t;

Checks whether an error has previously occurred for this device.

Returns cairo::status_t::SUCCESS on success or an error code if the device is in an error state.