2011-12-19 09:38:28 -05:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2011-12-19 09:38:28 -05:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2011-12-19 09:38:28 -05:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2011-12-19 09:38:28 -05:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2011-12-19 09:38:28 -05:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl-glib-source.h"
|
|
|
|
#include "cogl-poll.h"
|
|
|
|
|
|
|
|
typedef struct _CoglGLibSource
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
2013-04-16 18:46:03 -04:00
|
|
|
CoglRenderer *renderer;
|
2011-12-19 09:38:28 -05:00
|
|
|
|
|
|
|
GArray *poll_fds;
|
2013-04-16 18:46:03 -04:00
|
|
|
int poll_fds_age;
|
2011-12-19 09:38:28 -05:00
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
int64_t expiration_time;
|
2011-12-19 09:38:28 -05:00
|
|
|
} CoglGLibSource;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-12-19 09:38:28 -05:00
|
|
|
cogl_glib_source_prepare (GSource *source, int *timeout)
|
|
|
|
{
|
|
|
|
CoglGLibSource *cogl_source = (CoglGLibSource *) source;
|
|
|
|
CoglPollFD *poll_fds;
|
|
|
|
int n_poll_fds;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
int64_t cogl_timeout;
|
2013-04-16 18:46:03 -04:00
|
|
|
int age;
|
2011-12-19 09:38:28 -05:00
|
|
|
int i;
|
|
|
|
|
2013-04-16 18:46:03 -04:00
|
|
|
age = cogl_poll_renderer_get_info (cogl_source->renderer,
|
|
|
|
&poll_fds,
|
|
|
|
&n_poll_fds,
|
|
|
|
&cogl_timeout);
|
2011-12-19 09:38:28 -05:00
|
|
|
|
|
|
|
/* We have to be careful not to call g_source_add/remove_poll unless
|
2013-04-16 18:46:03 -04:00
|
|
|
* the FDs have changed because it will cause the main loop to
|
|
|
|
* immediately wake up. If we call it every time the source is
|
|
|
|
* prepared it will effectively never go idle. */
|
|
|
|
if (age != cogl_source->poll_fds_age)
|
2011-12-19 09:38:28 -05:00
|
|
|
{
|
|
|
|
/* Remove any existing polls before adding the new ones */
|
|
|
|
for (i = 0; i < cogl_source->poll_fds->len; i++)
|
|
|
|
{
|
|
|
|
GPollFD *poll_fd = &g_array_index (cogl_source->poll_fds, GPollFD, i);
|
|
|
|
g_source_remove_poll (source, poll_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_set_size (cogl_source->poll_fds, n_poll_fds);
|
|
|
|
|
|
|
|
for (i = 0; i < n_poll_fds; i++)
|
|
|
|
{
|
|
|
|
GPollFD *poll_fd = &g_array_index (cogl_source->poll_fds, GPollFD, i);
|
|
|
|
poll_fd->fd = poll_fds[i].fd;
|
|
|
|
g_source_add_poll (source, poll_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 18:46:03 -04:00
|
|
|
cogl_source->poll_fds_age = age;
|
|
|
|
|
2011-12-19 09:38:28 -05:00
|
|
|
/* Update the events */
|
|
|
|
for (i = 0; i < n_poll_fds; i++)
|
|
|
|
{
|
|
|
|
GPollFD *poll_fd = &g_array_index (cogl_source->poll_fds, GPollFD, i);
|
|
|
|
poll_fd->events = poll_fds[i].events;
|
|
|
|
poll_fd->revents = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cogl_timeout == -1)
|
|
|
|
{
|
|
|
|
*timeout = -1;
|
|
|
|
cogl_source->expiration_time = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Round up to ensure that we don't try again too early */
|
|
|
|
*timeout = (cogl_timeout + 999) / 1000;
|
|
|
|
cogl_source->expiration_time = (g_source_get_time (source) +
|
|
|
|
cogl_timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *timeout == 0;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-12-19 09:38:28 -05:00
|
|
|
cogl_glib_source_check (GSource *source)
|
|
|
|
{
|
|
|
|
CoglGLibSource *cogl_source = (CoglGLibSource *) source;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (cogl_source->expiration_time >= 0 &&
|
|
|
|
g_source_get_time (source) >= cogl_source->expiration_time)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < cogl_source->poll_fds->len; i++)
|
|
|
|
{
|
|
|
|
GPollFD *poll_fd = &g_array_index (cogl_source->poll_fds, GPollFD, i);
|
|
|
|
if (poll_fd->revents != 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-12-19 09:38:28 -05:00
|
|
|
cogl_glib_source_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglGLibSource *cogl_source = (CoglGLibSource *) source;
|
|
|
|
CoglPollFD *poll_fds =
|
|
|
|
(CoglPollFD *) &g_array_index (cogl_source->poll_fds, GPollFD, 0);
|
|
|
|
|
2013-04-16 18:46:03 -04:00
|
|
|
cogl_poll_renderer_dispatch (cogl_source->renderer,
|
|
|
|
poll_fds,
|
|
|
|
cogl_source->poll_fds->len);
|
2011-12-19 09:38:28 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogl_glib_source_finalize (GSource *source)
|
|
|
|
{
|
|
|
|
CoglGLibSource *cogl_source = (CoglGLibSource *) source;
|
|
|
|
|
|
|
|
g_array_free (cogl_source->poll_fds, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSourceFuncs
|
|
|
|
cogl_glib_source_funcs =
|
|
|
|
{
|
|
|
|
cogl_glib_source_prepare,
|
|
|
|
cogl_glib_source_check,
|
|
|
|
cogl_glib_source_dispatch,
|
|
|
|
cogl_glib_source_finalize
|
|
|
|
};
|
|
|
|
|
|
|
|
GSource *
|
2013-04-16 18:46:03 -04:00
|
|
|
cogl_glib_renderer_source_new (CoglRenderer *renderer,
|
|
|
|
int priority)
|
2011-12-19 09:38:28 -05:00
|
|
|
{
|
|
|
|
GSource *source;
|
|
|
|
CoglGLibSource *cogl_source;
|
|
|
|
|
|
|
|
source = g_source_new (&cogl_glib_source_funcs,
|
|
|
|
sizeof (CoglGLibSource));
|
|
|
|
cogl_source = (CoglGLibSource *) source;
|
|
|
|
|
2013-04-16 18:46:03 -04:00
|
|
|
cogl_source->renderer = renderer;
|
2011-12-19 09:38:28 -05:00
|
|
|
cogl_source->poll_fds = g_array_new (FALSE, FALSE, sizeof (GPollFD));
|
|
|
|
|
|
|
|
if (priority != G_PRIORITY_DEFAULT)
|
|
|
|
g_source_set_priority (source, priority);
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
2013-04-16 18:46:03 -04:00
|
|
|
|
|
|
|
GSource *
|
|
|
|
cogl_glib_source_new (CoglContext *context,
|
|
|
|
int priority)
|
|
|
|
{
|
|
|
|
return cogl_glib_renderer_source_new (cogl_context_get_renderer (context),
|
|
|
|
priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
|