blob: b9902c7af0074412e033ca60f46779acd68b775b [file] [log] [blame]
Brian Pauladbff7e2005-04-22 21:09:39 +00001/**
2 * Surface-related functions.
3 *
4 * See the eglcontext.c file for comments that also apply here.
5 */
6
7
8#include <assert.h>
9#include <stdlib.h>
10#include <string.h>
11#include "eglcontext.h"
12#include "eglconfig.h"
13#include "eglsurface.h"
14#include "eglglobals.h"
15#include "eglhash.h"
16
17
18void
19_eglInitSurface(_EGLSurface *surf)
20{
21 /* XXX fix this up */
22 memset(surf, 0, sizeof(_EGLSurface));
23}
24
25
26void
27_eglSaveSurface(_EGLSurface *surf)
28{
29 assert(surf);
30 surf->Handle = _eglHashGenKey(_eglGlobal.Contexts);
31 _eglHashInsert(_eglGlobal.Surfaces, surf->Handle, surf);
32}
33
34
35void
36_eglRemoveSurface(_EGLSurface *surf)
37{
38 _eglHashRemove(_eglGlobal.Surfaces, surf->Handle);
39}
40
41
42_EGLSurface *
43_eglLookupSurface(EGLSurface surf)
44{
45 _EGLSurface *c = (_EGLSurface *) _eglHashLookup(_eglGlobal.Surfaces, surf);
46 return c;
47}
48
49
50_EGLSurface *
51_eglGetCurrentSurface(EGLint readdraw)
52{
53 _EGLContext *ctx = _eglGetCurrentContext();
54 if (ctx) {
55 switch (readdraw) {
56 case EGL_DRAW:
57 return ctx->DrawSurface;
58 case EGL_READ:
59 return ctx->ReadSurface;
60 default:
61 return NULL;
62 }
63 }
64 return NULL;
65}
66
67
68EGLBoolean
69_eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw)
70{
71 /* Basically just do error checking */
72 _EGLContext *context = _eglGetCurrentContext();
73 _EGLSurface *surface = _eglLookupSurface(draw);
74 if (context && context->DrawSurface != surface) {
75 _eglError(EGL_BAD_SURFACE, "eglSwapBuffers");
76 return EGL_FALSE;
77 }
78 if (surface == NULL) {
79 _eglError(EGL_BAD_SURFACE, "eglSwapBuffers");
80 return EGL_FALSE;
81 }
82 return EGL_TRUE;
83}
84
85
86EGLBoolean
87_eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixmapType target)
88{
89 /* XXX unfinished */
90 return EGL_FALSE;
91}
92
93
94EGLBoolean
95_eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLint attribute, EGLint *value)
96{
97 _EGLSurface *surface = _eglLookupSurface(surf);
98 if (surface == NULL) {
99 _eglError(EGL_BAD_SURFACE, "eglQuerySurface");
100 return EGL_FALSE;
101 }
102 switch (attribute) {
103 case EGL_WIDTH:
104 *value = surface->Width;
105 return EGL_TRUE;
106 case EGL_HEIGHT:
107 *value = surface->Height;
108 return EGL_TRUE;
109 case EGL_CONFIG_ID:
110 *value = GET_CONFIG_ATTRIB(surface->Config, EGL_CONFIG_ID);
111 return EGL_TRUE;
112 case EGL_TEXTURE_FORMAT:
113 /* texture attributes: only for pbuffers, no error otherwise */
114 if (surface->Type == EGL_PBUFFER_BIT)
115 *value = surface->TextureFormat;
116 return EGL_TRUE;
117 case EGL_TEXTURE_TARGET:
118 if (surface->Type == EGL_PBUFFER_BIT)
119 *value = surface->TextureTarget;
120 return EGL_TRUE;
121 case EGL_MIPMAP_TEXTURE:
122 if (surface->Type == EGL_PBUFFER_BIT)
123 *value = surface->MipmapTexture;
124 return EGL_TRUE;
125 case EGL_MIPMAP_LEVEL:
126 if (surface->Type == EGL_PBUFFER_BIT)
127 *value = surface->MipmapLevel;
128 return EGL_TRUE;
129 default:
130 _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface");
131 return EGL_FALSE;
132 }
133}
134
135
136/**
137 * Default fallback routine - drivers should usually override this.
138 */
139EGLSurface
140_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list)
141{
142 /* nothing - just a placeholder */
143 return EGL_NO_SURFACE;
144}
145
146
147/**
148 * Default fallback routine - drivers should usually override this.
149 */
150EGLSurface
151_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list)
152{
153 /* nothing - just a placeholder */
154 return EGL_NO_SURFACE;
155}
156
157
158/**
159 * Default fallback routine - drivers should usually override this.
160 */
161EGLSurface
162_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
163{
164 /* nothing - just a placeholder */
165 return EGL_NO_SURFACE;
166}
167
168
169/**
170 * Default fallback routine - drivers should usually override this.
171 */
172EGLBoolean
173_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface)
174{
175 _EGLSurface *surf = _eglLookupSurface(surface);
176 if (surf) {
177 _eglHashRemove(_eglGlobal.Surfaces, surface);
178 if (surf->IsBound) {
179 surf->DeletePending = EGL_TRUE;
180 }
181 else {
182 free(surf);
183 }
184 return EGL_TRUE;
185 }
186 else {
187 _eglError(EGL_BAD_SURFACE, "eglDestroySurface");
188 return EGL_FALSE;
189 }
190}
191
192
193/**
194 * Default fallback routine - drivers might override this.
195 */
196EGLBoolean
197_eglSurfaceAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLint attribute, EGLint value)
198{
199 _EGLSurface *surface = _eglLookupSurface(surf);
200
201 if (surface == NULL) {
202 _eglError(EGL_BAD_SURFACE, "eglSurfaceAttrib");
203 return EGL_FALSE;
204 }
205
206 switch (attribute) {
207 case EGL_MIPMAP_LEVEL:
208 surface->MipmapLevel = value;
209 break;
210 default:
211 _eglError(EGL_BAD_ATTRIBUTE, "eglSurfaceAttrib");
212 return EGL_FALSE;
213 }
214 return EGL_TRUE;
215}
216
217
218EGLBoolean
219_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer)
220{
221 /* XXX unfinished */
222 return EGL_FALSE;
223}
224
225
226EGLBoolean
227_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer)
228{
229 /* XXX unfinished */
230 return EGL_FALSE;
231}
232
233
234EGLBoolean
235_eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval)
236{
237 _EGLSurface *surf = _eglGetCurrentSurface(EGL_DRAW);
238 if (surf == NULL) {
239 _eglError(EGL_BAD_SURFACE, "eglSwapInterval");
240 return EGL_FALSE;
241 }
242 surf->SwapInterval = interval;
243 return EGL_TRUE;
244}
245
246