From f22665df95406567193dee0089f4830664ff4101 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 17 Jun 2010 17:14:03 +0800 Subject: egl: Introduce platform displays internally. 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. --- src/egl/drivers/dri2/egl_dri2.c | 11 +++++++---- src/egl/drivers/glx/egl_glx.c | 14 +++++++++----- src/egl/main/Makefile | 13 +++++++++++++ src/egl/main/SConscript | 3 ++- src/egl/main/eglapi.c | 9 ++++++++- src/egl/main/egldisplay.c | 10 +++++++--- src/egl/main/egldisplay.h | 19 ++++++++++++++++--- src/egl/main/egldriver.c | 10 ++++++++++ src/egl/main/egldriver.h | 5 +++++ 9 files changed, 77 insertions(+), 17 deletions(-) (limited to 'src/egl') diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index aa384cb1172..5a5e43bffe0 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -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; diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index e08ef5f2228..804dc028a3c 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -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); } diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index d9e9e4fcd6d..be27d9450f4 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -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)\" diff --git a/src/egl/main/SConscript b/src/egl/main/SConscript index a331c9711ec..fad0671f38a 100644 --- a/src/egl/main/SConscript +++ b/src/egl/main/SConscript @@ -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', diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 9912043e06c..32a79d8a199 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -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); diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 5dc5fd9719a..d666bdabe02 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -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; diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 42e305f91ac..65dfdc33410 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -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 diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index f56214472e9..db7b4a7471e 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -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. diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 8b34c43b924..6a523747647 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -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); -- cgit v1.2.3