Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 1 | /** |
| 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 | |
| 18 | void |
| 19 | _eglInitSurface(_EGLSurface *surf) |
| 20 | { |
| 21 | /* XXX fix this up */ |
| 22 | memset(surf, 0, sizeof(_EGLSurface)); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | void |
| 27 | _eglSaveSurface(_EGLSurface *surf) |
| 28 | { |
| 29 | assert(surf); |
| 30 | surf->Handle = _eglHashGenKey(_eglGlobal.Contexts); |
| 31 | _eglHashInsert(_eglGlobal.Surfaces, surf->Handle, surf); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | void |
| 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 | |
| 68 | EGLBoolean |
| 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 | |
| 86 | EGLBoolean |
| 87 | _eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixmapType target) |
| 88 | { |
| 89 | /* XXX unfinished */ |
| 90 | return EGL_FALSE; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | EGLBoolean |
| 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; |
Jon Smirl | 380991c | 2005-05-16 16:50:38 +0000 | [diff] [blame^] | 129 | case EGL_SURFACE_TYPE: |
| 130 | *value = surface->Type; |
| 131 | return EGL_TRUE; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 132 | default: |
| 133 | _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); |
| 134 | return EGL_FALSE; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /** |
| 140 | * Default fallback routine - drivers should usually override this. |
| 141 | */ |
| 142 | EGLSurface |
| 143 | _eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) |
| 144 | { |
| 145 | /* nothing - just a placeholder */ |
| 146 | return EGL_NO_SURFACE; |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /** |
| 151 | * Default fallback routine - drivers should usually override this. |
| 152 | */ |
| 153 | EGLSurface |
| 154 | _eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list) |
| 155 | { |
| 156 | /* nothing - just a placeholder */ |
| 157 | return EGL_NO_SURFACE; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /** |
| 162 | * Default fallback routine - drivers should usually override this. |
| 163 | */ |
| 164 | EGLSurface |
| 165 | _eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) |
| 166 | { |
| 167 | /* nothing - just a placeholder */ |
| 168 | return EGL_NO_SURFACE; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /** |
| 173 | * Default fallback routine - drivers should usually override this. |
| 174 | */ |
| 175 | EGLBoolean |
| 176 | _eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) |
| 177 | { |
| 178 | _EGLSurface *surf = _eglLookupSurface(surface); |
| 179 | if (surf) { |
| 180 | _eglHashRemove(_eglGlobal.Surfaces, surface); |
| 181 | if (surf->IsBound) { |
| 182 | surf->DeletePending = EGL_TRUE; |
| 183 | } |
| 184 | else { |
| 185 | free(surf); |
| 186 | } |
| 187 | return EGL_TRUE; |
| 188 | } |
| 189 | else { |
| 190 | _eglError(EGL_BAD_SURFACE, "eglDestroySurface"); |
| 191 | return EGL_FALSE; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |
| 196 | /** |
| 197 | * Default fallback routine - drivers might override this. |
| 198 | */ |
| 199 | EGLBoolean |
| 200 | _eglSurfaceAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLint attribute, EGLint value) |
| 201 | { |
| 202 | _EGLSurface *surface = _eglLookupSurface(surf); |
| 203 | |
| 204 | if (surface == NULL) { |
| 205 | _eglError(EGL_BAD_SURFACE, "eglSurfaceAttrib"); |
| 206 | return EGL_FALSE; |
| 207 | } |
| 208 | |
| 209 | switch (attribute) { |
| 210 | case EGL_MIPMAP_LEVEL: |
| 211 | surface->MipmapLevel = value; |
| 212 | break; |
| 213 | default: |
| 214 | _eglError(EGL_BAD_ATTRIBUTE, "eglSurfaceAttrib"); |
| 215 | return EGL_FALSE; |
| 216 | } |
| 217 | return EGL_TRUE; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | EGLBoolean |
| 222 | _eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 223 | { |
| 224 | /* XXX unfinished */ |
| 225 | return EGL_FALSE; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | EGLBoolean |
| 230 | _eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 231 | { |
| 232 | /* XXX unfinished */ |
| 233 | return EGL_FALSE; |
| 234 | } |
| 235 | |
| 236 | |
| 237 | EGLBoolean |
| 238 | _eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval) |
| 239 | { |
| 240 | _EGLSurface *surf = _eglGetCurrentSurface(EGL_DRAW); |
| 241 | if (surf == NULL) { |
| 242 | _eglError(EGL_BAD_SURFACE, "eglSwapInterval"); |
| 243 | return EGL_FALSE; |
| 244 | } |
| 245 | surf->SwapInterval = interval; |
| 246 | return EGL_TRUE; |
| 247 | } |
| 248 | |
| 249 | |