[vlc-commits] vlc_gl_t: abstract OpenGL provider

Rémi Denis-Courmont git at videolan.org
Sat Feb 19 14:16:36 CET 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Feb 17 22:27:55 2011 +0200| [97a961bd136084cfbd49eab2b404f54d2e574d10] | committer: Rémi Denis-Courmont

vlc_gl_t: abstract OpenGL provider

This API is abstracted away from the video output. In a way, this goes
back to the previous opengl provider API, except that:
 - it is really independent of the video output,
 - it supports GL ES explicitly.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=97a961bd136084cfbd49eab2b404f54d2e574d10
---

 include/vlc_opengl.h      |   83 +++++++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am           |    2 +
 src/libvlccore.sym        |    2 +
 src/video_output/opengl.c |   83 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+), 0 deletions(-)

diff --git a/include/vlc_opengl.h b/include/vlc_opengl.h
new file mode 100644
index 0000000..6270bd5
--- /dev/null
+++ b/include/vlc_opengl.h
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * vlc_gl.h: VLC GL API
+ *****************************************************************************
+ * Copyright (C) 2009 Laurent Aimar
+ * Copyright (C) 2011 Rémi Denis-Courmont
+ *
+ * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_GL_H
+#define VLC_GL_H 1
+
+/**
+ * \file
+ * This file defines GL structures and functions.
+ */
+
+struct vout_window_t;
+
+/**
+ * A VLC GL context (and its underlying surface)
+ */
+typedef struct vlc_gl vlc_gl_t;
+
+struct vlc_gl
+{
+    VLC_COMMON_MEMBERS
+
+    struct vout_window_t *surface;
+    module_t *module;
+    void *sys;
+
+    int  (*makeCurrent)(vlc_gl_t *);
+    void (*swap)(vlc_gl_t *);
+    int  (*lock)(vlc_gl_t *);
+    void (*unlock)(vlc_gl_t *);
+};
+
+enum {
+    VLC_OPENGL,
+    VLC_OPENGL_ES,
+    VLC_OPENGL_ES2,
+};
+
+VLC_EXPORT( vlc_gl_t *, vlc_gl_Create, (struct vout_window_t *, unsigned, const char *) ) LIBVLC_USED;
+VLC_EXPORT( void, vlc_gl_Destroy, (vlc_gl_t *) );
+
+static inline int vlc_gl_MakeCurrent(vlc_gl_t *gl)
+{
+    return gl->makeCurrent(gl);
+}
+
+static inline int vlc_gl_Lock(vlc_gl_t *gl)
+{
+    return (gl->lock != NULL) ? gl->lock(gl) : VLC_SUCCESS;
+}
+
+static inline void vlc_gl_Unlock(vlc_gl_t *gl)
+{
+    if (gl->unlock != NULL)
+        gl->unlock(gl);
+}
+
+static inline void vlc_gl_Swap(vlc_gl_t *gl)
+{
+    gl->swap(gl);
+}
+
+#endif /* VLC_GL_H */
diff --git a/src/Makefile.am b/src/Makefile.am
index b07d41b..fff0177 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -71,6 +71,7 @@ pluginsinclude_HEADERS = \
 	../include/vlc_fourcc.h \
 	../include/vlc_fs.h \
 	../include/vlc_gcrypt.h \
+	../include/vlc_opengl.h \
 	../include/vlc_http.h \
 	../include/vlc_httpd.h \
 	../include/vlc_image.h \
@@ -393,6 +394,7 @@ SOURCES_libvlc_common = \
 	video_output/video_widgets.c \
 	video_output/vout_subpictures.c \
 	video_output/window.c \
+	video_output/opengl.c \
 	video_output/vout_intf.c \
 	video_output/vout_internal.h \
 	video_output/vout_control.h \
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 5231bb5..cb1b50c 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -627,6 +627,8 @@ vlc_epg_Delete
 vlc_epg_AddEvent
 vlc_epg_SetCurrent
 vlc_epg_Merge
+vlc_gl_Create
+vlc_gl_Destroy
 vlm_Control
 vlm_Delete
 vlm_ExecuteCommand
diff --git a/src/video_output/opengl.c b/src/video_output/opengl.c
new file mode 100644
index 0000000..4226284
--- /dev/null
+++ b/src/video_output/opengl.c
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * opengl.c: VLC GL API
+ *****************************************************************************
+ * Copyright (C) 2011 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <vlc_common.h>
+#include <vlc_opengl.h>
+#include "libvlc.h"
+#include <vlc_modules.h>
+
+#undef vlc_gl_Create
+/**
+ * Creates an OpenGL context (and its underlying surface).
+ *
+ * @note In most cases, you should vlc_gl_MakeCurrent() afterward.
+ *
+ * @param wnd window to use as OpenGL surface
+ * @param flags OpenGL context type
+ * @param name module name (or NULL for auto)
+ * @return a new context, or NULL on failure
+ */
+vlc_gl_t *vlc_gl_Create(struct vout_window_t *wnd, unsigned flags,
+                        const char *name)
+{
+    vlc_object_t *parent = (vlc_object_t *)wnd;
+    vlc_gl_t *gl;
+    const char *type;
+
+    switch (flags /*& VLC_OPENGL_API_MASK*/)
+    {
+        case VLC_OPENGL:
+            type = "opengl";
+            break;
+        case VLC_OPENGL_ES:
+            type = "opengl es";
+            break;
+        case VLC_OPENGL_ES2:
+            type = "opengl es2";
+            break;
+        default:
+            return NULL;
+    }
+
+    gl = vlc_custom_create(parent, sizeof (*gl), VLC_OBJECT_GENERIC, "gl");
+    if (unlikely(gl == NULL))
+        return NULL;
+    vlc_object_attach(gl, parent);
+
+    gl->surface = wnd;
+    gl->module = module_need(gl, type, name, true);
+    if (gl->module == NULL)
+    {
+        vlc_object_release(gl);
+        return NULL;
+    }
+
+    return gl;
+}
+
+void vlc_gl_Destroy(vlc_gl_t *gl)
+{
+    module_unneed(gl, gl->module);
+    vlc_object_release(gl);
+}



More information about the vlc-commits mailing list