[cogl/wip/expose-glx-egl-context: 3/3] Expose EGL context/display and GLX context



commit ab69f39d12b98fe0dc78ab925967648ac2ddc959
Author: Robert Bragg <robert linux intel com>
Date:   Wed Mar 5 01:25:50 2014 +0000

    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 two new top-level headers <cogl/cogl-egl.h> and
    <cogl/cogl-glx.h> that need to be included explicitly to access these
    apis.
    
    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

 cogl/Makefile.am                  |    4 +-
 cogl/cogl-context.c               |   13 ----
 cogl/cogl-egl.h                   |  118 +++++++++++++++++++++++++++++++++++++
 cogl/cogl-glx.h                   |   95 +++++++++++++++++++++++++++++
 cogl/cogl.symbols                 |    5 ++
 cogl/winsys/cogl-winsys-egl.c     |   27 +++++---
 cogl/winsys/cogl-winsys-glx.c     |    9 +++
 cogl/winsys/cogl-winsys-private.h |    5 --
 8 files changed, 247 insertions(+), 29 deletions(-)
---
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index ca9e645..9bc94c1 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -389,6 +389,7 @@ cogl_sources_c += \
        $(srcdir)/winsys/cogl-texture-pixmap-x11-private.h
 endif
 if SUPPORT_GLX
+cogl_public_h += $(srcdir)/cogl-glx.h
 cogl_sources_c += \
        $(srcdir)/cogl-glx-renderer-private.h \
        $(srcdir)/cogl-glx-display-private.h \
@@ -447,6 +448,7 @@ cogl_sources_c += \
        $(srcdir)/winsys/cogl-winsys-egl-android-private.h
 endif
 if SUPPORT_EGL
+cogl_public_h += $(srcdir)/cogl-egl.h
 cogl_nodist_experimental_h += \
        $(builddir)/cogl-egl-defines.h
 
@@ -618,7 +620,7 @@ if UNIT_TESTS
 Cogl_2_0_gir_LIBS += $(top_builddir)/test-fixtures/libtest-fixtures.la
 endif
 Cogl_2_0_gir_FILES = $(cogl_public_h) cogl-enum-types.h
-Cogl_2_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__
+Cogl_2_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__
 Cogl_2_0_gir_INCLUDES = GL-1.0 GObject-2.0
 Cogl_2_0_gir_EXPORT_PACKAGES = cogl2
 Cogl_2_0_gir_SCANNERFLAGS = --warn-all --c-include='cogl/cogl.h'
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index f2d1696..8941cff 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -555,19 +555,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)
diff --git a/cogl/cogl-egl.h b/cogl/cogl-egl.h
new file mode 100644
index 0000000..11bfffb
--- /dev/null
+++ b/cogl/cogl-egl.h
@@ -0,0 +1,118 @@
+/*
+ * 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_EGL_H__
+#define __COGL_EGL_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_EGL_H_INSIDE__ */
+#ifndef __COGL_EGL_H_INSIDE__
+#define __COGL_EGL_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 <cogl/cogl-egl-defines.h>
+#include <cogl/cogl-types.h>
+
+COGL_BEGIN_DECLS
+
+/**
+ * cogl_egl_context_get_egl_display:
+ * @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 EGLDisplay
+ * 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.8
+ * Stability: unstable
+ */
+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
+ * 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_EGL_H_INSIDE__
+#undef __COGL_MUST_UNDEF_COGL_H_INSIDE__
+#endif
+
+#endif /* __COGL_EGL_H__ */
diff --git a/cogl/cogl-glx.h b/cogl/cogl-glx.h
new file mode 100644
index 0000000..b3c6480
--- /dev/null
+++ b/cogl/cogl-glx.h
@@ -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 GLXDisplay handle.
+ * Since: 1.8
+ * 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__ */
diff --git a/cogl/cogl.symbols b/cogl/cogl.symbols
index c7039f4..fd1cc48 100644
--- a/cogl/cogl.symbols
+++ b/cogl/cogl.symbols
@@ -135,6 +135,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
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index e336bfb..64a35ae 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -46,6 +46,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"
 
@@ -851,14 +852,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)
 {
@@ -965,8 +958,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,
@@ -1065,3 +1056,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;
+}
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index d59f3dc..8f1a52a 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -57,6 +57,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>
@@ -2688,3 +2689,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;
+}
diff --git a/cogl/winsys/cogl-winsys-private.h b/cogl/winsys/cogl-winsys-private.h
index 72dc615..268463a 100644
--- a/cogl/winsys/cogl-winsys-private.h
+++ b/cogl/winsys/cogl-winsys-private.h
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]