From: Emil Velikov Date: Tue, 20 Jun 2017 14:40:28 +0000 (+0100) Subject: egl: fold _eglError() + return EGL_FALSE X-Git-Tag: upstream/18.1.0~8368 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c58af5cbb295760687b23428f8ac240459e5cf56;p=platform%2Fupstream%2Fmesa.git egl: fold _eglError() + return EGL_FALSE The function _eglError() already explicitly returns EGL_FALSE, explicitly to simplify the callers. Make use of it. While EGL_FALSE is numerically identical to false, NULL, EGL_NO_FOO, storage is not the same so we cannot use it for "everything". Signed-off-by: Emil Velikov Reviewed-by: Eric Engestrom --- diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index a022a5d..f81bd35 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1969,10 +1969,8 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) * incomplete, EGL_BAD_PARAMETER is generated." */ if (attrs->Width <= 0 || attrs->Height <= 0 || - !attrs->DMABufFourCC.IsPresent) { - _eglError(EGL_BAD_PARAMETER, "attribute(s) missing"); - return EGL_FALSE; - } + !attrs->DMABufFourCC.IsPresent) + return _eglError(EGL_BAD_PARAMETER, "attribute(s) missing"); /** * Also: @@ -1983,10 +1981,8 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) */ for (unsigned i = 0; i < ARRAY_SIZE(attrs->DMABufPlanePitches); ++i) { if (attrs->DMABufPlanePitches[i].IsPresent && - attrs->DMABufPlanePitches[i].Value <= 0) { - _eglError(EGL_BAD_ACCESS, "invalid pitch"); - return EGL_FALSE; - } + attrs->DMABufPlanePitches[i].Value <= 0) + return _eglError(EGL_BAD_ACCESS, "invalid pitch"); } /** @@ -1998,10 +1994,8 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) */ for (unsigned i = 0; i < DMA_BUF_MAX_PLANES; ++i) { if (attrs->DMABufPlaneModifiersLo[i].IsPresent != - attrs->DMABufPlaneModifiersHi[i].IsPresent) { - _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing"); - return EGL_FALSE; - } + attrs->DMABufPlaneModifiersHi[i].IsPresent) + return _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing"); } /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't @@ -2013,10 +2007,8 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) (attrs->DMABufPlaneModifiersLo[0].Value != attrs->DMABufPlaneModifiersLo[i].Value) || (attrs->DMABufPlaneModifiersHi[0].Value != - attrs->DMABufPlaneModifiersHi[i].Value)) { - _eglError(EGL_BAD_PARAMETER, "modifier attributes not equal"); - return EGL_FALSE; - } + attrs->DMABufPlaneModifiersHi[i].Value)) + return _eglError(EGL_BAD_PARAMETER, "modifier attributes not equal"); } } @@ -2160,10 +2152,8 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp, EGLint max, EGLint *formats, EGLint *count) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - if (max < 0 || (max > 0 && formats == NULL)) { - _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats"); - return EGL_FALSE; - } + if (max < 0 || (max > 0 && formats == NULL)) + return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats"); if (dri2_dpy->image->base.version < 15 || dri2_dpy->image->queryDmaBufFormats == NULL) @@ -2183,15 +2173,11 @@ dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format, { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - if (max < 0) { - _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats"); - return EGL_FALSE; - } + if (max < 0) + return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats"); - if (max > 0 && modifiers == NULL) { - _eglError(EGL_BAD_PARAMETER, "invalid modifiers array"); - return EGL_FALSE; - } + if (max > 0 && modifiers == NULL) + return _eglError(EGL_BAD_PARAMETER, "invalid modifiers array"); if (dri2_dpy->image->base.version < 15 || dri2_dpy->image->queryDmaBufModifiers == NULL) @@ -2200,10 +2186,8 @@ dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format, if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format, max, modifiers, (unsigned int *) external_only, - count) == false) { - _eglError(EGL_BAD_PARAMETER, "invalid format"); - return EGL_FALSE; - } + count) == false) + return _eglError(EGL_BAD_PARAMETER, "invalid format"); return EGL_TRUE; } @@ -2406,10 +2390,8 @@ dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, (void) drv; if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, - __DRI_IMAGE_ATTRIB_NAME, name)) { - _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); - return EGL_FALSE; - } + __DRI_IMAGE_ATTRIB_NAME, name)) + return _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); if (handle) dri2_dpy->image->queryImage(dri2_img->dri_image, @@ -2966,15 +2948,11 @@ dri2_signal_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); EGLint ret; - if (sync->Type != EGL_SYNC_REUSABLE_KHR) { - _eglError(EGL_BAD_MATCH, "eglSignalSyncKHR"); - return EGL_FALSE; - } + if (sync->Type != EGL_SYNC_REUSABLE_KHR) + return _eglError(EGL_BAD_MATCH, "eglSignalSyncKHR"); - if (mode != EGL_SIGNALED_KHR && mode != EGL_UNSIGNALED_KHR) { - _eglError(EGL_BAD_ATTRIBUTE, "eglSignalSyncKHR"); - return EGL_FALSE; - } + if (mode != EGL_SIGNALED_KHR && mode != EGL_UNSIGNALED_KHR) + return _eglError(EGL_BAD_ATTRIBUTE, "eglSignalSyncKHR"); dri2_sync->base.SyncStatus = mode; @@ -2982,10 +2960,8 @@ dri2_signal_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, ret = cnd_broadcast(&dri2_sync->cond); /* fail to broadcast */ - if (ret) { - _eglError(EGL_BAD_ACCESS, "eglSignalSyncKHR"); - return EGL_FALSE; - } + if (ret) + return _eglError(EGL_BAD_ACCESS, "eglSignalSyncKHR"); } return EGL_TRUE; diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index aef8a10..3be69d8 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -666,10 +666,8 @@ droid_set_damage_region(_EGLDriver *drv, return EGL_TRUE; droid_rects = malloc(n_rects * sizeof(android_native_rect_t)); - if (droid_rects == NULL) { - _eglError(EGL_BAD_ALLOC, "eglSetDamageRegionKHR"); - return EGL_FALSE; - } + if (droid_rects == NULL) + return _eglError(EGL_BAD_ALLOC, "eglSetDamageRegionKHR"); for (EGLint num_drects = 0; num_drects < n_rects; num_drects++) { EGLint i = num_drects * 4; diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index c5ae49e..8e12aed 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -434,10 +434,8 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) /* Make sure we have a back buffer in case we're swapping without * ever rendering. */ - if (get_back_bo(dri2_surf) < 0) { - _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers"); - return EGL_FALSE; - } + if (get_back_bo(dri2_surf) < 0) + return _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers"); dri2_surf->current = dri2_surf->back; dri2_surf->current->age = 1; diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index a50b763..d56d658 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -727,10 +727,8 @@ dri2_wl_swap_buffers_with_damage(_EGLDriver *drv, /* Make sure we have a back buffer in case we're swapping without ever * rendering. */ - if (get_back_bo(dri2_surf) < 0) { - _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers"); - return EGL_FALSE; - } + if (get_back_bo(dri2_surf) < 0) + return _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers"); if (draw->SwapInterval > 0) { dri2_surf->throttle_callback = diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 324128d..9176c8e 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -902,8 +902,7 @@ dri2_x11_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) if (dri2_x11_swap_buffers_msc(drv, disp, draw, 0, 0, 0) == -1) { /* Swap failed with a window drawable. */ - _eglError(EGL_BAD_NATIVE_WINDOW, __func__); - return EGL_FALSE; + return _eglError(EGL_BAD_NATIVE_WINDOW, __func__); } return EGL_TRUE; } @@ -1116,10 +1115,8 @@ dri2_x11_get_sync_values(_EGLDisplay *display, _EGLSurface *surface, cookie = xcb_dri2_get_msc(dri2_dpy->conn, dri2_surf->drawable); reply = xcb_dri2_get_msc_reply(dri2_dpy->conn, cookie, NULL); - if (!reply) { - _eglError(EGL_BAD_ACCESS, __func__); - return EGL_FALSE; - } + if (!reply) + return _eglError(EGL_BAD_ACCESS, __func__); *ust = ((EGLuint64KHR) reply->ust_hi << 32) | reply->ust_lo; *msc = ((EGLuint64KHR) reply->msc_hi << 32) | reply->msc_lo; diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp index ef74f65..10f3abc 100644 --- a/src/egl/drivers/haiku/egl_haiku.cpp +++ b/src/egl/drivers/haiku/egl_haiku.cpp @@ -150,10 +150,8 @@ haiku_add_configs_for_visuals(_EGLDisplay *dpy) struct haiku_egl_config* conf; conf = (struct haiku_egl_config*) calloc(1, sizeof (*conf)); - if (!conf) { - _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals"); - return EGL_FALSE; - } + if (!conf) + return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals"); _eglInitConfig(&conf->base, dpy, 1); TRACE("Config inited\n"); diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index 05cc523..df8b45c 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -489,10 +489,8 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, _EGLConfig *conf, const EGLenum api = eglQueryAPI(); EGLint err; - if (api == EGL_NONE) { - _eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)"); - return EGL_FALSE; - } + if (api == EGL_NONE) + return _eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)"); _eglInitResource(&ctx->Resource, sizeof(*ctx), dpy); ctx->ClientAPI = api; diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 6eeaa35..7aaab3c 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -495,12 +495,10 @@ _eglParseX11DisplayAttribList(_EGLDisplay *display, const EGLint *attrib_list) /* EGL_EXT_platform_x11 recognizes exactly one attribute, * EGL_PLATFORM_X11_SCREEN_EXT, which is optional. */ - if (attrib == EGL_PLATFORM_X11_SCREEN_EXT) { - display->Options.Platform = (void *)(uintptr_t)value; - } else { - _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); - return EGL_FALSE; - } + if (attrib != EGL_PLATFORM_X11_SCREEN_EXT) + return _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); + + display->Options.Platform = (void *)(uintptr_t)value; } return EGL_TRUE; diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index 8094912..f6e41f1 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -286,11 +286,9 @@ _eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type, return EGL_FALSE; } - if ((conf->SurfaceType & type) == 0) { + if ((conf->SurfaceType & type) == 0) /* The config can't be used to create a surface of this type */ - _eglError(EGL_BAD_MATCH, func); - return EGL_FALSE; - } + return _eglError(EGL_BAD_MATCH, func); _eglInitResource(&surf->Resource, sizeof(*surf), dpy); surf->Type = type; @@ -397,36 +395,32 @@ _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, *value = surface->VGColorspace; break; case EGL_GL_COLORSPACE_KHR: - if (!dpy->Extensions.KHR_gl_colorspace) { - _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); - return EGL_FALSE; - } + if (!dpy->Extensions.KHR_gl_colorspace) + return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); + *value = surface->GLColorspace; break; case EGL_POST_SUB_BUFFER_SUPPORTED_NV: *value = surface->PostSubBufferSupportedNV; break; case EGL_BUFFER_AGE_EXT: - if (!dpy->Extensions.EXT_buffer_age) { - _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); - return EGL_FALSE; - } + if (!dpy->Extensions.EXT_buffer_age) + return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); + _EGLContext *ctx = _eglGetCurrentContext(); EGLint result = drv->API.QueryBufferAge(drv, dpy, surface); /* error happened */ if (result < 0) return EGL_FALSE; if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || - ctx->DrawSurface != surface) { - _eglError(EGL_BAD_SURFACE, "eglQuerySurface"); - return EGL_FALSE; - } + ctx->DrawSurface != surface) + return _eglError(EGL_BAD_SURFACE, "eglQuerySurface"); + *value = result; surface->BufferAgeRead = EGL_TRUE; break; default: - _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); - return EGL_FALSE; + return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); } return EGL_TRUE; @@ -513,25 +507,17 @@ _eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, if (dpy->Extensions.NOK_texture_from_pixmap) texture_type |= EGL_PIXMAP_BIT; - if (!(surface->Type & texture_type)) { - _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); - return EGL_FALSE; - } + if (!(surface->Type & texture_type)) + return _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); - if (surface->TextureFormat == EGL_NO_TEXTURE) { - _eglError(EGL_BAD_MATCH, "eglBindTexImage"); - return EGL_FALSE; - } + if (surface->TextureFormat == EGL_NO_TEXTURE) + return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); - if (surface->TextureTarget == EGL_NO_TEXTURE) { - _eglError(EGL_BAD_MATCH, "eglBindTexImage"); - return EGL_FALSE; - } + if (surface->TextureTarget == EGL_NO_TEXTURE) + return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); - if (buffer != EGL_BACK_BUFFER) { - _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); - return EGL_FALSE; - } + if (buffer != EGL_BACK_BUFFER) + return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); surface->BoundToTexture = EGL_TRUE; @@ -549,10 +535,7 @@ _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint texture_type = EGL_PBUFFER_BIT; if (surf == EGL_NO_SURFACE) - { - _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); - return EGL_FALSE; - } + return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); if (!surf->BoundToTexture) { @@ -561,25 +544,16 @@ _eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, } if (surf->TextureFormat == EGL_NO_TEXTURE) - { - _eglError(EGL_BAD_MATCH, "eglReleaseTexImage"); - return EGL_FALSE; - } + return _eglError(EGL_BAD_MATCH, "eglReleaseTexImage"); if (buffer != EGL_BACK_BUFFER) - { - _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage"); - return EGL_FALSE; - } + return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage"); if (dpy->Extensions.NOK_texture_from_pixmap) texture_type |= EGL_PIXMAP_BIT; if (!(surf->Type & texture_type)) - { - _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); - return EGL_FALSE; - } + return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); surf->BoundToTexture = EGL_FALSE;