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