egl: Rework eglSwapInterval.
authorChia-I Wu <olvaffe@gmail.com>
Thu, 15 Oct 2009 03:08:48 +0000 (11:08 +0800)
committerBrian Paul <brianp@vmware.com>
Thu, 15 Oct 2009 18:54:00 +0000 (12:54 -0600)
This adds error checking to eglSwapInterval and clamps the swap
interval.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
src/egl/main/eglapi.c
src/egl/main/eglapi.h
src/egl/main/eglsurface.c
src/egl/main/eglsurface.h

index 366901889fe7e67e9203af58e2b641ef66b1e74f..5ce04693519904095db09fc9d6514708851d7075 100644 (file)
@@ -520,8 +520,18 @@ eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
 EGLBoolean EGLAPIENTRY
 eglSwapInterval(EGLDisplay dpy, EGLint interval)
 {
 EGLBoolean EGLAPIENTRY
 eglSwapInterval(EGLDisplay dpy, EGLint interval)
 {
+   _EGLContext *ctx = _eglGetCurrentContext();
+   _EGLSurface *surf;
    _EGL_DECLARE_DD(dpy);
    _EGL_DECLARE_DD(dpy);
-   return drv->API.SwapInterval(drv, disp, interval);
+
+   if (!ctx || !_eglIsContextLinked(ctx) || ctx->Display != disp)
+      return _eglError(EGL_BAD_CONTEXT, __FUNCTION__);
+
+   surf = ctx->DrawSurface;
+   if (!_eglIsSurfaceLinked(surf))
+      return _eglError(EGL_BAD_SURFACE, __FUNCTION__);
+
+   return drv->API.SwapInterval(drv, disp, surf, interval);
 }
 
 
 }
 
 
index 6081e588928959ecca0f5d5a9973433763aa3b20..feb35c863c4165d7735758b5725224f0e9eb385f 100644 (file)
@@ -35,7 +35,7 @@ typedef EGLBoolean (*QuerySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurf
 typedef EGLBoolean (*SurfaceAttrib_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint value);
 typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer);
 typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer);
 typedef EGLBoolean (*SurfaceAttrib_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint value);
 typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer);
 typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer);
-typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint interval);
+typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
 typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw);
 typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, NativePixmapType target);
 
 typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw);
 typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, NativePixmapType target);
 
index e7a1a8329e1807a24b15241e3807055a3ba01fb9..940a1b760cf1321844e7d52608deb464882f4580 100644 (file)
 #include "eglsurface.h"
 
 
 #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.
 /**
  * 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->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 */
 #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
 
 
 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;
 }
 
    return EGL_TRUE;
 }
 
index f6d44b5922e0c826548bf4fc9cc6c2d178b9a317..b75fa9c3686643f5641ddb8337fd47180afa0b0b 100644 (file)
@@ -86,7 +86,7 @@ _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint
 
 
 extern EGLBoolean
 
 
 extern EGLBoolean
-_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, EGLint interval);
+_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
 
 
 #ifdef EGL_VERSION_1_2
 
 
 #ifdef EGL_VERSION_1_2