[615/906] preliminary support for Win32 EGL

This commit is contained in:
Matthew Waters 2012-11-19 21:52:22 +11:00 committed by Tim-Philipp Müller
parent d378a9d1d9
commit cc1f734857
3 changed files with 342 additions and 0 deletions

View file

@ -25,7 +25,12 @@
#include "gstglwindow_win32.h" #include "gstglwindow_win32.h"
#if HAVE_WGL
#include "gstglwindow_win32_wgl.h" #include "gstglwindow_win32_wgl.h"
#endif
#if HAVE_EGL
#include "gstglwindow_win32_egl.h"
#endif
#define WM_GST_GL_WINDOW_CUSTOM (WM_APP+1) #define WM_GST_GL_WINDOW_CUSTOM (WM_APP+1)
#define WM_GST_GL_WINDOW_QUIT (WM_APP+2) #define WM_GST_GL_WINDOW_QUIT (WM_APP+2)

View file

@ -0,0 +1,267 @@
/*
* GStreamer
* Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstglwindow.h"
static guintptr gst_gl_window_win32_wgl_get_gl_context (GstGLWindowWin32 *
window_win32);
static void gst_gl_window_win32_wgl_swap_buffers (GstGLWindowWin32 *
window_win32);
static gboolean gst_gl_window_win32_wgl_choose_format (GstGLWindowWin32 *
window_win32);
static gboolean gst_gl_window_win32_wgl_activate (GstGLWindowWin32 *
window_win32, gboolean activate);
static gboolean gst_gl_window_win32_wgl_create_context (GstGLWindowWin32 *
window_win32, GstGLRendererAPI render_api, guintptr external_gl_context);
static void gst_gl_window_win32_wgl_destroy_context (GstGLWindowWin32 *
window_win32);
const gchar *EGLErrorString ();
#define GST_CAT_DEFAULT gst_gl_window_win32_wgl_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
#define DEBUG_INIT \
GST_DEBUG_CATEGORY_GET (GST_CAT_DEFAULT, "glwindow");
#define gst_gl_window_win32_wgl_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstGLWindowWin32EGL, gst_gl_window_win32_egl,
GST_GL_TYPE_WINDOW, DEBUG_INIT);
static void
gst_gl_window_win32_egl_class_init (GstGLWindowWin32EGLClass * klass)
{
GstGLWindowWin32Class *window_class = (GstGLWindowWin32 *) klass;
window_win32_class->get_gl_context =
GST_DEBUG_FUNCPTR (gst_gl_window_win32_wgl_get_gl_context);
window_win32_class->choose_format =
GST_DEBUG_FUNCPTR (gst_gl_window_win32_wgl_choose_format);
window_win32_class->activate =
GST_DEBUG_FUNCPTR (gst_gl_window_win32_wgl_activate);
window_win32_class->create_context =
GST_DEBUG_FUNCPTR (gst_gl_window_win32_wgl_create_context);
window_win32_class->destroy_context =
GST_DEBUG_FUNCPTR (gst_gl_window_win32_wgl_destroy_context);
window_win32_class->swap_buffers =
GST_DEBUG_FUNCPTR (gst_gl_window_win32_wgl_swap_buffers);
}
static void
gst_gl_window_win32_egl_init (GstGLWindow * window)
{
}
/* Must be called in the gl thread */
GstGLWindowWin32EGL *
gst_gl_window_win32_egl_new (GstGLRendererAPI render_api,
guintptr external_gl_context)
{
GstGLWindowWin32EGL *window =
g_object_new (GST_GL_TYPE_WINDOW_WIN32_EGL, NULL);
gst_gl_window_win32_open_device (GST_GL_WINDOW_WIN32 (window));
return window;
}
guintptr
gst_gl_window_win32_egl_get_gl_context (GstGLWindowWin32 * window_win32)
{
return (guintptr) GST_GL_WINDOW_WIN32_EGL (window_win32)->wgl_context}
static gboolean
gst_gl_window_win32_egl_activate (GstGLWindowWin32 * window_win32,
gboolean activate)
{
GstGLWindowWin32EGL window;
gboolean result;
window = GST_GL_WINDOW_WIN32_ELG (window_win32);
if (activate) {
result = eglMakeCurrent (window->display, window->surface, window->surface,
window->gl_context);
} else {
result = eglMakeCurrent (window->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT)
}
return result;
}
static gboolean
gst_gl_window_win32_egl_create_context (GstGLWindowWin32 * window_win32,
GstGLRendererAPI render_api, guintptr external_gl_context)
{
GstGLWindowWin32EGL *window_egl;
EGLint majorVersion;
EGLint minorVersion;
EGLint numConfigs;
EGLConfig config;
EGLint contextAttribs[] =
{ EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
EGLint attribList[] = {
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 8,
EGL_STENCIL_SIZE, 8,
EGL_SAMPLE_BUFFERS, EGL_DONT_CARE, //1
EGL_NONE
};
window_egl = GST_GL_WINDOW_WIN32_EGL (window_win32);
window_egl->display = eglGetDisplay (window_win32->device);
if (priv->display != EGL_NO_DISPLAY)
g_debug ("display retrieved: %d\n", window_egl->display);
else {
g_debug ("failed to retrieve display %s\n", EGLErrorString ());
goto failure;
}
if (eglInitialize (priv->display, &majorVersion, &minorVersion))
g_debug ("egl initialized: %d.%d\n", majorVersion, minorVersion);
else {
g_debug ("failed to initialize egl %d, %s\n", priv->display,
EGLErrorString ());
goto failure;
}
if (eglGetConfigs (window_egl->display, NULL, 0, &numConfigs))
g_debug ("configs retrieved: %d\n", numConfigs);
else {
g_debug ("failed to retrieve configs %d, %s\n", window_egl->display,
EGLErrorString ());
goto failure;
}
if (eglChooseConfig (priv->display, attribList, &config, 1, &numConfigs))
g_debug ("config set: %d, %d\n", config, numConfigs);
else {
g_debug ("failed to set config %d, %s\n", window_egl->display,
EGLErrorString ());
goto failure;
}
window_egl->surface =
eglCreateWindowSurface (window_egl->display, config,
(EGLNativeWindowType) WindowFromDC (window_win32->device), NULL);
if (priv->surface != EGL_NO_SURFACE)
g_debug ("surface created: %d\n", window_egl->surface);
else {
g_debug ("failed to create surface %d, %d, %s\n", window_egl->display,
window_egl->surface, EGLErrorString ());
goto failure;
}
window_egl->egl_context =
eglCreateContext (window_egl->display, config,
window_egl->external_gl_context, contextAttribs);
if (window_egl->egl_context != EGL_NO_CONTEXT)
g_debug ("gl context created: %lud, external: %lud\n",
(gulong) window_egl->egl_context,
(gulong) window_egl->external_gl_context);
else {
g_debug
("failed to create glcontext %lud, extenal: %lud, %s\n",
(gulong) window_egl->egl_context,
(gulong) window_egl->external_gl_context, EGLErrorString ());
goto failure;
}
return TRUE;
failure:
return FALSE;
}
static void
gst_gl_window_win32_egl_destroy_context (GstGLWindowWin32 * window_win32)
{
GstGLWindowWin32EGL *window_egl;
window_egl = GST_GL_WINDOW_WIN32_EGL (window_win32);
if (window_egl->egl_context) {
if (!eglDestroyContext (window_egl->display, window_egl->egl_context))
g_debug ("failed to destroy context %d, %s\n", window_egl->egl_context,
EGLErrorString ());
window_egl->egl_context = NULL;
}
if (window_egl->surface) {
if (!eglDestroySurface (window_egl->display, window_egl->surface))
g_debug ("failed to destroy surface %d, %s\n", window_egl->surface,
EGLErrorString ());
window_egl->surface = NULL;
}
if (window_egl->display) {
if (!eglTerminate (window_egl->display))
g_debug ("failed to terminate display %d, %s\n", window_egl->display,
EGLErrorString ());
window_egl->display = NULL;
}
}
const gchar *
EGLErrorString ()
{
EGLint nErr = eglGetError ();
switch (nErr) {
case EGL_SUCCESS:
return "EGL_SUCCESS";
case EGL_BAD_DISPLAY:
return "EGL_BAD_DISPLAY";
case EGL_NOT_INITIALIZED:
return "EGL_NOT_INITIALIZED";
case EGL_BAD_ACCESS:
return "EGL_BAD_ACCESS";
case EGL_BAD_ALLOC:
return "EGL_BAD_ALLOC";
case EGL_BAD_ATTRIBUTE:
return "EGL_BAD_ATTRIBUTE";
case EGL_BAD_CONFIG:
return "EGL_BAD_CONFIG";
case EGL_BAD_CONTEXT:
return "EGL_BAD_CONTEXT";
case EGL_BAD_CURRENT_SURFACE:
return "EGL_BAD_CURRENT_SURFACE";
case EGL_BAD_MATCH:
return "EGL_BAD_MATCH";
case EGL_BAD_NATIVE_PIXMAP:
return "EGL_BAD_NATIVE_PIXMAP";
case EGL_BAD_NATIVE_WINDOW:
return "EGL_BAD_NATIVE_WINDOW";
case EGL_BAD_PARAMETER:
return "EGL_BAD_PARAMETER";
case EGL_BAD_SURFACE:
return "EGL_BAD_SURFACE";
default:
return "unknown";
}
}

View file

@ -0,0 +1,70 @@
/*
* GStreamer
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_GL_WINDOW_WIN32_EGL_H__
#define __GST_GL_WINDOW_WIN32_EGL_H__
#include "gstglwindow_win32.h"
#undef UNICODE
#include <windows.h>
#define UNICODE
G_BEGIN_DECLS
#define GST_GL_TYPE_WINDOW_WIN32_EGL (gst_gl_window_win32_egl_get_type())
#define GST_GL_WINDOW_WIN32_EGL(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_GL_TYPE_WINDOW_WIN32_EGL, GstGLWindowWin32EGL))
#define GST_GL_WINDOW_WIN32_EGL_CLASS(k) (G_TYPE_CHECK_CLASS((k), GST_GL_TYPE_WINDOW_WIN32_EGL, GstGLWindowWin32EGLClass))
#define GST_GL_IS_WINDOW_WIN32_EGL(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_GL_TYPE_WINDOW_WIN32_EGL))
#define GST_GL_IS_WINDOW_WIN32_EGL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_GL_TYPE_WINDOW_WIN32_EGL))
#define GST_GL_WINDOW_WIN32_EGL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_GL_TYPE_WINDOW_WIN32_EGL, GstGLWindowWin32EGLClass))
typedef struct _GstGLWindowWin32EGL GstGLWindowWin32EGL;
typedef struct _GstGLWindowWin32EGLClass GstGLWindowWin32EGLClass;
struct _GstGLWindowWin32EGL {
/*< private >*/
GstGLWindowWin32 parent;
EGLNativeWindowType internal_win_id;
EGLDisplay display;
EGLSurface surface;
EGLContext egl_context;
EGLContext external_gl_context;
gpointer _reserved[GST_PADDING];
};
struct _GstGLWindowWin32EGLClass {
/*< private >*/
GstGLWindowWin32Class parent_class;
/*< private >*/
gpointer _reserved[GST_PADDING];
};
GType gst_gl_window_win32_egl_get_type (void);
GstGLWindowWin32EGL * gst_gl_window_win32_egl_new (GstGLRendererAPI render_api,
guintptr external_gl_context);
G_END_DECLS
#endif /* __GST_GL_WINDOW_X11_H__ */