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