diff options
author | Matthew Waters <ystreet00@gmail.com> | 2012-12-09 09:30:48 +1100 |
---|---|---|
committer | Matthew Waters <ystreet00@gmail.com> | 2014-03-15 18:36:51 +0100 |
commit | 76dfdd656f989f4eec95ca3f758f41ff52215e1e (patch) | |
tree | 45eac3c3e6cd0c4edb03bc010edf48359e4c3ef7 /gst-libs/gst/gl/win32 | |
parent | 1fc0f14d441475da37246878b1ab7cec2737e783 (diff) | |
download | gstreamer-plugins-bad-76dfdd656f989f4eec95ca3f758f41ff52215e1e.tar.gz |
[629/906] window: add GError for error handling of context creation
Diffstat (limited to 'gst-libs/gst/gl/win32')
-rw-r--r-- | gst-libs/gst/gl/win32/gstglwindow_win32.c | 22 | ||||
-rw-r--r-- | gst-libs/gst/gl/win32/gstglwindow_win32.h | 9 | ||||
-rw-r--r-- | gst-libs/gst/gl/win32/gstglwindow_win32_egl.c | 62 | ||||
-rw-r--r-- | gst-libs/gst/gl/win32/gstglwindow_win32_egl.h | 5 | ||||
-rw-r--r-- | gst-libs/gst/gl/win32/gstglwindow_win32_wgl.c | 30 | ||||
-rw-r--r-- | gst-libs/gst/gl/win32/gstglwindow_win32_wgl.h | 3 |
6 files changed, 68 insertions, 63 deletions
diff --git a/gst-libs/gst/gl/win32/gstglwindow_win32.c b/gst-libs/gst/gl/win32/gstglwindow_win32.c index 795eca995..d4ed0dd90 100644 --- a/gst-libs/gst/gl/win32/gstglwindow_win32.c +++ b/gst-libs/gst/gl/win32/gstglwindow_win32.c @@ -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) diff --git a/gst-libs/gst/gl/win32/gstglwindow_win32.h b/gst-libs/gst/gl/win32/gstglwindow_win32.h index cd62b8b26..526b05b45 100644 --- a/gst-libs/gst/gl/win32/gstglwindow_win32.h +++ b/gst-libs/gst/gl/win32/gstglwindow_win32.h @@ -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 diff --git a/gst-libs/gst/gl/win32/gstglwindow_win32_egl.c b/gst-libs/gst/gl/win32/gstglwindow_win32_egl.c index 84fa9cb61..7508b0f85 100644 --- a/gst-libs/gst/gl/win32/gstglwindow_win32_egl.c +++ b/gst-libs/gst/gl/win32/gstglwindow_win32_egl.c @@ -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; } diff --git a/gst-libs/gst/gl/win32/gstglwindow_win32_egl.h b/gst-libs/gst/gl/win32/gstglwindow_win32_egl.h index 5e17813d2..c82c9e07d 100644 --- a/gst-libs/gst/gl/win32/gstglwindow_win32_egl.h +++ b/gst-libs/gst/gl/win32/gstglwindow_win32_egl.h @@ -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 diff --git a/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.c b/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.c index 2273508c9..8e7b67e91 100644 --- a/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.c +++ b/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.c @@ -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; } diff --git a/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.h b/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.h index 9a6506e34..b28a5a1c6 100644 --- a/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.h +++ b/gst-libs/gst/gl/win32/gstglwindow_win32_wgl.h @@ -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 |