On Fri, Aug 14, 2009 at 03:03:02PM +0100, Keith Whitwell wrote:
> Regarding 0006-progs-egl-Fix-compilation-error-of-demo3.patch:
> In general it is preferable not to introduce compilation errors into the
> git history, at least knowingly.  Can you respin your patch series to
> not introduce the error in the first place?
Sure, sorry about that.  This patch series reflects my git history, and
as you said, it is better not to introduce build error.  I have the
updated patch series attached.
> I think I saw this in a previous series from you, that compilation broke
> in one patch & was fixed in a subsequent one in the series.  That's a
> pain later on if someone tries to bisect & lands at your broken patch...
Regarding the api overhaul series, I intended to split them in a way
that I assume is easier to review.  Logically, it changes only one
thing: eglapi.c.  I want to add a check to functions in it.  But the
result is that I have to update many files and drivers.  If I were to
try not break the build, I would have to either submit a single big
patch, or many small ones each touches many files cross the tree.
Either way, they are harder to read.

As for driver/display series, I will update it after I receive more
comments.  This is to avoid it from reaching version 6 or something too
soon :)

-- 
Regards,
olv
>From 989aed2ffe8a5f972bbbf08c6376aba36c1e7db4 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Fri, 14 Aug 2009 17:29:23 +0800
Subject: [PATCH 1/5] egl: Remove hash table for surfaces.

The hash table was used to map a surface to a handle.  It is simpler to
cast directly.

Signed-off-by: Chia-I Wu <[email protected]>
---
 src/egl/main/egldisplay.c |   35 ++++++-----------------------------
 src/egl/main/egldisplay.h |    3 ---
 src/egl/main/eglsurface.h |    1 -
 3 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 0693f25..7f2d035 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -18,8 +18,6 @@
 
 static _EGL_DECLARE_MUTEX(_eglDisplayInitMutex);
 static _EGLHashtable *_eglDisplayHash;
-/* TODO surface hash table should be per-display */
-static _EGLHashtable *_eglSurfaceHash;
 
 
 /**
@@ -47,8 +45,6 @@ _eglFiniDisplay(void)
 
       _eglDeleteHashTable(_eglDisplayHash);
       _eglDisplayHash = NULL;
-      _eglDeleteHashTable(_eglSurfaceHash);
-      _eglSurfaceHash = NULL;
    }
    _eglUnlockMutex(&_eglDisplayInitMutex);
 }
@@ -64,7 +60,6 @@ _eglInitDisplay(void)
       /* check again after acquiring lock */
       if (!_eglDisplayHash) {
          _eglDisplayHash = _eglNewHashTable();
-         _eglSurfaceHash = _eglNewHashTable();
 
          _eglAddAtExitCall(_eglFiniDisplay);
       }
@@ -90,9 +85,6 @@ _eglNewDisplay(NativeDisplayType nativeDisplay)
       dpy->Xdpy = (Display *) nativeDisplay;
 #endif
 
-      _eglInitDisplay();
-      dpy->SurfaceHash = _eglSurfaceHash;
-
       dpy->DriverName = _eglPreloadDriver(dpy);
       if (!dpy->DriverName) {
          free(dpy);
@@ -319,18 +311,10 @@ _eglLookupContext(EGLContext ctx, _EGLDisplay *dpy)
 EGLSurface
 _eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy)
 {
-   EGLuint key;
-
    surf->Display = dpy;
    surf->Next = dpy->SurfaceList;
    dpy->SurfaceList = surf;
-
-   key = _eglHashGenKey(dpy->SurfaceHash);
-   assert(key);
-   _eglHashInsert(dpy->SurfaceHash, key, surf);
-
-   surf->Handle = (EGLSurface) _eglUIntToPointer(key);
-   return surf->Handle;
+   return (EGLSurface) surf;
 }
 
 
@@ -342,10 +326,6 @@ void
 _eglUnlinkSurface(_EGLSurface *surf)
 {
    _EGLSurface *prev;
-   EGLuint key = _eglPointerToUInt((void *) surf->Handle);
-
-   _eglHashRemove(surf->Display->SurfaceHash, key);
-   surf->Handle = EGL_NO_SURFACE;
 
    prev = surf->Display->SurfaceList;
    if (prev != surf) {
@@ -371,12 +351,9 @@ _eglUnlinkSurface(_EGLSurface *surf)
  * Return the handle of a linked surface, or EGL_NO_SURFACE.
  */
 EGLSurface
-_eglGetSurfaceHandle(_EGLSurface *surface)
+_eglGetSurfaceHandle(_EGLSurface *surf)
 {
-   if (surface)
-      return surface->Handle;
-   else
-      return EGL_NO_SURFACE;
+   return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
 }
 
 
@@ -385,8 +362,8 @@ _eglGetSurfaceHandle(_EGLSurface *surface)
  * Return NULL if the handle has no corresponding linked surface.
  */
 _EGLSurface *
-_eglLookupSurface(EGLSurface surf, _EGLDisplay *dpy)
+_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
 {
-   EGLuint key = _eglPointerToUInt((void *) surf);
-   return (_EGLSurface *) _eglHashLookup(dpy->SurfaceHash, key);
+   _EGLSurface *surf = (_EGLSurface *) surface;
+   return (surf && surf->Display) ? surf : NULL;
 }
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index e1cbbac..dfc54f1 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -52,9 +52,6 @@ struct _egl_display
    _EGLContext *ContextList;
    _EGLSurface *SurfaceList;
 
-   /* hash table to map surfaces to handles */
-   _EGLHashtable *SurfaceHash;
-
 #ifdef _EGL_PLATFORM_X
    Display *Xdpy;
 #endif
diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h
index cfae697..f6d44b5 100644
--- a/src/egl/main/eglsurface.h
+++ b/src/egl/main/eglsurface.h
@@ -13,7 +13,6 @@ struct _egl_surface
    /* Managed by EGLDisplay for linking */
    _EGLDisplay *Display;
    _EGLSurface *Next;
-   EGLSurface Handle;
 
    /* The bound status of the surface */
    _EGLContext *Binding;
-- 
1.6.3.3

>From deca3d4cdb47556b2ef642e0acf239a9f683cc3a Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Fri, 14 Aug 2009 17:47:00 +0800
Subject: [PATCH 2/5] egl: Remove hash table for displays.

The hash table was used to map a display to a handle.  It is simpler to
cast directly.

Signed-off-by: Chia-I Wu <[email protected]>
---
 src/egl/main/egldisplay.c |  124 ++++++++++++++++++---------------------------
 src/egl/main/egldisplay.h |    8 +++-
 src/egl/main/eglglobals.c |    4 +-
 src/egl/main/eglglobals.h |    6 ++-
 4 files changed, 64 insertions(+), 78 deletions(-)

diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 7f2d035..000db6c 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -16,56 +16,27 @@
 #include "egllog.h"
 
 
-static _EGL_DECLARE_MUTEX(_eglDisplayInitMutex);
-static _EGLHashtable *_eglDisplayHash;
-
-
 /**
  * Finish display management.
  */
-static void
+void
 _eglFiniDisplay(void)
 {
-   _eglLockMutex(&_eglDisplayInitMutex);
-   if (_eglDisplayHash) {
-      EGLuint key = _eglHashFirstEntry(_eglDisplayHash);
-
-      while (key) {
-         _EGLDisplay *dpy = (_EGLDisplay *)
-            _eglHashLookup(_eglDisplayHash, key);
-         assert(dpy);
-
-         if (dpy->ContextList || dpy->SurfaceList)
-            _eglLog(_EGL_DEBUG, "Display %u is destroyed with resources", key);
-
-         free(dpy);
-
-         key = _eglHashNextEntry(_eglDisplayHash, key);
-      }
-
-      _eglDeleteHashTable(_eglDisplayHash);
-      _eglDisplayHash = NULL;
-   }
-   _eglUnlockMutex(&_eglDisplayInitMutex);
-}
-
-
-/* This can be avoided if hash table can be statically initialized */
-static INLINE void
-_eglInitDisplay(void)
-{
-   if (!_eglDisplayHash) {
-      _eglLockMutex(&_eglDisplayInitMutex);
+   _EGLDisplay *dpyList, *dpy;
 
-      /* check again after acquiring lock */
-      if (!_eglDisplayHash) {
-         _eglDisplayHash = _eglNewHashTable();
+   /* atexit function is called with global mutex locked */
+   dpyList = _eglGlobal.DisplayList;
+   while (dpyList) {
+      /* pop list head */
+      dpy = dpyList;
+      dpyList = dpyList->Next;
 
-         _eglAddAtExitCall(_eglFiniDisplay);
-      }
+      if (dpy->ContextList || dpy->SurfaceList)
+         _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy);
 
-      _eglUnlockMutex(&_eglDisplayInitMutex);
+      free(dpy);
    }
+   _eglGlobal.DisplayList = NULL;
 }
 
 
@@ -102,17 +73,14 @@ _eglNewDisplay(NativeDisplayType nativeDisplay)
 EGLDisplay
 _eglLinkDisplay(_EGLDisplay *dpy)
 {
-   EGLuint key;
+   _eglLockMutex(_eglGlobal.Mutex);
 
-   _eglInitDisplay();
+   dpy->Next = _eglGlobal.DisplayList;
+   _eglGlobal.DisplayList = dpy;
 
-   key = _eglHashGenKey(_eglDisplayHash);
-   assert(key);
-   /* "link" the display to the hash table */
-   _eglHashInsert(_eglDisplayHash, key, dpy);
-   dpy->Handle = (EGLDisplay) _eglUIntToPointer(key);
+   _eglUnlockMutex(_eglGlobal.Mutex);
 
-   return dpy->Handle;
+   return (EGLDisplay) dpy;
 }
 
 
@@ -123,12 +91,25 @@ _eglLinkDisplay(_EGLDisplay *dpy)
 void
 _eglUnlinkDisplay(_EGLDisplay *dpy)
 {
-   EGLuint key = _eglPointerToUInt((void *) dpy->Handle);
+   _EGLDisplay *prev;
 
-   _eglInitDisplay();
+   _eglLockMutex(_eglGlobal.Mutex);
 
-   _eglHashRemove(_eglDisplayHash, key);
-   dpy->Handle = EGL_NO_DISPLAY;
+   prev = _eglGlobal.DisplayList;
+   if (prev != dpy) {
+      while (prev) {
+         if (prev->Next == dpy)
+            break;
+         prev = prev->Next;
+      }
+      assert(prev);
+      prev->Next = dpy->Next;
+   }
+   else {
+      _eglGlobal.DisplayList = dpy->Next;
+   }
+
+   _eglUnlockMutex(_eglGlobal.Mutex);
 }
 
 
@@ -136,12 +117,9 @@ _eglUnlinkDisplay(_EGLDisplay *dpy)
  * Return the handle of a linked display, or EGL_NO_DISPLAY.
  */
 EGLDisplay
-_eglGetDisplayHandle(_EGLDisplay *display)
+_eglGetDisplayHandle(_EGLDisplay *dpy)
 {
-   if (display)
-      return display->Handle;
-   else
-      return EGL_NO_DISPLAY;
+   return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
 }
 
 
@@ -150,13 +128,10 @@ _eglGetDisplayHandle(_EGLDisplay *display)
  * Return NULL if the handle has no corresponding linked display.
  */
 _EGLDisplay *
-_eglLookupDisplay(EGLDisplay dpy)
+_eglLookupDisplay(EGLDisplay display)
 {
-   EGLuint key = _eglPointerToUInt((void *) dpy);
-
-   _eglInitDisplay();
-
-   return (_EGLDisplay *) _eglHashLookup(_eglDisplayHash, key);
+   _EGLDisplay *dpy = (_EGLDisplay *) display;
+   return dpy;
 }
 
 
@@ -167,22 +142,21 @@ _eglLookupDisplay(EGLDisplay dpy)
 _EGLDisplay *
 _eglFindDisplay(NativeDisplayType nativeDisplay)
 {
-   EGLuint key;
+   _EGLDisplay *dpy;
 
-   _eglInitDisplay();
+   _eglLockMutex(_eglGlobal.Mutex);
 
-   /* Walk the hash table.  Should switch to list if it is a problem. */
-   key = _eglHashFirstEntry(_eglDisplayHash);
-   while (key) {
-      _EGLDisplay *dpy = (_EGLDisplay *)
-            _eglHashLookup(_eglDisplayHash, key);
-      assert(dpy);
-
-      if (dpy->NativeDisplay == nativeDisplay)
+   dpy = _eglGlobal.DisplayList;
+   while (dpy) {
+      if (dpy->NativeDisplay == nativeDisplay) {
+         _eglUnlockMutex(_eglGlobal.Mutex);
          return dpy;
-      key = _eglHashNextEntry(_eglDisplayHash, key);
+      }
+      dpy = dpy->Next;
    }
 
+   _eglUnlockMutex(_eglGlobal.Mutex);
+
    return NULL;
 }
 
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index dfc54f1..f7aded8 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -24,8 +24,10 @@ struct _egl_extensions
 
 struct _egl_display 
 {
+   /* used to link displays */
+   _EGLDisplay *Next;
+
    EGLNativeDisplayType NativeDisplay;
-   EGLDisplay Handle;
 
    const char *DriverName;
    _EGLDriver *Driver;
@@ -58,6 +60,10 @@ struct _egl_display
 };
 
 
+void
+_eglFiniDisplay(void);
+
+
 extern _EGLDisplay *
 _eglNewDisplay(NativeDisplayType displayName);
 
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
index 8c14f9c..3ae4c1a 100644
--- a/src/egl/main/eglglobals.c
+++ b/src/egl/main/eglglobals.c
@@ -13,12 +13,14 @@ static _EGL_DECLARE_MUTEX(_eglGlobalMutex);
 struct _egl_global _eglGlobal =
 {
    &_eglGlobalMutex,       /* Mutex */
+   NULL,                   /* DisplayList */
    1,                      /* FreeScreenHandle */
    0x0,                    /* ClientAPIsMask */
    0,                      /* NumDrivers */
    { NULL },               /* Drivers */
-   1,                      /* NumAtExitCalls */
+   2,                      /* NumAtExitCalls */
    {                       /* AtExitCalls */
+      _eglFiniDisplay,
       _eglUnloadDrivers
    },
 };
diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h
index d00d12a..5851107 100644
--- a/src/egl/main/eglglobals.h
+++ b/src/egl/main/eglglobals.h
@@ -2,7 +2,7 @@
 #define EGLGLOBALS_INCLUDED
 
 #include "egltypedefs.h"
-#include "eglhash.h"
+#include "egldisplay.h"
 #include "eglcurrent.h"
 #include "eglmutex.h"
 
@@ -13,6 +13,10 @@
 struct _egl_global
 {
    _EGLMutex *Mutex;
+
+   /* the list of all displays */
+   _EGLDisplay *DisplayList;
+
    EGLScreenMESA FreeScreenHandle;
 
    /* bitmaks of supported APIs (supported by _some_ driver) */
-- 
1.6.3.3

>From 6ac217ebde6f378937a0468e27c6f0998301d7af Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Fri, 14 Aug 2009 18:05:19 +0800
Subject: [PATCH 3/5] egl: Make lookup functions static inline.

progs/egl/demo3.c is also changed since it uses an internal function.

Signed-off-by: Chia-I Wu <[email protected]>
---
 progs/egl/demo3.c         |    2 +-
 src/egl/main/egldisplay.c |   66 --------------------------
 src/egl/main/egldisplay.h |  112 +++++++++++++++++++++++++++++++--------------
 3 files changed, 79 insertions(+), 101 deletions(-)

diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c
index a6096a2..daab62d 100644
--- a/progs/egl/demo3.c
+++ b/progs/egl/demo3.c
@@ -551,7 +551,7 @@ write_ppm(const char *filename, const GLubyte *buffer, int width, int height)
    }
 }
 
-#include "../src/egl/main/egldisplay.h"
+#include "../../src/egl/main/egldisplay.h"
 
 typedef struct fb_display
 {
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 000db6c..7f1c53a 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -114,28 +114,6 @@ _eglUnlinkDisplay(_EGLDisplay *dpy)
 
 
 /**
- * Return the handle of a linked display, or EGL_NO_DISPLAY.
- */
-EGLDisplay
-_eglGetDisplayHandle(_EGLDisplay *dpy)
-{
-   return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
-}
-
-
-/**
- * Lookup a handle to find the linked display.
- * Return NULL if the handle has no corresponding linked display.
- */
-_EGLDisplay *
-_eglLookupDisplay(EGLDisplay display)
-{
-   _EGLDisplay *dpy = (_EGLDisplay *) display;
-   return dpy;
-}
-
-
-/**
  * Find the display corresponding to the specified native display id in all
  * linked displays.
  */
@@ -257,28 +235,6 @@ _eglUnlinkContext(_EGLContext *ctx)
 
 
 /**
- * Return the handle of a linked context, or EGL_NO_CONTEXT.
- */
-EGLContext
-_eglGetContextHandle(_EGLContext *ctx)
-{
-   return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT);
-}
-
-
-/**
- * Lookup a handle to find the linked context.
- * Return NULL if the handle has no corresponding linked context.
- */
-_EGLContext *
-_eglLookupContext(EGLContext ctx, _EGLDisplay *dpy)
-{
-   _EGLContext *context = (_EGLContext *) ctx;
-   return (context && context->Display) ? context : NULL;
-}
-
-
-/**
  * Link a surface to a display and return the handle of the link.
  * The handle can be passed to client directly.
  */
@@ -319,25 +275,3 @@ _eglUnlinkSurface(_EGLSurface *surf)
    surf->Next = NULL;
    surf->Display = NULL;
 }
-
-
-/**
- * Return the handle of a linked surface, or EGL_NO_SURFACE.
- */
-EGLSurface
-_eglGetSurfaceHandle(_EGLSurface *surf)
-{
-   return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
-}
-
-
-/**
- * Lookup a handle to find the linked surface.
- * Return NULL if the handle has no corresponding linked surface.
- */
-_EGLSurface *
-_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
-{
-   _EGLSurface *surf = (_EGLSurface *) surface;
-   return (surf && surf->Display) ? surf : NULL;
-}
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index f7aded8..0654b00 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -6,8 +6,9 @@
 #endif
 
 #include "egltypedefs.h"
-#include "eglhash.h"
 #include "egldefines.h"
+#include "eglcontext.h"
+#include "eglsurface.h"
 
 
 /**
@@ -76,24 +77,6 @@ extern void
 _eglUnlinkDisplay(_EGLDisplay *dpy);
 
 
-extern EGLDisplay
-_eglGetDisplayHandle(_EGLDisplay *display);
-
-
-extern _EGLDisplay *
-_eglLookupDisplay(EGLDisplay dpy);
-
-
-/**
- * Return true if the display is linked.
- */
-static INLINE EGLBoolean
-_eglIsDisplayLinked(_EGLDisplay *dpy)
-{
-   return (EGLBoolean) (_eglGetDisplayHandle(dpy) != EGL_NO_DISPLAY);
-}
-
-
 extern _EGLDisplay *
 _eglFindDisplay(NativeDisplayType nativeDisplay);
 
@@ -114,37 +97,98 @@ extern void
 _eglUnlinkContext(_EGLContext *ctx);
 
 
-extern EGLContext
-_eglGetContextHandle(_EGLContext *ctx);
+extern EGLSurface
+_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy);
 
 
-extern _EGLContext *
-_eglLookupContext(EGLContext ctx, _EGLDisplay *dpy);
+extern void
+_eglUnlinkSurface(_EGLSurface *surf);
 
 
 /**
- * Return true if the context is linked to a display.
+ * Lookup a handle to find the linked display.
+ * Return NULL if the handle has no corresponding linked display.
+ */
+static INLINE _EGLDisplay *
+_eglLookupDisplay(EGLDisplay display)
+{
+   _EGLDisplay *dpy = (_EGLDisplay *) display;
+   return dpy;
+}
+
+
+/**
+ * Return the handle of a linked display, or EGL_NO_DISPLAY.
+ */
+static INLINE EGLDisplay
+_eglGetDisplayHandle(_EGLDisplay *dpy)
+{
+   return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
+}
+
+
+/**
+ * Return true if the display is linked.
  */
 static INLINE EGLBoolean
-_eglIsContextLinked(_EGLContext *ctx)
+_eglIsDisplayLinked(_EGLDisplay *dpy)
 {
-   return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT);
+   return (EGLBoolean) (_eglGetDisplayHandle(dpy) != EGL_NO_DISPLAY);
 }
 
-extern EGLSurface
-_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy);
 
+/**
+ * Lookup a handle to find the linked context.
+ * Return NULL if the handle has no corresponding linked context.
+ */
+static INLINE _EGLContext *
+_eglLookupContext(EGLContext context, _EGLDisplay *dpy)
+{
+   _EGLContext *ctx = (_EGLContext *) context;
+   return (ctx && ctx->Display) ? ctx : NULL;
+}
 
-extern void
-_eglUnlinkSurface(_EGLSurface *surf);
 
+/**
+ * Return the handle of a linked context, or EGL_NO_CONTEXT.
+ */
+static INLINE EGLContext
+_eglGetContextHandle(_EGLContext *ctx)
+{
+   return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT);
+}
 
-extern EGLSurface
-_eglGetSurfaceHandle(_EGLSurface *);
+
+/**
+ * Return true if the context is linked to a display.
+ */
+static INLINE EGLBoolean
+_eglIsContextLinked(_EGLContext *ctx)
+{
+   return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT);
+}
 
 
-extern _EGLSurface *
-_eglLookupSurface(EGLSurface surf, _EGLDisplay *dpy);
+/**
+ * Lookup a handle to find the linked surface.
+ * Return NULL if the handle has no corresponding linked surface.
+ */
+static INLINE _EGLSurface *
+_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
+{
+   _EGLSurface *surf = (_EGLSurface *) surface;
+   return (surf && surf->Display) ? surf : NULL;
+}
+
+
+/**
+ * Return the handle of a linked surface, or EGL_NO_SURFACE.
+ */
+static INLINE EGLSurface
+_eglGetSurfaceHandle(_EGLSurface *surf)
+{
+   return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
+}
 
 
 /**
-- 
1.6.3.3

>From b1bd84e0eda343f7aca1fe22d410fa933812474b Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Fri, 14 Aug 2009 18:02:38 +0800
Subject: [PATCH 4/5] egl: Add back handle checking.

Handle checking was done using hash tables.  Now that they are gone, we
have to loop over the lists.

Signed-off-by: Chia-I Wu <[email protected]>
---
 src/egl/main/Makefile     |    3 +-
 src/egl/main/egldisplay.c |   53 +++++++++++++++++++++++++++++++++++++++++++++
 src/egl/main/egldisplay.h |   39 +++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile
index ab61d68..17c40a6 100644
--- a/src/egl/main/Makefile
+++ b/src/egl/main/Makefile
@@ -47,8 +47,7 @@ SOURCES = \
 OBJECTS = $(SOURCES:.c=.o)
 
 
-# Undefined for now
-LOCAL_CFLAGS = -D_EGL_PLATFORM_X=1
+LOCAL_CFLAGS = -D_EGL_CHECK_HANDLE=1 -D_EGL_PLATFORM_X=1
 
 
 .c.o:
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 7f1c53a..d882f43 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -275,3 +275,56 @@ _eglUnlinkSurface(_EGLSurface *surf)
    surf->Next = NULL;
    surf->Display = NULL;
 }
+
+
+#if _EGL_CHECK_HANDLE
+
+
+EGLBoolean
+_eglCheckDisplayHandle(EGLDisplay dpy)
+{
+   _EGLDisplay *cur;
+
+   _eglLockMutex(_eglGlobal.Mutex);
+   cur = _eglGlobal.DisplayList;
+   while (cur) {
+      if (cur == (_EGLDisplay *) dpy)
+         break;
+      cur = cur->Next;
+   }
+   _eglUnlockMutex(_eglGlobal.Mutex);
+   return (cur != NULL);
+}
+
+
+EGLBoolean
+_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
+{
+   _EGLContext *cur;
+
+   cur = dpy->ContextList;
+   while (cur) {
+      if (cur == (_EGLContext *) ctx)
+         break;
+      cur = cur->Next;
+   }
+   return (cur != NULL);
+}
+
+
+EGLBoolean
+_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
+{
+   _EGLSurface *cur;
+
+   cur = dpy->SurfaceList;
+   while (cur) {
+      if (cur == (_EGLSurface *) surf)
+         break;
+      cur = cur->Next;
+   }
+   return (cur != NULL);
+}
+
+
+#endif /* _EGL_CHECK_HANDLE */
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 0654b00..bc633e2 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -105,6 +105,39 @@ extern void
 _eglUnlinkSurface(_EGLSurface *surf);
 
 
+#if _EGL_CHECK_HANDLE
+
+
+extern EGLBoolean
+_eglCheckDisplayHandle(EGLDisplay dpy);
+
+
+extern EGLBoolean
+_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy);
+
+
+extern EGLBoolean
+_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy);
+
+
+#else /* _EGL_CHECK_HANDLE */
+
+
+static INLINE EGLBoolean
+_eglCheckDisplayHandle(EGLDisplay dpy) { return EGL_TRUE; }
+
+
+static INLINE EGLBoolean
+_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) { return EGL_TRUE; }
+
+
+static INLINE EGLBoolean
+_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy) { return EGL_TRUE; }
+
+
+#endif /* !_EGL_CHECK_HANDLE */
+
+
 /**
  * Lookup a handle to find the linked display.
  * Return NULL if the handle has no corresponding linked display.
@@ -113,6 +146,8 @@ static INLINE _EGLDisplay *
 _eglLookupDisplay(EGLDisplay display)
 {
    _EGLDisplay *dpy = (_EGLDisplay *) display;
+   if (!_eglCheckDisplayHandle(display))
+      dpy = NULL;
    return dpy;
 }
 
@@ -145,6 +180,8 @@ static INLINE _EGLContext *
 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
 {
    _EGLContext *ctx = (_EGLContext *) context;
+   if (!_eglCheckContextHandle(context, dpy))
+      ctx = NULL;
    return (ctx && ctx->Display) ? ctx : NULL;
 }
 
@@ -177,6 +214,8 @@ static INLINE _EGLSurface *
 _eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
 {
    _EGLSurface *surf = (_EGLSurface *) surface;
+   if (!_eglCheckSurfaceHandle(surf, dpy))
+      surf = NULL;
    return (surf && surf->Display) ? surf : NULL;
 }
 
-- 
1.6.3.3

>From 9c36ebcaafd97b673d920357a0632acb161f8c35 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Fri, 14 Aug 2009 18:26:26 +0800
Subject: [PATCH 5/5] egl: Remove eglhash.c and eglhash.h.

Signed-off-by: Chia-I Wu <[email protected]>
---
 src/egl/drivers/glx/egl_glx.c |    1 -
 src/egl/main/Makefile         |    2 -
 src/egl/main/egldisplay.c     |    1 -
 src/egl/main/eglhash.c        |  347 -----------------------------------------
 src/egl/main/eglhash.h        |   39 -----
 src/egl/main/eglsurface.c     |    1 -
 6 files changed, 0 insertions(+), 391 deletions(-)
 delete mode 100644 src/egl/main/eglhash.c
 delete mode 100644 src/egl/main/eglhash.h

diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c
index 9d80bc1..3c8f8b6 100644
--- a/src/egl/drivers/glx/egl_glx.c
+++ b/src/egl/drivers/glx/egl_glx.c
@@ -57,7 +57,6 @@
 #include "egldisplay.h"
 #include "egldriver.h"
 #include "eglglobals.h"
-#include "eglhash.h"
 #include "egllog.h"
 #include "eglsurface.h"
 
diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile
index 17c40a6..dd8eb3e 100644
--- a/src/egl/main/Makefile
+++ b/src/egl/main/Makefile
@@ -17,7 +17,6 @@ HEADERS = \
 	egldriver.h \
 	eglglobals.h \
 	egllog.h \
-	eglhash.h \
 	eglmisc.h \
 	eglmode.h \
 	eglmutex.h \
@@ -36,7 +35,6 @@ SOURCES = \
 	egldriver.c \
 	eglglobals.c \
 	egllog.c \
-	eglhash.c \
 	eglmisc.c \
 	eglmode.c \
 	eglscreen.c \
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index d882f43..7411250 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -10,7 +10,6 @@
 #include "egldisplay.h"
 #include "egldriver.h"
 #include "eglglobals.h"
-#include "eglhash.h"
 #include "eglstring.h"
 #include "eglmutex.h"
 #include "egllog.h"
diff --git a/src/egl/main/eglhash.c b/src/egl/main/eglhash.c
deleted file mode 100644
index 8e3da2e..0000000
--- a/src/egl/main/eglhash.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/**
- * \file hash.c
- * Generic hash table. 
- *
- * This code taken from Mesa and adapted.
- */
-
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include "eglhash.h"
-
-
-#define TABLE_SIZE 1023  /**< Size of lookup table/array */
-
-#define HASH_FUNC(K)  ((K) % TABLE_SIZE)
-
-
-/*
- * Unfinished mutex stuff
- */
-
-typedef int _EGLMutex;
-
-static void
-_eglInitMutex(_EGLMutex m)
-{
-}
-
-static void
-_eglDestroyMutex(_EGLMutex m)
-{
-}
-
-static void
-_eglLockMutex(_EGLMutex m)
-{
-}
-
-static void
-_eglUnlockMutex(_EGLMutex m)
-{
-}
-
-
-
-typedef struct _egl_hashentry _EGLHashentry;
-
-struct _egl_hashentry
-{
-   EGLuint Key;            /**< the entry's key */
-   void *Data;             /**< the entry's data */
-   _EGLHashentry *Next;    /**< pointer to next entry */
-};
-
-
-struct _egl_hashtable
-{
-   _EGLHashentry *Table[TABLE_SIZE];  /**< the lookup table */
-   EGLuint MaxKey;                    /**< highest key inserted so far */
-   _EGLMutex Mutex;                   /**< mutual exclusion lock */
-};
-
-
-/**
- * Create a new hash table.
- * 
- * \return pointer to a new, empty hash table.
- */
-_EGLHashtable *
-_eglNewHashTable(void)
-{
-   _EGLHashtable *table = (_EGLHashtable *) calloc(1, sizeof(_EGLHashtable));
-   if (table) {
-      _eglInitMutex(table->Mutex);
-      table->MaxKey = 1;
-   }
-   return table;
-}
-
-
-
-/**
- * Delete a hash table.
- * Frees each entry on the hash table and then the hash table structure itself.
- * Note that the caller should have already traversed the table and deleted
- * the objects in the table (i.e. We don't free the entries' data pointer).
- *
- * \param table the hash table to delete.
- */
-void
-_eglDeleteHashTable(_EGLHashtable *table)
-{
-   EGLuint i;
-   assert(table);
-   for (i = 0; i < TABLE_SIZE; i++) {
-      _EGLHashentry *entry = table->Table[i];
-      while (entry) {
-	 _EGLHashentry *next = entry->Next;
-	 free(entry);
-	 entry = next;
-      }
-   }
-   _eglDestroyMutex(table->Mutex);
-   free(table);
-}
-
-
-
-/**
- * Lookup an entry in the hash table.
- * 
- * \param table the hash table.
- * \param key the key.
- * 
- * \return pointer to user's data or NULL if key not in table
- */
-void *
-_eglHashLookup(const _EGLHashtable *table, EGLuint key)
-{
-   EGLuint pos;
-   const _EGLHashentry *entry;
-
-   assert(table);
-
-   if (!key)
-      return NULL;
-
-   pos = HASH_FUNC(key);
-   entry = table->Table[pos];
-   while (entry) {
-      if (entry->Key == key) {
-	 return entry->Data;
-      }
-      entry = entry->Next;
-   }
-   return NULL;
-}
-
-
-
-/**
- * Insert a key/pointer pair into the hash table.  
- * If an entry with this key already exists we'll replace the existing entry.
- * 
- * \param table the hash table.
- * \param key the key (not zero).
- * \param data pointer to user data.
- */
-void
-_eglHashInsert(_EGLHashtable *table, EGLuint key, void *data)
-{
-   /* search for existing entry with this key */
-   EGLuint pos;
-   _EGLHashentry *entry;
-
-   assert(table);
-   assert(key);
-
-   _eglLockMutex(table->Mutex);
-
-   if (key > table->MaxKey)
-      table->MaxKey = key;
-
-   pos = HASH_FUNC(key);
-   entry = table->Table[pos];
-   while (entry) {
-      if (entry->Key == key) {
-         /* replace entry's data */
-	 entry->Data = data;
-         _eglUnlockMutex(table->Mutex);
-	 return;
-      }
-      entry = entry->Next;
-   }
-
-   /* alloc and insert new table entry */
-   entry = (_EGLHashentry *) malloc(sizeof(_EGLHashentry));
-   entry->Key = key;
-   entry->Data = data;
-   entry->Next = table->Table[pos];
-   table->Table[pos] = entry;
-
-   _eglUnlockMutex(table->Mutex);
-}
-
-
-
-/**
- * Remove an entry from the hash table.
- * 
- * \param table the hash table.
- * \param key key of entry to remove.
- *
- * While holding the hash table's lock, searches the entry with the matching
- * key and unlinks it.
- */
-void
-_eglHashRemove(_EGLHashtable *table, EGLuint key)
-{
-   EGLuint pos;
-   _EGLHashentry *entry, *prev;
-
-   assert(table);
-   assert(key);
-
-   _eglLockMutex(table->Mutex);
-
-   pos = HASH_FUNC(key);
-   prev = NULL;
-   entry = table->Table[pos];
-   while (entry) {
-      if (entry->Key == key) {
-         /* found it! */
-         if (prev) {
-            prev->Next = entry->Next;
-         }
-         else {
-            table->Table[pos] = entry->Next;
-         }
-         free(entry);
-         _eglUnlockMutex(table->Mutex);
-	 return;
-      }
-      prev = entry;
-      entry = entry->Next;
-   }
-
-   _eglUnlockMutex(table->Mutex);
-}
-
-
-
-/**
- * Get the key of the "first" entry in the hash table.
- * 
- * This is used in the course of deleting all display lists when
- * a context is destroyed.
- * 
- * \param table the hash table
- * 
- * \return key for the "first" entry in the hash table.
- *
- * While holding the lock, walks through all table positions until finding
- * the first entry of the first non-empty one.
- */
-EGLuint
-_eglHashFirstEntry(_EGLHashtable *table)
-{
-   EGLuint pos;
-   assert(table);
-   _eglLockMutex(table->Mutex);
-   for (pos = 0; pos < TABLE_SIZE; pos++) {
-      if (table->Table[pos]) {
-         _eglUnlockMutex(table->Mutex);
-         return table->Table[pos]->Key;
-      }
-   }
-   _eglUnlockMutex(table->Mutex);
-   return 0;
-}
-
-
-/**
- * Given a hash table key, return the next key.  This is used to walk
- * over all entries in the table.  Note that the keys returned during
- * walking won't be in any particular order.
- * \return next hash key or 0 if end of table.
- */
-EGLuint
-_eglHashNextEntry(const _EGLHashtable *table, EGLuint key)
-{
-   const _EGLHashentry *entry;
-   EGLuint pos;
-
-   assert(table);
-   assert(key);
-
-   /* Find the entry with given key */
-   pos = HASH_FUNC(key);
-   entry = table->Table[pos];
-   while (entry) {
-      if (entry->Key == key) {
-         break;
-      }
-      entry = entry->Next;
-   }
-
-   if (!entry) {
-      /* the key was not found, we can't find next entry */
-      return 0;
-   }
-
-   if (entry->Next) {
-      /* return next in linked list */
-      return entry->Next->Key;
-   }
-   else {
-      /* look for next non-empty table slot */
-      pos++;
-      while (pos < TABLE_SIZE) {
-         if (table->Table[pos]) {
-            return table->Table[pos]->Key;
-         }
-         pos++;
-      }
-      return 0;
-   }
-}
-
-
-/**
- * Dump contents of hash table for debugging.
- * 
- * \param table the hash table.
- */
-void
-_eglHashPrint(const _EGLHashtable *table)
-{
-   EGLuint i;
-   assert(table);
-   for (i = 0; i < TABLE_SIZE; i++) {
-      const _EGLHashentry *entry = table->Table[i];
-      while (entry) {
-	 printf("%u %p\n", entry->Key, entry->Data);
-	 entry = entry->Next;
-      }
-   }
-}
-
-
-
-/**
- * Return a new, unused hash key.
- */
-EGLuint
-_eglHashGenKey(_EGLHashtable *table)
-{
-   EGLuint k;
-
-   _eglLockMutex(table->Mutex);
-   k = table->MaxKey;
-   table->MaxKey++;
-   _eglUnlockMutex(table->Mutex);
-   return k;
-}
-
diff --git a/src/egl/main/eglhash.h b/src/egl/main/eglhash.h
deleted file mode 100644
index 1d6db95..0000000
--- a/src/egl/main/eglhash.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * \file eglhash.h
- * Generic hash table. 
- */
-
-
-#ifndef EGLHASH_INCLUDED
-#define EGLHASH_INCLUDED
-
-
-/* XXX move this? */
-typedef unsigned int EGLuint;
-
-
-typedef struct _egl_hashtable _EGLHashtable;
-
-
-extern _EGLHashtable *_eglNewHashTable(void);
-
-extern void _eglDeleteHashTable(_EGLHashtable *table);
-
-extern void *_eglHashLookup(const _EGLHashtable *table, EGLuint key);
-
-extern void _eglHashInsert(_EGLHashtable *table, EGLuint key, void *data);
-
-extern void _eglHashRemove(_EGLHashtable *table, EGLuint key);
-
-extern EGLuint _eglHashFirstEntry(_EGLHashtable *table);
-
-extern EGLuint _eglHashNextEntry(const _EGLHashtable *table, EGLuint key);
-
-extern void _eglHashPrint(const _EGLHashtable *table);
-
-extern EGLuint _eglHashGenKey(_EGLHashtable *table);
-
-extern void _egltest_hash_functions(void);
-
-
-#endif /* EGLHASH_INCLUDED */
diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c
index adf125f..e7a1a83 100644
--- a/src/egl/main/eglsurface.c
+++ b/src/egl/main/eglsurface.c
@@ -11,7 +11,6 @@
 #include "eglconfig.h"
 #include "egldriver.h"
 #include "eglglobals.h"
-#include "eglhash.h"
 #include "egllog.h"
 #include "eglsurface.h"
 
-- 
1.6.3.3

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to