1/************************************************************************** 2 * 3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com> 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 31#ifndef EGLSURFACE_INCLUDED 32#define EGLSURFACE_INCLUDED 33 34 35#include "egltypedefs.h" 36#include "egldisplay.h" 37 38 39/** 40 * "Base" class for device driver surfaces. 41 */ 42struct _egl_surface 43{ 44 /* A surface is a display resource */ 45 _EGLResource Resource; 46 47 /* The context that is currently bound to the surface */ 48 _EGLContext *CurrentContext; 49 50 _EGLConfig *Config; 51 52 EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */ 53 54 /* attributes set by attribute list */ 55 EGLint Width, Height; 56 EGLenum TextureFormat; 57 EGLenum TextureTarget; 58 EGLBoolean MipmapTexture; 59 EGLBoolean LargestPbuffer; 60 EGLenum RenderBuffer; 61 EGLenum VGAlphaFormat; 62 EGLenum VGColorspace; 63 64 /* attributes set by eglSurfaceAttrib */ 65 EGLint MipmapLevel; 66 EGLenum MultisampleResolve; 67 EGLenum SwapBehavior; 68 69 EGLint HorizontalResolution, VerticalResolution; 70 EGLint AspectRatio; 71 72 EGLint SwapInterval; 73 74 /* True if the surface is bound to an OpenGL ES texture */ 75 EGLBoolean BoundToTexture; 76 77 EGLBoolean PostSubBufferSupportedNV; 78}; 79 80 81PUBLIC EGLBoolean 82_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type, 83 _EGLConfig *config, const EGLint *attrib_list); 84 85 86extern EGLBoolean 87_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value); 88 89 90extern EGLBoolean 91_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value); 92 93 94PUBLIC extern EGLBoolean 95_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer); 96 97 98extern EGLBoolean 99_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval); 100 101 102/** 103 * Increment reference count for the surface. 104 */ 105static INLINE _EGLSurface * 106_eglGetSurface(_EGLSurface *surf) 107{ 108 if (surf) 109 _eglGetResource(&surf->Resource); 110 return surf; 111} 112 113 114/** 115 * Decrement reference count for the surface. 116 */ 117static INLINE EGLBoolean 118_eglPutSurface(_EGLSurface *surf) 119{ 120 return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE; 121} 122 123 124/** 125 * Link a surface to its display and return the handle of the link. 126 * The handle can be passed to client directly. 127 */ 128static INLINE EGLSurface 129_eglLinkSurface(_EGLSurface *surf) 130{ 131 _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); 132 return (EGLSurface) surf; 133} 134 135 136/** 137 * Unlink a linked surface from its display. 138 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. 139 */ 140static INLINE void 141_eglUnlinkSurface(_EGLSurface *surf) 142{ 143 _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); 144} 145 146 147/** 148 * Lookup a handle to find the linked surface. 149 * Return NULL if the handle has no corresponding linked surface. 150 */ 151static INLINE _EGLSurface * 152_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy) 153{ 154 _EGLSurface *surf = (_EGLSurface *) surface; 155 if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy)) 156 surf = NULL; 157 return surf; 158} 159 160 161/** 162 * Return the handle of a linked surface, or EGL_NO_SURFACE. 163 */ 164static INLINE EGLSurface 165_eglGetSurfaceHandle(_EGLSurface *surf) 166{ 167 _EGLResource *res = (_EGLResource *) surf; 168 return (res && _eglIsResourceLinked(res)) ? 169 (EGLSurface) surf : EGL_NO_SURFACE; 170} 171 172 173#endif /* EGLSURFACE_INCLUDED */ 174