diff options
Diffstat (limited to 'src/egl/main/eglsurface.c')
-rw-r--r-- | src/egl/main/eglsurface.c | 276 |
1 files changed, 185 insertions, 91 deletions
diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index fdc2de6236..82f47f116b 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -10,16 +10,134 @@ #include <string.h> #include "eglcontext.h" #include "eglconfig.h" -#include "eglsurface.h" #include "eglglobals.h" #include "eglhash.h" +#include "egllog.h" +#include "eglsurface.h" -void -_eglInitSurface(_EGLSurface *surf) +/** + * Do error check on parameters and initialize the given _EGLSurface object. + * \return EGL_TRUE if no errors, EGL_FALSE otherwise. + */ +EGLBoolean +_eglInitSurface(_EGLDriver *drv, EGLDisplay dpy, + _EGLSurface *surf, EGLint type, EGLConfig config, + const EGLint *attrib_list) { - /* XXX fix this up */ + const char *func; + _EGLConfig *conf; + EGLint width = 0, height = 0, largest = 0; + EGLint texFormat = 0, texTarget = 0, mipmapTex = 0; + EGLint i; + + switch (type) { + case EGL_WINDOW_BIT: + func = "eglCreateWindowSurface"; + break; + case EGL_PIXMAP_BIT: + func = "eglCreatePixmapSurface"; + break; + case EGL_PBUFFER_BIT: + func = "eglCreatePBufferSurface"; + break; + case EGL_SCREEN_BIT_MESA: + func = "eglCreateScreenSurface"; + break; + default: + _eglLog(_EGL_WARNING, "Bad type in _eglInitSurface"); + return EGL_FALSE; + } + + conf = _eglLookupConfig(drv, dpy, config); + if (!conf) { + _eglError(EGL_BAD_CONFIG, func); + return EGL_FALSE; + } + + /* + * Parse attribute list. Different kinds of surfaces support different + * attributes. + */ + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + case EGL_WIDTH: + if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) { + width = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_HEIGHT: + if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) { + height = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_LARGEST_PBUFFER: + if (type == EGL_PBUFFER_BIT) { + largest = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_TEXTURE_FORMAT: + if (type == EGL_PBUFFER_BIT) { + texFormat = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_TEXTURE_TARGET: + if (type == EGL_PBUFFER_BIT) { + texTarget = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_MIPMAP_TEXTURE: + if (type == EGL_PBUFFER_BIT) { + mipmapTex = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + default: + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + } + + if (width <= 0 || height <= 0) { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + memset(surf, 0, sizeof(_EGLSurface)); + surf->Config = conf; + surf->Type = type; + surf->Width = width; + surf->Height = height; + surf->TextureFormat = texFormat; + surf->TextureTarget = texTarget; + surf->MipmapTexture = mipmapTex; + surf->MipmapLevel = 0; + surf->SwapInterval = 0; + + return EGL_TRUE; } @@ -27,7 +145,9 @@ void _eglSaveSurface(_EGLSurface *surf) { assert(surf); + assert(!surf->Handle); surf->Handle = _eglHashGenKey(_eglGlobal.Contexts); + assert(surf->Handle); _eglHashInsert(_eglGlobal.Surfaces, surf->Handle, surf); } @@ -86,7 +206,8 @@ _eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) EGLBoolean -_eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixmapType target) +_eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, + NativePixmapType target) { /* copy surface to native pixmap */ /* All implementation burdon for this is in the device driver */ @@ -95,7 +216,8 @@ _eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixma EGLBoolean -_eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLint attribute, EGLint *value) +_eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, + EGLint attribute, EGLint *value) { _EGLSurface *surface = _eglLookupSurface(surf); if (surface == NULL) { @@ -140,34 +262,82 @@ _eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLint attrib /** - * Default fallback routine - drivers should usually override this. + * Example function - drivers should do a proper implementation. */ EGLSurface -_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) +_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + NativeWindowType window, const EGLint *attrib_list) { - /* nothing - just a placeholder */ +#if 0 /* THIS IS JUST EXAMPLE CODE */ + _EGLSurface *surf; + + surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, surf, EGL_WINDOW_BIT, config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(surf); + + return surf->Handle; +#endif return EGL_NO_SURFACE; } /** - * Default fallback routine - drivers should usually override this. + * Example function - drivers should do a proper implementation. */ EGLSurface -_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list) +_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + NativePixmapType pixmap, const EGLint *attrib_list) { - /* nothing - just a placeholder */ +#if 0 /* THIS IS JUST EXAMPLE CODE */ + _EGLSurface *surf; + + surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, surf, EGL_PIXMAP_BIT, config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(surf); + + return surf->Handle; +#endif return EGL_NO_SURFACE; } /** - * Default fallback routine - drivers should usually override this. + * Example function - drivers should do a proper implementation. */ EGLSurface -_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) { - /* nothing - just a placeholder */ +#if 0 /* THIS IS JUST EXAMPLE CODE */ + _EGLSurface *surf; + + surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, surf, EGL_PBUFFER_BIT, config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(surf); + + return surf->Handle; +#endif return EGL_NO_SURFACE; } @@ -248,79 +418,3 @@ _eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval) surf->SwapInterval = interval; return EGL_TRUE; } - - - -/** - ** EGL Surface Utility Functions. This could be handy for device drivers. - **/ - - -/** - * Initialize the fields of the given _EGLSurface object from the other - * parameters. Do error checking too. Allocate EGLSurface handle and - * insert into hash table. - * \return EGLSurface handle or EGL_NO_SURFACE if any error - */ -EGLSurface -_eglInitPbufferSurface(_EGLSurface *surface, _EGLDriver *drv, EGLDisplay dpy, - EGLConfig config, const EGLint *attrib_list) -{ - _EGLConfig *conf; - EGLint width = 0, height = 0, largest = 0; - EGLint texFormat = 0, texTarget = 0, mipmapTex = 0; - EGLint i; - - conf = _eglLookupConfig(drv, dpy, config); - if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreatePbufferSurface"); - return EGL_NO_SURFACE; - } - - for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { - switch (attrib_list[i]) { - case EGL_WIDTH: - width = attrib_list[++i]; - break; - case EGL_HEIGHT: - height = attrib_list[++i]; - break; - case EGL_LARGEST_PBUFFER: - largest = attrib_list[++i]; - break; - case EGL_TEXTURE_FORMAT: - texFormat = attrib_list[++i]; - break; - case EGL_TEXTURE_TARGET: - texTarget = attrib_list[++i]; - break; - case EGL_MIPMAP_TEXTURE: - mipmapTex = attrib_list[++i]; - break; - default: - _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePbufferSurface"); - return EGL_NO_SURFACE; - } - } - - if (width <= 0 || height <= 0) { - _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePbufferSurface(width or height)"); - return EGL_NO_SURFACE; - } - - surface->Config = conf; - surface->Type = EGL_PBUFFER_BIT; - surface->Width = width; - surface->Height = height; - surface->TextureFormat = texFormat; - surface->TextureTarget = texTarget; - surface->MipmapTexture = mipmapTex; - surface->MipmapLevel = 0; - surface->SwapInterval = 0; - - /* insert into hash table */ - _eglSaveSurface(surface); - assert(surface->Handle); - - return surface->Handle; -} |