Merge remote branch 'origin/master' into lp-binning
[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 EGLint Width, Height;
24 EGLint TextureFormat, TextureTarget;
25 EGLint MipmapTexture, MipmapLevel;
26 EGLint SwapInterval;
27
28 /* True if the surface is bound to an OpenGL ES texture */
29 EGLBoolean BoundToTexture;
30
31 #ifdef EGL_VERSION_1_2
32 EGLint SwapBehavior; /* one of EGL_BUFFER_PRESERVED/DESTROYED */
33 EGLint HorizontalResolution, VerticalResolution;
34 EGLint AspectRatio;
35 EGLint RenderBuffer; /* EGL_BACK_BUFFER or EGL_SINGLE_BUFFER */
36 EGLint AlphaFormat; /* EGL_ALPHA_FORMAT_NONPRE or EGL_ALPHA_FORMAT_PRE */
37 EGLint Colorspace; /* EGL_COLORSPACE_sRGB or EGL_COLORSPACE_LINEAR */
38 #endif /* EGL_VERSION_1_2 */
39 };
40
41
42 PUBLIC EGLBoolean
43 _eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
44 _EGLConfig *config, const EGLint *attrib_list);
45
46
47 extern EGLBoolean
48 _eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf);
49
50
51 extern EGLBoolean
52 _eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLNativePixmapType target);
53
54
55 extern EGLBoolean
56 _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
57
58
59 extern _EGLSurface *
60 _eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativeWindowType window, const EGLint *attrib_list);
61
62
63 extern _EGLSurface *
64 _eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativePixmapType pixmap, const EGLint *attrib_list);
65
66
67 extern _EGLSurface *
68 _eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list);
69
70
71 extern EGLBoolean
72 _eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf);
73
74
75 extern EGLBoolean
76 _eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
77
78
79 extern EGLBoolean
80 _eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
81
82
83 extern EGLBoolean
84 _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
85
86
87 extern EGLBoolean
88 _eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
89
90
91 #ifdef EGL_VERSION_1_2
92
93 extern _EGLSurface *
94 _eglCreatePbufferFromClientBuffer(_EGLDriver *drv, _EGLDisplay *dpy,
95 EGLenum buftype, EGLClientBuffer buffer,
96 _EGLConfig *conf, const EGLint *attrib_list);
97
98 #endif /* EGL_VERSION_1_2 */
99
100
101 /**
102 * Return true if there is a context bound to the surface.
103 */
104 static INLINE EGLBoolean
105 _eglIsSurfaceBound(_EGLSurface *surf)
106 {
107 return (surf->CurrentContext != NULL);
108 }
109
110
111 /**
112 * Link a surface to a display and return the handle of the link.
113 * The handle can be passed to client directly.
114 */
115 static INLINE EGLSurface
116 _eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy)
117 {
118 _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE, dpy);
119 return (EGLSurface) surf;
120 }
121
122
123 /**
124 * Unlink a linked surface from its display.
125 * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
126 */
127 static INLINE void
128 _eglUnlinkSurface(_EGLSurface *surf)
129 {
130 _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
131 }
132
133
134 /**
135 * Lookup a handle to find the linked surface.
136 * Return NULL if the handle has no corresponding linked surface.
137 */
138 static INLINE _EGLSurface *
139 _eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
140 {
141 _EGLSurface *surf = (_EGLSurface *) surface;
142 if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
143 surf = NULL;
144 return surf;
145 }
146
147
148 /**
149 * Return the handle of a linked surface, or EGL_NO_SURFACE.
150 */
151 static INLINE EGLSurface
152 _eglGetSurfaceHandle(_EGLSurface *surf)
153 {
154 _EGLResource *res = (_EGLResource *) surf;
155 return (res && _eglIsResourceLinked(res)) ?
156 (EGLSurface) surf : EGL_NO_SURFACE;
157 }
158
159
160 /**
161 * Return true if the surface is linked to a display.
162 */
163 static INLINE EGLBoolean
164 _eglIsSurfaceLinked(_EGLSurface *surf)
165 {
166 _EGLResource *res = (_EGLResource *) surf;
167 return (res && _eglIsResourceLinked(res));
168 }
169
170
171 #endif /* EGLSURFACE_INCLUDED */