summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-09-06 11:50:21 +0200
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-09-06 13:39:50 +0200
commit30a8c566b7cfccc60ea4e8b4781c4176bb54f8b3 (patch)
tree60ceb26581faccfa9753dc4c3381819e097ff207
parent2a7cefab1a366ae27a65179cef72f1c6dce2f230 (diff)
display: fix physical display size when display is rotated.
-rw-r--r--configure.ac17
-rw-r--r--gst-libs/gst/vaapi/Makefile.am2
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay_x11.c54
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay_x11_priv.h1
4 files changed, 72 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 1f98001..227aa64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -312,6 +312,23 @@ if test "$enable_x11" = "yes"; then
fi
fi
+dnl Check for XRandR
+HAVE_XRANDR=0
+if test $USE_X11 -eq 1; then
+ HAVE_XRANDR=1
+ PKG_CHECK_MODULES([XRANDR], [xrandr], [:], [HAVE_XRANDR=0])
+ if test $HAVE_XRANDR -eq 1; then
+ saved_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $XRANDR_CFLAGS"
+ AC_CHECK_HEADERS([X11/extensions/Xrandr.h], [:], [HAVE_XRANDR=0])
+ CPPFLAGS="$saved_CPPFLAGS"
+ fi
+fi
+if test $HAVE_XRANDR -eq 1; then
+ AC_DEFINE_UNQUOTED(HAVE_XRANDR, 1,
+ [Defined to 1 if the XRandR extension exists.])
+fi
+
dnl OpenGL
enable_opengl="no"
if test "$enable_glx" = "yes"; then
diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am
index b93d9c3..7f645c8 100644
--- a/gst-libs/gst/vaapi/Makefile.am
+++ b/gst-libs/gst/vaapi/Makefile.am
@@ -278,12 +278,14 @@ libgstvaapi_x11_@GST_MAJORMINOR@_la_CFLAGS = \
$(GLIB_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(X11_CFLAGS) \
+ $(XRANDR_CFLAGS) \
$(LIBVA_X11_CFLAGS) \
$(NULL)
libgstvaapi_x11_@GST_MAJORMINOR@_la_LIBADD = \
$(GLIB_LIBS) \
$(X11_LIBS) \
+ $(XRANDR_LIBS) \
$(LIBVA_X11_LIBS) \
libgstvaapi-@GST_MAJORMINOR@.la \
$(NULL)
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c
index 1c89d15..f00b5af 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c
+++ b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c
@@ -32,6 +32,10 @@
#include "gstvaapidisplay_x11.h"
#include "gstvaapidisplay_x11_priv.h"
+#ifdef HAVE_XRANDR
+# include <X11/extensions/Xrandr.h>
+#endif
+
#define DEBUG 1
#include "gstvaapidebug.h"
@@ -265,6 +269,14 @@ gst_vaapi_display_x11_open_display(GstVaapiDisplay *display)
if (priv->synchronous)
XSynchronize(priv->x11_display, True);
+
+#ifdef HAVE_XRANDR
+ {
+ int evt_base, err_base;
+ priv->use_xrandr = XRRQueryExtension(
+ priv->x11_display, &evt_base, &err_base);
+ }
+#endif
return TRUE;
}
@@ -375,15 +387,52 @@ gst_vaapi_display_x11_get_size_mm(
{
GstVaapiDisplayX11Private * const priv =
GST_VAAPI_DISPLAY_X11(display)->priv;
+ guint width_mm, height_mm;
if (!priv->x11_display)
return;
+ width_mm = DisplayWidthMM(priv->x11_display, priv->x11_screen);
+ height_mm = DisplayHeightMM(priv->x11_display, priv->x11_screen);
+
+#ifdef HAVE_XRANDR
+ /* 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);
+ }
+#endif
+
if (pwidth)
- *pwidth = DisplayWidthMM(priv->x11_display, priv->x11_screen);
+ *pwidth = width_mm;
if (pheight)
- *pheight = DisplayHeightMM(priv->x11_display, priv->x11_screen);
+ *pheight = height_mm;
}
static void
@@ -476,6 +525,7 @@ gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
priv->x11_display = NULL;
priv->x11_screen = 0;
priv->display_name = NULL;
+ priv->use_xrandr = FALSE;
}
/**
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_x11_priv.h b/gst-libs/gst/vaapi/gstvaapidisplay_x11_priv.h
index a1b9213..bc04ecb 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay_x11_priv.h
+++ b/gst-libs/gst/vaapi/gstvaapidisplay_x11_priv.h
@@ -60,6 +60,7 @@ struct _GstVaapiDisplayX11Private {
int x11_screen;
guint create_display : 1;
guint synchronous : 1;
+ guint use_xrandr : 1;
};
G_END_DECLS