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
;
85 dpy
->DriverName
= _eglPreloadDriver(dpy
);
86 if (!dpy
->DriverName
) {
96 * Link a display to itself and return the handle of the link.
97 * The handle can be passed to client directly.
100 _eglLinkDisplay(_EGLDisplay
*dpy
)
102 _eglLockMutex(_eglGlobal
.Mutex
);
104 dpy
->Next
= _eglGlobal
.DisplayList
;
105 _eglGlobal
.DisplayList
= dpy
;
107 _eglUnlockMutex(_eglGlobal
.Mutex
);
109 return (EGLDisplay
) dpy
;
114 * Unlink a linked display from itself.
115 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
118 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
122 _eglLockMutex(_eglGlobal
.Mutex
);
124 prev
= _eglGlobal
.DisplayList
;
127 if (prev
->Next
== dpy
)
132 prev
->Next
= dpy
->Next
;
135 _eglGlobal
.DisplayList
= dpy
->Next
;
138 _eglUnlockMutex(_eglGlobal
.Mutex
);
143 * Find the display corresponding to the specified native display id in all
147 _eglFindDisplay(NativeDisplayType nativeDisplay
)
151 _eglLockMutex(_eglGlobal
.Mutex
);
153 dpy
= _eglGlobal
.DisplayList
;
155 if (dpy
->NativeDisplay
== nativeDisplay
) {
156 _eglUnlockMutex(_eglGlobal
.Mutex
);
162 _eglUnlockMutex(_eglGlobal
.Mutex
);
169 * Destroy the contexts and surfaces that are linked to the display.
172 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
174 _EGLContext
*contexts
;
175 _EGLSurface
*surfaces
;
177 contexts
= display
->ContextList
;
178 surfaces
= display
->SurfaceList
;
181 _EGLContext
*ctx
= contexts
;
182 contexts
= contexts
->Next
;
184 _eglUnlinkContext(ctx
);
185 drv
->API
.DestroyContext(drv
, display
, ctx
);
187 assert(!display
->ContextList
);
190 _EGLSurface
*surf
= surfaces
;
191 surfaces
= surfaces
->Next
;
193 _eglUnlinkSurface(surf
);
194 drv
->API
.DestroySurface(drv
, display
, surf
);
196 assert(!display
->SurfaceList
);
201 * Free all the data hanging of an _EGLDisplay object, but not
205 _eglCleanupDisplay(_EGLDisplay
*disp
)
210 for (i
= 0; i
< disp
->NumConfigs
; i
++)
211 free(disp
->Configs
[i
]);
213 disp
->Configs
= NULL
;
214 disp
->NumConfigs
= 0;
222 * Link a context to a display and return the handle of the link.
223 * The handle can be passed to client directly.
226 _eglLinkContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
)
229 ctx
->Next
= dpy
->ContextList
;
230 dpy
->ContextList
= ctx
;
231 return (EGLContext
) ctx
;
236 * Unlink a linked context from its display.
237 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
240 _eglUnlinkContext(_EGLContext
*ctx
)
244 prev
= ctx
->Display
->ContextList
;
247 if (prev
->Next
== ctx
)
252 prev
->Next
= ctx
->Next
;
255 ctx
->Display
->ContextList
= ctx
->Next
;
264 * Link a surface to a display and return the handle of the link.
265 * The handle can be passed to client directly.
268 _eglLinkSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
)
271 surf
->Next
= dpy
->SurfaceList
;
272 dpy
->SurfaceList
= surf
;
273 return (EGLSurface
) surf
;
278 * Unlink a linked surface from its display.
279 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
282 _eglUnlinkSurface(_EGLSurface
*surf
)
286 prev
= surf
->Display
->SurfaceList
;
289 if (prev
->Next
== surf
)
294 prev
->Next
= surf
->Next
;
298 surf
->Display
->SurfaceList
= surf
->Next
;
302 surf
->Display
= NULL
;
306 #ifndef _EGL_SKIP_HANDLE_CHECK
310 * Return EGL_TRUE if the given handle is a valid handle to a display.
313 _eglCheckDisplayHandle(EGLDisplay dpy
)
317 _eglLockMutex(_eglGlobal
.Mutex
);
318 cur
= _eglGlobal
.DisplayList
;
320 if (cur
== (_EGLDisplay
*) dpy
)
324 _eglUnlockMutex(_eglGlobal
.Mutex
);
325 return (cur
!= NULL
);
330 * Return EGL_TRUE if the given handle is a valid handle to a context.
333 _eglCheckContextHandle(EGLContext ctx
, _EGLDisplay
*dpy
)
335 _EGLContext
*cur
= NULL
;
338 cur
= dpy
->ContextList
;
340 if (cur
== (_EGLContext
*) ctx
) {
341 assert(cur
->Display
== dpy
);
346 return (cur
!= NULL
);
351 * Return EGL_TRUE if the given handle is a valid handle to a surface.
354 _eglCheckSurfaceHandle(EGLSurface surf
, _EGLDisplay
*dpy
)
356 _EGLSurface
*cur
= NULL
;
359 cur
= dpy
->SurfaceList
;
361 if (cur
== (_EGLSurface
*) surf
) {
362 assert(cur
->Display
== dpy
);
367 return (cur
!= NULL
);
371 #endif /* !_EGL_SKIP_HANDLE_CHECK */