13464ebd5Sriastradh/************************************************************************** 23464ebd5Sriastradh * 3af69d88dSmrg * Copyright 2008 VMware, Inc. 43464ebd5Sriastradh * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com> 53464ebd5Sriastradh * Copyright 2010 LunarG, Inc. 63464ebd5Sriastradh * All Rights Reserved. 73464ebd5Sriastradh * 83464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a 93464ebd5Sriastradh * copy of this software and associated documentation files (the 103464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including 113464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish, 123464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to 133464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to 143464ebd5Sriastradh * the following conditions: 153464ebd5Sriastradh * 163464ebd5Sriastradh * The above copyright notice and this permission notice (including the 173464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions 183464ebd5Sriastradh * of the Software. 193464ebd5Sriastradh * 203464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 213464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 223464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 233464ebd5Sriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 243464ebd5Sriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 253464ebd5Sriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 263464ebd5Sriastradh * DEALINGS IN THE SOFTWARE. 273464ebd5Sriastradh * 283464ebd5Sriastradh **************************************************************************/ 293464ebd5Sriastradh 303464ebd5Sriastradh 314a49301eSmrg#ifndef EGLSURFACE_INCLUDED 324a49301eSmrg#define EGLSURFACE_INCLUDED 334a49301eSmrg 3401e04c3fSmrg#include "c99_compat.h" 354a49301eSmrg 364a49301eSmrg#include "egltypedefs.h" 37cdc920a0Smrg#include "egldisplay.h" 384a49301eSmrg 394a49301eSmrg 4001e04c3fSmrg#ifdef __cplusplus 4101e04c3fSmrgextern "C" { 4201e04c3fSmrg#endif 4301e04c3fSmrg 4401e04c3fSmrgstruct _egl_xy 4501e04c3fSmrg{ 4601e04c3fSmrg EGLint x; 4701e04c3fSmrg EGLint y; 4801e04c3fSmrg}; 4901e04c3fSmrg 5001e04c3fSmrgstruct _egl_hdr_metadata 5101e04c3fSmrg{ 5201e04c3fSmrg struct _egl_xy display_primary_r; 5301e04c3fSmrg struct _egl_xy display_primary_g; 5401e04c3fSmrg struct _egl_xy display_primary_b; 5501e04c3fSmrg struct _egl_xy white_point; 5601e04c3fSmrg EGLint max_luminance; 5701e04c3fSmrg EGLint min_luminance; 5801e04c3fSmrg EGLint max_cll; 5901e04c3fSmrg EGLint max_fall; 6001e04c3fSmrg}; 6101e04c3fSmrg 624a49301eSmrg/** 634a49301eSmrg * "Base" class for device driver surfaces. 644a49301eSmrg */ 654a49301eSmrgstruct _egl_surface 664a49301eSmrg{ 67cdc920a0Smrg /* A surface is a display resource */ 68cdc920a0Smrg _EGLResource Resource; 694a49301eSmrg 70cdc920a0Smrg /* The context that is currently bound to the surface */ 71cdc920a0Smrg _EGLContext *CurrentContext; 724a49301eSmrg 734a49301eSmrg _EGLConfig *Config; 744a49301eSmrg 754a49301eSmrg EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */ 764a49301eSmrg 7701e04c3fSmrg /* The native surface is lost. The EGL spec requires certain functions 7801e04c3fSmrg * to generate EGL_BAD_NATIVE_WINDOW when given this surface. 7901e04c3fSmrg */ 8001e04c3fSmrg EGLBoolean Lost; 8101e04c3fSmrg 82cdc920a0Smrg /* attributes set by attribute list */ 83cdc920a0Smrg EGLint Width, Height; 84cdc920a0Smrg EGLenum TextureFormat; 85cdc920a0Smrg EGLenum TextureTarget; 86cdc920a0Smrg EGLBoolean MipmapTexture; 87cdc920a0Smrg EGLBoolean LargestPbuffer; 8801e04c3fSmrg 8901e04c3fSmrg /** 9001e04c3fSmrg * Value of EGL_RENDER_BUFFER selected at creation. 9101e04c3fSmrg * 9201e04c3fSmrg * The user may select, for window surfaces, the EGL_RENDER_BUFFER through 9301e04c3fSmrg * the attribute list of eglCreateWindowSurface(). The EGL spec allows the 9401e04c3fSmrg * implementation to ignore request, though; hence why we maintain both 9501e04c3fSmrg * RequestedRenderBuffer and ActiveRenderBuffer. For pbuffer and pixmap 9601e04c3fSmrg * surfaces, the EGL spec hard-codes the EGL_RENDER_BUFFER value and the 9701e04c3fSmrg * user must not provide it in the attribute list. 9801e04c3fSmrg * 9901e04c3fSmrg * Normally, the attribute is immutable and after surface creation. 10001e04c3fSmrg * However, EGL_KHR_mutable_render_buffer allows the user to change it in 10101e04c3fSmrg * window surfaces via eglSurfaceAttrib, in which case 10201e04c3fSmrg * eglQuerySurface(EGL_RENDER_BUFFER) will immediately afterwards return 10301e04c3fSmrg * the requested value but the actual render buffer used by the context 10401e04c3fSmrg * does not change until completion of the next eglSwapBuffers call. 10501e04c3fSmrg * 10601e04c3fSmrg * From the EGL_KHR_mutable_render_buffer spec (v12): 10701e04c3fSmrg * 10801e04c3fSmrg * Querying EGL_RENDER_BUFFER returns the buffer which client API 10901e04c3fSmrg * rendering is requested to use. For a window surface, this is the 11001e04c3fSmrg * attribute value specified when the surface was created or last set 11101e04c3fSmrg * via eglSurfaceAttrib. 11201e04c3fSmrg * 11301e04c3fSmrg * eglQueryContext(EGL_RENDER_BUFFER) ignores this. 11401e04c3fSmrg */ 11501e04c3fSmrg EGLenum RequestedRenderBuffer; 11601e04c3fSmrg 11701e04c3fSmrg /** 11801e04c3fSmrg * The EGL_RENDER_BUFFER in use by the context. 11901e04c3fSmrg * 12001e04c3fSmrg * This is valid only when bound as the draw surface. This may differ from 12101e04c3fSmrg * the RequestedRenderBuffer. 12201e04c3fSmrg * 12301e04c3fSmrg * Refer to eglQueryContext(EGL_RENDER_BUFFER) in the EGL spec. 12401e04c3fSmrg * eglQuerySurface(EGL_RENDER_BUFFER) ignores this. 12501e04c3fSmrg * 12601e04c3fSmrg * If a window surface is bound as the draw surface and has a pending, 12701e04c3fSmrg * user-requested change to EGL_RENDER_BUFFER, then the next eglSwapBuffers 12801e04c3fSmrg * will flush the pending change. (The flush of EGL_RENDER_BUFFER state may 12901e04c3fSmrg * occur without the implicit glFlush induced by eglSwapBuffers). The spec 13001e04c3fSmrg * requires that the flush occur at that time and nowhere else. During the 13101e04c3fSmrg * state-flush, we copy RequestedRenderBuffer to ActiveRenderBuffer. 13201e04c3fSmrg * 13301e04c3fSmrg * From the EGL_KHR_mutable_render_buffer spec (v12): 13401e04c3fSmrg * 13501e04c3fSmrg * If [...] there is a pending change to the EGL_RENDER_BUFFER 13601e04c3fSmrg * attribute, eglSwapBuffers performs an implicit flush operation on the 13701e04c3fSmrg * context and effects the attribute change. 13801e04c3fSmrg */ 13901e04c3fSmrg EGLenum ActiveRenderBuffer; 14001e04c3fSmrg 141cdc920a0Smrg EGLenum VGAlphaFormat; 142cdc920a0Smrg EGLenum VGColorspace; 14301e04c3fSmrg EGLenum GLColorspace; 144cdc920a0Smrg 145cdc920a0Smrg /* attributes set by eglSurfaceAttrib */ 146cdc920a0Smrg EGLint MipmapLevel; 147cdc920a0Smrg EGLenum MultisampleResolve; 148cdc920a0Smrg EGLenum SwapBehavior; 1494a49301eSmrg 1504a49301eSmrg EGLint HorizontalResolution, VerticalResolution; 1514a49301eSmrg EGLint AspectRatio; 152cdc920a0Smrg 153cdc920a0Smrg EGLint SwapInterval; 154cdc920a0Smrg 15501e04c3fSmrg /* EGL_KHR_partial_update 15601e04c3fSmrg * True if the damage region is already set 15701e04c3fSmrg * between frame boundaries. 15801e04c3fSmrg */ 15901e04c3fSmrg EGLBoolean SetDamageRegionCalled; 16001e04c3fSmrg 16101e04c3fSmrg /* EGL_KHR_partial_update 16201e04c3fSmrg * True if the buffer age is read by the client 16301e04c3fSmrg * between frame boundaries. 16401e04c3fSmrg */ 16501e04c3fSmrg EGLBoolean BufferAgeRead; 16601e04c3fSmrg 167cdc920a0Smrg /* True if the surface is bound to an OpenGL ES texture */ 168cdc920a0Smrg EGLBoolean BoundToTexture; 169af69d88dSmrg 170af69d88dSmrg EGLBoolean PostSubBufferSupportedNV; 17101e04c3fSmrg 1727ec681f3Smrg EGLBoolean ProtectedContent; 1737ec681f3Smrg 1747ec681f3Smrg EGLBoolean PresentOpaque; 1757ec681f3Smrg 17601e04c3fSmrg struct _egl_hdr_metadata HdrMetadata; 1777ec681f3Smrg 1787ec681f3Smrg void *NativeSurface; 1794a49301eSmrg}; 1804a49301eSmrg 1814a49301eSmrg 18201e04c3fSmrgextern EGLBoolean 1837e102996Smaya_eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, 1847ec681f3Smrg _EGLConfig *config, const EGLint *attrib_list, 1857ec681f3Smrg void *native_surface); 1864a49301eSmrg 1874a49301eSmrg 1884a49301eSmrgextern EGLBoolean 1897ec681f3Smrg_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value); 1904a49301eSmrg 1914a49301eSmrg 1924a49301eSmrgextern EGLBoolean 1937ec681f3Smrg_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint value); 1944a49301eSmrg 1954a49301eSmrg 19601e04c3fSmrgextern EGLBoolean 1977ec681f3Smrg_eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); 1984a49301eSmrg 19901e04c3fSmrgextern EGLBoolean 2007ec681f3Smrg_eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); 201af69d88dSmrg 2024a49301eSmrg 20301e04c3fSmrgextern EGLBoolean 20401e04c3fSmrg_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf); 20501e04c3fSmrg 20601e04c3fSmrgextern EGLBoolean 20701e04c3fSmrg_eglSurfaceInSharedBufferMode(_EGLSurface *surf); 2084a49301eSmrg 2093464ebd5Sriastradh/** 2103464ebd5Sriastradh * Increment reference count for the surface. 2113464ebd5Sriastradh */ 21201e04c3fSmrgstatic inline _EGLSurface * 2133464ebd5Sriastradh_eglGetSurface(_EGLSurface *surf) 2143464ebd5Sriastradh{ 2153464ebd5Sriastradh if (surf) 2163464ebd5Sriastradh _eglGetResource(&surf->Resource); 2173464ebd5Sriastradh return surf; 2183464ebd5Sriastradh} 2194a49301eSmrg 2204a49301eSmrg 2214a49301eSmrg/** 2223464ebd5Sriastradh * Decrement reference count for the surface. 2234a49301eSmrg */ 22401e04c3fSmrgstatic inline EGLBoolean 2253464ebd5Sriastradh_eglPutSurface(_EGLSurface *surf) 2264a49301eSmrg{ 2273464ebd5Sriastradh return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE; 228cdc920a0Smrg} 229cdc920a0Smrg 230cdc920a0Smrg 231cdc920a0Smrg/** 2323464ebd5Sriastradh * Link a surface to its display and return the handle of the link. 233cdc920a0Smrg * The handle can be passed to client directly. 234cdc920a0Smrg */ 23501e04c3fSmrgstatic inline EGLSurface 2363464ebd5Sriastradh_eglLinkSurface(_EGLSurface *surf) 237cdc920a0Smrg{ 2383464ebd5Sriastradh _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); 239cdc920a0Smrg return (EGLSurface) surf; 240cdc920a0Smrg} 241cdc920a0Smrg 242cdc920a0Smrg 243cdc920a0Smrg/** 244cdc920a0Smrg * Unlink a linked surface from its display. 245cdc920a0Smrg * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. 246cdc920a0Smrg */ 24701e04c3fSmrgstatic inline void 248cdc920a0Smrg_eglUnlinkSurface(_EGLSurface *surf) 249cdc920a0Smrg{ 250cdc920a0Smrg _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); 251cdc920a0Smrg} 252cdc920a0Smrg 253cdc920a0Smrg 254cdc920a0Smrg/** 255cdc920a0Smrg * Lookup a handle to find the linked surface. 256cdc920a0Smrg * Return NULL if the handle has no corresponding linked surface. 257cdc920a0Smrg */ 25801e04c3fSmrgstatic inline _EGLSurface * 2597e102996Smaya_eglLookupSurface(EGLSurface surface, _EGLDisplay *disp) 260cdc920a0Smrg{ 261cdc920a0Smrg _EGLSurface *surf = (_EGLSurface *) surface; 2627e102996Smaya if (!disp || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, disp)) 263cdc920a0Smrg surf = NULL; 264cdc920a0Smrg return surf; 265cdc920a0Smrg} 266cdc920a0Smrg 267cdc920a0Smrg 268cdc920a0Smrg/** 269cdc920a0Smrg * Return the handle of a linked surface, or EGL_NO_SURFACE. 270cdc920a0Smrg */ 27101e04c3fSmrgstatic inline EGLSurface 272cdc920a0Smrg_eglGetSurfaceHandle(_EGLSurface *surf) 273cdc920a0Smrg{ 274cdc920a0Smrg _EGLResource *res = (_EGLResource *) surf; 275cdc920a0Smrg return (res && _eglIsResourceLinked(res)) ? 276cdc920a0Smrg (EGLSurface) surf : EGL_NO_SURFACE; 277cdc920a0Smrg} 278cdc920a0Smrg 279cdc920a0Smrg 28001e04c3fSmrg#ifdef __cplusplus 28101e04c3fSmrg} 28201e04c3fSmrg#endif 28301e04c3fSmrg 2844a49301eSmrg#endif /* EGLSURFACE_INCLUDED */ 285