egl: Remove dependency on libX11.
[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 char *
69 _eglSplitDisplayString(const char *dpyString, const char **args);
70
71
72 extern _EGLDisplay *
73 _eglNewDisplay(NativeDisplayType displayName);
74
75
76 extern EGLDisplay
77 _eglLinkDisplay(_EGLDisplay *dpy);
78
79
80 extern void
81 _eglUnlinkDisplay(_EGLDisplay *dpy);
82
83
84 extern _EGLDisplay *
85 _eglFindDisplay(NativeDisplayType nativeDisplay);
86
87
88 extern void
89 _eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy);
90
91
92 extern void
93 _eglCleanupDisplay(_EGLDisplay *disp);
94
95
96 extern EGLContext
97 _eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy);
98
99
100 extern void
101 _eglUnlinkContext(_EGLContext *ctx);
102
103
104 extern EGLSurface
105 _eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy);
106
107
108 extern void
109 _eglUnlinkSurface(_EGLSurface *surf);
110
111
112 #ifndef _EGL_SKIP_HANDLE_CHECK
113
114
115 extern EGLBoolean
116 _eglCheckDisplayHandle(EGLDisplay dpy);
117
118
119 extern EGLBoolean
120 _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy);
121
122
123 extern EGLBoolean
124 _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy);
125
126
127 #else /* !_EGL_SKIP_HANDLE_CHECK */
128
129 /* Only do a quick check. This is NOT standard compliant. */
130
131 static INLINE EGLBoolean
132 _eglCheckDisplayHandle(EGLDisplay dpy)
133 {
134 return ((_EGLDisplay *) dpy != NULL);
135 }
136
137
138 static INLINE EGLBoolean
139 _eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
140 {
141 _EGLContext *c = (_EGLContext *) ctx;
142 return (dpy && c && c->Display == dpy);
143 }
144
145
146 static INLINE EGLBoolean
147 _eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
148 {
149 _EGLSurface *s = (_EGLSurface *) surf;
150 return (dpy && s && s->Display == dpy);
151 }
152
153
154 #endif /* _EGL_SKIP_HANDLE_CHECK */
155
156
157 /**
158 * Lookup a handle to find the linked display.
159 * Return NULL if the handle has no corresponding linked display.
160 */
161 static INLINE _EGLDisplay *
162 _eglLookupDisplay(EGLDisplay display)
163 {
164 _EGLDisplay *dpy = (_EGLDisplay *) display;
165 if (!_eglCheckDisplayHandle(display))
166 dpy = NULL;
167 return dpy;
168 }
169
170
171 /**
172 * Return the handle of a linked display, or EGL_NO_DISPLAY.
173 */
174 static INLINE EGLDisplay
175 _eglGetDisplayHandle(_EGLDisplay *dpy)
176 {
177 return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
178 }
179
180
181 /**
182 * Return true if the display is linked.
183 */
184 static INLINE EGLBoolean
185 _eglIsDisplayLinked(_EGLDisplay *dpy)
186 {
187 return (EGLBoolean) (_eglGetDisplayHandle(dpy) != EGL_NO_DISPLAY);
188 }
189
190
191 /**
192 * Lookup a handle to find the linked context.
193 * Return NULL if the handle has no corresponding linked context.
194 */
195 static INLINE _EGLContext *
196 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
197 {
198 _EGLContext *ctx = (_EGLContext *) context;
199 if (!_eglCheckContextHandle(context, dpy))
200 ctx = NULL;
201 return ctx;
202 }
203
204
205 /**
206 * Return the handle of a linked context, or EGL_NO_CONTEXT.
207 */
208 static INLINE EGLContext
209 _eglGetContextHandle(_EGLContext *ctx)
210 {
211 return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT);
212 }
213
214
215 /**
216 * Return true if the context is linked to a display.
217 */
218 static INLINE EGLBoolean
219 _eglIsContextLinked(_EGLContext *ctx)
220 {
221 return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT);
222 }
223
224
225 /**
226 * Lookup a handle to find the linked surface.
227 * Return NULL if the handle has no corresponding linked surface.
228 */
229 static INLINE _EGLSurface *
230 _eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
231 {
232 _EGLSurface *surf = (_EGLSurface *) surface;
233 if (!_eglCheckSurfaceHandle(surf, dpy))
234 surf = NULL;
235 return surf;
236 }
237
238
239 /**
240 * Return the handle of a linked surface, or EGL_NO_SURFACE.
241 */
242 static INLINE EGLSurface
243 _eglGetSurfaceHandle(_EGLSurface *surf)
244 {
245 return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
246 }
247
248
249 /**
250 * Return true if the surface is linked to a display.
251 */
252 static INLINE EGLBoolean
253 _eglIsSurfaceLinked(_EGLSurface *surf)
254 {
255 return (EGLBoolean) (_eglGetSurfaceHandle(surf) != EGL_NO_SURFACE);
256 }
257
258
259 /**
260 * Cast an unsigned int to a pointer.
261 */
262 static INLINE void *
263 _eglUIntToPointer(unsigned int v)
264 {
265 return (void *) ((uintptr_t) v);
266 }
267
268
269 /**
270 * Cast a pointer to an unsigned int. The pointer must be one that is
271 * returned by _eglUIntToPointer.
272 */
273 static INLINE unsigned int
274 _eglPointerToUInt(const void *p)
275 {
276 return (unsigned int) ((uintptr_t) p);
277 }
278
279
280 #endif /* EGLDISPLAY_INCLUDED */