cogl: Remove no longer used poll renderer API
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3887>
This commit is contained in:
parent
1d0680471e
commit
1ceb206897
6 changed files with 11 additions and 340 deletions
|
@ -39,9 +39,6 @@ typedef struct _CoglGLibSource
|
|||
|
||||
CoglRenderer *renderer;
|
||||
|
||||
GArray *poll_fds;
|
||||
int poll_fds_age;
|
||||
|
||||
int64_t expiration_time;
|
||||
} CoglGLibSource;
|
||||
|
||||
|
@ -49,49 +46,10 @@ static gboolean
|
|||
cogl_glib_source_prepare (GSource *source, int *timeout)
|
||||
{
|
||||
CoglGLibSource *cogl_source = (CoglGLibSource *) source;
|
||||
CoglPollFD *poll_fds;
|
||||
int n_poll_fds;
|
||||
int64_t cogl_timeout;
|
||||
int age;
|
||||
int i;
|
||||
|
||||
age = cogl_poll_renderer_get_info (cogl_source->renderer,
|
||||
&poll_fds,
|
||||
&n_poll_fds,
|
||||
&cogl_timeout);
|
||||
|
||||
/* We have to be careful not to call g_source_add/remove_poll unless
|
||||
* 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)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
cogl_source->poll_fds_age = age;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
cogl_poll_renderer_get_info (cogl_source->renderer,
|
||||
&cogl_timeout);
|
||||
|
||||
if (cogl_timeout == -1)
|
||||
{
|
||||
|
@ -113,19 +71,11 @@ static gboolean
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -135,31 +85,19 @@ cogl_glib_source_dispatch (GSource *source,
|
|||
void *user_data)
|
||||
{
|
||||
CoglGLibSource *cogl_source = (CoglGLibSource *) source;
|
||||
CoglPollFD *poll_fds =
|
||||
(CoglPollFD *) &g_array_index (cogl_source->poll_fds, GPollFD, 0);
|
||||
|
||||
cogl_poll_renderer_dispatch (cogl_source->renderer,
|
||||
poll_fds,
|
||||
cogl_source->poll_fds->len);
|
||||
cogl_poll_renderer_dispatch (cogl_source->renderer);
|
||||
|
||||
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
|
||||
NULL
|
||||
};
|
||||
|
||||
GSource *
|
||||
|
@ -175,7 +113,6 @@ cogl_glib_renderer_source_new (CoglRenderer *renderer,
|
|||
cogl_source = (CoglGLibSource *) source;
|
||||
|
||||
cogl_source->renderer = renderer;
|
||||
cogl_source->poll_fds = g_array_new (FALSE, FALSE, sizeof (GPollFD));
|
||||
|
||||
if (priority != G_PRIORITY_DEFAULT)
|
||||
g_source_set_priority (source, priority);
|
||||
|
|
|
@ -34,25 +34,6 @@
|
|||
#include "cogl/cogl-renderer.h"
|
||||
#include "cogl/cogl-closure-list-private.h"
|
||||
|
||||
typedef int64_t (*CoglPollPrepareCallback) (void *user_data);
|
||||
typedef void (*CoglPollDispatchCallback) (void *user_data, int revents);
|
||||
|
||||
void
|
||||
_cogl_poll_renderer_add_fd (CoglRenderer *renderer,
|
||||
int fd,
|
||||
CoglPollFDEvent events,
|
||||
CoglPollPrepareCallback prepare,
|
||||
CoglPollDispatchCallback dispatch,
|
||||
void *user_data);
|
||||
|
||||
typedef struct _CoglPollSource CoglPollSource;
|
||||
|
||||
CoglPollSource *
|
||||
_cogl_poll_renderer_add_source (CoglRenderer *renderer,
|
||||
CoglPollPrepareCallback prepare,
|
||||
CoglPollDispatchCallback dispatch,
|
||||
void *user_data);
|
||||
|
||||
typedef void (*CoglIdleCallback) (void *user_data);
|
||||
|
||||
CoglClosure *
|
||||
|
|
|
@ -37,182 +37,25 @@
|
|||
#include "cogl/cogl-renderer-private.h"
|
||||
#include "cogl/winsys/cogl-winsys-private.h"
|
||||
|
||||
struct _CoglPollSource
|
||||
{
|
||||
int fd;
|
||||
CoglPollPrepareCallback prepare;
|
||||
CoglPollDispatchCallback dispatch;
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
int
|
||||
void
|
||||
cogl_poll_renderer_get_info (CoglRenderer *renderer,
|
||||
CoglPollFD **poll_fds,
|
||||
int *n_poll_fds,
|
||||
int64_t *timeout)
|
||||
{
|
||||
GList *l, *next;
|
||||
|
||||
g_return_val_if_fail (COGL_IS_RENDERER (renderer), 0);
|
||||
g_return_val_if_fail (poll_fds != NULL, 0);
|
||||
g_return_val_if_fail (n_poll_fds != NULL, 0);
|
||||
g_return_val_if_fail (timeout != NULL, 0);
|
||||
g_return_if_fail (COGL_IS_RENDERER (renderer));
|
||||
g_return_if_fail (timeout != NULL);
|
||||
|
||||
*timeout = -1;
|
||||
|
||||
if (!_cogl_list_empty (&renderer->idle_closures))
|
||||
*timeout = 0;
|
||||
|
||||
/* This loop needs to cope with the prepare callback removing its
|
||||
* own fd */
|
||||
for (l = renderer->poll_sources; l; l = next)
|
||||
{
|
||||
CoglPollSource *source = l->data;
|
||||
|
||||
next = l->next;
|
||||
|
||||
if (source->prepare)
|
||||
{
|
||||
int64_t source_timeout = source->prepare (source->user_data);
|
||||
if (source_timeout >= 0 &&
|
||||
(*timeout == -1 || *timeout > source_timeout))
|
||||
*timeout = source_timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/* This is deliberately set after calling the prepare callbacks in
|
||||
* case one of them removes its fd */
|
||||
*poll_fds = (void *)renderer->poll_fds->data;
|
||||
*n_poll_fds = renderer->poll_fds->len;
|
||||
|
||||
return renderer->poll_fds_age;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_poll_renderer_dispatch (CoglRenderer *renderer,
|
||||
const CoglPollFD *poll_fds,
|
||||
int n_poll_fds)
|
||||
cogl_poll_renderer_dispatch (CoglRenderer *renderer)
|
||||
{
|
||||
GList *l, *next;
|
||||
|
||||
g_return_if_fail (COGL_IS_RENDERER (renderer));
|
||||
|
||||
_cogl_closure_list_invoke_no_args (&renderer->idle_closures);
|
||||
|
||||
/* This loop needs to cope with the dispatch callback removing its
|
||||
* own fd */
|
||||
for (l = renderer->poll_sources; l; l = next)
|
||||
{
|
||||
CoglPollSource *source = l->data;
|
||||
int i;
|
||||
|
||||
next = l->next;
|
||||
|
||||
if (source->fd == -1)
|
||||
{
|
||||
source->dispatch (source->user_data, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0; i < n_poll_fds; i++)
|
||||
{
|
||||
const CoglPollFD *pollfd = &poll_fds[i];
|
||||
|
||||
if (pollfd->fd == source->fd)
|
||||
{
|
||||
source->dispatch (source->user_data, pollfd->revents);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
find_pollfd (CoglRenderer *renderer, int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < renderer->poll_fds->len; i++)
|
||||
{
|
||||
CoglPollFD *pollfd = &g_array_index (renderer->poll_fds, CoglPollFD, i);
|
||||
|
||||
if (pollfd->fd == fd)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_poll_renderer_remove_fd (CoglRenderer *renderer, int fd)
|
||||
{
|
||||
int i = find_pollfd (renderer, fd);
|
||||
GList *l;
|
||||
|
||||
if (i < 0)
|
||||
return;
|
||||
|
||||
g_array_remove_index_fast (renderer->poll_fds, i);
|
||||
renderer->poll_fds_age++;
|
||||
|
||||
for (l = renderer->poll_sources; l; l = l->next)
|
||||
{
|
||||
CoglPollSource *source = l->data;
|
||||
if (source->fd == fd)
|
||||
{
|
||||
renderer->poll_sources =
|
||||
g_list_delete_link (renderer->poll_sources, l);
|
||||
g_free (source);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_poll_renderer_add_fd (CoglRenderer *renderer,
|
||||
int fd,
|
||||
CoglPollFDEvent events,
|
||||
CoglPollPrepareCallback prepare,
|
||||
CoglPollDispatchCallback dispatch,
|
||||
void *user_data)
|
||||
{
|
||||
CoglPollFD pollfd = {
|
||||
fd,
|
||||
events
|
||||
};
|
||||
CoglPollSource *source;
|
||||
|
||||
_cogl_poll_renderer_remove_fd (renderer, fd);
|
||||
|
||||
source = g_new0 (CoglPollSource, 1);
|
||||
source->fd = fd;
|
||||
source->prepare = prepare;
|
||||
source->dispatch = dispatch;
|
||||
source->user_data = user_data;
|
||||
|
||||
renderer->poll_sources = g_list_prepend (renderer->poll_sources, source);
|
||||
|
||||
g_array_append_val (renderer->poll_fds, pollfd);
|
||||
renderer->poll_fds_age++;
|
||||
}
|
||||
|
||||
CoglPollSource *
|
||||
_cogl_poll_renderer_add_source (CoglRenderer *renderer,
|
||||
CoglPollPrepareCallback prepare,
|
||||
CoglPollDispatchCallback dispatch,
|
||||
void *user_data)
|
||||
{
|
||||
CoglPollSource *source;
|
||||
|
||||
source = g_new0 (CoglPollSource, 1);
|
||||
source->fd = -1;
|
||||
source->prepare = prepare;
|
||||
source->dispatch = dispatch;
|
||||
source->user_data = user_data;
|
||||
|
||||
renderer->poll_sources = g_list_prepend (renderer->poll_sources, source);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
CoglClosure *
|
||||
|
|
|
@ -63,59 +63,10 @@ G_BEGIN_DECLS
|
|||
* to the main loop.
|
||||
*/
|
||||
|
||||
/**
|
||||
* CoglPollFDEvent:
|
||||
* @COGL_POLL_FD_EVENT_IN: there is data to read
|
||||
* @COGL_POLL_FD_EVENT_PRI: data can be written (without blocking)
|
||||
* @COGL_POLL_FD_EVENT_OUT: there is urgent data to read.
|
||||
* @COGL_POLL_FD_EVENT_ERR: error condition
|
||||
* @COGL_POLL_FD_EVENT_HUP: hung up (the connection has been broken, usually
|
||||
* for pipes and sockets).
|
||||
* @COGL_POLL_FD_EVENT_NVAL: invalid request. The file descriptor is not open.
|
||||
*
|
||||
* A bitmask of events that Cogl may need to wake on for a file
|
||||
* descriptor. Note that these all have the same values as the
|
||||
* corresponding defines for the poll function call on Unix so they
|
||||
* may be directly passed to poll.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
COGL_POLL_FD_EVENT_IN = COGL_SYSDEF_POLLIN,
|
||||
COGL_POLL_FD_EVENT_PRI = COGL_SYSDEF_POLLPRI,
|
||||
COGL_POLL_FD_EVENT_OUT = COGL_SYSDEF_POLLOUT,
|
||||
COGL_POLL_FD_EVENT_ERR = COGL_SYSDEF_POLLERR,
|
||||
COGL_POLL_FD_EVENT_HUP = COGL_SYSDEF_POLLHUP,
|
||||
COGL_POLL_FD_EVENT_NVAL = COGL_SYSDEF_POLLNVAL
|
||||
} CoglPollFDEvent;
|
||||
|
||||
/**
|
||||
* CoglPollFD:
|
||||
* @fd: The file descriptor to block on
|
||||
* @events: A bitmask of events to block on
|
||||
* @revents: A bitmask of returned events
|
||||
*
|
||||
* A struct for describing the state of a file descriptor that Cogl
|
||||
* needs to block on. The @events field contains a bitmask of
|
||||
* `CoglPollFDEvent`s that should cause the application to wake
|
||||
* up. After the application is woken up from idle it should pass back
|
||||
* an array of `CoglPollFD`s to Cogl and update the @revents
|
||||
* mask to the actual events that occurred on the file descriptor.
|
||||
*
|
||||
* Note that CoglPollFD is deliberately exactly the same as struct
|
||||
* pollfd on Unix so that it can simply be cast when calling poll.
|
||||
*/
|
||||
typedef struct {
|
||||
int fd;
|
||||
short int events;
|
||||
short int revents;
|
||||
} CoglPollFD;
|
||||
|
||||
/**
|
||||
* cogl_poll_renderer_get_info:
|
||||
* @renderer: A #CoglRenderer
|
||||
* @poll_fds: A return location for a pointer to an array
|
||||
* of `CoglPollFD`s
|
||||
* @n_poll_fds: A return location for the number of entries in *@poll_fds
|
||||
* @timeout: A return location for the maximum length of time to wait
|
||||
* in microseconds, or -1 to wait indefinitely.
|
||||
*
|
||||
|
@ -129,56 +80,23 @@ typedef struct {
|
|||
* should jump to the cogl_glib_source_new() api as a more convenient
|
||||
* way of integrating Cogl with the mainloop.
|
||||
*
|
||||
* After the function is called *@poll_fds will contain a pointer to
|
||||
* an array of #CoglPollFD structs describing the file descriptors
|
||||
* that Cogl expects. The fd and events members will be updated
|
||||
* accordingly. After the application has completed its idle it is
|
||||
* expected to either update the revents members directly in this
|
||||
* array or to create a copy of the array and update them
|
||||
* there.
|
||||
*
|
||||
* When the application mainloop returns from calling poll(2) (or its
|
||||
* equivalent) then it should call cogl_poll_renderer_dispatch()
|
||||
* passing a pointer the array of `CoglPollFD`s with updated
|
||||
* revent values.
|
||||
*
|
||||
* @timeout will contain a maximum amount of time to wait in
|
||||
* microseconds before the application should wake up or -1 if the
|
||||
* application should wait indefinitely. This can also be 0 if
|
||||
* Cogl needs to be woken up immediately.
|
||||
*
|
||||
* Return value: A "poll fd state age" that changes whenever the set
|
||||
* of poll_fds has changed. If this API is being used to
|
||||
* integrate with another system mainloop api then
|
||||
* knowing if the set of file descriptors and events has
|
||||
* really changed can help avoid redundant work
|
||||
* depending the api. The age isn't guaranteed to change
|
||||
* when the timeout changes.
|
||||
*/
|
||||
COGL_EXPORT int
|
||||
COGL_EXPORT void
|
||||
cogl_poll_renderer_get_info (CoglRenderer *renderer,
|
||||
CoglPollFD **poll_fds,
|
||||
int *n_poll_fds,
|
||||
int64_t *timeout);
|
||||
|
||||
/**
|
||||
* cogl_poll_renderer_dispatch:
|
||||
* @renderer: A #CoglRenderer
|
||||
* @poll_fds: An array of `CoglPollFD`s describing the events
|
||||
* that have occurred since the application went idle.
|
||||
* @n_poll_fds: The length of the @poll_fds array.
|
||||
*
|
||||
* This should be called whenever an application is woken up from
|
||||
* going idle in its main loop. The @poll_fds array should contain a
|
||||
* list of file descriptors matched with the events that occurred in
|
||||
* revents. The events field is ignored. It is safe to pass in extra
|
||||
* file descriptors that Cogl didn't request when calling
|
||||
* cogl_poll_renderer_get_info() or a shorter array missing some file
|
||||
* descriptors that Cogl requested.
|
||||
* going idle in its main loop.
|
||||
*/
|
||||
COGL_EXPORT void
|
||||
cogl_poll_renderer_dispatch (CoglRenderer *renderer,
|
||||
const CoglPollFD *poll_fds,
|
||||
int n_poll_fds);
|
||||
cogl_poll_renderer_dispatch (CoglRenderer *renderer);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -54,10 +54,6 @@ struct _CoglRenderer
|
|||
void *custom_winsys_user_data;
|
||||
CoglCustomWinsysVtableGetter custom_winsys_vtable_getter;
|
||||
|
||||
GArray *poll_fds;
|
||||
int poll_fds_age;
|
||||
GList *poll_sources;
|
||||
|
||||
CoglList idle_closures;
|
||||
|
||||
#ifdef HAVE_X11
|
||||
|
|
|
@ -165,8 +165,6 @@ cogl_renderer_dispose (GObject *object)
|
|||
g_slist_free_full (renderer->event_filters,
|
||||
(GDestroyNotify) native_filter_closure_free);
|
||||
|
||||
g_array_free (renderer->poll_fds, TRUE);
|
||||
|
||||
G_OBJECT_CLASS (cogl_renderer_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
|
@ -197,8 +195,6 @@ cogl_renderer_new (void)
|
|||
renderer->connected = FALSE;
|
||||
renderer->event_filters = NULL;
|
||||
|
||||
renderer->poll_fds = g_array_new (FALSE, TRUE, sizeof (CoglPollFD));
|
||||
|
||||
_cogl_list_init (&renderer->idle_closures);
|
||||
|
||||
return renderer;
|
||||
|
|
Loading…
Reference in a new issue