egl: Cleanup _EGLDisplay initialization.
[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 #include "eglarray.h"
9
10
11 enum _egl_platform_type {
12 _EGL_PLATFORM_WINDOWS,
13 _EGL_PLATFORM_X11,
14 _EGL_PLATFORM_DRM,
15 _EGL_PLATFORM_FBDEV,
16
17 _EGL_NUM_PLATFORMS,
18 _EGL_INVALID_PLATFORM = -1
19 };
20 typedef enum _egl_platform_type _EGLPlatformType;
21
22
23 enum _egl_resource_type {
24 _EGL_RESOURCE_CONTEXT,
25 _EGL_RESOURCE_SURFACE,
26 _EGL_RESOURCE_IMAGE,
27 _EGL_RESOURCE_SYNC,
28
29 _EGL_NUM_RESOURCES
30 };
31 /* this cannot and need not go into egltypedefs.h */
32 typedef enum _egl_resource_type _EGLResourceType;
33
34
35 /**
36 * A resource of a display.
37 */
38 struct _egl_resource
39 {
40 /* which display the resource belongs to */
41 _EGLDisplay *Display;
42 EGLBoolean IsLinked;
43 EGLint RefCount;
44
45 /* used to link resources of the same type */
46 _EGLResource *Next;
47 };
48
49
50 /**
51 * Optional EGL extensions info.
52 */
53 struct _egl_extensions
54 {
55 EGLBoolean MESA_screen_surface;
56 EGLBoolean MESA_copy_context;
57 EGLBoolean MESA_drm_display;
58 EGLBoolean MESA_drm_image;
59
60 EGLBoolean KHR_image_base;
61 EGLBoolean KHR_image_pixmap;
62 EGLBoolean KHR_vg_parent_image;
63 EGLBoolean KHR_gl_texture_2D_image;
64 EGLBoolean KHR_gl_texture_cubemap_image;
65 EGLBoolean KHR_gl_texture_3D_image;
66 EGLBoolean KHR_gl_renderbuffer_image;
67
68 EGLBoolean KHR_reusable_sync;
69 EGLBoolean KHR_fence_sync;
70
71 EGLBoolean KHR_surfaceless_gles1;
72 EGLBoolean KHR_surfaceless_gles2;
73 EGLBoolean KHR_surfaceless_opengl;
74
75 EGLBoolean NOK_swap_region;
76 EGLBoolean NOK_texture_from_pixmap;
77 };
78
79
80 struct _egl_display
81 {
82 /* used to link displays */
83 _EGLDisplay *Next;
84
85 _EGLMutex Mutex;
86
87 _EGLPlatformType Platform; /**< The type of the platform display */
88 void *PlatformDisplay; /**< A pointer to the platform display */
89
90 _EGLDriver *Driver; /**< Matched driver of the display */
91 EGLBoolean Initialized; /**< True if the display is initialized */
92
93 /* these fields are set by the driver during init */
94 void *DriverData; /**< Driver private data */
95 EGLint VersionMajor; /**< EGL major version */
96 EGLint VersionMinor; /**< EGL minor version */
97 EGLint ClientAPIs; /**< Bitmask of APIs supported (EGL_xxx_BIT) */
98 _EGLExtensions Extensions; /**< Extensions supported */
99
100 /* these fields are derived from above */
101 char VersionString[1000]; /**< EGL_VERSION */
102 char ClientAPIsString[1000]; /**< EGL_CLIENT_APIS */
103 char ExtensionsString[_EGL_MAX_EXTENSIONS_LEN]; /**< EGL_EXTENSIONS */
104
105 _EGLArray *Screens;
106 _EGLArray *Configs;
107
108 /* lists of resources */
109 _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
110 };
111
112
113 extern _EGLPlatformType
114 _eglGetNativePlatform(void);
115
116
117 extern void
118 _eglFiniDisplay(void);
119
120
121 extern _EGLDisplay *
122 _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy);
123
124
125 PUBLIC void
126 _eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy);
127
128
129 PUBLIC void
130 _eglCleanupDisplay(_EGLDisplay *disp);
131
132
133 extern EGLBoolean
134 _eglCheckDisplayHandle(EGLDisplay dpy);
135
136
137 PUBLIC EGLBoolean
138 _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy);
139
140
141 /**
142 * Lookup a handle to find the linked display.
143 * Return NULL if the handle has no corresponding linked display.
144 */
145 static INLINE _EGLDisplay *
146 _eglLookupDisplay(EGLDisplay display)
147 {
148 _EGLDisplay *dpy = (_EGLDisplay *) display;
149 if (!_eglCheckDisplayHandle(display))
150 dpy = NULL;
151 return dpy;
152 }
153
154
155 /**
156 * Return the handle of a linked display, or EGL_NO_DISPLAY.
157 */
158 static INLINE EGLDisplay
159 _eglGetDisplayHandle(_EGLDisplay *dpy)
160 {
161 return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
162 }
163
164
165 extern void
166 _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *dpy);
167
168
169 PUBLIC void
170 _eglGetResource(_EGLResource *res);
171
172
173 PUBLIC EGLBoolean
174 _eglPutResource(_EGLResource *res);
175
176
177 extern void
178 _eglLinkResource(_EGLResource *res, _EGLResourceType type);
179
180
181 extern void
182 _eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
183
184
185 /**
186 * Return true if the resource is linked.
187 */
188 static INLINE EGLBoolean
189 _eglIsResourceLinked(_EGLResource *res)
190 {
191 return res->IsLinked;
192 }
193
194
195 #endif /* EGLDISPLAY_INCLUDED */