summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>2015-11-26 10:14:45 +0100
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>2015-11-30 13:26:22 +0100
commit03fed576f0d9076d064cd2022099a6cb67df7c7b (patch)
treeface717f8ccd9df56bd729f779cb7fb6509f2fc5
parentd7bd0a4c103db08a20368975eafd397b3fab6a9f (diff)
downloadgst-vaapi-03fed576f0d9076d064cd2022099a6cb67df7c7b.tar.gz
libs: add gl_get_current_api()
In order to know which OpenGL API use, we must detect the API type of current context. This patch adds the function gl_get_current_api() which returns the OpenGL API type. This function is an adaptation of gst_gl_context_get_current_gl_api() from GstGL. Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com> https://bugzilla.gnome.org/show_bug.cgi?id=753099
-rw-r--r--gst-libs/gst/vaapi/gstvaapiutils_glx.c89
-rw-r--r--gst-libs/gst/vaapi/gstvaapiutils_glx.h14
2 files changed, 103 insertions, 0 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.c b/gst-libs/gst/vaapi/gstvaapiutils_glx.c
index b21cb6c9..974d3a03 100644
--- a/gst-libs/gst/vaapi/gstvaapiutils_glx.c
+++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.c
@@ -1087,3 +1087,92 @@ gl_unbind_framebuffer_object (GLFramebufferObject * fbo)
fbo->is_bound = FALSE;
return TRUE;
}
+
+/**
+ * gl_get_current_api:
+ * @major: (out): (allow-none): the GL major version
+ * @minor: (out): (allow-none): the GL minor version
+ *
+ * If an error occurs, @major and @minor aren't modified and
+ * %GST_VAAPI_GL_API_NONE is returned.
+ *
+ * This is an adaptation of gst_gl_context_get_current_gl_api() from GstGL.
+ *
+ * Returns: The version supported by the OpenGL context current in the calling
+ * thread or %GST_VAAPI_GL_API_NONE
+ */
+GstVaapiGLApi
+gl_get_current_api (guint * major, guint * minor)
+{
+ const gchar *version;
+ gint maj, min, n;
+ GstVaapiGLApi ret = (1 << 31);
+
+ while (ret != GST_VAAPI_GL_API_NONE) {
+ version = (const gchar *) glGetString (GL_VERSION);
+ if (!version)
+ goto next;
+
+ /* strlen (x.x) == 3 */
+ n = strlen (version);
+ if (n < 3)
+ goto next;
+
+ if (g_strstr_len (version, 9, "OpenGL ES")) {
+ /* strlen (OpenGL ES x.x) == 13 */
+ if (n < 13)
+ goto next;
+
+ sscanf (&version[10], "%d.%d", &maj, &min);
+
+ if (maj <= 0 || min < 0)
+ goto next;
+
+ if (maj == 1) {
+ ret = GST_VAAPI_GL_API_GLES1;
+ break;
+ } else if (maj == 2 || maj == 3) {
+ ret = GST_VAAPI_GL_API_GLES2;
+ break;
+ }
+
+ goto next;
+ } else {
+ sscanf (version, "%d.%d", &maj, &min);
+
+ if (maj <= 0 || min < 0)
+ goto next;
+
+ if (maj > 3 || (maj == 3 && min > 1)) {
+ GLuint context_flags = 0;
+
+ ret = GST_VAAPI_GL_API_NONE;
+ if (!gl_get_param (GL_CONTEXT_PROFILE_MASK, &context_flags))
+ break;
+
+ if (context_flags & GL_CONTEXT_CORE_PROFILE_BIT)
+ ret |= GST_VAAPI_GL_API_OPENGL3;
+ if (context_flags & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
+ ret |= GST_VAAPI_GL_API_OPENGL;
+ break;
+ }
+
+ ret = GST_VAAPI_GL_API_OPENGL;
+ break;
+ }
+
+ next:
+ /* iterate through the apis */
+ ret >>= 1;
+ }
+
+ if (ret == GST_VAAPI_GL_API_NONE)
+ return GST_VAAPI_GL_API_NONE;
+
+ if (major)
+ *major = maj;
+ if (minor)
+ *minor = min;
+
+ return ret;
+}
diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.h b/gst-libs/gst/vaapi/gstvaapiutils_glx.h
index d78b3ee7..42e047f5 100644
--- a/gst-libs/gst/vaapi/gstvaapiutils_glx.h
+++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.h
@@ -210,4 +210,18 @@ G_GNUC_INTERNAL
gboolean
gl_unbind_framebuffer_object (GLFramebufferObject * fbo);
+typedef enum {
+ GST_VAAPI_GL_API_NONE = 0,
+ GST_VAAPI_GL_API_OPENGL = (1 << 0),
+ GST_VAAPI_GL_API_OPENGL3 = (1 << 1),
+ GST_VAAPI_GL_API_GLES1 = (1 << 15),
+ GST_VAAPI_GL_API_GLES2 = (1 << 16),
+
+ GST_VAAPI_GL_API_ANY = G_MAXUINT32
+} GstVaapiGLApi;
+
+G_GNUC_INTERNAL
+GstVaapiGLApi
+gl_get_current_api (guint * major, guint * minor);
+
#endif /* GST_VAAPI_UTILS_GLX_H */