85
85
Putting this all together, a function that works with devices should
86
86
look something like this:
88
<div class="informalexample">
89
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
92
<td class="listing_lines" align="right"><pre>1
112
<td class="listing_code"><pre class="programlisting"><span class="type">void</span>
113
<span class="function">my_device_modifying_function</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">cairo_device_t</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">device</span><span class="symbol">)</span>
114
<span class="cbracket">{</span>
115
<span class="normal"> </span><span class="usertype">cairo_status_t</span><span class="normal"> status</span><span class="symbol">;</span>
117
<span class="normal"> </span><span class="comment">// Ensure the device is properly reset</span>
118
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/cairo/cairo-cairo-device-t.html#cairo-device-flush">cairo_device_flush</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">device</span><span class="symbol">);</span>
119
<span class="normal"> </span><span class="comment">// Try to acquire the device</span>
120
<span class="normal"> status </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/cairo/cairo-cairo-device-t.html#cairo-device-acquire">cairo_device_acquire</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">device</span><span class="symbol">);</span>
121
<span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">status </span><span class="symbol">!=</span><span class="normal"> <a href="/usr/share/gtk-doc/html/cairo/cairo-Error-handling.html#CAIRO-STATUS-SUCCESS:CAPS">CAIRO_STATUS_SUCCESS</a></span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
122
<span class="normal"> </span><span class="function">printf</span><span class="normal"> </span><span class="symbol">(</span><span class="string">"Failed to acquire the device: %s</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/cairo/cairo-Error-handling.html#cairo-status-to-string">cairo_status_to_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">status</span><span class="symbol">));</span>
123
<span class="normal"> </span><span class="keyword">return</span><span class="symbol">;</span>
124
<span class="normal"> </span><span class="cbracket">}</span>
126
<span class="normal"> </span><span class="comment">// Do the custom operations on the device here.</span>
127
<span class="normal"> </span><span class="comment">// But do not call any Cairo functions that might acquire devices.</span>
128
<span class="normal"> </span>
129
<span class="normal"> </span><span class="comment">// Release the device when done.</span>
130
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/cairo/cairo-cairo-device-t.html#cairo-device-release">cairo_device_release</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">device</span><span class="symbol">);</span>
131
<span class="cbracket">}</span></pre></td>
88
<div class="informalexample"><pre class="programlisting">
90
my_device_modifying_function (cairo_device_t *device)
92
cairo_status_t status;
94
// Ensure the device is properly reset
95
cairo_device_flush (device);
96
// Try to acquire the device
97
status = cairo_device_acquire (device);
98
if (status != CAIRO_STATUS_SUCCESS) {
99
printf ("Failed to acquire the device: %s\n", cairo_status_to_string (status));
103
// Do the custom operations on the device here.
104
// But do not call any Cairo functions that might acquire devices.
106
// Release the device when done.
107
cairo_device_release (device);