1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
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
31 #ifndef EGLSURFACE_INCLUDED
32 #define EGLSURFACE_INCLUDED
33
34 #include "c99_compat.h"
35
36 #include "egltypedefs.h"
37 #include "egldisplay.h"
38
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 struct _egl_xy
45 {
46 EGLint x;
47 EGLint y;
48 };
49
50 struct _egl_hdr_metadata
51 {
52 struct _egl_xy display_primary_r;
53 struct _egl_xy display_primary_g;
54 struct _egl_xy display_primary_b;
55 struct _egl_xy white_point;
56 EGLint max_luminance;
57 EGLint min_luminance;
58 EGLint max_cll;
59 EGLint max_fall;
60 };
61
62 /**
63 * "Base" class for device driver surfaces.
64 */
65 struct _egl_surface
66 {
67 /* A surface is a display resource */
68 _EGLResource Resource;
69
70 /* The context that is currently bound to the surface */
71 _EGLContext *CurrentContext;
72
73 _EGLConfig *Config;
74
75 EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
76
77 /* The native surface is lost. The EGL spec requires certain functions
78 * to generate EGL_BAD_NATIVE_WINDOW when given this surface.
79 */
80 EGLBoolean Lost;
81
82 /* attributes set by attribute list */
83 EGLint Width, Height;
84 EGLenum TextureFormat;
85 EGLenum TextureTarget;
86 EGLBoolean MipmapTexture;
87 EGLBoolean LargestPbuffer;
88
89 /**
90 * Value of EGL_RENDER_BUFFER selected at creation.
91 *
92 * The user may select, for window surfaces, the EGL_RENDER_BUFFER through
93 * the attribute list of eglCreateWindowSurface(). The EGL spec allows the
94 * implementation to ignore request, though; hence why we maintain both
95 * RequestedRenderBuffer and ActiveRenderBuffer. For pbuffer and pixmap
96 * surfaces, the EGL spec hard-codes the EGL_RENDER_BUFFER value and the
97 * user must not provide it in the attribute list.
98 *
99 * Normally, the attribute is immutable and after surface creation.
100 * However, EGL_KHR_mutable_render_buffer allows the user to change it in
101 * window surfaces via eglSurfaceAttrib, in which case
102 * eglQuerySurface(EGL_RENDER_BUFFER) will immediately afterwards return
103 * the requested value but the actual render buffer used by the context
104 * does not change until completion of the next eglSwapBuffers call.
105 *
106 * From the EGL_KHR_mutable_render_buffer spec (v12):
107 *
108 * Querying EGL_RENDER_BUFFER returns the buffer which client API
109 * rendering is requested to use. For a window surface, this is the
110 * attribute value specified when the surface was created or last set
111 * via eglSurfaceAttrib.
112 *
113 * eglQueryContext(EGL_RENDER_BUFFER) ignores this.
114 */
115 EGLenum RequestedRenderBuffer;
116
117 /**
118 * The EGL_RENDER_BUFFER in use by the context.
119 *
120 * This is valid only when bound as the draw surface. This may differ from
121 * the RequestedRenderBuffer.
122 *
123 * Refer to eglQueryContext(EGL_RENDER_BUFFER) in the EGL spec.
124 * eglQuerySurface(EGL_RENDER_BUFFER) ignores this.
125 *
126 * If a window surface is bound as the draw surface and has a pending,
127 * user-requested change to EGL_RENDER_BUFFER, then the next eglSwapBuffers
128 * will flush the pending change. (The flush of EGL_RENDER_BUFFER state may
129 * occur without the implicit glFlush induced by eglSwapBuffers). The spec
130 * requires that the flush occur at that time and nowhere else. During the
131 * state-flush, we copy RequestedRenderBuffer to ActiveRenderBuffer.
132 *
133 * From the EGL_KHR_mutable_render_buffer spec (v12):
134 *
135 * If [...] there is a pending change to the EGL_RENDER_BUFFER
136 * attribute, eglSwapBuffers performs an implicit flush operation on the
137 * context and effects the attribute change.
138 */
139 EGLenum ActiveRenderBuffer;
140
141 EGLenum VGAlphaFormat;
142 EGLenum VGColorspace;
143 EGLenum GLColorspace;
144
145 /* attributes set by eglSurfaceAttrib */
146 EGLint MipmapLevel;
147 EGLenum MultisampleResolve;
148 EGLenum SwapBehavior;
149
150 EGLint HorizontalResolution, VerticalResolution;
151 EGLint AspectRatio;
152
153 EGLint SwapInterval;
154
155 /* EGL_KHR_partial_update
156 * True if the damage region is already set
157 * between frame boundaries.
158 */
159 EGLBoolean SetDamageRegionCalled;
160
161 /* EGL_KHR_partial_update
162 * True if the buffer age is read by the client
163 * between frame boundaries.
164 */
165 EGLBoolean BufferAgeRead;
166
167 /* True if the surface is bound to an OpenGL ES texture */
168 EGLBoolean BoundToTexture;
169
170 EGLBoolean PostSubBufferSupportedNV;
171
172 EGLBoolean ProtectedContent;
173
174 EGLBoolean PresentOpaque;
175
176 struct _egl_hdr_metadata HdrMetadata;
177
178 void *NativeSurface;
179 };
180
181
182 extern EGLBoolean
183 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
184 _EGLConfig *config, const EGLint *attrib_list,
185 void *native_surface);
186
187
188 extern EGLBoolean
189 _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value);
190
191
192 extern EGLBoolean
193 _eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint value);
194
195
196 extern EGLBoolean
197 _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
198
199 extern EGLBoolean
200 _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
201
202
203 extern EGLBoolean
204 _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf);
205
206 extern EGLBoolean
207 _eglSurfaceInSharedBufferMode(_EGLSurface *surf);
208
209 /**
210 * Increment reference count for the surface.
211 */
212 static inline _EGLSurface *
_eglGetSurface(_EGLSurface * surf)213 _eglGetSurface(_EGLSurface *surf)
214 {
215 if (surf)
216 _eglGetResource(&surf->Resource);
217 return surf;
218 }
219
220
221 /**
222 * Decrement reference count for the surface.
223 */
224 static inline EGLBoolean
_eglPutSurface(_EGLSurface * surf)225 _eglPutSurface(_EGLSurface *surf)
226 {
227 return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
228 }
229
230
231 /**
232 * Link a surface to its display and return the handle of the link.
233 * The handle can be passed to client directly.
234 */
235 static inline EGLSurface
_eglLinkSurface(_EGLSurface * surf)236 _eglLinkSurface(_EGLSurface *surf)
237 {
238 _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
239 return (EGLSurface) surf;
240 }
241
242
243 /**
244 * Unlink a linked surface from its display.
245 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
246 */
247 static inline void
_eglUnlinkSurface(_EGLSurface * surf)248 _eglUnlinkSurface(_EGLSurface *surf)
249 {
250 _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
251 }
252
253
254 /**
255 * Lookup a handle to find the linked surface.
256 * Return NULL if the handle has no corresponding linked surface.
257 */
258 static inline _EGLSurface *
_eglLookupSurface(EGLSurface surface,_EGLDisplay * disp)259 _eglLookupSurface(EGLSurface surface, _EGLDisplay *disp)
260 {
261 _EGLSurface *surf = (_EGLSurface *) surface;
262 if (!disp || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, disp))
263 surf = NULL;
264 return surf;
265 }
266
267
268 /**
269 * Return the handle of a linked surface, or EGL_NO_SURFACE.
270 */
271 static inline EGLSurface
_eglGetSurfaceHandle(_EGLSurface * surf)272 _eglGetSurfaceHandle(_EGLSurface *surf)
273 {
274 _EGLResource *res = (_EGLResource *) surf;
275 return (res && _eglIsResourceLinked(res)) ?
276 (EGLSurface) surf : EGL_NO_SURFACE;
277 }
278
279
280 #ifdef __cplusplus
281 }
282 #endif
283
284 #endif /* EGLSURFACE_INCLUDED */
285