X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fegl%2Fmain%2Fegldisplay.c;h=5dc5fd9719a682e029be8a470d3efbe2e8a0e691;hb=1e6c10f4be9e36cc052a6b47fb2cb1eae60caa00;hp=47a2323eafb3923e508fdb9527dcc64c3983d243;hpb=58a82ee57f1e1e67387dd860ac253223db250789;p=mesa.git diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 47a2323eafb..5dc5fd9719a 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -1,4 +1,3 @@ - /** * Functions related to EGLDisplay. */ @@ -7,93 +6,109 @@ #include #include #include "eglcontext.h" +#include "eglsurface.h" #include "egldisplay.h" #include "egldriver.h" #include "eglglobals.h" -#include "eglhash.h" -#include "eglstring.h" +#include "eglmutex.h" +#include "egllog.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. + * Finish display management. */ -_EGLDisplay * -_eglNewDisplay(NativeDisplayType nativeDisplay) +void +_eglFiniDisplay(void) { - _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; -#endif - - dpy->DriverName = _eglChooseDriver(dpy); - if (!dpy->DriverName) { - free(dpy); - return NULL; + _EGLDisplay *dpyList, *dpy; + + /* atexit function is called with global mutex locked */ + dpyList = _eglGlobal.DisplayList; + while (dpyList) { + EGLint i; + + /* pop list head */ + dpy = dpyList; + dpyList = dpyList->Next; + + for (i = 0; i < _EGL_NUM_RESOURCES; i++) { + if (dpy->ResourceLists[i]) { + _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy); + break; + } } + + free(dpy); } - return dpy; + _eglGlobal.DisplayList = NULL; } /** - * Return the public handle for an internal _EGLDisplay. - * This is the inverse of _eglLookupDisplay(). + * Find the display corresponding to the specified native display, or create a + * new one. */ -EGLDisplay -_eglGetDisplayHandle(_EGLDisplay *display) +_EGLDisplay * +_eglFindDisplay(EGLNativeDisplayType nativeDisplay) { - if (display) - return display->Handle; - else - return EGL_NO_DISPLAY; + _EGLDisplay *dpy; + + _eglLockMutex(_eglGlobal.Mutex); + + /* search the display list first */ + dpy = _eglGlobal.DisplayList; + while (dpy) { + if (dpy->NativeDisplay == nativeDisplay) + break; + dpy = dpy->Next; + } + + /* create a new display */ + if (!dpy) { + dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); + if (dpy) { + _eglInitMutex(&dpy->Mutex); + dpy->NativeDisplay = nativeDisplay; + + /* add to the display list */ + dpy->Next = _eglGlobal.DisplayList; + _eglGlobal.DisplayList = dpy; + } + } + + _eglUnlockMutex(_eglGlobal.Mutex); + + return dpy; } - + /** - * Return the _EGLDisplay object that corresponds to the given public/ - * opaque display handle. - * This is the inverse of _eglGetDisplayHandle(). + * Destroy the contexts and surfaces that are linked to the display. */ -_EGLDisplay * -_eglLookupDisplay(EGLDisplay dpy) +void +_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *display) { - EGLuint key = (EGLuint) dpy; - if (!_eglGlobal.Displays) - return NULL; - return (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, key); -} + _EGLResource *list; + list = display->ResourceLists[_EGL_RESOURCE_CONTEXT]; + while (list) { + _EGLContext *ctx = (_EGLContext *) list; + list = list->Next; -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); -} + _eglUnlinkContext(ctx); + drv->API.DestroyContext(drv, display, ctx); + } + assert(!display->ResourceLists[_EGL_RESOURCE_CONTEXT]); + list = display->ResourceLists[_EGL_RESOURCE_SURFACE]; + while (list) { + _EGLSurface *surf = (_EGLSurface *) list; + list = list->Next; -_EGLDisplay * -_eglGetCurrentDisplay(void) -{ - _EGLContext *ctx = _eglGetCurrentContext(); - if (ctx) - return ctx->Display; - else - return NULL; + _eglUnlinkSurface(surf); + drv->API.DestroySurface(drv, display, surf); + } + assert(!display->ResourceLists[_EGL_RESOURCE_SURFACE]); } @@ -106,16 +121,101 @@ _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; + disp->MaxConfigs = 0; } - free(disp->Configs); - disp->Configs = NULL; /* XXX incomplete */ +} + + +/** + * 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 resource is valid. That is, the display does + * own the resource. + */ +EGLBoolean +_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy) +{ + _EGLResource *list = dpy->ResourceLists[type]; + + if (!res) + return EGL_FALSE; + + while (list) { + if (res == (void *) list) { + assert(list->Display == dpy); + break; + } + list = list->Next; + } + + return (list != NULL); +} + - free((void *) disp->DriverName); - disp->DriverName = NULL; +/** + * Link a resource to a display. + */ +void +_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy) +{ + assert(!res->Display || res->Display == dpy); + + res->Display = dpy; + res->IsLinked = EGL_TRUE; + res->Next = dpy->ResourceLists[type]; + dpy->ResourceLists[type] = res; +} + + +/** + * Unlink a linked resource from its display. + */ +void +_eglUnlinkResource(_EGLResource *res, _EGLResourceType type) +{ + _EGLResource *prev; + + prev = res->Display->ResourceLists[type]; + if (prev != res) { + while (prev) { + if (prev->Next == res) + break; + prev = prev->Next; + } + assert(prev); + prev->Next = res->Next; + } + else { + res->Display->ResourceLists[type] = res->Next; + } - /* driver deletes the _EGLDisplay object */ + res->Next = NULL; + /* do not reset res->Display */ + res->IsLinked = EGL_FALSE; }