egl: Use SConscript for Windows build.
[mesa.git] / src / egl / main / eglapi.c
index 647be652207ec060755a4abf70dfa7fe6e59de7b..9912043e06c61eab3103586f0fd2768de173aea0 100644 (file)
@@ -56,6 +56,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#include "eglstring.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
 #include "egltypedefs.h"
@@ -261,7 +263,7 @@ EGLBoolean EGLAPIENTRY
 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
 {
    _EGLDisplay *disp = _eglLockDisplay(dpy);
-   EGLint major_int, minor_int;
+   EGLint major_int = 0, minor_int = 0;
 
    if (!disp)
       RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
@@ -272,17 +274,19 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
       if (!drv) {
          _eglPreloadDrivers();
          drv = _eglMatchDriver(disp);
-         if (!drv)
-            RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
+        /* Initialize the particular display now */
+        if (drv && !drv->API.Initialize(drv, disp, &major_int, &minor_int))
+           RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
       }
-
-      /* Initialize the particular display now */
-      if (!drv->API.Initialize(drv, disp, &major_int, &minor_int))
-         RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
+      if (!drv)
+        /* Load and initialize the first default driver that works */
+        drv = _eglLoadDefaultDriver(disp, &major_int, &minor_int);
+      if (!drv)
+        RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
 
       disp->APImajor = major_int;
       disp->APIminor = minor_int;
-      snprintf(disp->Version, sizeof(disp->Version),
+      _eglsnprintf(disp->Version, sizeof(disp->Version),
                "%d.%d (%s)", major_int, minor_int, drv->Name);
 
       /* limit to APIs supported by core */
@@ -836,6 +840,9 @@ eglGetProcAddress(const char *procname)
       { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
       { "eglDestroyImageKHR", (_EGLProc) eglDestroyImageKHR },
 #endif /* EGL_KHR_image_base */
+#ifdef EGL_NOK_swap_region
+      { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK },
+#endif
       { NULL, NULL }
    };
    EGLint i;
@@ -1244,3 +1251,32 @@ eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
 
 
 #endif /* EGL_KHR_image_base */
+
+
+#ifdef EGL_NOK_swap_region
+
+EGLBoolean
+eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface,
+                       EGLint numRects, const EGLint *rects)
+{
+   _EGLContext *ctx = _eglGetCurrentContext();
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLSurface *surf = _eglLookupSurface(surface, disp);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
+
+   /* surface must be bound to current context in EGL 1.4 */
+   if (!ctx || !_eglIsContextLinked(ctx) || surf != ctx->DrawSurface)
+      RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
+
+   if (drv->API.SwapBuffersRegionNOK)
+      ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects);
+   else
+      ret = drv->API.SwapBuffers(drv, disp, surf);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
+#endif /* EGL_NOK_swap_region */