egl: Clean up surface attributes.
[mesa.git] / src / egl / main / eglsurface.h
1 #ifndef EGLSURFACE_INCLUDED
2 #define EGLSURFACE_INCLUDED
3
4
5 #include "egltypedefs.h"
6 #include "egldisplay.h"
7
8
9 /**
10 * "Base" class for device driver surfaces.
11 */
12 struct _egl_surface
13 {
14 /* A surface is a display resource */
15 _EGLResource Resource;
16
17 /* The context that is currently bound to the surface */
18 _EGLContext *CurrentContext;
19
20 _EGLConfig *Config;
21
22 EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
23
24 /* attributes set by attribute list */
25 EGLint Width, Height;
26 EGLenum TextureFormat;
27 EGLenum TextureTarget;
28 EGLBoolean MipmapTexture;
29 EGLBoolean LargestPbuffer;
30 EGLenum RenderBuffer;
31 EGLenum VGAlphaFormat;
32 EGLenum VGColorspace;
33
34 /* attributes set by eglSurfaceAttrib */
35 EGLint MipmapLevel;
36 EGLenum MultisampleResolve;
37 EGLenum SwapBehavior;
38
39 EGLint HorizontalResolution, VerticalResolution;
40 EGLint AspectRatio;
41
42 EGLint SwapInterval;
43
44 /* True if the surface is bound to an OpenGL ES texture */
45 EGLBoolean BoundToTexture;
46 };
47
48
49 PUBLIC EGLBoolean
50 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
51 _EGLConfig *config, const EGLint *attrib_list);
52
53
54 extern EGLBoolean
55 _eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf);
56
57
58 extern EGLBoolean
59 _eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLNativePixmapType target);
60
61
62 extern EGLBoolean
63 _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
64
65
66 extern _EGLSurface *
67 _eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativeWindowType window, const EGLint *attrib_list);
68
69
70 extern _EGLSurface *
71 _eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativePixmapType pixmap, const EGLint *attrib_list);
72
73
74 extern _EGLSurface *
75 _eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list);
76
77
78 extern EGLBoolean
79 _eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf);
80
81
82 extern EGLBoolean
83 _eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
84
85
86 extern EGLBoolean
87 _eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
88
89
90 extern EGLBoolean
91 _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
92
93
94 extern EGLBoolean
95 _eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
96
97
98 #ifdef EGL_VERSION_1_2
99
100 extern _EGLSurface *
101 _eglCreatePbufferFromClientBuffer(_EGLDriver *drv, _EGLDisplay *dpy,
102 EGLenum buftype, EGLClientBuffer buffer,
103 _EGLConfig *conf, const EGLint *attrib_list);
104
105 #endif /* EGL_VERSION_1_2 */
106
107
108 /**
109 * Return true if there is a context bound to the surface.
110 */
111 static INLINE EGLBoolean
112 _eglIsSurfaceBound(_EGLSurface *surf)
113 {
114 return (surf->CurrentContext != NULL);
115 }
116
117
118 /**
119 * Link a surface to a display and return the handle of the link.
120 * The handle can be passed to client directly.
121 */
122 static INLINE EGLSurface
123 _eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy)
124 {
125 _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE, dpy);
126 return (EGLSurface) surf;
127 }
128
129
130 /**
131 * Unlink a linked surface from its display.
132 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
133 */
134 static INLINE void
135 _eglUnlinkSurface(_EGLSurface *surf)
136 {
137 _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
138 }
139
140
141 /**
142 * Lookup a handle to find the linked surface.
143 * Return NULL if the handle has no corresponding linked surface.
144 */
145 static INLINE _EGLSurface *
146 _eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
147 {
148 _EGLSurface *surf = (_EGLSurface *) surface;
149 if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
150 surf = NULL;
151 return surf;
152 }
153
154
155 /**
156 * Return the handle of a linked surface, or EGL_NO_SURFACE.
157 */
158 static INLINE EGLSurface
159 _eglGetSurfaceHandle(_EGLSurface *surf)
160 {
161 _EGLResource *res = (_EGLResource *) surf;
162 return (res && _eglIsResourceLinked(res)) ?
163 (EGLSurface) surf : EGL_NO_SURFACE;
164 }
165
166
167 /**
168 * Return true if the surface is linked to a display.
169 */
170 static INLINE EGLBoolean
171 _eglIsSurfaceLinked(_EGLSurface *surf)
172 {
173 _EGLResource *res = (_EGLResource *) surf;
174 return (res && _eglIsResourceLinked(res));
175 }
176
177
178 #endif /* EGLSURFACE_INCLUDED */