Merge remote branch 'origin/master' into lp-binning
[mesa.git] / src / egl / main / eglsurface.c
index e7a1a8329e1807a24b15241e3807055a3ba01fb9..940a1b760cf1321844e7d52608deb464882f4580 100644 (file)
 #include "eglsurface.h"
 
 
+static void
+_eglClampSwapInterval(_EGLSurface *surf, EGLint interval)
+{
+   EGLint bound = GET_CONFIG_ATTRIB(surf->Config, EGL_MAX_SWAP_INTERVAL);
+   if (interval >= bound) {
+      interval = bound;
+   }
+   else {
+      bound = GET_CONFIG_ATTRIB(surf->Config, EGL_MIN_SWAP_INTERVAL);
+      if (interval < bound)
+         interval = bound;
+   }
+   surf->SwapInterval = interval;
+}
+
+
 /**
  * Do error check on parameters and initialize the given _EGLSurface object.
  * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
@@ -194,7 +210,9 @@ _eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
    surf->TextureTarget = texTarget;
    surf->MipmapTexture = mipmapTex;
    surf->MipmapLevel = 0;
-   surf->SwapInterval = 0;
+   /* the default swap interval is 1 */
+   _eglClampSwapInterval(surf, 1);
+
 #ifdef EGL_VERSION_1_2
    surf->SwapBehavior = EGL_BUFFER_DESTROYED; /* XXX ok? */
    surf->HorizontalResolution = EGL_UNKNOWN; /* set by caller */
@@ -466,11 +484,10 @@ _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface,
 
 
 EGLBoolean
-_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, EGLint interval)
+_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
+                 EGLint interval)
 {
-   _EGLSurface *surf = _eglGetCurrentSurface(EGL_DRAW);
-   if (surf)
-      surf->SwapInterval = interval;
+   _eglClampSwapInterval(surf, interval);
    return EGL_TRUE;
 }