egl: Make surfaces and contexts resources.
[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
7
8 enum _egl_resource_type {
9 _EGL_RESOURCE_CONTEXT,
10 _EGL_RESOURCE_SURFACE,
11
12 _EGL_NUM_RESOURCES
13 };
14
15
16 /**
17 * A resource of a display.
18 */
19 struct _egl_resource
20 {
21 _EGLDisplay *Display;
22 _EGLResource *Next;
23 };
24
25
26 /**
27 * Optional EGL extensions info.
28 */
29 struct _egl_extensions
30 {
31 EGLBoolean MESA_screen_surface;
32 EGLBoolean MESA_copy_context;
33
34 char String[_EGL_MAX_EXTENSIONS_LEN];
35 };
36
37
38 struct _egl_display
39 {
40 /* used to link displays */
41 _EGLDisplay *Next;
42
43 EGLNativeDisplayType NativeDisplay;
44
45 _EGLDriver *Driver;
46 void *DriverData; /* private to driver */
47
48 int APImajor, APIminor; /**< as returned by eglInitialize() */
49 char Version[1000]; /**< initialized from APImajor/minor, DriverName */
50
51 /** Bitmask of supported APIs (EGL_xx_BIT) set by the driver during init */
52 EGLint ClientAPIsMask;
53 char ClientAPIs[1000]; /**< updated by eglQueryString */
54
55 _EGLExtensions Extensions;
56
57 int LargestPbuffer;
58
59 EGLint NumScreens;
60 _EGLScreen **Screens; /* array [NumScreens] */
61
62 EGLint MaxConfigs;
63 EGLint NumConfigs;
64 _EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */
65
66 /* lists of resources */
67 _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
68 };
69
70
71 extern void
72 _eglFiniDisplay(void);
73
74
75 extern _EGLDisplay *
76 _eglNewDisplay(NativeDisplayType displayName);
77
78
79 extern EGLDisplay
80 _eglLinkDisplay(_EGLDisplay *dpy);
81
82
83 extern void
84 _eglUnlinkDisplay(_EGLDisplay *dpy);
85
86
87 extern _EGLDisplay *
88 _eglFindDisplay(NativeDisplayType nativeDisplay);
89
90
91 PUBLIC void
92 _eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy);
93
94
95 PUBLIC void
96 _eglCleanupDisplay(_EGLDisplay *disp);
97
98
99 #ifndef _EGL_SKIP_HANDLE_CHECK
100
101
102 extern EGLBoolean
103 _eglCheckDisplayHandle(EGLDisplay dpy);
104
105
106 extern EGLBoolean
107 _eglCheckResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy);
108
109
110 #else /* !_EGL_SKIP_HANDLE_CHECK */
111
112 /* Only do a quick check. This is NOT standard compliant. */
113
114 static INLINE EGLBoolean
115 _eglCheckDisplayHandle(EGLDisplay dpy)
116 {
117 return ((_EGLDisplay *) dpy != NULL);
118 }
119
120
121 static INLINE EGLBoolean
122 _eglCheckResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy)
123 {
124 return (res->Display == dpy);
125 }
126
127
128 #endif /* _EGL_SKIP_HANDLE_CHECK */
129
130
131 /**
132 * Lookup a handle to find the linked display.
133 * Return NULL if the handle has no corresponding linked display.
134 */
135 static INLINE _EGLDisplay *
136 _eglLookupDisplay(EGLDisplay display)
137 {
138 _EGLDisplay *dpy = (_EGLDisplay *) display;
139 if (!_eglCheckDisplayHandle(display))
140 dpy = NULL;
141 return dpy;
142 }
143
144
145 /**
146 * Return the handle of a linked display, or EGL_NO_DISPLAY.
147 */
148 static INLINE EGLDisplay
149 _eglGetDisplayHandle(_EGLDisplay *dpy)
150 {
151 return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
152 }
153
154
155 /**
156 * Return true if the display is linked.
157 */
158 static INLINE EGLBoolean
159 _eglIsDisplayLinked(_EGLDisplay *dpy)
160 {
161 return (EGLBoolean) (_eglGetDisplayHandle(dpy) != EGL_NO_DISPLAY);
162 }
163
164
165 extern void
166 _eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy);
167
168
169 extern void
170 _eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
171
172
173 /**
174 * Return true if the resource is linked.
175 */
176 static INLINE EGLBoolean
177 _eglIsResourceLinked(_EGLResource *res)
178 {
179 return (res->Display != NULL);
180 }
181
182
183 /**
184 * Cast an unsigned int to a pointer.
185 */
186 static INLINE void *
187 _eglUIntToPointer(unsigned int v)
188 {
189 return (void *) ((uintptr_t) v);
190 }
191
192
193 /**
194 * Cast a pointer to an unsigned int. The pointer must be one that is
195 * returned by _eglUIntToPointer.
196 */
197 static INLINE unsigned int
198 _eglPointerToUInt(const void *p)
199 {
200 return (unsigned int) ((uintptr_t) p);
201 }
202
203
204 #endif /* EGLDISPLAY_INCLUDED */