• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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    /* attributes set by eglSurfaceAttrib */
139    EGLint MipmapLevel;
140    EGLenum MultisampleResolve;
141    EGLenum SwapBehavior;
142 
143    EGLint HorizontalResolution, VerticalResolution;
144    EGLint AspectRatio;
145 
146    EGLint SwapInterval;
147 
148    /* EGL_KHR_partial_update
149     * True if the damage region is already set
150     * between frame boundaries.
151     */
152    EGLBoolean SetDamageRegionCalled;
153 
154    /* EGL_KHR_partial_update
155     * True if the buffer age is read by the client
156     * between frame boundaries.
157     */
158    EGLBoolean BufferAgeRead;
159 
160    /* True if the surface is bound to an OpenGL ES texture */
161    EGLBoolean BoundToTexture;
162 
163    EGLBoolean PostSubBufferSupportedNV;
164 
165    EGLBoolean ProtectedContent;
166 
167    EGLBoolean PresentOpaque;
168 
169    struct _egl_hdr_metadata HdrMetadata;
170 
171    void *NativeSurface;
172 };
173 
174 extern EGLBoolean
175 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
176                 _EGLConfig *config, const EGLint *attrib_list,
177                 void *native_surface);
178 
179 extern EGLBoolean
180 _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
181                  EGLint *value);
182 
183 extern EGLBoolean
184 _eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
185                   EGLint value);
186 
187 extern EGLBoolean
188 _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
189 
190 extern EGLBoolean
191 _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
192 
193 extern EGLBoolean
194 _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf);
195 
196 extern EGLBoolean
197 _eglSurfaceInSharedBufferMode(_EGLSurface *surf);
198 
199 /**
200  * Increment reference count for the surface.
201  */
202 static inline _EGLSurface *
_eglGetSurface(_EGLSurface * surf)203 _eglGetSurface(_EGLSurface *surf)
204 {
205    if (surf)
206       _eglGetResource(&surf->Resource);
207    return surf;
208 }
209 
210 /**
211  * Decrement reference count for the surface.
212  */
213 static inline EGLBoolean
_eglPutSurface(_EGLSurface * surf)214 _eglPutSurface(_EGLSurface *surf)
215 {
216    return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
217 }
218 
219 /**
220  * Link a surface to its display and return the handle of the link.
221  * The handle can be passed to client directly.
222  */
223 static inline EGLSurface
_eglLinkSurface(_EGLSurface * surf)224 _eglLinkSurface(_EGLSurface *surf)
225 {
226    _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
227    return (EGLSurface)surf;
228 }
229 
230 /**
231  * Unlink a linked surface from its display.
232  * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
233  */
234 static inline void
_eglUnlinkSurface(_EGLSurface * surf)235 _eglUnlinkSurface(_EGLSurface *surf)
236 {
237    _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
238 }
239 
240 /**
241  * Lookup a handle to find the linked surface.
242  * Return NULL if the handle has no corresponding linked surface.
243  */
244 static inline _EGLSurface *
_eglLookupSurface(EGLSurface surface,_EGLDisplay * disp)245 _eglLookupSurface(EGLSurface surface, _EGLDisplay *disp)
246 {
247    _EGLSurface *surf = (_EGLSurface *)surface;
248    if (!disp || !_eglCheckResource((void *)surf, _EGL_RESOURCE_SURFACE, disp))
249       surf = NULL;
250    return surf;
251 }
252 
253 /**
254  * Return the handle of a linked surface, or EGL_NO_SURFACE.
255  */
256 static inline EGLSurface
_eglGetSurfaceHandle(_EGLSurface * surf)257 _eglGetSurfaceHandle(_EGLSurface *surf)
258 {
259    _EGLResource *res = (_EGLResource *)surf;
260    return (res && _eglIsResourceLinked(res)) ? (EGLSurface)surf
261                                              : EGL_NO_SURFACE;
262 }
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif /* EGLSURFACE_INCLUDED */
269