From 1ed1027e886980b9b0f48fa6bfcf3d6e209c7787 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 27 May 2008 13:45:41 -0600 Subject: assorted changes to compile with new EGL 1.4 headers (untested) --- src/egl/main/egldisplay.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 074a85bf26..59d0bd3dc3 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -26,10 +26,11 @@ _eglNewDisplay(NativeDisplayType displayName) { _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); if (dpy) { - dpy->Handle = _eglHashGenKey(_eglGlobal.Displays); - _eglHashInsert(_eglGlobal.Displays, dpy->Handle, dpy); + EGLuint key = _eglHashGenKey(_eglGlobal.Displays); + dpy->Handle = (EGLDisplay) key; + _eglHashInsert(_eglGlobal.Displays, key, dpy); if (displayName) - dpy->Name = my_strdup(displayName); + dpy->Name = my_strdup((char *) displayName); else dpy->Name = NULL; dpy->Driver = NULL; /* this gets set later */ @@ -45,7 +46,8 @@ _eglNewDisplay(NativeDisplayType displayName) _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy) { - _EGLDisplay *d = (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, dpy); + EGLuint key = (EGLuint) dpy; + _EGLDisplay *d = (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key); return d; } -- cgit v1.2.3 From 721ba15bf4596b2e9589e7656005b387724875c3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 27 May 2008 14:33:54 -0600 Subject: added _eglGet*Handle() functions These are the inverse of the _eglLookup*() functions. Returns the public handle for a private surface/config/display/etc. Removes glapi.c's direct access of private fields. --- src/egl/main/eglapi.c | 15 +++------------ src/egl/main/eglconfig.c | 12 ++++++++++++ src/egl/main/eglconfig.h | 4 ++++ src/egl/main/egldisplay.c | 15 +++++++++++++++ src/egl/main/egldisplay.h | 4 ++++ src/egl/main/eglsurface.c | 20 ++++++++++++++++++++ src/egl/main/eglsurface.h | 4 ++++ 7 files changed, 62 insertions(+), 12 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 4df31cc03f..e4eec26de0 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -53,10 +53,7 @@ eglGetDisplay(NativeDisplayType displayName) _EGLDisplay *dpy; _eglInitGlobals(); dpy = _eglNewDisplay(displayName); - if (dpy) - return dpy->Handle; - else - return EGL_NO_DISPLAY; + return _eglGetDisplayHandle(dpy); } @@ -269,10 +266,7 @@ EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void) { _EGLDisplay *dpy = _eglGetCurrentDisplay(); - if (dpy) - return dpy->Handle; - else - return EGL_NO_DISPLAY; + return _eglGetDisplayHandle(dpy); } @@ -288,10 +282,7 @@ EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { _EGLSurface *s = _eglGetCurrentSurface(readdraw); - if (s) - return s->Handle; - else - return EGL_NO_SURFACE; + return _eglGetSurfaceHandle(s); } diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index a74cd23113..1b49f7afd9 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -101,8 +101,20 @@ _eglInitConfig(_EGLConfig *config, EGLint id) } +/** + * Return the public handle for an internal _EGLConfig. + * This is the inverse of _eglLookupConfig(). + */ +EGLConfig +_eglGetConfigHandle(_EGLConfig *config) +{ + return config ? config->Handle : 0; +} + + /** * Given an EGLConfig handle, return the corresponding _EGLConfig object. + * This is the inverse of _eglGetConfigHandle(). */ _EGLConfig * _eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config) diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h index 88e44dfc7d..4a80612980 100644 --- a/src/egl/main/eglconfig.h +++ b/src/egl/main/eglconfig.h @@ -27,6 +27,10 @@ extern void _eglInitConfig(_EGLConfig *config, EGLint id); +extern EGLConfig +_eglGetConfigHandle(_EGLConfig *config); + + extern _EGLConfig * _eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config); diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 59d0bd3dc3..fd24f22273 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -39,9 +39,24 @@ _eglNewDisplay(NativeDisplayType displayName) } +/** + * Return the public handle for an internal _EGLDisplay. + * This is the inverse of _eglLookupDisplay(). + */ +EGLDisplay +_eglGetDisplayHandle(_EGLDisplay *display) +{ + if (display) + return display->Handle; + else + return EGL_NO_DISPLAY; +} + + /** * Return the _EGLDisplay object that corresponds to the given public/ * opaque display handle. + * This is the inverse of _eglGetDisplayHandle(). */ _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy) diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 1a03fdd4ad..fe7b788455 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -24,6 +24,10 @@ extern _EGLDisplay * _eglNewDisplay(NativeDisplayType displayName); +EGLDisplay +_eglGetDisplayHandle(_EGLDisplay *display); + + extern _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy); diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index 134afa7cbd..1dbb12ecfe 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -223,6 +223,26 @@ _eglRemoveSurface(_EGLSurface *surf) } + +/** + * Return the public handle for an internal _EGLSurface. + * This is the inverse of _eglLookupSurface(). + */ +EGLSurface +_eglGetSurfaceHandle(_EGLSurface *surface) +{ + if (surface) + return surface->Handle; + else + return EGL_NO_SURFACE; +} + + +/** + * Return the private _EGLSurface which corresponds to a public EGLSurface + * handle. + * This is the inverse of _eglGetSurfaceHandle(). + */ _EGLSurface * _eglLookupSurface(EGLSurface surf) { diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h index 79abeca0b2..df1e70122e 100644 --- a/src/egl/main/eglsurface.h +++ b/src/egl/main/eglsurface.h @@ -51,6 +51,10 @@ extern void _eglRemoveSurface(_EGLSurface *surf); +extern EGLSurface +_eglGetSurfaceHandle(_EGLSurface *surface); + + extern _EGLSurface * _eglLookupSurface(EGLSurface surf); -- cgit v1.2.3 From 6052af172f0241e6678cd16efac0a0f14f40146c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 27 May 2008 16:48:23 -0600 Subject: minor overhaul/re-org of driver selection/loading code --- src/egl/main/Makefile | 11 ++++++--- src/egl/main/eglapi.c | 27 ++++++++++++++------- src/egl/main/eglconfig.c | 4 +--- src/egl/main/eglconfig.h | 6 ++--- src/egl/main/egldisplay.c | 57 ++++++++++++++++++++++++++++++++----------- src/egl/main/egldisplay.h | 14 ++++++++++- src/egl/main/egldriver.c | 61 +++++++++++++++++++++++++++-------------------- src/egl/main/egldriver.h | 6 ++--- 8 files changed, 124 insertions(+), 62 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index e1058a23f7..0efcd4e605 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -16,7 +16,8 @@ HEADERS = \ eglhash.h \ eglmode.h \ eglscreen.h \ - eglsurface.h + eglsurface.h \ + eglx.h SOURCES = \ eglapi.c \ @@ -29,13 +30,17 @@ SOURCES = \ eglhash.c \ eglmode.c \ eglscreen.c \ - eglsurface.c + eglsurface.c \ + eglx.c OBJECTS = $(SOURCES:.c=.o) +LOCAL_CFLAGS = -D_EGL_PLATFORM_X=1 + + .c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@ diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index e4eec26de0..fe63d36b80 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -43,27 +43,38 @@ /** - * NOTE: displayName is treated as a string in _eglChooseDriver()!!! - * This will probably change! - * See _eglChooseDriver() for details! + * This is typically the first EGL function that an application calls. + * We initialize our global vars and create a private _EGLDisplay object. */ EGLDisplay EGLAPIENTRY -eglGetDisplay(NativeDisplayType displayName) +eglGetDisplay(NativeDisplayType nativeDisplay) { _EGLDisplay *dpy; _eglInitGlobals(); - dpy = _eglNewDisplay(displayName); + dpy = _eglNewDisplay(nativeDisplay); return _eglGetDisplayHandle(dpy); } +/** + * This is typically the second EGL function that an application calls. + * Here we load/initialize the actual hardware driver. + */ EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) { if (dpy) { - _EGLDriver *drv = _eglChooseDriver(dpy); - if (drv) - return drv->API.Initialize(drv, dpy, major, minor); + _EGLDisplay *dpyPriv = _eglLookupDisplay(dpy); + if (!dpyPriv) { + return EGL_FALSE; + } + dpyPriv->Driver = _eglOpenDriver(dpyPriv, dpyPriv->DriverName); + if (!dpyPriv->Driver) { + return EGL_FALSE; + } + /* Initialize the particular driver now */ + return dpyPriv->Driver->API.Initialize(dpyPriv->Driver, dpy, + major, minor); } return EGL_FALSE; } diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index 1b49f7afd9..eb2c34a802 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -17,7 +17,6 @@ #define MIN2(A, B) (((A) < (B)) ? (A) : (B)) -#if 0 /** * Convert an _EGLConfig to a __GLcontextModes object. * NOTE: This routine may be incomplete - we're only making sure that @@ -58,7 +57,6 @@ _eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode) mode->visualType = GLX_TRUE_COLOR; mode->renderType = GLX_RGBA_BIT; } -#endif void @@ -445,6 +443,7 @@ _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, } +#if 0 /** * Creates a set of \c __GLcontextModes that a driver will expose. * @@ -512,7 +511,6 @@ _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32, * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it. */ -#if 0 GLboolean _eglFillInConfigs(_EGLConfig * configs, GLenum fb_format, GLenum fb_type, diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h index 4a80612980..e025f7f845 100644 --- a/src/egl/main/eglconfig.h +++ b/src/egl/main/eglconfig.h @@ -3,9 +3,8 @@ #include "egltypedefs.h" -#if 0 +#include #include "GL/internal/glcore.h" -#endif #define MAX_ATTRIBS 100 @@ -68,10 +67,9 @@ _eglFillInConfigs( _EGLConfig *configs, int visType ); #endif -#if 0 + extern void _eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode); -#endif #endif /* EGLCONFIG_INCLUDED */ diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index fd24f22273..9c42194c61 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -1,7 +1,14 @@ + +/** + * Functions related to EGLDisplay. + */ + +#include #include #include #include "eglcontext.h" #include "egldisplay.h" +#include "egldriver.h" #include "eglglobals.h" #include "eglhash.h" @@ -9,31 +16,41 @@ static char * my_strdup(const char *s) { - int l = strlen(s); - char *s2 = malloc(l + 1); - strcpy(s2, s); - return s2; + if (s) { + int l = strlen(s); + char *s2 = malloc(l + 1); + if (s2) + strcpy(s2, s); + return s2; + } + return NULL; } /** - * We're assuming that the NativeDisplayType parameter is actually - * a string. - * Return a new _EGLDisplay object for the given displayName + * Allocate a new _EGLDisplay object for the given nativeDisplay handle. + * We'll also try to determine the device driver name at this time. */ _EGLDisplay * -_eglNewDisplay(NativeDisplayType displayName) +_eglNewDisplay(NativeDisplayType nativeDisplay) { _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); if (dpy) { EGLuint key = _eglHashGenKey(_eglGlobal.Displays); + dpy->Handle = (EGLDisplay) key; _eglHashInsert(_eglGlobal.Displays, key, dpy); - if (displayName) - dpy->Name = my_strdup((char *) displayName); - else - dpy->Name = NULL; - dpy->Driver = NULL; /* this gets set later */ + + dpy->NativeDisplay = nativeDisplay; +#if defined(_EGL_PLATFORM_X) + dpy->Xdpy = (Display *) nativeDisplay; +#endif + + dpy->DriverName = my_strdup(_eglChooseDriver(dpy)); + if (!dpy->DriverName) { + free(dpy); + return NULL; + } } return dpy; } @@ -67,6 +84,18 @@ _eglLookupDisplay(EGLDisplay dpy) } +void +_eglSaveDisplay(_EGLDisplay *dpy) +{ + EGLuint key = _eglHashGenKey(_eglGlobal.Displays); + assert(dpy); + assert(!dpy->Handle); + dpy->Handle = (EGLDisplay) key; + assert(dpy->Handle); + _eglHashInsert(_eglGlobal.Displays, key, dpy); +} + + _EGLDisplay * _eglGetCurrentDisplay(void) { @@ -83,6 +112,6 @@ _eglCleanupDisplay(_EGLDisplay *disp) { /* XXX incomplete */ free(disp->Configs); - free(disp->Name); + free((void *) disp->DriverName); /* driver deletes _EGLDisplay */ } diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index fe7b788455..be134374ca 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -1,15 +1,19 @@ #ifndef EGLDISPLAY_INCLUDED #define EGLDISPLAY_INCLUDED +#ifdef _EGL_PLATFORM_X +#include +#endif #include "egltypedefs.h" struct _egl_display { + EGLNativeDisplayType NativeDisplay; EGLDisplay Handle; - char *Name; + const char *DriverName; _EGLDriver *Driver; EGLint NumScreens; @@ -17,6 +21,10 @@ struct _egl_display EGLint NumConfigs; _EGLConfig *Configs; /* array [NumConfigs] */ + +#ifdef _EGL_PLATFORM_X + Display *Xdpy; +#endif }; @@ -32,6 +40,10 @@ extern _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy); +extern void +_eglSaveDisplay(_EGLDisplay *dpy); + + extern _EGLDisplay * _eglGetCurrentDisplay(void); diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index bda06dd827..50c466c258 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -1,3 +1,8 @@ +/** + * Functions for choosing and opening/loading device drivers. + */ + + #include #include #include @@ -11,62 +16,64 @@ #include "eglmode.h" #include "eglscreen.h" #include "eglsurface.h" +#include "eglx.h" const char *DefaultDriverName = "demodriver"; /** - * Choose and open/init the hardware driver for the given EGLDisplay. - * Previously, the EGLDisplay was created with _eglNewDisplay() where - * we recorded the user's NativeDisplayType parameter. + * Determine/return the name of the driver to use for the given _EGLDisplay. * - * Now we'll use the NativeDisplayType value. + * Try to be clever and determine if nativeDisplay is an Xlib Display + * ptr or a string (naming a driver or screen number, etc). * - * Currently, the native display value is treated as a string. * If the first character is ':' we interpret it as a screen or card index * number (i.e. ":0" or ":1", etc) * Else if the first character is '!' we interpret it as specific driver name * (i.e. "!r200" or "!i830". + * + * The caller should make a copy of the returned string. */ -_EGLDriver * -_eglChooseDriver(EGLDisplay display) +const char * +_eglChooseDriver(_EGLDisplay *dpy) { - _EGLDisplay *dpy = _eglLookupDisplay(display); - _EGLDriver *drv; - const char *driverName = DefaultDriverName; - const char *name; + const char *name = (const char *) dpy->NativeDisplay; + const char *driverName = NULL; - assert(dpy); - - name = dpy->Name; - if (!name) { - /* use default */ + if (!dpy->NativeDisplay) { + /* choose a default */ + driverName = DefaultDriverName; } - else if (name[0] == ':' && (name[1] >= '0' && name[1] <= '9') && !name[2]) { + else if (name && name[0] == ':' && + (name[1] >= '0' && name[1] <= '9') && !name[2]) { /* XXX probe hardware here to determine which driver to open */ driverName = "libEGLdri"; } - else if (name[0] == '!') { + else if (name && name[0] == '!') { /* use specified driver name */ driverName = name + 1; } else { - /* Maybe display was returned by XOpenDisplay? */ - _eglLog(_EGL_FATAL, "eglChooseDriver() bad name"); +#if defined(_EGL_PLATFORM_X) + driverName = _xeglChooseDriver(dpy); +#elif defined(_EGL_PLATFORM_WINDOWS) + /* XXX to do */ + driverName = _weglChooseDriver(dpy); +#elif defined(_EGL_PLATFORM_WINCE) + /* XXX to do */ +#endif } - _eglLog(_EGL_INFO, "eglChooseDriver() choosing %s", driverName); - - drv = _eglOpenDriver(dpy, driverName); - dpy->Driver = drv; - - return drv; + return driverName; } /** * Open/load the named driver and call its bootstrap function: _eglMain(). + * By the time this function is called, the dpy->DriverName should have + * been determined. + * * \return new _EGLDriver object. */ _EGLDriver * @@ -77,6 +84,8 @@ _eglOpenDriver(_EGLDisplay *dpy, const char *driverName) void *lib; char driverFilename[1000]; + assert(driverName); + /* XXX also prepend a directory path??? */ sprintf(driverFilename, "%s.so", driverName); diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 88526e973d..bde726e25e 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -45,12 +45,12 @@ struct _egl_driver extern _EGLDriver *_eglMain(_EGLDisplay *dpy); -extern _EGLDriver * -_eglChooseDriver(EGLDisplay dpy); +extern const char * +_eglChooseDriver(_EGLDisplay *dpy); extern _EGLDriver * -_eglOpenDriver(_EGLDisplay *dpy, const char *driverName); +_eglOpenDriver(_EGLDisplay *dpy, const char *DriverName); extern EGLBoolean -- cgit v1.2.3 From 0c8908c411c434eda318b41b4f2a370a1e794831 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 28 May 2008 12:56:36 -0600 Subject: egl: added args string to _eglMain() --- src/egl/drivers/demo/demo.c | 2 +- src/egl/drivers/dri/egldri.c | 4 ++-- src/egl/main/eglapi.c | 4 +++- src/egl/main/egldisplay.c | 19 ++++--------------- src/egl/main/egldisplay.h | 1 + src/egl/main/egldriver.c | 35 +++++++++++++++++++++++++---------- src/egl/main/egldriver.h | 4 ++-- src/egl/main/egltypedefs.h | 2 +- 8 files changed, 39 insertions(+), 32 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/drivers/demo/demo.c b/src/egl/drivers/demo/demo.c index 1033f1b4ed..6b8b71d16b 100644 --- a/src/egl/drivers/demo/demo.c +++ b/src/egl/drivers/demo/demo.c @@ -286,7 +286,7 @@ demoMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface rea * plug in API functions. */ _EGLDriver * -_eglMain(_EGLDisplay *dpy) +_eglMain(_EGLDisplay *dpy, const char *args) { DemoDriver *demo; diff --git a/src/egl/drivers/dri/egldri.c b/src/egl/drivers/dri/egldri.c index f00625a059..677073fb3a 100644 --- a/src/egl/drivers/dri/egldri.c +++ b/src/egl/drivers/dri/egldri.c @@ -79,11 +79,11 @@ driver_name_from_card_number(int card, char *driverName, int maxDriverName) * This function, in turn, loads a specific DRI driver (ex: r200_dri.so). */ _EGLDriver * -_eglMain(_EGLDisplay *dpy) +_eglMain(_EGLDisplay *dpy, const char *args) { #if 1 const char *displayString = (const char *) dpy->NativeDisplay; - const int card = atoi(displayString + 1); + const int card = atoi(args); _EGLDriver *driver = NULL; char driverName[1000]; diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index fe63d36b80..984af4ea22 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -68,7 +68,9 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) if (!dpyPriv) { return EGL_FALSE; } - dpyPriv->Driver = _eglOpenDriver(dpyPriv, dpyPriv->DriverName); + dpyPriv->Driver = _eglOpenDriver(dpyPriv, + dpyPriv->DriverName, + dpyPriv->DriverArgs); if (!dpyPriv->Driver) { return EGL_FALSE; } diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 9c42194c61..b2d30d4274 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -11,25 +11,14 @@ #include "egldriver.h" #include "eglglobals.h" #include "eglhash.h" - - -static char * -my_strdup(const char *s) -{ - if (s) { - int l = strlen(s); - char *s2 = malloc(l + 1); - if (s2) - strcpy(s2, s); - return s2; - } - return NULL; -} +#include "eglstring.h" /** * Allocate a new _EGLDisplay object for the given nativeDisplay handle. * We'll also try to determine the device driver name at this time. + * + * Note that nativeDisplay may be an X Display ptr, or a string. */ _EGLDisplay * _eglNewDisplay(NativeDisplayType nativeDisplay) @@ -46,7 +35,7 @@ _eglNewDisplay(NativeDisplayType nativeDisplay) dpy->Xdpy = (Display *) nativeDisplay; #endif - dpy->DriverName = my_strdup(_eglChooseDriver(dpy)); + dpy->DriverName = _eglstrdup(_eglChooseDriver(dpy)); if (!dpy->DriverName) { free(dpy); return NULL; diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index be134374ca..e2ebab0b21 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -14,6 +14,7 @@ struct _egl_display EGLDisplay Handle; const char *DriverName; + const char *DriverArgs; _EGLDriver *Driver; EGLint NumScreens; diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index cbdd47948d..599077190a 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "eglconfig.h" #include "eglcontext.h" @@ -15,6 +16,7 @@ #include "egllog.h" #include "eglmode.h" #include "eglscreen.h" +#include "eglstring.h" #include "eglsurface.h" #if defined(_EGL_PLATFORM_X) @@ -25,7 +27,7 @@ /* XXX to do */ #endif -const char *DefaultDriverName = "demodriver"; +const char *DefaultDriverName = ":0"; /** @@ -44,23 +46,36 @@ const char *DefaultDriverName = "demodriver"; const char * _eglChooseDriver(_EGLDisplay *dpy) { - const char *name = (const char *) dpy->NativeDisplay; + const char *displayString = (const char *) dpy->NativeDisplay; const char *driverName = NULL; - if (!dpy->NativeDisplay) { + if (!displayString) { /* choose a default */ - driverName = DefaultDriverName; + displayString = DefaultDriverName; } - else if (name && name[0] == ':' && - (name[1] >= '0' && name[1] <= '9') && !name[2]) { + + /* extract default DriverArgs = whatever follows ':' */ + if (displayString[0] == '!' || + displayString[0] == ':') { + const char *args = strchr(displayString, ':'); + if (args) + dpy->DriverArgs = _eglstrdup(args + 1); + } + + + if (displayString && displayString[0] == ':' && + (displayString[1] >= '0' && displayString[1] <= '9') && + !displayString[2]) { /* XXX probe hardware here to determine which driver to open */ driverName = "libEGLdri"; } - else if (name && name[0] == '!') { + else if (displayString && displayString[0] == '!') { /* use specified driver name */ - driverName = name + 1; + driverName = displayString + 1; } else { + /* NativeDisplay is not a string! */ + #if defined(_EGL_PLATFORM_X) driverName = _xeglChooseDriver(dpy); #elif defined(_EGL_PLATFORM_WINDOWS) @@ -83,7 +98,7 @@ _eglChooseDriver(_EGLDisplay *dpy) * \return new _EGLDriver object. */ _EGLDriver * -_eglOpenDriver(_EGLDisplay *dpy, const char *driverName) +_eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args) { _EGLDriver *drv; _EGLMain_t mainFunc; @@ -110,7 +125,7 @@ _eglOpenDriver(_EGLDisplay *dpy, const char *driverName) return NULL; } - drv = mainFunc(dpy); + drv = mainFunc(dpy, args); if (!drv) { dlclose(lib); return NULL; diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index bde726e25e..9c505880b7 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -42,7 +42,7 @@ struct _egl_driver }; -extern _EGLDriver *_eglMain(_EGLDisplay *dpy); +extern _EGLDriver *_eglMain(_EGLDisplay *dpy, const char *args); extern const char * @@ -50,7 +50,7 @@ _eglChooseDriver(_EGLDisplay *dpy); extern _EGLDriver * -_eglOpenDriver(_EGLDisplay *dpy, const char *DriverName); +_eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args); extern EGLBoolean diff --git a/src/egl/main/egltypedefs.h b/src/egl/main/egltypedefs.h index 53810a5a44..b1c8ec1f02 100644 --- a/src/egl/main/egltypedefs.h +++ b/src/egl/main/egltypedefs.h @@ -30,7 +30,7 @@ typedef struct _egl_thread_info _EGLThreadInfo; typedef void (*_EGLProc)(); -typedef _EGLDriver *(*_EGLMain_t)(_EGLDisplay *dpy); +typedef _EGLDriver *(*_EGLMain_t)(_EGLDisplay *dpy, const char *args); #endif /* EGLTYPEDEFS_INCLUDED */ -- cgit v1.2.3 From 9843c6420d88db0c43b831cf79a3d1872c636225 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 28 May 2008 14:51:40 -0600 Subject: egl: bring card->driver lookup code into egldriver.c --- src/egl/main/egldisplay.c | 2 +- src/egl/main/egldriver.c | 60 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 8 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index b2d30d4274..8fd29b8421 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -35,7 +35,7 @@ _eglNewDisplay(NativeDisplayType nativeDisplay) dpy->Xdpy = (Display *) nativeDisplay; #endif - dpy->DriverName = _eglstrdup(_eglChooseDriver(dpy)); + dpy->DriverName = _eglChooseDriver(dpy); if (!dpy->DriverName) { free(dpy); return NULL; diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 599077190a..b58222e48e 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -28,6 +28,44 @@ #endif const char *DefaultDriverName = ":0"; +const char *SysFS = "/sys/class"; + + + + +/** + * Given a card number, use sysfs to determine the DRI driver name. + */ +static const char * +_eglChooseDRMDriver(int card) +{ +#if 0 + return _eglstrdup("libEGLdri"); +#else + char path[2000], driverName[2000]; + FILE *f; + int length; + + snprintf(path, sizeof(path), "%s/drm/card%d/dri_library_name", SysFS, card); + + f = fopen(path, "r"); + if (!f) + return NULL; + + fgets(driverName, sizeof(driverName), f); + fclose(f); + + if ((length = strlen(driverName)) > 1) { + /* remove the trailing newline from sysfs */ + driverName[length - 1] = '\0'; + strncat(driverName, "_dri", sizeof(driverName)); + return _eglstrdup(driverName); + } + else { + return NULL; + } +#endif +} /** @@ -41,7 +79,9 @@ const char *DefaultDriverName = ":0"; * Else if the first character is '!' we interpret it as specific driver name * (i.e. "!r200" or "!i830". * - * The caller should make a copy of the returned string. + * Whatever follows ':' is copied and put into dpy->DriverArgs. + * + * The caller may free() the returned string. */ const char * _eglChooseDriver(_EGLDisplay *dpy) @@ -62,20 +102,26 @@ _eglChooseDriver(_EGLDisplay *dpy) dpy->DriverArgs = _eglstrdup(args + 1); } - + /* determine driver name now */ if (displayString && displayString[0] == ':' && (displayString[1] >= '0' && displayString[1] <= '9') && !displayString[2]) { - /* XXX probe hardware here to determine which driver to open */ - driverName = "libEGLdri"; + int card = atoi(displayString + 1); + driverName = _eglChooseDRMDriver(card); } else if (displayString && displayString[0] == '!') { - /* use specified driver name */ - driverName = displayString + 1; + /* use user-specified driver name */ + driverName = _eglstrdup(displayString + 1); + /* truncate driverName at ':' if present */ + { + char *args = strchr(driverName, ':'); + if (args) { + *args = 0; + } + } } else { /* NativeDisplay is not a string! */ - #if defined(_EGL_PLATFORM_X) driverName = _xeglChooseDriver(dpy); #elif defined(_EGL_PLATFORM_WINDOWS) -- cgit v1.2.3 From 97035cb19aaf508aad45446651a80da9af1d0e8c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 4 Jun 2008 11:34:10 -0600 Subject: egl: in _eglAddConfig() just save a pointer to the config; don't copy the config This allows subclassing by drivers. --- src/egl/main/eglconfig.c | 25 +++++++++++++------------ src/egl/main/eglconfig.h | 2 +- src/egl/main/egldisplay.c | 18 ++++++++++++++++-- src/egl/main/egldisplay.h | 2 +- 4 files changed, 31 insertions(+), 16 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index c6369e7adf..794a783b9e 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -78,8 +78,8 @@ _eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config) EGLint i; _EGLDisplay *disp = _eglLookupDisplay(dpy); for (i = 0; i < disp->NumConfigs; i++) { - if (disp->Configs[i].Handle == config) { - return disp->Configs + i; + if (disp->Configs[i]->Handle == config) { + return disp->Configs[i]; } } return NULL; @@ -88,23 +88,24 @@ _eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config) /** * Add the given _EGLConfig to the given display. + * Note that we just save the ptr to the config (we don't copy the config). */ _EGLConfig * -_eglAddConfig(_EGLDisplay *display, const _EGLConfig *config) +_eglAddConfig(_EGLDisplay *display, _EGLConfig *config) { - _EGLConfig *newConfigs; + _EGLConfig **newConfigs; EGLint n; n = display->NumConfigs; - newConfigs = (_EGLConfig *) realloc(display->Configs, - (n + 1) * sizeof(_EGLConfig)); + /* realloc array of ptrs */ + newConfigs = (_EGLConfig **) realloc(display->Configs, + (n + 1) * sizeof(_EGLConfig *)); if (newConfigs) { display->Configs = newConfigs; - display->Configs[n] = *config; /* copy struct */ - display->Configs[n].Handle = (EGLConfig) n; + display->Configs[n] = config; display->NumConfigs++; - return display->Configs + n; + return config; } else { return NULL; @@ -330,8 +331,8 @@ _eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, /* make array of pointers to qualifying configs */ for (i = count = 0; i < disp->NumConfigs && count < config_size; i++) { - if (_eglConfigQualifies(disp->Configs + i, &criteria)) { - configList[count++] = disp->Configs + i; + if (_eglConfigQualifies(disp->Configs[i], &criteria)) { + configList[count++] = disp->Configs[i]; } } @@ -389,7 +390,7 @@ _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint i; *num_config = MIN2(disp->NumConfigs, config_size); for (i = 0; i < *num_config; i++) { - configs[i] = disp->Configs[i].Handle; + configs[i] = disp->Configs[i]->Handle; } } else { diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h index b10a61985d..d12f66245c 100644 --- a/src/egl/main/eglconfig.h +++ b/src/egl/main/eglconfig.h @@ -34,7 +34,7 @@ _eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config); extern _EGLConfig * -_eglAddConfig(_EGLDisplay *display, const _EGLConfig *config); +_eglAddConfig(_EGLDisplay *display, _EGLConfig *config); extern EGLBoolean diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 8fd29b8421..540efd4fee 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -96,11 +96,25 @@ _eglGetCurrentDisplay(void) } +/** + * Free all the data hanging of an _EGLDisplay object, but not + * the object itself. + */ void _eglCleanupDisplay(_EGLDisplay *disp) { - /* XXX incomplete */ + EGLint i; + + for (i = 0; i < disp->NumConfigs; i++) { + free(disp->Configs[i]); + } free(disp->Configs); + disp->Configs = NULL; + + /* XXX incomplete */ + free((void *) disp->DriverName); - /* driver deletes _EGLDisplay */ + disp->DriverName = NULL; + + /* driver deletes the _EGLDisplay object */ } diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index e2ebab0b21..ff623ee1c6 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -21,7 +21,7 @@ struct _egl_display _EGLScreen **Screens; /* array [NumScreens] */ EGLint NumConfigs; - _EGLConfig *Configs; /* array [NumConfigs] */ + _EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */ #ifdef _EGL_PLATFORM_X Display *Xdpy; -- cgit v1.2.3 From 677151ad71d7f0792fb79597e972e2cad2cfc7d4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 20 Jun 2008 14:28:59 -0600 Subject: egl: added null ptr check --- src/egl/main/egldisplay.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 540efd4fee..47a2323eaf 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -68,8 +68,9 @@ _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy) { EGLuint key = (EGLuint) dpy; - _EGLDisplay *d = (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key); - return d; + if (!_eglGlobal.Displays) + return NULL; + return (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key); } -- cgit v1.2.3 From 75da80b29556e6dbbba21e5297ca440e475f65cb Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 17 Jul 2009 11:41:02 -0600 Subject: egl: Support per-thread info. This commit introduces a "current" system to manage per-thread info. It uses TLS, if GLX_USE_TLS is defined, or pthread, if PTHREADS is defined. If none of them are defined, it uses a dummy implementation that is just like before. Signed-off-by: Chia-I Wu --- configs/default | 2 +- src/egl/main/Makefile | 2 + src/egl/main/eglapi.c | 16 +++++-- src/egl/main/eglcontext.c | 14 ++---- src/egl/main/eglcontext.h | 4 -- src/egl/main/egldisplay.c | 11 ----- src/egl/main/egldisplay.h | 4 -- src/egl/main/eglglobals.c | 113 ++-------------------------------------------- src/egl/main/eglglobals.h | 31 +------------ src/egl/main/eglsurface.c | 18 -------- src/egl/main/eglsurface.h | 4 -- 11 files changed, 23 insertions(+), 196 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/configs/default b/configs/default index a8996702d7..60638d739d 100644 --- a/configs/default +++ b/configs/default @@ -105,7 +105,7 @@ GALLIUM_STATE_TRACKERS_DIRS = glx # Library dependencies #EXTRA_LIB_PATH ?= GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread -EGL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -ldl +EGL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -ldl -lpthread OSMESA_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) GLU_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm GLUT_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXi -lm diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index 4034b28e91..e1ff8794b3 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -11,6 +11,7 @@ HEADERS = \ eglconfig.h \ eglconfigutil.h \ eglcontext.h \ + eglcurrent.h \ egldefines.h \ egldisplay.h \ egldriver.h \ @@ -29,6 +30,7 @@ SOURCES = \ eglconfig.c \ eglconfigutil.c \ eglcontext.c \ + eglcurrent.c \ egldisplay.c \ egldriver.c \ eglglobals.c \ diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 9df938e188..8f4a489b91 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -321,7 +321,8 @@ eglGetError(void) { _EGLThreadInfo *t = _eglGetCurrentThread(); EGLint e = t->LastError; - t->LastError = EGL_SUCCESS; + if (!_eglIsCurrentThreadDummy()) + t->LastError = EGL_SUCCESS; return e; } @@ -546,6 +547,9 @@ eglBindAPI(EGLenum api) { _EGLThreadInfo *t = _eglGetCurrentThread(); + if (_eglIsCurrentThreadDummy()) + return _eglError(EGL_BAD_ALLOC, "eglBindAPI"); + switch (api) { #ifdef EGL_VERSION_1_4 case EGL_OPENGL_API: @@ -603,15 +607,19 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLBoolean eglReleaseThread(void) { - _EGLThreadInfo *t = _eglGetCurrentThread(); - EGLDisplay dpy = eglGetCurrentDisplay(); + EGLDisplay dpy; + + if (_eglIsCurrentThreadDummy()) + return EGL_TRUE; + + dpy = eglGetCurrentDisplay(); if (dpy) { _EGLDriver *drv = _eglLookupDriver(dpy); /* unbind context */ (void) drv->API.MakeCurrent(drv, dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } - _eglDeleteThreadData(t); + _eglDestroyCurrentThread(); return EGL_TRUE; } diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index 461679db09..5e24b02a58 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -108,17 +108,6 @@ _eglLookupContext(EGLContext ctx) } -/** - * Return the currently bound _EGLContext object, or NULL. - */ -_EGLContext * -_eglGetCurrentContext(void) -{ - _EGLThreadInfo *t = _eglGetCurrentThread(); - return t->CurrentContext; -} - - /** * Just a placeholder/demo function. Real driver will never use this! */ @@ -219,6 +208,9 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, _EGLSurface *oldDrawSurface = _eglGetCurrentSurface(EGL_DRAW); _EGLSurface *oldReadSurface = _eglGetCurrentSurface(EGL_READ); + if (_eglIsCurrentThreadDummy()) + return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent"); + /* error checking */ if (ctx) { if (draw == NULL || read == NULL) { diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h index 34fee9c637..5c8403153b 100644 --- a/src/egl/main/eglcontext.h +++ b/src/egl/main/eglcontext.h @@ -47,10 +47,6 @@ extern _EGLContext * _eglLookupContext(EGLContext ctx); -extern _EGLContext * -_eglGetCurrentContext(void); - - extern EGLContext _eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 47a2323eaf..01f67f6e47 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -86,17 +86,6 @@ _eglSaveDisplay(_EGLDisplay *dpy) } -_EGLDisplay * -_eglGetCurrentDisplay(void) -{ - _EGLContext *ctx = _eglGetCurrentContext(); - if (ctx) - return ctx->Display; - else - return NULL; -} - - /** * Free all the data hanging of an _EGLDisplay object, but not * the object itself. diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index ff623ee1c6..69f0d130ef 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -45,10 +45,6 @@ extern void _eglSaveDisplay(_EGLDisplay *dpy); -extern _EGLDisplay * -_eglGetCurrentDisplay(void); - - extern void _eglCleanupDisplay(_EGLDisplay *disp); diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c index b770e55dbd..55de394ef5 100644 --- a/src/egl/main/eglglobals.c +++ b/src/egl/main/eglglobals.c @@ -1,6 +1,6 @@ -#include #include #include "eglglobals.h" +#include "egllog.h" struct _egl_global _eglGlobal = { @@ -22,8 +22,8 @@ _eglInitGlobals(void) _eglGlobal.ClientAPIsMask = 0x0; - /* XXX temporary */ - _eglGlobal.ThreadInfo = _eglNewThreadInfo(); + if (!_eglInitCurrent()) + _eglLog(_EGL_FATAL, "failed to initialize \"current\" system"); } } @@ -34,113 +34,8 @@ _eglInitGlobals(void) void _eglDestroyGlobals(void) { + _eglFiniCurrent(); /* XXX TODO walk over table entries, deleting each */ _eglDeleteHashTable(_eglGlobal.Displays); _eglDeleteHashTable(_eglGlobal.Surfaces); } - - -/** - * Allocate and init a new _EGLThreadInfo object. - */ -_EGLThreadInfo * -_eglNewThreadInfo(void) -{ - _EGLThreadInfo *t = (_EGLThreadInfo *) calloc(1, sizeof(_EGLThreadInfo)); - if (t) { - t->CurrentContext = EGL_NO_CONTEXT; - t->LastError = EGL_SUCCESS; - t->CurrentAPI = EGL_OPENGL_ES_API; /* default, per EGL spec */ - } - return t; -} - - -/** - * Delete/free a _EGLThreadInfo object. - */ -void -_eglDeleteThreadData(_EGLThreadInfo *t) -{ - free(t); -} - - - -/** - * Return pointer to calling thread's _EGLThreadInfo object. - * Create a new one if needed. - * Should never return NULL. - */ -_EGLThreadInfo * -_eglGetCurrentThread(void) -{ - _eglInitGlobals(); - - /* XXX temporary */ - return _eglGlobal.ThreadInfo; -} - - -/** - * Record EGL error code. - */ -void -_eglError(EGLint errCode, const char *msg) -{ - _EGLThreadInfo *t = _eglGetCurrentThread(); - const char *s; - - if (t->LastError == EGL_SUCCESS) { - t->LastError = errCode; - - switch (errCode) { - case EGL_BAD_ACCESS: - s = "EGL_BAD_ACCESS"; - break; - case EGL_BAD_ALLOC: - s = "EGL_BAD_ALLOC"; - break; - case EGL_BAD_ATTRIBUTE: - s = "EGL_BAD_ATTRIBUTE"; - break; - case EGL_BAD_CONFIG: - s = "EGL_BAD_CONFIG"; - break; - case EGL_BAD_CONTEXT: - s = "EGL_BAD_CONTEXT"; - break; - case EGL_BAD_CURRENT_SURFACE: - s = "EGL_BAD_CURRENT_SURFACE"; - break; - case EGL_BAD_DISPLAY: - s = "EGL_BAD_DISPLAY"; - break; - case EGL_BAD_MATCH: - s = "EGL_BAD_MATCH"; - break; - case EGL_BAD_NATIVE_PIXMAP: - s = "EGL_BAD_NATIVE_PIXMAP"; - break; - case EGL_BAD_NATIVE_WINDOW: - s = "EGL_BAD_NATIVE_WINDOW"; - break; - case EGL_BAD_PARAMETER: - s = "EGL_BAD_PARAMETER"; - break; - case EGL_BAD_SURFACE: - s = "EGL_BAD_SURFACE"; - break; - case EGL_BAD_SCREEN_MESA: - s = "EGL_BAD_SCREEN_MESA"; - break; - case EGL_BAD_MODE_MESA: - s = "EGL_BAD_MODE_MESA"; - break; - default: - s = "other"; - } - /* XXX temporary */ - fprintf(stderr, "EGL user error 0x%x (%s) in %s\n", errCode, s, msg); - } -} diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h index 14d8ea487a..fbb55c23f0 100644 --- a/src/egl/main/eglglobals.h +++ b/src/egl/main/eglglobals.h @@ -3,17 +3,7 @@ #include "egltypedefs.h" #include "eglhash.h" - - -/** - * Per-thread info - */ -struct _egl_thread_info -{ - EGLint LastError; - _EGLContext *CurrentContext; - EGLenum CurrentAPI; -}; +#include "eglcurrent.h" /** @@ -33,9 +23,6 @@ struct _egl_global char ClientAPIs[1000]; /**< updated by eglQueryString */ - /* XXX temporary - should be thread-specific data (TSD) */ - _EGLThreadInfo *ThreadInfo; - EGLint NumDrivers; _EGLDriver *Drivers[10]; }; @@ -52,20 +39,4 @@ extern void _eglDestroyGlobals(void); -extern _EGLThreadInfo * -_eglNewThreadInfo(void); - - -extern void -_eglDeleteThreadData(_EGLThreadInfo *t); - - -extern _EGLThreadInfo * -_eglGetCurrentThread(void); - - -extern void -_eglError(EGLint errCode, const char *msg); - - #endif /* EGLGLOBALS_INCLUDED */ diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index 6905acac50..964288aac8 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -259,24 +259,6 @@ _eglLookupSurface(EGLSurface surf) } -_EGLSurface * -_eglGetCurrentSurface(EGLint readdraw) -{ - _EGLContext *ctx = _eglGetCurrentContext(); - if (ctx) { - switch (readdraw) { - case EGL_DRAW: - return ctx->DrawSurface; - case EGL_READ: - return ctx->ReadSurface; - default: - return NULL; - } - } - return NULL; -} - - EGLBoolean _eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) { diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h index 50f965b5cb..3b54221bd3 100644 --- a/src/egl/main/eglsurface.h +++ b/src/egl/main/eglsurface.h @@ -60,10 +60,6 @@ extern _EGLSurface * _eglLookupSurface(EGLSurface surf); -extern _EGLSurface * -_eglGetCurrentSurface(EGLint readdraw); - - extern EGLBoolean _eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw); -- cgit v1.2.3 From 18457cb263e3e062e12314e7b3d5c81a7f2ba048 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 17 Jul 2009 11:48:27 -0600 Subject: egl: Add funtions to link contexts and surfaces to displays. EGL contexts and surfaces are resources of displays. They should be managed by displays. This commit adds a bunch of functions to egldisplay.c to help establish the links between contexts/surfaces and displays. How links are established is considered opaque outside display. Functions like _eglGetSurfaceHandle or _eglLookupSurface are therefore moved to egldisplay.c, with some small modifications. The idea is also extended to display. That is, displays need to link to themselves to be looked up. This commit only adds the functions. A commit to use them should follow. Signed-off-by: Chia-I Wu --- src/egl/main/eglapi.c | 2 + src/egl/main/eglcontext.c | 25 ------ src/egl/main/eglcontext.h | 12 +-- src/egl/main/egldisplay.c | 202 ++++++++++++++++++++++++++++++++++++++++------ src/egl/main/egldisplay.h | 44 ++++++++-- src/egl/main/eglsurface.c | 29 +------ src/egl/main/eglsurface.h | 14 ++-- 7 files changed, 228 insertions(+), 100 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 332b98adf2..eaee9facd8 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -52,6 +52,8 @@ eglGetDisplay(NativeDisplayType nativeDisplay) _EGLDisplay *dpy; _eglInitGlobals(); dpy = _eglNewDisplay(nativeDisplay); + if (dpy) + _eglLinkDisplay(dpy); return _eglGetDisplayHandle(dpy); } diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index 81e69e946b..edcc6a986f 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -83,31 +83,6 @@ _eglRemoveContext(_EGLContext *ctx) } -/** - * Return the public handle for the given private context ptr. - * This is the inverse of _eglLookupContext(). - */ -EGLContext -_eglGetContextHandle(_EGLContext *ctx) -{ - /* just a cast! */ - return (EGLContext) ctx; -} - - -/** - * Return the _EGLContext object that corresponds to the given - * EGLContext handle. - * This is the inverse of _eglGetContextHandle(). - */ -_EGLContext * -_eglLookupContext(EGLContext ctx) -{ - /* just a cast since EGLContext is just a void ptr */ - return (_EGLContext *) ctx; -} - - /** * Just a placeholder/demo function. Real driver will never use this! */ diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h index 5c8403153b..6e418dfbbe 100644 --- a/src/egl/main/eglcontext.h +++ b/src/egl/main/eglcontext.h @@ -11,7 +11,9 @@ */ struct _egl_context { - _EGLDisplay *Display; /* who do I belong to? */ + /* Managed by EGLDisplay for linking */ + _EGLDisplay *Display; + _EGLContext *Next; _EGLConfig *Config; @@ -39,14 +41,6 @@ extern void _eglRemoveContext(_EGLContext *ctx); -extern EGLContext -_eglGetContextHandle(_EGLContext *ctx); - - -extern _EGLContext * -_eglLookupContext(EGLContext ctx); - - extern EGLContext _eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 01f67f6e47..a30e810b4a 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -7,6 +7,7 @@ #include #include #include "eglcontext.h" +#include "eglsurface.h" #include "egldisplay.h" #include "egldriver.h" #include "eglglobals.h" @@ -25,11 +26,6 @@ _eglNewDisplay(NativeDisplayType nativeDisplay) { _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); if (dpy) { - EGLuint key = _eglHashGenKey(_eglGlobal.Displays); - - dpy->Handle = (EGLDisplay) key; - _eglHashInsert(_eglGlobal.Displays, key, dpy); - dpy->NativeDisplay = nativeDisplay; #if defined(_EGL_PLATFORM_X) dpy->Xdpy = (Display *) nativeDisplay; @@ -46,8 +42,37 @@ _eglNewDisplay(NativeDisplayType nativeDisplay) /** - * Return the public handle for an internal _EGLDisplay. - * This is the inverse of _eglLookupDisplay(). + * Link a display to itself and return the handle of the link. + * The handle can be passed to client directly. + */ +EGLDisplay +_eglLinkDisplay(_EGLDisplay *dpy) +{ + EGLuint key; + key = _eglHashGenKey(_eglGlobal.Displays); + assert(key); + /* "link" the display to the hash table */ + _eglHashInsert(_eglGlobal.Displays, key, dpy); + dpy->Handle = (EGLDisplay) key; + + return dpy->Handle; +} + + +/** + * Unlink a linked display from itself. + * Accessing an unlinked display should generate EGL_BAD_DISPLAY error. + */ +void +_eglUnlinkDisplay(_EGLDisplay *dpy) +{ + _eglHashRemove(_eglGlobal.Displays, (EGLuint) dpy->Handle); + dpy->Handle = EGL_NO_DISPLAY; +} + + +/** + * Return the handle of a linked display, or EGL_NO_DISPLAY. */ EGLDisplay _eglGetDisplayHandle(_EGLDisplay *display) @@ -60,32 +85,17 @@ _eglGetDisplayHandle(_EGLDisplay *display) /** - * Return the _EGLDisplay object that corresponds to the given public/ - * opaque display handle. - * This is the inverse of _eglGetDisplayHandle(). + * Lookup a handle to find the linked display. + * Return NULL if the handle has no corresponding linked display. */ _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy) { EGLuint key = (EGLuint) dpy; - if (!_eglGlobal.Displays) - return NULL; return (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key); } -void -_eglSaveDisplay(_EGLDisplay *dpy) -{ - EGLuint key = _eglHashGenKey(_eglGlobal.Displays); - assert(dpy); - assert(!dpy->Handle); - dpy->Handle = (EGLDisplay) key; - assert(dpy->Handle); - _eglHashInsert(_eglGlobal.Displays, key, dpy); -} - - /** * Free all the data hanging of an _EGLDisplay object, but not * the object itself. @@ -108,3 +118,147 @@ _eglCleanupDisplay(_EGLDisplay *disp) /* driver deletes the _EGLDisplay object */ } + + +/** + * Link a context to a display and return the handle of the link. + * The handle can be passed to client directly. + */ +EGLContext +_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy) +{ + ctx->Display = dpy; + ctx->Next = dpy->ContextList; + dpy->ContextList = ctx; + return (EGLContext) ctx; +} + + +/** + * Unlink a linked context from its display. + * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. + */ +void +_eglUnlinkContext(_EGLContext *ctx) +{ + _EGLContext *prev; + + prev = ctx->Display->ContextList; + if (prev != ctx) { + while (prev) { + if (prev->Next == ctx) + break; + prev = prev->Next; + } + assert(prev); + prev->Next = ctx->Next; + } + else { + ctx->Display->ContextList = ctx->Next; + } + + ctx->Next = NULL; + ctx->Display = NULL; +} + + +/** + * 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) +{ + _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. + */ +EGLSurface +_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy) +{ + EGLuint key; + + surf->Display = dpy; + surf->Next = dpy->SurfaceList; + dpy->SurfaceList = surf; + + key = _eglHashGenKey(_eglGlobal.Surfaces); + assert(key); + _eglHashInsert(_eglGlobal.Surfaces, key, surf); + + surf->Handle = (EGLSurface) key; + return surf->Handle; +} + + +/** + * Unlink a linked surface from its display. + * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. + */ +void +_eglUnlinkSurface(_EGLSurface *surf) +{ + _EGLSurface *prev; + + _eglHashRemove(_eglGlobal.Surfaces, (EGLuint) surf->Handle); + surf->Handle = EGL_NO_SURFACE; + + prev = surf->Display->SurfaceList; + if (prev != surf) { + while (prev) { + if (prev->Next == surf) + break; + prev = prev->Next; + } + assert(prev); + prev->Next = surf->Next; + } + else { + prev = NULL; + surf->Display->SurfaceList = surf->Next; + } + + surf->Next = NULL; + surf->Display = NULL; +} + + +/** + * Return the handle of a linked surface, or EGL_NO_SURFACE. + */ +EGLSurface +_eglGetSurfaceHandle(_EGLSurface *surface) +{ + if (surface) + return surface->Handle; + else + return EGL_NO_SURFACE; +} + + +/** + * Lookup a handle to find the linked surface. + * Return NULL if the handle has no corresponding linked surface. + */ +_EGLSurface * +_eglLookupSurface(EGLSurface surf) +{ + _EGLSurface *c = (_EGLSurface *) _eglHashLookup(_eglGlobal.Surfaces, + (EGLuint) surf); + return c; +} diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 69f0d130ef..ac285f52a7 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -23,6 +23,9 @@ struct _egl_display EGLint NumConfigs; _EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */ + /* lists of linked contexts and surface */ + _EGLContext *ContextList; + _EGLSurface *SurfaceList; #ifdef _EGL_PLATFORM_X Display *Xdpy; #endif @@ -33,7 +36,15 @@ extern _EGLDisplay * _eglNewDisplay(NativeDisplayType displayName); -EGLDisplay +extern EGLDisplay +_eglLinkDisplay(_EGLDisplay *dpy); + + +extern void +_eglUnlinkDisplay(_EGLDisplay *dpy); + + +extern EGLDisplay _eglGetDisplayHandle(_EGLDisplay *display); @@ -42,16 +53,39 @@ _eglLookupDisplay(EGLDisplay dpy); extern void -_eglSaveDisplay(_EGLDisplay *dpy); +_eglCleanupDisplay(_EGLDisplay *disp); + + +extern EGLContext +_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy); extern void -_eglCleanupDisplay(_EGLDisplay *disp); +_eglUnlinkContext(_EGLContext *ctx); + + +extern EGLContext +_eglGetContextHandle(_EGLContext *ctx); + + +extern _EGLContext * +_eglLookupContext(EGLContext ctx); + + +extern EGLSurface +_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy); + + +extern void +_eglUnlinkSurface(_EGLSurface *surf); + +extern EGLSurface +_eglGetSurfaceHandle(_EGLSurface *); -extern EGLBoolean -_eglQueryDisplayMESA(_EGLDriver *drv, EGLDisplay dpy, EGLint attrib, EGLint *value); +extern _EGLSurface * +_eglLookupSurface(EGLSurface surf); #endif /* EGLDISPLAY_INCLUDED */ diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index 964288aac8..854f499fce 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -6,6 +6,7 @@ #include #include #include +#include "egldisplay.h" #include "eglcontext.h" #include "eglconfig.h" #include "egldriver.h" @@ -231,34 +232,6 @@ _eglRemoveSurface(_EGLSurface *surf) -/** - * Return the public handle for an internal _EGLSurface. - * This is the inverse of _eglLookupSurface(). - */ -EGLSurface -_eglGetSurfaceHandle(_EGLSurface *surface) -{ - if (surface) - return surface->Handle; - else - return EGL_NO_SURFACE; -} - - -/** - * Return the private _EGLSurface which corresponds to a public EGLSurface - * handle. - * This is the inverse of _eglGetSurfaceHandle(). - */ -_EGLSurface * -_eglLookupSurface(EGLSurface surf) -{ - _EGLSurface *c = (_EGLSurface *) _eglHashLookup(_eglGlobal.Surfaces, - (EGLuint) surf); - return c; -} - - EGLBoolean _eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) { diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h index 3b54221bd3..dc53669091 100644 --- a/src/egl/main/eglsurface.h +++ b/src/egl/main/eglsurface.h @@ -10,7 +10,11 @@ */ struct _egl_surface { - EGLSurface Handle; /* The public/opaque handle which names this object */ + /* Managed by EGLDisplay for linking */ + _EGLDisplay *Display; + _EGLSurface *Next; + EGLSurface Handle; + _EGLConfig *Config; /* May need reference counting here */ @@ -52,14 +56,6 @@ extern void _eglRemoveSurface(_EGLSurface *surf); -extern EGLSurface -_eglGetSurfaceHandle(_EGLSurface *surface); - - -extern _EGLSurface * -_eglLookupSurface(EGLSurface surf); - - extern EGLBoolean _eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw); -- cgit v1.2.3 From be9d1ab171b1b29108c781af84dd500707a12925 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 16 Jul 2009 21:21:56 -0700 Subject: egl: Return the same EGL Display for the same native display. 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 --- src/egl/main/eglapi.c | 9 ++++++--- src/egl/main/egldisplay.c | 24 ++++++++++++++++++++++++ src/egl/main/egldisplay.h | 4 ++++ 3 files changed, 34 insertions(+), 3 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index eaee9facd8..f0a6f7f935 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -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); } diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index a30e810b4a..1f1f41ea71 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -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. diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index ac285f52a7..0a6003f39e 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -52,6 +52,10 @@ extern _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy); +extern _EGLDisplay * +_eglFindDisplay(NativeDisplayType nativeDisplay); + + extern void _eglCleanupDisplay(_EGLDisplay *disp); -- cgit v1.2.3 From 3f7e0d5302ed0fadd794a41af6e476d2c408adc7 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 16 Jul 2009 21:21:57 -0700 Subject: egl: Destroy display's resources upon termination. eglTerminate should destroy the contexts and surfaces of the display. Signed-off-by: Chia-I Wu --- src/egl/main/egldisplay.c | 32 ++++++++++++++++++++++++++++++++ src/egl/main/egldisplay.h | 4 ++++ src/egl/main/egldriver.c | 4 +--- 3 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 1f1f41ea71..89de609d0b 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -120,6 +120,38 @@ _eglFindDisplay(NativeDisplayType nativeDisplay) } +/** + * Destroy the contexts and surfaces that are linked to the display. + */ +void +_eglReleaseDisplayResources(_EGLDriver *drv, EGLDisplay dpy) +{ + _EGLDisplay *display; + _EGLContext *contexts; + _EGLSurface *surfaces; + + display = _eglLookupDisplay(dpy); + if (!display) + return; + contexts = display->ContextList; + surfaces = display->SurfaceList; + + while (contexts) { + EGLContext handle = _eglGetContextHandle(contexts); + contexts = contexts->Next; + drv->API.DestroyContext(drv, dpy, handle); + } + assert(!display->ContextList); + + while (surfaces) { + EGLSurface handle = _eglGetSurfaceHandle(surfaces); + surfaces = surfaces->Next; + drv->API.DestroySurface(drv, dpy, handle); + } + assert(!display->SurfaceList); +} + + /** * Free all the data hanging of an _EGLDisplay object, but not * the object itself. diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 0a6003f39e..30b466cb4a 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -56,6 +56,10 @@ extern _EGLDisplay * _eglFindDisplay(NativeDisplayType nativeDisplay); +extern void +_eglReleaseDisplayResources(_EGLDriver *drv, EGLDisplay dpy); + + extern void _eglCleanupDisplay(_EGLDisplay *disp); diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 43b1f51903..f2a864cd8a 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -284,9 +284,7 @@ _eglCloseDriver(_EGLDriver *drv, EGLDisplay dpy) _eglLog(_EGL_DEBUG, "Closing %s", drv->Name); - /* - * XXX check for currently bound context/surfaces and delete them? - */ + _eglReleaseDisplayResources(drv, dpy); b = drv->API.Terminate(drv, dpy); -- cgit v1.2.3 From dc516d6e2afe7f157dbe5aad1288e5624b27e093 Mon Sep 17 00:00:00 2001 From: Chia-Wu Date: Fri, 31 Jul 2009 07:28:56 -0600 Subject: egl: Silence warnings on x86-64. Casting an unsigned int to or from a pointer directly gives warnings on x86-64. Add wrappers to silence the warnings. Signed-off-by: Chia-I Wu --- src/egl/main/eglcompiler.h | 33 +++++++++++++++++++++++++++++++++ src/egl/main/eglconfig.c | 2 +- src/egl/main/egldisplay.c | 19 ++++++++++--------- src/egl/main/egldisplay.h | 21 +++++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglcompiler.h b/src/egl/main/eglcompiler.h index 0b19afedfd..6b639b75c6 100644 --- a/src/egl/main/eglcompiler.h +++ b/src/egl/main/eglcompiler.h @@ -2,6 +2,39 @@ #define EGLCOMPILER_INCLUDED +/** + * Get standard integer types + */ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +# include +#elif defined(_MSC_VER) + typedef __int8 int8_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef unsigned __int16 uint16_t; +# ifndef __eglplatform_h_ + typedef __int32 int32_t; +# endif + typedef unsigned __int32 uint32_t; + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; + +# if defined(_WIN64) + typedef __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +# else + typedef __int32 intptr_t; + typedef unsigned __int32 uintptr_t; +# endif + +# define INT64_C(__val) __val##i64 +# define UINT64_C(__val) __val##ui64 +#else +/* hope the best instead of adding a bunch of ifdef's */ +# include +#endif + + /** * Function inlining */ diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index f2f32585c7..bbc585b55e 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -34,7 +34,7 @@ void _eglInitConfig(_EGLConfig *config, EGLint id) { memset(config, 0, sizeof(*config)); - config->Handle = (EGLConfig) id; + config->Handle = (EGLConfig) _eglUIntToPointer((unsigned int) id); _eglSetConfigAttrib(config, EGL_CONFIG_ID, id); _eglSetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGB, EGL_DONT_CARE); _eglSetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGBA, EGL_DONT_CARE); diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 89de609d0b..5304b84a26 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -53,7 +53,7 @@ _eglLinkDisplay(_EGLDisplay *dpy) assert(key); /* "link" the display to the hash table */ _eglHashInsert(_eglGlobal.Displays, key, dpy); - dpy->Handle = (EGLDisplay) key; + dpy->Handle = (EGLDisplay) _eglUIntToPointer(key); return dpy->Handle; } @@ -66,7 +66,8 @@ _eglLinkDisplay(_EGLDisplay *dpy) void _eglUnlinkDisplay(_EGLDisplay *dpy) { - _eglHashRemove(_eglGlobal.Displays, (EGLuint) dpy->Handle); + EGLuint key = _eglPointerToUInt((void *) dpy->Handle); + _eglHashRemove(_eglGlobal.Displays, key); dpy->Handle = EGL_NO_DISPLAY; } @@ -91,7 +92,7 @@ _eglGetDisplayHandle(_EGLDisplay *display) _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy) { - EGLuint key = (EGLuint) dpy; + EGLuint key = _eglPointerToUInt((void *) dpy); return (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key); } @@ -224,7 +225,7 @@ _eglUnlinkContext(_EGLContext *ctx) EGLContext _eglGetContextHandle(_EGLContext *ctx) { - return (EGLContext) (ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT; + return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT); } @@ -257,7 +258,7 @@ _eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy) assert(key); _eglHashInsert(_eglGlobal.Surfaces, key, surf); - surf->Handle = (EGLSurface) key; + surf->Handle = (EGLSurface) _eglUIntToPointer(key); return surf->Handle; } @@ -270,8 +271,9 @@ void _eglUnlinkSurface(_EGLSurface *surf) { _EGLSurface *prev; + EGLuint key = _eglPointerToUInt((void *) surf->Handle); - _eglHashRemove(_eglGlobal.Surfaces, (EGLuint) surf->Handle); + _eglHashRemove(_eglGlobal.Surfaces, key); surf->Handle = EGL_NO_SURFACE; prev = surf->Display->SurfaceList; @@ -314,7 +316,6 @@ _eglGetSurfaceHandle(_EGLSurface *surface) _EGLSurface * _eglLookupSurface(EGLSurface surf) { - _EGLSurface *c = (_EGLSurface *) _eglHashLookup(_eglGlobal.Surfaces, - (EGLuint) surf); - return c; + EGLuint key = _eglPointerToUInt((void *) surf); + return (_EGLSurface *) _eglHashLookup(_eglGlobal.Surfaces, key); } diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 372ed3cd79..2ef5db8a18 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -125,4 +125,25 @@ _eglIsSurfaceLinked(_EGLSurface *surf) } +/** + * Cast an unsigned int to a pointer. + */ +static INLINE void * +_eglUIntToPointer(unsigned int v) +{ + return (void *) ((uintptr_t) v); +} + + +/** + * Cast a pointer to an unsigned int. The pointer must be one that is + * returned by _eglUIntToPointer. + */ +static INLINE unsigned int +_eglPointerToUInt(const void *p) +{ + return (unsigned int) ((uintptr_t) p); +} + + #endif /* EGLDISPLAY_INCLUDED */ -- cgit v1.2.3 From 621801abd287238f9a3209554bc84fec5d2e9ccd Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 10 Aug 2009 14:16:32 +0800 Subject: egl: Make display and surface hash tables local. Move display and surface hash tables to egldisplay.c, and have them initialized on demand. Signed-off-by: Chia-I Wu --- src/egl/main/egldisplay.c | 85 +++++++++++++++++++++++++++++++++++++++-------- src/egl/main/egldisplay.h | 5 +++ src/egl/main/eglglobals.c | 6 +--- src/egl/main/eglglobals.h | 4 --- 4 files changed, 78 insertions(+), 22 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 5304b84a26..58d935225c 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -1,4 +1,3 @@ - /** * Functions related to EGLDisplay. */ @@ -13,6 +12,51 @@ #include "eglglobals.h" #include "eglhash.h" #include "eglstring.h" +#include "eglmutex.h" + + +static _EGL_DECLARE_MUTEX(_eglDisplayInitMutex); +static _EGLHashtable *_eglDisplayHash; +/* TODO surface hash table should be per-display */ +static _EGLHashtable *_eglSurfaceHash; + + +/** + * Finish display management. + */ +static void +_eglFiniDisplay(void) +{ + _eglLockMutex(&_eglDisplayInitMutex); + if (_eglDisplayHash) { + /* XXX TODO walk over table entries, deleting each */ + _eglDeleteHashTable(_eglDisplayHash); + _eglDisplayHash = NULL; + _eglDeleteHashTable(_eglSurfaceHash); + _eglSurfaceHash = NULL; + } + _eglUnlockMutex(&_eglDisplayInitMutex); +} + + +/* This can be avoided if hash table can be statically initialized */ +static INLINE void +_eglInitDisplay(void) +{ + if (!_eglDisplayHash) { + _eglLockMutex(&_eglDisplayInitMutex); + + /* check again after acquiring lock */ + if (!_eglDisplayHash) { + _eglDisplayHash = _eglNewHashTable(); + _eglSurfaceHash = _eglNewHashTable(); + + (void) _eglFiniDisplay; + } + + _eglUnlockMutex(&_eglDisplayInitMutex); + } +} /** @@ -31,6 +75,9 @@ _eglNewDisplay(NativeDisplayType nativeDisplay) dpy->Xdpy = (Display *) nativeDisplay; #endif + _eglInitDisplay(); + dpy->SurfaceHash = _eglSurfaceHash; + dpy->DriverName = _eglChooseDriver(dpy); if (!dpy->DriverName) { free(dpy); @@ -49,10 +96,13 @@ EGLDisplay _eglLinkDisplay(_EGLDisplay *dpy) { EGLuint key; - key = _eglHashGenKey(_eglGlobal.Displays); + + _eglInitDisplay(); + + key = _eglHashGenKey(_eglDisplayHash); assert(key); /* "link" the display to the hash table */ - _eglHashInsert(_eglGlobal.Displays, key, dpy); + _eglHashInsert(_eglDisplayHash, key, dpy); dpy->Handle = (EGLDisplay) _eglUIntToPointer(key); return dpy->Handle; @@ -67,7 +117,10 @@ void _eglUnlinkDisplay(_EGLDisplay *dpy) { EGLuint key = _eglPointerToUInt((void *) dpy->Handle); - _eglHashRemove(_eglGlobal.Displays, key); + + _eglInitDisplay(); + + _eglHashRemove(_eglDisplayHash, key); dpy->Handle = EGL_NO_DISPLAY; } @@ -84,7 +137,7 @@ _eglGetDisplayHandle(_EGLDisplay *display) return EGL_NO_DISPLAY; } - + /** * Lookup a handle to find the linked display. * Return NULL if the handle has no corresponding linked display. @@ -93,7 +146,10 @@ _EGLDisplay * _eglLookupDisplay(EGLDisplay dpy) { EGLuint key = _eglPointerToUInt((void *) dpy); - return (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key); + + _eglInitDisplay(); + + return (_EGLDisplay *) _eglHashLookup(_eglDisplayHash, key); } @@ -104,17 +160,20 @@ _eglLookupDisplay(EGLDisplay dpy) _EGLDisplay * _eglFindDisplay(NativeDisplayType nativeDisplay) { - EGLuint key = _eglHashFirstEntry(_eglGlobal.Displays); + EGLuint key; + + _eglInitDisplay(); /* Walk the hash table. Should switch to list if it is a problem. */ + key = _eglHashFirstEntry(_eglDisplayHash); while (key) { _EGLDisplay *dpy = (_EGLDisplay *) - _eglHashLookup(_eglGlobal.Displays, key); + _eglHashLookup(_eglDisplayHash, key); assert(dpy); if (dpy->NativeDisplay == nativeDisplay) return dpy; - key = _eglHashNextEntry(_eglGlobal.Displays, key); + key = _eglHashNextEntry(_eglDisplayHash, key); } return NULL; @@ -254,9 +313,9 @@ _eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy) surf->Next = dpy->SurfaceList; dpy->SurfaceList = surf; - key = _eglHashGenKey(_eglGlobal.Surfaces); + key = _eglHashGenKey(dpy->SurfaceHash); assert(key); - _eglHashInsert(_eglGlobal.Surfaces, key, surf); + _eglHashInsert(dpy->SurfaceHash, key, surf); surf->Handle = (EGLSurface) _eglUIntToPointer(key); return surf->Handle; @@ -273,7 +332,7 @@ _eglUnlinkSurface(_EGLSurface *surf) _EGLSurface *prev; EGLuint key = _eglPointerToUInt((void *) surf->Handle); - _eglHashRemove(_eglGlobal.Surfaces, key); + _eglHashRemove(surf->Display->SurfaceHash, key); surf->Handle = EGL_NO_SURFACE; prev = surf->Display->SurfaceList; @@ -317,5 +376,5 @@ _EGLSurface * _eglLookupSurface(EGLSurface surf) { EGLuint key = _eglPointerToUInt((void *) surf); - return (_EGLSurface *) _eglHashLookup(_eglGlobal.Surfaces, key); + return (_EGLSurface *) _eglHashLookup(_eglSurfaceHash, key); } diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 2ef5db8a18..70c59ef5e4 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -6,6 +6,7 @@ #endif #include "egltypedefs.h" +#include "eglhash.h" struct _egl_display @@ -26,6 +27,10 @@ struct _egl_display /* lists of linked contexts and surface */ _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/eglglobals.c b/src/egl/main/eglglobals.c index 23a3ef5ca8..f2c1c217a5 100644 --- a/src/egl/main/eglglobals.c +++ b/src/egl/main/eglglobals.c @@ -1,5 +1,6 @@ #include #include "eglglobals.h" +#include "egldisplay.h" #include "egllog.h" struct _egl_global _eglGlobal = @@ -15,8 +16,6 @@ void _eglInitGlobals(void) { if (!_eglGlobal.Initialized) { - _eglGlobal.Displays = _eglNewHashTable(); - _eglGlobal.Surfaces = _eglNewHashTable(); _eglGlobal.FreeScreenHandle = 1; _eglGlobal.Initialized = EGL_TRUE; @@ -31,7 +30,4 @@ _eglInitGlobals(void) void _eglDestroyGlobals(void) { - /* XXX TODO walk over table entries, deleting each */ - _eglDeleteHashTable(_eglGlobal.Displays); - _eglDeleteHashTable(_eglGlobal.Surfaces); } diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h index a9443cfbdd..47fd943fd5 100644 --- a/src/egl/main/eglglobals.h +++ b/src/egl/main/eglglobals.h @@ -13,10 +13,6 @@ struct _egl_global { EGLBoolean Initialized; - /* these are private to egldisplay.c */ - _EGLHashtable *Displays; - _EGLHashtable *Surfaces; - EGLScreenMESA FreeScreenHandle; /* bitmaks of supported APIs (supported by _some_ driver) */ -- cgit v1.2.3 From 413969a92052c019bcf3c5bf48cf564613eba598 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 10 Aug 2009 15:13:42 +0800 Subject: egl: Implement _eglFiniDisplay. _eglFiniDisplay is called at exit time to free allocated displays. It is, however, not used right now. Signed-off-by: Chia-I Wu --- src/egl/main/egldisplay.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 58d935225c..6fdb3b7a1c 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -13,6 +13,7 @@ #include "eglhash.h" #include "eglstring.h" #include "eglmutex.h" +#include "egllog.h" static _EGL_DECLARE_MUTEX(_eglDisplayInitMutex); @@ -29,7 +30,22 @@ _eglFiniDisplay(void) { _eglLockMutex(&_eglDisplayInitMutex); if (_eglDisplayHash) { - /* XXX TODO walk over table entries, deleting each */ + 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); + + _eglCleanupDisplay(dpy); + free(dpy); + + key = _eglHashNextEntry(_eglDisplayHash, key); + } + _eglDeleteHashTable(_eglDisplayHash); _eglDisplayHash = NULL; _eglDeleteHashTable(_eglSurfaceHash); -- cgit v1.2.3 From 64e7bb326207df559b5cebdb278f62df83cf1425 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 10 Aug 2009 16:45:12 +0800 Subject: egl: Use _eglAddAtExitCall to free thread infos and displays. Thread infos and displays are usually not freed by applications. This commit add atexit calls to free them. Signed-off-by: Chia-I Wu --- src/egl/main/eglcurrent.c | 5 +++-- src/egl/main/egldisplay.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c index f92719cfbc..4431f964f6 100644 --- a/src/egl/main/eglcurrent.c +++ b/src/egl/main/eglcurrent.c @@ -4,6 +4,7 @@ #include "eglcontext.h" #include "egllog.h" #include "eglmutex.h" +#include "eglglobals.h" /* This should be kept in sync with _eglInitThreadInfo() */ @@ -84,7 +85,7 @@ static INLINE EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) return EGL_FALSE; } _egl_FreeTSD = dtor; - (void) _eglFiniTSD; + _eglAddAtExitCall(_eglFiniTSD); _egl_TSDInitialized = EGL_TRUE; } @@ -118,7 +119,7 @@ static INLINE EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) { if (!_egl_FreeTSD && dtor) { _egl_FreeTSD = dtor; - (void) _eglFiniTSD; + _eglAddAtExitCall(_eglFiniTSD); } return EGL_TRUE; } diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 6fdb3b7a1c..feae1d6040 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -67,7 +67,7 @@ _eglInitDisplay(void) _eglDisplayHash = _eglNewHashTable(); _eglSurfaceHash = _eglNewHashTable(); - (void) _eglFiniDisplay; + _eglAddAtExitCall(_eglFiniDisplay); } _eglUnlockMutex(&_eglDisplayInitMutex); -- cgit v1.2.3 From 2f2cf461c57974abd89e4917945cc8ae6a67a72e Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 11 Aug 2009 17:09:39 +0800 Subject: egl: Overhaul driver API. The motivation is so that drivers do not need to look up and check for bad display, context, and etc. It also becomes unnecessary for drivers to call the link functions. This commit makes eglapi.[ch] do the lookup and check. As a result, the driver API is overhauled, and almost all sources and drivers need update. The updates are mainly find and replace with human brains. Signed-off-by: Chia-I Wu --- src/egl/drivers/demo/demo.c | 83 ++-- src/egl/drivers/glx/egl_glx.c | 182 ++++---- src/egl/main/eglapi.c | 669 ++++++++++++++++++++------- src/egl/main/eglapi.h | 74 +-- src/egl/main/eglconfig.c | 18 +- src/egl/main/eglconfig.h | 8 +- src/egl/main/eglcontext.c | 80 +--- src/egl/main/eglcontext.h | 10 +- src/egl/main/egldisplay.c | 24 +- src/egl/main/egldisplay.h | 6 +- src/egl/main/egldriver.c | 2 +- src/egl/main/egldriver.h | 2 +- src/egl/main/eglmisc.c | 6 +- src/egl/main/eglmisc.h | 6 +- src/egl/main/eglmode.c | 37 +- src/egl/main/eglmode.h | 10 +- src/egl/main/eglscreen.c | 109 +---- src/egl/main/eglscreen.h | 24 +- src/egl/main/eglsurface.c | 131 ++---- src/egl/main/eglsurface.h | 34 +- src/gallium/state_trackers/egl/egl_context.c | 24 +- src/gallium/state_trackers/egl/egl_surface.c | 49 +- src/gallium/state_trackers/egl/egl_tracker.c | 7 +- src/gallium/state_trackers/egl/egl_tracker.h | 33 +- src/gallium/winsys/egl_xlib/egl_xlib.c | 154 +++--- 25 files changed, 898 insertions(+), 884 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/drivers/demo/demo.c b/src/egl/drivers/demo/demo.c index e8c0c1df5e..e9e6bac5b1 100644 --- a/src/egl/drivers/demo/demo.c +++ b/src/egl/drivers/demo/demo.c @@ -49,9 +49,8 @@ typedef struct demo_context static EGLBoolean -demoInitialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor) +demoInitialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); _EGLScreen *scrn; EGLint i; @@ -95,7 +94,7 @@ demoInitialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor) static EGLBoolean -demoTerminate(_EGLDriver *drv, EGLDisplay dpy) +demoTerminate(_EGLDriver *drv, _EGLDisplay *dpy) { /*DemoDriver *demo = DEMO_DRIVER(dpy);*/ free(drv); @@ -104,62 +103,48 @@ demoTerminate(_EGLDriver *drv, EGLDisplay dpy) static DemoContext * -LookupDemoContext(EGLContext ctx) +LookupDemoContext(_EGLContext *c) { - _EGLContext *c = _eglLookupContext(ctx); return (DemoContext *) c; } static DemoSurface * -LookupDemoSurface(EGLSurface surf) +LookupDemoSurface(_EGLSurface *s) { - _EGLSurface *s = _eglLookupSurface(surf); return (DemoSurface *) s; } - -static EGLContext -demoCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) +static _EGLContext * +demoCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list) { - _EGLConfig *conf; DemoContext *c; int i; - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreateContext"); - return EGL_NO_CONTEXT; - } - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { switch (attrib_list[i]) { /* no attribs defined for now */ default: _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext"); - return EGL_NO_CONTEXT; + return NULL; } } c = (DemoContext *) calloc(1, sizeof(DemoContext)); if (!c) - return EGL_NO_CONTEXT; + return NULL; _eglInitContext(drv, &c->Base, conf, attrib_list); c->DemoStuff = 1; printf("demoCreateContext\n"); - /* link to display */ - _eglLinkContext(&c->Base, _eglLookupDisplay(dpy)); - assert(_eglGetContextHandle(&c->Base)); - - return _eglGetContextHandle(&c->Base); + return &c->Base; } -static EGLSurface -demoCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) +static _EGLSurface * +demoCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list) { int i; for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { @@ -167,75 +152,65 @@ demoCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, Nativ /* no attribs at this time */ default: _eglError(EGL_BAD_ATTRIBUTE, "eglCreateWindowSurface"); - return EGL_NO_SURFACE; + return NULL; } } printf("eglCreateWindowSurface()\n"); /* XXX unfinished */ - return EGL_NO_SURFACE; + return NULL; } -static EGLSurface -demoCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list) +static _EGLSurface * +demoCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list) { - _EGLConfig *conf; EGLint i; - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreatePixmapSurface"); - return EGL_NO_SURFACE; - } - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { switch (attrib_list[i]) { /* no attribs at this time */ default: _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePixmapSurface"); - return EGL_NO_SURFACE; + return NULL; } } if (conf->Attrib[EGL_SURFACE_TYPE - FIRST_ATTRIB] == 0) { _eglError(EGL_BAD_MATCH, "eglCreatePixmapSurface"); - return EGL_NO_SURFACE; + return NULL; } printf("eglCreatePixmapSurface()\n"); - return EGL_NO_SURFACE; + return NULL; } -static EGLSurface -demoCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +static _EGLSurface * +demoCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list) { DemoSurface *surf = (DemoSurface *) calloc(1, sizeof(DemoSurface)); - _EGLConfig *conf; if (!surf) - return EGL_NO_SURFACE; + return NULL; - conf = _eglLookupConfig(drv, dpy, config); if (!_eglInitSurface(drv, &surf->Base, EGL_PBUFFER_BIT, conf, attrib_list)) { free(surf); - return EGL_NO_SURFACE; + return NULL; } /* a real driver would allocate the pbuffer memory here */ - return surf->Base.Handle; + return &surf->Base; } static EGLBoolean -demoDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +demoDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface) { DemoSurface *fs = LookupDemoSurface(surface); - _eglUnlinkSurface(&fs->Base); if (!_eglIsSurfaceBound(&fs->Base)) free(fs); return EGL_TRUE; @@ -243,10 +218,9 @@ demoDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) static EGLBoolean -demoDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) +demoDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *context) { DemoContext *fc = LookupDemoContext(context); - _eglUnlinkContext(&fc->Base); if (!_eglIsContextBound(&fc->Base)) free(fc); return EGL_TRUE; @@ -254,15 +228,12 @@ demoDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) static EGLBoolean -demoMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context) +demoMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *drawSurf, _EGLSurface *readSurf, _EGLContext *ctx) { /*DemoDriver *demo = DEMO_DRIVER(dpy);*/ - DemoSurface *readSurf = LookupDemoSurface(read); - DemoSurface *drawSurf = LookupDemoSurface(draw); - DemoContext *ctx = LookupDemoContext(context); EGLBoolean b; - b = _eglMakeCurrent(drv, dpy, draw, read, context); + b = _eglMakeCurrent(drv, dpy, drawSurf, readSurf, ctx); if (!b) return EGL_FALSE; diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index 5ed4b6883f..607e649e5c 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -157,6 +157,13 @@ GLX_egl_surface(_EGLSurface *surf) return (struct GLX_egl_surface *) surf; } +static int +GLX_egl_config_id(_EGLConfig *conf) +{ + /* see create_configs */ + return (int) _eglPointerToUInt(_eglGetConfigHandle(conf)) - 1; +} + static GLboolean get_visual_attribs(Display *dpy, XVisualInfo *vInfo, struct visual_attribs *attribs) @@ -351,7 +358,6 @@ create_configs(_EGLDisplay *disp, struct GLX_egl_driver *GLX_drv) int numVisuals; long mask; int i; - int egl_configs = 1; struct visual_attribs attribs; GLX_drv->fbconfigs = NULL; @@ -441,11 +447,10 @@ end: * Called via eglInitialize(), GLX_drv->API.Initialize(). */ static EGLBoolean -GLX_eglInitialize(_EGLDriver *drv, EGLDisplay dpy, +GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *minor, EGLint *major) { struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv); - _EGLDisplay *disp = _eglLookupDisplay(dpy); _eglLog(_EGL_DEBUG, "GLX: eglInitialize"); @@ -504,10 +509,8 @@ FreeDisplayExt(Display *dpy) * Called via eglTerminate(), drv->API.Terminate(). */ static EGLBoolean -GLX_eglTerminate(_EGLDriver *drv, EGLDisplay dpy) +GLX_eglTerminate(_EGLDriver *drv, _EGLDisplay *disp) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _eglLog(_EGL_DEBUG, "GLX: eglTerminate"); FreeDisplayExt(disp->Xdpy); @@ -519,42 +522,37 @@ GLX_eglTerminate(_EGLDriver *drv, EGLDisplay dpy) /** * Called via eglCreateContext(), drv->API.CreateContext(). */ -static EGLContext -GLX_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, - EGLContext share_list, const EGLint *attrib_list) +static _EGLContext * +GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, + _EGLContext *share_list, const EGLint *attrib_list) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); struct GLX_egl_context *GLX_ctx = CALLOC_STRUCT(GLX_egl_context); struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv); - struct GLX_egl_context *GLX_ctx_shared = NULL; - _EGLConfig *conf; + struct GLX_egl_context *GLX_ctx_shared = GLX_egl_context(share_list); if (!GLX_ctx) - return EGL_NO_CONTEXT; - - conf = _eglLookupConfig(drv, dpy, config); - assert(conf); + return NULL; if (!_eglInitContext(drv, &GLX_ctx->Base, conf, attrib_list)) { free(GLX_ctx); - return EGL_NO_CONTEXT; - } - - if (share_list != EGL_NO_CONTEXT) { - _EGLContext *shareCtx = _eglLookupContext(share_list); - if (!shareCtx) { - _eglError(EGL_BAD_CONTEXT, "eglCreateContext(share_list)"); - return EGL_FALSE; - } - GLX_ctx_shared = GLX_egl_context(shareCtx); + return NULL; } #ifdef GLX_VERSION_1_3 if (GLX_drv->fbconfigs) - GLX_ctx->context = glXCreateNewContext(disp->Xdpy, GLX_drv->fbconfigs[(int)config-1], GLX_RGBA_TYPE, GLX_ctx_shared ? GLX_ctx_shared->context : NULL, GL_TRUE); + GLX_ctx->context = + glXCreateNewContext(disp->Xdpy, + GLX_drv->fbconfigs[GLX_egl_config_id(conf)], + GLX_RGBA_TYPE, + GLX_ctx_shared ? GLX_ctx_shared->context : NULL, + GL_TRUE); else #endif - GLX_ctx->context = glXCreateContext(disp->Xdpy, &GLX_drv->visuals[(int)config-1], GLX_ctx_shared ? GLX_ctx_shared->context : NULL, GL_TRUE); + GLX_ctx->context = + glXCreateContext(disp->Xdpy, + &GLX_drv->visuals[GLX_egl_config_id(conf)], + GLX_ctx_shared ? GLX_ctx_shared->context : NULL, + GL_TRUE); if (!GLX_ctx->context) return EGL_FALSE; @@ -564,7 +562,7 @@ GLX_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, return EGL_FALSE; #endif - return _eglLinkContext(&GLX_ctx->Base, disp); + return &GLX_ctx->Base; } @@ -572,18 +570,14 @@ GLX_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, * Called via eglMakeCurrent(), drv->API.MakeCurrent(). */ static EGLBoolean -GLX_eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, - EGLSurface r, EGLContext context) +GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, + _EGLSurface *rsurf, _EGLContext *ctx) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLContext *ctx = _eglLookupContext(context); - _EGLSurface *dsurf = _eglLookupSurface(d); - _EGLSurface *rsurf = _eglLookupSurface(r); struct GLX_egl_surface *GLX_dsurf = GLX_egl_surface(dsurf); struct GLX_egl_surface *GLX_rsurf = GLX_egl_surface(rsurf); struct GLX_egl_context *GLX_ctx = GLX_egl_context(ctx); - if (!_eglMakeCurrent(drv, dpy, d, r, context)) + if (!_eglMakeCurrent(drv, disp, dsurf, rsurf, ctx)) return EGL_FALSE; #ifdef GLX_VERSION_1_3 @@ -612,104 +606,86 @@ get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height) /** * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). */ -static EGLSurface -GLX_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +static _EGLSurface * +GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); struct GLX_egl_surface *GLX_surf; uint width, height; - _EGLConfig *conf; - - conf = _eglLookupConfig(drv, dpy, config); - assert(conf); GLX_surf = CALLOC_STRUCT(GLX_egl_surface); if (!GLX_surf) - return EGL_NO_SURFACE; + return NULL; if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_WINDOW_BIT, conf, attrib_list)) { free(GLX_surf); - return EGL_FALSE; + return NULL; } - _eglLinkSurface(&GLX_surf->Base, disp); - GLX_surf->drawable = window; get_drawable_size(disp->Xdpy, window, &width, &height); GLX_surf->Base.Width = width; GLX_surf->Base.Height = height; - return _eglGetSurfaceHandle(&GLX_surf->Base); + return &GLX_surf->Base; } #ifdef GLX_VERSION_1_3 -static EGLSurface -GLX_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +static _EGLSurface * +GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list) { struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv); - _EGLDisplay *disp = _eglLookupDisplay(dpy); struct GLX_egl_surface *GLX_surf; - _EGLConfig *conf; int i; - conf = _eglLookupConfig(drv, dpy, config); - assert(conf); - GLX_surf = CALLOC_STRUCT(GLX_egl_surface); if (!GLX_surf) - return EGL_NO_SURFACE; + return NULL; if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PIXMAP_BIT, conf, attrib_list)) { free(GLX_surf); - return EGL_FALSE; + return NULL; } - _eglLinkSurface(&GLX_surf->Base, disp); - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { switch (attrib_list[i]) { /* no attribs at this time */ default: _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePixmapSurface"); - return EGL_NO_SURFACE; + return NULL; } } - GLX_surf->drawable = glXCreatePixmap(disp->Xdpy, GLX_drv->fbconfigs[(int)config-1], pixmap, NULL); + GLX_surf->drawable = + glXCreatePixmap(disp->Xdpy, + GLX_drv->fbconfigs[GLX_egl_config_id(conf)], + pixmap, NULL); - return _eglGetSurfaceHandle(&GLX_surf->Base); + return &GLX_surf->Base; } -static EGLSurface -GLX_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +static _EGLSurface * +GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv); - _EGLDisplay *disp = _eglLookupDisplay(dpy); struct GLX_egl_surface *GLX_surf; - _EGLConfig *conf; int attribs[5]; int i = 0, j = 0; - conf = _eglLookupConfig(drv, dpy, config); - assert(conf); - GLX_surf = CALLOC_STRUCT(GLX_egl_surface); if (!GLX_surf) - return EGL_NO_SURFACE; + return NULL; if (!_eglInitSurface(drv, &GLX_surf->Base, EGL_PBUFFER_BIT, conf, attrib_list)) { free(GLX_surf); - return EGL_NO_SURFACE; + return NULL; } - _eglLinkSurface(&GLX_surf->Base, disp); - while(attrib_list[i] != EGL_NONE) { switch (attrib_list[i]) { case EGL_WIDTH: @@ -725,38 +701,40 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, } attribs[j++] = 0; - GLX_surf->drawable = glXCreatePbuffer(disp->Xdpy, GLX_drv->fbconfigs[(int)config-1], attribs); + GLX_surf->drawable = + glXCreatePbuffer(disp->Xdpy, + GLX_drv->fbconfigs[GLX_egl_config_id(conf)], attribs); - return _eglGetSurfaceHandle(&GLX_surf->Base); + return &GLX_surf->Base; } #endif static EGLBoolean -GLX_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +GLX_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLSurface *surf = _eglLookupSurface(surface); - return EGL_TRUE; - if (surf) { - _eglUnlinkSurface(surf); - if (!_eglIsSurfaceBound(surf)) - free(surf); - - return EGL_TRUE; - } - else { - _eglError(EGL_BAD_SURFACE, "eglDestroySurface"); - return EGL_FALSE; + if (!_eglIsSurfaceBound(surf)) { + struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf); + switch (surf->Type) { + case EGL_PBUFFER_BIT: + glXDestroyPbuffer(disp->Xdpy, GLX_surf->drawable); + break; + case EGL_PIXMAP_BIT: + glXDestroyPixmap(disp->Xdpy, GLX_surf->drawable); + break; + default: + break; + } + free(surf); } + + return EGL_TRUE; } static EGLBoolean -GLX_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, +GLX_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLSurface *surf = _eglLookupSurface(surface); struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf); /* buffer ?? */ @@ -767,11 +745,9 @@ GLX_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, static EGLBoolean -GLX_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, +GLX_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLSurface *surf = _eglLookupSurface(surface); struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf); /* buffer ?? */ @@ -782,16 +758,14 @@ GLX_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, static EGLBoolean -GLX_eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) +GLX_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLSurface *surf = _eglLookupSurface(draw); - struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf); + struct GLX_egl_surface *GLX_surf = GLX_egl_surface(draw); _eglLog(_EGL_DEBUG, "GLX: EGL SwapBuffers 0x%x",draw); /* error checking step: */ - if (!_eglSwapBuffers(drv, dpy, draw)) + if (!_eglSwapBuffers(drv, disp, draw)) return EGL_FALSE; glXSwapBuffers(disp->Xdpy, GLX_surf->drawable); @@ -810,13 +784,14 @@ GLX_eglGetProcAddress(const char *procname) * some point. */ _EGLProc (*get_proc_addr)(const char *procname); + _EGLProc proc_addr; get_proc_addr = dlsym(NULL, "st_get_proc_address"); if (get_proc_addr) return get_proc_addr(procname); - get_proc_addr = glXGetProcAddress((const GLubyte *)procname); - if (get_proc_addr) - return get_proc_addr(procname); + proc_addr = glXGetProcAddress((const GLubyte *)procname); + if (proc_addr) + return proc_addr; return (_EGLProc)dlsym(NULL, procname); } @@ -831,7 +806,6 @@ _eglMain(_EGLDisplay *disp, const char *args) { struct GLX_egl_driver *GLX_drv = CALLOC_STRUCT(GLX_egl_driver); char *env; - int maj = 0, min = 0; if (!GLX_drv) return NULL; diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index fde6b7316c..e8a5b18912 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -29,7 +29,6 @@ */ - #include #include #include @@ -39,7 +38,9 @@ #include "eglglobals.h" #include "egldriver.h" #include "eglsurface.h" - +#include "eglconfig.h" +#include "eglscreen.h" +#include "eglmode.h" /** @@ -67,232 +68,481 @@ eglGetDisplay(NativeDisplayType nativeDisplay) EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) { + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLDriver *drv; EGLint major_int, minor_int; - if (dpy) { - EGLBoolean retVal; - _EGLDisplay *dpyPriv = _eglLookupDisplay(dpy); - if (!dpyPriv) { - return EGL_FALSE; - } - dpyPriv->Driver = _eglOpenDriver(dpyPriv, - dpyPriv->DriverName, - dpyPriv->DriverArgs); - if (!dpyPriv->Driver) { - return EGL_FALSE; - } - /* Initialize the particular driver now */ - retVal = dpyPriv->Driver->API.Initialize(dpyPriv->Driver, dpy, - &major_int, &minor_int); - - dpyPriv->Driver->APImajor = major_int; - dpyPriv->Driver->APIminor = minor_int; - snprintf(dpyPriv->Driver->Version, sizeof(dpyPriv->Driver->Version), - "%d.%d (%s)", major_int, minor_int, dpyPriv->Driver->Name); - - /* Update applications version of major and minor if not NULL */ - if((major != NULL) && (minor != NULL)) - { - *major = major_int; - *minor = minor_int; + if (!disp) + return _eglError(EGL_BAD_DISPLAY, __FUNCTION__); + + drv = disp->Driver; + if (!drv) { + drv = _eglOpenDriver(disp, disp->DriverName, disp->DriverArgs); + if (!drv) + return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__); + + /* Initialize the particular display now */ + if (!drv->API.Initialize(drv, disp, &major_int, &minor_int)) { + _eglCloseDriver(drv, disp); + return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__); } - return retVal; + drv->APImajor = major_int; + drv->APIminor = minor_int; + snprintf(drv->Version, sizeof(drv->Version), + "%d.%d (%s)", major_int, minor_int, drv->Name); + + disp->Driver = drv; + } else { + major_int = drv->APImajor; + minor_int = drv->APIminor; } - return EGL_FALSE; + + /* Update applications version of major and minor if not NULL */ + if ((major != NULL) && (minor != NULL)) { + *major = major_int; + *minor = minor_int; + } + + return EGL_TRUE; } EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy) { - _EGLDriver *drv = _eglLookupDriver(dpy); - if (drv) - return _eglCloseDriver(drv, dpy); - else - return EGL_FALSE; + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLDriver *drv; + + if (!disp) + return _eglError(EGL_BAD_DISPLAY, __FUNCTION__); + + drv = disp->Driver; + if (drv) { + /* TODO drv->API.Terminate should be called here */ + _eglCloseDriver(drv, disp); + disp->Driver = NULL; + } + + return EGL_TRUE; +} + + +/** + * A bunch of check functions and declare macros to simply error checking. + */ +static INLINE _EGLDriver * +_eglCheckDisplay(_EGLDisplay *disp, const char *msg) +{ + if (!disp) { + _eglError(EGL_BAD_DISPLAY, msg); + return NULL; + } + if (!disp->Driver) { + _eglError(EGL_NOT_INITIALIZED, msg); + return NULL; + } + return disp->Driver; +} + + +static INLINE _EGLDriver * +_eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!surf) { + _eglError(EGL_BAD_SURFACE, msg); + return NULL; + } + return drv; } +static INLINE _EGLDriver * +_eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!context) { + _eglError(EGL_BAD_CONTEXT, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!conf) { + _eglError(EGL_BAD_CONFIG, msg); + return NULL; + } + return drv; +} + + +#define _EGL_DECLARE_DD(dpy) \ + _EGLDisplay *disp = _eglLookupDisplay(dpy); \ + _EGLDriver *drv; \ + do { \ + drv = _eglCheckDisplay(disp, __FUNCTION__); \ + if (!drv) \ + return EGL_FALSE; \ + } while (0) + + +#define _EGL_DECLARE_DD_AND_SURFACE(dpy, surface) \ + _EGLDisplay *disp = _eglLookupDisplay(dpy); \ + _EGLSurface *surf = _eglLookupSurface((surface), disp); \ + _EGLDriver *drv; \ + do { \ + drv = _eglCheckSurface(disp, surf, __FUNCTION__); \ + if (!drv) \ + return EGL_FALSE; \ + } while (0) + + +#define _EGL_DECLARE_DD_AND_CONTEXT(dpy, ctx) \ + _EGLDisplay *disp = _eglLookupDisplay(dpy); \ + _EGLContext *context = _eglLookupContext((ctx), disp); \ + _EGLDriver *drv; \ + do { \ + drv = _eglCheckContext(disp, context, __FUNCTION__); \ + if (!drv) \ + return EGL_FALSE; \ + } while (0) + + +#ifdef EGL_MESA_screen_surface + + +static INLINE _EGLDriver * +_eglCheckScreen(_EGLDisplay *disp, _EGLScreen *scrn, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckMode(_EGLDisplay *disp, _EGLMode *m, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!m) { + _eglError(EGL_BAD_MODE_MESA, msg); + return NULL; + } + return drv; +} + + +#define _EGL_DECLARE_DD_AND_SCREEN(dpy, screen) \ + _EGLDisplay *disp = _eglLookupDisplay(dpy); \ + _EGLScreen *scrn = _eglLookupScreen((screen), disp); \ + _EGLDriver *drv; \ + do { \ + drv = _eglCheckScreen(disp, scrn, __FUNCTION__); \ + if (!drv) \ + return EGL_FALSE; \ + } while (0) + + +#define _EGL_DECLARE_DD_AND_MODE(dpy, mode) \ + _EGLDisplay *disp = _eglLookupDisplay(dpy); \ + _EGLMode *m = _eglLookupMode((mode), disp); \ + _EGLDriver *drv; \ + do { \ + drv = _eglCheckMode(disp, m, __FUNCTION__); \ + if (!drv) \ + return EGL_FALSE; \ + } while (0) + + +#endif /* EGL_MESA_screen_surface */ + + const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) { - _EGLDriver *drv = _eglLookupDriver(dpy); - if (drv) - return drv->API.QueryString(drv, dpy, name); - else - return NULL; + _EGL_DECLARE_DD(dpy); + return drv->API.QueryString(drv, disp, name); } EGLBoolean EGLAPIENTRY -eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) +eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, + EGLint config_size, EGLint *num_config) { - _EGLDriver *drv = _eglLookupDriver(dpy); - /* XXX check drv for null in remaining functions */ - return drv->API.GetConfigs(drv, dpy, configs, config_size, num_config); + _EGL_DECLARE_DD(dpy); + return drv->API.GetConfigs(drv, disp, configs, config_size, num_config); } EGLBoolean EGLAPIENTRY -eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) +eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, + EGLint config_size, EGLint *num_config) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.ChooseConfig(drv, dpy, attrib_list, configs, config_size, num_config); + _EGL_DECLARE_DD(dpy); + return drv->API.ChooseConfig(drv, disp, attrib_list, configs, + config_size, num_config); } EGLBoolean EGLAPIENTRY -eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) +eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, + EGLint attribute, EGLint *value) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.GetConfigAttrib(drv, dpy, config, attribute, value); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + + drv = _eglCheckConfig(disp, conf, __FUNCTION__); + if (!drv) + return EGL_FALSE; + + return drv->API.GetConfigAttrib(drv, disp, conf, attribute, value); } EGLContext EGLAPIENTRY -eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) -{ - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.CreateContext(drv, dpy, config, share_list, attrib_list); +eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, + const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLContext *share = _eglLookupContext(share_list, disp); + _EGLDriver *drv; + _EGLContext *context; + + drv = _eglCheckConfig(disp, conf, __FUNCTION__); + if (!drv) + return EGL_NO_CONTEXT; + if (!share && share_list != EGL_NO_CONTEXT) { + _eglError(EGL_BAD_CONTEXT, __FUNCTION__); + return EGL_NO_CONTEXT; + } + + context = drv->API.CreateContext(drv, disp, conf, share, attrib_list); + if (context) + return _eglLinkContext(context, disp); + else + return EGL_NO_CONTEXT; } EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.DestroyContext(drv, dpy, ctx); + _EGL_DECLARE_DD_AND_CONTEXT(dpy, ctx); + _eglUnlinkContext(context); + return drv->API.DestroyContext(drv, disp, context); } EGLBoolean EGLAPIENTRY -eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) +eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, + EGLContext ctx) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.MakeCurrent(drv, dpy, draw, read, ctx); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLContext *context = _eglLookupContext(ctx, disp); + _EGLSurface *draw_surf = _eglLookupSurface(draw, disp); + _EGLSurface *read_surf = _eglLookupSurface(read, disp); + _EGLDriver *drv; + + drv = _eglCheckDisplay(disp, __FUNCTION__); + if (!drv) + return EGL_FALSE; + if (!context && ctx != EGL_NO_CONTEXT) + return _eglError(EGL_BAD_CONTEXT, __FUNCTION__); + if ((!draw_surf && draw != EGL_NO_SURFACE) || + (!read_surf && read != EGL_NO_SURFACE)) + return _eglError(EGL_BAD_SURFACE, __FUNCTION__); + + return drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context); } EGLBoolean EGLAPIENTRY -eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) +eglQueryContext(EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.QueryContext(drv, dpy, ctx, attribute, value); + _EGL_DECLARE_DD_AND_CONTEXT(dpy, ctx); + return drv->API.QueryContext(drv, disp, context, attribute, value); } EGLSurface EGLAPIENTRY -eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) +eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, + NativeWindowType window, const EGLint *attrib_list) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.CreateWindowSurface(drv, dpy, config, window, attrib_list); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + + drv = _eglCheckConfig(disp, conf, __FUNCTION__); + if (!drv) + return EGL_NO_SURFACE; + + surf = drv->API.CreateWindowSurface(drv, disp, conf, window, attrib_list); + if (surf) + return _eglLinkSurface(surf, disp); + else + return EGL_NO_SURFACE; } EGLSurface EGLAPIENTRY -eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list) +eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, + NativePixmapType pixmap, const EGLint *attrib_list) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.CreatePixmapSurface(drv, dpy, config, pixmap, attrib_list); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + + drv = _eglCheckConfig(disp, conf, __FUNCTION__); + if (!drv) + return EGL_NO_SURFACE; + + surf = drv->API.CreatePixmapSurface(drv, disp, conf, pixmap, attrib_list); + if (surf) + return _eglLinkSurface(surf, disp); + else + return EGL_NO_SURFACE; } EGLSurface EGLAPIENTRY -eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.CreatePbufferSurface(drv, dpy, config, attrib_list); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + + drv = _eglCheckConfig(disp, conf, __FUNCTION__); + if (!drv) + return EGL_NO_SURFACE; + + surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list); + if (surf) + return _eglLinkSurface(surf, disp); + else + return EGL_NO_SURFACE; } EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.DestroySurface(drv, dpy, surface); + _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); + _eglUnlinkSurface(surf); + return drv->API.DestroySurface(drv, disp, surf); } - EGLBoolean EGLAPIENTRY -eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) +eglQuerySurface(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint *value) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.QuerySurface(drv, dpy, surface, attribute, value); + _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); + return drv->API.QuerySurface(drv, disp, surf, attribute, value); } - EGLBoolean EGLAPIENTRY -eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint value) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.SurfaceAttrib(drv, dpy, surface, attribute, value); + _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); + return drv->API.SurfaceAttrib(drv, disp, surf, attribute, value); } EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.BindTexImage(drv, dpy, surface, buffer); + _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); + return drv->API.BindTexImage(drv, disp, surf, buffer); } EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.ReleaseTexImage(drv, dpy, surface, buffer); + _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); + return drv->API.ReleaseTexImage(drv, disp, surf, buffer); } EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.SwapInterval(drv, dpy, interval); + _EGL_DECLARE_DD(dpy); + return drv->API.SwapInterval(drv, disp, interval); } EGLBoolean EGLAPIENTRY -eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) +eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.SwapBuffers(drv, dpy, draw); + _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); + return drv->API.SwapBuffers(drv, disp, surf); } EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, NativePixmapType target) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.CopyBuffers(drv, dpy, surface, target); + _EGL_DECLARE_DD_AND_SURFACE(dpy, surface); + return drv->API.CopyBuffers(drv, disp, surf, target); } EGLBoolean EGLAPIENTRY eglWaitGL(void) { - EGLDisplay dpy = eglGetCurrentDisplay(); - if (dpy != EGL_NO_DISPLAY) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.WaitGL(drv, dpy); - } - else - return EGL_FALSE; + _EGLDisplay *disp = _eglGetCurrentDisplay(); + _EGLDriver *drv; + + if (!disp) + return EGL_TRUE; + + /* a current display is always initialized */ + drv = disp->Driver; + + return drv->API.WaitGL(drv, disp); } EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) { - EGLDisplay dpy = eglGetCurrentDisplay(); - if (dpy != EGL_NO_DISPLAY) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.WaitNative(drv, dpy, engine); - } - else - return EGL_FALSE; + _EGLDisplay *disp = _eglGetCurrentDisplay(); + _EGLDriver *drv; + + if (!disp) + return EGL_TRUE; + + /* a current display is always initialized */ + drv = disp->Driver; + + return drv->API.WaitNative(drv, disp, engine); } @@ -420,111 +670,168 @@ eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes) { - _EGLDriver *drv = _eglLookupDriver(dpy); - if (drv) - return drv->API.ChooseModeMESA(drv, dpy, screen, attrib_list, modes, modes_size, num_modes); - else - return EGL_FALSE; + _EGL_DECLARE_DD_AND_SCREEN(dpy, screen); + return drv->API.ChooseModeMESA(drv, disp, scrn, attrib_list, + modes, modes_size, num_modes); } EGLBoolean EGLAPIENTRY -eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint mode_size, EGLint *num_mode) +eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, + EGLint mode_size, EGLint *num_mode) { - _EGLDriver *drv = _eglLookupDriver(dpy); - if (drv) - return drv->API.GetModesMESA(drv, dpy, screen, modes, mode_size, num_mode); - else - return EGL_FALSE; + _EGL_DECLARE_DD_AND_SCREEN(dpy, screen); + return drv->API.GetModesMESA(drv, disp, scrn, modes, mode_size, num_mode); } EGLBoolean EGLAPIENTRY -eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value) +eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, + EGLint attribute, EGLint *value) { - _EGLDriver *drv = _eglLookupDriver(dpy); - if (drv) - return drv->API.GetModeAttribMESA(drv, dpy, mode, attribute, value); - else - return EGL_FALSE; + _EGL_DECLARE_DD_AND_MODE(dpy, mode); + return drv->API.GetModeAttribMESA(drv, disp, m, attribute, value); } EGLBoolean EGLAPIENTRY -eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask) -{ - _EGLDriver *drv = _eglLookupDriver(dpy); - if (drv) - return drv->API.CopyContextMESA(drv, dpy, source, dest, mask); - else +eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest, + EGLint mask) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLContext *source_context = _eglLookupContext(source, disp); + _EGLContext *dest_context = _eglLookupContext(dest, disp); + _EGLDriver *drv; + + drv = _eglCheckContext(disp, source_context, __FUNCTION__); + if (!drv || !dest_context) { + if (drv) + _eglError(EGL_BAD_CONTEXT, __FUNCTION__); return EGL_FALSE; + } + + return drv->API.CopyContextMESA(drv, disp, source_context, dest_context, + mask); } EGLBoolean -eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens) +eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, + EGLint max_screens, EGLint *num_screens) { - _EGLDriver *drv = _eglLookupDriver(dpy); - if (drv) - return drv->API.GetScreensMESA(drv, dpy, screens, max_screens, num_screens); - else - return EGL_FALSE; + _EGL_DECLARE_DD(dpy); + return drv->API.GetScreensMESA(drv, disp, screens, + max_screens, num_screens); } EGLSurface -eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.CreateScreenSurfaceMESA(drv, dpy, config, attrib_list); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + + drv = _eglCheckConfig(disp, conf, __FUNCTION__); + if (!drv) + return EGL_NO_SURFACE; + + surf = drv->API.CreateScreenSurfaceMESA(drv, disp, conf, attrib_list); + if (surf) + return _eglLinkSurface(surf, disp); + else + return EGL_NO_SURFACE; } EGLBoolean -eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode) +eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen, + EGLSurface surface, EGLModeMESA mode) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.ShowScreenSurfaceMESA(drv, dpy, screen, surface, mode); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLMode *m = _eglLookupMode(mode, disp); + _EGLDriver *drv; + + drv = _eglCheckScreen(disp, scrn, __FUNCTION__); + if (!drv) + return EGL_FALSE; + if (!surf && surface != EGL_NO_SURFACE) + return _eglError(EGL_BAD_SURFACE, __FUNCTION__); + if (!m && mode != EGL_NO_MODE_MESA) + return _eglError(EGL_BAD_MODE_MESA, __FUNCTION__); + + return drv->API.ShowScreenSurfaceMESA(drv, disp, scrn, surf, m); } EGLBoolean eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.ScreenPositionMESA(drv, dpy, screen, x, y); + _EGL_DECLARE_DD_AND_SCREEN(dpy, screen); + return drv->API.ScreenPositionMESA(drv, disp, scrn, x, y); } EGLBoolean -eglQueryScreenMESA( EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value) +eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLint attribute, EGLint *value) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.QueryScreenMESA(drv, dpy, screen, attribute, value); + _EGL_DECLARE_DD_AND_SCREEN(dpy, screen); + return drv->API.QueryScreenMESA(drv, disp, scrn, attribute, value); } EGLBoolean -eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface) +eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLSurface *surface) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.QueryScreenSurfaceMESA(drv, dpy, screen, surface); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp); + _EGLDriver *drv; + _EGLSurface *surf; + + drv = _eglCheckScreen(disp, scrn, __FUNCTION__); + if (!drv) + return EGL_FALSE; + + if (drv->API.QueryScreenSurfaceMESA(drv, disp, scrn, &surf) != EGL_TRUE) + surf = NULL; + if (surface) + *surface = _eglGetSurfaceHandle(surf); + return (surf != NULL); } EGLBoolean eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.QueryScreenModeMESA(drv, dpy, screen, mode); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp); + _EGLDriver *drv; + _EGLMode *m; + + drv = _eglCheckScreen(disp, scrn, __FUNCTION__); + if (!drv) + return EGL_FALSE; + + if (drv->API.QueryScreenModeMESA(drv, disp, scrn, &m) != EGL_TRUE) + m = NULL; + if (mode) + *mode = m->Handle; + + return (m != NULL); } const char * eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.QueryModeStringMESA(drv, dpy, mode); + _EGL_DECLARE_DD_AND_MODE(dpy, mode); + return drv->API.QueryModeStringMESA(drv, disp, m); } @@ -605,27 +912,37 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.CreatePbufferFromClientBuffer(drv, dpy, buftype, buffer, - config, attrib_list); + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + + drv = _eglCheckConfig(disp, conf, __FUNCTION__); + if (!drv) + return EGL_NO_SURFACE; + + surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer, + conf, attrib_list); + if (surf) + return _eglLinkSurface(surf, disp); + else + return EGL_NO_SURFACE; } EGLBoolean eglReleaseThread(void) { - EGLDisplay dpy; - - if (_eglIsCurrentThreadDummy()) - return EGL_TRUE; - - dpy = eglGetCurrentDisplay(); - if (dpy) { - _EGLDriver *drv = _eglLookupDriver(dpy); - /* unbind context */ - (void) drv->API.MakeCurrent(drv, dpy, EGL_NO_SURFACE, - EGL_NO_SURFACE, EGL_NO_CONTEXT); + /* unbind current context */ + if (!_eglIsCurrentThreadDummy()) { + _EGLDisplay *disp = _eglGetCurrentDisplay(); + _EGLDriver *drv; + if (disp) { + drv = disp->Driver; + (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL); + } } + _eglDestroyCurrentThread(); return EGL_TRUE; } @@ -634,13 +951,17 @@ eglReleaseThread(void) EGLBoolean eglWaitClient(void) { - EGLDisplay dpy = eglGetCurrentDisplay(); - if (dpy != EGL_NO_DISPLAY) { - _EGLDriver *drv = _eglLookupDriver(dpy); - return drv->API.WaitClient(drv, dpy); - } - else - return EGL_FALSE; + _EGLDisplay *disp = _eglGetCurrentDisplay(); + _EGLDriver *drv; + + if (!disp) + return EGL_TRUE; + + /* a current display is always initialized */ + drv = disp->Driver; + + return drv->API.WaitClient(drv, disp); } + #endif /* EGL_VERSION_1_2 */ diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h index f6163a0c7a..6081e58892 100644 --- a/src/egl/main/eglapi.h +++ b/src/egl/main/eglapi.h @@ -12,61 +12,61 @@ typedef void (*_EGLProc)(); */ /* driver funcs */ -typedef EGLBoolean (*Initialize_t)(_EGLDriver *, EGLDisplay dpy, EGLint *major, EGLint *minor); -typedef EGLBoolean (*Terminate_t)(_EGLDriver *, EGLDisplay dpy); +typedef EGLBoolean (*Initialize_t)(_EGLDriver *, _EGLDisplay *dpy, EGLint *major, EGLint *minor); +typedef EGLBoolean (*Terminate_t)(_EGLDriver *, _EGLDisplay *dpy); /* config funcs */ -typedef EGLBoolean (*GetConfigs_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); -typedef EGLBoolean (*ChooseConfig_t)(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); -typedef EGLBoolean (*GetConfigAttrib_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value); +typedef EGLBoolean (*GetConfigs_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); +typedef EGLBoolean (*ChooseConfig_t)(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); +typedef EGLBoolean (*GetConfigAttrib_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLint attribute, EGLint *value); /* context funcs */ -typedef EGLContext (*CreateContext_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); -typedef EGLBoolean (*DestroyContext_t)(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx); -typedef EGLBoolean (*MakeCurrent_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); -typedef EGLBoolean (*QueryContext_t)(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value); +typedef _EGLContext *(*CreateContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, _EGLContext *share_list, const EGLint *attrib_list); +typedef EGLBoolean (*DestroyContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx); +typedef EGLBoolean (*MakeCurrent_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx); +typedef EGLBoolean (*QueryContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value); /* surface funcs */ -typedef EGLSurface (*CreateWindowSurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list); -typedef EGLSurface (*CreatePixmapSurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list); -typedef EGLSurface (*CreatePbufferSurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); -typedef EGLBoolean (*DestroySurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface); -typedef EGLBoolean (*QuerySurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value); -typedef EGLBoolean (*SurfaceAttrib_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value); -typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); -typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); -typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, EGLDisplay dpy, EGLint interval); -typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw); -typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixmapType target); +typedef _EGLSurface *(*CreateWindowSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, NativeWindowType window, const EGLint *attrib_list); +typedef _EGLSurface *(*CreatePixmapSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, NativePixmapType pixmap, const EGLint *attrib_list); +typedef _EGLSurface *(*CreatePbufferSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, const EGLint *attrib_list); +typedef EGLBoolean (*DestroySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface); +typedef EGLBoolean (*QuerySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint *value); +typedef EGLBoolean (*SurfaceAttrib_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint value); +typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer); +typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer); +typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint interval); +typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw); +typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, NativePixmapType target); /* misc funcs */ -typedef const char *(*QueryString_t)(_EGLDriver *drv, EGLDisplay dpy, EGLint name); -typedef EGLBoolean (*WaitGL_t)(_EGLDriver *drv, EGLDisplay dpy); -typedef EGLBoolean (*WaitNative_t)(_EGLDriver *drv, EGLDisplay dpy, EGLint engine); +typedef const char *(*QueryString_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name); +typedef EGLBoolean (*WaitGL_t)(_EGLDriver *drv, _EGLDisplay *dpy); +typedef EGLBoolean (*WaitNative_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine); typedef _EGLProc (*GetProcAddress_t)(const char *procname); #ifdef EGL_MESA_screen_surface -typedef EGLBoolean (*ChooseModeMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); -typedef EGLBoolean (*GetModesMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint mode_size, EGLint *num_mode); -typedef EGLBoolean (*GetModeAttribMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value); -typedef EGLBoolean (*CopyContextMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask); -typedef EGLBoolean (*GetScreensMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); -typedef EGLSurface (*CreateScreenSurfaceMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); -typedef EGLBoolean (*ShowScreenSurfaceMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface surface, EGLModeMESA mode); -typedef EGLBoolean (*ScreenPositionMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y); -typedef EGLBoolean (*QueryScreenMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value); -typedef EGLBoolean (*QueryScreenSurfaceMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface); -typedef EGLBoolean (*QueryScreenModeMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode); -typedef const char * (*QueryModeStringMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode); +typedef EGLBoolean (*ChooseModeMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); +typedef EGLBoolean (*GetModesMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, EGLModeMESA *modes, EGLint mode_size, EGLint *num_mode); +typedef EGLBoolean (*GetModeAttribMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *mode, EGLint attribute, EGLint *value); +typedef EGLBoolean (*CopyContextMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *source, _EGLContext *dest, EGLint mask); +typedef EGLBoolean (*GetScreensMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); +typedef _EGLSurface *(*CreateScreenSurfaceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, const EGLint *attrib_list); +typedef EGLBoolean (*ShowScreenSurfaceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLSurface *surface, _EGLMode *mode); +typedef EGLBoolean (*ScreenPositionMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, EGLint x, EGLint y); +typedef EGLBoolean (*QueryScreenMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, EGLint attribute, EGLint *value); +typedef EGLBoolean (*QueryScreenSurfaceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLSurface **surface); +typedef EGLBoolean (*QueryScreenModeMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLMode **mode); +typedef const char * (*QueryModeStringMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *mode); #endif /* EGL_MESA_screen_surface */ #ifdef EGL_VERSION_1_2 -typedef EGLBoolean (*WaitClient_t)(_EGLDriver *drv, EGLDisplay dpy); -typedef EGLSurface (*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list); +typedef EGLBoolean (*WaitClient_t)(_EGLDriver *drv, _EGLDisplay *dpy); +typedef _EGLSurface *(*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLenum buftype, EGLClientBuffer buffer, _EGLConfig *config, const EGLint *attrib_list); #endif /* EGL_VERSION_1_2 */ diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index bbc585b55e..d47b99eed4 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -71,10 +71,9 @@ _eglGetConfigHandle(_EGLConfig *config) * This is the inverse of _eglGetConfigHandle(). */ _EGLConfig * -_eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config) +_eglLookupConfig(EGLConfig config, _EGLDisplay *disp) { EGLint i; - _EGLDisplay *disp = _eglLookupDisplay(dpy); for (i = 0; i < disp->NumConfigs; i++) { if (disp->Configs[i]->Handle == config) { return disp->Configs[i]; @@ -319,10 +318,9 @@ _eglCompareConfigs(const void *a, const void *b) * Typical fallback routine for eglChooseConfig */ EGLBoolean -_eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, +_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_configs) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); _EGLConfig **configList, criteria; EGLint i, count; @@ -367,10 +365,9 @@ _eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, * Fallback for eglGetConfigAttrib. */ EGLBoolean -_eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLint attribute, EGLint *value) { - const _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); const EGLint k = attribute - FIRST_ATTRIB; if (k >= 0 && k < MAX_ATTRIBS) { *value = conf->Attrib[k]; @@ -387,16 +384,9 @@ _eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, * Fallback for eglGetConfigs. */ EGLBoolean -_eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, +_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); - - if (!drv->Initialized) { - _eglError(EGL_NOT_INITIALIZED, "eglGetConfigs"); - return EGL_FALSE; - } - if (configs) { EGLint i; *num_config = MIN2(disp->NumConfigs, config_size); diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h index db1c4c10e0..36ed96ae95 100644 --- a/src/egl/main/eglconfig.h +++ b/src/egl/main/eglconfig.h @@ -34,7 +34,7 @@ _eglGetConfigHandle(_EGLConfig *config); extern _EGLConfig * -_eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config); +_eglLookupConfig(EGLConfig config, _EGLDisplay *dpy); extern _EGLConfig * @@ -46,15 +46,15 @@ _eglParseConfigAttribs(_EGLConfig *config, const EGLint *attrib_list); extern EGLBoolean -_eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); +_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); extern EGLBoolean -_eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value); +_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLint attribute, EGLint *value); extern EGLBoolean -_eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); +_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); extern void diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index 88de60d69b..b094f49bfc 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -25,11 +25,6 @@ _eglInitContext(_EGLDriver *drv, _EGLContext *ctx, return EGL_FALSE; } - if (!conf) { - _eglError(EGL_BAD_CONFIG, "_eglInitContext"); - return EGL_FALSE; - } - memset(ctx, 0, sizeof(_EGLContext)); ctx->ClientVersion = 1; /* the default, per EGL spec */ @@ -58,32 +53,25 @@ _eglInitContext(_EGLDriver *drv, _EGLContext *ctx, /** * Just a placeholder/demo function. Real driver will never use this! */ -EGLContext -_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, - EGLContext share_list, const EGLint *attrib_list) +_EGLContext * +_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + _EGLContext *share_list, const EGLint *attrib_list) { #if 0 /* example code */ _EGLContext *context; - _EGLConfig *conf; - - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreateContext"); - return EGL_NO_CONTEXT; - } context = (_EGLContext *) calloc(1, sizeof(_EGLContext)); if (!context) - return EGL_NO_CONTEXT; + return NULL; if (!_eglInitContext(drv, context, conf, attrib_list)) { free(context); - return EGL_NO_CONTEXT; + return NULL; } - return _eglLinkContext(context, _eglLookupDisplay(dpy)); + return context; #endif - return EGL_NO_CONTEXT; + return NULL; } @@ -91,36 +79,21 @@ _eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, * Default fallback routine - drivers should usually override this. */ EGLBoolean -_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) +_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) { - _EGLContext *context = _eglLookupContext(ctx); - if (context) { - _eglUnlinkContext(context); - if (!_eglIsContextBound(context)) - free(context); - return EGL_TRUE; - } - else { - _eglError(EGL_BAD_CONTEXT, "eglDestroyContext"); - return EGL_TRUE; - } + if (!_eglIsContextBound(ctx)) + free(ctx); + return EGL_TRUE; } EGLBoolean -_eglQueryContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, +_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *c, EGLint attribute, EGLint *value) { - _EGLContext *c = _eglLookupContext(ctx); - (void) drv; (void) dpy; - if (!c) { - _eglError(EGL_BAD_CONTEXT, "eglQueryContext"); - return EGL_FALSE; - } - switch (attribute) { case EGL_CONFIG_ID: *value = GET_CONFIG_ATTRIB(c->Config, EGL_CONFIG_ID); @@ -146,14 +119,10 @@ _eglQueryContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, * Then, the driver will do its device-dependent Make-Current stuff. */ EGLBoolean -_eglMakeCurrent(_EGLDriver *drv, EGLDisplay display, EGLSurface d, - EGLSurface r, EGLContext context) +_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, + _EGLSurface *read, _EGLContext *ctx) { _EGLThreadInfo *t = _eglGetCurrentThread(); - _EGLDisplay *dpy = _eglLookupDisplay(display); - _EGLContext *ctx = _eglLookupContext(context); - _EGLSurface *draw = _eglLookupSurface(d); - _EGLSurface *read = _eglLookupSurface(r); _EGLContext *oldContext = NULL; _EGLSurface *oldDrawSurface = NULL; _EGLSurface *oldReadSurface = NULL; @@ -161,18 +130,13 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay display, EGLSurface d, if (_eglIsCurrentThreadDummy()) return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent"); - if (dpy == NULL) - return _eglError(EGL_BAD_DISPLAY, "eglMakeCurrent"); if (ctx) { /* error checking */ if (ctx->Binding && ctx->Binding != t) return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); - if (draw == NULL || read == NULL) { - EGLint err = (d == EGL_NO_SURFACE || r == EGL_NO_SURFACE) - ? EGL_BAD_MATCH : EGL_BAD_SURFACE; - return _eglError(err, "eglMakeCurrent"); - } + if (draw == NULL || read == NULL) + return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); if (draw->Config != ctx->Config || read->Config != ctx->Config) return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); if ((draw->Binding && draw->Binding->Binding != t) || @@ -197,8 +161,6 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay display, EGLSurface d, apiIndex = _eglConvertApiToIndex(ctx->ClientAPI); } else { - if (context != EGL_NO_CONTEXT) - return _eglError(EGL_BAD_CONTEXT, "eglMakeCurrent"); if (draw != NULL || read != NULL) return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); apiIndex = t->CurrentAPIIndex; @@ -221,23 +183,19 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay display, EGLSurface d, /* * check if the old context or surfaces need to be deleted - * FIXME They are linked so that they can be unlinked. This is ugly. */ if (!_eglIsSurfaceLinked(oldDrawSurface)) { assert(draw != oldDrawSurface && read != oldDrawSurface); - drv->API.DestroySurface(drv, display, - _eglLinkSurface(oldDrawSurface, dpy)); + drv->API.DestroySurface(drv, dpy, oldDrawSurface); } if (oldReadSurface != oldDrawSurface && !_eglIsSurfaceLinked(oldReadSurface)) { assert(draw != oldReadSurface && read != oldReadSurface); - drv->API.DestroySurface(drv, display, - _eglLinkSurface(oldReadSurface, dpy)); + drv->API.DestroySurface(drv, dpy, oldReadSurface); } if (!_eglIsContextLinked(oldContext)) { assert(ctx != oldContext); - drv->API.DestroyContext(drv, display, - _eglLinkContext(oldContext, dpy)); + drv->API.DestroyContext(drv, dpy, oldContext); } } diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h index 4276c0980e..647f24488f 100644 --- a/src/egl/main/eglcontext.h +++ b/src/egl/main/eglcontext.h @@ -32,20 +32,20 @@ _eglInitContext(_EGLDriver *drv, _EGLContext *ctx, _EGLConfig *config, const EGLint *attrib_list); -extern EGLContext -_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); +extern _EGLContext * +_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list); extern EGLBoolean -_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx); +_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx); extern EGLBoolean -_eglQueryContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value); +_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value); extern EGLBoolean -_eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); +_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx); extern EGLBoolean diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index feae1d6040..c684e4291e 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -200,29 +200,29 @@ _eglFindDisplay(NativeDisplayType nativeDisplay) * Destroy the contexts and surfaces that are linked to the display. */ void -_eglReleaseDisplayResources(_EGLDriver *drv, EGLDisplay dpy) +_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *display) { - _EGLDisplay *display; _EGLContext *contexts; _EGLSurface *surfaces; - display = _eglLookupDisplay(dpy); - if (!display) - return; contexts = display->ContextList; surfaces = display->SurfaceList; while (contexts) { - EGLContext handle = _eglGetContextHandle(contexts); + _EGLContext *ctx = contexts; contexts = contexts->Next; - drv->API.DestroyContext(drv, dpy, handle); + + _eglUnlinkContext(ctx); + drv->API.DestroyContext(drv, display, ctx); } assert(!display->ContextList); while (surfaces) { - EGLSurface handle = _eglGetSurfaceHandle(surfaces); + _EGLSurface *surf = surfaces; surfaces = surfaces->Next; - drv->API.DestroySurface(drv, dpy, handle); + + _eglUnlinkSurface(surf); + drv->API.DestroySurface(drv, display, surf); } assert(!display->SurfaceList); } @@ -309,7 +309,7 @@ _eglGetContextHandle(_EGLContext *ctx) * Return NULL if the handle has no corresponding linked context. */ _EGLContext * -_eglLookupContext(EGLContext ctx) +_eglLookupContext(EGLContext ctx, _EGLDisplay *dpy) { _EGLContext *context = (_EGLContext *) ctx; return (context && context->Display) ? context : NULL; @@ -389,8 +389,8 @@ _eglGetSurfaceHandle(_EGLSurface *surface) * Return NULL if the handle has no corresponding linked surface. */ _EGLSurface * -_eglLookupSurface(EGLSurface surf) +_eglLookupSurface(EGLSurface surf, _EGLDisplay *dpy) { EGLuint key = _eglPointerToUInt((void *) surf); - return (_EGLSurface *) _eglHashLookup(_eglSurfaceHash, key); + return (_EGLSurface *) _eglHashLookup(dpy->SurfaceHash, key); } diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 70c59ef5e4..1ebc0fcb59 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -72,7 +72,7 @@ _eglFindDisplay(NativeDisplayType nativeDisplay); extern void -_eglReleaseDisplayResources(_EGLDriver *drv, EGLDisplay dpy); +_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy); extern void @@ -92,7 +92,7 @@ _eglGetContextHandle(_EGLContext *ctx); extern _EGLContext * -_eglLookupContext(EGLContext ctx); +_eglLookupContext(EGLContext ctx, _EGLDisplay *dpy); /** @@ -117,7 +117,7 @@ _eglGetSurfaceHandle(_EGLSurface *); extern _EGLSurface * -_eglLookupSurface(EGLSurface surf); +_eglLookupSurface(EGLSurface surf, _EGLDisplay *dpy); /** diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index f2a864cd8a..a8ac7b3233 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -277,7 +277,7 @@ _eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args) EGLBoolean -_eglCloseDriver(_EGLDriver *drv, EGLDisplay dpy) +_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy) { void *handle = drv->LibHandle; EGLBoolean b; diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 4066c6ec1d..d97a24db1d 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -59,7 +59,7 @@ _eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args); extern EGLBoolean -_eglCloseDriver(_EGLDriver *drv, EGLDisplay dpy); +_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy); extern void diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c index b5bdc3ea4b..3440b77dd9 100644 --- a/src/egl/main/eglmisc.c +++ b/src/egl/main/eglmisc.c @@ -77,7 +77,7 @@ _eglUpdateAPIsString(_EGLDriver *drv) const char * -_eglQueryString(_EGLDriver *drv, EGLDisplay dpy, EGLint name) +_eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name) { (void) drv; (void) dpy; @@ -102,7 +102,7 @@ _eglQueryString(_EGLDriver *drv, EGLDisplay dpy, EGLint name) EGLBoolean -_eglWaitGL(_EGLDriver *drv, EGLDisplay dpy) +_eglWaitGL(_EGLDriver *drv, _EGLDisplay *dpy) { /* just a placeholder */ (void) drv; @@ -112,7 +112,7 @@ _eglWaitGL(_EGLDriver *drv, EGLDisplay dpy) EGLBoolean -_eglWaitNative(_EGLDriver *drv, EGLDisplay dpy, EGLint engine) +_eglWaitNative(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine) { /* just a placeholder */ (void) drv; diff --git a/src/egl/main/eglmisc.h b/src/egl/main/eglmisc.h index 4e2a40ea99..a15c839be2 100644 --- a/src/egl/main/eglmisc.h +++ b/src/egl/main/eglmisc.h @@ -33,15 +33,15 @@ extern const char * -_eglQueryString(_EGLDriver *drv, EGLDisplay dpy, EGLint name); +_eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name); extern EGLBoolean -_eglWaitGL(_EGLDriver *drv, EGLDisplay dpy); +_eglWaitGL(_EGLDriver *drv, _EGLDisplay *dpy); extern EGLBoolean -_eglWaitNative(_EGLDriver *drv, EGLDisplay dpy, EGLint engine); +_eglWaitNative(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine); #endif /* EGLMISC_INCLUDED */ diff --git a/src/egl/main/eglmode.c b/src/egl/main/eglmode.c index 786432234b..0f3ba6e5c0 100644 --- a/src/egl/main/eglmode.c +++ b/src/egl/main/eglmode.c @@ -34,9 +34,8 @@ my_strdup(const char *s) * or null if non-existant. */ _EGLMode * -_eglLookupMode(EGLDisplay dpy, EGLModeMESA mode) +_eglLookupMode(EGLModeMESA mode, _EGLDisplay *disp) { - const _EGLDisplay *disp = _eglLookupDisplay(dpy); EGLint scrnum; /* loop over all screens on the display */ @@ -272,19 +271,13 @@ _eglCompareModes(const void *a, const void *b) * Called via eglChooseModeMESA API function. */ EGLBoolean -_eglChooseModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, +_eglChooseModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes) { - const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); _EGLMode **modeList, min; EGLint i, count; - if (!scrn) { - _eglError(EGL_BAD_SCREEN_MESA, "eglChooseModeMESA"); - return EGL_FALSE; - } - if (!_eglParseModeAttribs(&min, attrib_list)) { /* error code will have been recorded */ return EGL_FALSE; @@ -326,16 +319,9 @@ _eglChooseModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, * Called via eglGetModesMESA() API function. */ EGLBoolean -_eglGetModesMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, +_eglGetModesMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes) { - _EGLScreen *scrn = _eglLookupScreen(dpy, screen); - - if (!scrn) { - _eglError(EGL_BAD_SCREEN_MESA, "eglGetModesMESA"); - return EGL_FALSE; - } - if (modes) { EGLint i; *num_modes = MIN2(scrn->NumModes, modes_size); @@ -356,17 +342,11 @@ _eglGetModesMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, * Query an attribute of a mode. */ EGLBoolean -_eglGetModeAttribMESA(_EGLDriver *drv, EGLDisplay dpy, - EGLModeMESA mode, EGLint attribute, EGLint *value) +_eglGetModeAttribMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLMode *m, EGLint attribute, EGLint *value) { - _EGLMode *m = _eglLookupMode(dpy, mode); EGLint v; - if (!m) { - _eglError(EGL_BAD_MODE_MESA, "eglGetModeAttribMESA"); - return EGL_FALSE; - } - v = getModeAttrib(m, attribute); if (v < 0) { _eglError(EGL_BAD_ATTRIBUTE, "eglGetModeAttribMESA"); @@ -382,13 +362,8 @@ _eglGetModeAttribMESA(_EGLDriver *drv, EGLDisplay dpy, * This is the default function called by eglQueryModeStringMESA(). */ const char * -_eglQueryModeStringMESA(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode) +_eglQueryModeStringMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m) { - _EGLMode *m = _eglLookupMode(dpy, mode); - if (!m) { - _eglError(EGL_BAD_MODE_MESA, "eglQueryModeStringMESA"); - return NULL; - } return m->Name; } diff --git a/src/egl/main/eglmode.h b/src/egl/main/eglmode.h index 52d4875676..af7c2c56d3 100644 --- a/src/egl/main/eglmode.h +++ b/src/egl/main/eglmode.h @@ -26,7 +26,7 @@ struct _egl_mode extern _EGLMode * -_eglLookupMode(EGLDisplay dpy, EGLModeMESA mode); +_eglLookupMode(EGLModeMESA mode, _EGLDisplay *dpy); extern _EGLMode * @@ -35,23 +35,23 @@ _eglAddNewMode(_EGLScreen *screen, EGLint width, EGLint height, extern EGLBoolean -_eglChooseModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, +_eglChooseModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); extern EGLBoolean -_eglGetModesMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, +_eglGetModesMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); extern EGLBoolean -_eglGetModeAttribMESA(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode, +_eglGetModeAttribMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m, EGLint attribute, EGLint *value); extern const char * -_eglQueryModeStringMESA(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode); +_eglQueryModeStringMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m); #endif /* EGLMODE_INCLUDED */ diff --git a/src/egl/main/eglscreen.c b/src/egl/main/eglscreen.c index b6bde65e8b..14a1e9f8fe 100644 --- a/src/egl/main/eglscreen.c +++ b/src/egl/main/eglscreen.c @@ -52,13 +52,9 @@ _eglInitScreen(_EGLScreen *screen) * Given a public screen handle, return the internal _EGLScreen object. */ _EGLScreen * -_eglLookupScreen(EGLDisplay dpy, EGLScreenMESA screen) +_eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *display) { EGLint i; - _EGLDisplay *display = _eglLookupDisplay(dpy); - - if (!display) - return NULL; for (i = 0; i < display->NumScreens; i++) { if (display->Screens[i]->Handle == screen) @@ -89,17 +85,11 @@ _eglAddScreen(_EGLDisplay *display, _EGLScreen *screen) EGLBoolean -_eglGetScreensMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens, +_eglGetScreensMESA(_EGLDriver *drv, _EGLDisplay *display, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens) { - _EGLDisplay *display = _eglLookupDisplay(dpy); EGLint n; - if (!display) { - _eglError(EGL_BAD_DISPLAY, "eglGetScreensMESA"); - return EGL_FALSE; - } - if (display->NumScreens > max_screens) { n = max_screens; } @@ -122,33 +112,26 @@ _eglGetScreensMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens, /** * Example function - drivers should do a proper implementation. */ -EGLSurface -_eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +_EGLSurface * +_eglCreateScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list) { #if 0 /* THIS IS JUST EXAMPLE CODE */ _EGLSurface *surf; - _EGLConfig *conf; - - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreateScreenSurfaceMESA"); - return EGL_NO_SURFACE; - } surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); if (!surf) - return EGL_NO_SURFACE; + return NULL; if (!_eglInitSurface(drv, surf, EGL_SCREEN_BIT_MESA, conf, attrib_list)) { free(surf); - return EGL_NO_SURFACE; + return NULL; } - return _eglLinkSurface(surf, _eglLookupDisplay(dpy)); + return surf; #endif - return EGL_NO_SURFACE; + return NULL; } @@ -160,28 +143,15 @@ _eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, * this with code that _really_ shows the surface. */ EGLBoolean -_eglShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, - EGLScreenMESA screen, EGLSurface surface, - EGLModeMESA m) +_eglShowScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scrn, _EGLSurface *surf, + _EGLMode *mode) { - _EGLScreen *scrn = _eglLookupScreen(dpy, screen); - _EGLMode *mode = _eglLookupMode(dpy, m); - - if (!scrn) { - _eglError(EGL_BAD_SCREEN_MESA, "eglShowSurfaceMESA"); - return EGL_FALSE; - } - if (!mode && (m != EGL_NO_MODE_MESA )) { - _eglError(EGL_BAD_MODE_MESA, "eglShowSurfaceMESA"); - return EGL_FALSE; - } - - if (surface == EGL_NO_SURFACE) { + if (!surf) { scrn->CurrentSurface = NULL; } else { - _EGLSurface *surf = _eglLookupSurface(surface); - if (!surf || surf->Type != EGL_SCREEN_BIT_MESA) { + if (surf->Type != EGL_SCREEN_BIT_MESA) { _eglError(EGL_BAD_SURFACE, "eglShowSurfaceMESA"); return EGL_FALSE; } @@ -206,18 +176,10 @@ _eglShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, * this with code that _really_ sets the mode. */ EGLBoolean -_eglScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, - EGLModeMESA mode) +_eglScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + _EGLMode *m) { - _EGLScreen *scrn = _eglLookupScreen(dpy, screen); - - if (!scrn) { - _eglError(EGL_BAD_SCREEN_MESA, "eglScreenModeMESA"); - return EGL_FALSE; - } - - scrn->CurrentMode = _eglLookupMode(dpy, mode); - + scrn->CurrentMode = m; return EGL_TRUE; } @@ -226,15 +188,9 @@ _eglScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, * Set a screen's surface origin. */ EGLBoolean -_eglScreenPositionMESA(_EGLDriver *drv, EGLDisplay dpy, - EGLScreenMESA screen, EGLint x, EGLint y) +_eglScreenPositionMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scrn, EGLint x, EGLint y) { - _EGLScreen *scrn = _eglLookupScreen(dpy, screen); - if (!scrn) { - _eglError(EGL_BAD_SCREEN_MESA, "eglScreenPositionMESA"); - return EGL_FALSE; - } - scrn->OriginX = x; scrn->OriginY = y; @@ -246,14 +202,10 @@ _eglScreenPositionMESA(_EGLDriver *drv, EGLDisplay dpy, * Query a screen's current surface. */ EGLBoolean -_eglQueryScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, - EGLScreenMESA screen, EGLSurface *surface) +_eglQueryScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scrn, _EGLSurface **surf) { - const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); - if (scrn->CurrentSurface) - *surface = scrn->CurrentSurface->Handle; - else - *surface = EGL_NO_SURFACE; + *surf = scrn->CurrentSurface; return EGL_TRUE; } @@ -262,29 +214,18 @@ _eglQueryScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, * Query a screen's current mode. */ EGLBoolean -_eglQueryScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, - EGLModeMESA *mode) +_eglQueryScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + _EGLMode **m) { - const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); - if (scrn->CurrentMode) - *mode = scrn->CurrentMode->Handle; - else - *mode = EGL_NO_MODE_MESA; + *m = scrn->CurrentMode; return EGL_TRUE; } EGLBoolean -_eglQueryScreenMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, +_eglQueryScreenMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, EGLint attribute, EGLint *value) { - const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); - - if (!scrn) { - _eglError(EGL_BAD_SCREEN_MESA, "eglQueryScreenMESA"); - return EGL_FALSE; - } - switch (attribute) { case EGL_SCREEN_POSITION_MESA: value[0] = scrn->OriginX; diff --git a/src/egl/main/eglscreen.h b/src/egl/main/eglscreen.h index 833439b410..8860a2aa7f 100644 --- a/src/egl/main/eglscreen.h +++ b/src/egl/main/eglscreen.h @@ -35,7 +35,7 @@ _eglInitScreen(_EGLScreen *screen); extern _EGLScreen * -_eglLookupScreen(EGLDisplay dpy, EGLScreenMESA screen); +_eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *dpy); extern void @@ -43,40 +43,40 @@ _eglAddScreen(_EGLDisplay *display, _EGLScreen *screen); extern EGLBoolean -_eglGetScreensMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); +_eglGetScreensMESA(_EGLDriver *drv, _EGLDisplay *dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); -extern EGLSurface -_eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); +extern _EGLSurface * +_eglCreateScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list); extern EGLBoolean -_eglShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface surface, EGLModeMESA mode); +_eglShowScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, _EGLSurface *surf, _EGLMode *m); extern EGLBoolean -_eglScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA mode); +_eglScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, _EGLMode *m); extern EGLBoolean -_eglScreenPositionMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y); +_eglScreenPositionMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, EGLint x, EGLint y); extern EGLBoolean -_eglQueryDisplayMESA(_EGLDriver *drv, EGLDisplay dpy, EGLint attribute, EGLint *value); +_eglQueryDisplayMESA(_EGLDriver *drv, _EGLDisplay *dpy, EGLint attribute, EGLint *value); extern EGLBoolean -_eglQueryScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, - EGLScreenMESA screen, EGLSurface *surface); +_eglQueryScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scrn, _EGLSurface **surface); extern EGLBoolean -_eglQueryScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode); +_eglQueryScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, _EGLMode **m); extern EGLBoolean -_eglQueryScreenMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value); +_eglQueryScreenMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, EGLint attribute, EGLint *value); extern void diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index 3947051127..056288c850 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -211,22 +211,15 @@ _eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type, EGLBoolean -_eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) +_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) { - /* Basically just do error checking here. Drivers have to do the - * actual buffer swap. - */ - _EGLSurface *surface = _eglLookupSurface(draw); - if (surface == NULL) { - _eglError(EGL_BAD_SURFACE, "eglSwapBuffers"); - return EGL_FALSE; - } + /* Drivers have to do the actual buffer swap. */ return EGL_TRUE; } EGLBoolean -_eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, +_eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, NativePixmapType target) { /* copy surface to native pixmap */ @@ -236,14 +229,9 @@ _eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLBoolean -_eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, +_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint *value) { - _EGLSurface *surface = _eglLookupSurface(surf); - if (surface == NULL) { - _eglError(EGL_BAD_SURFACE, "eglQuerySurface"); - return EGL_FALSE; - } switch (attribute) { case EGL_WIDTH: *value = surface->Width; @@ -312,96 +300,75 @@ _eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, /** * Example function - drivers should do a proper implementation. */ -EGLSurface -_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +_EGLSurface * +_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list) { #if 0 /* THIS IS JUST EXAMPLE CODE */ _EGLSurface *surf; - _EGLConfig *conf; - - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreateWindowSurface"); - return EGL_NO_SURFACE; - } surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); if (!surf) - return EGL_NO_SURFACE; + return NULL; if (!_eglInitSurface(drv, surf, EGL_WINDOW_BIT, conf, attrib_list)) { free(surf); - return EGL_NO_SURFACE; + return NULL; } - return _eglLinkSurface(surf, _eglLookupDisplay(dpy)); + return surf; #endif - return EGL_NO_SURFACE; + return NULL; } /** * Example function - drivers should do a proper implementation. */ -EGLSurface -_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +_EGLSurface * +_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list) { #if 0 /* THIS IS JUST EXAMPLE CODE */ _EGLSurface *surf; - _EGLConfig *conf; - - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreatePixmapSurface"); - return EGL_NO_SURFACE; - } surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); if (!surf) - return EGL_NO_SURFACE; + return NULL; if (!_eglInitSurface(drv, surf, EGL_PIXMAP_BIT, conf, attrib_list)) { free(surf); - return EGL_NO_SURFACE; + return NULL; } - return _eglLinkSurface(surf, _eglLookupDisplay(dpy)); + return surf; #endif - return EGL_NO_SURFACE; + return NULL; } /** * Example function - drivers should do a proper implementation. */ -EGLSurface -_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +_EGLSurface * +_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list) { #if 0 /* THIS IS JUST EXAMPLE CODE */ _EGLSurface *surf; - _EGLConfig *conf; - - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreatePbufferSurface"); - return EGL_NO_SURFACE; - } surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); if (!surf) - return EGL_NO_SURFACE; + return NULL; if (!_eglInitSurface(drv, surf, EGL_PBUFFER_BIT, conf, attrib_list)) { free(surf); - return EGL_NO_SURFACE; + return NULL; } - return _eglLinkSurface(surf, _eglLookupDisplay(dpy)); + return NULL; #endif - return EGL_NO_SURFACE; + return NULL; } @@ -409,19 +376,11 @@ _eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, * Default fallback routine - drivers should usually override this. */ EGLBoolean -_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) { - _EGLSurface *surf = _eglLookupSurface(surface); - if (surf) { - _eglUnlinkSurface(surf); - if (!_eglIsSurfaceBound(surf)) - free(surf); - return EGL_TRUE; - } - else { - _eglError(EGL_BAD_SURFACE, "eglDestroySurface"); - return EGL_FALSE; - } + if (!_eglIsSurfaceBound(surf)) + free(surf); + return EGL_TRUE; } @@ -429,16 +388,9 @@ _eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) * Default fallback routine - drivers might override this. */ EGLBoolean -_eglSurfaceAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, +_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint value) { - _EGLSurface *surface = _eglLookupSurface(surf); - - if (surface == NULL) { - _eglError(EGL_BAD_SURFACE, "eglSurfaceAttrib"); - return EGL_FALSE; - } - switch (attribute) { case EGL_MIPMAP_LEVEL: surface->MipmapLevel = value; @@ -452,15 +404,14 @@ _eglSurfaceAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLBoolean -_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, +_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer) { /* Just do basic error checking and return success/fail. * Drivers must implement the real stuff. */ - _EGLSurface *surface = _eglLookupSurface(surf); - if (!surface || surface->Type != EGL_PBUFFER_BIT) { + if (surface->Type != EGL_PBUFFER_BIT) { _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); return EGL_FALSE; } @@ -482,15 +433,14 @@ _eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLBoolean -_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, +_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer) { /* Just do basic error checking and return success/fail. * Drivers must implement the real stuff. */ - _EGLSurface *surface = _eglLookupSurface(surf); - if (!surface || surface->Type != EGL_PBUFFER_BIT) { + if (surface->Type != EGL_PBUFFER_BIT) { _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); return EGL_FALSE; } @@ -517,14 +467,11 @@ _eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLBoolean -_eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval) +_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, EGLint interval) { _EGLSurface *surf = _eglGetCurrentSurface(EGL_DRAW); - if (surf == NULL) { - _eglError(EGL_BAD_SURFACE, "eglSwapInterval"); - return EGL_FALSE; - } - surf->SwapInterval = interval; + if (surf) + surf->SwapInterval = interval; return EGL_TRUE; } @@ -534,17 +481,17 @@ _eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval) /** * Example function - drivers should do a proper implementation. */ -EGLSurface -_eglCreatePbufferFromClientBuffer(_EGLDriver *drv, EGLDisplay dpy, +_EGLSurface * +_eglCreatePbufferFromClientBuffer(_EGLDriver *drv, _EGLDisplay *dpy, EGLenum buftype, EGLClientBuffer buffer, - EGLConfig config, const EGLint *attrib_list) + _EGLConfig *conf, const EGLint *attrib_list) { if (buftype != EGL_OPENVG_IMAGE) { _eglError(EGL_BAD_PARAMETER, "eglCreatePbufferFromClientBuffer"); - return EGL_NO_SURFACE; + return NULL; } - return EGL_NO_SURFACE; + return NULL; } #endif /* EGL_VERSION_1_2 */ diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h index 8864176844..cfae6970f2 100644 --- a/src/egl/main/eglsurface.h +++ b/src/egl/main/eglsurface.h @@ -47,55 +47,55 @@ _eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type, extern EGLBoolean -_eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw); +_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf); extern EGLBoolean -_eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixmapType target); +_eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, NativePixmapType target); extern EGLBoolean -_eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value); +_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value); -extern EGLSurface -_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list); +extern _EGLSurface * +_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list); -extern EGLSurface -_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list); +extern _EGLSurface * +_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list); -extern EGLSurface -_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); +extern _EGLSurface * +_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list); extern EGLBoolean -_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface); +_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf); extern EGLBoolean -_eglSurfaceAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value); +_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value); extern EGLBoolean -_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); +_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer); extern EGLBoolean -_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); +_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer); extern EGLBoolean -_eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval); +_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, EGLint interval); #ifdef EGL_VERSION_1_2 -extern EGLSurface -_eglCreatePbufferFromClientBuffer(_EGLDriver *drv, EGLDisplay dpy, +extern _EGLSurface * +_eglCreatePbufferFromClientBuffer(_EGLDriver *drv, _EGLDisplay *dpy, EGLenum buftype, EGLClientBuffer buffer, - EGLConfig config, const EGLint *attrib_list); + _EGLConfig *conf, const EGLint *attrib_list); #endif /* EGL_VERSION_1_2 */ diff --git a/src/gallium/state_trackers/egl/egl_context.c b/src/gallium/state_trackers/egl/egl_context.c index 2c8f51cf38..52b6453d29 100644 --- a/src/gallium/state_trackers/egl/egl_context.c +++ b/src/gallium/state_trackers/egl/egl_context.c @@ -83,23 +83,16 @@ const struct dri_extension card_extensions[] = { {NULL, NULL} }; -EGLContext -drm_create_context(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) +_EGLContext * +drm_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list) { struct drm_device *dev = (struct drm_device *)drv; struct drm_context *ctx; struct drm_context *share = NULL; struct st_context *st_share = NULL; - _EGLConfig *conf; int i; __GLcontextModes *visual; - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreateContext"); - return EGL_NO_CONTEXT; - } - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { switch (attrib_list[i]) { /* no attribs defined for now */ @@ -129,25 +122,20 @@ drm_create_context(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext if (!ctx->st) goto err_gl; - /* link to display */ - _eglLinkContext(&ctx->base, _eglLookupDisplay(dpy)); - assert(_eglGetContextHandle(&ctx->base)); - - return _eglGetContextHandle(&ctx->base); + return &ctx->base; err_gl: ctx->pipe->destroy(ctx->pipe); err_pipe: free(ctx); err_c: - return EGL_NO_CONTEXT; + return NULL; } EGLBoolean -drm_destroy_context(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) +drm_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *context) { struct drm_context *c = lookup_drm_context(context); - _eglUnlinkContext(&c->base); if (!_eglIsContextBound(&c->base)) { st_destroy_context(c->st); c->pipe->destroy(c->pipe); @@ -157,7 +145,7 @@ drm_destroy_context(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) } EGLBoolean -drm_make_current(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context) +drm_make_current(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *context) { struct drm_surface *readSurf = lookup_drm_surface(read); struct drm_surface *drawSurf = lookup_drm_surface(draw); diff --git a/src/gallium/state_trackers/egl/egl_surface.c b/src/gallium/state_trackers/egl/egl_surface.c index d4cd2d3c74..c66c48f848 100644 --- a/src/gallium/state_trackers/egl/egl_surface.c +++ b/src/gallium/state_trackers/egl/egl_surface.c @@ -178,22 +178,22 @@ drm_takedown_shown_screen(_EGLDriver *drv, struct drm_screen *screen) screen->shown = 0; } -EGLSurface -drm_create_window_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) +_EGLSurface * +drm_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list) { - return EGL_NO_SURFACE; + return NULL; } -EGLSurface -drm_create_pixmap_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list) +_EGLSurface * +drm_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list) { - return EGL_NO_SURFACE; + return NULL; } -EGLSurface -drm_create_pbuffer_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +_EGLSurface * +drm_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list) { int i; @@ -201,13 +201,6 @@ drm_create_pbuffer_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, int height = -1; struct drm_surface *surf = NULL; __GLcontextModes *visual; - _EGLConfig *conf; - - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreatePbufferSurface"); - return EGL_NO_CONTEXT; - } for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { switch (attrib_list[i]) { @@ -225,7 +218,7 @@ drm_create_pbuffer_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, if (width < 1 || height < 1) { _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePbufferSurface"); - return EGL_NO_SURFACE; + return NULL; } surf = (struct drm_surface *) calloc(1, sizeof(struct drm_surface)); @@ -245,17 +238,16 @@ drm_create_pbuffer_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, (void*)surf); drm_visual_modes_destroy(visual); - _eglLinkSurface(&surf->base, _eglLookupDisplay(dpy)); - return surf->base.Handle; + return &surf->base; err_surf: free(surf); err: - return EGL_NO_SURFACE; + return NULL; } -EGLSurface -drm_create_screen_surface_mesa(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg, +_EGLSurface * +drm_create_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *cfg, const EGLint *attrib_list) { EGLSurface surf = drm_create_pbuffer_surface(drv, dpy, cfg, attrib_list); @@ -264,14 +256,13 @@ drm_create_screen_surface_mesa(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg, } EGLBoolean -drm_show_screen_surface_mesa(_EGLDriver *drv, EGLDisplay dpy, - EGLScreenMESA screen, - EGLSurface surface, EGLModeMESA m) +drm_show_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *screen, + _EGLSurface *surface, _EGLMode *mode) { struct drm_device *dev = (struct drm_device *)drv; struct drm_surface *surf = lookup_drm_surface(surface); - struct drm_screen *scrn = lookup_drm_screen(dpy, screen); - _EGLMode *mode = _eglLookupMode(dpy, m); + struct drm_screen *scrn = lookup_drm_screen(screen); int ret; unsigned int i, k; @@ -361,11 +352,9 @@ err_bo: } EGLBoolean -drm_destroy_surface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface) { struct drm_surface *surf = lookup_drm_surface(surface); - _eglUnlinkSurface(&surf->base); - if (!_eglIsSurfaceBound(&surf->base)) { if (surf->screen) drm_takedown_shown_screen(drv, surf->screen); @@ -376,7 +365,7 @@ drm_destroy_surface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) } EGLBoolean -drm_swap_buffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) +drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw) { struct drm_surface *surf = lookup_drm_surface(draw); struct pipe_surface *back_surf; diff --git a/src/gallium/state_trackers/egl/egl_tracker.c b/src/gallium/state_trackers/egl/egl_tracker.c index 521c91d895..107f45cbcb 100644 --- a/src/gallium/state_trackers/egl/egl_tracker.c +++ b/src/gallium/state_trackers/egl/egl_tracker.c @@ -129,9 +129,8 @@ drm_find_dpms(struct drm_device *dev, struct drm_screen *screen) } EGLBoolean -drm_initialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor) +drm_initialize(_EGLDriver *drv, _EGLDisplay *disp, EGLint *major, EGLint *minor) { - _EGLDisplay *disp = _eglLookupDisplay(dpy); struct drm_device *dev = (struct drm_device *)drv; struct drm_screen *screen = NULL; drmModeConnectorPtr connector = NULL; @@ -214,7 +213,7 @@ err_fd: } EGLBoolean -drm_terminate(_EGLDriver *drv, EGLDisplay dpy) +drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy) { struct drm_device *dev = (struct drm_device *)drv; struct drm_screen *screen; @@ -240,7 +239,7 @@ drm_terminate(_EGLDriver *drv, EGLDisplay dpy) drmClose(dev->drmFD); - _eglCleanupDisplay(_eglLookupDisplay(dpy)); + _eglCleanupDisplay(dpy); free(dev); return EGL_TRUE; diff --git a/src/gallium/state_trackers/egl/egl_tracker.h b/src/gallium/state_trackers/egl/egl_tracker.h index 3b8836720d..25f70d885e 100644 --- a/src/gallium/state_trackers/egl/egl_tracker.h +++ b/src/gallium/state_trackers/egl/egl_tracker.h @@ -137,24 +137,21 @@ struct drm_screen static INLINE struct drm_context * -lookup_drm_context(EGLContext context) +lookup_drm_context(_EGLContext *c) { - _EGLContext *c = _eglLookupContext(context); return (struct drm_context *) c; } static INLINE struct drm_surface * -lookup_drm_surface(EGLSurface surface) +lookup_drm_surface(_EGLSurface *s) { - _EGLSurface *s = _eglLookupSurface(surface); return (struct drm_surface *) s; } static INLINE struct drm_screen * -lookup_drm_screen(EGLDisplay dpy, EGLScreenMESA screen) +lookup_drm_screen(_EGLScreen *s) { - _EGLScreen *s = _eglLookupScreen(dpy, screen); return (struct drm_screen *) s; } @@ -178,18 +175,18 @@ void drm_takedown_shown_screen(_EGLDriver *drv, struct drm_screen *screen); * All function exported to the egl side. */ /*@{*/ -EGLBoolean drm_initialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor); -EGLBoolean drm_terminate(_EGLDriver *drv, EGLDisplay dpy); -EGLContext drm_create_context(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); -EGLBoolean drm_destroy_context(_EGLDriver *drv, EGLDisplay dpy, EGLContext context); -EGLSurface drm_create_window_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list); -EGLSurface drm_create_pixmap_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list); -EGLSurface drm_create_pbuffer_surface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); -EGLSurface drm_create_screen_surface_mesa(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg, const EGLint *attrib_list); -EGLBoolean drm_show_screen_surface_mesa(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface surface, EGLModeMESA m); -EGLBoolean drm_destroy_surface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface); -EGLBoolean drm_make_current(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context); -EGLBoolean drm_swap_buffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw); +EGLBoolean drm_initialize(_EGLDriver *drv, _EGLDisplay *dpy, EGLint *major, EGLint *minor); +EGLBoolean drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy); +_EGLContext *drm_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list); +EGLBoolean drm_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *context); +_EGLSurface *drm_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list); +_EGLSurface *drm_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list); +_EGLSurface *drm_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list); +_EGLSurface *drm_create_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list); +EGLBoolean drm_show_screen_surface_mesa(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLSurface *surface, _EGLMode *mode); +EGLBoolean drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface); +EGLBoolean drm_make_current(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *context); +EGLBoolean drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw); /*@}*/ #endif diff --git a/src/gallium/winsys/egl_xlib/egl_xlib.c b/src/gallium/winsys/egl_xlib/egl_xlib.c index f409a3fd6b..ed7eab50dd 100644 --- a/src/gallium/winsys/egl_xlib/egl_xlib.c +++ b/src/gallium/winsys/egl_xlib/egl_xlib.c @@ -103,18 +103,16 @@ xlib_egl_driver(_EGLDriver *drv) static INLINE struct xlib_egl_surface * -lookup_surface(EGLSurface surf) +lookup_surface(_EGLSurface *surf) { - _EGLSurface *surface = _eglLookupSurface(surf); - return (struct xlib_egl_surface *) surface; + return (struct xlib_egl_surface *) surf; } static INLINE struct xlib_egl_context * -lookup_context(EGLContext ctx) +lookup_context(_EGLContext *ctx) { - _EGLContext *context = _eglLookupContext(ctx); - return (struct xlib_egl_context *) context; + return (struct xlib_egl_context *) ctx; } @@ -133,13 +131,12 @@ bitcount(unsigned int n) * Create the EGLConfigs. (one per X visual) */ static void -create_configs(_EGLDriver *drv, EGLDisplay dpy) +create_configs(_EGLDriver *drv, _EGLDisplay *disp) { static const EGLint all_apis = (EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENVG_BIT | EGL_OPENGL_BIT); - _EGLDisplay *disp = _eglLookupDisplay(dpy); XVisualInfo *visInfo, visTemplate; int num_visuals, i; @@ -194,7 +191,7 @@ create_configs(_EGLDriver *drv, EGLDisplay dpy) * Called via eglInitialize(), drv->API.Initialize(). */ static EGLBoolean -xlib_eglInitialize(_EGLDriver *drv, EGLDisplay dpy, +xlib_eglInitialize(_EGLDriver *drv, _EGLDisplay *dpy, EGLint *minor, EGLint *major) { create_configs(drv, dpy); @@ -213,7 +210,7 @@ xlib_eglInitialize(_EGLDriver *drv, EGLDisplay dpy, * Called via eglTerminate(), drv->API.Terminate(). */ static EGLBoolean -xlib_eglTerminate(_EGLDriver *drv, EGLDisplay dpy) +xlib_eglTerminate(_EGLDriver *drv, _EGLDisplay *dpy) { return EGL_TRUE; } @@ -342,24 +339,23 @@ flush_frontbuffer(struct pipe_winsys *pws, /** * Called via eglCreateContext(), drv->API.CreateContext(). */ -static EGLContext -xlib_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, - EGLContext share_list, const EGLint *attrib_list) +static _EGLContext * +xlib_eglCreateContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + _EGLContext *share_list, const EGLint *attrib_list) { struct xlib_egl_driver *xdrv = xlib_egl_driver(drv); - _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); struct xlib_egl_context *ctx; struct st_context *share_ctx = NULL; /* XXX fix */ __GLcontextModes visual; ctx = CALLOC_STRUCT(xlib_egl_context); if (!ctx) - return EGL_NO_CONTEXT; + return NULL; /* let EGL lib init the common stuff */ if (!_eglInitContext(drv, &ctx->Base, conf, attrib_list)) { free(ctx); - return EGL_NO_CONTEXT; + return NULL; } /* API-dependent context creation */ @@ -379,41 +375,33 @@ xlib_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, default: _eglError(EGL_BAD_MATCH, "eglCreateContext(unsupported API)"); free(ctx); - return EGL_NO_CONTEXT; + return NULL; } - _eglLinkContext(&ctx->Base, _eglLookupDisplay(dpy)); - - return _eglGetContextHandle(&ctx->Base); + return &ctx->Base; } static EGLBoolean -xlib_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) +xlib_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) { struct xlib_egl_context *context = lookup_context(ctx); - if (context) { - _eglUnlinkContext(&context->Base); - if (!_eglIsContextBound(&context->Base)) { - /* API-dependent clean-up */ - switch (context->Base.ClientAPI) { - case EGL_OPENGL_ES_API: - case EGL_OPENVG_API: - /* fall-through */ - case EGL_OPENGL_API: - st_destroy_context(context->Context); - break; - default: - assert(0); - } - free(context); + + if (!_eglIsContextBound(&context->Base)) { + /* API-dependent clean-up */ + switch (context->Base.ClientAPI) { + case EGL_OPENGL_ES_API: + case EGL_OPENVG_API: + /* fall-through */ + case EGL_OPENGL_API: + st_destroy_context(context->Context); + break; + default: + assert(0); } - return EGL_TRUE; - } - else { - _eglError(EGL_BAD_CONTEXT, "eglDestroyContext"); - return EGL_TRUE; + free(context); } + return EGL_TRUE; } @@ -421,15 +409,15 @@ xlib_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) * Called via eglMakeCurrent(), drv->API.MakeCurrent(). */ static EGLBoolean -xlib_eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, - EGLSurface draw, EGLSurface read, EGLContext ctx) +xlib_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx) { struct xlib_egl_context *context = lookup_context(ctx); struct xlib_egl_surface *draw_surf = lookup_surface(draw); struct xlib_egl_surface *read_surf = lookup_surface(read); struct st_context *oldctx = st_get_current(); - if (!_eglMakeCurrent(drv, dpy, draw, read, context)) + if (!_eglMakeCurrent(drv, dpy, draw, read, ctx)) return EGL_FALSE; /* Flush before switching context. Check client API? */ @@ -488,31 +476,26 @@ choose_stencil_format(const __GLcontextModes *visual) /** * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). */ -static EGLSurface -xlib_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +static _EGLSurface * +xlib_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list) { struct xlib_egl_driver *xdrv = xlib_egl_driver(drv); - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); - struct xlib_egl_surface *surf; __GLcontextModes visual; uint width, height; surf = CALLOC_STRUCT(xlib_egl_surface); if (!surf) - return EGL_NO_SURFACE; + return NULL; /* Let EGL lib init the common stuff */ if (!_eglInitSurface(drv, &surf->Base, EGL_WINDOW_BIT, conf, attrib_list)) { free(surf); - return EGL_NO_SURFACE; + return NULL; } - _eglLinkSurface(&surf->Base, disp); - /* * Now init the Xlib and gallium stuff */ @@ -539,46 +522,35 @@ xlib_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, st_resize_framebuffer(surf->Framebuffer, width, height); - return _eglGetSurfaceHandle(&surf->Base); + return &surf->Base; } -static EGLSurface -xlib_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, +static _EGLSurface * +xlib_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { struct xlib_egl_driver *xdrv = xlib_egl_driver(drv); - _EGLDisplay *disp = _eglLookupDisplay(dpy); - _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); struct xlib_egl_surface *surf; __GLcontextModes visual; uint width, height; EGLBoolean bind_texture; - if (!disp) { - _eglError(EGL_BAD_DISPLAY, "eglCreatePbufferSurface"); - return EGL_NO_SURFACE; - } - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreatePbufferSurface"); - return EGL_NO_SURFACE; - } - surf = CALLOC_STRUCT(xlib_egl_surface); if (!surf) { _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); - return EGL_NO_SURFACE; + return NULL; } if (!_eglInitSurface(drv, &surf->Base, EGL_PBUFFER_BIT, conf, attrib_list)) { free(surf); - return EGL_NO_SURFACE; + return NULL; } if (surf->Base.Width < 0 || surf->Base.Height < 0) { _eglError(EGL_BAD_PARAMETER, "eglCreatePbufferSurface"); free(surf); - return EGL_NO_SURFACE; + return NULL; } bind_texture = (surf->Base.TextureFormat != EGL_NO_TEXTURE); @@ -588,19 +560,19 @@ xlib_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, (surf->Base.TextureTarget != EGL_NO_TEXTURE && !bind_texture)) { _eglError(EGL_BAD_MATCH, "eglCreatePbufferSurface"); free(surf); - return EGL_NO_SURFACE; + return NULL; } /* a framebuffer of zero width or height confuses st */ if (width == 0 || height == 0) { _eglError(EGL_BAD_MATCH, "eglCreatePbufferSurface"); free(surf); - return EGL_NO_SURFACE; + return NULL; } /* no mipmap generation */ if (surf->Base.MipmapTexture) { _eglError(EGL_BAD_MATCH, "eglCreatePbufferSurface"); free(surf); - return EGL_NO_SURFACE; + return NULL; } surf->winsys = xdrv->winsys; @@ -616,34 +588,27 @@ xlib_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, (void *) surf); st_resize_framebuffer(surf->Framebuffer, width, height); - return _eglLinkSurface(&surf->Base, disp); + return &surf->Base; } static EGLBoolean -xlib_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +xlib_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface) { struct xlib_egl_surface *surf = lookup_surface(surface); - if (surf) { - _eglUnlinkSurface(&surf->Base); - if (!_eglIsSurfaceBound(&surf->Base)) { - if (surf->Base.Type != EGL_PBUFFER_BIT) - XFreeGC(surf->Dpy, surf->Gc); - st_unreference_framebuffer(surf->Framebuffer); - free(surf); - } - return EGL_TRUE; - } - else { - _eglError(EGL_BAD_SURFACE, "eglDestroySurface"); - return EGL_FALSE; + if (!_eglIsSurfaceBound(&surf->Base)) { + if (surf->Base.Type != EGL_PBUFFER_BIT) + XFreeGC(surf->Dpy, surf->Gc); + st_unreference_framebuffer(surf->Framebuffer); + free(surf); } + return EGL_TRUE; } static EGLBoolean -xlib_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, - EGLSurface surface, EGLint buffer) +xlib_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *surface, EGLint buffer) { struct xlib_egl_surface *xsurf = lookup_surface(surface); struct xlib_egl_context *xctx; @@ -680,12 +645,12 @@ xlib_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, /* flush properly */ if (eglGetCurrentSurface(EGL_DRAW) == surface) { - xctx = lookup_context(eglGetCurrentContext()); + xctx = lookup_context(_eglGetCurrentContext()); st_flush(xctx->Context, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); } else if (_eglIsSurfaceBound(&xsurf->Base)) { - xctx = lookup_context(_eglGetContextHandle(xsurf->Base.Binding)); + xctx = lookup_context(xsurf->Base.Binding); if (xctx) st_finish(xctx->Context); } @@ -700,7 +665,7 @@ xlib_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, static EGLBoolean -xlib_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, +xlib_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer) { struct xlib_egl_surface *xsurf = lookup_surface(surface); @@ -722,7 +687,7 @@ xlib_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, static EGLBoolean -xlib_eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) +xlib_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw) { /* error checking step: */ if (!_eglSwapBuffers(drv, dpy, draw)) @@ -831,4 +796,3 @@ _eglMain(_EGLDisplay *dpy, const char *args) return &xdrv->Base; } - -- cgit v1.2.3 From 0eaa02c836821556c1e8d0141f49f57e23f2548d Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 13 Aug 2009 13:01:48 +0800 Subject: egl: Change the way drivers are loaded. Driver is chosen and preloaded when eglGetDisplay is called. Later when eglInitialize is called, the same driver is matched to initialize the display. Also, add new, but unused, hooks to EGLDriver to allow a driver to probe a display or unload itself. Signed-off-by: Chia-I Wu --- src/egl/main/eglapi.c | 2 +- src/egl/main/egldisplay.c | 7 +- src/egl/main/egldisplay.h | 1 - src/egl/main/egldriver.c | 269 +++++++++++++++++++++++++++++++--------------- src/egl/main/egldriver.h | 15 ++- src/egl/main/eglglobals.c | 8 +- 6 files changed, 199 insertions(+), 103 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index e8a5b18912..464da00fe2 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -77,7 +77,7 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) drv = disp->Driver; if (!drv) { - drv = _eglOpenDriver(disp, disp->DriverName, disp->DriverArgs); + drv = _eglOpenDriver(disp); if (!drv) return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__); diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index c684e4291e..ba7e634c9d 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -94,7 +94,7 @@ _eglNewDisplay(NativeDisplayType nativeDisplay) _eglInitDisplay(); dpy->SurfaceHash = _eglSurfaceHash; - dpy->DriverName = _eglChooseDriver(dpy); + dpy->DriverName = _eglPreloadDriver(dpy); if (!dpy->DriverName) { free(dpy); return NULL; @@ -244,11 +244,6 @@ _eglCleanupDisplay(_EGLDisplay *disp) disp->Configs = NULL; /* XXX incomplete */ - - free((void *) disp->DriverName); - disp->DriverName = NULL; - - /* driver deletes the _EGLDisplay object */ } diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 1ebc0fcb59..78fbf5b840 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -15,7 +15,6 @@ struct _egl_display EGLDisplay Handle; const char *DriverName; - const char *DriverArgs; _EGLDriver *Driver; EGLint NumScreens; diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index a8ac7b3233..36cc2948c0 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -114,11 +114,12 @@ _eglChooseDRMDriver(int card) #endif } + /** * XXX this function is totally subject change!!! * * - * Determine/return the name of the driver to use for the given _EGLDisplay. + * Determine/return the path of the driver to use for the given native display. * * Try to be clever and determine if nativeDisplay is an Xlib Display * ptr or a string (naming a driver or screen number, etc). @@ -128,89 +129,69 @@ _eglChooseDRMDriver(int card) * Else if the first character is '!' we interpret it as specific driver name * (i.e. "!r200" or "!i830". * - * Whatever follows ':' is copied and put into dpy->DriverArgs. + * Whatever follows ':' is interpreted as arguments. * - * The caller may free() the returned string. + * The caller may free() the returned strings. */ -const char * -_eglChooseDriver(_EGLDisplay *dpy) +static char * +_eglChooseDriver(_EGLDisplay *dpy, char **argsRet) { - /* Under Windows, the NativeDisplay is an HDC handle, therefore */ - /* it can't be interpreted as a string or a pointer. */ -#if defined(_EGL_PLATFORM_WINDOWS) - const char *displayString = NULL; -#else - const char *displayString = (const char *) dpy->NativeDisplay; -#endif - const char *driverName = NULL; + char *path = NULL; + const char *args = NULL; - (void) DefaultDriverName; + path = getenv("EGL_DRIVER"); + if (path) + path = _eglstrdup(path); #if defined(_EGL_PLATFORM_X) - /* First, if the EGL_DRIVER env var is set, use that */ - driverName = getenv("EGL_DRIVER"); - if (driverName) - return _eglstrdup(driverName); -#endif + (void) DefaultDriverName; -#if 0 - if (!displayString) { - /* choose a default */ - displayString = DefaultDriverName; - } -#endif - /* extract default DriverArgs = whatever follows ':' */ - if (displayString && - (displayString[0] == '!' || - displayString[0] == ':')) { - const char *args = strchr(displayString, ':'); - if (args) - dpy->DriverArgs = _eglstrdup(args + 1); - } + if (!path && dpy->NativeDisplay) { + const char *dpyString = (const char *) dpy->NativeDisplay; + char *p; + /* parse the display string */ + if (dpyString[0] == '!' || dpyString[0] == ':') { + if (dpyString[0] == '!') { + path = _eglstrdup(dpyString); + p = strchr(path, ':'); + if (p) + *p++ = '\0'; + } else { + p = strchr(dpyString, ':'); + if (p) + p++; + } - /* determine driver name now */ - if (displayString && displayString[0] == ':' && - (displayString[1] >= '0' && displayString[1] <= '9') && - !displayString[2]) { - int card = atoi(displayString + 1); - driverName = _eglChooseDRMDriver(card); - } - else if (displayString && displayString[0] == '!') { - /* use user-specified driver name */ - driverName = _eglstrdup(displayString + 1); - /* truncate driverName at ':' if present */ - { - char *args = strchr(driverName, ':'); - if (args) { - *args = 0; + if (p) { + if (!path && p[0] >= '0' && p[0] <= '9' && !p[1]) { + int card = atoi(p); + path = (char *) _eglChooseDRMDriver(card); + } + args = p; } } + else { + path = (char *) _xeglChooseDriver(dpy); + } } - else - { - /* NativeDisplay is not a string! */ -#if defined(_EGL_PLATFORM_X) - driverName = _xeglChooseDriver(dpy); -#else - driverName = DefaultDriverName; -#endif - } +#elif defined(_EGL_PLATFORM_WINDOWS) + if (!path) + path = _eglstrdup(DefaultDriverName); +#endif /* _EGL_PLATFORM_X */ - return driverName; + if (path && argsRet) + *argsRet = (args) ? _eglstrdup(args) : NULL; + + return path; } /** - * Open/load the named driver and call its bootstrap function: _eglMain(). - * By the time this function is called, the dpy->DriverName should have - * been determined. - * - * \return new _EGLDriver object. + * Open the named driver and find its bootstrap function: _eglMain(). */ -_EGLDriver * -_eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args) +static _EGLMain_t +_eglOpenLibrary(const char *driverName, lib_handle *handle) { - _EGLDriver *drv; _EGLMain_t mainFunc; lib_handle lib; char driverFilename[1000]; @@ -249,58 +230,170 @@ _eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args) if (!mainFunc) { _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverFilename); - close_library(lib); + if (lib) + close_library(lib); return NULL; } + *handle = lib; + return mainFunc; +} + + +/** + * Load the named driver. The path and args passed will be + * owned by the driver and freed. + */ +static _EGLDriver * +_eglLoadDriver(_EGLDisplay *dpy, char *path, char *args) +{ + _EGLMain_t mainFunc; + lib_handle lib; + _EGLDriver *drv = NULL; + + mainFunc = _eglOpenLibrary(path, &lib); + if (!mainFunc) + return NULL; + drv = mainFunc(dpy, args); if (!drv) { - close_library(lib); + if (lib) + close_library(lib); return NULL; } - /* with a recurvise open you want the inner most handle */ - if (!drv->LibHandle) { - drv->LibHandle = lib; + if (!drv->Name) { + _eglLog(_EGL_WARNING, "Driver loaded from %s has no name", path); + drv->Name = "UNNAMED"; } - else { - close_library(lib); + + drv->Path = path; + drv->Args = args; + drv->LibHandle = lib; + + return drv; +} + + +/** + * Match a display to a preloaded driver. + */ +static _EGLDriver * +_eglMatchDriver(_EGLDisplay *dpy) +{ + _EGLDriver *defaultDriver = NULL; + EGLint i; + + for (i = 0; i < _eglGlobal.NumDrivers; i++) { + _EGLDriver *drv = _eglGlobal.Drivers[i]; + + /* display specifies a driver */ + if (dpy->DriverName) { + if (strcmp(dpy->DriverName, drv->Name) == 0) + return drv; + } + else if (drv->Probe) { + if (drv->Probe(drv, dpy)) + return drv; + } + else { + if (!defaultDriver) + defaultDriver = drv; + } } + return defaultDriver; +} + + +/** + * Load a driver and save it. + */ +const char * +_eglPreloadDriver(_EGLDisplay *dpy) +{ + char *path, *args; + _EGLDriver *drv; + EGLint i; + + path = _eglChooseDriver(dpy, &args); + if (!path) + return NULL; + + for (i = 0; i < _eglGlobal.NumDrivers; i++) { + drv = _eglGlobal.Drivers[i]; + if (strcmp(drv->Path, path) == 0) { + _eglLog(_EGL_DEBUG, "Driver %s is already preloaded", + drv->Name); + free(path); + if (args) + free(args); + return drv->Name; + } + } + + drv = _eglLoadDriver(dpy, path, args); + if (!drv) + return NULL; + /* update the global notion of supported APIs */ _eglGlobal.ClientAPIsMask |= drv->ClientAPIsMask; - _eglSaveDriver(drv); + _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv; + return drv->Name; +} + + +/** + * Open a preloaded driver. + */ +_EGLDriver * +_eglOpenDriver(_EGLDisplay *dpy) +{ + _EGLDriver *drv = _eglMatchDriver(dpy); return drv; } +/** + * Close a preloaded driver. + */ EGLBoolean _eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy) { - void *handle = drv->LibHandle; - EGLBoolean b; - - _eglLog(_EGL_DEBUG, "Closing %s", drv->Name); - _eglReleaseDisplayResources(drv, dpy); - - b = drv->API.Terminate(drv, dpy); - - close_library(handle); - - return b; + drv->API.Terminate(drv, dpy); + return EGL_TRUE; } /** - * Save the given driver pointer in the list of all known drivers. + * Unload preloaded drivers. */ void -_eglSaveDriver(_EGLDriver *drv) +_eglUnloadDrivers(void) { - _eglGlobal.Drivers[ _eglGlobal.NumDrivers++ ] = drv; + EGLint i; + for (i = 0; i < _eglGlobal.NumDrivers; i++) { + _EGLDriver *drv = _eglGlobal.Drivers[i]; + lib_handle handle = drv->LibHandle; + + if (drv->Path) + free((char *) drv->Path); + if (drv->Args) + free((char *) drv->Args); + + /* destroy driver */ + if (drv->Unload) + drv->Unload(drv); + + if (handle) + close_library(handle); + _eglGlobal.Drivers[i] = NULL; + } + + _eglGlobal.NumDrivers = 0; } diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index d97a24db1d..430c0949d4 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -27,8 +27,14 @@ struct _egl_driver EGLBoolean Initialized; /**< set by driver after initialized */ void *LibHandle; /**< dlopen handle */ + const char *Path; /**< path to this driver */ + const char *Args; /**< args to load this driver */ const char *Name; /**< name of this driver */ + /**< probe a display to see if it is supported */ + EGLBoolean (*Probe)(_EGLDriver *drv, _EGLDisplay *dpy); + /**< called before dlclose to release this driver */ + void (*Unload)(_EGLDriver *drv); int APImajor, APIminor; /**< as returned by eglInitialize() */ char Version[1000]; /**< initialized from APImajor/minor, Name */ @@ -50,20 +56,21 @@ extern _EGLDriver *_eglMain(_EGLDisplay *dpy, const char *args); extern const char * _eglChooseDRMDriver(int card); + extern const char * -_eglChooseDriver(_EGLDisplay *dpy); +_eglPreloadDriver(_EGLDisplay *dpy); extern _EGLDriver * -_eglOpenDriver(_EGLDisplay *dpy, const char *driverName, const char *args); +_eglOpenDriver(_EGLDisplay *dpy); extern EGLBoolean _eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy); -extern void -_eglSaveDriver(_EGLDriver *drv); +void +_eglUnloadDrivers(void); extern _EGLDriver * diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c index e93b48e03b..a532f142b7 100644 --- a/src/egl/main/eglglobals.c +++ b/src/egl/main/eglglobals.c @@ -1,7 +1,7 @@ #include #include #include "eglglobals.h" -#include "egldisplay.h" +#include "egldriver.h" #include "egllog.h" #include "eglmutex.h" @@ -18,8 +18,10 @@ struct _egl_global _eglGlobal = { 0x0 }, /* ClientAPIs */ 0, /* NumDrivers */ { NULL }, /* Drivers */ - 0, /* NumAtExitCalls */ - { NULL }, /* AtExitCalls */ + 1, /* NumAtExitCalls */ + { /* AtExitCalls */ + _eglUnloadDrivers + }, }; -- cgit v1.2.3 From ccc2b0bc65b02d4582d52d133290c8cb046bce8f Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 13 Aug 2009 13:39:51 +0800 Subject: egl: _eglCloseDriver should be no-op. Move drv->API.Terminate call to eglTerminate. Remove _eglReleaseDisplayResource as drivers are doing it. Signed-off-by: Chia-I Wu --- src/egl/main/eglapi.c | 2 +- src/egl/main/egldisplay.c | 11 ++++++----- src/egl/main/egldriver.c | 2 -- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index a23b57120c..29617b7aff 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -122,7 +122,7 @@ eglTerminate(EGLDisplay dpy) drv = disp->Driver; if (drv) { - /* TODO drv->API.Terminate should be called here */ + drv->API.Terminate(drv, disp); _eglCloseDriver(drv, disp); disp->Driver = NULL; } diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index ba7e634c9d..0693f258de 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -40,7 +40,6 @@ _eglFiniDisplay(void) if (dpy->ContextList || dpy->SurfaceList) _eglLog(_EGL_DEBUG, "Display %u is destroyed with resources", key); - _eglCleanupDisplay(dpy); free(dpy); key = _eglHashNextEntry(_eglDisplayHash, key); @@ -237,11 +236,13 @@ _eglCleanupDisplay(_EGLDisplay *disp) { EGLint i; - for (i = 0; i < disp->NumConfigs; i++) { - free(disp->Configs[i]); + if (disp->Configs) { + for (i = 0; i < disp->NumConfigs; i++) + free(disp->Configs[i]); + free(disp->Configs); + disp->Configs = NULL; + disp->NumConfigs = 0; } - free(disp->Configs); - disp->Configs = NULL; /* XXX incomplete */ } diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 0e6b294385..a252a9aabb 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -359,8 +359,6 @@ _eglOpenDriver(_EGLDisplay *dpy) EGLBoolean _eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy) { - _eglReleaseDisplayResources(drv, dpy); - drv->API.Terminate(drv, dpy); return EGL_TRUE; } -- cgit v1.2.3 From 7a9f52800932c02f5b425158b4978d0c1d2f4fd3 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Aug 2009 17:29:23 +0800 Subject: 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 --- 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(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 0693f258de..7f2d035c66 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 e1cbbac837..dfc54f17cb 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 cfae6970f2..f6d44b5922 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; -- cgit v1.2.3 From 38feefdc4eb4a3c7530b9cddea4c55e9ef39aec8 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Aug 2009 17:47:00 +0800 Subject: 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 --- 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(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 7f2d035c66..000db6c69a 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 dfc54f17cb..19a4d4e542 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 }; +extern void +_eglFiniDisplay(void); + + extern _EGLDisplay * _eglNewDisplay(NativeDisplayType displayName); diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c index 8c14f9c4bf..3ae4c1ad3a 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 d00d12afd8..58511076d4 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) */ -- cgit v1.2.3 From e3734e46850c3cf9a80df32bacae92593a416c14 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Aug 2009 18:05:19 +0800 Subject: 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 --- progs/egl/demo3.c | 2 +- src/egl/main/egldisplay.c | 66 --------------------------- src/egl/main/egldisplay.h | 112 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 79 insertions(+), 101 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c index a6096a257e..daab62d173 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 000db6c69a..7f1c53abf8 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -113,28 +113,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. @@ -256,28 +234,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 19a4d4e542..e8a3d49d96 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); +} /** -- cgit v1.2.3 From e484a929289e859d9f8ef8028af3b0d8dc77b6d6 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Aug 2009 18:02:38 +0800 Subject: 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 --- src/egl/main/egldisplay.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ src/egl/main/egldisplay.h | 52 +++++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 2 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 7f1c53abf8..d79d7e3913 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -275,3 +275,69 @@ _eglUnlinkSurface(_EGLSurface *surf) surf->Next = NULL; surf->Display = NULL; } + + +#ifndef _EGL_SKIP_HANDLE_CHECK + + +/** + * Return EGL_TRUE if the given handle is a valid handle to a display. + */ +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); +} + + +/** + * Return EGL_TRUE if the given handle is a valid handle to a context. + */ +EGLBoolean +_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) +{ + _EGLContext *cur; + + cur = dpy->ContextList; + while (cur) { + if (cur == (_EGLContext *) ctx) { + assert(cur->Display == dpy); + break; + } + cur = cur->Next; + } + return (cur != NULL); +} + + +/** + * Return EGL_TRUE if the given handle is a valid handle to a surface. + */ +EGLBoolean +_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy) +{ + _EGLSurface *cur; + + cur = dpy->SurfaceList; + while (cur) { + if (cur == (_EGLSurface *) surf) { + assert(cur->Display == dpy); + break; + } + cur = cur->Next; + } + return (cur != NULL); +} + + +#endif /* !_EGL_SKIP_HANDLE_CHECK */ diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index e8a3d49d96..6394c9cedb 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -105,6 +105,48 @@ extern void _eglUnlinkSurface(_EGLSurface *surf); +#ifndef _EGL_SKIP_HANDLE_CHECK + + +extern EGLBoolean +_eglCheckDisplayHandle(EGLDisplay dpy); + + +extern EGLBoolean +_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy); + + +extern EGLBoolean +_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy); + + +#else /* !_EGL_SKIP_HANDLE_CHECK */ + +/* Only do a quick check. This is NOT standard compliant. */ + +static INLINE EGLBoolean +_eglCheckDisplayHandle(EGLDisplay dpy) { return EGL_TRUE; } + + +static INLINE EGLBoolean +_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) +{ + _EGLContext *c = (_EGLContext *) ctx; + return (c && c->Display == dpy); +} + + +static INLINE EGLBoolean +_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy) +{ + _EGLSurface *s = (_EGLSurface *) surf; + return (s && s->Display == dpy); +} + + +#endif /* _EGL_SKIP_HANDLE_CHECK */ + + /** * Lookup a handle to find the linked display. * Return NULL if the handle has no corresponding linked display. @@ -113,6 +155,8 @@ static INLINE _EGLDisplay * _eglLookupDisplay(EGLDisplay display) { _EGLDisplay *dpy = (_EGLDisplay *) display; + if (!_eglCheckDisplayHandle(display)) + dpy = NULL; return dpy; } @@ -145,7 +189,9 @@ static INLINE _EGLContext * _eglLookupContext(EGLContext context, _EGLDisplay *dpy) { _EGLContext *ctx = (_EGLContext *) context; - return (ctx && ctx->Display) ? ctx : NULL; + if (!_eglCheckContextHandle(context, dpy)) + ctx = NULL; + return ctx; } @@ -177,7 +223,9 @@ static INLINE _EGLSurface * _eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy) { _EGLSurface *surf = (_EGLSurface *) surface; - return (surf && surf->Display) ? surf : NULL; + if (!_eglCheckSurfaceHandle(surf, dpy)) + surf = NULL; + return surf; } -- cgit v1.2.3 From 34d8c13bff05de200dbad70d0798519108e186f2 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Aug 2009 18:26:26 +0800 Subject: egl: Remove eglhash.c and eglhash.h. Signed-off-by: Chia-I Wu --- 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, 391 deletions(-) delete mode 100644 src/egl/main/eglhash.c delete mode 100644 src/egl/main/eglhash.h (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index 9d80bc1a84..3c8f8b6a68 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 ab61d68f2b..15cd1d09c7 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 d79d7e3913..30a49a25ae 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 8e3da2e906..0000000000 --- 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 -#include -#include -#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 1d6db9598c..0000000000 --- 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 adf125f88a..e7a1a8329e 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" -- cgit v1.2.3 From 408db29792a2d57409f2604974e4398a3545a38f Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 19 Aug 2009 13:00:25 +0800 Subject: egl: Check for null display in handle checking. The display may be NULL when checking a handle. Signed-off-by: Chia-I Wu --- src/egl/main/egldisplay.c | 10 ++++++---- src/egl/main/egldisplay.h | 9 ++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 30a49a25ae..9b4227f545 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -305,9 +305,10 @@ _eglCheckDisplayHandle(EGLDisplay dpy) EGLBoolean _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) { - _EGLContext *cur; + _EGLContext *cur = NULL; - cur = dpy->ContextList; + if (dpy) + cur = dpy->ContextList; while (cur) { if (cur == (_EGLContext *) ctx) { assert(cur->Display == dpy); @@ -325,9 +326,10 @@ _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) EGLBoolean _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy) { - _EGLSurface *cur; + _EGLSurface *cur = NULL; - cur = dpy->SurfaceList; + if (dpy) + cur = dpy->SurfaceList; while (cur) { if (cur == (_EGLSurface *) surf) { assert(cur->Display == dpy); diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 6394c9cedb..20651e51ff 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -125,14 +125,17 @@ _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy); /* Only do a quick check. This is NOT standard compliant. */ static INLINE EGLBoolean -_eglCheckDisplayHandle(EGLDisplay dpy) { return EGL_TRUE; } +_eglCheckDisplayHandle(EGLDisplay dpy) +{ + return ((_EGLDisplay *) dpy != NULL); +} static INLINE EGLBoolean _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy) { _EGLContext *c = (_EGLContext *) ctx; - return (c && c->Display == dpy); + return (dpy && c && c->Display == dpy); } @@ -140,7 +143,7 @@ static INLINE EGLBoolean _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy) { _EGLSurface *s = (_EGLSurface *) surf; - return (s && s->Display == dpy); + return (dpy && s && s->Display == dpy); } -- cgit v1.2.3 From 5a459d58fca2b71cb77c39f98df8a81ce6298421 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 21 Aug 2009 13:53:36 +0800 Subject: egl: Remove dependency on libX11. libX11 is used to determine the screen number, which is in turned used to determine the DRI driver. However, the sysfs interface for determining the DRI driver is gone, and no working driver depends on this mechanism. Display string parsing is moved to a new function, _eglSplitDisplayString. Signed-off-by: Chia-I Wu --- configs/default | 2 +- src/egl/main/Makefile | 6 +-- src/egl/main/egldisplay.c | 30 ++++++++++++++ src/egl/main/egldisplay.h | 4 ++ src/egl/main/egldriver.c | 91 ++++------------------------------------- src/egl/main/egldriver.h | 4 -- src/egl/main/eglx.c | 100 ---------------------------------------------- src/egl/main/eglx.h | 12 ------ 8 files changed, 44 insertions(+), 205 deletions(-) delete mode 100644 src/egl/main/eglx.c delete mode 100644 src/egl/main/eglx.h (limited to 'src/egl/main/egldisplay.c') diff --git a/configs/default b/configs/default index 60638d739d..127b98e76c 100644 --- a/configs/default +++ b/configs/default @@ -105,7 +105,7 @@ GALLIUM_STATE_TRACKERS_DIRS = glx # Library dependencies #EXTRA_LIB_PATH ?= GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread -EGL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -ldl -lpthread +EGL_LIB_DEPS = $(EXTRA_LIB_PATH) -ldl -lpthread OSMESA_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) GLU_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm GLUT_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXi -lm diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index 15cd1d09c7..c951b070f1 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -22,8 +22,7 @@ HEADERS = \ eglmutex.h \ eglscreen.h \ eglstring.h \ - eglsurface.h \ - eglx.h + eglsurface.h SOURCES = \ eglapi.c \ @@ -39,8 +38,7 @@ SOURCES = \ eglmode.c \ eglscreen.c \ eglstring.c \ - eglsurface.c \ - eglx.c + eglsurface.c OBJECTS = $(SOURCES:.c=.o) diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 9b4227f545..2c271efd67 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -39,6 +39,36 @@ _eglFiniDisplay(void) } +/** + * If the first character is '!' we interpret it as specific driver name + * (i.e. "!r200" or "!i830"). Whatever follows ':' is interpreted as + * arguments. + * + * The caller may free() the returned driver name. + */ +char * +_eglSplitDisplayString(const char *dpyString, const char **args) +{ + char *drv, *p; + + if (!dpyString || dpyString[0] != '!') + return NULL; + drv = _eglstrdup(dpyString + 1); + if (!drv) + return NULL; + + p = strchr(dpyString, ':'); + if (p) { + drv[p - dpyString] = '\0'; + p++; + } + if (args) + *args = p; + + return drv; +} + + /** * Allocate a new _EGLDisplay object for the given nativeDisplay handle. * We'll also try to determine the device driver name at this time. diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 20651e51ff..c7a41cd588 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -65,6 +65,10 @@ extern void _eglFiniDisplay(void); +extern char * +_eglSplitDisplayString(const char *dpyString, const char **args); + + extern _EGLDisplay * _eglNewDisplay(NativeDisplayType displayName); diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index a252a9aabb..06e10f6189 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -22,7 +22,6 @@ #if defined(_EGL_PLATFORM_X) #include -#include "eglx.h" #elif defined(_EGL_PLATFORM_WINDOWS) /* Use static linking on Windows for now */ #define WINDOWS_STATIC_LINK @@ -38,7 +37,6 @@ /* XXX Need to decide how to do dynamic name lookup on Windows */ static const char *DefaultDriverName = "TBD"; #endif - static const char *SysFS = NULL; typedef HMODULE lib_handle; static HMODULE @@ -61,8 +59,7 @@ } #elif defined(_EGL_PLATFORM_X) - static const char *DefaultDriverName = ":0"; - static const char *SysFS = "/sys/class"; + static const char *DefaultDriverName = "egl_softpipe"; typedef void * lib_handle; @@ -80,57 +77,9 @@ #endif -/** - * Given a card number, use sysfs to determine the DRI driver name. - */ -const char * -_eglChooseDRMDriver(int card) -{ -#if 0 - return _eglstrdup("libEGLdri"); -#else - char path[2000], driverName[2000]; - FILE *f; - int length; - - snprintf(path, sizeof(path), "%s/drm/card%d/dri_library_name", SysFS, card); - - f = fopen(path, "r"); - if (!f) - return NULL; - - fgets(driverName, sizeof(driverName), f); - fclose(f); - - if ((length = strlen(driverName)) > 1) { - /* remove the trailing newline from sysfs */ - driverName[length - 1] = '\0'; - strncat(driverName, "_dri", sizeof(driverName)); - return _eglstrdup(driverName); - } - else { - return NULL; - } -#endif -} - /** - * XXX this function is totally subject change!!! - * - * - * Determine/return the path of the driver to use for the given native display. - * - * Try to be clever and determine if nativeDisplay is an Xlib Display - * ptr or a string (naming a driver or screen number, etc). - * - * If the first character is ':' we interpret it as a screen or card index - * number (i.e. ":0" or ":1", etc) - * Else if the first character is '!' we interpret it as specific driver name - * (i.e. "!r200" or "!i830". - * - * Whatever follows ':' is interpreted as arguments. - * + * Choose a driver for a given display. * The caller may free() the returned strings. */ static char * @@ -144,42 +93,16 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet) path = _eglstrdup(path); #if defined(_EGL_PLATFORM_X) - (void) DefaultDriverName; - if (!path && dpy->NativeDisplay) { - const char *dpyString = (const char *) dpy->NativeDisplay; - char *p; - /* parse the display string */ - if (dpyString[0] == '!' || dpyString[0] == ':') { - if (dpyString[0] == '!') { - path = _eglstrdup(dpyString); - p = strchr(path, ':'); - if (p) - *p++ = '\0'; - } else { - p = strchr(dpyString, ':'); - if (p) - p++; - } - - if (p) { - if (!path && p[0] >= '0' && p[0] <= '9' && !p[1]) { - int card = atoi(p); - path = (char *) _eglChooseDRMDriver(card); - } - args = p; - } - } - else { - path = (char *) _xeglChooseDriver(dpy); - } + /* assume (wrongly!) that the native display is a display string */ + path = _eglSplitDisplayString((const char *) dpy->NativeDisplay, &args); } -#elif defined(_EGL_PLATFORM_WINDOWS) +#endif /* _EGL_PLATFORM_X */ + if (!path) path = _eglstrdup(DefaultDriverName); -#endif /* _EGL_PLATFORM_X */ - if (path && argsRet) + if (argsRet) *argsRet = (args) ? _eglstrdup(args) : NULL; return path; diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 7fba938085..6c848eb35e 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -28,10 +28,6 @@ struct _egl_driver extern _EGLDriver *_eglMain(const char *args); -extern const char * -_eglChooseDRMDriver(int card); - - extern const char * _eglPreloadDriver(_EGLDisplay *dpy); diff --git a/src/egl/main/eglx.c b/src/egl/main/eglx.c deleted file mode 100644 index 50acc3a24f..0000000000 --- a/src/egl/main/eglx.c +++ /dev/null @@ -1,100 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -/** - * X-specific EGL code. - * - * Any glue code needed to make EGL work with X is placed in this file. - */ - - -#include -#include -#include -#include - -#include "egldriver.h" -#include "egllog.h" -#include "eglstring.h" -#include "eglx.h" - - -static const char *DefaultGLXDriver = "egl_glx"; -static const char *DefaultSoftDriver = "egl_softpipe"; - - -/** - * Given an X Display ptr (at dpy->Xdpy) try to determine the appropriate - * device driver. Return its name. - * - * This boils down to whether to use the egl_glx.so driver which will - * load a DRI driver or the egl_softpipe.so driver that'll do software - * rendering on Xlib. - */ -const char * -_xeglChooseDriver(_EGLDisplay *dpy) -{ -#ifdef _EGL_PLATFORM_X - _XPrivDisplay xdpy; - int screen; - const char *driverName; - - assert(dpy); - - if (!dpy->Xdpy) { - dpy->Xdpy = XOpenDisplay(NULL); - if (!dpy->Xdpy) { - /* can't open X display -> can't use X-based driver */ - return NULL; - } - } - xdpy = (_XPrivDisplay) dpy->Xdpy; - - assert(dpy->Xdpy); - - screen = DefaultScreen(dpy->Xdpy); - - /* See if we can choose a DRI/DRM driver */ - driverName = _eglChooseDRMDriver(screen); - if (driverName) { - free((void *) driverName); - driverName = _eglstrdup(DefaultGLXDriver); - } - else { - driverName = _eglstrdup(DefaultSoftDriver); - } - - _eglLog(_EGL_DEBUG, "_xeglChooseDriver: %s", driverName); - - return driverName; -#else - return NULL; -#endif -} - - diff --git a/src/egl/main/eglx.h b/src/egl/main/eglx.h deleted file mode 100644 index 4323d55838..0000000000 --- a/src/egl/main/eglx.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef EGLX_INCLUDED -#define EGLX_INCLUDED - - -#include "egldisplay.h" - - -extern const char * -_xeglChooseDriver(_EGLDisplay *dpy); - - -#endif /* EGLX_INCLUDED */ -- cgit v1.2.3 From e1d978775f982a450bd84588a4f9567d6bbccebd Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 26 Aug 2009 16:06:39 +0800 Subject: egl: Remove Xdpy from EGLDisplay. It is not used anymore. Signed-off-by: Chia-I Wu --- src/egl/main/egldisplay.c | 3 --- src/egl/main/egldisplay.h | 8 -------- 2 files changed, 11 deletions(-) (limited to 'src/egl/main/egldisplay.c') diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 2c271efd67..896d60dbe1 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -81,9 +81,6 @@ _eglNewDisplay(NativeDisplayType nativeDisplay) _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); if (dpy) { dpy->NativeDisplay = nativeDisplay; -#if defined(_EGL_PLATFORM_X) - dpy->Xdpy = (Display *) nativeDisplay; -#endif dpy->DriverName = _eglPreloadDriver(dpy); if (!dpy->DriverName) { diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index c7a41cd588..6575fdf198 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -1,10 +1,6 @@ #ifndef EGLDISPLAY_INCLUDED #define EGLDISPLAY_INCLUDED -#ifdef _EGL_PLATFORM_X -#include -#endif - #include "egltypedefs.h" #include "egldefines.h" #include "eglcontext.h" @@ -54,10 +50,6 @@ struct _egl_display /* lists of linked contexts and surface */ _EGLContext *ContextList; _EGLSurface *SurfaceList; - -#ifdef _EGL_PLATFORM_X - Display *Xdpy; -#endif }; -- cgit v1.2.3