1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2008 VMware, Inc. 4848b8605Smrg * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com> 5848b8605Smrg * Copyright 2010 LunarG, Inc. 6848b8605Smrg * All Rights Reserved. 7848b8605Smrg * 8848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 9848b8605Smrg * copy of this software and associated documentation files (the 10848b8605Smrg * "Software"), to deal in the Software without restriction, including 11848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 12848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 13848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 14848b8605Smrg * the following conditions: 15848b8605Smrg * 16848b8605Smrg * The above copyright notice and this permission notice (including the 17848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 18848b8605Smrg * of the Software. 19848b8605Smrg * 20848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26848b8605Smrg * DEALINGS IN THE SOFTWARE. 27848b8605Smrg * 28848b8605Smrg **************************************************************************/ 29848b8605Smrg 30848b8605Smrg 31848b8605Smrg#ifndef EGLSURFACE_INCLUDED 32848b8605Smrg#define EGLSURFACE_INCLUDED 33848b8605Smrg 34b8e80941Smrg#include "c99_compat.h" 35848b8605Smrg 36848b8605Smrg#include "egltypedefs.h" 37848b8605Smrg#include "egldisplay.h" 38848b8605Smrg 39848b8605Smrg 40b8e80941Smrg#ifdef __cplusplus 41b8e80941Smrgextern "C" { 42b8e80941Smrg#endif 43b8e80941Smrg 44b8e80941Smrgstruct _egl_xy 45b8e80941Smrg{ 46b8e80941Smrg EGLint x; 47b8e80941Smrg EGLint y; 48b8e80941Smrg}; 49b8e80941Smrg 50b8e80941Smrgstruct _egl_hdr_metadata 51b8e80941Smrg{ 52b8e80941Smrg struct _egl_xy display_primary_r; 53b8e80941Smrg struct _egl_xy display_primary_g; 54b8e80941Smrg struct _egl_xy display_primary_b; 55b8e80941Smrg struct _egl_xy white_point; 56b8e80941Smrg EGLint max_luminance; 57b8e80941Smrg EGLint min_luminance; 58b8e80941Smrg EGLint max_cll; 59b8e80941Smrg EGLint max_fall; 60b8e80941Smrg}; 61b8e80941Smrg 62848b8605Smrg/** 63848b8605Smrg * "Base" class for device driver surfaces. 64848b8605Smrg */ 65848b8605Smrgstruct _egl_surface 66848b8605Smrg{ 67848b8605Smrg /* A surface is a display resource */ 68848b8605Smrg _EGLResource Resource; 69848b8605Smrg 70848b8605Smrg /* The context that is currently bound to the surface */ 71848b8605Smrg _EGLContext *CurrentContext; 72848b8605Smrg 73848b8605Smrg _EGLConfig *Config; 74848b8605Smrg 75848b8605Smrg EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */ 76848b8605Smrg 77b8e80941Smrg /* The native surface is lost. The EGL spec requires certain functions 78b8e80941Smrg * to generate EGL_BAD_NATIVE_WINDOW when given this surface. 79b8e80941Smrg */ 80b8e80941Smrg EGLBoolean Lost; 81b8e80941Smrg 82848b8605Smrg /* attributes set by attribute list */ 83848b8605Smrg EGLint Width, Height; 84848b8605Smrg EGLenum TextureFormat; 85848b8605Smrg EGLenum TextureTarget; 86848b8605Smrg EGLBoolean MipmapTexture; 87848b8605Smrg EGLBoolean LargestPbuffer; 88b8e80941Smrg 89b8e80941Smrg /** 90b8e80941Smrg * Value of EGL_RENDER_BUFFER selected at creation. 91b8e80941Smrg * 92b8e80941Smrg * The user may select, for window surfaces, the EGL_RENDER_BUFFER through 93b8e80941Smrg * the attribute list of eglCreateWindowSurface(). The EGL spec allows the 94b8e80941Smrg * implementation to ignore request, though; hence why we maintain both 95b8e80941Smrg * RequestedRenderBuffer and ActiveRenderBuffer. For pbuffer and pixmap 96b8e80941Smrg * surfaces, the EGL spec hard-codes the EGL_RENDER_BUFFER value and the 97b8e80941Smrg * user must not provide it in the attribute list. 98b8e80941Smrg * 99b8e80941Smrg * Normally, the attribute is immutable and after surface creation. 100b8e80941Smrg * However, EGL_KHR_mutable_render_buffer allows the user to change it in 101b8e80941Smrg * window surfaces via eglSurfaceAttrib, in which case 102b8e80941Smrg * eglQuerySurface(EGL_RENDER_BUFFER) will immediately afterwards return 103b8e80941Smrg * the requested value but the actual render buffer used by the context 104b8e80941Smrg * does not change until completion of the next eglSwapBuffers call. 105b8e80941Smrg * 106b8e80941Smrg * From the EGL_KHR_mutable_render_buffer spec (v12): 107b8e80941Smrg * 108b8e80941Smrg * Querying EGL_RENDER_BUFFER returns the buffer which client API 109b8e80941Smrg * rendering is requested to use. For a window surface, this is the 110b8e80941Smrg * attribute value specified when the surface was created or last set 111b8e80941Smrg * via eglSurfaceAttrib. 112b8e80941Smrg * 113b8e80941Smrg * eglQueryContext(EGL_RENDER_BUFFER) ignores this. 114b8e80941Smrg */ 115b8e80941Smrg EGLenum RequestedRenderBuffer; 116b8e80941Smrg 117b8e80941Smrg /** 118b8e80941Smrg * The EGL_RENDER_BUFFER in use by the context. 119b8e80941Smrg * 120b8e80941Smrg * This is valid only when bound as the draw surface. This may differ from 121b8e80941Smrg * the RequestedRenderBuffer. 122b8e80941Smrg * 123b8e80941Smrg * Refer to eglQueryContext(EGL_RENDER_BUFFER) in the EGL spec. 124b8e80941Smrg * eglQuerySurface(EGL_RENDER_BUFFER) ignores this. 125b8e80941Smrg * 126b8e80941Smrg * If a window surface is bound as the draw surface and has a pending, 127b8e80941Smrg * user-requested change to EGL_RENDER_BUFFER, then the next eglSwapBuffers 128b8e80941Smrg * will flush the pending change. (The flush of EGL_RENDER_BUFFER state may 129b8e80941Smrg * occur without the implicit glFlush induced by eglSwapBuffers). The spec 130b8e80941Smrg * requires that the flush occur at that time and nowhere else. During the 131b8e80941Smrg * state-flush, we copy RequestedRenderBuffer to ActiveRenderBuffer. 132b8e80941Smrg * 133b8e80941Smrg * From the EGL_KHR_mutable_render_buffer spec (v12): 134b8e80941Smrg * 135b8e80941Smrg * If [...] there is a pending change to the EGL_RENDER_BUFFER 136b8e80941Smrg * attribute, eglSwapBuffers performs an implicit flush operation on the 137b8e80941Smrg * context and effects the attribute change. 138b8e80941Smrg */ 139b8e80941Smrg EGLenum ActiveRenderBuffer; 140b8e80941Smrg 141848b8605Smrg EGLenum VGAlphaFormat; 142848b8605Smrg EGLenum VGColorspace; 143b8e80941Smrg EGLenum GLColorspace; 144848b8605Smrg 145848b8605Smrg /* attributes set by eglSurfaceAttrib */ 146848b8605Smrg EGLint MipmapLevel; 147848b8605Smrg EGLenum MultisampleResolve; 148848b8605Smrg EGLenum SwapBehavior; 149848b8605Smrg 150848b8605Smrg EGLint HorizontalResolution, VerticalResolution; 151848b8605Smrg EGLint AspectRatio; 152848b8605Smrg 153848b8605Smrg EGLint SwapInterval; 154848b8605Smrg 155b8e80941Smrg /* EGL_KHR_partial_update 156b8e80941Smrg * True if the damage region is already set 157b8e80941Smrg * between frame boundaries. 158b8e80941Smrg */ 159b8e80941Smrg EGLBoolean SetDamageRegionCalled; 160b8e80941Smrg 161b8e80941Smrg /* EGL_KHR_partial_update 162b8e80941Smrg * True if the buffer age is read by the client 163b8e80941Smrg * between frame boundaries. 164b8e80941Smrg */ 165b8e80941Smrg EGLBoolean BufferAgeRead; 166b8e80941Smrg 167848b8605Smrg /* True if the surface is bound to an OpenGL ES texture */ 168848b8605Smrg EGLBoolean BoundToTexture; 169848b8605Smrg 170848b8605Smrg EGLBoolean PostSubBufferSupportedNV; 171b8e80941Smrg 172b8e80941Smrg struct _egl_hdr_metadata HdrMetadata; 173848b8605Smrg}; 174848b8605Smrg 175848b8605Smrg 176b8e80941Smrgextern EGLBoolean 177b8e80941Smrg_eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, 178848b8605Smrg _EGLConfig *config, const EGLint *attrib_list); 179848b8605Smrg 180848b8605Smrg 181848b8605Smrgextern EGLBoolean 182b8e80941Smrg_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value); 183848b8605Smrg 184848b8605Smrg 185848b8605Smrgextern EGLBoolean 186b8e80941Smrg_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint value); 187848b8605Smrg 188848b8605Smrg 189b8e80941Smrgextern EGLBoolean 190b8e80941Smrg_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); 191848b8605Smrg 192b8e80941Smrgextern EGLBoolean 193848b8605Smrg_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); 194848b8605Smrg 195848b8605Smrg 196848b8605Smrgextern EGLBoolean 197b8e80941Smrg_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint interval); 198848b8605Smrg 199b8e80941Smrgextern EGLBoolean 200b8e80941Smrg_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf); 201b8e80941Smrg 202b8e80941Smrgextern EGLBoolean 203b8e80941Smrg_eglSurfaceInSharedBufferMode(_EGLSurface *surf); 204848b8605Smrg 205848b8605Smrg/** 206848b8605Smrg * Increment reference count for the surface. 207848b8605Smrg */ 208b8e80941Smrgstatic inline _EGLSurface * 209848b8605Smrg_eglGetSurface(_EGLSurface *surf) 210848b8605Smrg{ 211848b8605Smrg if (surf) 212848b8605Smrg _eglGetResource(&surf->Resource); 213848b8605Smrg return surf; 214848b8605Smrg} 215848b8605Smrg 216848b8605Smrg 217848b8605Smrg/** 218848b8605Smrg * Decrement reference count for the surface. 219848b8605Smrg */ 220b8e80941Smrgstatic inline EGLBoolean 221848b8605Smrg_eglPutSurface(_EGLSurface *surf) 222848b8605Smrg{ 223848b8605Smrg return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE; 224848b8605Smrg} 225848b8605Smrg 226848b8605Smrg 227848b8605Smrg/** 228848b8605Smrg * Link a surface to its display and return the handle of the link. 229848b8605Smrg * The handle can be passed to client directly. 230848b8605Smrg */ 231b8e80941Smrgstatic inline EGLSurface 232848b8605Smrg_eglLinkSurface(_EGLSurface *surf) 233848b8605Smrg{ 234848b8605Smrg _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); 235848b8605Smrg return (EGLSurface) surf; 236848b8605Smrg} 237848b8605Smrg 238848b8605Smrg 239848b8605Smrg/** 240848b8605Smrg * Unlink a linked surface from its display. 241848b8605Smrg * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. 242848b8605Smrg */ 243b8e80941Smrgstatic inline void 244848b8605Smrg_eglUnlinkSurface(_EGLSurface *surf) 245848b8605Smrg{ 246848b8605Smrg _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); 247848b8605Smrg} 248848b8605Smrg 249848b8605Smrg 250848b8605Smrg/** 251848b8605Smrg * Lookup a handle to find the linked surface. 252848b8605Smrg * Return NULL if the handle has no corresponding linked surface. 253848b8605Smrg */ 254b8e80941Smrgstatic inline _EGLSurface * 255b8e80941Smrg_eglLookupSurface(EGLSurface surface, _EGLDisplay *disp) 256848b8605Smrg{ 257848b8605Smrg _EGLSurface *surf = (_EGLSurface *) surface; 258b8e80941Smrg if (!disp || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, disp)) 259848b8605Smrg surf = NULL; 260848b8605Smrg return surf; 261848b8605Smrg} 262848b8605Smrg 263848b8605Smrg 264848b8605Smrg/** 265848b8605Smrg * Return the handle of a linked surface, or EGL_NO_SURFACE. 266848b8605Smrg */ 267b8e80941Smrgstatic inline EGLSurface 268848b8605Smrg_eglGetSurfaceHandle(_EGLSurface *surf) 269848b8605Smrg{ 270848b8605Smrg _EGLResource *res = (_EGLResource *) surf; 271848b8605Smrg return (res && _eglIsResourceLinked(res)) ? 272848b8605Smrg (EGLSurface) surf : EGL_NO_SURFACE; 273848b8605Smrg} 274848b8605Smrg 275848b8605Smrg 276b8e80941Smrg#ifdef __cplusplus 277b8e80941Smrg} 278b8e80941Smrg#endif 279b8e80941Smrg 280848b8605Smrg#endif /* EGLSURFACE_INCLUDED */ 281