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
41extern "C" {
42#endif
43
44/**
45 * "Base" class for device driver surfaces.
46 */
47struct _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   /* attributes set by attribute list */
60   EGLint Width, Height;
61   EGLenum TextureFormat;
62   EGLenum TextureTarget;
63   EGLBoolean MipmapTexture;
64   EGLBoolean LargestPbuffer;
65   EGLenum RenderBuffer;
66   EGLenum VGAlphaFormat;
67   EGLenum VGColorspace;
68   EGLenum GLColorspace;
69
70   /* attributes set by eglSurfaceAttrib */
71   EGLint MipmapLevel;
72   EGLenum MultisampleResolve;
73   EGLenum SwapBehavior;
74
75   EGLint HorizontalResolution, VerticalResolution;
76   EGLint AspectRatio;
77
78   EGLint SwapInterval;
79
80   /* True if the surface is bound to an OpenGL ES texture */
81   EGLBoolean BoundToTexture;
82
83   EGLBoolean PostSubBufferSupportedNV;
84};
85
86
87extern EGLBoolean
88_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
89                _EGLConfig *config, const EGLint *attrib_list);
90
91
92extern EGLBoolean
93_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
94
95
96extern EGLBoolean
97_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
98
99
100extern EGLBoolean
101_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
102
103extern EGLBoolean
104_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
105
106
107extern EGLBoolean
108_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
109
110
111/**
112 * Increment reference count for the surface.
113 */
114static inline _EGLSurface *
115_eglGetSurface(_EGLSurface *surf)
116{
117   if (surf)
118      _eglGetResource(&surf->Resource);
119   return surf;
120}
121
122
123/**
124 * Decrement reference count for the surface.
125 */
126static inline EGLBoolean
127_eglPutSurface(_EGLSurface *surf)
128{
129   return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
130}
131
132
133/**
134 * Link a surface to its display and return the handle of the link.
135 * The handle can be passed to client directly.
136 */
137static inline EGLSurface
138_eglLinkSurface(_EGLSurface *surf)
139{
140   _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
141   return (EGLSurface) surf;
142}
143
144
145/**
146 * Unlink a linked surface from its display.
147 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
148 */
149static inline void
150_eglUnlinkSurface(_EGLSurface *surf)
151{
152   _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
153}
154
155
156/**
157 * Lookup a handle to find the linked surface.
158 * Return NULL if the handle has no corresponding linked surface.
159 */
160static inline _EGLSurface *
161_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
162{
163   _EGLSurface *surf = (_EGLSurface *) surface;
164   if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
165      surf = NULL;
166   return surf;
167}
168
169
170/**
171 * Return the handle of a linked surface, or EGL_NO_SURFACE.
172 */
173static inline EGLSurface
174_eglGetSurfaceHandle(_EGLSurface *surf)
175{
176   _EGLResource *res = (_EGLResource *) surf;
177   return (res && _eglIsResourceLinked(res)) ?
178      (EGLSurface) surf : EGL_NO_SURFACE;
179}
180
181
182#ifdef __cplusplus
183}
184#endif
185
186#endif /* EGLSURFACE_INCLUDED */
187