diff options
author | Chia-I Wu <olv@lunarg.com> | 2010-02-17 15:22:03 +0800 |
---|---|---|
committer | Chia-I Wu <olv@lunarg.com> | 2010-02-17 20:00:10 +0800 |
commit | f3e03e1277839cddc35e0cc3427a7972bc17a10a (patch) | |
tree | 20d7072dd5236fb6f6c896a55f1612dce1558cb5 /src/egl | |
parent | 31c816731ead9abce69829e6b5f55a201da3bb47 (diff) |
egl: Add new error checking macros.
Add _EGL_CHECK_* which will replace _EGL_DECLARE_* for error checking.
Move _eglCheck* earlier in the file so that the macros and the functions
are grouped together.
Diffstat (limited to 'src/egl')
-rw-r--r-- | src/egl/main/eglapi.c | 228 |
1 files changed, 134 insertions, 94 deletions
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 364ad9c458..b74b960158 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -70,6 +70,140 @@ /** + * Macros to help return an API entrypoint. + */ +#define _EGL_ERROR(disp, err, ret) \ + ({ \ + /* EGL error codes are non-zero */ \ + if (err) \ + _eglError(err, __FUNCTION__); \ + ret; \ + }) + + +/** + * A bunch of macros and checks to simplify error checking. + */ +#define _EGL_CHECK_DISPLAY(disp, ret) \ + ({ \ + _EGLDriver *__drv = _eglCheckDisplay(disp, __FUNCTION__); \ + if (!__drv) \ + return _EGL_ERROR(disp, 0, ret); \ + __drv; \ + }) + + +#define _EGL_CHECK_OBJECT(disp, type, obj, ret) \ + ({ \ + _EGLDriver *__drv = _eglCheck ## type(disp, obj, __FUNCTION__); \ + if (!__drv) \ + return _EGL_ERROR(disp, 0, ret); \ + __drv; \ + }) +#define _EGL_CHECK_SURFACE(disp, surf, ret) \ + _EGL_CHECK_OBJECT(disp, Surface, surf, ret) +#define _EGL_CHECK_CONTEXT(disp, context, ret) \ + _EGL_CHECK_OBJECT(disp, Context, context, ret) +#define _EGL_CHECK_CONFIG(disp, conf, ret) \ + _EGL_CHECK_OBJECT(disp, Config, conf, ret) +#define _EGL_CHECK_SCREEN(disp, scrn, ret) \ + _EGL_CHECK_OBJECT(disp, Screen, scrn, ret) +#define _EGL_CHECK_MODE(disp, m, ret) \ + _EGL_CHECK_OBJECT(disp, Mode, m, ret) + + +static INLINE _EGLDriver * +_eglCheckDisplay(_EGLDisplay *disp, const char *msg) +{ + if (!disp) { + _eglError(EGL_BAD_DISPLAY, msg); + return NULL; + } + if (!disp->Initialized) { + _eglError(EGL_NOT_INITIALIZED, msg); + return NULL; + } + return disp->Driver; +} + + +static INLINE _EGLDriver * +_eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!surf) { + _eglError(EGL_BAD_SURFACE, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!context) { + _eglError(EGL_BAD_CONTEXT, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!conf) { + _eglError(EGL_BAD_CONFIG, msg); + return NULL; + } + return drv; +} + + +#ifdef EGL_MESA_screen_surface + + +static INLINE _EGLDriver * +_eglCheckScreen(_EGLDisplay *disp, _EGLScreen *scrn, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckMode(_EGLDisplay *disp, _EGLMode *m, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!m) { + _eglError(EGL_BAD_MODE_MESA, msg); + return NULL; + } + return drv; +} + + +#endif /* EGL_MESA_screen_surface */ + + +/** * This is typically the first EGL function that an application calls. * We initialize our global vars and create a private _EGLDisplay object. */ @@ -159,66 +293,6 @@ eglTerminate(EGLDisplay dpy) } -/** - * A bunch of check functions and declare macros to simply error checking. - */ -static INLINE _EGLDriver * -_eglCheckDisplay(_EGLDisplay *disp, const char *msg) -{ - if (!disp) { - _eglError(EGL_BAD_DISPLAY, msg); - return NULL; - } - if (!disp->Initialized) { - _eglError(EGL_NOT_INITIALIZED, msg); - return NULL; - } - return disp->Driver; -} - - -static INLINE _EGLDriver * -_eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) -{ - _EGLDriver *drv = _eglCheckDisplay(disp, msg); - if (!drv) - return NULL; - if (!surf) { - _eglError(EGL_BAD_SURFACE, msg); - return NULL; - } - return drv; -} - - -static INLINE _EGLDriver * -_eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) -{ - _EGLDriver *drv = _eglCheckDisplay(disp, msg); - if (!drv) - return NULL; - if (!context) { - _eglError(EGL_BAD_CONTEXT, msg); - return NULL; - } - return drv; -} - - -static INLINE _EGLDriver * -_eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) -{ - _EGLDriver *drv = _eglCheckDisplay(disp, msg); - if (!drv) - return NULL; - if (!conf) { - _eglError(EGL_BAD_CONFIG, msg); - return NULL; - } - return drv; -} - - #define _EGL_DECLARE_DD(dpy) \ _EGLDisplay *disp = _eglLookupDisplay(dpy); \ _EGLDriver *drv; \ @@ -251,37 +325,6 @@ _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) } while (0) -#ifdef EGL_MESA_screen_surface - - -static INLINE _EGLDriver * -_eglCheckScreen(_EGLDisplay *disp, _EGLScreen *scrn, const char *msg) -{ - _EGLDriver *drv = _eglCheckDisplay(disp, msg); - if (!drv) - return NULL; - if (!scrn) { - _eglError(EGL_BAD_SCREEN_MESA, msg); - return NULL; - } - return drv; -} - - -static INLINE _EGLDriver * -_eglCheckMode(_EGLDisplay *disp, _EGLMode *m, const char *msg) -{ - _EGLDriver *drv = _eglCheckDisplay(disp, msg); - if (!drv) - return NULL; - if (!m) { - _eglError(EGL_BAD_MODE_MESA, msg); - return NULL; - } - return drv; -} - - #define _EGL_DECLARE_DD_AND_SCREEN(dpy, screen) \ _EGLDisplay *disp = _eglLookupDisplay(dpy); \ _EGLScreen *scrn = _eglLookupScreen((screen), disp); \ @@ -304,9 +347,6 @@ _eglCheckMode(_EGLDisplay *disp, _EGLMode *m, const char *msg) } while (0) -#endif /* EGL_MESA_screen_surface */ - - const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) { |