3 * Functions related to EGLDisplay.
9 #include "eglcontext.h"
10 #include "eglsurface.h"
11 #include "egldisplay.h"
12 #include "egldriver.h"
13 #include "eglglobals.h"
15 #include "eglstring.h"
19 * Allocate a new _EGLDisplay object for the given nativeDisplay handle.
20 * We'll also try to determine the device driver name at this time.
22 * Note that nativeDisplay may be an X Display ptr, or a string.
25 _eglNewDisplay(NativeDisplayType nativeDisplay
)
27 _EGLDisplay
*dpy
= (_EGLDisplay
*) calloc(1, sizeof(_EGLDisplay
));
29 dpy
->NativeDisplay
= nativeDisplay
;
30 #if defined(_EGL_PLATFORM_X)
31 dpy
->Xdpy
= (Display
*) nativeDisplay
;
34 dpy
->DriverName
= _eglChooseDriver(dpy
);
35 if (!dpy
->DriverName
) {
45 * Link a display to itself and return the handle of the link.
46 * The handle can be passed to client directly.
49 _eglLinkDisplay(_EGLDisplay
*dpy
)
52 key
= _eglHashGenKey(_eglGlobal
.Displays
);
54 /* "link" the display to the hash table */
55 _eglHashInsert(_eglGlobal
.Displays
, key
, dpy
);
56 dpy
->Handle
= (EGLDisplay
) _eglUIntToPointer(key
);
63 * Unlink a linked display from itself.
64 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
67 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
69 EGLuint key
= _eglPointerToUInt((void *) dpy
->Handle
);
70 _eglHashRemove(_eglGlobal
.Displays
, key
);
71 dpy
->Handle
= EGL_NO_DISPLAY
;
76 * Return the handle of a linked display, or EGL_NO_DISPLAY.
79 _eglGetDisplayHandle(_EGLDisplay
*display
)
82 return display
->Handle
;
84 return EGL_NO_DISPLAY
;
89 * Lookup a handle to find the linked display.
90 * Return NULL if the handle has no corresponding linked display.
93 _eglLookupDisplay(EGLDisplay dpy
)
95 EGLuint key
= _eglPointerToUInt((void *) dpy
);
96 return (_EGLDisplay
*) _eglHashLookup(_eglGlobal
.Displays
, key
);
101 * Find the display corresponding to the specified native display id in all
105 _eglFindDisplay(NativeDisplayType nativeDisplay
)
107 EGLuint key
= _eglHashFirstEntry(_eglGlobal
.Displays
);
109 /* Walk the hash table. Should switch to list if it is a problem. */
111 _EGLDisplay
*dpy
= (_EGLDisplay
*)
112 _eglHashLookup(_eglGlobal
.Displays
, key
);
115 if (dpy
->NativeDisplay
== nativeDisplay
)
117 key
= _eglHashNextEntry(_eglGlobal
.Displays
, key
);
125 * Destroy the contexts and surfaces that are linked to the display.
128 _eglReleaseDisplayResources(_EGLDriver
*drv
, EGLDisplay dpy
)
130 _EGLDisplay
*display
;
131 _EGLContext
*contexts
;
132 _EGLSurface
*surfaces
;
134 display
= _eglLookupDisplay(dpy
);
137 contexts
= display
->ContextList
;
138 surfaces
= display
->SurfaceList
;
141 EGLContext handle
= _eglGetContextHandle(contexts
);
142 contexts
= contexts
->Next
;
143 drv
->API
.DestroyContext(drv
, dpy
, handle
);
145 assert(!display
->ContextList
);
148 EGLSurface handle
= _eglGetSurfaceHandle(surfaces
);
149 surfaces
= surfaces
->Next
;
150 drv
->API
.DestroySurface(drv
, dpy
, handle
);
152 assert(!display
->SurfaceList
);
157 * Free all the data hanging of an _EGLDisplay object, but not
161 _eglCleanupDisplay(_EGLDisplay
*disp
)
165 for (i
= 0; i
< disp
->NumConfigs
; i
++) {
166 free(disp
->Configs
[i
]);
169 disp
->Configs
= NULL
;
173 free((void *) disp
->DriverName
);
174 disp
->DriverName
= NULL
;
176 /* driver deletes the _EGLDisplay object */
181 * Link a context to a display and return the handle of the link.
182 * The handle can be passed to client directly.
185 _eglLinkContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
)
188 ctx
->Next
= dpy
->ContextList
;
189 dpy
->ContextList
= ctx
;
190 return (EGLContext
) ctx
;
195 * Unlink a linked context from its display.
196 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
199 _eglUnlinkContext(_EGLContext
*ctx
)
203 prev
= ctx
->Display
->ContextList
;
206 if (prev
->Next
== ctx
)
211 prev
->Next
= ctx
->Next
;
214 ctx
->Display
->ContextList
= ctx
->Next
;
223 * Return the handle of a linked context, or EGL_NO_CONTEXT.
226 _eglGetContextHandle(_EGLContext
*ctx
)
228 return (EGLContext
) ((ctx
&& ctx
->Display
) ? ctx
: EGL_NO_CONTEXT
);
233 * Lookup a handle to find the linked context.
234 * Return NULL if the handle has no corresponding linked context.
237 _eglLookupContext(EGLContext ctx
)
239 _EGLContext
*context
= (_EGLContext
*) ctx
;
240 return (context
&& context
->Display
) ? context
: NULL
;
245 * Link a surface to a display and return the handle of the link.
246 * The handle can be passed to client directly.
249 _eglLinkSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
)
254 surf
->Next
= dpy
->SurfaceList
;
255 dpy
->SurfaceList
= surf
;
257 key
= _eglHashGenKey(_eglGlobal
.Surfaces
);
259 _eglHashInsert(_eglGlobal
.Surfaces
, key
, surf
);
261 surf
->Handle
= (EGLSurface
) _eglUIntToPointer(key
);
267 * Unlink a linked surface from its display.
268 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
271 _eglUnlinkSurface(_EGLSurface
*surf
)
274 EGLuint key
= _eglPointerToUInt((void *) surf
->Handle
);
276 _eglHashRemove(_eglGlobal
.Surfaces
, key
);
277 surf
->Handle
= EGL_NO_SURFACE
;
279 prev
= surf
->Display
->SurfaceList
;
282 if (prev
->Next
== surf
)
287 prev
->Next
= surf
->Next
;
291 surf
->Display
->SurfaceList
= surf
->Next
;
295 surf
->Display
= NULL
;
300 * Return the handle of a linked surface, or EGL_NO_SURFACE.
303 _eglGetSurfaceHandle(_EGLSurface
*surface
)
306 return surface
->Handle
;
308 return EGL_NO_SURFACE
;
313 * Lookup a handle to find the linked surface.
314 * Return NULL if the handle has no corresponding linked surface.
317 _eglLookupSurface(EGLSurface surf
)
319 EGLuint key
= _eglPointerToUInt((void *) surf
);
320 return (_EGLSurface
*) _eglHashLookup(_eglGlobal
.Surfaces
, key
);