egl: Add back handle checking.
[mesa.git] / src / egl / main / egldisplay.h
1 #ifndef EGLDISPLAY_INCLUDED
2 #define EGLDISPLAY_INCLUDED
3
4 #ifdef _EGL_PLATFORM_X
5 #include <X11/Xlib.h>
6 #endif
7
8 #include "egltypedefs.h"
9 #include "egldefines.h"
10 #include "eglcontext.h"
11 #include "eglsurface.h"
12
13
14 /**
15 * Optional EGL extensions info.
16 */
17 struct _egl_extensions
18 {
19 EGLBoolean MESA_screen_surface;
20 EGLBoolean MESA_copy_context;
21
22 char String[_EGL_MAX_EXTENSIONS_LEN];
23 };
24
25
26 struct _egl_display
27 {
28 /* used to link displays */
29 _EGLDisplay *Next;
30
31 EGLNativeDisplayType NativeDisplay;
32
33 const char *DriverName;
34 _EGLDriver *Driver;
35 void *DriverData; /* private to driver */
36
37 int APImajor, APIminor; /**< as returned by eglInitialize() */
38 char Version[1000]; /**< initialized from APImajor/minor, DriverName */
39
40 /** Bitmask of supported APIs (EGL_xx_BIT) set by the driver during init */
41 EGLint ClientAPIsMask;
42 char ClientAPIs[1000]; /**< updated by eglQueryString */
43
44 _EGLExtensions Extensions;
45
46 int LargestPbuffer;
47
48 EGLint NumScreens;
49 _EGLScreen **Screens; /* array [NumScreens] */
50
51 EGLint NumConfigs;
52 _EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */
53
54 /* lists of linked contexts and surface */
55 _EGLContext *ContextList;
56 _EGLSurface *SurfaceList;
57
58 #ifdef _EGL_PLATFORM_X
59 Display *Xdpy;
60 #endif
61 };
62
63
64 extern void
65 _eglFiniDisplay(void);
66
67
68 extern _EGLDisplay *
69 _eglNewDisplay(NativeDisplayType displayName);
70
71
72 extern EGLDisplay
73 _eglLinkDisplay(_EGLDisplay *dpy);
74
75
76 extern void
77 _eglUnlinkDisplay(_EGLDisplay *dpy);
78
79
80 extern _EGLDisplay *
81 _eglFindDisplay(NativeDisplayType nativeDisplay);
82
83
84 extern void
85 _eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy);
86
87
88 extern void
89 _eglCleanupDisplay(_EGLDisplay *disp);
90
91
92 extern EGLContext
93 _eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy);
94
95
96 extern void
97 _eglUnlinkContext(_EGLContext *ctx);
98
99
100 extern EGLSurface
101 _eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy);
102
103
104 extern void
105 _eglUnlinkSurface(_EGLSurface *surf);
106
107
108 #ifndef _EGL_SKIP_HANDLE_CHECK
109
110
111 extern EGLBoolean
112 _eglCheckDisplayHandle(EGLDisplay dpy);
113
114
115 extern EGLBoolean
116 _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy);
117
118
119 extern EGLBoolean
120 _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy);
121
122
123 #else /* !_EGL_SKIP_HANDLE_CHECK */
124
125 /* Only do a quick check. This is NOT standard compliant. */
126
127 static INLINE EGLBoolean
128 _eglCheckDisplayHandle(EGLDisplay dpy) { return EGL_TRUE; }
129
130
131 static INLINE EGLBoolean
132 _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
133 {
134 _EGLContext *c = (_EGLContext *) ctx;
135 return (c && c->Display == dpy);
136 }
137
138
139 static INLINE EGLBoolean
140 _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
141 {
142 _EGLSurface *s = (_EGLSurface *) surf;
143 return (s && s->Display == dpy);
144 }
145
146
147 #endif /* _EGL_SKIP_HANDLE_CHECK */
148
149
150 /**
151 * Lookup a handle to find the linked display.
152 * Return NULL if the handle has no corresponding linked display.
153 */
154 static INLINE _EGLDisplay *
155 _eglLookupDisplay(EGLDisplay display)
156 {
157 _EGLDisplay *dpy = (_EGLDisplay *) display;
158 if (!_eglCheckDisplayHandle(display))
159 dpy = NULL;
160 return dpy;
161 }
162
163
164 /**
165 * Return the handle of a linked display, or EGL_NO_DISPLAY.
166 */
167 static INLINE EGLDisplay
168 _eglGetDisplayHandle(_EGLDisplay *dpy)
169 {
170 return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
171 }
172
173
174 /**
175 * Return true if the display is linked.
176 */
177 static INLINE EGLBoolean
178 _eglIsDisplayLinked(_EGLDisplay *dpy)
179 {
180 return (EGLBoolean) (_eglGetDisplayHandle(dpy) != EGL_NO_DISPLAY);
181 }
182
183
184 /**
185 * Lookup a handle to find the linked context.
186 * Return NULL if the handle has no corresponding linked context.
187 */
188 static INLINE _EGLContext *
189 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
190 {
191 _EGLContext *ctx = (_EGLContext *) context;
192 if (!_eglCheckContextHandle(context, dpy))
193 ctx = NULL;
194 return ctx;
195 }
196
197
198 /**
199 * Return the handle of a linked context, or EGL_NO_CONTEXT.
200 */
201 static INLINE EGLContext
202 _eglGetContextHandle(_EGLContext *ctx)
203 {
204 return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT);
205 }
206
207
208 /**
209 * Return true if the context is linked to a display.
210 */
211 static INLINE EGLBoolean
212 _eglIsContextLinked(_EGLContext *ctx)
213 {
214 return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT);
215 }
216
217
218 /**
219 * Lookup a handle to find the linked surface.
220 * Return NULL if the handle has no corresponding linked surface.
221 */
222 static INLINE _EGLSurface *
223 _eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
224 {
225 _EGLSurface *surf = (_EGLSurface *) surface;
226 if (!_eglCheckSurfaceHandle(surf, dpy))
227 surf = NULL;
228 return surf;
229 }
230
231
232 /**
233 * Return the handle of a linked surface, or EGL_NO_SURFACE.
234 */
235 static INLINE EGLSurface
236 _eglGetSurfaceHandle(_EGLSurface *surf)
237 {
238 return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
239 }
240
241
242 /**
243 * Return true if the surface is linked to a display.
244 */
245 static INLINE EGLBoolean
246 _eglIsSurfaceLinked(_EGLSurface *surf)
247 {
248 return (EGLBoolean) (_eglGetSurfaceHandle(surf) != EGL_NO_SURFACE);
249 }
250
251
252 /**
253 * Cast an unsigned int to a pointer.
254 */
255 static INLINE void *
256 _eglUIntToPointer(unsigned int v)
257 {
258 return (void *) ((uintptr_t) v);
259 }
260
261
262 /**
263 * Cast a pointer to an unsigned int. The pointer must be one that is
264 * returned by _eglUIntToPointer.
265 */
266 static INLINE unsigned int
267 _eglPointerToUInt(const void *p)
268 {
269 return (unsigned int) ((uintptr_t) p);
270 }
271
272
273 #endif /* EGLDISPLAY_INCLUDED */