"Initial commit to Gerrit"
[profile/ivi/cogl.git] / doc / reference / cogl-2.0-experimental / html / cogl-2.0-experimental-Main-loop-integeration.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Main loop integeration</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="Cogl 2.0 Reference Manual">
8 <link rel="up" href="ch01.html" title="Cogl - a modern 3D graphics API">
9 <link rel="prev" href="cogl-2.0-experimental-The-Top-Level-Context.html" title="The Top-Level Context">
10 <link rel="next" href="cogl-pipeline-apis.html" title="Setting Up A GPU Pipeline">
11 <meta name="generator" content="GTK-Doc V1.18.1 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
16 <tr valign="middle">
17 <td><a accesskey="p" href="cogl-2.0-experimental-The-Top-Level-Context.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="ch01.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">Cogl 2.0 Reference Manual</th>
21 <td><a accesskey="n" href="cogl-pipeline-apis.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
22 </tr>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#cogl-2.0-experimental-Main-loop-integeration.synopsis" class="shortcut">Top</a>
25                    | 
26                   <a href="#cogl-2.0-experimental-Main-loop-integeration.description" class="shortcut">Description</a>
27 </td></tr>
28 </table>
29 <div class="refentry">
30 <a name="cogl-2.0-experimental-Main-loop-integeration"></a><div class="titlepage"></div>
31 <div class="refnamediv"><table width="100%"><tr>
32 <td valign="top">
33 <h2><span class="refentrytitle"><a name="cogl-2.0-experimental-Main-loop-integeration.top_of_page"></a>Main loop integeration</span></h2>
34 <p>Main loop integeration — Functions for integrating Cogl with an
35   application's main loop</p>
36 </td>
37 <td valign="top" align="right"></td>
38 </tr></table></div>
39 <div class="refsynopsisdiv">
40 <a name="cogl-2.0-experimental-Main-loop-integeration.synopsis"></a><h2>Synopsis</h2>
41 <pre class="synopsis">enum                <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFDEvent" title="enum CoglPollFDEvent">CoglPollFDEvent</a>;
42                     <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD">CoglPollFD</a>;
43 <span class="returnvalue">void</span>                <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#cogl-poll-get-info" title="cogl_poll_get_info ()">cogl_poll_get_info</a>                  (<em class="parameter"><code><span class="type">CoglContext</span> *context</code></em>,
44                                                          <em class="parameter"><code><a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a> **poll_fds</code></em>,
45                                                          <em class="parameter"><code><span class="type">int</span> *n_poll_fds</code></em>,
46                                                          <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gint64"><span class="type">gint64</span></a> *timeout</code></em>);
47 <span class="returnvalue">void</span>                <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#cogl-poll-dispatch" title="cogl_poll_dispatch ()">cogl_poll_dispatch</a>                  (<em class="parameter"><code><span class="type">CoglContext</span> *context</code></em>,
48                                                          <em class="parameter"><code>const <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a> *poll_fds</code></em>,
49                                                          <em class="parameter"><code><span class="type">int</span> n_poll_fds</code></em>);
50 <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GSource"><span class="returnvalue">GSource</span></a> *           <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#cogl-glib-source-new" title="cogl_glib_source_new ()">cogl_glib_source_new</a>                (<em class="parameter"><code><span class="type">CoglContext</span> *context</code></em>,
51                                                          <em class="parameter"><code><span class="type">int</span> priority</code></em>);
52 </pre>
53 </div>
54 <div class="refsect1">
55 <a name="cogl-2.0-experimental-Main-loop-integeration.description"></a><h2>Description</h2>
56 <p>
57 Cogl needs to integrate with the application's main loop so that it
58 can internally handle some events from the driver. All Cogl
59 applications must use these functions. They provide enough
60 information to describe the state that Cogl will need to wake up
61 on. An application using the GLib main loop can instead use
62 <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#cogl-glib-source-new" title="cogl_glib_source_new ()"><code class="function">cogl_glib_source_new()</code></a> which provides a <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a> ready to be added
63 to the main loop.
64 </p>
65 </div>
66 <div class="refsect1">
67 <a name="cogl-2.0-experimental-Main-loop-integeration.details"></a><h2>Details</h2>
68 <div class="refsect2">
69 <a name="CoglPollFDEvent"></a><h3>enum CoglPollFDEvent</h3>
70 <pre class="programlisting">typedef enum {
71   COGL_POLL_FD_EVENT_IN = COGL_SYSDEF_POLLIN,
72   COGL_POLL_FD_EVENT_PRI = COGL_SYSDEF_POLLPRI,
73   COGL_POLL_FD_EVENT_OUT = COGL_SYSDEF_POLLOUT,
74   COGL_POLL_FD_EVENT_ERR = COGL_SYSDEF_POLLERR,
75   COGL_POLL_FD_EVENT_HUP = COGL_SYSDEF_POLLHUP,
76   COGL_POLL_FD_EVENT_NVAL = COGL_SYSDEF_POLLNVAL
77 } CoglPollFDEvent;
78 </pre>
79 <p>
80 A bitmask of events that Cogl may need to wake on for a file
81 descriptor. Note that these all have the same values as the
82 corresponding defines for the poll function call on Unix so they
83 may be directly passed to poll.
84 </p>
85 <p class="since">Since 1.10</p>
86 <p class="stability">Stability Level: Unstable</p>
87 </div>
88 <hr>
89 <div class="refsect2">
90 <a name="CoglPollFD"></a><h3>CoglPollFD</h3>
91 <pre class="programlisting">typedef struct {
92   int fd;
93   short int events;
94   short int revents;
95 } CoglPollFD;
96 </pre>
97 <p>
98 A struct for describing the state of a file descriptor that Cogl
99 needs to block on. The <em class="parameter"><code>events</code></em> field contains a bitmask of
100 <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFDEvent" title="enum CoglPollFDEvent"><span class="type">CoglPollFDEvent</span></a>s that should cause the application to wake
101 up. After the application is woken up from idle it should pass back
102 an array of <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a>s to Cogl and update the <em class="parameter"><code>revents</code></em>
103 mask to the actual events that occurred on the file descriptor.
104 </p>
105 <p>
106 Note that CoglPollFD is deliberately exactly the same as struct
107 pollfd on Unix so that it can simply be cast when calling poll.
108 </p>
109 <div class="variablelist"><table border="0">
110 <col align="left" valign="top">
111 <tbody>
112 <tr>
113 <td><p><span class="term"><span class="type">int</span> <em class="structfield"><code><a name="CoglPollFD.fd"></a>fd</code></em>;</span></p></td>
114 <td>The file descriptor to block on</td>
115 </tr>
116 <tr>
117 <td><p><span class="term">short <span class="type">int</span> <em class="structfield"><code><a name="CoglPollFD.events"></a>events</code></em>;</span></p></td>
118 <td>A bitmask of events to block on</td>
119 </tr>
120 <tr>
121 <td><p><span class="term">short <span class="type">int</span> <em class="structfield"><code><a name="CoglPollFD.revents"></a>revents</code></em>;</span></p></td>
122 <td>A bitmask of returned events</td>
123 </tr>
124 </tbody>
125 </table></div>
126 <p class="since">Since 1.10</p>
127 <p class="stability">Stability Level: Unstable</p>
128 </div>
129 <hr>
130 <div class="refsect2">
131 <a name="cogl-poll-get-info"></a><h3>cogl_poll_get_info ()</h3>
132 <pre class="programlisting"><span class="returnvalue">void</span>                cogl_poll_get_info                  (<em class="parameter"><code><span class="type">CoglContext</span> *context</code></em>,
133                                                          <em class="parameter"><code><a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a> **poll_fds</code></em>,
134                                                          <em class="parameter"><code><span class="type">int</span> *n_poll_fds</code></em>,
135                                                          <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gint64"><span class="type">gint64</span></a> *timeout</code></em>);</pre>
136 <p>
137 This should be called whenever an application is about to go idle
138 so that Cogl has a chance to describe what state it needs to be
139 woken up on. The assumption is that the application is using a main
140 loop with something like the poll function call on Unix or the GLib
141 main loop.
142 </p>
143 <p>
144 After the function is called *<em class="parameter"><code>poll_fds</code></em> will contain a pointer to
145 an array of <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a> structs describing the file descriptors
146 that Cogl expects. The fd and events members will be updated
147 accordingly. After the application has completed its idle it is
148 expected to either update the revents members directly in this
149 array or to create a copy of the array and update them
150 there. Either way it should pass a pointer to either array back to
151 Cogl when calling <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#cogl-poll-dispatch" title="cogl_poll_dispatch ()"><code class="function">cogl_poll_dispatch()</code></a>.
152 </p>
153 <p>
154 When using the <code class="literal">COGL_WINSYS_ID_WGL</code> winsys (where file descriptors
155 don't make any sense) or <code class="literal">COGL_WINSYS_ID_SDL</code> (where the event
156 handling functions of SDL don't allow blocking on a file
157 descriptor) *n_poll_fds is guaranteed to be zero.
158 </p>
159 <p>
160 <em class="parameter"><code>timeout</code></em> will contain a maximum amount of time to wait in
161 microseconds before the application should wake up or -1 if the
162 application should wait indefinitely. This can also be 0 zero if
163 Cogl needs to be woken up immediately.
164 </p>
165 <div class="variablelist"><table border="0">
166 <col align="left" valign="top">
167 <tbody>
168 <tr>
169 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
170 <td>A <span class="type">CoglContext</span>
171 </td>
172 </tr>
173 <tr>
174 <td><p><span class="term"><em class="parameter"><code>poll_fds</code></em> :</span></p></td>
175 <td>A return location for a pointer to an array
176 of <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a>s</td>
177 </tr>
178 <tr>
179 <td><p><span class="term"><em class="parameter"><code>n_poll_fds</code></em> :</span></p></td>
180 <td>A return location for the number of entries in *<em class="parameter"><code>poll_fds</code></em>
181 </td>
182 </tr>
183 <tr>
184 <td><p><span class="term"><em class="parameter"><code>timeout</code></em> :</span></p></td>
185 <td>A return location for the maximum length of time to wait
186 in microseconds, or -1 to wait indefinitely.</td>
187 </tr>
188 </tbody>
189 </table></div>
190 <p class="since">Since 1.10</p>
191 <p class="stability">Stability Level: Unstable</p>
192 </div>
193 <hr>
194 <div class="refsect2">
195 <a name="cogl-poll-dispatch"></a><h3>cogl_poll_dispatch ()</h3>
196 <pre class="programlisting"><span class="returnvalue">void</span>                cogl_poll_dispatch                  (<em class="parameter"><code><span class="type">CoglContext</span> *context</code></em>,
197                                                          <em class="parameter"><code>const <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a> *poll_fds</code></em>,
198                                                          <em class="parameter"><code><span class="type">int</span> n_poll_fds</code></em>);</pre>
199 <p>
200 This should be called whenever an application is woken up from
201 going idle in its main loop. The <em class="parameter"><code>poll_fds</code></em> array should contain a
202 list of file descriptors matched with the events that occurred in
203 revents. The events field is ignored. It is safe to pass in extra
204 file descriptors that Cogl didn't request from
205 <code class="function">cogl_context_begin_idle()</code> or a shorter array missing some file
206 descriptors that Cogl requested.
207 </p>
208 <div class="variablelist"><table border="0">
209 <col align="left" valign="top">
210 <tbody>
211 <tr>
212 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
213 <td>A <span class="type">CoglContext</span>
214 </td>
215 </tr>
216 <tr>
217 <td><p><span class="term"><em class="parameter"><code>poll_fds</code></em> :</span></p></td>
218 <td>An array of <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#CoglPollFD" title="CoglPollFD"><span class="type">CoglPollFD</span></a>s describing the events
219 that have occurred since the application went idle.</td>
220 </tr>
221 <tr>
222 <td><p><span class="term"><em class="parameter"><code>n_poll_fds</code></em> :</span></p></td>
223 <td>The length of the <em class="parameter"><code>poll_fds</code></em> array.</td>
224 </tr>
225 </tbody>
226 </table></div>
227 <p class="since">Since 1.10</p>
228 <p class="stability">Stability Level: Unstable</p>
229 </div>
230 <hr>
231 <div class="refsect2">
232 <a name="cogl-glib-source-new"></a><h3>cogl_glib_source_new ()</h3>
233 <pre class="programlisting"><a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GSource"><span class="returnvalue">GSource</span></a> *           cogl_glib_source_new                (<em class="parameter"><code><span class="type">CoglContext</span> *context</code></em>,
234                                                          <em class="parameter"><code><span class="type">int</span> priority</code></em>);</pre>
235 <p>
236 Creates a <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a> which handles Cogl's internal system event
237 processing. This can be used as a convenience instead of
238 <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#cogl-poll-get-info" title="cogl_poll_get_info ()"><code class="function">cogl_poll_get_info()</code></a> and <a class="link" href="cogl-2.0-experimental-Main-loop-integeration.html#cogl-poll-dispatch" title="cogl_poll_dispatch ()"><code class="function">cogl_poll_dispatch()</code></a> in applications that
239 are already using the GLib main loop. After this is called the
240 <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a> should be attached to the main loop using
241 <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-source-attach"><code class="function">g_source_attach()</code></a>.
242 </p>
243 <div class="variablelist"><table border="0">
244 <col align="left" valign="top">
245 <tbody>
246 <tr>
247 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
248 <td>A <span class="type">CoglContext</span>
249 </td>
250 </tr>
251 <tr>
252 <td><p><span class="term"><em class="parameter"><code>priority</code></em> :</span></p></td>
253 <td>The priority of the <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a>
254 </td>
255 </tr>
256 <tr>
257 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
258 <td>a new <a href="http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a>
259 </td>
260 </tr>
261 </tbody>
262 </table></div>
263 <p class="since">Since 1.10</p>
264 <p class="stability">Stability Level: Unstable</p>
265 </div>
266 </div>
267 </div>
268 <div class="footer">
269 <hr>
270           Generated by GTK-Doc V1.18.1</div>
271 </body>
272 </html>