From: Chia-I Wu Date: Thu, 17 Jun 2010 09:14:03 +0000 (+0800) Subject: egl: Introduce platform displays internally. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f22665df95406567193dee0089f4830664ff4101;p=mesa.git 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. --- 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); diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 361cc7960bd..8c7d2cb33e7 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -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)"); diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 3f60348c489..494becb61f2 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -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_ */ diff --git a/src/gallium/state_trackers/egl/common/native_probe.h b/src/gallium/state_trackers/egl/common/native_probe.h index aeed9f85dd5..539c4aa70d2 100644 --- a/src/gallium/state_trackers/egl/common/native_probe.h +++ b/src/gallium/state_trackers/egl/common/native_probe.h @@ -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. diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c index d70b7c6eb96..399c1251ef6 100644 --- a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c +++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c @@ -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; diff --git a/src/gallium/state_trackers/egl/gdi/native_gdi.c b/src/gallium/state_trackers/egl/gdi/native_gdi.c index 1791d198d50..56f190de002 100644 --- a/src/gallium/state_trackers/egl/gdi/native_gdi.c +++ b/src/gallium/state_trackers/egl/gdi/native_gdi.c @@ -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; diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c index bfb4a9d2588..f90b8714c99 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.c +++ b/src/gallium/state_trackers/egl/kms/native_kms.c @@ -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; diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c index 3f802dd713f..e90c33b824d 100644 --- a/src/gallium/state_trackers/egl/x11/native_dri2.c +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c @@ -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) { diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c index b6d51bbf9fb..bfa12b26a77 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.c +++ b/src/gallium/state_trackers/egl/x11/native_x11.c @@ -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; diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h index 1678403b459..f1fea7f3de4 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.h +++ b/src/gallium/state_trackers/egl/x11/native_x11.h @@ -30,11 +30,11 @@ #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); diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c index 45679fc9b4e..ee10a04cfb2 100644 --- a/src/gallium/state_trackers/egl/x11/native_ximage.c +++ b/src/gallium/state_trackers/egl/x11/native_ximage.c @@ -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;