egl/x11: deduplicate depth-to-format logic
authorEric Engestrom <eric.engestrom@intel.com>
Thu, 17 May 2018 15:16:34 +0000 (16:16 +0100)
committerEric Engestrom <eric.engestrom@intel.com>
Thu, 24 May 2018 17:01:45 +0000 (18:01 +0100)
Suggested-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/egl/drivers/dri2/platform_x11.c
src/egl/drivers/dri2/platform_x11_dri3.c
src/egl/drivers/dri2/platform_x11_dri3.h

index 7aca0a90203f3e9180e67335ebd09706ed4e3983..b2a3000b252ec0ddb12f873f6b1b08281a78fc16 100644 (file)
@@ -1006,6 +1006,24 @@ dri2_x11_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
    return EGL_TRUE;
 }
 
+uint32_t
+dri2_format_for_depth(uint32_t depth)
+{
+   switch (depth) {
+   case 16:
+      return __DRI_IMAGE_FORMAT_RGB565;
+   case 24:
+      return __DRI_IMAGE_FORMAT_XRGB8888;
+   case 30:
+      return __DRI_IMAGE_FORMAT_XRGB2101010;
+   case 32:
+      return __DRI_IMAGE_FORMAT_ARGB8888;
+   default:
+      return __DRI_IMAGE_FORMAT_NONE;
+   }
+}
+
+
 static _EGLImage *
 dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
                             EGLClientBuffer buffer, const EGLint *attr_list)
@@ -1050,20 +1068,9 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
    }
 
-   switch (geometry_reply->depth) {
-   case 16:
-      format = __DRI_IMAGE_FORMAT_RGB565;
-      break;
-   case 24:
-      format = __DRI_IMAGE_FORMAT_XRGB8888;
-      break;
-   case 30:
-      format = __DRI_IMAGE_FORMAT_XRGB2101010;
-      break;
-   case 32:
-      format = __DRI_IMAGE_FORMAT_ARGB8888;
-      break;
-   default:
+   format = dri2_format_for_depth(geometry_reply->depth);
+
+   if (format == __DRI_IMAGE_FORMAT_NONE) {
       _eglError(EGL_BAD_PARAMETER,
                "dri2_create_image_khr: unsupported pixmap depth");
       free(buffers_reply);
index 5cb6d65c0a3a89d8d2b9b682c234b51bf87ec70b..0d5a9d037f5b5895f23ad2e4424d2a2d1aa3eb70 100644 (file)
 #include "loader.h"
 #include "loader_dri3_helper.h"
 
-static uint32_t
-dri3_format_for_depth(uint32_t depth)
-{
-   switch (depth) {
-   case 16:
-      return __DRI_IMAGE_FORMAT_RGB565;
-   case 24:
-      return __DRI_IMAGE_FORMAT_XRGB8888;
-   case 30:
-      return __DRI_IMAGE_FORMAT_XRGB2101010;
-   case 32:
-      return __DRI_IMAGE_FORMAT_ARGB8888;
-   default:
-      return __DRI_IMAGE_FORMAT_NONE;
-   }
-}
-
 static struct dri3_egl_surface *
 loader_drawable_to_egl_surface(struct loader_dri3_drawable *draw) {
    size_t offset = offsetof(struct dri3_egl_surface, loader_drawable);
@@ -298,7 +281,7 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
    }
 
-   format = dri3_format_for_depth(bp_reply->depth);
+   format = dri2_format_for_depth(bp_reply->depth);
    if (format == __DRI_IMAGE_FORMAT_NONE) {
       _eglError(EGL_BAD_PARAMETER,
                 "dri3_create_image_khr: unsupported pixmap depth");
@@ -350,7 +333,7 @@ dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx,
       return EGL_NO_IMAGE_KHR;
    }
 
-   format = dri3_format_for_depth(bp_reply->depth);
+   format = dri2_format_for_depth(bp_reply->depth);
    if (format == __DRI_IMAGE_FORMAT_NONE) {
       _eglError(EGL_BAD_PARAMETER,
                 "dri3_create_image_khr: unsupported pixmap depth");
index 96e7ee972d9f76afb061124ca4ba188a6e19deda..e6fd0136697833db97084da56f302593c6b2feee 100644 (file)
@@ -38,4 +38,7 @@ extern struct dri2_egl_display_vtbl dri3_x11_display_vtbl;
 EGLBoolean
 dri3_x11_connect(struct dri2_egl_display *dri2_dpy);
 
+uint32_t
+dri2_format_for_depth(uint32_t depth);
+
 #endif