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"
14 #include "eglstring.h"
20 * Finish display management.
25 _EGLDisplay
*dpyList
, *dpy
;
27 /* atexit function is called with global mutex locked */
28 dpyList
= _eglGlobal
.DisplayList
;
32 dpyList
= dpyList
->Next
;
34 if (dpy
->ContextList
|| dpy
->SurfaceList
)
35 _eglLog(_EGL_DEBUG
, "Display %p is destroyed with resources", dpy
);
39 _eglGlobal
.DisplayList
= NULL
;
44 * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
45 * We'll also try to determine the device driver name at this time.
47 * Note that nativeDisplay may be an X Display ptr, or a string.
50 _eglNewDisplay(NativeDisplayType nativeDisplay
)
52 _EGLDisplay
*dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
54 dpy
->NativeDisplay
= nativeDisplay
;
55 #if defined(_EGL_PLATFORM_X)
56 dpy
->Xdpy
= (Display
*) nativeDisplay
;
59 dpy
->DriverName
= _eglPreloadDriver(dpy
);
60 if (!dpy
->DriverName
) {
70 * Link a display to itself and return the handle of the link.
71 * The handle can be passed to client directly.
74 _eglLinkDisplay(_EGLDisplay
*dpy
)
76 _eglLockMutex(_eglGlobal
.Mutex
);
78 dpy
->Next
= _eglGlobal
.DisplayList
;
79 _eglGlobal
.DisplayList
= dpy
;
81 _eglUnlockMutex(_eglGlobal
.Mutex
);
83 return (EGLDisplay
) dpy
;
88 * Unlink a linked display from itself.
89 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
92 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
96 _eglLockMutex(_eglGlobal
.Mutex
);
98 prev
= _eglGlobal
.DisplayList
;
101 if (prev
->Next
== dpy
)
106 prev
->Next
= dpy
->Next
;
109 _eglGlobal
.DisplayList
= dpy
->Next
;
112 _eglUnlockMutex(_eglGlobal
.Mutex
);
117 * Return the handle of a linked display, or EGL_NO_DISPLAY.
120 _eglGetDisplayHandle(_EGLDisplay
*dpy
)
122 return (EGLDisplay
) ((dpy
) ? dpy
: EGL_NO_DISPLAY
);
127 * Lookup a handle to find the linked display.
128 * Return NULL if the handle has no corresponding linked display.
131 _eglLookupDisplay(EGLDisplay display
)
133 _EGLDisplay
*dpy
= (_EGLDisplay
*) display
;
139 * Find the display corresponding to the specified native display id in all
143 _eglFindDisplay(NativeDisplayType nativeDisplay
)
147 _eglLockMutex(_eglGlobal
.Mutex
);
149 dpy
= _eglGlobal
.DisplayList
;
151 if (dpy
->NativeDisplay
== nativeDisplay
) {
152 _eglUnlockMutex(_eglGlobal
.Mutex
);
158 _eglUnlockMutex(_eglGlobal
.Mutex
);
165 * Destroy the contexts and surfaces that are linked to the display.
168 _eglReleaseDisplayResources(_EGLDriver
*drv
, _EGLDisplay
*display
)
170 _EGLContext
*contexts
;
171 _EGLSurface
*surfaces
;
173 contexts
= display
->ContextList
;
174 surfaces
= display
->SurfaceList
;
177 _EGLContext
*ctx
= contexts
;
178 contexts
= contexts
->Next
;
180 _eglUnlinkContext(ctx
);
181 drv
->API
.DestroyContext(drv
, display
, ctx
);
183 assert(!display
->ContextList
);
186 _EGLSurface
*surf
= surfaces
;
187 surfaces
= surfaces
->Next
;
189 _eglUnlinkSurface(surf
);
190 drv
->API
.DestroySurface(drv
, display
, surf
);
192 assert(!display
->SurfaceList
);
197 * Free all the data hanging of an _EGLDisplay object, but not
201 _eglCleanupDisplay(_EGLDisplay
*disp
)
206 for (i
= 0; i
< disp
->NumConfigs
; i
++)
207 free(disp
->Configs
[i
]);
209 disp
->Configs
= NULL
;
210 disp
->NumConfigs
= 0;
218 * Link a context to a display and return the handle of the link.
219 * The handle can be passed to client directly.
222 _eglLinkContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
)
225 ctx
->Next
= dpy
->ContextList
;
226 dpy
->ContextList
= ctx
;
227 return (EGLContext
) ctx
;
232 * Unlink a linked context from its display.
233 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
236 _eglUnlinkContext(_EGLContext
*ctx
)
240 prev
= ctx
->Display
->ContextList
;
243 if (prev
->Next
== ctx
)
248 prev
->Next
= ctx
->Next
;
251 ctx
->Display
->ContextList
= ctx
->Next
;
260 * Return the handle of a linked context, or EGL_NO_CONTEXT.
263 _eglGetContextHandle(_EGLContext
*ctx
)
265 return (EGLContext
) ((ctx
&& ctx
->Display
) ? ctx
: EGL_NO_CONTEXT
);
270 * Lookup a handle to find the linked context.
271 * Return NULL if the handle has no corresponding linked context.
274 _eglLookupContext(EGLContext ctx
, _EGLDisplay
*dpy
)
276 _EGLContext
*context
= (_EGLContext
*) ctx
;
277 return (context
&& context
->Display
) ? context
: NULL
;
282 * Link a surface to a display and return the handle of the link.
283 * The handle can be passed to client directly.
286 _eglLinkSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
)
289 surf
->Next
= dpy
->SurfaceList
;
290 dpy
->SurfaceList
= surf
;
291 return (EGLSurface
) surf
;
296 * Unlink a linked surface from its display.
297 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
300 _eglUnlinkSurface(_EGLSurface
*surf
)
304 prev
= surf
->Display
->SurfaceList
;
307 if (prev
->Next
== surf
)
312 prev
->Next
= surf
->Next
;
316 surf
->Display
->SurfaceList
= surf
->Next
;
320 surf
->Display
= NULL
;
325 * Return the handle of a linked surface, or EGL_NO_SURFACE.
328 _eglGetSurfaceHandle(_EGLSurface
*surf
)
330 return (EGLSurface
) ((surf
&& surf
->Display
) ? surf
: EGL_NO_SURFACE
);
335 * Lookup a handle to find the linked surface.
336 * Return NULL if the handle has no corresponding linked surface.
339 _eglLookupSurface(EGLSurface surface
, _EGLDisplay
*dpy
)
341 _EGLSurface
*surf
= (_EGLSurface
*) surface
;
342 return (surf
&& surf
->Display
) ? surf
: NULL
;