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;
186 * Link a context to a display and return the handle of the link.
187 * The handle can be passed to client directly.
190 _eglLinkContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
)
193 ctx
->Next
= dpy
->ContextList
;
194 dpy
->ContextList
= ctx
;
195 return (EGLContext
) ctx
;
200 * Unlink a linked context from its display.
201 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
204 _eglUnlinkContext(_EGLContext
*ctx
)
208 prev
= ctx
->Display
->ContextList
;
211 if (prev
->Next
== ctx
)
216 prev
->Next
= ctx
->Next
;
219 ctx
->Display
->ContextList
= ctx
->Next
;
228 * Link a surface to a display and return the handle of the link.
229 * The handle can be passed to client directly.
232 _eglLinkSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
)
235 surf
->Next
= dpy
->SurfaceList
;
236 dpy
->SurfaceList
= surf
;
237 return (EGLSurface
) surf
;
242 * Unlink a linked surface from its display.
243 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
246 _eglUnlinkSurface(_EGLSurface
*surf
)
250 prev
= surf
->Display
->SurfaceList
;
253 if (prev
->Next
== surf
)
258 prev
->Next
= surf
->Next
;
262 surf
->Display
->SurfaceList
= surf
->Next
;
266 surf
->Display
= NULL
;
270 #ifndef _EGL_SKIP_HANDLE_CHECK
274 * Return EGL_TRUE if the given handle is a valid handle to a display.
277 _eglCheckDisplayHandle(EGLDisplay dpy
)
281 _eglLockMutex(_eglGlobal
.Mutex
);
282 cur
= _eglGlobal
.DisplayList
;
284 if (cur
== (_EGLDisplay
*) dpy
)
288 _eglUnlockMutex(_eglGlobal
.Mutex
);
289 return (cur
!= NULL
);
294 * Return EGL_TRUE if the given handle is a valid handle to a context.
297 _eglCheckContextHandle(EGLContext ctx
, _EGLDisplay
*dpy
)
299 _EGLContext
*cur
= NULL
;
302 cur
= dpy
->ContextList
;
304 if (cur
== (_EGLContext
*) ctx
) {
305 assert(cur
->Display
== dpy
);
310 return (cur
!= NULL
);
315 * Return EGL_TRUE if the given handle is a valid handle to a surface.
318 _eglCheckSurfaceHandle(EGLSurface surf
, _EGLDisplay
*dpy
)
320 _EGLSurface
*cur
= NULL
;
323 cur
= dpy
->SurfaceList
;
325 if (cur
== (_EGLSurface
*) surf
) {
326 assert(cur
->Display
== dpy
);
331 return (cur
!= NULL
);
335 #endif /* !_EGL_SKIP_HANDLE_CHECK */