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"
|
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) {
|
2010-01-24 12:32:34 +00:00
|
|
|
EGLint i;
|
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
/* pop list head */
|
|
|
|
dpy = dpyList;
|
|
|
|
dpyList = dpyList->Next;
|
2009-08-10 07:16:32 +01:00
|
|
|
|
2010-01-24 12:32:34 +00:00
|
|
|
for (i = 0; i < _EGL_NUM_RESOURCES; i++) {
|
|
|
|
if (dpy->ResourceLists[i]) {
|
|
|
|
_eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-02-17 10:39:27 +00:00
|
|
|
* Find the display corresponding to the specified native display, or create a
|
|
|
|
* new one.
|
2009-07-17 05:21:56 +01:00
|
|
|
*/
|
|
|
|
_EGLDisplay *
|
2010-01-25 03:55:48 +00:00
|
|
|
_eglFindDisplay(EGLNativeDisplayType nativeDisplay)
|
2009-07-17 05:21:56 +01:00
|
|
|
{
|
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
|
|
|
|
2010-02-17 10:39:27 +00:00
|
|
|
/* search the display list first */
|
2009-08-14 10:47:00 +01:00
|
|
|
dpy = _eglGlobal.DisplayList;
|
|
|
|
while (dpy) {
|
2010-02-17 10:39:27 +00:00
|
|
|
if (dpy->NativeDisplay == nativeDisplay)
|
|
|
|
break;
|
2009-08-14 10:47:00 +01:00
|
|
|
dpy = dpy->Next;
|
2009-07-17 05:21:56 +01:00
|
|
|
}
|
|
|
|
|
2010-02-17 10:39:27 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-14 10:47:00 +01:00
|
|
|
_eglUnlockMutex(_eglGlobal.Mutex);
|
|
|
|
|
2010-02-17 10:39:27 +00:00
|
|
|
return dpy;
|
2009-07-17 05:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-01-24 12:32:34 +00:00
|
|
|
_EGLResource *list;
|
2009-07-17 05:21:57 +01:00
|
|
|
|
2010-01-24 12:32:34 +00:00
|
|
|
list = display->ResourceLists[_EGL_RESOURCE_CONTEXT];
|
|
|
|
while (list) {
|
|
|
|
_EGLContext *ctx = (_EGLContext *) list;
|
|
|
|
list = list->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
|
|
|
}
|
2010-01-24 12:32:34 +00:00
|
|
|
assert(!display->ResourceLists[_EGL_RESOURCE_CONTEXT]);
|
2009-07-17 05:21:57 +01:00
|
|
|
|
2010-01-24 12:32:34 +00:00
|
|
|
list = display->ResourceLists[_EGL_RESOURCE_SURFACE];
|
|
|
|
while (list) {
|
|
|
|
_EGLSurface *surf = (_EGLSurface *) list;
|
|
|
|
list = list->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
|
|
|
}
|
2010-01-24 12:32:34 +00:00
|
|
|
assert(!display->ResourceLists[_EGL_RESOURCE_SURFACE]);
|
2009-07-17 05:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2010-01-26 10:34:29 +00:00
|
|
|
disp->MaxConfigs = 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
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-24 12:30:04 +00:00
|
|
|
/**
|
|
|
|
* Return EGL_TRUE if the given resource is valid. That is, the display does
|
|
|
|
* own the resource.
|
|
|
|
*/
|
|
|
|
EGLBoolean
|
2010-01-25 03:39:44 +00:00
|
|
|
_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy)
|
2010-01-24 12:30:04 +00:00
|
|
|
{
|
|
|
|
_EGLResource *list = dpy->ResourceLists[type];
|
|
|
|
|
2010-01-25 03:39:44 +00:00
|
|
|
if (!res)
|
|
|
|
return EGL_FALSE;
|
|
|
|
|
2010-01-24 12:30:04 +00:00
|
|
|
while (list) {
|
2010-01-25 03:39:44 +00:00
|
|
|
if (res == (void *) list) {
|
2010-01-24 12:30:04 +00:00
|
|
|
assert(list->Display == dpy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
list = list->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (list != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link a resource to a display.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy)
|
|
|
|
{
|
2010-01-26 07:16:49 +00:00
|
|
|
assert(!res->Display || res->Display == dpy);
|
|
|
|
|
2010-01-24 12:30:04 +00:00
|
|
|
res->Display = dpy;
|
2010-01-26 07:16:49 +00:00
|
|
|
res->IsLinked = EGL_TRUE;
|
2010-01-24 12:30:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->Next = NULL;
|
2010-01-26 07:16:49 +00:00
|
|
|
/* do not reset res->Display */
|
|
|
|
res->IsLinked = EGL_FALSE;
|
2010-01-24 12:30:04 +00:00
|
|
|
}
|