2008-05-27 23:48:23 +01:00
|
|
|
/**
|
|
|
|
* Functions related to EGLDisplay.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2005-04-22 22:09:39 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "eglcontext.h"
|
2009-07-17 18:48:27 +01:00
|
|
|
#include "eglsurface.h"
|
2005-04-22 22:09:39 +01:00
|
|
|
#include "egldisplay.h"
|
2008-05-27 23:48:23 +01:00
|
|
|
#include "egldriver.h"
|
2005-04-22 22:09:39 +01:00
|
|
|
#include "eglglobals.h"
|
2008-05-28 19:56:36 +01:00
|
|
|
#include "eglstring.h"
|
2009-08-10 07:16:32 +01:00
|
|
|
#include "eglmutex.h"
|
2009-08-10 08:13:42 +01:00
|
|
|
#include "egllog.h"
|
2009-08-10 07:16:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finish display management.
|
|
|
|
*/
|
2009-08-14 10:47:00 +01:00
|
|
|
void
|
2009-08-10 07:16:32 +01:00
|
|
|
_eglFiniDisplay(void)
|
|
|
|
{
|
2009-08-14 10:47:00 +01:00
|
|
|
_EGLDisplay *dpyList, *dpy;
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
/* atexit function is called with global mutex locked */
|
|
|
|
dpyList = _eglGlobal.DisplayList;
|
|
|
|
while (dpyList) {
|
|
|
|
/* pop list head */
|
|
|
|
dpy = dpyList;
|
|
|
|
dpyList = dpyList->Next;
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
if (dpy->ContextList || dpy->SurfaceList)
|
|
|
|
_eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy);
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
free(dpy);
|
2009-08-10 07:16:32 +01:00
|
|
|
}
|
2009-08-14 10:47:00 +01:00
|
|
|
_eglGlobal.DisplayList = NULL;
|
2009-08-10 07:16:32 +01:00
|
|
|
}
|
2005-04-22 22:09:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-05-27 23:48:23 +01:00
|
|
|
* Allocate a new _EGLDisplay object for the given nativeDisplay handle.
|
|
|
|
* We'll also try to determine the device driver name at this time.
|
2008-05-28 19:56:36 +01:00
|
|
|
*
|
|
|
|
* Note that nativeDisplay may be an X Display ptr, or a string.
|
2005-04-22 22:09:39 +01:00
|
|
|
*/
|
|
|
|
_EGLDisplay *
|
2008-05-27 23:48:23 +01:00
|
|
|
_eglNewDisplay(NativeDisplayType nativeDisplay)
|
2005-04-22 22:09:39 +01:00
|
|
|
{
|
2005-12-23 08:17:44 +00:00
|
|
|
_EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
|
2005-04-22 22:09:39 +01:00
|
|
|
if (dpy) {
|
2008-05-27 23:48:23 +01:00
|
|
|
dpy->NativeDisplay = nativeDisplay;
|
2005-04-22 22:09:39 +01:00
|
|
|
}
|
|
|
|
return dpy;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-27 21:33:54 +01:00
|
|
|
/**
|
2009-07-17 18:48:27 +01:00
|
|
|
* Link a display to itself and return the handle of the link.
|
|
|
|
* The handle can be passed to client directly.
|
|
|
|
*/
|
|
|
|
EGLDisplay
|
|
|
|
_eglLinkDisplay(_EGLDisplay *dpy)
|
|
|
|
{
|
2009-08-14 10:47:00 +01:00
|
|
|
_eglLockMutex(_eglGlobal.Mutex);
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
dpy->Next = _eglGlobal.DisplayList;
|
|
|
|
_eglGlobal.DisplayList = dpy;
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
_eglUnlockMutex(_eglGlobal.Mutex);
|
2009-07-17 18:48:27 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
return (EGLDisplay) dpy;
|
2009-07-17 18:48:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlink a linked display from itself.
|
|
|
|
* Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_eglUnlinkDisplay(_EGLDisplay *dpy)
|
|
|
|
{
|
2009-08-14 10:47:00 +01:00
|
|
|
_EGLDisplay *prev;
|
|
|
|
|
|
|
|
_eglLockMutex(_eglGlobal.Mutex);
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
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;
|
|
|
|
}
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
_eglUnlockMutex(_eglGlobal.Mutex);
|
2009-07-17 18:48:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-17 05:21:56 +01:00
|
|
|
/**
|
|
|
|
* Find the display corresponding to the specified native display id in all
|
|
|
|
* linked displays.
|
|
|
|
*/
|
|
|
|
_EGLDisplay *
|
|
|
|
_eglFindDisplay(NativeDisplayType nativeDisplay)
|
|
|
|
{
|
2009-08-14 10:47:00 +01:00
|
|
|
_EGLDisplay *dpy;
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
_eglLockMutex(_eglGlobal.Mutex);
|
2009-07-17 05:21:56 +01:00
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
dpy = _eglGlobal.DisplayList;
|
|
|
|
while (dpy) {
|
|
|
|
if (dpy->NativeDisplay == nativeDisplay) {
|
|
|
|
_eglUnlockMutex(_eglGlobal.Mutex);
|
2009-07-17 05:21:56 +01:00
|
|
|
return dpy;
|
2009-08-14 10:47:00 +01:00
|
|
|
}
|
|
|
|
dpy = dpy->Next;
|
2009-07-17 05:21:56 +01:00
|
|
|
}
|
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
_eglUnlockMutex(_eglGlobal.Mutex);
|
|
|
|
|
2009-07-17 05:21:56 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-17 05:21:57 +01:00
|
|
|
/**
|
|
|
|
* Destroy the contexts and surfaces that are linked to the display.
|
|
|
|
*/
|
|
|
|
void
|
2009-08-11 10:09:39 +01:00
|
|
|
_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *display)
|
2009-07-17 05:21:57 +01:00
|
|
|
{
|
|
|
|
_EGLContext *contexts;
|
|
|
|
_EGLSurface *surfaces;
|
|
|
|
|
|
|
|
contexts = display->ContextList;
|
|
|
|
surfaces = display->SurfaceList;
|
|
|
|
|
|
|
|
while (contexts) {
|
2009-08-11 10:09:39 +01:00
|
|
|
_EGLContext *ctx = contexts;
|
2009-07-17 05:21:57 +01:00
|
|
|
contexts = contexts->Next;
|
2009-08-11 10:09:39 +01:00
|
|
|
|
|
|
|
_eglUnlinkContext(ctx);
|
|
|
|
drv->API.DestroyContext(drv, display, ctx);
|
2009-07-17 05:21:57 +01:00
|
|
|
}
|
|
|
|
assert(!display->ContextList);
|
|
|
|
|
|
|
|
while (surfaces) {
|
2009-08-11 10:09:39 +01:00
|
|
|
_EGLSurface *surf = surfaces;
|
2009-07-17 05:21:57 +01:00
|
|
|
surfaces = surfaces->Next;
|
2009-08-11 10:09:39 +01:00
|
|
|
|
|
|
|
_eglUnlinkSurface(surf);
|
|
|
|
drv->API.DestroySurface(drv, display, surf);
|
2009-07-17 05:21:57 +01:00
|
|
|
}
|
|
|
|
assert(!display->SurfaceList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-04 18:34:10 +01:00
|
|
|
/**
|
|
|
|
* Free all the data hanging of an _EGLDisplay object, but not
|
|
|
|
* the object itself.
|
|
|
|
*/
|
2005-04-22 22:09:39 +01:00
|
|
|
void
|
2005-05-13 19:31:35 +01:00
|
|
|
_eglCleanupDisplay(_EGLDisplay *disp)
|
2005-04-22 22:09:39 +01:00
|
|
|
{
|
2008-06-04 18:34:10 +01:00
|
|
|
EGLint i;
|
|
|
|
|
2009-08-13 06:39:51 +01:00
|
|
|
if (disp->Configs) {
|
|
|
|
for (i = 0; i < disp->NumConfigs; i++)
|
|
|
|
free(disp->Configs[i]);
|
|
|
|
free(disp->Configs);
|
|
|
|
disp->Configs = NULL;
|
|
|
|
disp->NumConfigs = 0;
|
2008-06-04 18:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX incomplete */
|
2005-04-22 22:09:39 +01:00
|
|
|
}
|
2009-07-17 18:48:27 +01:00
|
|
|
|
|
|
|
|
2009-08-14 11:02:38 +01:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !_EGL_SKIP_HANDLE_CHECK */
|