[Mesa-dev] [RFC PATCH] Add ability to use libXrandr for OML_sync_control

Matt Turner mattst88 at gmail.com
Tue Sep 20 12:37:20 PDT 2011


One more nail in the coffin of XF86VidMode.

Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
I'm not sure how to test this, but the translation from XF86VidMode
Xrandr seems to be pretty straightforward. Almost certainly there's
something wrong with it, as this is the first client-side X programming
I've done, and I'm specifically unsure about
	- checking for the appropriate Xrandr version.
	  XRRGetScreenResourcesCurrent is a 1.3 function. It's not totally
	  clear to me what the difference between it and XRRGetScreenResources
	  is. (These aren't documented in the man page)
	- How do I know the current mode? resource->modes[0] can't be right.

 configs/autoconf.in |    1 +
 configure.ac        |    7 +++++++
 scons/gallium.py    |    1 +
 src/glx/Makefile    |    8 ++++++--
 src/glx/SConscript  |    4 ++++
 src/glx/glxcmds.c   |   33 +++++++++++++++++++++++++++------
 6 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/configs/autoconf.in b/configs/autoconf.in
index 9bbafc9..8339049 100644
--- a/configs/autoconf.in
+++ b/configs/autoconf.in
@@ -226,4 +226,5 @@ ifneq ($(LLVM_VERSION),)
   DEFINES += -DHAVE_LLVM=$(HAVE_LLVM)
 endif
 
+HAVE_XRANDR = @HAVE_XRANDR@
 HAVE_XF86VIDMODE = @HAVE_XF86VIDMODE@
diff --git a/configure.ac b/configure.ac
index a686a11..0f4e868 100644
--- a/configure.ac
+++ b/configure.ac
@@ -966,6 +966,12 @@ xyesno)
     if test "$x11_pkgconfig" = yes; then
         dri_modules="x11 xext xdamage xfixes"
 
+        # add xrandr if available
+        PKG_CHECK_MODULES([XRANDR], [xrandr], HAVE_XRANDR=yes, HAVE_XRANDR=no)
+        if test "$HAVE_XRANDR" = yes ; then
+            dri_modules="$dri_modules xrandr"
+        fi
+
         # add xf86vidmode if available
         PKG_CHECK_MODULES([XF86VIDMODE], [xxf86vm], HAVE_XF86VIDMODE=yes, HAVE_XF86VIDMODE=no)
         if test "$HAVE_XF86VIDMODE" = yes ; then
@@ -1060,6 +1066,7 @@ AC_SUBST([DRI_CXXFLAGS])
 AC_SUBST([DRI_CFLAGS])
 AC_SUBST([MESA_MODULES])
 
+AC_SUBST([HAVE_XRANDR])
 AC_SUBST([HAVE_XF86VIDMODE])
 
 dnl
diff --git a/scons/gallium.py b/scons/gallium.py
index 1c9c0ea..8541d95 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -629,6 +629,7 @@ def generate(env):
     createInstallMethods(env)
 
     env.PkgCheckModules('X11', ['x11', 'xext', 'xdamage', 'xfixes'])
+    env.PkgCheckModules('XRANDR', ['xrandr'])
     env.PkgCheckModules('XF86VIDMODE', ['xxf86vm'])
     env.PkgCheckModules('DRM', ['libdrm'])
     env.PkgCheckModules('DRM_INTEL', ['libdrm_intel'])
diff --git a/src/glx/Makefile b/src/glx/Makefile
index dd96973..ef0bea0 100644
--- a/src/glx/Makefile
+++ b/src/glx/Makefile
@@ -1,12 +1,16 @@
 TOP = ../..
 include $(TOP)/configs/current
 
+ifeq ($(HAVE_XRANDR),yes)
+EXTRA_DEFINES_XRANDR = -DXRANDR
+endif
+
 ifeq ($(HAVE_XF86VIDMODE),yes)
 EXTRA_DEFINES_XF86VIDMODE = -DXF86VIDMODE
 endif
 
-EXTRA_DEFINES = $(EXTRA_DEFINES_XF86VIDMODE) -D_REENTRANT \
-                -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\"
+EXTRA_DEFINES = $(EXTRA_DEFINES_XF86VIDMODE) $(EXTRA_DEFINES_XRANDR) \
+                -D_REENTRANT -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\"
 
 SOURCES = \
 	  clientattrib.c \
diff --git a/src/glx/SConscript b/src/glx/SConscript
index afef337..ceccd21 100644
--- a/src/glx/SConscript
+++ b/src/glx/SConscript
@@ -29,6 +29,10 @@ env.Prepend(LIBS = [
 env.PkgUseModules('X11')
 env.PkgUseModules('DRM')
 
+if env['HAVE_XRANDR']:
+    env.Append(CPPDEFINES = ['XRANDR'])
+    env.PkgUseModules('XRANDR')
+
 if env['HAVE_XF86VIDMODE']:
     env.Append(CPPDEFINES = ['XF86VIDMODE'])
     env.PkgUseModules('XF86VIDMODE')
diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c
index c8ec9c2..e4c04e8 100644
--- a/src/glx/glxcmds.c
+++ b/src/glx/glxcmds.c
@@ -45,7 +45,9 @@
 #include "glx_error.h"
 #else
 #include <sys/time.h>
-#ifdef XF86VIDMODE
+#ifdef XRANDR
+#include <X11/extensions/Xrandr.h>
+#elif defined XF86VIDMODE
 #include <X11/extensions/xf86vmode.h>
 #endif
 #include "xf86dri.h"
@@ -2037,13 +2039,31 @@ _X_HIDDEN GLboolean
 __glxGetMscRate(__GLXDRIdrawable *glxDraw,
 		int32_t * numerator, int32_t * denominator)
 {
-#ifdef XF86VIDMODE
-   struct glx_screen *psc;
+#if defined XRANDR || defined XF86VIDMODE
+   struct glx_screen *psc = glxDraw->psc;
+   int i;
+#ifdef XRANDR
+   int event_base, error_base;
+   int major, minor;
+
+   if (XRRQueryExtension(psc->dpy, &event_base, &error_base) &&
+       XRRQueryVersion(psc->dpy, &major, &minor)) {
+      Window root = RootWindow(psc->dpy, DefaultScreen(psc->dpy));
+      XRRScreenResources *resource = XRRGetScreenResourcesCurrent(psc->dpy, root);
+
+      unsigned n = resource->modes[0].dotClock * 1000;
+      unsigned d = resource->modes[0].hTotal * resource->modes[0].vTotal;
+
+      if (resource->modes[0].modeFlags & RR_Interlace)
+         n *= 2;
+      else if (resource->modes[0].modeFlags & RR_DoubleScan)
+         d *= 2;
+
+      XRRFreeScreenResources(resource);
+#elif defined XF86VIDMODE
    XF86VidModeModeLine mode_line;
    int dot_clock;
-   int i;
 
-   psc = glxDraw->psc;
    if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
        XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
       unsigned n = dot_clock * 1000;
@@ -2056,6 +2076,7 @@ __glxGetMscRate(__GLXDRIdrawable *glxDraw,
          n *= 2;
       else if (mode_line.flags & V_DBLSCAN)
          d *= 2;
+#endif
 
       /* The OML_sync_control spec requires that if the refresh rate is a
        * whole number, that the returned numerator be equal to the refresh
@@ -2113,7 +2134,7 @@ _X_HIDDEN GLboolean
 __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
                    int32_t * numerator, int32_t * denominator)
 {
-#if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
+#if defined( GLX_DIRECT_RENDERING ) && (defined( XRANDR ) || defined( XF86VIDMODE ))
    __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
 
    if (draw == NULL)
-- 
1.7.3.4



More information about the mesa-dev mailing list