From ff0a237458cb92a4ace65ba4662a994ba0902fc1 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Wed, 10 Dec 2014 18:12:24 +0100 Subject: [PATCH] window: add generic helper to create windows. Add a new generic helper function gst_vaapi_window_new() to create a window without having the caller to check for the display type himself. i.e. internally, there is now a GstVaapiDisplayClass hook to create windows, and the actual backend implementation fills it in. Add new generic helper functions gst_vaapi_texture_new_wrapped() This is a simplification in view to supporting EGL. --- gst-libs/gst/vaapi/gstvaapidisplay_drm.c | 10 ++++ gst-libs/gst/vaapi/gstvaapidisplay_glx.c | 11 +++++ gst-libs/gst/vaapi/gstvaapidisplay_priv.h | 5 ++ gst-libs/gst/vaapi/gstvaapidisplay_wayland.c | 11 +++++ gst-libs/gst/vaapi/gstvaapidisplay_x11.c | 11 +++++ gst-libs/gst/vaapi/gstvaapiwindow.c | 52 ++++++++++++-------- gst-libs/gst/vaapi/gstvaapiwindow.h | 3 ++ gst-libs/gst/vaapi/gstvaapiwindow_drm.c | 5 +- gst-libs/gst/vaapi/gstvaapiwindow_glx.c | 9 ++-- gst-libs/gst/vaapi/gstvaapiwindow_priv.h | 8 +-- gst-libs/gst/vaapi/gstvaapiwindow_wayland.c | 6 +-- gst-libs/gst/vaapi/gstvaapiwindow_x11.c | 10 ++-- 12 files changed, 100 insertions(+), 41 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_drm.c b/gst-libs/gst/vaapi/gstvaapidisplay_drm.c index d24bd67808..43516e40f7 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_drm.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_drm.c @@ -36,6 +36,7 @@ #include "gstvaapidisplay_priv.h" #include "gstvaapidisplay_drm.h" #include "gstvaapidisplay_drm_priv.h" +#include "gstvaapiwindow_drm.h" #define DEBUG 1 #include "gstvaapidebug.h" @@ -312,6 +313,14 @@ gst_vaapi_display_drm_get_display_info (GstVaapiDisplay * display, return TRUE; } +static GstVaapiWindow * +gst_vaapi_display_drm_create_window (GstVaapiDisplay * display, GstVaapiID id, + guint width, guint height) +{ + return id != GST_VAAPI_ID_INVALID ? + NULL : gst_vaapi_window_drm_new (display, width, height); +} + static void gst_vaapi_display_drm_init (GstVaapiDisplay * display) { @@ -337,6 +346,7 @@ gst_vaapi_display_drm_class_init (GstVaapiDisplayDRMClass * klass) dpy_class->open_display = gst_vaapi_display_drm_open_display; dpy_class->close_display = gst_vaapi_display_drm_close_display; dpy_class->get_display = gst_vaapi_display_drm_get_display_info; + dpy_class->create_window = gst_vaapi_display_drm_create_window; } static inline const GstVaapiDisplayClass * diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_glx.c b/gst-libs/gst/vaapi/gstvaapidisplay_glx.c index 9a3ab3eeed..2738454b07 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_glx.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_glx.c @@ -35,6 +35,7 @@ #include "gstvaapidisplay_x11_priv.h" #include "gstvaapidisplay_glx.h" #include "gstvaapidisplay_glx_priv.h" +#include "gstvaapiwindow_glx.h" #include "gstvaapitexture_glx.h" #define DEBUG 1 @@ -42,6 +43,15 @@ static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_GLX; +static GstVaapiWindow * +gst_vaapi_display_glx_create_window (GstVaapiDisplay * display, GstVaapiID id, + guint width, guint height) +{ + return id != GST_VAAPI_ID_INVALID ? + gst_vaapi_window_glx_new_with_xid (display, id) : + gst_vaapi_window_glx_new (display, width, height); +} + static GstVaapiTexture * gst_vaapi_display_glx_create_texture (GstVaapiDisplay * display, GstVaapiID id, guint target, guint format, guint width, guint height) @@ -62,6 +72,7 @@ gst_vaapi_display_glx_class_init (GstVaapiDisplayGLXClass * klass) object_class->size = sizeof (GstVaapiDisplayGLX); dpy_class->display_type = GST_VAAPI_DISPLAY_TYPE_GLX; + dpy_class->create_window = gst_vaapi_display_glx_create_window; dpy_class->create_texture = gst_vaapi_display_glx_create_texture; } diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_priv.h b/gst-libs/gst/vaapi/gstvaapidisplay_priv.h index a19b7d197b..c9b0e00449 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_priv.h +++ b/gst-libs/gst/vaapi/gstvaapidisplay_priv.h @@ -27,6 +27,7 @@ #include #include +#include #include #include "gstvaapiminiobject.h" @@ -67,6 +68,8 @@ typedef void (*GstVaapiDisplayGetSizeFunc) (GstVaapiDisplay * display, guint * pwidth, guint * pheight); typedef void (*GstVaapiDisplayGetSizeMFunc) (GstVaapiDisplay * display, guint * pwidth, guint * pheight); +typedef GstVaapiWindow *(*GstVaapiDisplayCreateWindowFunc) ( + GstVaapiDisplay * display, GstVaapiID id, guint width, guint height); typedef GstVaapiTexture *(*GstVaapiDisplayCreateTextureFunc) ( GstVaapiDisplay * display, GstVaapiID id, guint target, guint format, guint width, guint height); @@ -187,6 +190,7 @@ struct _GstVaapiDisplay * @get_display: virtual function to retrieve the #GstVaapiDisplayInfo * @get_size: virtual function to retrieve the display dimensions, in pixels * @get_size_mm: virtual function to retrieve the display dimensions, in millimeters + * @create_window: (optional) virtual function to create a window * @create_texture: (optional) virtual function to create a texture * * Base class for VA displays. @@ -212,6 +216,7 @@ struct _GstVaapiDisplayClass GstVaapiDisplayGetSizeFunc get_size; GstVaapiDisplayGetSizeMFunc get_size_mm; + GstVaapiDisplayCreateWindowFunc create_window; GstVaapiDisplayCreateTextureFunc create_texture; }; diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_wayland.c b/gst-libs/gst/vaapi/gstvaapidisplay_wayland.c index b0458a99bf..090965eae2 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_wayland.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_wayland.c @@ -31,6 +31,7 @@ #include "gstvaapidisplay_priv.h" #include "gstvaapidisplay_wayland.h" #include "gstvaapidisplay_wayland_priv.h" +#include "gstvaapiwindow_wayland.h" #define DEBUG 1 #include "gstvaapidebug.h" @@ -320,6 +321,15 @@ gst_vaapi_display_wayland_get_size_mm (GstVaapiDisplay * display, *pheight = priv->phys_height; } +static GstVaapiWindow * +gst_vaapi_display_wayland_create_window (GstVaapiDisplay * display, + GstVaapiID id, guint width, guint height) +{ + return id != GST_VAAPI_ID_INVALID ? + NULL : + gst_vaapi_window_wayland_new (display, width, height); +} + static void gst_vaapi_display_wayland_init (GstVaapiDisplay * display) { @@ -347,6 +357,7 @@ gst_vaapi_display_wayland_class_init (GstVaapiDisplayWaylandClass * klass) dpy_class->get_display = gst_vaapi_display_wayland_get_display_info; dpy_class->get_size = gst_vaapi_display_wayland_get_size; dpy_class->get_size_mm = gst_vaapi_display_wayland_get_size_mm; + dpy_class->create_window = gst_vaapi_display_wayland_create_window; } static inline const GstVaapiDisplayClass * diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c index d17535f0ab..658b597577 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c @@ -33,6 +33,7 @@ #include "gstvaapidisplay_priv.h" #include "gstvaapidisplay_x11.h" #include "gstvaapidisplay_x11_priv.h" +#include "gstvaapiwindow_x11.h" #ifdef HAVE_XRANDR # include @@ -368,6 +369,15 @@ gst_vaapi_display_x11_get_size_mm (GstVaapiDisplay * display, *pheight = height_mm; } +static GstVaapiWindow * +gst_vaapi_display_x11_create_window (GstVaapiDisplay * display, GstVaapiID id, + guint width, guint height) +{ + return id != GST_VAAPI_ID_INVALID ? + gst_vaapi_window_x11_new_with_xid (display, id) : + gst_vaapi_window_x11_new (display, width, height); +} + void gst_vaapi_display_x11_class_init (GstVaapiDisplayX11Class * klass) { @@ -387,6 +397,7 @@ gst_vaapi_display_x11_class_init (GstVaapiDisplayX11Class * klass) dpy_class->get_display = gst_vaapi_display_x11_get_display_info; dpy_class->get_size = gst_vaapi_display_x11_get_size; dpy_class->get_size_mm = gst_vaapi_display_x11_get_size_mm; + dpy_class->create_window = gst_vaapi_display_x11_create_window; } static inline const GstVaapiDisplayClass * diff --git a/gst-libs/gst/vaapi/gstvaapiwindow.c b/gst-libs/gst/vaapi/gstvaapiwindow.c index 7ebbdac9fe..c8956826a5 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow.c @@ -30,6 +30,7 @@ #include "sysdeps.h" #include "gstvaapiwindow.h" #include "gstvaapiwindow_priv.h" +#include "gstvaapidisplay_priv.h" #include "gstvaapisurface_priv.h" #define DEBUG 1 @@ -74,20 +75,26 @@ gst_vaapi_window_create (GstVaapiWindow * window, guint width, guint height) } GstVaapiWindow * -gst_vaapi_window_new (const GstVaapiWindowClass * window_class, - GstVaapiDisplay * display, guint width, guint height) +gst_vaapi_window_new_internal (const GstVaapiWindowClass * window_class, + GstVaapiDisplay * display, GstVaapiID id, guint width, guint height) { GstVaapiWindow *window; - g_return_val_if_fail (width > 0, NULL); - g_return_val_if_fail (height > 0, NULL); + if (id != GST_VAAPI_ID_INVALID) { + g_return_val_if_fail (width == 0, NULL); + g_return_val_if_fail (height == 0, NULL); + } else { + g_return_val_if_fail (width > 0, NULL); + g_return_val_if_fail (height > 0, NULL); + } window = gst_vaapi_object_new (GST_VAAPI_OBJECT_CLASS (window_class), display); if (!window) return NULL; - GST_VAAPI_OBJECT_ID (window) = 0; + window->use_foreign_window = id != GST_VAAPI_ID_INVALID; + GST_VAAPI_OBJECT_ID (window) = window->use_foreign_window ? id : 0; if (!gst_vaapi_window_create (window, width, height)) goto error; return window; @@ -97,26 +104,29 @@ error: return NULL; } +/** + * gst_vaapi_window_new: + * @display: a #GstVaapiDisplay + * @width: the requested window width, in pixels + * @height: the requested windo height, in pixels + * + * Creates a window with the specified @width and @height. The window + * will be attached to the @display and remains invisible to the user + * until gst_vaapi_window_show() is called. + * + * Return value: the newly allocated #GstVaapiWindow object + */ GstVaapiWindow * -gst_vaapi_window_new_from_native (const GstVaapiWindowClass * window_class, - GstVaapiDisplay * display, gpointer native_window) +gst_vaapi_window_new (GstVaapiDisplay * display, guint width, guint height) { - GstVaapiWindow *window; + GstVaapiDisplayClass *dpy_class; - window = gst_vaapi_object_new (GST_VAAPI_OBJECT_CLASS (window_class), - display); - if (!window) + g_return_val_if_fail (display != NULL, NULL); + + dpy_class = GST_VAAPI_DISPLAY_GET_CLASS (display); + if (G_UNLIKELY (!dpy_class->create_window)) return NULL; - - GST_VAAPI_OBJECT_ID (window) = GPOINTER_TO_SIZE (native_window); - window->use_foreign_window = TRUE; - if (!gst_vaapi_window_create (window, 0, 0)) - goto error; - return window; - -error: - gst_vaapi_window_unref_internal (window); - return NULL; + return dpy_class->create_window (display, GST_VAAPI_ID_INVALID, width, height); } /** diff --git a/gst-libs/gst/vaapi/gstvaapiwindow.h b/gst-libs/gst/vaapi/gstvaapiwindow.h index 84a6ef8db2..64ee3e50e4 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow.h +++ b/gst-libs/gst/vaapi/gstvaapiwindow.h @@ -40,6 +40,9 @@ G_BEGIN_DECLS typedef struct _GstVaapiWindow GstVaapiWindow; typedef struct _GstVaapiWindowClass GstVaapiWindowClass; +GstVaapiWindow * +gst_vaapi_window_new (GstVaapiDisplay * display, guint width, guint height); + GstVaapiWindow * gst_vaapi_window_ref (GstVaapiWindow * window); diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_drm.c b/gst-libs/gst/vaapi/gstvaapiwindow_drm.c index 510ae3b605..ae49a07cb0 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_drm.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_drm.c @@ -137,6 +137,7 @@ gst_vaapi_window_drm_new (GstVaapiDisplay * display, guint width, guint height) g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_DRM (display), NULL); return - gst_vaapi_window_new (GST_VAAPI_WINDOW_CLASS (gst_vaapi_window_drm_class - ()), display, width, height); + gst_vaapi_window_new_internal (GST_VAAPI_WINDOW_CLASS + (gst_vaapi_window_drm_class ()), display, GST_VAAPI_ID_INVALID, width, + height); } diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_glx.c b/gst-libs/gst/vaapi/gstvaapiwindow_glx.c index 8830801dc3..722d522853 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_glx.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_glx.c @@ -347,8 +347,9 @@ gst_vaapi_window_glx_new (GstVaapiDisplay * display, guint width, guint height) g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_GLX (display), NULL); window = - gst_vaapi_window_new (GST_VAAPI_WINDOW_CLASS (gst_vaapi_window_glx_class - ()), display, width, height); + gst_vaapi_window_new_internal (GST_VAAPI_WINDOW_CLASS + (gst_vaapi_window_glx_class ()), display, GST_VAAPI_ID_INVALID, width, + height); if (!window) return NULL; @@ -384,8 +385,8 @@ gst_vaapi_window_glx_new_with_xid (GstVaapiDisplay * display, Window xid) g_return_val_if_fail (xid != None, NULL); window = - gst_vaapi_window_new_from_native (GST_VAAPI_WINDOW_CLASS - (gst_vaapi_window_glx_class ()), display, GINT_TO_POINTER (xid)); + gst_vaapi_window_new_internal (GST_VAAPI_WINDOW_CLASS + (gst_vaapi_window_glx_class ()), display, xid, 0, 0); if (!window) return NULL; diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_priv.h b/gst-libs/gst/vaapi/gstvaapiwindow_priv.h index fdc0937003..aac0361db5 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_priv.h +++ b/gst-libs/gst/vaapi/gstvaapiwindow_priv.h @@ -102,12 +102,8 @@ struct _GstVaapiWindowClass }; GstVaapiWindow * -gst_vaapi_window_new (const GstVaapiWindowClass * window_class, - GstVaapiDisplay * display, guint width, guint height); - -GstVaapiWindow * -gst_vaapi_window_new_from_native (const GstVaapiWindowClass * - window_class, GstVaapiDisplay * display, gpointer native_window); +gst_vaapi_window_new_internal (const GstVaapiWindowClass * window_class, + GstVaapiDisplay * display, guintptr handle, guint width, guint height); /* Inline reference counting for core libgstvaapi library */ #ifdef IN_LIBGSTVAAPI_CORE diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c index 28f7cce741..2c40e48895 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c @@ -545,7 +545,7 @@ gst_vaapi_window_wayland_new (GstVaapiDisplay * display, g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_WAYLAND (display), NULL); - return - gst_vaapi_window_new (GST_VAAPI_WINDOW_CLASS - (gst_vaapi_window_wayland_class ()), display, width, height); + return gst_vaapi_window_new_internal (GST_VAAPI_WINDOW_CLASS + (gst_vaapi_window_wayland_class ()), display, GST_VAAPI_ID_INVALID, width, + height); } diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_x11.c b/gst-libs/gst/vaapi/gstvaapiwindow_x11.c index 77ec6d5d63..18b361eff7 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_x11.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_x11.c @@ -565,8 +565,9 @@ gst_vaapi_window_x11_new (GstVaapiDisplay * display, guint width, guint height) g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_X11 (display), NULL); return - gst_vaapi_window_new (GST_VAAPI_WINDOW_CLASS (gst_vaapi_window_x11_class - ()), display, width, height); + gst_vaapi_window_new_internal (GST_VAAPI_WINDOW_CLASS + (gst_vaapi_window_x11_class ()), display, GST_VAAPI_ID_INVALID, width, + height); } /** @@ -589,9 +590,8 @@ gst_vaapi_window_x11_new_with_xid (GstVaapiDisplay * display, Window xid) g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_X11 (display), NULL); g_return_val_if_fail (xid != None, NULL); - return - gst_vaapi_window_new_from_native (GST_VAAPI_WINDOW_CLASS - (gst_vaapi_window_x11_class ()), display, GINT_TO_POINTER (xid)); + return gst_vaapi_window_new_internal (GST_VAAPI_WINDOW_CLASS + (gst_vaapi_window_x11_class ()), display, xid, 0, 0); } /**