"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-poll.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2012 Intel Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20  *
21  *
22  * Authors:
23  *  Neil Roberts <neil@linux.intel.com>
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "cogl-poll.h"
31 #include "cogl-winsys-private.h"
32 #include "cogl-context-private.h"
33
34 void
35 cogl_poll_get_info (CoglContext *context,
36                     CoglPollFD **poll_fds,
37                     int *n_poll_fds,
38                     gint64 *timeout)
39 {
40   const CoglWinsysVtable *winsys;
41
42   _COGL_RETURN_IF_FAIL (cogl_is_context (context));
43   _COGL_RETURN_IF_FAIL (poll_fds != NULL);
44   _COGL_RETURN_IF_FAIL (n_poll_fds != NULL);
45   _COGL_RETURN_IF_FAIL (timeout != NULL);
46
47   winsys = _cogl_context_get_winsys (context);
48
49   if (winsys->poll_get_info)
50     {
51       winsys->poll_get_info (context,
52                              poll_fds,
53                              n_poll_fds,
54                              timeout);
55       return;
56     }
57
58   /* By default we'll assume Cogl doesn't need to block on anything */
59   *poll_fds = NULL;
60   *n_poll_fds = 0;
61   *timeout = -1; /* no timeout */
62 }
63
64 void
65 cogl_poll_dispatch (CoglContext *context,
66                     const CoglPollFD *poll_fds,
67                     int n_poll_fds)
68 {
69   const CoglWinsysVtable *winsys;
70
71   _COGL_RETURN_IF_FAIL (cogl_is_context (context));
72
73   winsys = _cogl_context_get_winsys (context);
74
75   if (winsys->poll_dispatch)
76     winsys->poll_dispatch (context, poll_fds, n_poll_fds);
77 }