renderer: Expose winsys ID setter/getters

This adds API to let you override the choice of Cogl's winsys backend.
Previously it was only possible to override the winsys using the
COGL_RENDERER environment variable, but it's useful for something like
Clutter to be able to control the winsys via API without needing
environment variable tricks. This also adds API to query back the
winsys chosen by Cogl, in case you don't set an explicit override.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2011-06-20 13:29:12 +01:00
parent c4eb869bd7
commit b3a105c576
8 changed files with 92 additions and 3 deletions

View File

@ -40,6 +40,7 @@ struct _CoglRenderer
CoglObject _parent;
gboolean connected;
const CoglWinsysVtable *winsys_vtable;
CoglWinsysID winsys_id_override;
#ifdef COGL_HAS_XLIB_SUPPORT
Display *foreign_xdpy;
#endif

View File

@ -172,7 +172,6 @@ gboolean
cogl_renderer_connect (CoglRenderer *renderer, GError **error)
{
int i;
char *renderer_name = getenv ("COGL_RENDERER");
GString *error_message;
if (renderer->connected)
@ -184,8 +183,17 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
const CoglWinsysVtable *winsys = _cogl_winsys_vtable_getters[i]();
GError *tmp_error = NULL;
if (renderer_name && strcmp (winsys->name, renderer_name) != 0)
continue;
if (renderer->winsys_id_override != COGL_WINSYS_ID_ANY)
{
if (renderer->winsys_id_override != winsys->id)
continue;
}
else
{
char *user_choice = getenv ("COGL_RENDERER");
if (user_choice && strcmp (winsys->name, user_choice) != 0)
continue;
}
/* At least temporarily we will associate this winsys with
* the renderer in-case ->renderer_connect calls API that
@ -282,3 +290,20 @@ cogl_renderer_remove_native_filter (CoglRenderer *renderer,
}
}
}
void
cogl_renderer_set_winsys_id (CoglRenderer *renderer,
CoglWinsysID winsys_id)
{
g_return_if_fail (!renderer->connected);
renderer->winsys_id_override = winsys_id;
}
CoglWinsysID
cogl_renderer_get_winsys_id (CoglRenderer *renderer)
{
g_return_val_if_fail (renderer->connected, 0);
return renderer->winsys_vtable->id;
}

View File

@ -67,6 +67,61 @@ cogl_renderer_new (void);
/* optional configuration APIs */
/**
* CoglWinsysID:
* @COGL_WINSYS_ID_ANY: Implies no preference for which backend is used
* @COGL_WINSYS_ID_STUB: Use the no-op stub backend
* @COGL_WINSYS_ID_GLX: Use the GLX window system binding API
* @COGL_WINSYS_ID_EGL: Use the Khronos EGL window system binding API
* @COGL_WINSYS_ID_WGL: Use the Microsoft Windows WGL binding API
*
* Identifies specific window system backends that Cogl supports.
*
* These can be used to query what backend Cogl is using or to try and
* explicitly select a backend to use.
*/
typedef enum
{
COGL_WINSYS_ID_ANY,
COGL_WINSYS_ID_STUB,
COGL_WINSYS_ID_GLX,
COGL_WINSYS_ID_EGL,
COGL_WINSYS_ID_WGL
} CoglWinsysID;
/**
* cogl_renderer_set_winsys_id:
* @renderer: A #CoglRenderer
* @winsys_id: An ID of the winsys you explicitly want to use.
*
* This allows you to explicitly select a winsys backend to use instead
* of letting Cogl automatically select a backend.
*
* if you select an unsupported backend then cogl_renderer_connect()
* will fail and report an error.
*
* This may only be called on an un-connected #CoglRenderer.
*/
#define cogl_renderer_set_winsys_id cogl_renderer_set_winsys_id_EXP
void
cogl_renderer_set_winsys_id (CoglRenderer *renderer,
CoglWinsysID winsys_id);
/**
* cogl_renderer_get_winsys_id:
* @renderer: A #CoglRenderer
*
* Queries which window system backend Cogl has chosen to use.
*
* This may only be called on a connected #CoglRenderer.
*
* Returns: The #CoglWinsysID corresponding to the chosen window
* system backend.
*/
#define cogl_renderer_get_winsys_id cogl_renderer_get_winsys_id_EXP
CoglWinsysID
cogl_renderer_get_winsys_id (CoglRenderer *renderer);
#define cogl_renderer_handle_native_event cogl_renderer_handle_native_event_EXP
/*
* cogl_renderer_handle_native_event:

View File

@ -1646,6 +1646,7 @@ _cogl_winsys_texture_pixmap_x11_get_texture (CoglTexturePixmapX11 *tex_pixmap)
static CoglWinsysVtable _cogl_winsys_vtable =
{
.id = COGL_WINSYS_ID_EGL,
.name = "EGL",
.get_proc_address = _cogl_winsys_get_proc_address,
.renderer_connect = _cogl_winsys_renderer_connect,

View File

@ -1895,6 +1895,7 @@ _cogl_winsys_texture_pixmap_x11_get_texture (CoglTexturePixmapX11 *tex_pixmap)
static CoglWinsysVtable _cogl_winsys_vtable =
{
.id = COGL_WINSYS_ID_GLX,
.name = "GLX",
.get_proc_address = _cogl_winsys_get_proc_address,
.renderer_connect = _cogl_winsys_renderer_connect,

View File

@ -24,6 +24,8 @@
#ifndef __COGL_WINSYS_PRIVATE_H
#define __COGL_WINSYS_PRIVATE_H
#include "cogl-renderer.h"
#include "cogl-framebuffer-private.h"
#ifdef COGL_HAS_XLIB_SUPPORT
#include "cogl-texture-pixmap-x11-private.h"
@ -54,6 +56,8 @@ typedef enum
typedef struct _CoglWinsysVtable
{
CoglWinsysID id;
const char *name;
/* Required functions */

View File

@ -134,6 +134,7 @@ _cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
static CoglWinsysVtable _cogl_winsys_vtable =
{
.id = COGL_WINSYS_ID_STUB,
.name = "STUB",
.get_proc_address = _cogl_winsys_get_proc_address,
.renderer_connect = _cogl_winsys_renderer_connect,

View File

@ -827,6 +827,7 @@ _cogl_winsys_wgl_get_vtable (void)
{
memset (&vtable, 0, sizeof (vtable));
vtable.id = COGL_WINSYS_ID_EGL;
vtable.name = "WGL";
vtable.get_proc_address = _cogl_winsys_get_proc_address;
vtable.renderer_connect = _cogl_winsys_renderer_connect;