From 142b229c5c2684f94af32358d1401b61aa3019aa Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Wed, 12 Jan 2011 22:06:58 +0000 Subject: [PATCH] cogl: Adds _cogl_swap_buffers_notify for clutter backends This adds a stop-gap mechanism for Cogl to know when the window system is requested to present the current backbuffer to the frontbuffer by adding a _cogl_swap_buffers_notify function that backends are now expected to call right after issuing the equivalent request to OpenGL vie the platforms OpenGL binding layer. This (blindly) updates all the backends to call this new function. For now Cogl doesn't do anything with the notification but the intention is to use it as part of a planned read-pixel optimization which will need to reset some state at the start of each new frame. --- clutter/cogl/cogl/cogl-framebuffer-private.h | 3 +++ clutter/cogl/cogl/cogl-framebuffer.c | 5 +++++ clutter/cogl/cogl/cogl.c | 10 ++++++++++ clutter/cogl/cogl/cogl.h | 3 +++ clutter/egl/clutter-stage-egl.c | 1 + clutter/fruity/clutter-backend-fruity.c | 1 + clutter/glx/clutter-stage-glx.c | 1 + clutter/osx/clutter-stage-osx.c | 1 + clutter/wayland/clutter-stage-wayland.c | 2 ++ clutter/win32/clutter-backend-win32.c | 5 ++++- 10 files changed, 31 insertions(+), 1 deletion(-) diff --git a/clutter/cogl/cogl/cogl-framebuffer-private.h b/clutter/cogl/cogl/cogl-framebuffer-private.h index 0bfc64e61..3d9cba364 100644 --- a/clutter/cogl/cogl/cogl-framebuffer-private.h +++ b/clutter/cogl/cogl/cogl-framebuffer-private.h @@ -193,6 +193,9 @@ _cogl_framebuffer_flush_journal (CoglFramebuffer *framebuffer); void _cogl_framebuffer_flush_dependency_journals (CoglFramebuffer *framebuffer); +void +_cogl_framebuffer_swap_notify (CoglFramebuffer *framebuffer); + typedef enum _CoglFramebufferFlushFlags { /* XXX: When using this, that imples you are going to manually load the diff --git a/clutter/cogl/cogl/cogl-framebuffer.c b/clutter/cogl/cogl/cogl-framebuffer.c index ede491e37..a0c5b944d 100644 --- a/clutter/cogl/cogl/cogl-framebuffer.c +++ b/clutter/cogl/cogl/cogl-framebuffer.c @@ -313,6 +313,11 @@ _cogl_framebuffer_clear (CoglFramebuffer *framebuffer, cogl_color_get_alpha_float (color)); } +void +_cogl_framebuffer_swap_notify (CoglFramebuffer *framebuffer) +{ +} + int _cogl_framebuffer_get_width (CoglFramebuffer *framebuffer) { diff --git a/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c index c2cee24ae..b6c3fa535 100644 --- a/clutter/cogl/cogl/cogl.c +++ b/clutter/cogl/cogl/cogl.c @@ -1097,3 +1097,13 @@ _cogl_error_quark (void) return g_quark_from_static_string ("cogl-error-quark"); } +/* Until Cogl becomes responsible for handling swap-buffer requests + * this API is used by Clutter to notify us when it issues a + * swap-buffer on our behalf. */ +void +_cogl_swap_buffers_notify (void) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + _cogl_framebuffer_swap_notify (_cogl_get_framebuffer ()); +} diff --git a/clutter/cogl/cogl/cogl.h b/clutter/cogl/cogl/cogl.h index d6170fe16..0e8d1ad08 100644 --- a/clutter/cogl/cogl/cogl.h +++ b/clutter/cogl/cogl/cogl.h @@ -1293,6 +1293,9 @@ _cogl_driver_error_quark (void); void _cogl_onscreen_clutter_backend_set_size (int width, int height); +void +_cogl_swap_buffers_notify (void); + G_END_DECLS #undef __COGL_H_INSIDE__ diff --git a/clutter/egl/clutter-stage-egl.c b/clutter/egl/clutter-stage-egl.c index 6bf8dd73c..6f31f479a 100644 --- a/clutter/egl/clutter-stage-egl.c +++ b/clutter/egl/clutter-stage-egl.c @@ -573,6 +573,7 @@ _clutter_stage_egl_redraw (ClutterStageEGL *stage_egl, CLUTTER_TIMER_START (_clutter_uprof_context, swapbuffers_timer); eglSwapBuffers (backend_egl->edpy, egl_surface); CLUTTER_TIMER_STOP (_clutter_uprof_context, swapbuffers_timer); + _cogl_swap_buffers_notify (); } /* reset the redraw clipping for the next paint... */ diff --git a/clutter/fruity/clutter-backend-fruity.c b/clutter/fruity/clutter-backend-fruity.c index df1c1e8f1..054c34bb5 100644 --- a/clutter/fruity/clutter-backend-fruity.c +++ b/clutter/fruity/clutter-backend-fruity.c @@ -77,6 +77,7 @@ clutter_backend_egl_redraw (ClutterBackend *backend, cogl_flush (); eglWaitGL(); eglSwapBuffers (backend_egl->edpy, stage_egl->egl_surface); + _cogl_swap_buffers_notify (); } static ClutterActor * diff --git a/clutter/glx/clutter-stage-glx.c b/clutter/glx/clutter-stage-glx.c index ae3c8cda1..1854017a9 100644 --- a/clutter/glx/clutter-stage-glx.c +++ b/clutter/glx/clutter-stage-glx.c @@ -737,6 +737,7 @@ _clutter_stage_glx_redraw (ClutterStageGLX *stage_glx, CLUTTER_TIMER_START (_clutter_uprof_context, swapbuffers_timer); glXSwapBuffers (backend_x11->xdpy, drawable); CLUTTER_TIMER_STOP (_clutter_uprof_context, swapbuffers_timer); + _cogl_swap_buffers_notify (); } backend_glx->last_video_sync_count = video_sync_count; diff --git a/clutter/osx/clutter-stage-osx.c b/clutter/osx/clutter-stage-osx.c index aa5fe6115..4f70e1220 100644 --- a/clutter/osx/clutter-stage-osx.c +++ b/clutter/osx/clutter-stage-osx.c @@ -152,6 +152,7 @@ clutter_stage_osx_get_wrapper (ClutterStageWindow *stage_window); _clutter_stage_do_paint (CLUTTER_STAGE (self->stage_osx->wrapper), NULL); cogl_flush (); [[self openGLContext] flushBuffer]; + _cogl_swap_buffers_notify (); } /* In order to receive key events */ diff --git a/clutter/wayland/clutter-stage-wayland.c b/clutter/wayland/clutter-stage-wayland.c index 19c4b530b..3bd478abb 100644 --- a/clutter/wayland/clutter-stage-wayland.c +++ b/clutter/wayland/clutter-stage-wayland.c @@ -372,6 +372,8 @@ wayland_swap_buffers (ClutterStageWayland *stage_wayland) wl_display_frame_callback (backend_wayland->wayland_display, wayland_frame_callback, stage_wayland); + + _cogl_swap_buffers_notify (); } static void diff --git a/clutter/win32/clutter-backend-win32.c b/clutter/win32/clutter-backend-win32.c index 9f6720b4d..1e132d1f7 100644 --- a/clutter/win32/clutter-backend-win32.c +++ b/clutter/win32/clutter-backend-win32.c @@ -498,7 +498,10 @@ clutter_backend_win32_redraw (ClutterBackend *backend, cogl_flush (); if (stage_win32->client_dc) - SwapBuffers (stage_win32->client_dc); + { + SwapBuffers (stage_win32->client_dc); + _cogl_swap_buffers_notify (); + } } static ClutterStageWindow *