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
) key
;
63 * Unlink a linked display from itself.
64 * Accessing an unlinked display should generate EGL_BAD_DISPLAY error.
67 _eglUnlinkDisplay(_EGLDisplay
*dpy
)
69 _eglHashRemove(_eglGlobal
.Displays
, (EGLuint
) dpy
->Handle
);
70 dpy
->Handle
= EGL_NO_DISPLAY
;
75 * Return the handle of a linked display, or EGL_NO_DISPLAY.
78 _eglGetDisplayHandle(_EGLDisplay
*display
)
81 return display
->Handle
;
83 return EGL_NO_DISPLAY
;
88 * Lookup a handle to find the linked display.
89 * Return NULL if the handle has no corresponding linked display.
92 _eglLookupDisplay(EGLDisplay dpy
)
94 EGLuint key
= (EGLuint
) dpy
;
95 return (_EGLDisplay
*) _eglHashLookup(_eglGlobal
.Displays
, key
);
100 * Free all the data hanging of an _EGLDisplay object, but not
104 _eglCleanupDisplay(_EGLDisplay
*disp
)
108 for (i
= 0; i
< disp
->NumConfigs
; i
++) {
109 free(disp
->Configs
[i
]);
112 disp
->Configs
= NULL
;
116 free((void *) disp
->DriverName
);
117 disp
->DriverName
= NULL
;
119 /* driver deletes the _EGLDisplay object */
124 * Link a context to a display and return the handle of the link.
125 * The handle can be passed to client directly.
128 _eglLinkContext(_EGLContext
*ctx
, _EGLDisplay
*dpy
)
131 ctx
->Next
= dpy
->ContextList
;
132 dpy
->ContextList
= ctx
;
133 return (EGLContext
) ctx
;
138 * Unlink a linked context from its display.
139 * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
142 _eglUnlinkContext(_EGLContext
*ctx
)
146 prev
= ctx
->Display
->ContextList
;
149 if (prev
->Next
== ctx
)
154 prev
->Next
= ctx
->Next
;
157 ctx
->Display
->ContextList
= ctx
->Next
;
166 * Return the handle of a linked context, or EGL_NO_CONTEXT.
169 _eglGetContextHandle(_EGLContext
*ctx
)
171 return (EGLContext
) (ctx
&& ctx
->Display
) ? ctx
: EGL_NO_CONTEXT
;
176 * Lookup a handle to find the linked context.
177 * Return NULL if the handle has no corresponding linked context.
180 _eglLookupContext(EGLContext ctx
)
182 _EGLContext
*context
= (_EGLContext
*) ctx
;
183 return (context
&& context
->Display
) ? context
: NULL
;
188 * Link a surface to a display and return the handle of the link.
189 * The handle can be passed to client directly.
192 _eglLinkSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
)
197 surf
->Next
= dpy
->SurfaceList
;
198 dpy
->SurfaceList
= surf
;
200 key
= _eglHashGenKey(_eglGlobal
.Surfaces
);
202 _eglHashInsert(_eglGlobal
.Surfaces
, key
, surf
);
204 surf
->Handle
= (EGLSurface
) key
;
210 * Unlink a linked surface from its display.
211 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
214 _eglUnlinkSurface(_EGLSurface
*surf
)
218 _eglHashRemove(_eglGlobal
.Surfaces
, (EGLuint
) surf
->Handle
);
219 surf
->Handle
= EGL_NO_SURFACE
;
221 prev
= surf
->Display
->SurfaceList
;
224 if (prev
->Next
== surf
)
229 prev
->Next
= surf
->Next
;
233 surf
->Display
->SurfaceList
= surf
->Next
;
237 surf
->Display
= NULL
;
242 * Return the handle of a linked surface, or EGL_NO_SURFACE.
245 _eglGetSurfaceHandle(_EGLSurface
*surface
)
248 return surface
->Handle
;
250 return EGL_NO_SURFACE
;
255 * Lookup a handle to find the linked surface.
256 * Return NULL if the handle has no corresponding linked surface.
259 _eglLookupSurface(EGLSurface surf
)
261 _EGLSurface
*c
= (_EGLSurface
*) _eglHashLookup(_eglGlobal
.Surfaces
,