| 1 |
/************************************************************************** |
| 2 |
* |
| 3 |
* Copyright 2008 VMware, Inc. |
| 4 |
* Copyright 2009-2010 Chia-I Wu <[email protected]> |
| 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 |
/* EGL_EXT_surface_compression |
| 139 |
* Value of EGL_SURFACE_COMPRESSION_EXT attribute selected at creation. |
| 140 |
*/ |
| 141 |
EGLint CompressionRate; |
| 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 ProtectedContent; |
| 169 |
|
| 170 |
EGLBoolean PresentOpaque; |
| 171 |
|
| 172 |
struct _egl_hdr_metadata HdrMetadata; |
| 173 |
|
| 174 |
void *NativeSurface; |
| 175 |
}; |
| 176 |
|
| 177 |
extern EGLBoolean |
| 178 |
_eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, |
| 179 |
_EGLConfig *config, const EGLint *attrib_list, |
| 180 |
void *native_surface); |
| 181 |
|
| 182 |
extern EGLBoolean |
| 183 |
_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, |
| 184 |
EGLint *value); |
| 185 |
|
| 186 |
extern EGLBoolean |
| 187 |
_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, |
| 188 |
EGLint value); |
| 189 |
|
| 190 |
extern EGLBoolean |
| 191 |
_eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); |
| 192 |
|
| 193 |
extern EGLBoolean |
| 194 |
_eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); |
| 195 |
|
| 196 |
extern EGLBoolean |
| 197 |
_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf); |
| 198 |
|
| 199 |
extern EGLBoolean |
| 200 |
_eglSurfaceInSharedBufferMode(_EGLSurface *surf); |
| 201 |
|
| 202 |
/** |
| 203 |
* Increment reference count for the surface. |
| 204 |
*/ |
| 205 |
static inline _EGLSurface * |
| 206 |
_eglGetSurface(_EGLSurface *surf) |
| 207 |
{ |
| 208 |
if (surf) |
| 209 |
_eglGetResource(&surf->Resource); |
| 210 |
return surf; |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Decrement reference count for the surface. |
| 215 |
*/ |
| 216 |
static inline EGLBoolean |
| 217 |
_eglPutSurface(_EGLSurface *surf) |
| 218 |
{ |
| 219 |
return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE; |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Link a surface to its display and return the handle of the link. |
| 224 |
* The handle can be passed to client directly. |
| 225 |
*/ |
| 226 |
static inline EGLSurface |
| 227 |
_eglLinkSurface(_EGLSurface *surf) |
| 228 |
{ |
| 229 |
_eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); |
| 230 |
return (EGLSurface)surf; |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Unlink a linked surface from its display. |
| 235 |
* Accessing an unlinked surface should generate EGL_BAD_SURFACE error. |
| 236 |
*/ |
| 237 |
static inline void |
| 238 |
_eglUnlinkSurface(_EGLSurface *surf) |
| 239 |
{ |
| 240 |
_eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Lookup a handle to find the linked surface. |
| 245 |
* Return NULL if the handle has no corresponding linked surface. |
| 246 |
*/ |
| 247 |
static inline _EGLSurface * |
| 248 |
_eglLookupSurface(EGLSurface surface, _EGLDisplay *disp) |
| 249 |
{ |
| 250 |
_EGLSurface *surf = (_EGLSurface *)surface; |
| 251 |
if (!disp || !_eglCheckResource((void *)surf, _EGL_RESOURCE_SURFACE, disp)) |
| 252 |
surf = NULL; |
| 253 |
return surf; |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Return the handle of a linked surface, or EGL_NO_SURFACE. |
| 258 |
*/ |
| 259 |
static inline EGLSurface |
| 260 |
_eglGetSurfaceHandle(_EGLSurface *surf) |
| 261 |
{ |
| 262 |
_EGLResource *res = (_EGLResource *)surf; |
| 263 |
return (res && _eglIsResourceLinked(res)) ? (EGLSurface)surf |
| 264 |
: EGL_NO_SURFACE; |
| 265 |
} |
| 266 |
|
| 267 |
#ifdef __cplusplus |
| 268 |
} |
| 269 |
#endif |
| 270 |
|
| 271 |
#endif /* EGLSURFACE_INCLUDED */ |