Expose EGL context/display and GLX context

To help facilitate integration with third party frameworks this exposes
the EGL context and display to applications as well as the GLX context.
(Note that the GLX display is already available via
cogl_xlib_renderer_get_display())

This adds a new top-level <cogl/cogl-glx.h> header that needs to be
included explicitly to access the glx specific api.

Anyone using these apis will be responsible for checking that Cogl
is indeed using EGL or GLX by calling cogl_renderer_get_winsys_id()

This will enable GStreamer, for example, to be able to create a GL
context that shares resources with Cogl's context.

https://bugzilla.gnome.org/show_bug.cgi?id=724992

Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2014-03-05 01:25:50 +00:00 committed by Robert Bragg
parent 081acdc146
commit 804082abd3
8 changed files with 148 additions and 29 deletions

View File

@ -435,6 +435,7 @@ cogl_sources_c += \
$(srcdir)/winsys/cogl-texture-pixmap-x11-private.h
endif
if SUPPORT_GLX
cogl_experimental_h += $(srcdir)/cogl-glx.h
cogl_sources_c += \
$(srcdir)/cogl-glx-renderer-private.h \
$(srcdir)/cogl-glx-display-private.h \
@ -667,7 +668,7 @@ if UNIT_TESTS
Cogl_1_0_gir_LIBS += $(top_builddir)/test-fixtures/libtest-fixtures.la
endif
Cogl_1_0_gir_FILES = $(cogl_1_public_h) cogl-enum-types.h
Cogl_1_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_DEP_CFLAGS) -UCOGL_ENABLE_EXPERIMENTAL_API -UCOGL_ENABLE_EXPERIMENTAL_2_0_API -UCOGL_COMPILATION -D__COGL_H_INSIDE__ -D__COGL_XLIB_H_INSIDE__ -D__COGL_EGL_H_INSIDE__ -DCOGL_GIR_SCANNING
Cogl_1_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_DEP_CFLAGS) -UCOGL_ENABLE_EXPERIMENTAL_API -UCOGL_ENABLE_EXPERIMENTAL_2_0_API -UCOGL_COMPILATION -D__COGL_H_INSIDE__ -D__COGL_XLIB_H_INSIDE__ -D__COGL_EGL_H_INSIDE__ -D__COGL_GLX_H_INSIDE__ -DCOGL_GIR_SCANNING
Cogl_1_0_gir_INCLUDES = GL-1.0 GObject-2.0
Cogl_1_0_gir_EXPORT_PACKAGES = cogl-1.0
Cogl_1_0_gir_SCANNERFLAGS = --warn-all --c-include='cogl/cogl.h'

View File

@ -639,19 +639,6 @@ cogl_context_get_renderer (CoglContext *context)
return context->display->renderer;
}
#ifdef COGL_HAS_EGL_SUPPORT
EGLDisplay
cogl_egl_context_get_egl_display (CoglContext *context)
{
const CoglWinsysVtable *winsys = _cogl_context_get_winsys (context);
/* This should only be called for EGL contexts */
_COGL_RETURN_VAL_IF_FAIL (winsys->context_egl_get_egl_display != NULL, NULL);
return winsys->context_egl_get_egl_display (context);
}
#endif
CoglBool
_cogl_context_update_features (CoglContext *context,
CoglError **error)

View File

@ -79,6 +79,26 @@ COGL_BEGIN_DECLS
EGLDisplay
cogl_egl_context_get_egl_display (CoglContext *context);
/**
* cogl_egl_context_get_egl_context:
* @context: A #CoglContext pointer
*
* If you have done a runtime check to determine that Cogl is using
* EGL internally then this API can be used to retrieve the EGLContext
* handle that was setup internally. The result is undefined if Cogl
* is not using EGL.
*
* Note: The current window system backend can be checked using
* cogl_renderer_get_winsys_id().
*
* Return value: The internally setup EGLDisplay handle.
* Since: 1.18
* Stability: unstable
*/
EGLContext
cogl_egl_context_get_egl_context (CoglContext *context);
COGL_END_DECLS
/* The gobject introspection scanner seems to parse public headers in

95
cogl/cogl-glx.h Normal file
View File

@ -0,0 +1,95 @@
/*
* Cogl
*
* A Low-Level GPU Graphics and Utilities API
*
* Copyright (C) 2014 Intel Corporation.
*
* 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_GLX_H__
#define __COGL_GLX_H__
/* NB: this is a top-level header that can be included directly but we
* want to be careful not to define __COGL_H_INSIDE__ when this is
* included internally while building Cogl itself since
* __COGL_H_INSIDE__ is used in headers to guard public vs private api
* definitions
*/
#ifndef COGL_COMPILATION
/* Note: When building Cogl .gir we explicitly define
* __COGL_GLX_H_INSIDE__ */
#ifndef __COGL_GLX_H_INSIDE__
#define __COGL_GLX_H_INSIDE__
#endif
/* Note: When building Cogl .gir we explicitly define
* __COGL_H_INSIDE__ */
#ifndef __COGL_H_INSIDE__
#define __COGL_H_INSIDE__
#define __COGL_MUST_UNDEF_COGL_H_INSIDE__
#endif
#endif /* COGL_COMPILATION */
#include <GL/glx.h>
#include <cogl/cogl-types.h>
COGL_BEGIN_DECLS
/**
* cogl_glx_context_get_glx_context:
* @context: A #CoglContext pointer
*
* If you have done a runtime check to determine that Cogl is using
* GLX internally then this API can be used to retrieve the GLXContext
* handle that was setup internally. The result is undefined if Cogl
* is not using GLX.
*
* Return value: The internally setup GLXContext handle.
* Since: 1.18
* Stability: unstable
*/
GLXContext
cogl_glx_context_get_glx_context (CoglContext *context);
COGL_END_DECLS
/* The gobject introspection scanner seems to parse public headers in
* isolation which means we need to be extra careful about how we
* define and undefine __COGL_H_INSIDE__ used to detect when internal
* headers are incorrectly included by developers. In the gobject
* introspection case we have to manually define __COGL_H_INSIDE__ as
* a commandline argument for the scanner which means we must be
* careful not to undefine it in a header...
*/
#ifdef __COGL_MUST_UNDEF_COGL_H_INSIDE__
#undef __COGL_H_INSIDE__
#undef __COGL_GLX_H_INSIDE__
#undef __COGL_MUST_UNDEF_COGL_H_INSIDE__
#endif
#endif /* __COGL_GLX_H__ */

View File

@ -164,6 +164,11 @@ cogl_color_unpremultiply
#ifdef COGL_HAS_EGL_SUPPORT
cogl_egl_context_get_egl_display
cogl_egl_context_get_egl_context
#endif
#ifdef COGL_HAS_GLX_SUPPORT
cogl_glx_context_get_glx_context
#endif
cogl_context_get_display

View File

@ -47,6 +47,7 @@
#include "cogl-onscreen-template-private.h"
#include "cogl-gles2-context-private.h"
#include "cogl-error-private.h"
#include "cogl-egl.h"
#include "cogl-private.h"
@ -860,14 +861,6 @@ _cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
_cogl_winsys_onscreen_bind (onscreen);
}
static EGLDisplay
_cogl_winsys_context_egl_get_egl_display (CoglContext *context)
{
CoglRendererEGL *egl_renderer = context->display->renderer->winsys;
return egl_renderer->edpy;
}
static void
_cogl_winsys_save_context (CoglContext *ctx)
{
@ -974,8 +967,6 @@ static CoglWinsysVtable _cogl_winsys_vtable =
.display_destroy = _cogl_winsys_display_destroy,
.context_init = _cogl_winsys_context_init,
.context_deinit = _cogl_winsys_context_deinit,
.context_egl_get_egl_display =
_cogl_winsys_context_egl_get_egl_display,
.context_create_gles2_context =
_cogl_winsys_context_create_gles2_context,
.destroy_gles2_context = _cogl_winsys_destroy_gles2_context,
@ -1074,3 +1065,19 @@ _cogl_egl_query_wayland_buffer (CoglContext *ctx,
value);
}
#endif
EGLDisplay
cogl_egl_context_get_egl_display (CoglContext *context)
{
CoglRendererEGL *egl_renderer = context->display->renderer->winsys;
return egl_renderer->edpy;
}
EGLContext
cogl_egl_context_get_egl_context (CoglContext *context)
{
CoglDisplayEGL *egl_display = context->display->winsys;
return egl_display->egl_context;
}

View File

@ -59,6 +59,7 @@
#include "cogl-error-private.h"
#include "cogl-poll-private.h"
#include "cogl-version.h"
#include "cogl-glx.h"
#include <stdlib.h>
#include <sys/types.h>
@ -2707,3 +2708,11 @@ _cogl_winsys_glx_get_vtable (void)
{
return &_cogl_winsys_vtable;
}
GLXContext
cogl_glx_context_get_glx_context (CoglContext *context)
{
CoglGLXDisplay *glx_display = context->display->winsys;
return glx_display->glx_context;
}

View File

@ -145,11 +145,6 @@ typedef struct _CoglWinsysVtable
int
(*onscreen_get_buffer_age) (CoglOnscreen *onscreen);
#ifdef COGL_HAS_EGL_SUPPORT
EGLDisplay
(*context_egl_get_egl_display) (CoglContext *context);
#endif
#ifdef COGL_HAS_XLIB_SUPPORT
XVisualInfo *
(*xlib_get_visual_info) (void);