egl: split _eglParseImageAttribList into per extension functions
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 28 Jun 2017 21:39:51 +0000 (22:39 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 12 Jul 2017 14:42:54 +0000 (15:42 +0100)
Will allow us to simplify existing code and make further improvements
short and simple.

No functional change intended.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
src/egl/main/eglimage.c

index 619e1a1e5db7a6ed5351a4c7b6623247f2f16f26..8f46725be99b4219f14cb6f42e50fd9df8a2ed1a 100644 (file)
 #include "eglimage.h"
 #include "egllog.h"
 
+static EGLint
+_eglParseKHRImageAttribs(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
+                         EGLint attr, EGLint val)
+{
+   switch (attr) {
+   /* EGL_KHR_image_base */
+   case EGL_IMAGE_PRESERVED_KHR:
+      attrs->ImagePreserved = val;
+      break;
+
+   /* EGL_KHR_gl_image */
+   case EGL_GL_TEXTURE_LEVEL_KHR:
+      attrs->GLTextureLevel = val;
+      break;
+   case EGL_GL_TEXTURE_ZOFFSET_KHR:
+      attrs->GLTextureZOffset = val;
+      break;
+   default:
+      return EGL_BAD_PARAMETER;
+   }
+
+   return EGL_SUCCESS;
+}
+
+static EGLint
+_eglParseMESADrmImageAttribs(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
+                             EGLint attr, EGLint val)
+{
+   switch (attr) {
+   /* EGL_MESA_drm_image */
+   case EGL_WIDTH:
+      attrs->Width = val;
+      break;
+   case EGL_HEIGHT:
+      attrs->Height = val;
+      break;
+   case EGL_DRM_BUFFER_FORMAT_MESA:
+      attrs->DRMBufferFormatMESA = val;
+      break;
+   case EGL_DRM_BUFFER_USE_MESA:
+      attrs->DRMBufferUseMESA = val;
+      break;
+   case EGL_DRM_BUFFER_STRIDE_MESA:
+      attrs->DRMBufferStrideMESA = val;
+      break;
+   default:
+      return EGL_BAD_PARAMETER;
+   }
+
+   return EGL_SUCCESS;
+}
+
+static EGLint
+_eglParseWLBindWaylandDisplayAttribs(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
+                                     EGLint attr, EGLint val)
+{
+   switch (attr) {
+   /* EGL_WL_bind_wayland_display */
+   case EGL_WAYLAND_PLANE_WL:
+      attrs->PlaneWL = val;
+      break;
+   default:
+      return EGL_BAD_PARAMETER;
+   }
+
+   return EGL_SUCCESS;
+}
+
+static EGLint
+_eglParseEXTImageDmaBufImportAttribs(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
+                                     EGLint attr, EGLint val)
+{
+   EGLint err = EGL_SUCCESS;
+
+   switch (attr) {
+   case EGL_LINUX_DRM_FOURCC_EXT:
+      attrs->DMABufFourCC.Value = val;
+      attrs->DMABufFourCC.IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE0_FD_EXT:
+      attrs->DMABufPlaneFds[0].Value = val;
+      attrs->DMABufPlaneFds[0].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE0_OFFSET_EXT:
+      attrs->DMABufPlaneOffsets[0].Value = val;
+      attrs->DMABufPlaneOffsets[0].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE0_PITCH_EXT:
+      attrs->DMABufPlanePitches[0].Value = val;
+      attrs->DMABufPlanePitches[0].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE1_FD_EXT:
+       attrs->DMABufPlaneFds[1].Value = val;
+       attrs->DMABufPlaneFds[1].IsPresent = EGL_TRUE;
+       break;
+   case EGL_DMA_BUF_PLANE1_OFFSET_EXT:
+      attrs->DMABufPlaneOffsets[1].Value = val;
+      attrs->DMABufPlaneOffsets[1].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE1_PITCH_EXT:
+      attrs->DMABufPlanePitches[1].Value = val;
+      attrs->DMABufPlanePitches[1].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE2_FD_EXT:
+      attrs->DMABufPlaneFds[2].Value = val;
+      attrs->DMABufPlaneFds[2].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE2_OFFSET_EXT:
+      attrs->DMABufPlaneOffsets[2].Value = val;
+      attrs->DMABufPlaneOffsets[2].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE2_PITCH_EXT:
+      attrs->DMABufPlanePitches[2].Value = val;
+      attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
+      break;
+   case EGL_YUV_COLOR_SPACE_HINT_EXT:
+      if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
+          val != EGL_ITU_REC2020_EXT) {
+         err = EGL_BAD_ATTRIBUTE;
+      } else {
+         attrs->DMABufYuvColorSpaceHint.Value = val;
+         attrs->DMABufYuvColorSpaceHint.IsPresent = EGL_TRUE;
+      }
+      break;
+   case EGL_SAMPLE_RANGE_HINT_EXT:
+      if (val != EGL_YUV_FULL_RANGE_EXT && val != EGL_YUV_NARROW_RANGE_EXT) {
+         err = EGL_BAD_ATTRIBUTE;
+      } else {
+         attrs->DMABufSampleRangeHint.Value = val;
+         attrs->DMABufSampleRangeHint.IsPresent = EGL_TRUE;
+      }
+      break;
+   case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT:
+      if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
+          val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
+         err = EGL_BAD_ATTRIBUTE;
+      } else {
+         attrs->DMABufChromaHorizontalSiting.Value = val;
+         attrs->DMABufChromaHorizontalSiting.IsPresent = EGL_TRUE;
+      }
+      break;
+   case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT:
+      if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
+          val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
+         err = EGL_BAD_ATTRIBUTE;
+      } else {
+         attrs->DMABufChromaVerticalSiting.Value = val;
+         attrs->DMABufChromaVerticalSiting.IsPresent = EGL_TRUE;
+      }
+      break;
+   default:
+      err = EGL_BAD_PARAMETER;
+      break;
+   }
+
+   return err;
+}
+
+static EGLint
+_eglParseEXTImageDmaBufImportModifiersAttribs(_EGLImageAttribs *attrs,
+                                              _EGLDisplay *dpy,
+                                              EGLint attr, EGLint val)
+{
+   EGLint err = EGL_SUCCESS;
+
+   switch (attr) {
+   case EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersLo[0].Value = val;
+      attrs->DMABufPlaneModifiersLo[0].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersHi[0].Value = val;
+      attrs->DMABufPlaneModifiersHi[0].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersLo[1].Value = val;
+      attrs->DMABufPlaneModifiersLo[1].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersHi[1].Value = val;
+      attrs->DMABufPlaneModifiersHi[1].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersLo[2].Value = val;
+      attrs->DMABufPlaneModifiersLo[2].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersHi[2].Value = val;
+      attrs->DMABufPlaneModifiersHi[2].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE3_FD_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneFds[3].Value = val;
+      attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneOffsets[3].Value = val;
+      attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE3_PITCH_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlanePitches[3].Value = val;
+      attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersLo[3].Value = val;
+      attrs->DMABufPlaneModifiersLo[3].IsPresent = EGL_TRUE;
+      break;
+   case EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT:
+      if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+         err = EGL_BAD_PARAMETER;
+      attrs->DMABufPlaneModifiersHi[3].Value = val;
+      attrs->DMABufPlaneModifiersHi[3].IsPresent = EGL_TRUE;
+      break;
+   default:
+      err = EGL_BAD_PARAMETER;
+      break;
+   }
+
+   return err;
+}
 
 /**
  * Parse the list of image attributes.
@@ -45,9 +284,7 @@ EGLBoolean
 _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
                          const EGLint *attrib_list)
 {
-   EGLint i, err = EGL_SUCCESS;
-
-   (void) dpy;
+   EGLint i, err;
 
    memset(attrs, 0, sizeof(*attrs));
 
@@ -58,190 +295,27 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
       EGLint attr = attrib_list[i++];
       EGLint val = attrib_list[i];
 
-      switch (attr) {
-      /* EGL_KHR_image_base */
-      case EGL_IMAGE_PRESERVED_KHR:
-         attrs->ImagePreserved = val;
-         break;
-
-      /* EGL_KHR_gl_image */
-      case EGL_GL_TEXTURE_LEVEL_KHR:
-         attrs->GLTextureLevel = val;
-         break;
-      case EGL_GL_TEXTURE_ZOFFSET_KHR:
-         attrs->GLTextureZOffset = val;
-         break;
-
-      /* EGL_MESA_drm_image */
-      case EGL_WIDTH:
-         attrs->Width = val;
-         break;
-      case EGL_HEIGHT:
-         attrs->Height = val;
-         break;
-      case EGL_DRM_BUFFER_FORMAT_MESA:
-         attrs->DRMBufferFormatMESA = val;
-         break;
-      case EGL_DRM_BUFFER_USE_MESA:
-         attrs->DRMBufferUseMESA = val;
-         break;
-      case EGL_DRM_BUFFER_STRIDE_MESA:
-         attrs->DRMBufferStrideMESA = val;
-         break;
-
-      /* EGL_WL_bind_wayland_display */
-      case EGL_WAYLAND_PLANE_WL:
-         attrs->PlaneWL = val;
-         break;
-
-      case EGL_LINUX_DRM_FOURCC_EXT:
-         attrs->DMABufFourCC.Value = val;
-         attrs->DMABufFourCC.IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE0_FD_EXT:
-         attrs->DMABufPlaneFds[0].Value = val;
-         attrs->DMABufPlaneFds[0].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE0_OFFSET_EXT:
-         attrs->DMABufPlaneOffsets[0].Value = val;
-         attrs->DMABufPlaneOffsets[0].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE0_PITCH_EXT:
-         attrs->DMABufPlanePitches[0].Value = val;
-         attrs->DMABufPlanePitches[0].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersLo[0].Value = val;
-         attrs->DMABufPlaneModifiersLo[0].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersHi[0].Value = val;
-         attrs->DMABufPlaneModifiersHi[0].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE1_FD_EXT:
-         attrs->DMABufPlaneFds[1].Value = val;
-         attrs->DMABufPlaneFds[1].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE1_OFFSET_EXT:
-         attrs->DMABufPlaneOffsets[1].Value = val;
-         attrs->DMABufPlaneOffsets[1].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE1_PITCH_EXT:
-         attrs->DMABufPlanePitches[1].Value = val;
-         attrs->DMABufPlanePitches[1].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersLo[1].Value = val;
-         attrs->DMABufPlaneModifiersLo[1].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersHi[1].Value = val;
-         attrs->DMABufPlaneModifiersHi[1].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE2_FD_EXT:
-         attrs->DMABufPlaneFds[2].Value = val;
-         attrs->DMABufPlaneFds[2].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE2_OFFSET_EXT:
-         attrs->DMABufPlaneOffsets[2].Value = val;
-         attrs->DMABufPlaneOffsets[2].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE2_PITCH_EXT:
-         attrs->DMABufPlanePitches[2].Value = val;
-         attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersLo[2].Value = val;
-         attrs->DMABufPlaneModifiersLo[2].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersHi[2].Value = val;
-         attrs->DMABufPlaneModifiersHi[2].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE3_FD_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneFds[3].Value = val;
-         attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneOffsets[3].Value = val;
-         attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE3_PITCH_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlanePitches[3].Value = val;
-         attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersLo[3].Value = val;
-         attrs->DMABufPlaneModifiersLo[3].IsPresent = EGL_TRUE;
-         break;
-      case EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT:
-         if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
-            err = EGL_BAD_PARAMETER;
-         attrs->DMABufPlaneModifiersHi[3].Value = val;
-         attrs->DMABufPlaneModifiersHi[3].IsPresent = EGL_TRUE;
-         break;
-      case EGL_YUV_COLOR_SPACE_HINT_EXT:
-         if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
-             val != EGL_ITU_REC2020_EXT) {
-            err = EGL_BAD_ATTRIBUTE;
-         } else {
-            attrs->DMABufYuvColorSpaceHint.Value = val;
-            attrs->DMABufYuvColorSpaceHint.IsPresent = EGL_TRUE;
-         }
-         break;
-      case EGL_SAMPLE_RANGE_HINT_EXT:
-         if (val != EGL_YUV_FULL_RANGE_EXT && val != EGL_YUV_NARROW_RANGE_EXT) {
-            err = EGL_BAD_ATTRIBUTE;
-         } else {
-            attrs->DMABufSampleRangeHint.Value = val;
-            attrs->DMABufSampleRangeHint.IsPresent = EGL_TRUE;
-         }
-         break;
-      case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT:
-         if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
-             val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
-            err = EGL_BAD_ATTRIBUTE;
-         } else {
-            attrs->DMABufChromaHorizontalSiting.Value = val;
-            attrs->DMABufChromaHorizontalSiting.IsPresent = EGL_TRUE;
-         }
-         break;
-      case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT:
-         if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
-             val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
-            err = EGL_BAD_ATTRIBUTE;
-         } else {
-            attrs->DMABufChromaVerticalSiting.Value = val;
-            attrs->DMABufChromaVerticalSiting.IsPresent = EGL_TRUE;
-         }
-         break;
-
-      default:
-         return _eglError(EGL_BAD_ATTRIBUTE, __func__);
-      }
+      err = _eglParseKHRImageAttribs(attrs, dpy, attr, val);
+      if (err == EGL_SUCCESS)
+          continue;
+
+      err = _eglParseMESADrmImageAttribs(attrs, dpy, attr, val);
+      if (err == EGL_SUCCESS)
+          continue;
+
+      err = _eglParseWLBindWaylandDisplayAttribs(attrs, dpy, attr, val);
+      if (err == EGL_SUCCESS)
+          continue;
+
+      err = _eglParseEXTImageDmaBufImportAttribs(attrs, dpy, attr, val);
+      if (err == EGL_SUCCESS)
+          continue;
+
+      err = _eglParseEXTImageDmaBufImportModifiersAttribs(attrs, dpy, attr, val);
+      if (err == EGL_SUCCESS)
+          continue;
 
-      if (err != EGL_SUCCESS)
-         return _eglError(err, __func__);
+      return _eglError(err, __func__);
    }
 
    return EGL_TRUE;