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 * If the first character is '!' we interpret it as specific driver name
44 * (i.e. "!r200" or "!i830"). Whatever follows ':' is interpreted as
47 * The caller may free() the returned driver name.
50 _eglSplitDisplayString(const char *dpyString
, const char **args
)
54 if (!dpyString
|| dpyString
[0] != '!')
56 drv
= _eglstrdup(dpyString
+ 1);
60 p
= strchr(dpyString
, ':');
62 drv
[p
- dpyString
] = '\0';
73 * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
74 * We'll also try to determine the device driver name at this time.
76 * Note that nativeDisplay may be an X Display ptr, or a string.
79 _eglNewDisplay(NativeDisplayType nativeDisplay
)
81 _EGLDisplay
*dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
83 dpy
->NativeDisplay
= nativeDisplay
;
84 #if defined(_EGL_PLATFORM_X)
85 dpy
->Xdpy
= (Display
*) nativeDisplay
;
88 dpy
->DriverName
= _eglPreloadDriver(dpy
);
89 if (!dpy
->DriverName
) {
99 * Link a display to itself and return the handle of the link.
100 * The handle can be passed to client directly.
103 _eglLinkDisplay(_EGLDisplay
*dpy
)
105 _eglLockMutex(_eglGlobal
.Mutex
);
107 dpy
->Next
= _eglGlobal
.DisplayList
;
108 _eglGlobal
.DisplayList
= dpy
;
110 _eglUnlockMutex(_eglGlobal
.Mutex
);
112 return (EGLDisplay
) dpy
;
117 * Unlink a linked display from itself.
118 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
121 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
125 _eglLockMutex(_eglGlobal
.Mutex
);
127 prev
= _eglGlobal
.DisplayList
;
130 if (prev
->Next
== dpy
)
135 prev
->Next
= dpy
->Next
;
138 _eglGlobal
.DisplayList
= dpy
->Next
;
141 _eglUnlockMutex(_eglGlobal
.Mutex
);
146 * Find the display corresponding to the specified native display id in all
150 _eglFindDisplay(NativeDisplayType nativeDisplay
)
154 _eglLockMutex(_eglGlobal
.Mutex
);
156 dpy
= _eglGlobal
.DisplayList
;
158 if (dpy
->NativeDisplay
== nativeDisplay
) {
159 _eglUnlockMutex(_eglGlobal
.Mutex
);
165 _eglUnlockMutex(_eglGlobal
.Mutex
);
172 * Destroy the contexts and surfaces that are linked to the display.
175 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
177 _EGLContext
*contexts
;
178 _EGLSurface
*surfaces
;
180 contexts
= display
->ContextList
;
181 surfaces
= display
->SurfaceList
;
184 _EGLContext
*ctx
= contexts
;
185 contexts
= contexts
->Next
;
187 _eglUnlinkContext(ctx
);
188 drv
->API
.DestroyContext(drv
, display
, ctx
);
190 assert(!display
->ContextList
);
193 _EGLSurface
*surf
= surfaces
;
194 surfaces
= surfaces
->Next
;
196 _eglUnlinkSurface(surf
);
197 drv
->API
.DestroySurface(drv
, display
, surf
);
199 assert(!display
->SurfaceList
);
204 * Free all the data hanging of an _EGLDisplay object, but not
208 _eglCleanupDisplay(_EGLDisplay
*disp
)
213 for (i
= 0; i
< disp
->NumConfigs
; i
++)
214 free(disp
->Configs
[i
]);
216 disp
->Configs
= NULL
;
217 disp
->NumConfigs
= 0;
225 * Link a context to a display and return the handle of the link.
226 * The handle can be passed to client directly.
229 _eglLinkContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
)
232 ctx
->Next
= dpy
->ContextList
;
233 dpy
->ContextList
= ctx
;
234 return (EGLContext
) ctx
;
239 * Unlink a linked context from its display.
240 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
243 _eglUnlinkContext(_EGLContext
*ctx
)
247 prev
= ctx
->Display
->ContextList
;
250 if (prev
->Next
== ctx
)
255 prev
->Next
= ctx
->Next
;
258 ctx
->Display
->ContextList
= ctx
->Next
;
267 * Link a surface to a display and return the handle of the link.
268 * The handle can be passed to client directly.
271 _eglLinkSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
)
274 surf
->Next
= dpy
->SurfaceList
;
275 dpy
->SurfaceList
= surf
;
276 return (EGLSurface
) surf
;
281 * Unlink a linked surface from its display.
282 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
285 _eglUnlinkSurface(_EGLSurface
*surf
)
289 prev
= surf
->Display
->SurfaceList
;
292 if (prev
->Next
== surf
)
297 prev
->Next
= surf
->Next
;
301 surf
->Display
->SurfaceList
= surf
->Next
;
305 surf
->Display
= NULL
;
309 #ifndef _EGL_SKIP_HANDLE_CHECK
313 * Return EGL_TRUE if the given handle is a valid handle to a display.
316 _eglCheckDisplayHandle(EGLDisplay dpy
)
320 _eglLockMutex(_eglGlobal
.Mutex
);
321 cur
= _eglGlobal
.DisplayList
;
323 if (cur
== (_EGLDisplay
*) dpy
)
327 _eglUnlockMutex(_eglGlobal
.Mutex
);
328 return (cur
!= NULL
);
333 * Return EGL_TRUE if the given handle is a valid handle to a context.
336 _eglCheckContextHandle(EGLContext ctx
, _EGLDisplay
*dpy
)
338 _EGLContext
*cur
= NULL
;
341 cur
= dpy
->ContextList
;
343 if (cur
== (_EGLContext
*) ctx
) {
344 assert(cur
->Display
== dpy
);
349 return (cur
!= NULL
);
354 * Return EGL_TRUE if the given handle is a valid handle to a surface.
357 _eglCheckSurfaceHandle(EGLSurface surf
, _EGLDisplay
*dpy
)
359 _EGLSurface
*cur
= NULL
;
362 cur
= dpy
->SurfaceList
;
364 if (cur
== (_EGLSurface
*) surf
) {
365 assert(cur
->Display
== dpy
);
370 return (cur
!= NULL
);
374 #endif /* !_EGL_SKIP_HANDLE_CHECK */