/**************************************************************************1*2* Copyright 2008 VMware, Inc.3* Copyright 2009-2010 Chia-I Wu <[email protected]>4* Copyright 2010 LunarG, Inc.5* All Rights Reserved.6*7* Permission is hereby granted, free of charge, to any person obtaining a8* copy of this software and associated documentation files (the9* "Software"), to deal in the Software without restriction, including10* without limitation the rights to use, copy, modify, merge, publish,11* distribute, sub license, and/or sell copies of the Software, and to12* permit persons to whom the Software is furnished to do so, subject to13* the following conditions:14*15* The above copyright notice and this permission notice (including the16* next paragraph) shall be included in all copies or substantial portions17* of the Software.18*19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR20* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,21* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL22* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER23* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING24* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER25* DEALINGS IN THE SOFTWARE.26*27**************************************************************************/282930#ifndef EGLSURFACE_INCLUDED31#define EGLSURFACE_INCLUDED3233#include "c99_compat.h"3435#include "egltypedefs.h"36#include "egldisplay.h"373839#ifdef __cplusplus40extern "C" {41#endif4243struct _egl_xy44{45EGLint x;46EGLint y;47};4849struct _egl_hdr_metadata50{51struct _egl_xy display_primary_r;52struct _egl_xy display_primary_g;53struct _egl_xy display_primary_b;54struct _egl_xy white_point;55EGLint max_luminance;56EGLint min_luminance;57EGLint max_cll;58EGLint max_fall;59};6061/**62* "Base" class for device driver surfaces.63*/64struct _egl_surface65{66/* A surface is a display resource */67_EGLResource Resource;6869/* The context that is currently bound to the surface */70_EGLContext *CurrentContext;7172_EGLConfig *Config;7374EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */7576/* The native surface is lost. The EGL spec requires certain functions77* to generate EGL_BAD_NATIVE_WINDOW when given this surface.78*/79EGLBoolean Lost;8081/* attributes set by attribute list */82EGLint Width, Height;83EGLenum TextureFormat;84EGLenum TextureTarget;85EGLBoolean MipmapTexture;86EGLBoolean LargestPbuffer;8788/**89* Value of EGL_RENDER_BUFFER selected at creation.90*91* The user may select, for window surfaces, the EGL_RENDER_BUFFER through92* the attribute list of eglCreateWindowSurface(). The EGL spec allows the93* implementation to ignore request, though; hence why we maintain both94* RequestedRenderBuffer and ActiveRenderBuffer. For pbuffer and pixmap95* surfaces, the EGL spec hard-codes the EGL_RENDER_BUFFER value and the96* user must not provide it in the attribute list.97*98* Normally, the attribute is immutable and after surface creation.99* However, EGL_KHR_mutable_render_buffer allows the user to change it in100* window surfaces via eglSurfaceAttrib, in which case101* eglQuerySurface(EGL_RENDER_BUFFER) will immediately afterwards return102* the requested value but the actual render buffer used by the context103* does not change until completion of the next eglSwapBuffers call.104*105* From the EGL_KHR_mutable_render_buffer spec (v12):106*107* Querying EGL_RENDER_BUFFER returns the buffer which client API108* rendering is requested to use. For a window surface, this is the109* attribute value specified when the surface was created or last set110* via eglSurfaceAttrib.111*112* eglQueryContext(EGL_RENDER_BUFFER) ignores this.113*/114EGLenum RequestedRenderBuffer;115116/**117* The EGL_RENDER_BUFFER in use by the context.118*119* This is valid only when bound as the draw surface. This may differ from120* the RequestedRenderBuffer.121*122* Refer to eglQueryContext(EGL_RENDER_BUFFER) in the EGL spec.123* eglQuerySurface(EGL_RENDER_BUFFER) ignores this.124*125* If a window surface is bound as the draw surface and has a pending,126* user-requested change to EGL_RENDER_BUFFER, then the next eglSwapBuffers127* will flush the pending change. (The flush of EGL_RENDER_BUFFER state may128* occur without the implicit glFlush induced by eglSwapBuffers). The spec129* requires that the flush occur at that time and nowhere else. During the130* state-flush, we copy RequestedRenderBuffer to ActiveRenderBuffer.131*132* From the EGL_KHR_mutable_render_buffer spec (v12):133*134* If [...] there is a pending change to the EGL_RENDER_BUFFER135* attribute, eglSwapBuffers performs an implicit flush operation on the136* context and effects the attribute change.137*/138EGLenum ActiveRenderBuffer;139140EGLenum VGAlphaFormat;141EGLenum VGColorspace;142EGLenum GLColorspace;143144/* attributes set by eglSurfaceAttrib */145EGLint MipmapLevel;146EGLenum MultisampleResolve;147EGLenum SwapBehavior;148149EGLint HorizontalResolution, VerticalResolution;150EGLint AspectRatio;151152EGLint SwapInterval;153154/* EGL_KHR_partial_update155* True if the damage region is already set156* between frame boundaries.157*/158EGLBoolean SetDamageRegionCalled;159160/* EGL_KHR_partial_update161* True if the buffer age is read by the client162* between frame boundaries.163*/164EGLBoolean BufferAgeRead;165166/* True if the surface is bound to an OpenGL ES texture */167EGLBoolean BoundToTexture;168169EGLBoolean PostSubBufferSupportedNV;170171EGLBoolean ProtectedContent;172173struct _egl_hdr_metadata HdrMetadata;174175void *NativeSurface;176};177178179extern EGLBoolean180_eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,181_EGLConfig *config, const EGLint *attrib_list,182void *native_surface);183184185extern EGLBoolean186_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value);187188189extern EGLBoolean190_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint value);191192193extern EGLBoolean194_eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);195196extern EGLBoolean197_eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);198199200extern EGLBoolean201_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf);202203extern EGLBoolean204_eglSurfaceInSharedBufferMode(_EGLSurface *surf);205206/**207* Increment reference count for the surface.208*/209static inline _EGLSurface *210_eglGetSurface(_EGLSurface *surf)211{212if (surf)213_eglGetResource(&surf->Resource);214return surf;215}216217218/**219* Decrement reference count for the surface.220*/221static inline EGLBoolean222_eglPutSurface(_EGLSurface *surf)223{224return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;225}226227228/**229* Link a surface to its display and return the handle of the link.230* The handle can be passed to client directly.231*/232static inline EGLSurface233_eglLinkSurface(_EGLSurface *surf)234{235_eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);236return (EGLSurface) surf;237}238239240/**241* Unlink a linked surface from its display.242* Accessing an unlinked surface should generate EGL_BAD_SURFACE error.243*/244static inline void245_eglUnlinkSurface(_EGLSurface *surf)246{247_eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);248}249250251/**252* Lookup a handle to find the linked surface.253* Return NULL if the handle has no corresponding linked surface.254*/255static inline _EGLSurface *256_eglLookupSurface(EGLSurface surface, _EGLDisplay *disp)257{258_EGLSurface *surf = (_EGLSurface *) surface;259if (!disp || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, disp))260surf = NULL;261return surf;262}263264265/**266* Return the handle of a linked surface, or EGL_NO_SURFACE.267*/268static inline EGLSurface269_eglGetSurfaceHandle(_EGLSurface *surf)270{271_EGLResource *res = (_EGLResource *) surf;272return (res && _eglIsResourceLinked(res)) ?273(EGLSurface) surf : EGL_NO_SURFACE;274}275276277#ifdef __cplusplus278}279#endif280281#endif /* EGLSURFACE_INCLUDED */282283284