diff --git a/cogl/cogl/cogl-mutter.h b/cogl/cogl/cogl-mutter.h new file mode 100644 index 000000000..21ef0745d --- /dev/null +++ b/cogl/cogl/cogl-mutter.h @@ -0,0 +1,42 @@ +/* + * Cogl + * + * A Low Level GPU Graphics and Utilities API + * + * Copyright (C) 2016 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * + */ + +#ifndef __COGL_MUTTER_H___ +#define __COGL_MUTTER_H___ + +#include +#include + +typedef const CoglWinsysVtable *(*CoglWinsysVtableGetter) (void); + +void cogl_renderer_set_custom_winsys (CoglRenderer *renderer, + CoglWinsysVtableGetter winsys_vtable_getter); + +#endif /* __COGL_MUTTER_H___ */ diff --git a/cogl/cogl/cogl-renderer-private.h b/cogl/cogl/cogl-renderer-private.h index 06aa21320..81d956fde 100644 --- a/cogl/cogl/cogl-renderer-private.h +++ b/cogl/cogl/cogl-renderer-private.h @@ -39,6 +39,7 @@ #include "cogl-texture-driver.h" #include "cogl-context.h" #include "cogl-closure-list-private.h" +#include "cogl-mutter.h" #ifdef COGL_HAS_XLIB_SUPPORT #include @@ -52,6 +53,7 @@ struct _CoglRenderer const CoglDriverVtable *driver_vtable; const CoglTextureDriver *texture_driver; const CoglWinsysVtable *winsys_vtable; + CoglWinsysVtableGetter custom_winsys_vtable_getter; CoglWinsysID winsys_id_override; GList *constraints; diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c index 498a00ff4..da2f41195 100644 --- a/cogl/cogl/cogl-renderer.c +++ b/cogl/cogl/cogl-renderer.c @@ -41,6 +41,7 @@ #include "cogl-object.h" #include "cogl-context-private.h" #include "cogl-util-gl-private.h" +#include "cogl-mutter.h" #include "cogl-renderer.h" #include "cogl-renderer-private.h" @@ -65,8 +66,6 @@ #include "cogl-xlib-renderer.h" #endif -typedef const CoglWinsysVtable *(*CoglWinsysVtableGetter) (void); - #ifdef HAVE_COGL_GL extern const CoglTextureDriver _cogl_texture_driver_gl; extern const CoglDriverVtable _cogl_driver_gl; @@ -564,6 +563,46 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer, /* Final connection API */ +void +cogl_renderer_set_custom_winsys (CoglRenderer *renderer, + CoglWinsysVtableGetter winsys_vtable_getter) +{ + renderer->custom_winsys_vtable_getter = winsys_vtable_getter; +} + +static CoglBool +connect_custom_winsys (CoglRenderer *renderer, + CoglError **error) +{ + const CoglWinsysVtable *winsys = renderer->custom_winsys_vtable_getter(); + CoglError *tmp_error = NULL; + GString *error_message; + + renderer->winsys_vtable = winsys; + + error_message = g_string_new (""); + if (!winsys->renderer_connect (renderer, &tmp_error)) + { + g_string_append_c (error_message, '\n'); + g_string_append (error_message, tmp_error->message); + cogl_error_free (tmp_error); + } + else + { + renderer->connected = TRUE; + g_string_free (error_message, TRUE); + return TRUE; + } + + renderer->winsys_vtable = NULL; + _cogl_set_error (error, COGL_WINSYS_ERROR, + COGL_WINSYS_ERROR_INIT, + "Failed to connected to any renderer: %s", + error_message->str); + g_string_free (error_message, TRUE); + return FALSE; +} + CoglBool cogl_renderer_connect (CoglRenderer *renderer, CoglError **error) { @@ -580,6 +619,9 @@ cogl_renderer_connect (CoglRenderer *renderer, CoglError **error) if (!_cogl_renderer_choose_driver (renderer, error)) return FALSE; + if (renderer->custom_winsys_vtable_getter) + return connect_custom_winsys (renderer, error); + error_message = g_string_new (""); for (i = 0; i < G_N_ELEMENTS (_cogl_winsys_vtable_getters); i++) { diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h index 7fa392137..778fdda5a 100644 --- a/cogl/cogl/cogl.h +++ b/cogl/cogl/cogl.h @@ -96,6 +96,10 @@ #include #include +#ifdef COGL_ENABLE_MUTTER_API +#include +#endif + /* * 2.0 api that's compatible with the 1.x api... */