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