egl: Simplify queries for EGL_RENDER_BUFFER
[mesa.git] / src / egl / main / eglsurface.h
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
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 #include "c99_compat.h"
35
36 #include "egltypedefs.h"
37 #include "egldisplay.h"
38
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /**
45 * "Base" class for device driver surfaces.
46 */
47 struct _egl_surface
48 {
49 /* A surface is a display resource */
50 _EGLResource Resource;
51
52 /* The context that is currently bound to the surface */
53 _EGLContext *CurrentContext;
54
55 _EGLConfig *Config;
56
57 EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
58
59 /* The native surface is lost. The EGL spec requires certain functions
60 * to generate EGL_BAD_NATIVE_WINDOW when given this surface.
61 */
62 EGLBoolean Lost;
63
64 /* attributes set by attribute list */
65 EGLint Width, Height;
66 EGLenum TextureFormat;
67 EGLenum TextureTarget;
68 EGLBoolean MipmapTexture;
69 EGLBoolean LargestPbuffer;
70
71 /**
72 * Value of EGL_RENDER_BUFFER selected at creation.
73 *
74 * The user may select, for window surfaces, the EGL_RENDER_BUFFER through
75 * the attribute list of eglCreateWindowSurface(). The EGL spec allows the
76 * implementation to ignore request, though; hence why we maintain both
77 * RequestedRenderBuffer and ActiveRenderBuffer. For pbuffer and pixmap
78 * surfaces, the EGL spec hard-codes the EGL_RENDER_BUFFER value and the
79 * user must not provide it in the attribute list.
80 *
81 * Refer to eglQuerySurface() in the EGL spec.
82 * eglQueryContext(EGL_RENDER_BUFFER) ignores this.
83 */
84 EGLenum RequestedRenderBuffer;
85
86 /**
87 * The EGL_RENDER_BUFFER in use by the context.
88 *
89 * This is valid only when bound as the draw surface. This may differ from
90 * the RequestedRenderBuffer.
91 *
92 * Refer to eglQueryContext(EGL_RENDER_BUFFER) in the EGL spec.
93 * eglQuerySurface(EGL_RENDER_BUFFER) ignores this.
94 */
95 EGLenum ActiveRenderBuffer;
96
97 EGLenum VGAlphaFormat;
98 EGLenum VGColorspace;
99 EGLenum GLColorspace;
100
101 /* attributes set by eglSurfaceAttrib */
102 EGLint MipmapLevel;
103 EGLenum MultisampleResolve;
104 EGLenum SwapBehavior;
105
106 EGLint HorizontalResolution, VerticalResolution;
107 EGLint AspectRatio;
108
109 EGLint SwapInterval;
110
111 /* EGL_KHR_partial_update
112 * True if the damage region is already set
113 * between frame boundaries.
114 */
115 EGLBoolean SetDamageRegionCalled;
116
117 /* EGL_KHR_partial_update
118 * True if the buffer age is read by the client
119 * between frame boundaries.
120 */
121 EGLBoolean BufferAgeRead;
122
123 /* True if the surface is bound to an OpenGL ES texture */
124 EGLBoolean BoundToTexture;
125
126 EGLBoolean PostSubBufferSupportedNV;
127 };
128
129
130 extern EGLBoolean
131 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
132 _EGLConfig *config, const EGLint *attrib_list);
133
134
135 extern EGLBoolean
136 _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
137
138
139 extern EGLBoolean
140 _eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
141
142
143 extern EGLBoolean
144 _eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
145
146 extern EGLBoolean
147 _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
148
149
150 extern EGLBoolean
151 _eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
152
153
154 /**
155 * Increment reference count for the surface.
156 */
157 static inline _EGLSurface *
158 _eglGetSurface(_EGLSurface *surf)
159 {
160 if (surf)
161 _eglGetResource(&surf->Resource);
162 return surf;
163 }
164
165
166 /**
167 * Decrement reference count for the surface.
168 */
169 static inline EGLBoolean
170 _eglPutSurface(_EGLSurface *surf)
171 {
172 return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
173 }
174
175
176 /**
177 * Link a surface to its display and return the handle of the link.
178 * The handle can be passed to client directly.
179 */
180 static inline EGLSurface
181 _eglLinkSurface(_EGLSurface *surf)
182 {
183 _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
184 return (EGLSurface) surf;
185 }
186
187
188 /**
189 * Unlink a linked surface from its display.
190 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
191 */
192 static inline void
193 _eglUnlinkSurface(_EGLSurface *surf)
194 {
195 _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
196 }
197
198
199 /**
200 * Lookup a handle to find the linked surface.
201 * Return NULL if the handle has no corresponding linked surface.
202 */
203 static inline _EGLSurface *
204 _eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
205 {
206 _EGLSurface *surf = (_EGLSurface *) surface;
207 if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
208 surf = NULL;
209 return surf;
210 }
211
212
213 /**
214 * Return the handle of a linked surface, or EGL_NO_SURFACE.
215 */
216 static inline EGLSurface
217 _eglGetSurfaceHandle(_EGLSurface *surf)
218 {
219 _EGLResource *res = (_EGLResource *) surf;
220 return (res && _eglIsResourceLinked(res)) ?
221 (EGLSurface) surf : EGL_NO_SURFACE;
222 }
223
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #endif /* EGLSURFACE_INCLUDED */