[Mesa-dev] [PATCH 2/2] egl: fold _eglError() + return EGL_FALSE

Emil Velikov emil.l.velikov at gmail.com
Tue Jun 20 15:04:48 UTC 2017


From: Emil Velikov <emil.velikov at collabora.com>

The function _eglError() already explicitly returns EGL_FALSE,
explicitly to simplify the callers. Make use of it.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c         | 72 +++++++++++---------------------
 src/egl/drivers/dri2/platform_android.c |  6 +--
 src/egl/drivers/dri2/platform_drm.c     |  6 +--
 src/egl/drivers/dri2/platform_wayland.c |  6 +--
 src/egl/drivers/dri2/platform_x11.c     |  9 ++--
 src/egl/drivers/haiku/egl_haiku.cpp     |  6 +--
 src/egl/main/eglcontext.c               |  6 +--
 src/egl/main/egldisplay.c               | 10 ++---
 src/egl/main/eglsurface.c               | 74 +++++++++++----------------------
 9 files changed, 65 insertions(+), 130 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 7b951b7590d..b9a3c6e3e82 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1978,10 +1978,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:
@@ -1992,10 +1990,8 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)
     */
    for (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");
    }
 
    /**
@@ -2007,10 +2003,8 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)
     */
    for (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
@@ -2022,10 +2016,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");
       }
    }
 
@@ -2169,10 +2161,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)
@@ -2192,15 +2182,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)
@@ -2209,10 +2195,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;
 }
@@ -2416,10 +2400,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,
@@ -2976,15 +2958,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;
 
@@ -2992,10 +2970,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 8f76ab5f2fc..b2292e73cb0 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -671,10 +671,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 df61c0665f9..edecfd9517e 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -440,10 +440,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 f746f0bfd1c..0162ff36929 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -735,10 +735,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 ca36a56e080..aece4f09b62 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -898,8 +898,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;
 }
@@ -1113,10 +1112,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 ef74f657b14..10f3abc070a 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 05cc523c8d1..df8b45c7bd6 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 6eeaa35eb63..7aaab3c2c94 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 8094912ba12..f6e41f10d78 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;
 
-- 
2.13.0



More information about the mesa-dev mailing list