mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 20:51:13 +00:00
[637/906] x11_egl: add prelim support for choosing opengl or gles
This commit is contained in:
parent
59cb56fa4d
commit
87e5cd6777
2 changed files with 96 additions and 24 deletions
|
@ -107,28 +107,58 @@ gst_gl_window_x11_egl_choose_format (GstGLWindowX11 * window_x11,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_gl_window_x11_egl_choose_config (GstGLWindowX11EGL * window_egl,
|
||||||
|
GError ** error)
|
||||||
|
{
|
||||||
|
EGLint numConfigs;
|
||||||
|
gint i = 0;
|
||||||
|
EGLint config_attrib[20];
|
||||||
|
|
||||||
|
config_attrib[i++] = EGL_SURFACE_TYPE;
|
||||||
|
config_attrib[i++] = EGL_WINDOW_BIT;
|
||||||
|
config_attrib[i++] = EGL_RENDERABLE_TYPE;
|
||||||
|
if (window_egl->gl_api & GST_GL_API_GLES2)
|
||||||
|
config_attrib[i++] = EGL_OPENGL_ES2_BIT;
|
||||||
|
else
|
||||||
|
config_attrib[i++] = EGL_OPENGL_BIT;
|
||||||
|
config_attrib[i++] = EGL_DEPTH_SIZE;
|
||||||
|
config_attrib[i++] = 16;
|
||||||
|
config_attrib[i++] = EGL_NONE;
|
||||||
|
|
||||||
|
if (eglChooseConfig (window_egl->egl_display, config_attrib,
|
||||||
|
&window_egl->egl_config, 1, &numConfigs))
|
||||||
|
GST_INFO ("config set: %ld, %ld", (gulong) window_egl->egl_config,
|
||||||
|
(gulong) numConfigs);
|
||||||
|
else {
|
||||||
|
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_CONFIG,
|
||||||
|
"Failed to set window configuration: %s", X11EGLErrorString ());
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
failure:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_gl_window_x11_egl_create_context (GstGLWindowX11 * window_x11,
|
gst_gl_window_x11_egl_create_context (GstGLWindowX11 * window_x11,
|
||||||
GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
|
GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
|
||||||
{
|
{
|
||||||
GstGLWindowX11EGL *window_egl;
|
GstGLWindowX11EGL *window_egl;
|
||||||
|
|
||||||
EGLint config_attrib[] = {
|
gint i = 0;
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
EGLint context_attrib[3];
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
||||||
EGL_DEPTH_SIZE, 16,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
EGLint context_attrib[] = {
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
EGLint majorVersion;
|
EGLint majorVersion;
|
||||||
EGLint minorVersion;
|
EGLint minorVersion;
|
||||||
EGLint numConfigs;
|
|
||||||
EGLConfig config;
|
if ((gl_api & GST_GL_API_OPENGL) == GST_GL_API_NONE &&
|
||||||
|
(gl_api & GST_GL_API_GLES2) == GST_GL_API_NONE) {
|
||||||
|
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_API,
|
||||||
|
"xEGL supports opengl or gles2");
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
window_egl = GST_GL_WINDOW_X11_EGL (window_x11);
|
window_egl = GST_GL_WINDOW_X11_EGL (window_x11);
|
||||||
|
|
||||||
|
@ -144,17 +174,47 @@ gst_gl_window_x11_egl_create_context (GstGLWindowX11 * window_x11,
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eglChooseConfig (window_egl->egl_display, config_attrib, &config, 1,
|
if (gl_api & GST_GL_API_OPENGL) {
|
||||||
&numConfigs))
|
/* egl + opengl only available with EGL 1.4+ */
|
||||||
GST_INFO ("config set: %ld, %ld", (gulong) config, (gulong) numConfigs);
|
if (majorVersion == 1 && minorVersion <= 3) {
|
||||||
else {
|
if ((gl_api & ~GST_GL_API_OPENGL) == GST_GL_API_NONE) {
|
||||||
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_CONFIG,
|
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_OLD_LIBS,
|
||||||
"Failed to set window configuration: %s", X11EGLErrorString ());
|
"EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)",
|
||||||
goto failure;
|
majorVersion, minorVersion);
|
||||||
|
goto failure;
|
||||||
|
} else {
|
||||||
|
GST_WARNING
|
||||||
|
("EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)",
|
||||||
|
majorVersion, minorVersion);
|
||||||
|
if (gl_api & GST_GL_API_GLES2)
|
||||||
|
goto try_gles2;
|
||||||
|
else
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!eglBindAPI (EGL_OPENGL_API)) {
|
||||||
|
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_FAILED,
|
||||||
|
"Failed to bind OpenGL|ES API: %s", X11EGLErrorString ());
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
window_egl->gl_api = GST_GL_API_OPENGL;
|
||||||
|
} else if (gl_api & GST_GL_API_GLES2) {
|
||||||
|
try_gles2:
|
||||||
|
if (!eglBindAPI (EGL_OPENGL_ES_API)) {
|
||||||
|
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_FAILED,
|
||||||
|
"Failed to bind OpenGL|ES API: %s", X11EGLErrorString ());
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
window_egl->gl_api = GST_GL_API_GLES2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_gl_window_x11_egl_choose_config (window_egl, error);
|
||||||
|
|
||||||
window_egl->egl_surface =
|
window_egl->egl_surface =
|
||||||
eglCreateWindowSurface (window_egl->egl_display, config,
|
eglCreateWindowSurface (window_egl->egl_display, window_egl->egl_config,
|
||||||
(EGLNativeWindowType) window_x11->internal_win_id, NULL);
|
(EGLNativeWindowType) window_x11->internal_win_id, NULL);
|
||||||
if (window_egl->egl_surface != EGL_NO_SURFACE)
|
if (window_egl->egl_surface != EGL_NO_SURFACE)
|
||||||
GST_INFO ("surface created");
|
GST_INFO ("surface created");
|
||||||
|
@ -166,8 +226,14 @@ gst_gl_window_x11_egl_create_context (GstGLWindowX11 * window_x11,
|
||||||
|
|
||||||
GST_DEBUG ("about to create gl context\n");
|
GST_DEBUG ("about to create gl context\n");
|
||||||
|
|
||||||
|
if (window_egl->gl_api & GST_GL_API_GLES2) {
|
||||||
|
context_attrib[i++] = EGL_CONTEXT_CLIENT_VERSION;
|
||||||
|
context_attrib[i++] = 2;
|
||||||
|
}
|
||||||
|
context_attrib[i++] = EGL_NONE;
|
||||||
|
|
||||||
window_egl->egl_context =
|
window_egl->egl_context =
|
||||||
eglCreateContext (window_egl->egl_display, config,
|
eglCreateContext (window_egl->egl_display, window_egl->egl_config,
|
||||||
(EGLContext) external_gl_context, context_attrib);
|
(EGLContext) external_gl_context, context_attrib);
|
||||||
|
|
||||||
if (window_egl->egl_context != EGL_NO_CONTEXT)
|
if (window_egl->egl_context != EGL_NO_CONTEXT)
|
||||||
|
@ -233,7 +299,10 @@ gst_gl_window_x11_egl_swap_buffers (GstGLWindowX11 * window_x11)
|
||||||
GstGLAPI
|
GstGLAPI
|
||||||
gst_gl_window_x11_egl_get_gl_api (GstGLWindow * window)
|
gst_gl_window_x11_egl_get_gl_api (GstGLWindow * window)
|
||||||
{
|
{
|
||||||
return GST_GL_API_GLES2;
|
GstGLWindowX11EGL *window_egl = GST_GL_WINDOW_X11_EGL (window);
|
||||||
|
|
||||||
|
return window_egl->gl_api ? window_egl->
|
||||||
|
gl_api : GST_GL_API_GLES2 | GST_GL_API_OPENGL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
|
|
|
@ -44,6 +44,9 @@ struct _GstGLWindowX11EGL {
|
||||||
EGLContext egl_context;
|
EGLContext egl_context;
|
||||||
EGLDisplay egl_display;
|
EGLDisplay egl_display;
|
||||||
EGLSurface egl_surface;
|
EGLSurface egl_surface;
|
||||||
|
EGLConfig egl_config;
|
||||||
|
|
||||||
|
GstGLAPI gl_api;
|
||||||
|
|
||||||
gpointer _reserved[GST_PADDING];
|
gpointer _reserved[GST_PADDING];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue