2 * Functions related to EGLDisplay.
8 #include "eglcontext.h"
9 #include "eglsurface.h"
10 #include "egldisplay.h"
11 #include "egldriver.h"
12 #include "eglglobals.h"
13 #include "eglstring.h"
19 * Finish display management.
24 _EGLDisplay
*dpyList
, *dpy
;
26 /* atexit function is called with global mutex locked */
27 dpyList
= _eglGlobal
.DisplayList
;
31 dpyList
= dpyList
->Next
;
33 if (dpy
->ContextList
|| dpy
->SurfaceList
)
34 _eglLog(_EGL_DEBUG
, "Display %p is destroyed with resources", dpy
);
38 _eglGlobal
.DisplayList
= NULL
;
43 * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
44 * We'll also try to determine the device driver name at this time.
46 * Note that nativeDisplay may be an X Display ptr, or a string.
49 _eglNewDisplay(NativeDisplayType nativeDisplay
)
51 _EGLDisplay
*dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
53 dpy
->NativeDisplay
= nativeDisplay
;
60 * Link a display to itself and return the handle of the link.
61 * The handle can be passed to client directly.
64 _eglLinkDisplay(_EGLDisplay
*dpy
)
66 _eglLockMutex(_eglGlobal
.Mutex
);
68 dpy
->Next
= _eglGlobal
.DisplayList
;
69 _eglGlobal
.DisplayList
= dpy
;
71 _eglUnlockMutex(_eglGlobal
.Mutex
);
73 return (EGLDisplay
) dpy
;
78 * Unlink a linked display from itself.
79 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
82 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
86 _eglLockMutex(_eglGlobal
.Mutex
);
88 prev
= _eglGlobal
.DisplayList
;
91 if (prev
->Next
== dpy
)
96 prev
->Next
= dpy
->Next
;
99 _eglGlobal
.DisplayList
= dpy
->Next
;
102 _eglUnlockMutex(_eglGlobal
.Mutex
);
107 * Find the display corresponding to the specified native display id in all
111 _eglFindDisplay(NativeDisplayType nativeDisplay
)
115 _eglLockMutex(_eglGlobal
.Mutex
);
117 dpy
= _eglGlobal
.DisplayList
;
119 if (dpy
->NativeDisplay
== nativeDisplay
) {
120 _eglUnlockMutex(_eglGlobal
.Mutex
);
126 _eglUnlockMutex(_eglGlobal
.Mutex
);
133 * Destroy the contexts and surfaces that are linked to the display.
136 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
138 _EGLContext
*contexts
;
139 _EGLSurface
*surfaces
;
141 contexts
= display
->ContextList
;
142 surfaces
= display
->SurfaceList
;
145 _EGLContext
*ctx
= contexts
;
146 contexts
= contexts
->Next
;
148 _eglUnlinkContext(ctx
);
149 drv
->API
.DestroyContext(drv
, display
, ctx
);
151 assert(!display
->ContextList
);
154 _EGLSurface
*surf
= surfaces
;
155 surfaces
= surfaces
->Next
;
157 _eglUnlinkSurface(surf
);
158 drv
->API
.DestroySurface(drv
, display
, surf
);
160 assert(!display
->SurfaceList
);
165 * Free all the data hanging of an _EGLDisplay object, but not
169 _eglCleanupDisplay(_EGLDisplay
*disp
)
174 for (i
= 0; i
< disp
->NumConfigs
; i
++)
175 free(disp
->Configs
[i
]);
177 disp
->Configs
= NULL
;
178 disp
->NumConfigs
= 0;
185 #ifndef _EGL_SKIP_HANDLE_CHECK
189 * Return EGL_TRUE if the given handle is a valid handle to a display.
192 _eglCheckDisplayHandle(EGLDisplay dpy
)
196 _eglLockMutex(_eglGlobal
.Mutex
);
197 cur
= _eglGlobal
.DisplayList
;
199 if (cur
== (_EGLDisplay
*) dpy
)
203 _eglUnlockMutex(_eglGlobal
.Mutex
);
204 return (cur
!= NULL
);
208 #endif /* !_EGL_SKIP_HANDLE_CHECK */