[cogl] glx: Only call swap_buffer callbacks @ dispatch time
- From: Robert Bragg <rbragg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl] glx: Only call swap_buffer callbacks @ dispatch time
- Date: Wed, 8 Feb 2012 19:24:41 +0000 (UTC)
commit 15d43bb6972c45d449b3a2c4bc7063f837329b9a
Author: Robert Bragg <robert linux intel com>
Date: Wed Feb 8 18:58:06 2012 +0000
glx: Only call swap_buffer callbacks @ dispatch time
This ensures we don't call swap buffer notify callback functions
immediately when they are received since it could be awkward for
applications to ensure they have dropped all necessary locks if they
don't know when callbacks might be invoked.
Reviewed-by: Neil Roberts <neil linux intel com>
cogl/cogl-glx-display-private.h | 1 +
cogl/winsys/cogl-winsys-glx.c | 50 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/cogl/cogl-glx-display-private.h b/cogl/cogl-glx-display-private.h
index d302369..32ff87b 100644
--- a/cogl/cogl-glx-display-private.h
+++ b/cogl/cogl-glx-display-private.h
@@ -50,6 +50,7 @@ typedef struct _CoglGLXDisplay
GLXContext glx_context;
GLXWindow dummy_glxwin;
Window dummy_xwin;
+ gboolean pending_swap_notify;
} CoglGLXDisplay;
#endif /* __COGL_DISPLAY_GLX_PRIVATE_H */
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index e4a01f8..6540ab4 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -81,6 +81,7 @@ typedef struct _CoglOnscreenGLX
GLXDrawable glxwin;
guint32 last_swap_vsync_counter;
GList *swap_callbacks;
+ gboolean pending_swap_notify;
} CoglOnscreenGLX;
typedef struct _CoglTexturePixmapGLX
@@ -163,11 +164,20 @@ static void
notify_swap_buffers (CoglContext *context, GLXDrawable drawable)
{
CoglOnscreen *onscreen = find_onscreen_for_xid (context, (guint32)drawable);
+ CoglDisplay *display = context->display;
+ CoglGLXDisplay *glx_display = display->winsys;
+ CoglOnscreenGLX *glx_onscreen;
if (!onscreen)
return;
- _cogl_onscreen_notify_swap_buffers (onscreen);
+ glx_onscreen = onscreen->winsys;
+
+ /* We only want to notify that the swap is complete when the
+ application calls cogl_context_dispatch so instead of immediately
+ notifying we'll set a flag to remember to notify later */
+ glx_display->pending_swap_notify = TRUE;
+ glx_onscreen->pending_swap_notify = TRUE;
}
static CoglFilterReturn
@@ -1959,10 +1969,37 @@ _cogl_winsys_poll_get_info (CoglContext *context,
int *n_poll_fds,
gint64 *timeout)
{
+ CoglDisplay *display = context->display;
+ CoglGLXDisplay *glx_display = display->winsys;
+
_cogl_xlib_renderer_poll_get_info (context->display->renderer,
poll_fds,
n_poll_fds,
timeout);
+
+ /* If we've already got a pending swap notify then we'll dispatch
+ immediately */
+ if (glx_display->pending_swap_notify)
+ *timeout = 0;
+}
+
+static void
+flush_pending_swap_notify_cb (void *data,
+ void *user_data)
+{
+ CoglFramebuffer *framebuffer = data;
+
+ if (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN)
+ {
+ CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
+ CoglOnscreenGLX *glx_onscreen = onscreen->winsys;
+
+ if (glx_onscreen->pending_swap_notify)
+ {
+ _cogl_onscreen_notify_swap_buffers (onscreen);
+ glx_onscreen->pending_swap_notify = FALSE;
+ }
+ }
}
static void
@@ -1970,9 +2007,20 @@ _cogl_winsys_poll_dispatch (CoglContext *context,
const CoglPollFD *poll_fds,
int n_poll_fds)
{
+ CoglDisplay *display = context->display;
+ CoglGLXDisplay *glx_display = display->winsys;
+
_cogl_xlib_renderer_poll_dispatch (context->display->renderer,
poll_fds,
n_poll_fds);
+
+ if (glx_display->pending_swap_notify)
+ {
+ g_list_foreach (context->framebuffers,
+ flush_pending_swap_notify_cb,
+ NULL);
+ glx_display->pending_swap_notify = FALSE;
+ }
}
static CoglWinsysVtable _cogl_winsys_vtable =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]