template: Allow configuration of swap throttle
This adds cogl_onscreen_template_set_swap_throttled() api that allows developers to specify their preference for swap buffer throttling up-front as part of the onscreen template that is used to create a CoglDisplay when initializing Cogl. This is desirable because some platforms may not support configuring swap throttling on a per framebuffer basis and also since applications often want to apply the same policy to all onscreen framebuffers anyway.
This commit is contained in:
parent
1e03780510
commit
3161f1b0e6
@ -49,6 +49,7 @@ typedef struct
|
|||||||
CoglSwapChain *swap_chain;
|
CoglSwapChain *swap_chain;
|
||||||
gboolean need_stencil;
|
gboolean need_stencil;
|
||||||
int samples_per_pixel;
|
int samples_per_pixel;
|
||||||
|
gboolean swap_throttled;
|
||||||
} CoglFramebufferConfig;
|
} CoglFramebufferConfig;
|
||||||
|
|
||||||
/* Flags to pass to _cogl_offscreen_new_to_texture_full */
|
/* Flags to pass to _cogl_offscreen_new_to_texture_full */
|
||||||
|
@ -86,3 +86,11 @@ cogl_onscreen_template_set_samples_per_pixel (
|
|||||||
{
|
{
|
||||||
onscreen_template->config.samples_per_pixel = samples_per_pixel;
|
onscreen_template->config.samples_per_pixel = samples_per_pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cogl_onscreen_template_set_swap_throttled (
|
||||||
|
CoglOnscreenTemplate *onscreen_template,
|
||||||
|
gboolean throttled)
|
||||||
|
{
|
||||||
|
onscreen_template->config.swap_throttled = throttled;
|
||||||
|
}
|
||||||
|
@ -71,6 +71,23 @@ cogl_onscreen_template_set_samples_per_pixel (
|
|||||||
CoglOnscreenTemplate *onscreen_template,
|
CoglOnscreenTemplate *onscreen_template,
|
||||||
int n);
|
int n);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cogl_onscreen_template_set_swap_throttled:
|
||||||
|
* @onscreen_template: A #CoglOnscreenTemplate template framebuffer
|
||||||
|
* @throttled: Whether throttling should be enabled
|
||||||
|
*
|
||||||
|
* Requests that any future #CoglOnscreen framebuffers derived from this
|
||||||
|
* template should enable or disable swap throttling according to the given
|
||||||
|
* @throttled argument.
|
||||||
|
*
|
||||||
|
* Since: 1.10
|
||||||
|
* Stability: unstable
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
cogl_onscreen_template_set_swap_throttled (
|
||||||
|
CoglOnscreenTemplate *onscreen_template,
|
||||||
|
gboolean throttled);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __COGL_ONSCREEN_TEMPLATE_H__ */
|
#endif /* __COGL_ONSCREEN_TEMPLATE_H__ */
|
||||||
|
@ -100,9 +100,6 @@ cogl_onscreen_new (CoglContext *ctx, int width, int height)
|
|||||||
|
|
||||||
_cogl_onscreen_init_from_template (onscreen, ctx->display->onscreen_template);
|
_cogl_onscreen_init_from_template (onscreen, ctx->display->onscreen_template);
|
||||||
|
|
||||||
/* FIXME: This should be configurable via the template too */
|
|
||||||
onscreen->swap_throttled = TRUE;
|
|
||||||
|
|
||||||
return _cogl_onscreen_object_new (onscreen);
|
return _cogl_onscreen_object_new (onscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +287,7 @@ cogl_onscreen_set_swap_throttled (CoglOnscreen *onscreen,
|
|||||||
gboolean throttled)
|
gboolean throttled)
|
||||||
{
|
{
|
||||||
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
||||||
onscreen->swap_throttled = throttled;
|
framebuffer->config.swap_throttled = throttled;
|
||||||
if (framebuffer->allocated)
|
if (framebuffer->allocated)
|
||||||
{
|
{
|
||||||
const CoglWinsysVtable *winsys =
|
const CoglWinsysVtable *winsys =
|
||||||
|
@ -534,7 +534,8 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
|
|||||||
static void
|
static void
|
||||||
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
||||||
{
|
{
|
||||||
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
|
CoglFramebuffer *fb = COGL_FRAMEBUFFER (onscreen);
|
||||||
|
CoglContext *context = fb->context;
|
||||||
CoglDisplayEGL *egl_display = context->display->winsys;
|
CoglDisplayEGL *egl_display = context->display->winsys;
|
||||||
CoglRenderer *renderer = context->display->renderer;
|
CoglRenderer *renderer = context->display->renderer;
|
||||||
CoglRendererEGL *egl_renderer = renderer->winsys;
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
||||||
@ -550,7 +551,7 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
|||||||
egl_display->egl_context);
|
egl_display->egl_context);
|
||||||
egl_context->current_surface = egl_onscreen->egl_surface;
|
egl_context->current_surface = egl_onscreen->egl_surface;
|
||||||
|
|
||||||
if (onscreen->swap_throttled)
|
if (fb->config.swap_throttled)
|
||||||
eglSwapInterval (egl_renderer->edpy, 1);
|
eglSwapInterval (egl_renderer->edpy, 1);
|
||||||
else
|
else
|
||||||
eglSwapInterval (egl_renderer->edpy, 0);
|
eglSwapInterval (egl_renderer->edpy, 0);
|
||||||
|
@ -1061,7 +1061,8 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
|||||||
*/
|
*/
|
||||||
if (glx_renderer->pf_glXSwapInterval)
|
if (glx_renderer->pf_glXSwapInterval)
|
||||||
{
|
{
|
||||||
if (onscreen->swap_throttled)
|
CoglFramebuffer *fb = COGL_FRAMEBUFFER (onscreen);
|
||||||
|
if (fb->config.swap_throttled)
|
||||||
glx_renderer->pf_glXSwapInterval (1);
|
glx_renderer->pf_glXSwapInterval (1);
|
||||||
else
|
else
|
||||||
glx_renderer->pf_glXSwapInterval (0);
|
glx_renderer->pf_glXSwapInterval (0);
|
||||||
@ -1162,7 +1163,7 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
|
|||||||
framebuffer,
|
framebuffer,
|
||||||
COGL_FRAMEBUFFER_STATE_BIND);
|
COGL_FRAMEBUFFER_STATE_BIND);
|
||||||
|
|
||||||
if (onscreen->swap_throttled)
|
if (framebuffer->config.swap_throttled)
|
||||||
{
|
{
|
||||||
have_counter =
|
have_counter =
|
||||||
_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_VBLANK_COUNTER);
|
_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_VBLANK_COUNTER);
|
||||||
@ -1297,7 +1298,7 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
|
|||||||
|
|
||||||
drawable = glx_onscreen->glxwin ? glx_onscreen->glxwin : xlib_onscreen->xwin;
|
drawable = glx_onscreen->glxwin ? glx_onscreen->glxwin : xlib_onscreen->xwin;
|
||||||
|
|
||||||
if (onscreen->swap_throttled)
|
if (framebuffer->config.swap_throttled)
|
||||||
{
|
{
|
||||||
guint32 end_frame_vsync_counter = 0;
|
guint32 end_frame_vsync_counter = 0;
|
||||||
|
|
||||||
|
@ -89,7 +89,6 @@ typedef struct _CoglOnscreenWgl
|
|||||||
|
|
||||||
HDC client_dc;
|
HDC client_dc;
|
||||||
|
|
||||||
gboolean swap_throttled;
|
|
||||||
} CoglOnscreenWgl;
|
} CoglOnscreenWgl;
|
||||||
|
|
||||||
/* Define a set of arrays containing the functions required from GL
|
/* Define a set of arrays containing the functions required from GL
|
||||||
@ -651,6 +650,7 @@ _cogl_winsys_context_deinit (CoglContext *context)
|
|||||||
static void
|
static void
|
||||||
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
||||||
{
|
{
|
||||||
|
CoglFramebuffer *fb;
|
||||||
CoglContext *context;
|
CoglContext *context;
|
||||||
CoglContextWgl *wgl_context;
|
CoglContextWgl *wgl_context;
|
||||||
CoglDisplayWgl *wgl_display;
|
CoglDisplayWgl *wgl_display;
|
||||||
@ -663,7 +663,8 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
|||||||
context */
|
context */
|
||||||
_COGL_RETURN_IF_FAIL (onscreen != NULL);
|
_COGL_RETURN_IF_FAIL (onscreen != NULL);
|
||||||
|
|
||||||
context = COGL_FRAMEBUFFER (onscreen)->context;
|
fb = COGL_FRAMEBUFFER (onscreen);
|
||||||
|
context = fb->context;
|
||||||
wgl_context = context->winsys;
|
wgl_context = context->winsys;
|
||||||
wgl_display = context->display->winsys;
|
wgl_display = context->display->winsys;
|
||||||
wgl_onscreen = onscreen->winsys;
|
wgl_onscreen = onscreen->winsys;
|
||||||
@ -680,7 +681,7 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
|||||||
*/
|
*/
|
||||||
if (wgl_renderer->pf_wglSwapInterval)
|
if (wgl_renderer->pf_wglSwapInterval)
|
||||||
{
|
{
|
||||||
if (onscreen->swap_throttled)
|
if (fb->config.swap_throttled)
|
||||||
wgl_renderer->pf_wglSwapInterval (1);
|
wgl_renderer->pf_wglSwapInterval (1);
|
||||||
else
|
else
|
||||||
wgl_renderer->pf_wglSwapInterval (0);
|
wgl_renderer->pf_wglSwapInterval (0);
|
||||||
|
Loading…
Reference in New Issue
Block a user