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
;
90 * Link a display to itself and return the handle of the link.
91 * The handle can be passed to client directly.
94 _eglLinkDisplay(_EGLDisplay
*dpy
)
96 _eglLockMutex(_eglGlobal
.Mutex
);
98 dpy
->Next
= _eglGlobal
.DisplayList
;
99 _eglGlobal
.DisplayList
= dpy
;
101 _eglUnlockMutex(_eglGlobal
.Mutex
);
103 return (EGLDisplay
) dpy
;
108 * Unlink a linked display from itself.
109 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
112 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
116 _eglLockMutex(_eglGlobal
.Mutex
);
118 prev
= _eglGlobal
.DisplayList
;
121 if (prev
->Next
== dpy
)
126 prev
->Next
= dpy
->Next
;
129 _eglGlobal
.DisplayList
= dpy
->Next
;
132 _eglUnlockMutex(_eglGlobal
.Mutex
);
137 * Find the display corresponding to the specified native display id in all
141 _eglFindDisplay(NativeDisplayType nativeDisplay
)
145 _eglLockMutex(_eglGlobal
.Mutex
);
147 dpy
= _eglGlobal
.DisplayList
;
149 if (dpy
->NativeDisplay
== nativeDisplay
) {
150 _eglUnlockMutex(_eglGlobal
.Mutex
);
156 _eglUnlockMutex(_eglGlobal
.Mutex
);
163 * Destroy the contexts and surfaces that are linked to the display.
166 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
168 _EGLContext
*contexts
;
169 _EGLSurface
*surfaces
;
171 contexts
= display
->ContextList
;
172 surfaces
= display
->SurfaceList
;
175 _EGLContext
*ctx
= contexts
;
176 contexts
= contexts
->Next
;
178 _eglUnlinkContext(ctx
);
179 drv
->API
.DestroyContext(drv
, display
, ctx
);
181 assert(!display
->ContextList
);
184 _EGLSurface
*surf
= surfaces
;
185 surfaces
= surfaces
->Next
;
187 _eglUnlinkSurface(surf
);
188 drv
->API
.DestroySurface(drv
, display
, surf
);
190 assert(!display
->SurfaceList
);
195 * Free all the data hanging of an _EGLDisplay object, but not
199 _eglCleanupDisplay(_EGLDisplay
*disp
)
204 for (i
= 0; i
< disp
->NumConfigs
; i
++)
205 free(disp
->Configs
[i
]);
207 disp
->Configs
= NULL
;
208 disp
->NumConfigs
= 0;
216 * Link a context to a display and return the handle of the link.
217 * The handle can be passed to client directly.
220 _eglLinkContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
)
223 ctx
->Next
= dpy
->ContextList
;
224 dpy
->ContextList
= ctx
;
225 return (EGLContext
) ctx
;
230 * Unlink a linked context from its display.
231 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
234 _eglUnlinkContext(_EGLContext
*ctx
)
238 prev
= ctx
->Display
->ContextList
;
241 if (prev
->Next
== ctx
)
246 prev
->Next
= ctx
->Next
;
249 ctx
->Display
->ContextList
= ctx
->Next
;
258 * Link a surface to a display and return the handle of the link.
259 * The handle can be passed to client directly.
262 _eglLinkSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
)
265 surf
->Next
= dpy
->SurfaceList
;
266 dpy
->SurfaceList
= surf
;
267 return (EGLSurface
) surf
;
272 * Unlink a linked surface from its display.
273 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
276 _eglUnlinkSurface(_EGLSurface
*surf
)
280 prev
= surf
->Display
->SurfaceList
;
283 if (prev
->Next
== surf
)
288 prev
->Next
= surf
->Next
;
292 surf
->Display
->SurfaceList
= surf
->Next
;
296 surf
->Display
= NULL
;
300 #ifndef _EGL_SKIP_HANDLE_CHECK
304 * Return EGL_TRUE if the given handle is a valid handle to a display.
307 _eglCheckDisplayHandle(EGLDisplay dpy
)
311 _eglLockMutex(_eglGlobal
.Mutex
);
312 cur
= _eglGlobal
.DisplayList
;
314 if (cur
== (_EGLDisplay
*) dpy
)
318 _eglUnlockMutex(_eglGlobal
.Mutex
);
319 return (cur
!= NULL
);
324 * Return EGL_TRUE if the given handle is a valid handle to a context.
327 _eglCheckContextHandle(EGLContext ctx
, _EGLDisplay
*dpy
)
329 _EGLContext
*cur
= NULL
;
332 cur
= dpy
->ContextList
;
334 if (cur
== (_EGLContext
*) ctx
) {
335 assert(cur
->Display
== dpy
);
340 return (cur
!= NULL
);
345 * Return EGL_TRUE if the given handle is a valid handle to a surface.
348 _eglCheckSurfaceHandle(EGLSurface surf
, _EGLDisplay
*dpy
)
350 _EGLSurface
*cur
= NULL
;
353 cur
= dpy
->SurfaceList
;
355 if (cur
== (_EGLSurface
*) surf
) {
356 assert(cur
->Display
== dpy
);
361 return (cur
!= NULL
);
365 #endif /* !_EGL_SKIP_HANDLE_CHECK */