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