egl: Return the same EGL Display for the same native display.
authorChia-I Wu <olvaffe@gmail.com>
Fri, 17 Jul 2009 04:21:56 +0000 (21:21 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 17 Jul 2009 17:53:39 +0000 (11:53 -0600)
The latest revision of the spec explicitly requires the same handle to
be returned for the same native display.

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

index eaee9facd82f1a360f3a7d74760cf1f3c3343e2c..f0a6f7f935569c43e8334adbf719ca0f90d1b3ec 100644 (file)
@@ -51,9 +51,12 @@ eglGetDisplay(NativeDisplayType nativeDisplay)
 {
    _EGLDisplay *dpy;
    _eglInitGlobals();
-   dpy = _eglNewDisplay(nativeDisplay);
-   if (dpy)
-      _eglLinkDisplay(dpy);
+   dpy = _eglFindDisplay(nativeDisplay);
+   if (!dpy) {
+      dpy = _eglNewDisplay(nativeDisplay);
+      if (dpy)
+         _eglLinkDisplay(dpy);
+   }
    return _eglGetDisplayHandle(dpy);
 }
 
index a30e810b4a5e91249939c527ce389bc578f2af89..1f1f41ea71f769a48c1eaa692eef2fdbb7a9084c 100644 (file)
@@ -96,6 +96,30 @@ _eglLookupDisplay(EGLDisplay dpy)
 }
 
 
+/**
+ * Find the display corresponding to the specified native display id in all
+ * linked displays.
+ */
+_EGLDisplay *
+_eglFindDisplay(NativeDisplayType nativeDisplay)
+{
+   EGLuint key = _eglHashFirstEntry(_eglGlobal.Displays);
+
+   /* Walk the hash table.  Should switch to list if it is a problem. */
+   while (key) {
+      _EGLDisplay *dpy = (_EGLDisplay *)
+            _eglHashLookup(_eglGlobal.Displays, key);
+      assert(dpy);
+
+      if (dpy->NativeDisplay == nativeDisplay)
+         return dpy;
+      key = _eglHashNextEntry(_eglGlobal.Displays, key);
+   }
+
+   return NULL;
+}
+
+
 /**
  * Free all the data hanging of an _EGLDisplay object, but not
  * the object itself.
index ac285f52a7e629ccda2fffed3c6683a1c64ca2f3..0a6003f39eafcdbea727a0d6fc83eef00513fa2b 100644 (file)
@@ -52,6 +52,10 @@ extern _EGLDisplay *
 _eglLookupDisplay(EGLDisplay dpy);
 
 
+extern _EGLDisplay *
+_eglFindDisplay(NativeDisplayType nativeDisplay);
+
+
 extern void
 _eglCleanupDisplay(_EGLDisplay *disp);