display: record native display object.

Record the underlying native display instance into the toplevel
GstVaapiDisplay object. This is useful for fast lookups to the
underlying native display, e.g. for creating an EGL display.
This commit is contained in:
Gwenole Beauchesne 2014-12-01 17:08:29 +01:00
parent 2fb20e9906
commit 1843774c0b
8 changed files with 47 additions and 60 deletions

View file

@ -906,6 +906,7 @@ gst_vaapi_display_create_unlocked (GstVaapiDisplay * display,
return FALSE;
priv->display = info.va_display;
priv->display_type = info.display_type;
priv->native_display = info.native_display;
if (klass->get_size)
klass->get_size (display, &priv->width, &priv->height);
if (klass->get_size_mm)

View file

@ -71,6 +71,17 @@ typedef GstVaapiTexture *(*GstVaapiDisplayCreateTextureFunc) (
GstVaapiDisplay * display, GstVaapiID id, guint target, guint format,
guint width, guint height);
/**
* GST_VAAPI_DISPLAY_NATIVE:
* @display_: a #GstVaapiDisplay
*
* Macro that evaluates to the native display of @display.
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_DISPLAY_NATIVE
#define GST_VAAPI_DISPLAY_NATIVE(display_) \
(GST_VAAPI_DISPLAY_GET_PRIVATE (display_)->native_display)
/**
* GST_VAAPI_DISPLAY_VADISPLAY:
* @display_: a #GstVaapiDisplay
@ -150,6 +161,7 @@ struct _GstVaapiDisplayPrivate
GstVaapiDisplayType display_type;
gchar *display_name;
VADisplay display;
gpointer native_display;
guint width;
guint height;
guint width_mm;

View file

@ -131,37 +131,14 @@ G_PASTE(t_n,_class) (void) \
GST_VAAPI_DISPLAY_VADISPLAY (GST_VAAPI_OBJECT_DISPLAY (object))
/**
* GST_VAAPI_OBJECT_XDISPLAY:
* GST_VAAPI_OBJECT_NATIVE_DISPLAY:
* @object: a #GstVaapiObject
*
* Macro that evaluates to the underlying X11 #Display of @display.
* This is an internal macro that does not do any run-time type check
* and requires #include "gstvaapidisplay_x11_priv.h".
* Macro that evaluates to the underlying native @display object.
* This is an internal macro that does not do any run-time type check.
*/
#define GST_VAAPI_OBJECT_XDISPLAY(object) \
GST_VAAPI_DISPLAY_XDISPLAY (GST_VAAPI_OBJECT_DISPLAY (object))
/**
* GST_VAAPI_OBJECT_XSCREEN:
* @object: a #GstVaapiObject
*
* Macro that evaluates to the underlying X11 screen of @display.
* This is an internal macro that does not do any run-time type check
* and requires #include "gstvaapidisplay_x11_priv.h".
*/
#define GST_VAAPI_OBJECT_XSCREEN(object) \
GST_VAAPI_DISPLAY_XSCREEN (GST_VAAPI_OBJECT_DISPLAY (object))
/**
* GST_VAAPI_OBJECT_WL_DISPLAY:
* @object: a #GstVaapiObject
*
* Macro that evaluates to the underlying #wl_display of @display.
* This is an internal macro that does not do any run-time type check
* and requires #include "gstvaapidisplay_wayland_priv.h".
*/
#define GST_VAAPI_OBJECT_WL_DISPLAY(object) \
GST_VAAPI_DISPLAY_WL_DISPLAY (GST_VAAPI_OBJECT_DISPLAY (object))
#define GST_VAAPI_OBJECT_NATIVE_DISPLAY(object) \
GST_VAAPI_DISPLAY_NATIVE (GST_VAAPI_OBJECT_DISPLAY (object))
/**
* GST_VAAPI_OBJECT_LOCK_DISPLAY:

View file

@ -58,14 +58,14 @@ gst_vaapi_pixmap_x11_create_from_xid(GstVaapiPixmap *pixmap, Pixmap xid)
return FALSE;
GST_VAAPI_OBJECT_LOCK_DISPLAY(pixmap);
success = x11_get_geometry(GST_VAAPI_OBJECT_XDISPLAY(pixmap), xid,
success = x11_get_geometry(GST_VAAPI_OBJECT_NATIVE_DISPLAY(pixmap), xid,
NULL, NULL, &pixmap->width, &pixmap->height, &depth);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(pixmap);
if (!success)
return FALSE;
pixmap->format = gst_vaapi_display_x11_get_pixmap_format(
GST_VAAPI_DISPLAY_X11(GST_VAAPI_OBJECT_DISPLAY(pixmap)), depth);
GST_VAAPI_OBJECT_DISPLAY_X11(pixmap), depth);
if (pixmap->format == GST_VIDEO_FORMAT_UNKNOWN)
return FALSE;
return TRUE;
@ -76,7 +76,7 @@ gst_vaapi_pixmap_x11_create(GstVaapiPixmap *pixmap)
{
GstVaapiDisplayX11 * const display =
GST_VAAPI_DISPLAY_X11(GST_VAAPI_OBJECT_DISPLAY(pixmap));
Display * const dpy = GST_VAAPI_DISPLAY_XDISPLAY(display);
Display * const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY(display);
Window rootwin;
Pixmap xid;
guint depth;
@ -90,7 +90,7 @@ gst_vaapi_pixmap_x11_create(GstVaapiPixmap *pixmap)
return FALSE;
GST_VAAPI_OBJECT_LOCK_DISPLAY(pixmap);
rootwin = RootWindow(dpy, GST_VAAPI_DISPLAY_XSCREEN(display));
rootwin = RootWindow(dpy, DefaultScreen(dpy));
xid = XCreatePixmap(dpy, rootwin, pixmap->width, pixmap->height, depth);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(pixmap);
@ -102,13 +102,12 @@ gst_vaapi_pixmap_x11_create(GstVaapiPixmap *pixmap)
static void
gst_vaapi_pixmap_x11_destroy(GstVaapiPixmap *pixmap)
{
Display * const dpy = GST_VAAPI_OBJECT_XDISPLAY(pixmap);
const Pixmap xid = GST_VAAPI_OBJECT_ID(pixmap);
if (xid) {
if (!pixmap->use_foreign_pixmap) {
GST_VAAPI_OBJECT_LOCK_DISPLAY(pixmap);
XFreePixmap(dpy, xid);
XFreePixmap(GST_VAAPI_OBJECT_NATIVE_DISPLAY(pixmap), xid);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(pixmap);
}
GST_VAAPI_OBJECT_ID(pixmap) = None;

View file

@ -129,18 +129,18 @@ static gboolean
create_objects (GstVaapiTextureGLX * texture, guint texture_id)
{
GstVaapiTexture *const base_texture = GST_VAAPI_TEXTURE (texture);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (texture);
GLContextState old_cs;
gboolean success = FALSE;
gl_get_current_context (&old_cs);
texture->gl_context = gl_create_context (GST_VAAPI_OBJECT_XDISPLAY (texture),
GST_VAAPI_OBJECT_XSCREEN (texture), &old_cs);
texture->gl_context = gl_create_context (dpy, DefaultScreen (dpy), &old_cs);
if (!texture->gl_context ||
!gl_set_current_context (texture->gl_context, NULL))
return FALSE;
texture->pixo = gl_create_pixmap_object (GST_VAAPI_OBJECT_XDISPLAY (texture),
texture->pixo = gl_create_pixmap_object (dpy,
base_texture->width, base_texture->height);
if (!texture->pixo) {
GST_ERROR ("failed to create GLX pixmap");

View file

@ -128,7 +128,7 @@ _gst_vaapi_window_glx_create_context (GstVaapiWindow * window,
{
GstVaapiWindowGLXPrivate *const priv =
GST_VAAPI_WINDOW_GLX_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
GLContextState parent_cs;
parent_cs.display = dpy;
@ -136,8 +136,7 @@ _gst_vaapi_window_glx_create_context (GstVaapiWindow * window,
parent_cs.context = foreign_context;
GST_VAAPI_OBJECT_LOCK_DISPLAY (window);
priv->gl_context = gl_create_context (dpy,
GST_VAAPI_OBJECT_XSCREEN (window), &parent_cs);
priv->gl_context = gl_create_context (dpy, DefaultScreen (dpy), &parent_cs);
if (!priv->gl_context) {
GST_DEBUG ("could not create GLX context");
goto end;
@ -223,7 +222,7 @@ gst_vaapi_window_glx_destroy_colormap (GstVaapiWindow * window)
{
GstVaapiWindowGLXPrivate *const priv =
GST_VAAPI_WINDOW_GLX_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
if (priv->cmap) {
if (!window->use_foreign_window) {
@ -240,8 +239,7 @@ gst_vaapi_window_glx_create_colormap (GstVaapiWindow * window)
{
GstVaapiWindowGLXPrivate *const priv =
GST_VAAPI_WINDOW_GLX_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
int screen;
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
XWindowAttributes wattr;
gboolean success = FALSE;
@ -252,9 +250,7 @@ gst_vaapi_window_glx_create_colormap (GstVaapiWindow * window)
GST_VAAPI_OBJECT_LOCK_DISPLAY (window);
x11_trap_errors ();
/* XXX: add a GstVaapiDisplayX11:x11-screen property? */
screen = GST_VAAPI_OBJECT_XSCREEN (window);
priv->cmap = XCreateColormap (dpy,
RootWindow (dpy, screen),
priv->cmap = XCreateColormap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
priv->gl_context->visual->visual, AllocNone);
success = x11_untrap_errors () == 0;
GST_VAAPI_OBJECT_UNLOCK_DISPLAY (window);
@ -285,7 +281,7 @@ gst_vaapi_window_glx_resize (GstVaapiWindow * window, guint width, guint height)
GST_VAAPI_WINDOW_GLX_GET_PRIVATE (window);
const GstVaapiWindowGLXClass *const klass =
GST_VAAPI_WINDOW_GLX_GET_CLASS (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
GLContextState old_cs;
if (!klass->parent_resize (window, width, height))

View file

@ -163,7 +163,8 @@ gst_vaapi_window_wayland_sync (GstVaapiWindow * window)
GST_VAAPI_WINDOW_WAYLAND_GET_PRIVATE (window);
if (priv->frame) {
struct wl_display *const wl_display = GST_VAAPI_OBJECT_WL_DISPLAY (window);
struct wl_display *const wl_display =
GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
do {
if (wl_display_dispatch_queue (wl_display, priv->event_queue) < 0)
@ -409,7 +410,8 @@ gst_vaapi_window_wayland_render (GstVaapiWindow * window,
GstVaapiWindowWaylandPrivate *const priv =
GST_VAAPI_WINDOW_WAYLAND_GET_PRIVATE (window);
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (window);
struct wl_display *const wl_display = GST_VAAPI_OBJECT_WL_DISPLAY (window);
struct wl_display *const wl_display =
GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
struct wl_buffer *buffer;
FrameState *frame;
guint width, height, va_flags;

View file

@ -52,7 +52,7 @@ send_wmspec_change_state (GstVaapiWindow * window, Atom state, gboolean add)
{
GstVaapiWindowX11Private *const priv =
GST_VAAPI_WINDOW_X11_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
XClientMessageEvent xclient;
memset (&xclient, 0, sizeof (xclient));
@ -77,7 +77,7 @@ send_wmspec_change_state (GstVaapiWindow * window, Atom state, gboolean add)
static void
wait_event (GstVaapiWindow * window, int type)
{
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window xid = GST_VAAPI_OBJECT_ID (window);
XEvent e;
Bool got_event;
@ -96,7 +96,7 @@ static gboolean
timed_wait_event (GstVaapiWindow * window, int type, guint64 end_time,
XEvent * e)
{
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window xid = GST_VAAPI_OBJECT_ID (window);
XEvent tmp_event;
GTimeVal now;
@ -130,7 +130,7 @@ gst_vaapi_window_x11_show (GstVaapiWindow * window)
{
GstVaapiWindowX11Private *const priv =
GST_VAAPI_WINDOW_X11_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window xid = GST_VAAPI_OBJECT_ID (window);
XWindowAttributes wattr;
gboolean has_errors;
@ -172,7 +172,7 @@ gst_vaapi_window_x11_hide (GstVaapiWindow * window)
{
GstVaapiWindowX11Private *const priv =
GST_VAAPI_WINDOW_X11_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window xid = GST_VAAPI_OBJECT_ID (window);
XWindowAttributes wattr;
gboolean has_errors;
@ -212,7 +212,7 @@ gst_vaapi_window_x11_create (GstVaapiWindow * window, guint * width,
{
GstVaapiWindowX11Private *const priv =
GST_VAAPI_WINDOW_X11_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
Window xid = GST_VAAPI_OBJECT_ID (window);
Visual *vis = NULL;
Colormap cmap = None;
@ -265,7 +265,7 @@ gst_vaapi_window_x11_create (GstVaapiWindow * window, guint * width,
static void
gst_vaapi_window_x11_destroy (GstVaapiWindow * window)
{
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window xid = GST_VAAPI_OBJECT_ID (window);
#ifdef HAVE_XRENDER
@ -293,7 +293,7 @@ static gboolean
gst_vaapi_window_x11_get_geometry (GstVaapiWindow * window,
gint * px, gint * py, guint * pwidth, guint * pheight)
{
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window xid = GST_VAAPI_OBJECT_ID (window);
gboolean success;
@ -309,7 +309,7 @@ gst_vaapi_window_x11_set_fullscreen (GstVaapiWindow * window,
{
GstVaapiWindowX11Private *const priv =
GST_VAAPI_WINDOW_X11_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window xid = GST_VAAPI_OBJECT_ID (window);
XEvent e;
guint width, height;
@ -379,7 +379,7 @@ gst_vaapi_window_x11_resize (GstVaapiWindow * window, guint width, guint height)
GST_VAAPI_OBJECT_LOCK_DISPLAY (window);
x11_trap_errors ();
XResizeWindow (GST_VAAPI_OBJECT_XDISPLAY (window),
XResizeWindow (GST_VAAPI_OBJECT_NATIVE_DISPLAY (window),
GST_VAAPI_OBJECT_ID (window), width, height);
has_errors = x11_untrap_errors () != 0;
GST_VAAPI_OBJECT_UNLOCK_DISPLAY (window);
@ -427,7 +427,7 @@ gst_vaapi_window_x11_render_pixmap_xrender (GstVaapiWindow * window,
#ifdef HAVE_XRENDER
GstVaapiWindowX11Private *const priv =
GST_VAAPI_WINDOW_X11_GET_PRIVATE (window);
Display *const dpy = GST_VAAPI_OBJECT_XDISPLAY (window);
Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (window);
const Window win = GST_VAAPI_OBJECT_ID (window);
const Pixmap pix = GST_VAAPI_OBJECT_ID (pixmap);
Picture picture;