1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <[email protected]>
5 * Copyright 2010 LunarG, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30 #ifndef EGLSURFACE_INCLUDED
31 #define EGLSURFACE_INCLUDED
32
33 #include "egldisplay.h"
34 #include "egltypedefs.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 struct _egl_xy {
41 EGLint x;
42 EGLint y;
43 };
44
45 struct _egl_hdr_metadata {
46 struct _egl_xy display_primary_r;
47 struct _egl_xy display_primary_g;
48 struct _egl_xy display_primary_b;
49 struct _egl_xy white_point;
50 EGLint max_luminance;
51 EGLint min_luminance;
52 EGLint max_cll;
53 EGLint max_fall;
54 };
55
56 /**
57 * "Base" class for device driver surfaces.
58 */
59 struct _egl_surface {
60 /* A surface is a display resource */
61 _EGLResource Resource;
62
63 /* The context that is currently bound to the surface */
64 _EGLContext *CurrentContext;
65
66 _EGLConfig *Config;
67
68 EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
69
70 /* The native surface is lost. The EGL spec requires certain functions
71 * to generate EGL_BAD_NATIVE_WINDOW when given this surface.
72 */
73 EGLBoolean Lost;
74
75 /* attributes set by attribute list */
76 EGLint Width, Height;
77 EGLenum TextureFormat;
78 EGLenum TextureTarget;
79 EGLBoolean MipmapTexture;
80 EGLBoolean LargestPbuffer;
81
82 /**
83 * Value of EGL_RENDER_BUFFER selected at creation.
84 *
85 * The user may select, for window surfaces, the EGL_RENDER_BUFFER through
86 * the attribute list of eglCreateWindowSurface(). The EGL spec allows the
87 * implementation to ignore request, though; hence why we maintain both
88 * RequestedRenderBuffer and ActiveRenderBuffer. For pbuffer and pixmap
89 * surfaces, the EGL spec hard-codes the EGL_RENDER_BUFFER value and the
90 * user must not provide it in the attribute list.
91 *
92 * Normally, the attribute is immutable and after surface creation.
93 * However, EGL_KHR_mutable_render_buffer allows the user to change it in
94 * window surfaces via eglSurfaceAttrib, in which case
95 * eglQuerySurface(EGL_RENDER_BUFFER) will immediately afterwards return
96 * the requested value but the actual render buffer used by the context
97 * does not change until completion of the next eglSwapBuffers call.
98 *
99 * From the EGL_KHR_mutable_render_buffer spec (v12):
100 *
101 * Querying EGL_RENDER_BUFFER returns the buffer which client API
102 * rendering is requested to use. For a window surface, this is the
103 * attribute value specified when the surface was created or last set
104 * via eglSurfaceAttrib.
105 *
106 * eglQueryContext(EGL_RENDER_BUFFER) ignores this.
107 */
108 EGLenum RequestedRenderBuffer;
109
110 /**
111 * The EGL_RENDER_BUFFER in use by the context.
112 *
113 * This is valid only when bound as the draw surface. This may differ from
114 * the RequestedRenderBuffer.
115 *
116 * Refer to eglQueryContext(EGL_RENDER_BUFFER) in the EGL spec.
117 * eglQuerySurface(EGL_RENDER_BUFFER) ignores this.
118 *
119 * If a window surface is bound as the draw surface and has a pending,
120 * user-requested change to EGL_RENDER_BUFFER, then the next eglSwapBuffers
121 * will flush the pending change. (The flush of EGL_RENDER_BUFFER state may
122 * occur without the implicit glFlush induced by eglSwapBuffers). The spec
123 * requires that the flush occur at that time and nowhere else. During the
124 * state-flush, we copy RequestedRenderBuffer to ActiveRenderBuffer.
125 *
126 * From the EGL_KHR_mutable_render_buffer spec (v12):
127 *
128 * If [...] there is a pending change to the EGL_RENDER_BUFFER
129 * attribute, eglSwapBuffers performs an implicit flush operation on the
130 * context and effects the attribute change.
131 */
132 EGLenum ActiveRenderBuffer;
133
134 EGLenum VGAlphaFormat;
135 EGLenum VGColorspace;
136 EGLenum GLColorspace;
137
138 /* EGL_EXT_surface_compression
139 * Value of EGL_SURFACE_COMPRESSION_EXT attribute selected at creation.
140 */
141 EGLint CompressionRate;
142
143 /* attributes set by eglSurfaceAttrib */
144 EGLint MipmapLevel;
145 EGLenum MultisampleResolve;
146 EGLenum SwapBehavior;
147
148 EGLint HorizontalResolution, VerticalResolution;
149 EGLint AspectRatio;
150
151 EGLint SwapInterval;
152
153 /* EGL_KHR_partial_update
154 * True if the damage region is already set
155 * between frame boundaries.
156 */
157 EGLBoolean SetDamageRegionCalled;
158
159 /* EGL_KHR_partial_update
160 * True if the buffer age is read by the client
161 * between frame boundaries.
162 */
163 EGLBoolean BufferAgeRead;
164
165 /* True if the surface is bound to an OpenGL ES texture */
166 EGLBoolean BoundToTexture;
167
168 EGLBoolean PostSubBufferSupportedNV;
169
170 EGLBoolean ProtectedContent;
171
172 EGLBoolean PresentOpaque;
173
174 struct _egl_hdr_metadata HdrMetadata;
175
176 void *NativeSurface;
177 };
178
179 extern EGLBoolean
180 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
181 _EGLConfig *config, const EGLint *attrib_list,
182 void *native_surface);
183
184 extern EGLBoolean
185 _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
186 EGLint *value);
187
188 extern EGLBoolean
189 _eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
190 EGLint value);
191
192 extern EGLBoolean
193 _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
194
195 extern EGLBoolean
196 _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
197
198 extern EGLBoolean
199 _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf);
200
201 extern EGLBoolean
202 _eglSurfaceInSharedBufferMode(_EGLSurface *surf);
203
204 /**
205 * Increment reference count for the surface.
206 */
207 static inline _EGLSurface *
_eglGetSurface(_EGLSurface * surf)208 _eglGetSurface(_EGLSurface *surf)
209 {
210 if (surf)
211 _eglGetResource(&surf->Resource);
212 return surf;
213 }
214
215 /**
216 * Decrement reference count for the surface.
217 */
218 static inline EGLBoolean
_eglPutSurface(_EGLSurface * surf)219 _eglPutSurface(_EGLSurface *surf)
220 {
221 return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
222 }
223
224 /**
225 * Link a surface to its display and return the handle of the link.
226 * The handle can be passed to client directly.
227 */
228 static inline EGLSurface
_eglLinkSurface(_EGLSurface * surf)229 _eglLinkSurface(_EGLSurface *surf)
230 {
231 _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
232 return (EGLSurface)surf;
233 }
234
235 /**
236 * Unlink a linked surface from its display.
237 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
238 */
239 static inline void
_eglUnlinkSurface(_EGLSurface * surf)240 _eglUnlinkSurface(_EGLSurface *surf)
241 {
242 _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
243 }
244
245 /**
246 * Lookup a handle to find the linked surface.
247 * Return NULL if the handle has no corresponding linked surface.
248 */
249 static inline _EGLSurface *
_eglLookupSurface(EGLSurface surface,_EGLDisplay * disp)250 _eglLookupSurface(EGLSurface surface, _EGLDisplay *disp)
251 {
252 _EGLSurface *surf = (_EGLSurface *)surface;
253 if (!disp || !_eglCheckResource((void *)surf, _EGL_RESOURCE_SURFACE, disp))
254 surf = NULL;
255 return surf;
256 }
257
258 /**
259 * Return the handle of a linked surface, or EGL_NO_SURFACE.
260 */
261 static inline EGLSurface
_eglGetSurfaceHandle(_EGLSurface * surf)262 _eglGetSurfaceHandle(_EGLSurface *surf)
263 {
264 _EGLResource *res = (_EGLResource *)surf;
265 return (res && _eglIsResourceLinked(res)) ? (EGLSurface)surf
266 : EGL_NO_SURFACE;
267 }
268
269 #ifdef __cplusplus
270 }
271 #endif
272
273 #endif /* EGLSURFACE_INCLUDED */
274