DRI2/GLX: check for vblank_mode in DRI2 GLX code
authorJesse Barnes <jbarnes@virtuousgeek.org>
Thu, 22 Apr 2010 19:49:03 +0000 (12:49 -0700)
committerJesse Barnes <jbarnes@virtuousgeek.org>
Thu, 22 Apr 2010 19:49:45 +0000 (12:49 -0700)
Re-add support for the vblank_mode environment and configuration
variable.  Useful for benchmarking and app control.

src/glx/dri2_glx.c
src/mesa/drivers/dri/common/dri_util.c

index 3a53ce91b382a19aff115600c85eddafd2de94e2..1faaf08f36606c6b4ed24f49ac202719c8d02426 100644 (file)
 #include "xf86drm.h"
 #include "dri2.h"
 #include "dri_common.h"
-#include "../../mesa/drivers/dri/common/dri_util.h"
+
+/* From xmlpool/options.h, user exposed so should be stable */
+#define DRI_CONF_VBLANK_NEVER 0
+#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
+#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
+#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
 
 #undef DRI2_MINOR
 #define DRI2_MINOR 1
@@ -177,6 +182,7 @@ dri2CreateDrawable(__GLXscreenConfigs * psc,
    __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
    __GLXdisplayPrivate *dpyPriv;
    __GLXDRIdisplayPrivate *pdp;
+   GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
 
    pdraw = Xmalloc(sizeof(*pdraw));
    if (!pdraw)
@@ -187,7 +193,22 @@ dri2CreateDrawable(__GLXscreenConfigs * psc,
    pdraw->base.drawable = drawable;
    pdraw->base.psc = psc;
    pdraw->bufferCount = 0;
-   pdraw->swap_interval = 1;
+   pdraw->swap_interval = 1; /* default may be overridden below */
+
+   if (psc->config)
+      psc->config->configQueryi(psc->__driScreen, "vblank_mode", &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);
 
@@ -474,7 +495,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->config)
+      psc->config->configQueryi(psc->__driScreen, "vblank_mode", &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;
index 16d4cc5e174663302cf97a830b00d387c9b7ee14..8b3d8c27ce4e91e70775699293fc7b1848faf564 100644 (file)
 #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);