[Mesa-dev] [PATCH] dri2: add vblank_mode support

Jesse Barnes jbarnes at virtuousgeek.org
Thu Apr 22 11:28:55 PDT 2010


On Tue, 20 Apr 2010 11:35:11 -0700
Jesse Barnes <jbarnes at virtuousgeek.org> wrote:

> This patch adds vblank_mode support to DRI2, for direct rendered
> clients only.  It does this by adding some DRI options parsing at DRI2
> screen creation time, and some checking for the current vblank mode to
> dri2_glx.c.
> 
> Fixes fdo bug #27656.

This one fixes the layering violations, and makes things more generic.

any thoughts?

-- 
Jesse Barnes, Intel Open Source Technology Center

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index fa9b7c4..eb7f2e1 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -736,7 +736,7 @@ struct __DRIdri2LoaderExtensionRec {
  * constructors for DRI2.
  */
 #define __DRI_DRI2 "DRI_DRI2"
-#define __DRI_DRI2_VERSION 1
+#define __DRI_DRI2_VERSION 2
 
 struct __DRIdri2ExtensionRec {
     __DRIextension base;
@@ -755,6 +755,11 @@ struct __DRIdri2ExtensionRec {
 				      __DRIcontext *shared,
 				      void *loaderPrivate);
 
+    GLboolean *(*configQueryb)(__DRIscreen *screen, const char *var);
+
+    GLint *(*configQueryi)(__DRIscreen *screen, const char *var);
+
+    GLfloat *(*configQueryf)(__DRIscreen *screen, const char *var);
 };
 
 
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 3a53ce9..9ec67bf 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -48,6 +48,7 @@
 #include "dri2.h"
 #include "dri_common.h"
 #include "../../mesa/drivers/dri/common/dri_util.h"
+#include "../../mesa/drivers/dri/common/xmlpool/options.h"
 
 #undef DRI2_MINOR
 #define DRI2_MINOR 1
@@ -177,6 +178,7 @@ dri2CreateDrawable(__GLXscreenConfigs * psc,
    __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
    __GLXdisplayPrivate *dpyPriv;
    __GLXDRIdisplayPrivate *pdp;
+   GLuint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
 
    pdraw = Xmalloc(sizeof(*pdraw));
    if (!pdraw)
@@ -189,6 +191,21 @@ dri2CreateDrawable(__GLXscreenConfigs * psc,
    pdraw->bufferCount = 0;
    pdraw->swap_interval = 1;
 
+   if (psc->dri2->base.version >= 2)
+      vblank_mode = psc->dri2->configQueryi(psc->__driScreen, "vblank_mode");
+
+   switch (vblank_mode) {
+   case DRI_CONF_VBLANK_NEVER:
+   case DRI_CONF_VBLANK_DEF_INTERVAL_0:
+      pdraw->swap_interval = 0;
+      break;
+   case DRI_CONF_VBLANK_DEF_INTERVAL_1:
+   case DRI_CONF_VBLANK_ALWAYS_SYNC:
+   default:
+      pdraw->swap_interval = 1;
+      break;
+   }
+
    DRI2CreateDrawable(psc->dpy, xDrawable);
 
    dpyPriv = __glXInitialize(psc->dpy);
@@ -474,7 +491,23 @@ dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
 static void
 dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
 {
+   __GLXscreenConfigs *psc = pdraw->psc;
    __GLXDRIdrawablePrivate *priv =  (__GLXDRIdrawablePrivate *) pdraw;
+   GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
+
+   if (psc->dri2->base.version >= 2)
+      vblank_mode = psc->dri2->configQueryi(psc->__driScreen, "vblank_mode");
+
+   switch (vblank_mode) {
+   case DRI_CONF_VBLANK_NEVER:
+      return;
+   case DRI_CONF_VBLANK_ALWAYS_SYNC:
+      if (interval <= 0)
+	 return;
+      break;
+   default:
+      break;
+   }
 
    DRI2SwapInterval(priv->base.psc->dpy, pdraw->xDrawable, interval);
    priv->swap_interval = interval;
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index f1bbd38..bdb07b3 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -31,6 +31,17 @@
 #include "dri_util.h"
 #include "drm_sarea.h"
 #include "utils.h"
+#include "vblank.h"
+#include "xmlpool.h"
+
+PUBLIC const char __dri2ConfigOptions[] =
+   DRI_CONF_BEGIN
+      DRI_CONF_SECTION_PERFORMANCE
+         DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1)
+      DRI_CONF_SECTION_END
+   DRI_CONF_END;
+
+static const uint __dri2NConfigOptions = 1;
 
 #ifndef GLX_OML_sync_control
 typedef GLboolean ( * PFNGLXGETMSCRATEOMLPROC) (__DRIdrawable *drawable, int32_t *numerator, int32_t *denominator);
@@ -467,6 +478,25 @@ dri2CreateNewDrawable(__DRIscreen *screen,
     return pdraw;
 }
 
+static GLboolean
+dri2ConfigQueryb(__DRIscreen *screen, const char *var)
+{
+    return driQueryOptionb(&screen->optionCache, var);
+}
+
+static GLint
+dri2ConfigQueryi(__DRIscreen *screen, const char *var)
+{
+    return driQueryOptioni(&screen->optionCache, var);
+}
+
+static GLfloat
+dri2ConfigQueryf(__DRIscreen *screen, const char *var)
+{
+    return driQueryOptionf(&screen->optionCache, var);
+}
+
+
 static void dri_get_drawable(__DRIdrawable *pdp)
 {
     pdp->refcount++;
@@ -739,6 +769,7 @@ dri2CreateNewScreen(int scrn, int fd,
     static const __DRIextension *emptyExtensionList[] = { NULL };
     __DRIscreen *psp;
     drmVersionPtr version;
+    driOptionCache options;
 
     if (driDriverAPI.InitScreen2 == NULL)
         return NULL;
@@ -771,6 +802,9 @@ dri2CreateNewScreen(int scrn, int fd,
 
     psp->DriverAPI = driDriverAPI;
 
+    driParseOptionInfo(&options, __dri2ConfigOptions, __dri2NConfigOptions);
+    driParseConfigFiles(&psp->optionCache, &options, psp->myNum, "dri2");
+
     return psp;
 }
 
@@ -811,6 +845,9 @@ const __DRIdri2Extension driDRI2Extension = {
     dri2CreateNewScreen,
     dri2CreateNewDrawable,
     dri2CreateNewContext,
+    dri2ConfigQueryb,
+    dri2ConfigQueryi,
+    dri2ConfigQueryf,
 };
 
 static int
diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h
index 038a816..0d106d6 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -51,6 +51,7 @@
 #include <drm.h>
 #include <drm_sarea.h>
 #include <xf86drm.h>
+#include "xmlconfig.h"
 #include "main/glheader.h"
 #include "GL/internal/glcore.h"
 #include "GL/internal/dri_interface.h"
@@ -527,6 +528,8 @@ struct __DRIscreenRec {
 
     /* The lock actually in use, old sarea or DRI2 */
     drmLock *lock;
+
+    driOptionCache optionCache;
 };
 
 extern void



More information about the mesa-dev mailing list