egl: Introduce platform displays internally.
authorChia-I Wu <olv@lunarg.com>
Thu, 17 Jun 2010 09:14:03 +0000 (17:14 +0800)
committerChia-I Wu <olv@lunarg.com>
Wed, 23 Jun 2010 07:14:59 +0000 (15:14 +0800)
This commit introduces type-safe platform displays internally.  A
platform display consists of a generic pointer and an enum that
specifies the platform.

An EGLDisplay is created from a platform display.  Native displays
become platform displays whose platform is determined by
_eglGetNativePlatform().  Platform windows and pixmaps may also be
introduced if needed.

19 files changed:
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/glx/egl_glx.c
src/egl/main/Makefile
src/egl/main/SConscript
src/egl/main/eglapi.c
src/egl/main/egldisplay.c
src/egl/main/egldisplay.h
src/egl/main/egldriver.c
src/egl/main/egldriver.h
src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/common/native_probe.h
src/gallium/state_trackers/egl/fbdev/native_fbdev.c
src/gallium/state_trackers/egl/gdi/native_gdi.c
src/gallium/state_trackers/egl/kms/native_kms.c
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_x11.c
src/gallium/state_trackers/egl/x11/native_x11.h
src/gallium/state_trackers/egl/x11/native_ximage.c

index aa384cb11725a0fca85a208101948e58d6afa9d4..5a5e43bffe014a601f324341e295654f20b71d76 100644 (file)
@@ -702,15 +702,18 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp,
    struct dri2_egl_display *dri2_dpy;
    unsigned int api_mask;
 
+   if (disp->Platform != _EGL_PLATFORM_X11)
+      return EGL_FALSE;
+
    dri2_dpy = malloc(sizeof *dri2_dpy);
    if (!dri2_dpy)
       return _eglError(EGL_BAD_ALLOC, "eglInitialize");
 
    disp->DriverData = (void *) dri2_dpy;
-   if (disp->NativeDisplay == NULL) {
+   if (disp->PlatformDisplay == NULL) {
       dri2_dpy->conn = xcb_connect(0, 0);
    } else {
-      dri2_dpy->conn = XGetXCBConnection(disp->NativeDisplay);
+      dri2_dpy->conn = XGetXCBConnection((Display *) disp->PlatformDisplay);
    }
 
    if (xcb_connection_has_error(dri2_dpy->conn)) {
@@ -815,7 +818,7 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp,
  cleanup_driver:
    dlclose(dri2_dpy->driver);
  cleanup_conn:
-   if (disp->NativeDisplay == NULL)
+   if (disp->PlatformDisplay == NULL)
       xcb_disconnect(dri2_dpy->conn);
  cleanup_dpy:
    free(dri2_dpy);
@@ -837,7 +840,7 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
    dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen);
    close(dri2_dpy->fd);
    dlclose(dri2_dpy->driver);
-   if (disp->NativeDisplay == NULL)
+   if (disp->PlatformDisplay == NULL)
       xcb_disconnect(dri2_dpy->conn);
    free(dri2_dpy);
    disp->DriverData = NULL;
index e08ef5f2228111f3d387190b2be41f193bd7c322..804dc028a3c5236425583678599b0f8168655726 100644 (file)
@@ -498,11 +498,14 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
 {
    struct GLX_egl_display *GLX_dpy;
 
+   if (disp->Platform != _EGL_PLATFORM_X11)
+      return EGL_FALSE;
+
    GLX_dpy = CALLOC_STRUCT(GLX_egl_display);
    if (!GLX_dpy)
       return _eglError(EGL_BAD_ALLOC, "eglInitialize");
 
-   GLX_dpy->dpy = (Display *) disp->NativeDisplay;
+   GLX_dpy->dpy = (Display *) disp->PlatformDisplay;
    if (!GLX_dpy->dpy) {
       GLX_dpy->dpy = XOpenDisplay(NULL);
       if (!GLX_dpy->dpy) {
@@ -514,7 +517,7 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
 
    if (!glXQueryVersion(GLX_dpy->dpy, &GLX_dpy->glx_maj, &GLX_dpy->glx_min)) {
       _eglLog(_EGL_WARNING, "GLX: glXQueryVersion failed");
-      if (!disp->NativeDisplay)
+      if (!disp->PlatformDisplay)
          XCloseDisplay(GLX_dpy->dpy);
       free(GLX_dpy);
       return EGL_FALSE;
@@ -526,7 +529,7 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
    create_configs(disp, GLX_dpy, DefaultScreen(GLX_dpy->dpy));
    if (!disp->NumConfigs) {
       _eglLog(_EGL_WARNING, "GLX: failed to create any config");
-      if (!disp->NativeDisplay)
+      if (!disp->PlatformDisplay)
          XCloseDisplay(GLX_dpy->dpy);
       free(GLX_dpy);
       return EGL_FALSE;
@@ -558,7 +561,7 @@ GLX_eglTerminate(_EGLDriver *drv, _EGLDisplay *disp)
    if (GLX_dpy->fbconfigs)
       XFree(GLX_dpy->fbconfigs);
 
-   if (!disp->NativeDisplay)
+   if (!disp->PlatformDisplay)
       XCloseDisplay(GLX_dpy->dpy);
    free(GLX_dpy);
 
@@ -617,10 +620,11 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
 static void
 destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
 {
+   struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
    struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf);
 
    if (GLX_surf->destroy)
-      GLX_surf->destroy(disp->NativeDisplay, GLX_surf->glx_drawable);
+      GLX_surf->destroy(GLX_dpy->dpy, GLX_surf->glx_drawable);
 
    free(GLX_surf);
 }
index d9e9e4fcd6d5214401b7eb70df732dfdbee84fb6..be27d9450f4bc5d64df43aff948baa7ec6e91188 100644 (file)
@@ -53,7 +53,20 @@ LOCAL_CFLAGS = -D_EGL_OS_UNIX=1
 
 EGL_DEFAULT_PLATFORM = $(firstword $(EGL_PLATFORMS))
 
+# translate --with-egl-platforms to _EGLPlatformType
+EGL_NATIVE_PLATFORM=_EGL_INVALID_PLATFORM
+ifeq ($(firstword $(EGL_PLATFORMS)),x11)
+EGL_NATIVE_PLATFORM=_EGL_PLATFORM_X11
+endif
+ifeq ($(firstword $(EGL_PLATFORMS)),kms)
+EGL_NATIVE_PLATFORM=_EGL_PLATFORM_DRM
+endif
+ifeq ($(firstword $(EGL_PLATFORMS)),fbdev)
+EGL_NATIVE_PLATFORM=_EGL_PLATFORM_FBDEV
+endif
+
 LOCAL_CFLAGS += \
+       -D_EGL_NATIVE_PLATFORM=$(EGL_NATIVE_PLATFORM) \
        -D_EGL_DEFAULT_PLATFORM=\"$(EGL_DEFAULT_PLATFORM)\" \
        -D_EGL_DRIVER_SEARCH_DIR=\"$(EGL_DRIVER_INSTALL_DIR)\"
 
index a331c9711ec636d893863b7577d56898340ede72..fad0671f38aacba45e8bb0024a4a2f4dec270351 100644 (file)
@@ -9,7 +9,8 @@ if env['platform'] != 'winddk':
        env = env.Clone()
 
        env.Append(CPPDEFINES = [
-               '_EGL_DEFAULT_DISPLAY=\\"gdi\\"',
+               '_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_WINDOWS',
+               '_EGL_DEFAULT_PLATFORM=\\"gdi\\"',
                '_EGL_DRIVER_SEARCH_DIR=\\"\\"',
                '_EGL_OS_WINDOWS',
                'KHRONOS_DLL_EXPORTS',
index 9912043e06c61eab3103586f0fd2768de173aea0..32a79d8a199b23cceb35be20c4383d7cb9ee5c1f 100644 (file)
@@ -250,7 +250,8 @@ _eglUnlockDisplay(_EGLDisplay *dpy)
 EGLDisplay EGLAPIENTRY
 eglGetDisplay(EGLNativeDisplayType nativeDisplay)
 {
-   _EGLDisplay *dpy = _eglFindDisplay(nativeDisplay);
+   _EGLPlatformType plat = _eglGetNativePlatform();
+   _EGLDisplay *dpy = _eglFindDisplay(plat, (void *) nativeDisplay);
    return _eglGetDisplayHandle(dpy);
 }
 
@@ -491,6 +492,8 @@ eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
    EGLSurface ret;
 
    _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
+   if (disp->Platform != _eglGetNativePlatform())
+      RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
 
    surf = drv->API.CreateWindowSurface(drv, disp, conf, window, attrib_list);
    ret = (surf) ? _eglLinkSurface(surf, disp) : EGL_NO_SURFACE;
@@ -510,6 +513,8 @@ eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
    EGLSurface ret;
 
    _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
+   if (disp->Platform != _eglGetNativePlatform())
+      RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
 
    surf = drv->API.CreatePixmapSurface(drv, disp, conf, pixmap, attrib_list);
    ret = (surf) ? _eglLinkSurface(surf, disp) : EGL_NO_SURFACE;
@@ -667,6 +672,8 @@ eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
    EGLBoolean ret;
 
    _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv);
+   if (disp->Platform != _eglGetNativePlatform())
+      RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
    ret = drv->API.CopyBuffers(drv, disp, surf, target);
 
    RETURN_EGL_EVAL(disp, ret);
index 5dc5fd9719a682e029be8a470d3efbe2e8a0e691..d666bdabe02a2093a8e4ba63cc669d016033e3d0 100644 (file)
@@ -49,16 +49,19 @@ _eglFiniDisplay(void)
  * new one.
  */
 _EGLDisplay *
-_eglFindDisplay(EGLNativeDisplayType nativeDisplay)
+_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
 {
    _EGLDisplay *dpy;
 
+   if (plat == _EGL_INVALID_PLATFORM)
+      return NULL;
+
    _eglLockMutex(_eglGlobal.Mutex);
 
    /* search the display list first */
    dpy = _eglGlobal.DisplayList;
    while (dpy) {
-      if (dpy->NativeDisplay == nativeDisplay)
+      if (dpy->Platform == plat && dpy->PlatformDisplay == plat_dpy)
          break;
       dpy = dpy->Next;
    }
@@ -68,7 +71,8 @@ _eglFindDisplay(EGLNativeDisplayType nativeDisplay)
       dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
       if (dpy) {
          _eglInitMutex(&dpy->Mutex);
-         dpy->NativeDisplay = nativeDisplay;
+         dpy->Platform = plat;
+         dpy->PlatformDisplay = plat_dpy;
 
          /* add to the display list */ 
          dpy->Next = _eglGlobal.DisplayList;
index 42e305f91ac34073d248f6ad19ff86377d782b1b..65dfdc33410efa275797eb278c38bb1eccb4f796 100644 (file)
@@ -7,6 +7,18 @@
 #include "eglmutex.h"
 
 
+enum _egl_platform_type {
+   _EGL_PLATFORM_WINDOWS,
+   _EGL_PLATFORM_X11,
+   _EGL_PLATFORM_DRM,
+   _EGL_PLATFORM_FBDEV,
+
+   _EGL_NUM_PLATFORMS,
+   _EGL_INVALID_PLATFORM = -1
+};
+typedef enum _egl_platform_type _EGLPlatformType;
+
+
 enum _egl_resource_type {
    _EGL_RESOURCE_CONTEXT,
    _EGL_RESOURCE_SURFACE,
@@ -53,14 +65,15 @@ struct _egl_extensions
 };
 
 
-struct _egl_display 
+struct _egl_display
 {
    /* used to link displays */
    _EGLDisplay *Next;
 
    _EGLMutex Mutex;
 
-   EGLNativeDisplayType NativeDisplay;
+   _EGLPlatformType Platform;
+   void *PlatformDisplay;
 
    EGLBoolean Initialized; /**< True if the display is initialized */
    _EGLDriver *Driver;
@@ -92,7 +105,7 @@ _eglFiniDisplay(void);
 
 
 extern _EGLDisplay *
-_eglFindDisplay(EGLNativeDisplayType displayName);
+_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy);
 
 
 PUBLIC void
index f56214472e92a1fae1b796205d02b17dc18e56fe..db7b4a7471e32b641249a8350964514b28d59019 100644 (file)
@@ -580,6 +580,16 @@ _eglLoadDefaultDriver(EGLDisplay dpy, EGLint *major, EGLint *minor)
 }
 
 
+/**
+ * Return the native platform.  It is the platform of the EGL native types.
+ */
+_EGLPlatformType
+_eglGetNativePlatform(void)
+{
+   return _EGL_NATIVE_PLATFORM;
+}
+
+
 /**
  * Plug all the available fallback routines into the given driver's
  * dispatch table.
index 8b34c43b924dcba4873dbf479ea163cbd1b9815d..6a5237476473b25fc0849bf3761b12f1c16e7e51 100644 (file)
@@ -3,6 +3,7 @@
 
 
 #include "egltypedefs.h"
+#include "egldisplay.h"
 #include "eglapi.h"
 
 
@@ -88,6 +89,10 @@ extern _EGLDriver *
 _eglLoadDefaultDriver(EGLDisplay dpy, EGLint *major, EGLint *minor);
 
 
+extern _EGLPlatformType
+_eglGetNativePlatform(void);
+
+
 PUBLIC void
 _eglInitDriverFallbacks(_EGLDriver *drv);
 
index 361cc7960bdc5f3dcd762e7451dfefafed55a675..8c7d2cb33e71bbd967243046d18698ad058407a2 100644 (file)
@@ -74,10 +74,10 @@ egl_g3d_get_probe(_EGLDriver *drv, _EGLDisplay *dpy)
    struct native_probe *nprobe;
 
    nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
-   if (!nprobe || nprobe->display != dpy->NativeDisplay) {
+   if (!nprobe || nprobe->display != dpy->PlatformDisplay) {
       if (nprobe)
          nprobe->destroy(nprobe);
-      nprobe = native_create_probe(dpy->NativeDisplay);
+      nprobe = native_create_probe(dpy->PlatformDisplay);
       _eglSetProbeCache(gdrv->probe_key, (void *) nprobe);
    }
 
@@ -96,7 +96,7 @@ egl_g3d_destroy_probe(_EGLDriver *drv, _EGLDisplay *dpy)
    struct native_probe *nprobe;
 
    nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
-   if (nprobe && (!dpy || nprobe->display == dpy->NativeDisplay)) {
+   if (nprobe && (!dpy || nprobe->display == dpy->PlatformDisplay)) {
       nprobe->destroy(nprobe);
       _eglSetProbeCache(gdrv->probe_key, NULL);
    }
@@ -479,7 +479,7 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
    }
    dpy->DriverData = gdpy;
 
-   gdpy->native = native_create_display(dpy->NativeDisplay,
+   gdpy->native = native_create_display(dpy->PlatformDisplay,
          &egl_g3d_native_event_handler);
    if (!gdpy->native) {
       _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
index 3f60348c48932555b2197716961364f95bbde5fa..494becb61f26f93f1a5ec7e034bb938a56d410ec 100644 (file)
@@ -211,7 +211,6 @@ const char *
 native_get_name(void);
 
 struct native_display *
-native_create_display(EGLNativeDisplayType dpy,
-                      struct native_event_handler *handler);
+native_create_display(void *dpy, struct native_event_handler *handler);
 
 #endif /* _NATIVE_H_ */
index aeed9f85dd53b98bf9497c35ee39a5b86913e92f..539c4aa70d2d9ab12f6de219a296c503062c2ef1 100644 (file)
@@ -43,7 +43,7 @@ enum native_probe_result {
  */
 struct native_probe {
    int magic;
-   EGLNativeDisplayType display;
+   void *display;
    void *data;
 
    void (*destroy)(struct native_probe *nprobe);
@@ -57,7 +57,7 @@ struct native_probe {
  * same display.
  */
 struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy);
+native_create_probe(void *dpy);
 
 /**
  * Probe the probe object.
index d70b7c6eb965f3014ce070cca3275a3c48a6e55c..399c1251ef646dbd0fd22cf3a21c6ae5c6e909d3 100644 (file)
@@ -428,7 +428,7 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler)
 }
 
 struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy)
+native_create_probe(void *dpy)
 {
    return NULL;
 }
@@ -446,18 +446,17 @@ native_get_name(void)
 }
 
 struct native_display *
-native_create_display(EGLNativeDisplayType dpy,
-                      struct native_event_handler *event_handler)
+native_create_display(void *dpy, struct native_event_handler *event_handler)
 {
    struct native_display *ndpy;
    int fd;
 
    /* well, this makes fd 0 being ignored */
-   if (dpy == EGL_DEFAULT_DISPLAY) {
+   if (!dpy) {
       fd = open("/dev/fb0", O_RDWR);
    }
    else {
-      fd = dup((int) pointer_to_intptr((void *) dpy));
+      fd = dup((int) pointer_to_intptr(dpy));
    }
    if (fd < 0)
       return NULL;
index 1791d198d50212b6d271a4374c76fc86110066f0..56f190de00248ee9df0f5c628cf36a7349148bb8 100644 (file)
@@ -367,7 +367,7 @@ gdi_create_display(HDC hDC, struct pipe_screen *screen,
 }
 
 struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy)
+native_create_probe(void *dpy)
 {
    return NULL;
 }
@@ -385,8 +385,7 @@ native_get_name(void)
 }
 
 struct native_display *
-native_create_display(EGLNativeDisplayType dpy,
-                      struct native_event_handler *event_handler)
+native_create_display(void *dpy, struct native_event_handler *event_handler)
 {
    struct sw_winsys *winsys;
    struct pipe_screen *screen;
index bfb4a9d25889bfe81f94b0e803185c487278d3ea..f90b8714c99a48744e723802945a7a0a34d3052f 100644 (file)
@@ -779,7 +779,7 @@ kms_create_display(int fd, struct native_event_handler *event_handler,
 }
 
 struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy)
+native_create_probe(void *dpy)
 {
    return NULL;
 }
@@ -810,8 +810,7 @@ native_get_name(void)
 }
 
 struct native_display *
-native_create_display(EGLNativeDisplayType dpy,
-                      struct native_event_handler *event_handler)
+native_create_display(void *dpy, struct native_event_handler *event_handler)
 {
    struct native_display *ndpy = NULL;
    int fd;
index 3f802dd713f0d2be8393b11bacaeeab8cf41af7a..e90c33b824d383a7fb848de4c529afa127219897 100644 (file)
@@ -741,7 +741,7 @@ dri2_display_hash_table_compare(void *key1, void *key2)
 }
 
 struct native_display *
-x11_create_dri2_display(EGLNativeDisplayType dpy,
+x11_create_dri2_display(Display *dpy,
                         struct native_event_handler *event_handler,
                         struct drm_api *api)
 {
index b6d51bbf9fbe3063b1881fcc116b1e57fb02830d..bfa12b26a77487d922a6e1ac42df244558f387d6 100644 (file)
@@ -46,7 +46,7 @@ x11_probe_destroy(struct native_probe *nprobe)
 }
 
 struct native_probe *
-native_create_probe(EGLNativeDisplayType dpy)
+native_create_probe(void *dpy)
 {
    struct native_probe *nprobe;
    struct x11_screen *xscr;
@@ -127,8 +127,7 @@ native_get_name(void)
 }
 
 struct native_display *
-native_create_display(EGLNativeDisplayType dpy,
-                      struct native_event_handler *event_handler)
+native_create_display(void *dpy, struct native_event_handler *event_handler)
 {
    struct native_display *ndpy = NULL;
    boolean force_sw;
@@ -138,14 +137,14 @@ native_create_display(EGLNativeDisplayType dpy,
 
    force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE);
    if (api && !force_sw) {
-      ndpy = x11_create_dri2_display(dpy, event_handler, api);
+      ndpy = x11_create_dri2_display((Display *) dpy, event_handler, api);
    }
 
    if (!ndpy) {
       EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING;
 
       _eglLog(level, "use software fallback");
-      ndpy = x11_create_ximage_display(dpy, event_handler);
+      ndpy = x11_create_ximage_display((Display *) dpy, event_handler);
    }
 
    return ndpy;
index 1678403b45974e3db6f9ee06c86a20df0041eeb0..f1fea7f3de43557609d4cba6603706321c49a6f1 100644 (file)
 #include "common/native.h"
 
 struct native_display *
-x11_create_ximage_display(EGLNativeDisplayType dpy,
+x11_create_ximage_display(Display *dpy,
                           struct native_event_handler *event_handler);
 
 struct native_display *
-x11_create_dri2_display(EGLNativeDisplayType dpy,
+x11_create_dri2_display(Display *dpy,
                         struct native_event_handler *event_handler,
                         struct drm_api *api);
 
index 45679fc9b4e5f5dd08a4102f7aba72685c41b4c6..ee10a04cfb2b4fd6fbd9b5c73028298b73018a74 100644 (file)
@@ -441,7 +441,7 @@ ximage_display_destroy(struct native_display *ndpy)
 }
 
 struct native_display *
-x11_create_ximage_display(EGLNativeDisplayType dpy,
+x11_create_ximage_display(Display *dpy,
                           struct native_event_handler *event_handler)
 {
    struct ximage_display *xdpy;