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