Commit c3526080 authored by Matthew Waters's avatar Matthew Waters 🐨 Committed by Tim-Philipp Müller

[629/906] window: add GError for error handling of context creation

parent 6c0e3286
......@@ -23,7 +23,6 @@
#include <gst/gst.h>
#include "gstglapi.h"
#include "gstglwindow.h"
G_BEGIN_DECLS
......@@ -60,7 +59,8 @@ struct _GstGLWindowCocoaClass {
GType gst_gl_window_cocoa_get_type (void);
GstGLWindowCocoa * gst_gl_window_cocoa_new (GstGLAPI gl_api,
guintptr external_gl_context);
guintptr external_gl_context,
GError ** error);
G_END_DECLS
......
......@@ -197,7 +197,7 @@ gst_gl_window_cocoa_init (GstGLWindowCocoa * window)
/* Must be called in the gl thread */
GstGLWindowCocoa *
gst_gl_window_cocoa_new (GstGLAPI gl_api, guintptr external_gl_context)
gst_gl_window_cocoa_new (GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{
GstGLWindowCocoa *window = g_object_new (GST_GL_TYPE_WINDOW_COCOA, NULL);
GstGLWindowCocoaPrivate *priv = window->priv;
......
......@@ -42,22 +42,6 @@
# endif
#endif
#if HAVE_GLX
# include <GL/glx.h>
#endif
#if HAVE_EGL
# undef UNICODE
# include <EGL/egl.h>
# define UNICODE
#endif
#if HAVE_WGL
# undef UNICODE
# include <windows.h>
# define UNICODE
#endif
#include <gst/gst.h>
G_BEGIN_DECLS
......
......@@ -43,6 +43,12 @@ GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
#define gst_gl_window_parent_class parent_class
G_DEFINE_ABSTRACT_TYPE (GstGLWindow, gst_gl_window, G_TYPE_OBJECT);
GQuark
gst_gl_window_error_quark (void)
{
return g_quark_from_static_string ("gst-gl-window-error-quark");
}
static void
gst_gl_window_init (GstGLWindow * window)
{
......@@ -56,12 +62,14 @@ gst_gl_window_class_init (GstGLWindowClass * klass)
}
GstGLWindow *
gst_gl_window_new (GstGLAPI api, guintptr external_gl_context)
gst_gl_window_new (GstGLAPI api, guintptr external_gl_context, GError ** error)
{
GstGLWindow *window = NULL;
const gchar *user_choice;
static volatile gsize _init = 0;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (g_once_init_enter (&_init)) {
GST_DEBUG_CATEGORY_INIT (gst_gl_window_debug, "glwindow", 0,
"glwindow element");
......@@ -73,25 +81,39 @@ gst_gl_window_new (GstGLAPI api, guintptr external_gl_context)
#ifdef HAVE_WINDOW_X11
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
window = GST_GL_WINDOW (gst_gl_window_x11_new (api, external_gl_context));
window =
GST_GL_WINDOW (gst_gl_window_x11_new (api, external_gl_context, error));
#endif
#ifdef HAVE_WINDOW_WIN32
if (!window && (!user_choice || g_strstr_len (user_choice, 5, "win32")))
window = GST_GL_WINDOW (gst_gl_window_win32_new (api, external_gl_context));
window =
GST_GL_WINDOW (gst_gl_window_win32_new (api, external_gl_context,
error));
#endif
#ifdef HAVE_WINDOW_COCOA
if (!window && (!user_choice || g_strstr_len (user_choice, 5, "cocoa")))
window = GST_GL_WINDOW (gst_gl_window_cocoa_new (api, external_gl_context));
window =
GST_GL_WINDOW (gst_gl_window_cocoa_new (api, external_gl_context,
error));
#endif
#ifdef HAVE_WINDOW_WAYLAND
if (!window && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
window =
GST_GL_WINDOW (gst_gl_window_wayland_egl_new (api,
external_gl_context));
external_gl_context, error));
#endif
if (!window) {
GST_WARNING ("could not create a window, user choice:%s", user_choice);
/* FIXME: set and return a GError */
if (error && !*error) {
if (user_choice) {
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_FAILED,
"Could not create %s window", user_choice);
} else {
/* subclass did not set an error yet returned a NULL window */
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_FAILED,
"Could not create %s window, Unknown Error",
user_choice ? user_choice : "");
}
}
return NULL;
}
......
......@@ -51,6 +51,14 @@ G_BEGIN_DECLS
#define GST_GL_WINDOW_ERROR (gst_gl_window_error_quark ())
typedef enum
{
GST_GL_WINDOW_ERROR_FAILED,
GST_GL_WINDOW_ERROR_WRONG_CONFIG,
GST_GL_WINDOW_ERROR_CREATE_CONTEXT,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
} GstGLWindowError;
typedef void (*GstGLWindowCB) (gpointer data);
typedef void (*GstGLWindowResizeCB) (gpointer data, guint width, guint height);
......@@ -106,7 +114,7 @@ struct _GstGLWindowClass {
GQuark gst_gl_window_error_quark (void);
GType gst_gl_window_get_type (void);
GstGLWindow * gst_gl_window_new (GstGLAPI gl_api, guintptr external_gl_context);
GstGLWindow * gst_gl_window_new (GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
void gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowResizeCB callback, gpointer data);
......
......@@ -52,7 +52,8 @@ static void gst_gl_window_wayland_egl_send_message (GstGLWindow * window,
static void gst_gl_window_wayland_egl_destroy_context (GstGLWindowWaylandEGL *
window_egl);
static gboolean gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL
* window_egl, GstGLAPI gl_api, guintptr external_gl_context);
* window_egl, GstGLAPI gl_api, guintptr external_gl_context,
GError ** error);
GstGLAPI gst_gl_window_wayland_egl_get_gl_api (GstGLWindow * window);
static void gst_gl_window_wayland_egl_finalize (GObject * object);
......@@ -285,7 +286,8 @@ gst_gl_window_wayland_egl_init (GstGLWindowWaylandEGL * window)
/* Must be called in the gl thread */
GstGLWindowWaylandEGL *
gst_gl_window_wayland_egl_new (GstGLAPI gl_api, guintptr external_gl_context)
gst_gl_window_wayland_egl_new (GstGLAPI gl_api, guintptr external_gl_context,
GError ** error)
{
GstGLWindowWaylandEGL *window;
......@@ -296,7 +298,12 @@ gst_gl_window_wayland_egl_new (GstGLAPI gl_api, guintptr external_gl_context)
gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);
window->display.display = wl_display_connect (NULL);
g_assert (window->display.display);
if (!window->display.display) {
g_set_error (error, GST_GL_WINDOW_ERROR,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
"Failed to connect to Wayland display server");
goto error;
}
window->display.registry = wl_display_get_registry (window->display.display);
wl_registry_add_listener (window->display.registry, &registry_listener,
......@@ -316,9 +323,16 @@ gst_gl_window_wayland_egl_new (GstGLAPI gl_api, guintptr external_gl_context)
g_source_attach (window->wl_source, window->main_context);
gst_gl_window_wayland_egl_create_context (window, gl_api,
external_gl_context);
external_gl_context, error);
return window;
error:
{
if (window)
g_object_unref (window);
return NULL;
}
}
static void
......@@ -330,7 +344,9 @@ gst_gl_window_wayland_egl_finalize (GObject * object)
gst_gl_window_wayland_egl_destroy_context (window_egl);
wl_surface_destroy (window_egl->display.cursor_surface);
if (window_egl->display.cursor_surface)
wl_surface_destroy (window_egl->display.cursor_surface);
if (window_egl->display.cursor_theme)
wl_cursor_theme_destroy (window_egl->display.cursor_theme);
......@@ -340,15 +356,17 @@ gst_gl_window_wayland_egl_finalize (GObject * object)
if (window_egl->display.compositor)
wl_compositor_destroy (window_egl->display.compositor);
wl_display_flush (window_egl->display.display);
wl_display_disconnect (window_egl->display.display);
if (window_egl->display.display) {
wl_display_flush (window_egl->display.display);
wl_display_disconnect (window_egl->display.display);
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL * window_egl,
GstGLAPI gl_api, guintptr external_gl_context)
GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{
EGLint config_attrib[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
......@@ -376,13 +394,15 @@ gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL * window_egl,
if (eglInitialize (window_egl->egl_display, &majorVersion, &minorVersion))
GST_DEBUG ("egl initialized: %d.%d", majorVersion, minorVersion);
else {
GST_DEBUG ("failed to initialize egl %ld, %s",
(gulong) window_egl->egl_display, WlEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
"Failed to initialize egl: %s", WlEGLErrorString ());
goto failure;
}
if (!eglBindAPI (EGL_OPENGL_ES_API)) {
GST_WARNING ("failed to bind OpenGL|ES API");
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_FAILED,
"Failed to bind OpenGL|ES API: %s", WlEGLErrorString ());
goto failure;
}
......@@ -391,8 +411,8 @@ gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL * window_egl,
GST_DEBUG ("config set: %ld, %ld", (gulong) window_egl->egl_config,
(gulong) numConfigs);
else {
GST_DEBUG ("failed to set config %ld, %s", (gulong) window_egl->egl_display,
WlEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_CONFIG,
"Failed to set window configuration: %s", WlEGLErrorString ());
goto failure;
}
......@@ -405,9 +425,8 @@ gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL * window_egl,
if (window_egl->egl_context != EGL_NO_CONTEXT)
GST_DEBUG ("gl context created: %ld", (gulong) window_egl->egl_context);
else {
GST_DEBUG ("failed to create glcontext %ld, %ld, %s",
(gulong) window_egl->egl_context, (gulong) window_egl->egl_display,
WlEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_CREATE_CONTEXT,
"Failed to create a OpenGL context: %s", WlEGLErrorString ());
goto failure;
}
......
......@@ -25,7 +25,8 @@
#include <wayland-egl.h>
#include <wayland-cursor.h>
#include "gstglapi.h"
#include <EGL/egl.h>
#include "gstglwindow.h"
G_BEGIN_DECLS
......@@ -99,7 +100,8 @@ struct _GstGLWindowWaylandEGLClass {
GType gst_gl_window_wayland_egl_get_type (void);
GstGLWindowWaylandEGL * gst_gl_window_wayland_egl_new (GstGLAPI gl_api,
guintptr external_gl_context);
guintptr external_gl_context,
GError ** error);
G_END_DECLS
......
......@@ -53,6 +53,7 @@ struct _GstGLWindowWin32Private
{
GstGLAPI gl_api;
guintptr external_gl_context;
GError **error;
gboolean activate;
gboolean activate_result;
};
......@@ -138,7 +139,8 @@ gst_gl_window_win32_init (GstGLWindowWin32 * window)
/* Must be called in the gl thread */
GstGLWindowWin32 *
gst_gl_window_win32_new (GstGLAPI gl_api, guintptr external_gl_context)
gst_gl_window_win32_new (GstGLAPI gl_api, guintptr external_gl_context,
GError ** error)
{
GstGLWindowWin32 *window = NULL;
const gchar *user_choice;
......@@ -149,28 +151,30 @@ gst_gl_window_win32_new (GstGLAPI gl_api, guintptr external_gl_context)
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "wgl")))
window =
GST_GL_WINDOW_WIN32 (gst_gl_window_win32_wgl_new (gl_api,
external_gl_context));
external_gl_context, error));
#endif
#if HAVE_EGL
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "egl")))
window =
GST_GL_WINDOW_WIN32 (gst_gl_window_win32_egl_new (gl_api,
external_gl_context));
external_gl_context, error));
#endif
if (!window) {
GST_WARNING ("Failed to create x11 window, user_choice:%s",
GST_WARNING ("Failed to create win32 window, user_choice:%s",
user_choice ? user_choice : "NULL");
return NULL;
}
window->priv->gl_api = gl_api;
window->priv->external_gl_context = external_gl_context;
window->priv->error = error;
return window;
}
gboolean
gst_gl_window_win32_open_device (GstGLWindowWin32 * window_win32)
gst_gl_window_win32_open_device (GstGLWindowWin32 * window_win32,
GError ** error)
{
HINSTANCE hinstance = GetModuleHandle (NULL);
......@@ -261,7 +265,7 @@ gst_gl_window_win32_set_window_handle (GstGLWindow * window, guintptr id)
window_win32 = GST_GL_WINDOW_WIN32 (window);
//retrieve parent if previously set
/* retrieve parent if previously set */
parent_id = GetProp (window_win32->internal_win_id, "gl_window_parent_id");
if (window_win32->visible) {
......@@ -299,7 +303,7 @@ gst_gl_window_win32_set_window_handle (GstGLWindow * window, guintptr id)
WS_CHILD | WS_MAXIMIZE);
SetParent (window_win32->internal_win_id, (HWND) id);
//take changes into account: SWP_FRAMECHANGED
/* take changes into account: SWP_FRAMECHANGED */
GetClientRect ((HWND) id, &rect);
SetWindowPos (window_win32->internal_win_id, HWND_TOP, rect.left, rect.top,
rect.right, rect.bottom,
......@@ -308,7 +312,7 @@ gst_gl_window_win32_set_window_handle (GstGLWindow * window, guintptr id)
MoveWindow (window_win32->internal_win_id, rect.left, rect.top, rect.right,
rect.bottom, FALSE);
} else {
//no parent so the internal window needs borders and system menu
/* no parent so the internal window needs borders and system menu */
SetWindowLongPtr (window_win32->internal_win_id, GWL_STYLE,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW);
}
......@@ -427,7 +431,7 @@ window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
window_class->choose_format (window_win32);
window_class->create_context (window_win32, priv->gl_api,
priv->external_gl_context);
priv->external_gl_context, priv->error);
/* priv->gl_context = wglCreateContext (priv->device);
if (priv->gl_context)
......
......@@ -21,7 +21,6 @@
#ifndef __GST_GL_WINDOW_WIN32_H__
#define __GST_GL_WINDOW_WIN32_H__
#include "gstglapi.h"
#include "gstglwindow.h"
#undef UNICODE
......@@ -61,8 +60,8 @@ struct _GstGLWindowWin32Class {
GstGLWindowClass parent_class;
gboolean (*choose_format) (GstGLWindowWin32 *window);
gboolean (*create_context) (GstGLWindowWin32 *window, GstGLRendererAPI render_api,
guintptr external_gl_context);
gboolean (*create_context) (GstGLWindowWin32 *window, GstGLAPI gl_api,
guintptr external_gl_context, GError ** error);
gboolean (*share_context) (GstGLWindowWin32 *window, guintptr external_gl_context);
void (*swap_buffers) (GstGLWindowWin32 *window);
gboolean (*activate) (GstGLWindowWin32 *window, gboolean activate);
......@@ -76,8 +75,8 @@ struct _GstGLWindowWin32Class {
GType gst_gl_window_win32_get_type (void);
GstGLWindowWin32 * gst_gl_window_win32_new (GstGLAPI gl_api,
guintptr external_gl_context);
gboolean gst_gl_window_win32_open_device (GstGLWindowWin32 *window_win32);
guintptr external_gl_context, GError ** error);
gboolean gst_gl_window_win32_open_device (GstGLWindowWin32 *window_win32, GError ** error);
G_END_DECLS
......
......@@ -36,21 +36,19 @@ static gboolean gst_gl_window_win32_wgl_choose_format (GstGLWindowWin32 *
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, GstGLAPI gl_api, guintptr external_gl_context);
window_win32, GstGLAPI gl_api, guintptr external_gl_context,
GError ** error);
static void gst_gl_window_win32_wgl_destroy_context (GstGLWindowWin32 *
window_win32);
GstGLAPI gst_gl_window_win32_egl_get_gl_api (GstGLWindow * window);
const gchar *WinEGLErrorString ();
#define GST_CAT_DEFAULT gst_gl_window_win32_egl_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
#define GST_CAT_DEFAULT gst_gl_window_debug
#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);
G_DEFINE_TYPE (GstGLWindowWin32EGL, gst_gl_window_win32_egl,
GST_GL_TYPE_WINDOW);
static void
gst_gl_window_win32_egl_class_init (GstGLWindowWin32EGLClass * klass)
......@@ -82,12 +80,13 @@ gst_gl_window_win32_egl_init (GstGLWindow * window)
/* Must be called in the gl thread */
GstGLWindowWin32EGL *
gst_gl_window_win32_egl_new (GstGLAPI gl_api, guintptr external_gl_context)
gst_gl_window_win32_egl_new (GstGLAPI gl_api, guintptr external_gl_context,
GError ** error)
{
GstGLWindowWin32EGL *window =
g_object_new (GST_GL_TYPE_WINDOW_WIN32_EGL, NULL);
gst_gl_window_win32_open_device (GST_GL_WINDOW_WIN32 (window));
gst_gl_window_win32_open_device (GST_GL_WINDOW_WIN32 (window), error);
return window;
}
......@@ -95,7 +94,8 @@ gst_gl_window_win32_egl_new (GstGLAPI gl_api, guintptr external_gl_context)
guintptr
gst_gl_window_win32_egl_get_gl_context (GstGLWindowWin32 * window_win32)
{
return (guintptr) GST_GL_WINDOW_WIN32_EGL (window_win32)->wgl_context}
return (guintptr) GST_GL_WINDOW_WIN32_EGL (window_win32)->wgl_context;
}
static gboolean
gst_gl_window_win32_egl_activate (GstGLWindowWin32 * window_win32,
......@@ -119,7 +119,7 @@ gst_gl_window_win32_egl_activate (GstGLWindowWin32 * window_win32,
static gboolean
gst_gl_window_win32_egl_create_context (GstGLWindowWin32 * window_win32,
GstGLAPI gl_api, guintptr external_gl_context)
GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{
GstGLWindowWin32EGL *window_egl;
EGLint majorVersion;
......@@ -144,33 +144,36 @@ gst_gl_window_win32_egl_create_context (GstGLWindowWin32 * window_win32,
window_egl->display = eglGetDisplay (window_win32->device);
if (priv->display != EGL_NO_DISPLAY)
GST_DEBUG ("display retrieved: %d\n", window_egl->display);
GST_DEBUG ("display retrieved: %d", window_egl->display);
else {
GST_DEBUG ("failed to retrieve display %s\n", WinEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
"failed to retrieve display: %s", WinEGLErrorString ());
goto failure;
}
if (eglInitialize (priv->display, &majorVersion, &minorVersion))
GST_DEBUG ("egl initialized: %d.%d\n", majorVersion, minorVersion);
GST_DEBUG ("egl initialized: %d.%d", majorVersion, minorVersion);
else {
GST_DEBUG ("failed to initialize egl %d, %s\n", priv->display,
WinEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
"failed to initialize egl: %s", WinEGLErrorString ());
goto failure;
}
if (eglGetConfigs (window_egl->display, NULL, 0, &numConfigs))
GST_DEBUG ("configs retrieved: %d\n", numConfigs);
GST_DEBUG ("configs retrieved: %d", numConfigs);
else {
GST_DEBUG ("failed to retrieve configs %d, %s\n", window_egl->display,
WinEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_CONFIG,
"failed to retrieve configs %s", WinEGLErrorString ());
goto failure;
}
if (eglChooseConfig (priv->display, attribList, &config, 1, &numConfigs))
GST_DEBUG ("config set: %d, %d\n", config, numConfigs);
GST_DEBUG ("config set: %d, %d", config, numConfigs);
else {
GST_DEBUG ("failed to set config %d, %s\n", window_egl->display,
WinEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_CONFIG,
"failed to set config %s", WinEGLErrorString ());
goto failure;
}
......@@ -178,10 +181,10 @@ gst_gl_window_win32_egl_create_context (GstGLWindowWin32 * window_win32,
eglCreateWindowSurface (window_egl->display, config,
(EGLNativeWindowType) WindowFromDC (window_win32->device), NULL);
if (priv->surface != EGL_NO_SURFACE)
GST_DEBUG ("surface created: %d\n", window_egl->surface);
GST_DEBUG ("surface created: %d", window_egl->surface);
else {
GST_DEBUG ("failed to create surface %d, %d, %s\n", window_egl->display,
window_egl->surface, WinEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_CREATE_CONTEXT,
"failed to create surface %s", WinEGLErrorString ());
goto failure;
}
......@@ -189,13 +192,12 @@ gst_gl_window_win32_egl_create_context (GstGLWindowWin32 * window_win32,
eglCreateContext (window_egl->display, config, external_gl_context,
contextAttribs);
if (window_egl->egl_context != EGL_NO_CONTEXT)
GST_DEBUG ("gl context created: %lud, external: %lud\n",
GST_DEBUG ("gl context created: %lud, external: %lud",
(gulong) window_egl->egl_context, (gulong) external_gl_context);
else {
GST_DEBUG
("failed to create glcontext %lud, extenal: %lud, %s\n",
(gulong) window_egl->egl_context, (gulong) external_gl_context,
WinEGLErrorString ());
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_CREATE_CONTEXT,
"failed to create glcontext with external: %lud, %s",
(gulong) external_gl_context, WinEGLErrorString ());
goto failure;
}
......
......@@ -23,7 +23,8 @@
#include <gst/gst.h>
#include "gstglapi.h"
#include <EGL/egl.h>
#include "gstglwindow_win32.h"
G_BEGIN_DECLS
......@@ -62,7 +63,7 @@ struct _GstGLWindowWin32EGLClass {
GType gst_gl_window_win32_egl_get_type (void);
GstGLWindowWin32EGL * gst_gl_window_win32_egl_new (GstGLAPI gl_api,
guintptr external_gl_context);
guintptr external_gl_context, GError ** error);
G_END_DECLS
......
......@@ -29,14 +29,11 @@
#include "gstglwindow_win32_wgl.h"
#define GST_CAT_DEFAULT gst_gl_window_win32_wgl_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
#define GST_CAT_DEFAULT gst_gl_window_debug
#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 (GstGLWindowWin32WGL, gst_gl_window_win32_wgl,
GST_GL_TYPE_WINDOW_WIN32, DEBUG_INIT);
G_DEFINE_TYPE (GstGLWindowWin32WGL, gst_gl_window_win32_wgl,
GST_GL_TYPE_WINDOW_WIN32);
static guintptr gst_gl_window_win32_wgl_get_gl_context (GstGLWindowWin32 *
window_win32);
......@@ -47,7 +44,8 @@ static gboolean gst_gl_window_win32_wgl_choose_format (GstGLWindowWin32 *
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, GstGLAPI gl_api, guintptr external_gl_context);
window_win32, GstGLAPI gl_api, guintptr external_gl_context,
GError ** error);
static void gst_gl_window_win32_wgl_destroy_context (GstGLWindowWin32 *
window_win32);
GstGLAPI gst_gl_window_win32_wgl_get_gl_api (GstGLWindow * window);
......@@ -55,7 +53,7 @@ GstGLAPI gst_gl_window_win32_wgl_get_gl_api (GstGLWindow * window);
static void
gst_gl_window_win32_wgl_class_init (GstGLWindowWin32WGLClass * klass)
{
GstGLWindowClass *window_class;
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
GstGLWindowWin32Class *window_win32_class = (GstGLWindowWin32Class *) klass;
window_win32_class->get_gl_context =
......@@ -82,19 +80,20 @@ gst_gl_window_win32_wgl_init (GstGLWindowWin32WGL * window)
/* Must be called in the gl thread */
GstGLWindowWin32WGL *
gst_gl_window_win32_wgl_new (GstGLAPI gl_api, guintptr external_gl_context)
gst_gl_window_win32_wgl_new (GstGLAPI gl_api, guintptr external_gl_context,
GError ** error)
{
GstGLWindowWin32WGL *window =
g_object_new (GST_GL_TYPE_WINDOW_WIN32_WGL, NULL);
gst_gl_window_win32_open_device (GST_GL_WINDOW_WIN32 (window));
gst_gl_window_win32_open_device (GST_GL_WINDOW_WIN32 (window), error);
return window;
}
static gboolean
gst_gl_window_win32_wgl_create_context (GstGLWindowWin32 * window_win32,
GstGLAPI gl_api, guintptr external_gl_context)
GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{
GstGLWindowWin32WGL *window_wgl;
......@@ -102,10 +101,11 @@ gst_gl_window_win32_wgl_create_context (GstGLWindowWin32 * window_win32,
window_wgl->wgl_context = wglCreateContext (window_win32->device);
if (window_wgl->wgl_context)
GST_DEBUG ("gl context created: %" G_GUINTPTR_FORMAT "\n",
GST_DEBUG ("gl context created: %" G_GUINTPTR_FORMAT,
(guintptr) window_wgl->wgl_context);
else {
GST_DEBUG ("failed to create glcontext:%lud\n", GetLastError ());
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_CREATE_CONTEXT,
"failed to create glcontext:%lu", GetLastError ());
goto failure;
}
g_assert (window_wgl->wgl_context);
......@@ -125,8 +125,8 @@ gst_gl_window_win32_wgl_destroy_context (GstGLWindowWin32 * window_win32)
window_wgl = GST_GL_WINDOW_WIN32_WGL (window_win32);
wglDeleteContext (window_wgl->wgl_context);
if (window_wgl->wgl_context)
wglDeleteContext (window_wgl->wgl_context);
window_wgl->wgl_context = 0;
}
......
......@@ -21,7 +21,6 @@
#ifndef __GST_GL_WINDOW_WIN32_WGL_H__
#define __GST_GL_WINDOW_WIN32_WGL_H__
#include "gstglapi.h"
#include "gstglwindow_win32.h"
G_BEGIN_DECLS
......@@ -57,7 +56,7 @@ struct _GstGLWindowWin32WGLClass {
GType gst_gl_window_win32_wgl_get_type (void);
GstGLWindowWin32WGL * gst_gl_window_win32_wgl_new (GstGLAPI gl_api,
guintptr external_gl_context);
guintptr external_gl_context, GError ** error);
G_END_DECLS
......
......@@ -40,14 +40,10 @@
#define GST_GL_WINDOW_X11_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW_X11, GstGLWindowX11Private))
#define GST_CAT_DEFAULT gst_gl_window_x11_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
#define GST_CAT_DEFAULT gst_gl_window_debug
#define DEBUG_INIT \
GST_DEBUG_CATEGORY_GET (GST_CAT_DEFAULT, "glwindow");
#define gst_gl_window_x11_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstGLWindowX11, gst_gl_window_x11, GST_GL_TYPE_WINDOW,
DEBUG_INIT);
G_DEFINE_TYPE (GstGLWindowX11, gst_gl_window_x11, GST_GL_TYPE_WINDOW);
enum
{
......@@ -213,7 +209,8 @@ gst_gl_window_x11_init (GstGLWindowX11 * window)
/* Must be called in the gl thread */
GstGLWindowX11 *
gst_gl_window_x11_new (GstGLAPI gl_api, guintptr external_gl_context)
gst_gl_window_x11_new (GstGLAPI gl_api, guintptr external_gl_context,
GError ** error)
{
GstGLWindowX11 *window = NULL;
const gchar *user_choice;
......@@ -229,35 +226,35 @@ gst_gl_window_x11_new (GstGLAPI gl_api, guintptr external_gl_context)
|| g_strstr_len (user_choice, 3, "glx") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_glx_new (gl_api,
external_gl_context));
external_gl_context, error));
if (!window && (!user_choice
|| g_strstr_len (user_choice, 3, "egl") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_egl_new (gl_api,
external_gl_context));
external_gl_context, error));
} else { /* try EGL first for OpenGL|ES */
if (!window && (!user_choice
|| g_strstr_len (user_choice, 3, "egl") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_egl_new (gl_api,
external_gl_context));
external_gl_context, error));
if (!window && (!user_choice
|| g_strstr_len (user_choice, 3, "glx") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_glx_new (gl_api,
external_gl_context));
external_gl_context, error));