2010-01-25 16:15:01 +00:00
|
|
|
/*
|
|
|
|
* gstvaapidisplay_x11.c - VA/X11 display abstraction
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2013-11-22 05:37:12 +00:00
|
|
|
* Copyright (C) 2011-2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-01-25 16:15:01 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-01-25 16:15:01 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-01-25 16:15:01 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-05-03 07:07:27 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-01-25 16:15:01 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-01-25 16:15:01 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
2010-03-24 08:16:32 +00:00
|
|
|
* SECTION:gstvaapidisplay_x11
|
|
|
|
* @short_description: VA/X11 display abstraction
|
2010-03-19 15:45:21 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2012-01-12 14:03:04 +00:00
|
|
|
#include <string.h>
|
2010-03-16 09:15:48 +00:00
|
|
|
#include "gstvaapiutils.h"
|
2010-04-01 09:47:59 +00:00
|
|
|
#include "gstvaapidisplay_priv.h"
|
2010-04-01 13:41:24 +00:00
|
|
|
#include "gstvaapidisplay_x11.h"
|
|
|
|
#include "gstvaapidisplay_x11_priv.h"
|
2014-12-10 17:12:24 +00:00
|
|
|
#include "gstvaapiwindow_x11.h"
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2012-09-06 09:50:21 +00:00
|
|
|
#ifdef HAVE_XRANDR
|
|
|
|
# include <X11/extensions/Xrandr.h>
|
|
|
|
#endif
|
|
|
|
|
2013-07-22 07:00:38 +00:00
|
|
|
#ifdef HAVE_XRENDER
|
|
|
|
# include <X11/extensions/Xrender.h>
|
|
|
|
#endif
|
|
|
|
|
2016-10-13 03:53:17 +00:00
|
|
|
#define DEBUG_VAAPI_DISPLAY 1
|
2010-03-16 09:17:41 +00:00
|
|
|
#include "gstvaapidebug.h"
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2016-10-13 03:53:17 +00:00
|
|
|
#define _do_init \
|
|
|
|
G_ADD_PRIVATE (GstVaapiDisplayX11);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVaapiDisplayX11, gst_vaapi_display_x11,
|
|
|
|
GST_TYPE_VAAPI_DISPLAY, _do_init);
|
|
|
|
|
2014-12-10 17:02:55 +00:00
|
|
|
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_X11;
|
2013-05-27 11:17:31 +00:00
|
|
|
|
2014-07-25 08:55:53 +00:00
|
|
|
static gboolean
|
|
|
|
parse_display_name (const gchar * name, guint * len_ptr, guint * id_ptr,
|
|
|
|
guint * screen_ptr)
|
2012-01-12 14:03:04 +00:00
|
|
|
{
|
2014-07-25 08:55:53 +00:00
|
|
|
gulong len, id = 0, screen = 0;
|
|
|
|
gchar *end;
|
|
|
|
|
|
|
|
end = strchr (name, ':');
|
|
|
|
len = end ? end - name : strlen (name);
|
|
|
|
|
|
|
|
if (end) {
|
|
|
|
id = strtoul (&end[1], &end, 10);
|
|
|
|
if (*end == '.')
|
|
|
|
screen = strtoul (&end[1], &end, 10);
|
|
|
|
if (*end != '\0')
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-12 14:03:04 +00:00
|
|
|
|
2014-07-25 08:55:53 +00:00
|
|
|
if (len_ptr)
|
|
|
|
*len_ptr = len;
|
|
|
|
if (id_ptr)
|
|
|
|
*id_ptr = id;
|
|
|
|
if (screen_ptr)
|
|
|
|
*screen_ptr = screen;
|
|
|
|
return TRUE;
|
2012-01-12 14:03:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 14:19:23 +00:00
|
|
|
static gint
|
2013-12-20 12:27:07 +00:00
|
|
|
compare_display_name (gconstpointer a, gconstpointer b)
|
2012-01-12 14:03:04 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
const GstVaapiDisplayInfo *const info = a;
|
2014-07-25 08:55:53 +00:00
|
|
|
const gchar *const cached_name = info->display_name;
|
|
|
|
const gchar *const tested_name = b;
|
|
|
|
guint cached_name_length, cached_id;
|
|
|
|
guint tested_name_length, tested_id;
|
2013-12-20 12:27:07 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (cached_name, FALSE);
|
|
|
|
g_return_val_if_fail (tested_name, FALSE);
|
|
|
|
|
2014-07-25 08:55:53 +00:00
|
|
|
if (!parse_display_name (cached_name, &cached_name_length, &cached_id, NULL))
|
|
|
|
return FALSE;
|
|
|
|
if (!parse_display_name (tested_name, &tested_name_length, &tested_id, NULL))
|
|
|
|
return FALSE;
|
2013-12-20 12:27:07 +00:00
|
|
|
if (cached_name_length != tested_name_length)
|
|
|
|
return FALSE;
|
|
|
|
if (strncmp (cached_name, tested_name, cached_name_length) != 0)
|
|
|
|
return FALSE;
|
2014-07-25 08:55:53 +00:00
|
|
|
if (cached_id != tested_id)
|
|
|
|
return FALSE;
|
2013-12-20 12:27:07 +00:00
|
|
|
return TRUE;
|
2012-01-12 14:03:04 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 08:55:53 +00:00
|
|
|
static inline const gchar *
|
|
|
|
get_default_display_name (void)
|
|
|
|
{
|
|
|
|
static const gchar *g_display_name;
|
|
|
|
|
|
|
|
if (!g_display_name)
|
|
|
|
g_display_name = getenv ("DISPLAY");
|
|
|
|
return g_display_name;
|
|
|
|
}
|
|
|
|
|
2012-07-24 17:43:40 +00:00
|
|
|
/* Reconstruct a display name without our prefix */
|
|
|
|
static const gchar *
|
2013-12-20 12:27:07 +00:00
|
|
|
get_display_name (GstVaapiDisplayX11 * display)
|
2012-07-24 17:43:40 +00:00
|
|
|
{
|
2016-10-13 03:53:17 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv = display->priv;
|
2013-12-20 12:27:07 +00:00
|
|
|
const gchar *display_name = priv->display_name;
|
2012-07-24 17:43:40 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (!display_name || *display_name == '\0')
|
|
|
|
return NULL;
|
|
|
|
return display_name;
|
2012-07-24 17:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mangle display name with our prefix */
|
2013-05-07 09:39:34 +00:00
|
|
|
static gboolean
|
2013-12-20 12:27:07 +00:00
|
|
|
set_display_name (GstVaapiDisplayX11 * display, const gchar * display_name)
|
2010-03-11 15:01:00 +00:00
|
|
|
{
|
2016-10-13 03:53:17 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv = display->priv;
|
2010-03-11 15:01:00 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
g_free (priv->display_name);
|
2010-03-11 15:01:00 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (!display_name) {
|
|
|
|
display_name = get_default_display_name ();
|
|
|
|
if (!display_name)
|
|
|
|
display_name = "";
|
|
|
|
}
|
|
|
|
priv->display_name = g_strdup (display_name);
|
|
|
|
return priv->display_name != NULL;
|
2010-03-11 15:01:00 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 09:39:34 +00:00
|
|
|
/* Set synchronous behavious on the underlying X11 display */
|
2010-03-26 11:30:54 +00:00
|
|
|
static void
|
2013-12-20 12:27:07 +00:00
|
|
|
set_synchronous (GstVaapiDisplayX11 * display, gboolean synchronous)
|
2010-03-26 11:30:54 +00:00
|
|
|
{
|
2016-10-13 03:53:17 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv = display->priv;
|
2013-12-20 12:27:07 +00:00
|
|
|
|
|
|
|
if (priv->synchronous != synchronous) {
|
|
|
|
priv->synchronous = synchronous;
|
|
|
|
if (priv->x11_display) {
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
XSynchronize (priv->x11_display, synchronous);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
2010-03-26 11:30:54 +00:00
|
|
|
}
|
2013-12-20 12:27:07 +00:00
|
|
|
}
|
2010-03-26 11:30:54 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 07:00:38 +00:00
|
|
|
/* Check for display server extensions */
|
2010-03-11 15:01:00 +00:00
|
|
|
static void
|
2013-12-20 12:27:07 +00:00
|
|
|
check_extensions (GstVaapiDisplayX11 * display)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2016-10-13 03:53:17 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv = display->priv;
|
2013-12-20 12:27:07 +00:00
|
|
|
int evt_base, err_base;
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2013-07-22 07:00:38 +00:00
|
|
|
#ifdef HAVE_XRANDR
|
2013-12-20 12:27:07 +00:00
|
|
|
priv->use_xrandr = XRRQueryExtension (priv->x11_display,
|
|
|
|
&evt_base, &err_base);
|
2013-05-07 09:39:34 +00:00
|
|
|
#endif
|
2013-07-22 07:00:38 +00:00
|
|
|
#ifdef HAVE_XRENDER
|
2013-12-20 12:27:07 +00:00
|
|
|
priv->has_xrender = XRenderQueryExtension (priv->x11_display,
|
|
|
|
&evt_base, &err_base);
|
2013-07-22 07:00:38 +00:00
|
|
|
#endif
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 09:39:34 +00:00
|
|
|
static gboolean
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_bind_display (GstVaapiDisplay * base_display,
|
2013-05-07 09:39:34 +00:00
|
|
|
gpointer native_display)
|
2010-03-11 15:21:43 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11 *const display = GST_VAAPI_DISPLAY_X11_CAST (base_display);
|
2016-10-13 03:53:17 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv = display->priv;
|
2013-05-07 09:39:34 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
priv->x11_display = native_display;
|
|
|
|
priv->x11_screen = DefaultScreen (native_display);
|
|
|
|
priv->use_foreign_display = TRUE;
|
2010-03-11 15:21:43 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
check_extensions (display);
|
2010-03-11 15:35:43 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (!set_display_name (display, XDisplayString (priv->x11_display)))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2010-03-11 15:21:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-11 15:01:00 +00:00
|
|
|
static gboolean
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_open_display (GstVaapiDisplay * base_display,
|
|
|
|
const gchar * name)
|
2010-03-11 15:01:00 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11 *const display = GST_VAAPI_DISPLAY_X11_CAST (base_display);
|
2016-10-13 03:53:17 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv = display->priv;
|
|
|
|
|
2014-12-02 10:23:29 +00:00
|
|
|
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
2013-12-20 12:27:07 +00:00
|
|
|
const GstVaapiDisplayInfo *info;
|
2010-03-11 15:01:00 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (!set_display_name (display, name))
|
|
|
|
return FALSE;
|
2010-03-11 15:01:00 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
info = gst_vaapi_display_cache_lookup_custom (cache, compare_display_name,
|
2014-12-10 17:02:55 +00:00
|
|
|
priv->display_name, g_display_types);
|
2013-12-20 12:27:07 +00:00
|
|
|
if (info) {
|
|
|
|
priv->x11_display = info->native_display;
|
|
|
|
priv->use_foreign_display = TRUE;
|
|
|
|
} else {
|
|
|
|
priv->x11_display = XOpenDisplay (get_display_name (display));
|
|
|
|
if (!priv->x11_display)
|
|
|
|
return FALSE;
|
|
|
|
priv->use_foreign_display = FALSE;
|
|
|
|
}
|
|
|
|
priv->x11_screen = DefaultScreen (priv->x11_display);
|
2010-03-11 15:01:00 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
check_extensions (display);
|
|
|
|
return TRUE;
|
2010-03-11 15:01:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 11:35:20 +00:00
|
|
|
static void
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_close_display (GstVaapiDisplay * display)
|
2010-03-26 11:35:20 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
|
|
|
|
|
|
|
if (priv->pixmap_formats) {
|
|
|
|
g_array_free (priv->pixmap_formats, TRUE);
|
|
|
|
priv->pixmap_formats = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->x11_display) {
|
|
|
|
if (!priv->use_foreign_display)
|
|
|
|
XCloseDisplay (priv->x11_display);
|
|
|
|
priv->x11_display = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->display_name) {
|
|
|
|
g_free (priv->display_name);
|
|
|
|
priv->display_name = NULL;
|
|
|
|
}
|
2010-03-26 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_sync (GstVaapiDisplay * display)
|
2010-03-26 11:35:20 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
|
|
|
|
|
|
|
if (priv->x11_display) {
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
XSync (priv->x11_display, False);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
}
|
|
|
|
}
|
2010-03-26 11:35:20 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_display_x11_flush (GstVaapiDisplay * display)
|
|
|
|
{
|
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
|
|
|
|
|
|
|
if (priv->x11_display) {
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
XFlush (priv->x11_display);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
}
|
2010-03-26 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 14:03:04 +00:00
|
|
|
static gboolean
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_get_display_info (GstVaapiDisplay * display,
|
|
|
|
GstVaapiDisplayInfo * info)
|
2010-03-11 15:01:00 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
2014-12-02 10:23:29 +00:00
|
|
|
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
2013-12-20 12:27:07 +00:00
|
|
|
const GstVaapiDisplayInfo *cached_info;
|
|
|
|
|
|
|
|
/* Return any cached info even if child has its own VA display */
|
2014-03-07 13:50:14 +00:00
|
|
|
cached_info = gst_vaapi_display_cache_lookup_by_native_display (cache,
|
2014-12-10 17:02:55 +00:00
|
|
|
priv->x11_display, g_display_types);
|
2013-12-20 12:27:07 +00:00
|
|
|
if (cached_info) {
|
|
|
|
*info = *cached_info;
|
2012-01-12 14:03:04 +00:00
|
|
|
return TRUE;
|
2013-12-20 12:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, create VA display if there is none already */
|
|
|
|
info->native_display = priv->x11_display;
|
|
|
|
info->display_name = priv->display_name;
|
|
|
|
if (!info->va_display) {
|
|
|
|
info->va_display = vaGetDisplay (priv->x11_display);
|
|
|
|
if (!info->va_display)
|
|
|
|
return FALSE;
|
|
|
|
info->display_type = GST_VAAPI_DISPLAY_TYPE_X11;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2010-03-11 15:01:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-22 08:44:38 +00:00
|
|
|
static void
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_get_size (GstVaapiDisplay * display,
|
|
|
|
guint * pwidth, guint * pheight)
|
2010-03-22 08:44:38 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
2010-03-22 08:44:38 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (!priv->x11_display)
|
|
|
|
return;
|
2010-03-22 08:44:38 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (pwidth)
|
|
|
|
*pwidth = DisplayWidth (priv->x11_display, priv->x11_screen);
|
2010-03-22 08:44:38 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (pheight)
|
|
|
|
*pheight = DisplayHeight (priv->x11_display, priv->x11_screen);
|
2010-03-22 08:44:38 +00:00
|
|
|
}
|
|
|
|
|
2010-03-22 09:32:01 +00:00
|
|
|
static void
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_get_size_mm (GstVaapiDisplay * display,
|
|
|
|
guint * pwidth, guint * pheight)
|
2010-03-22 09:32:01 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
|
|
|
guint width_mm, height_mm;
|
2010-03-22 09:32:01 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (!priv->x11_display)
|
|
|
|
return;
|
2010-03-22 09:32:01 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
width_mm = DisplayWidthMM (priv->x11_display, priv->x11_screen);
|
|
|
|
height_mm = DisplayHeightMM (priv->x11_display, priv->x11_screen);
|
2012-09-06 09:50:21 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_XRANDR
|
2013-12-20 12:27:07 +00:00
|
|
|
/* XXX: fix up physical size if the display is rotated */
|
|
|
|
if (priv->use_xrandr) {
|
|
|
|
XRRScreenConfiguration *xrr_config = NULL;
|
|
|
|
XRRScreenSize *xrr_sizes;
|
|
|
|
Window win;
|
|
|
|
int num_xrr_sizes, size_id, screen;
|
|
|
|
Rotation rotation;
|
|
|
|
|
|
|
|
do {
|
|
|
|
win = DefaultRootWindow (priv->x11_display);
|
|
|
|
screen = XRRRootToScreen (priv->x11_display, win);
|
|
|
|
|
|
|
|
xrr_config = XRRGetScreenInfo (priv->x11_display, win);
|
|
|
|
if (!xrr_config)
|
|
|
|
break;
|
|
|
|
|
|
|
|
size_id = XRRConfigCurrentConfiguration (xrr_config, &rotation);
|
|
|
|
if (rotation == RR_Rotate_0 || rotation == RR_Rotate_180)
|
|
|
|
break;
|
|
|
|
|
|
|
|
xrr_sizes = XRRSizes (priv->x11_display, screen, &num_xrr_sizes);
|
|
|
|
if (!xrr_sizes || size_id >= num_xrr_sizes)
|
|
|
|
break;
|
|
|
|
|
|
|
|
width_mm = xrr_sizes[size_id].mheight;
|
|
|
|
height_mm = xrr_sizes[size_id].mwidth;
|
|
|
|
} while (0);
|
|
|
|
if (xrr_config)
|
|
|
|
XRRFreeScreenConfigInfo (xrr_config);
|
|
|
|
}
|
2012-09-06 09:50:21 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (pwidth)
|
|
|
|
*pwidth = width_mm;
|
2010-03-22 09:32:01 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (pheight)
|
|
|
|
*pheight = height_mm;
|
2010-03-22 09:32:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 17:12:24 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-07 09:39:34 +00:00
|
|
|
void
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_class_init (GstVaapiDisplayX11Class * klass)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayClass *const dpy_class = GST_VAAPI_DISPLAY_CLASS (klass);
|
|
|
|
|
2014-12-10 17:02:55 +00:00
|
|
|
dpy_class->display_type = GST_VAAPI_DISPLAY_TYPE_X11;
|
2013-12-20 12:27:07 +00:00
|
|
|
dpy_class->bind_display = gst_vaapi_display_x11_bind_display;
|
|
|
|
dpy_class->open_display = gst_vaapi_display_x11_open_display;
|
|
|
|
dpy_class->close_display = gst_vaapi_display_x11_close_display;
|
|
|
|
dpy_class->sync = gst_vaapi_display_x11_sync;
|
|
|
|
dpy_class->flush = gst_vaapi_display_x11_flush;
|
|
|
|
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;
|
2014-12-10 17:12:24 +00:00
|
|
|
dpy_class->create_window = gst_vaapi_display_x11_create_window;
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 03:53:17 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_display_x11_init (GstVaapiDisplayX11 * display)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2016-10-13 03:53:17 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
gst_vaapi_display_x11_get_instance_private (display);
|
2013-12-20 12:27:07 +00:00
|
|
|
|
2016-10-13 03:53:17 +00:00
|
|
|
display->priv = priv;
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_display_x11_new:
|
|
|
|
* @display_name: the X11 display name
|
|
|
|
*
|
|
|
|
* Opens an X11 #Display using @display_name and returns a newly
|
|
|
|
* allocated #GstVaapiDisplay object. The X11 display will be cloed
|
|
|
|
* when the reference count of the object reaches zero.
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated #GstVaapiDisplay object
|
|
|
|
*/
|
2010-03-11 15:01:00 +00:00
|
|
|
GstVaapiDisplay *
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_new (const gchar * display_name)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2016-10-13 03:53:17 +00:00
|
|
|
return gst_vaapi_display_new (g_object_new (GST_TYPE_VAAPI_DISPLAY_X11, NULL),
|
2013-12-20 12:27:07 +00:00
|
|
|
GST_VAAPI_DISPLAY_INIT_FROM_DISPLAY_NAME, (gpointer) display_name);
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_display_x11_new_with_display:
|
|
|
|
* @x11_display: an X11 #Display
|
|
|
|
*
|
|
|
|
* Creates a #GstVaapiDisplay based on the X11 @x11_display
|
|
|
|
* display. The caller still owns the display and must call
|
|
|
|
* XCloseDisplay() when all #GstVaapiDisplay references are
|
|
|
|
* released. Doing so too early can yield undefined behaviour.
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated #GstVaapiDisplay object
|
|
|
|
*/
|
2010-03-11 15:21:43 +00:00
|
|
|
GstVaapiDisplay *
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_new_with_display (Display * x11_display)
|
2010-03-11 15:21:43 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
g_return_val_if_fail (x11_display, NULL);
|
2010-04-01 13:41:24 +00:00
|
|
|
|
2016-10-13 03:53:17 +00:00
|
|
|
return gst_vaapi_display_new (g_object_new (GST_TYPE_VAAPI_DISPLAY_X11, NULL),
|
2013-12-20 12:27:07 +00:00
|
|
|
GST_VAAPI_DISPLAY_INIT_FROM_NATIVE_DISPLAY, x11_display);
|
2010-03-11 15:21:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_display_x11_get_display:
|
|
|
|
* @display: a #GstVaapiDisplayX11
|
|
|
|
*
|
|
|
|
* Returns the underlying X11 #Display that was created by
|
|
|
|
* gst_vaapi_display_x11_new() or that was bound from
|
|
|
|
* gst_vaapi_display_x11_new_with_display().
|
|
|
|
*
|
|
|
|
* Return value: the X11 #Display attached to @display
|
|
|
|
*/
|
2010-03-11 15:01:00 +00:00
|
|
|
Display *
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_get_display (GstVaapiDisplayX11 * display)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_X11 (display), NULL);
|
2010-03-10 12:25:19 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
return GST_VAAPI_DISPLAY_XDISPLAY (display);
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
2010-04-01 13:41:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_display_x11_get_screen:
|
|
|
|
* @display: a #GstVaapiDisplayX11
|
|
|
|
*
|
|
|
|
* Returns the default X11 screen that was created by
|
|
|
|
* gst_vaapi_display_x11_new() or that was bound from
|
|
|
|
* gst_vaapi_display_x11_new_with_display().
|
|
|
|
*
|
|
|
|
* Return value: the X11 #Display attached to @display
|
|
|
|
*/
|
|
|
|
int
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_get_screen (GstVaapiDisplayX11 * display)
|
2010-04-01 13:41:24 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_X11 (display), -1);
|
2010-04-01 13:41:24 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
return GST_VAAPI_DISPLAY_XSCREEN (display);
|
2013-05-07 09:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_display_x11_set_synchronous:
|
|
|
|
* @display: a #GstVaapiDisplayX11
|
|
|
|
* @synchronous: boolean value that indicates whether to enable or
|
|
|
|
* disable synchronization
|
|
|
|
*
|
|
|
|
* If @synchronous is %TRUE, gst_vaapi_display_x11_set_synchronous()
|
|
|
|
* turns on synchronous behaviour on the underlying X11
|
|
|
|
* display. Otherwise, synchronous behaviour is disabled if
|
|
|
|
* @synchronous is %FALSE.
|
|
|
|
*/
|
|
|
|
void
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_set_synchronous (GstVaapiDisplayX11 * display,
|
2013-05-07 09:39:34 +00:00
|
|
|
gboolean synchronous)
|
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
g_return_if_fail (GST_VAAPI_IS_DISPLAY_X11 (display));
|
2013-05-07 09:39:34 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
set_synchronous (display, synchronous);
|
2010-04-01 13:41:24 +00:00
|
|
|
}
|
2013-07-19 13:05:34 +00:00
|
|
|
|
|
|
|
typedef struct _GstVaapiPixmapFormatX11 GstVaapiPixmapFormatX11;
|
2013-12-20 12:27:07 +00:00
|
|
|
struct _GstVaapiPixmapFormatX11
|
|
|
|
{
|
|
|
|
GstVideoFormat format;
|
|
|
|
gint depth;
|
|
|
|
gint bpp;
|
2013-07-19 13:05:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstVideoFormat
|
2013-12-20 12:27:07 +00:00
|
|
|
pix_fmt_to_video_format (gint depth, gint bpp)
|
2013-07-19 13:05:34 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
|
2013-07-19 13:05:34 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
switch (bpp) {
|
2013-07-19 13:05:34 +00:00
|
|
|
case 16:
|
2013-12-20 12:27:07 +00:00
|
|
|
if (depth == 15)
|
|
|
|
format = GST_VIDEO_FORMAT_RGB15;
|
|
|
|
else if (depth == 16)
|
|
|
|
format = GST_VIDEO_FORMAT_RGB16;
|
|
|
|
break;
|
2013-07-19 13:05:34 +00:00
|
|
|
case 24:
|
2013-12-20 12:27:07 +00:00
|
|
|
if (depth == 24)
|
|
|
|
format = GST_VIDEO_FORMAT_RGB;
|
|
|
|
break;
|
2013-07-19 13:05:34 +00:00
|
|
|
case 32:
|
2013-12-20 12:27:07 +00:00
|
|
|
if (depth == 24 || depth == 32)
|
|
|
|
format = GST_VIDEO_FORMAT_xRGB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return format;
|
2013-07-19 13:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-12-20 12:27:07 +00:00
|
|
|
ensure_pix_fmts (GstVaapiDisplayX11 * display)
|
2013-07-19 13:05:34 +00:00
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
|
|
|
XPixmapFormatValues *pix_fmts;
|
|
|
|
int i, n, num_pix_fmts;
|
2013-07-19 13:05:34 +00:00
|
|
|
|
2013-12-20 12:27:07 +00:00
|
|
|
if (priv->pixmap_formats)
|
2013-07-19 13:05:34 +00:00
|
|
|
return TRUE;
|
2013-12-20 12:27:07 +00:00
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
pix_fmts = XListPixmapFormats (GST_VAAPI_DISPLAY_XDISPLAY (display),
|
|
|
|
&num_pix_fmts);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!pix_fmts)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
priv->pixmap_formats = g_array_sized_new (FALSE, FALSE,
|
|
|
|
sizeof (GstVaapiPixmapFormatX11), num_pix_fmts);
|
|
|
|
if (!priv->pixmap_formats) {
|
|
|
|
XFree (pix_fmts);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, n = 0; i < num_pix_fmts; i++) {
|
|
|
|
GstVaapiPixmapFormatX11 *const pix_fmt =
|
|
|
|
&g_array_index (priv->pixmap_formats, GstVaapiPixmapFormatX11, n);
|
|
|
|
|
|
|
|
pix_fmt->depth = pix_fmts[i].depth;
|
|
|
|
pix_fmt->bpp = pix_fmts[i].bits_per_pixel;
|
|
|
|
pix_fmt->format = pix_fmt_to_video_format (pix_fmt->depth, pix_fmt->bpp);
|
|
|
|
if (pix_fmt->format != GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
priv->pixmap_formats->len = n;
|
|
|
|
return TRUE;
|
2013-07-19 13:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the GstVideoFormat based on a supported Pixmap depth */
|
|
|
|
GstVideoFormat
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_get_pixmap_format (GstVaapiDisplayX11 * display,
|
2013-07-19 13:05:34 +00:00
|
|
|
guint depth)
|
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
if (ensure_pix_fmts (display)) {
|
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->pixmap_formats->len; i++) {
|
|
|
|
GstVaapiPixmapFormatX11 *const pix_fmt =
|
|
|
|
&g_array_index (priv->pixmap_formats, GstVaapiPixmapFormatX11, i);
|
|
|
|
if (pix_fmt->depth == depth)
|
|
|
|
return pix_fmt->format;
|
2013-07-19 13:05:34 +00:00
|
|
|
}
|
2013-12-20 12:27:07 +00:00
|
|
|
}
|
|
|
|
return GST_VIDEO_FORMAT_UNKNOWN;
|
2013-07-19 13:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the Pixmap depth based on a GstVideoFormat */
|
|
|
|
guint
|
2013-12-20 12:27:07 +00:00
|
|
|
gst_vaapi_display_x11_get_pixmap_depth (GstVaapiDisplayX11 * display,
|
2013-07-19 13:05:34 +00:00
|
|
|
GstVideoFormat format)
|
|
|
|
{
|
2013-12-20 12:27:07 +00:00
|
|
|
if (ensure_pix_fmts (display)) {
|
|
|
|
GstVaapiDisplayX11Private *const priv =
|
|
|
|
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->pixmap_formats->len; i++) {
|
|
|
|
GstVaapiPixmapFormatX11 *const pix_fmt =
|
|
|
|
&g_array_index (priv->pixmap_formats, GstVaapiPixmapFormatX11, i);
|
|
|
|
if (pix_fmt->format == format)
|
|
|
|
return pix_fmt->depth;
|
2013-07-19 13:05:34 +00:00
|
|
|
}
|
2013-12-20 12:27:07 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2013-07-19 13:05:34 +00:00
|
|
|
}
|