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) {
|
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
|
|
|
|
|
|
|
|
|
|
|
/**
|
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 *
|
2010-01-25 03:55:48 +00:00
|
|
|
_eglNewDisplay(EGLNativeDisplayType 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 *
|
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
|
|
|
|
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
|
|
|
{
|
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;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-14 11:02:38 +01:00
|
|
|
#endif /* !_EGL_SKIP_HANDLE_CHECK */
|
2010-01-24 12:30:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link a resource to a display.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy)
|
|
|
|
{
|
|
|
|
res->Display = dpy;
|
|
|
|
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;
|
|
|
|
res->Display = NULL;
|
|
|
|
}
|