blob: c57159e610744aec2c970261774f301caf3abdfb [file] [log] [blame]
Chia-I Wuf2001df2011-07-02 17:57:30 +09001/**************************************************************************
2 *
José Fonseca87712852014-01-17 16:27:50 +00003 * Copyright 2008 VMware, Inc.
Chia-I Wuf2001df2011-07-02 17:57:30 +09004 * 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
Brian Pauladbff7e2005-04-22 21:09:39 +000031#ifndef EGLSURFACE_INCLUDED
32#define EGLSURFACE_INCLUDED
33
Emil Velikov7bd16932015-02-28 16:35:22 +000034#include "c99_compat.h"
Brian Pauladbff7e2005-04-22 21:09:39 +000035
36#include "egltypedefs.h"
Chia-I Wuecb3b312010-01-24 20:32:34 +080037#include "egldisplay.h"
Brian Pauladbff7e2005-04-22 21:09:39 +000038
39
Alexander von Gluck IV83620682015-05-13 17:13:37 -050040#ifdef __cplusplus
41extern "C" {
42#endif
43
Tapani Pälli799b3d12018-04-05 13:02:36 +030044struct _egl_xy
45{
46 EGLint x;
47 EGLint y;
48};
49
50struct _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
Brian Pauladbff7e2005-04-22 21:09:39 +000062/**
63 * "Base" class for device driver surfaces.
64 */
65struct _egl_surface
66{
Chia-I Wuecb3b312010-01-24 20:32:34 +080067 /* A surface is a display resource */
68 _EGLResource Resource;
Chia-I Wu18457cb2009-07-17 11:48:27 -060069
Chia-I Wu00e17902010-01-30 22:45:54 +080070 /* The context that is currently bound to the surface */
71 _EGLContext *CurrentContext;
Brian Pauladbff7e2005-04-22 21:09:39 +000072
Chia-I Wu07ee0132009-08-03 11:34:37 -060073 _EGLConfig *Config;
74
Brian Pauladbff7e2005-04-22 21:09:39 +000075 EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
Chia-I Wueb961f82010-01-31 17:56:30 +080076
Chad Versace23c86c72017-05-04 17:46:33 -070077 /* 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
Chia-I Wueb961f82010-01-31 17:56:30 +080082 /* attributes set by attribute list */
Brian Pauladbff7e2005-04-22 21:09:39 +000083 EGLint Width, Height;
Chia-I Wueb961f82010-01-31 17:56:30 +080084 EGLenum TextureFormat;
85 EGLenum TextureTarget;
86 EGLBoolean MipmapTexture;
87 EGLBoolean LargestPbuffer;
Chad Versacef48f9a72018-04-07 14:23:48 -070088
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 *
Chad Versace3dc22382018-04-30 22:32:25 -070099 * 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 *
Chad Versacef48f9a72018-04-07 14:23:48 -0700113 * 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.
Chad Versace3dc22382018-04-30 22:32:25 -0700125 *
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.
Chad Versacef48f9a72018-04-07 14:23:48 -0700138 */
139 EGLenum ActiveRenderBuffer;
140
Chia-I Wueb961f82010-01-31 17:56:30 +0800141 EGLenum VGAlphaFormat;
142 EGLenum VGColorspace;
Marek Olšákc2c2e9a2015-06-10 02:49:29 +0200143 EGLenum GLColorspace;
Chia-I Wueb961f82010-01-31 17:56:30 +0800144
145 /* attributes set by eglSurfaceAttrib */
146 EGLint MipmapLevel;
147 EGLenum MultisampleResolve;
148 EGLenum SwapBehavior;
149
150 EGLint HorizontalResolution, VerticalResolution;
151 EGLint AspectRatio;
152
Brian Pauladbff7e2005-04-22 21:09:39 +0000153 EGLint SwapInterval;
154
Harish Krupo98275472017-06-09 20:13:34 +0530155 /* 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
Chia-I Wu00e17902010-01-30 22:45:54 +0800167 /* True if the surface is bound to an OpenGL ES texture */
168 EGLBoolean BoundToTexture;
Fredrik Höglund7d46b452011-12-14 21:24:09 +0100169
170 EGLBoolean PostSubBufferSupportedNV;
Tapani Pälli799b3d12018-04-05 13:02:36 +0300171
172 struct _egl_hdr_metadata HdrMetadata;
Paulo Zanoni04ecda32019-05-01 15:42:26 -0700173
174 void *NativeSurface;
Brian Pauladbff7e2005-04-22 21:09:39 +0000175};
176
177
Emil Velikovdd438ae2015-02-28 17:20:01 +0000178extern EGLBoolean
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000179_eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
Paulo Zanoni04ecda32019-05-01 15:42:26 -0700180 _EGLConfig *config, const EGLint *attrib_list,
181 void *native_surface);
Brian Pauladbff7e2005-04-22 21:09:39 +0000182
183
Brian Pauladbff7e2005-04-22 21:09:39 +0000184extern EGLBoolean
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200185_eglQuerySurface(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value);
Brian Pauladbff7e2005-04-22 21:09:39 +0000186
187
Brian Pauladbff7e2005-04-22 21:09:39 +0000188extern EGLBoolean
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200189_eglSurfaceAttrib(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint value);
Brian Pauladbff7e2005-04-22 21:09:39 +0000190
191
Emil Velikovdd438ae2015-02-28 17:20:01 +0000192extern EGLBoolean
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200193_eglBindTexImage(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
Brian Pauladbff7e2005-04-22 21:09:39 +0000194
Emil Velikovdd438ae2015-02-28 17:20:01 +0000195extern EGLBoolean
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200196_eglReleaseTexImage(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
Emil Velikov9b42fd12014-02-18 03:04:03 +0000197
Brian Pauladbff7e2005-04-22 21:09:39 +0000198
199extern EGLBoolean
Eric Engestrom9c6fa942020-07-31 01:38:41 +0200200_eglSwapInterval(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint interval);
Brian Pauladbff7e2005-04-22 21:09:39 +0000201
Chad Versace3dc22382018-04-30 22:32:25 -0700202extern EGLBoolean
203_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf);
204
205extern EGLBoolean
206_eglSurfaceInSharedBufferMode(_EGLSurface *surf);
Brian Pauladbff7e2005-04-22 21:09:39 +0000207
Chia-I Wu07ee0132009-08-03 11:34:37 -0600208/**
Chia-I Wudc4f8452010-10-23 11:59:03 +0800209 * Increment reference count for the surface.
210 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000211static inline _EGLSurface *
Chia-I Wudc4f8452010-10-23 11:59:03 +0800212_eglGetSurface(_EGLSurface *surf)
213{
214 if (surf)
215 _eglGetResource(&surf->Resource);
216 return surf;
217}
218
219
220/**
221 * Decrement reference count for the surface.
222 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000223static inline EGLBoolean
Chia-I Wudc4f8452010-10-23 11:59:03 +0800224_eglPutSurface(_EGLSurface *surf)
225{
226 return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
227}
228
229
230/**
Chia-I Wu4ce33ec2010-10-23 00:37:19 +0800231 * Link a surface to its display and return the handle of the link.
Chia-I Wuecb3b312010-01-24 20:32:34 +0800232 * The handle can be passed to client directly.
233 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000234static inline EGLSurface
Chia-I Wu4ce33ec2010-10-23 00:37:19 +0800235_eglLinkSurface(_EGLSurface *surf)
Chia-I Wub4d2c972010-01-23 22:57:23 +0800236{
Chia-I Wu4ce33ec2010-10-23 00:37:19 +0800237 _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
Chia-I Wuecb3b312010-01-24 20:32:34 +0800238 return (EGLSurface) surf;
Chia-I Wub4d2c972010-01-23 22:57:23 +0800239}
240
241
Chia-I Wuecb3b312010-01-24 20:32:34 +0800242/**
243 * Unlink a linked surface from its display.
244 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
245 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000246static inline void
Chia-I Wuecb3b312010-01-24 20:32:34 +0800247_eglUnlinkSurface(_EGLSurface *surf)
248{
249 _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
250}
Chia-I Wub4d2c972010-01-23 22:57:23 +0800251
252
253/**
254 * Lookup a handle to find the linked surface.
255 * Return NULL if the handle has no corresponding linked surface.
256 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000257static inline _EGLSurface *
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000258_eglLookupSurface(EGLSurface surface, _EGLDisplay *disp)
Chia-I Wub4d2c972010-01-23 22:57:23 +0800259{
260 _EGLSurface *surf = (_EGLSurface *) surface;
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000261 if (!disp || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, disp))
Chia-I Wub4d2c972010-01-23 22:57:23 +0800262 surf = NULL;
263 return surf;
264}
265
266
267/**
268 * Return the handle of a linked surface, or EGL_NO_SURFACE.
269 */
Emil Velikov7bd16932015-02-28 16:35:22 +0000270static inline EGLSurface
Chia-I Wub4d2c972010-01-23 22:57:23 +0800271_eglGetSurfaceHandle(_EGLSurface *surf)
272{
Chia-I Wuecb3b312010-01-24 20:32:34 +0800273 _EGLResource *res = (_EGLResource *) surf;
274 return (res && _eglIsResourceLinked(res)) ?
275 (EGLSurface) surf : EGL_NO_SURFACE;
Chia-I Wub4d2c972010-01-23 22:57:23 +0800276}
277
278
Alexander von Gluck IV83620682015-05-13 17:13:37 -0500279#ifdef __cplusplus
280}
281#endif
282
Brian Pauladbff7e2005-04-22 21:09:39 +0000283#endif /* EGLSURFACE_INCLUDED */