egl: Make eglGetDisplay atomic.
[mesa.git] / src / egl / main / egldisplay.h
1 #ifndef EGLDISPLAY_INCLUDED
2 #define EGLDISPLAY_INCLUDED
3
4
5 #include "egltypedefs.h"
6 #include "egldefines.h"
7 #include "eglmutex.h"
8
9
10 enum _egl_resource_type {
11 _EGL_RESOURCE_CONTEXT,
12 _EGL_RESOURCE_SURFACE,
13 _EGL_RESOURCE_IMAGE,
14
15 _EGL_NUM_RESOURCES
16 };
17
18
19 /**
20 * A resource of a display.
21 */
22 struct _egl_resource
23 {
24 /* which display the resource belongs to */
25 _EGLDisplay *Display;
26 EGLBoolean IsLinked;
27
28 /* used to link resources of the same type */
29 _EGLResource *Next;
30 };
31
32
33 /**
34 * Optional EGL extensions info.
35 */
36 struct _egl_extensions
37 {
38 EGLBoolean MESA_screen_surface;
39 EGLBoolean MESA_copy_context;
40 EGLBoolean KHR_image_base;
41 EGLBoolean KHR_image_pixmap;
42 EGLBoolean KHR_vg_parent_image;
43 EGLBoolean KHR_gl_texture_2D_image;
44 EGLBoolean KHR_gl_texture_cubemap_image;
45 EGLBoolean KHR_gl_texture_3D_image;
46 EGLBoolean KHR_gl_renderbuffer_image;
47
48 char String[_EGL_MAX_EXTENSIONS_LEN];
49 };
50
51
52 struct _egl_display
53 {
54 /* used to link displays */
55 _EGLDisplay *Next;
56
57 _EGLMutex Mutex;
58
59 EGLNativeDisplayType NativeDisplay;
60
61 EGLBoolean Initialized; /**< True if the display is initialized */
62 _EGLDriver *Driver;
63 void *DriverData; /* private to driver */
64
65 int APImajor, APIminor; /**< as returned by eglInitialize() */
66 char Version[1000]; /**< initialized from APImajor/minor, DriverName */
67
68 /** Bitmask of supported APIs (EGL_xx_BIT) set by the driver during init */
69 EGLint ClientAPIsMask;
70 char ClientAPIs[1000]; /**< updated by eglQueryString */
71
72 _EGLExtensions Extensions;
73
74 EGLint NumScreens;
75 _EGLScreen **Screens; /* array [NumScreens] */
76
77 EGLint MaxConfigs;
78 EGLint NumConfigs;
79 _EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */
80
81 /* lists of resources */
82 _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
83 };
84
85
86 extern void
87 _eglFiniDisplay(void);
88
89
90 extern _EGLDisplay *
91 _eglFindDisplay(EGLNativeDisplayType displayName);
92
93
94 PUBLIC void
95 _eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy);
96
97
98 PUBLIC void
99 _eglCleanupDisplay(_EGLDisplay *disp);
100
101
102 #ifndef _EGL_SKIP_HANDLE_CHECK
103
104
105 extern EGLBoolean
106 _eglCheckDisplayHandle(EGLDisplay dpy);
107
108
109 PUBLIC EGLBoolean
110 _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy);
111
112
113 #else /* !_EGL_SKIP_HANDLE_CHECK */
114
115 /* Only do a quick check. This is NOT standard compliant. */
116
117 static INLINE EGLBoolean
118 _eglCheckDisplayHandle(EGLDisplay dpy)
119 {
120 return ((_EGLDisplay *) dpy != NULL);
121 }
122
123
124 static INLINE EGLBoolean
125 _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy);
126 {
127 return (((_EGLResource *) res)->Display == dpy);
128 }
129
130
131 #endif /* _EGL_SKIP_HANDLE_CHECK */
132
133
134 /**
135 * Lookup a handle to find the linked display.
136 * Return NULL if the handle has no corresponding linked display.
137 */
138 static INLINE _EGLDisplay *
139 _eglLookupDisplay(EGLDisplay display)
140 {
141 _EGLDisplay *dpy = (_EGLDisplay *) display;
142 if (!_eglCheckDisplayHandle(display))
143 dpy = NULL;
144 return dpy;
145 }
146
147
148 /**
149 * Return the handle of a linked display, or EGL_NO_DISPLAY.
150 */
151 static INLINE EGLDisplay
152 _eglGetDisplayHandle(_EGLDisplay *dpy)
153 {
154 return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
155 }
156
157
158 extern void
159 _eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy);
160
161
162 extern void
163 _eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
164
165
166 /**
167 * Return true if the resource is linked.
168 */
169 static INLINE EGLBoolean
170 _eglIsResourceLinked(_EGLResource *res)
171 {
172 return res->IsLinked;
173 }
174
175
176 #endif /* EGLDISPLAY_INCLUDED */