egl: Make resource void pointer in _eglCheckResource.
[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 bound status of the surface */
18 _EGLContext *Binding;
19 EGLBoolean BoundToTexture;
20
21 _EGLConfig *Config;
22
23 EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
24 EGLint Width, Height;
25 EGLint TextureFormat, TextureTarget;
26 EGLint MipmapTexture, MipmapLevel;
27 EGLint SwapInterval;
28
29 /* If type == EGL_SCREEN_BIT: */
30 EGLint VisibleRefCount; /* number of screens I'm displayed on */
31
32 #ifdef EGL_VERSION_1_2
33 EGLint SwapBehavior; /* one of EGL_BUFFER_PRESERVED/DESTROYED */
34 EGLint HorizontalResolution, VerticalResolution;
35 EGLint AspectRatio;
36 EGLint RenderBuffer; /* EGL_BACK_BUFFER or EGL_SINGLE_BUFFER */
37 EGLint AlphaFormat; /* EGL_ALPHA_FORMAT_NONPRE or EGL_ALPHA_FORMAT_PRE */
38 EGLint Colorspace; /* EGL_COLORSPACE_sRGB or EGL_COLORSPACE_LINEAR */
39 #endif /* EGL_VERSION_1_2 */
40 };
41
42
43 PUBLIC EGLBoolean
44 _eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
45 _EGLConfig *config, const EGLint *attrib_list);
46
47
48 extern EGLBoolean
49 _eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf);
50
51
52 extern EGLBoolean
53 _eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, NativePixmapType target);
54
55
56 extern EGLBoolean
57 _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
58
59
60 extern _EGLSurface *
61 _eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list);
62
63
64 extern _EGLSurface *
65 _eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list);
66
67
68 extern _EGLSurface *
69 _eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attrib_list);
70
71
72 extern EGLBoolean
73 _eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf);
74
75
76 extern EGLBoolean
77 _eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
78
79
80 extern EGLBoolean
81 _eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
82
83
84 extern EGLBoolean
85 _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
86
87
88 extern EGLBoolean
89 _eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
90
91
92 #ifdef EGL_VERSION_1_2
93
94 extern _EGLSurface *
95 _eglCreatePbufferFromClientBuffer(_EGLDriver *drv, _EGLDisplay *dpy,
96 EGLenum buftype, EGLClientBuffer buffer,
97 _EGLConfig *conf, const EGLint *attrib_list);
98
99 #endif /* EGL_VERSION_1_2 */
100
101
102 /**
103 * Return true if the surface is bound to a thread.
104 * A surface bound to a texutre is not considered bound by
105 * this function.
106 */
107 static INLINE EGLBoolean
108 _eglIsSurfaceBound(_EGLSurface *surf)
109 {
110 return (surf->Binding != 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 */