intel: Share common __DRIimage allocation code
authorKristian Høgsberg <krh@bitplanet.net>
Thu, 5 Jul 2012 04:17:47 +0000 (00:17 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 5 Jul 2012 18:22:07 +0000 (14:22 -0400)
We have the same switch and allocation code in two places.

Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/intel/intel_screen.c

index 5fc56f7ca20c72adabbb9aab18f30bd777fc5c85..2b70aa4ebddc1ef6908d7b01800656954f08f4eb 100644 (file)
@@ -176,21 +176,17 @@ static const struct __DRI2flushExtensionRec intelFlushExtension = {
 };
 
 static __DRIimage *
-intel_create_image_from_name(__DRIscreen *screen,
-                            int width, int height, int format,
-                            int name, int pitch, void *loaderPrivate)
+intel_allocate_image(int dri_format, void *loaderPrivate)
 {
-    struct intel_screen *intelScreen = screen->driverPrivate;
     __DRIimage *image;
-    int cpp;
 
     image = CALLOC(sizeof *image);
     if (image == NULL)
        return NULL;
 
-    image->dri_format = format;
+    image->dri_format = dri_format;
 
-    switch (format) {
+    switch (dri_format) {
     case __DRI_IMAGE_FORMAT_RGB565:
        image->format = MESA_FORMAT_RGB565;
        break;
@@ -213,8 +209,21 @@ intel_create_image_from_name(__DRIscreen *screen,
 
     image->internal_format = _mesa_get_format_base_format(image->format);
     image->data = loaderPrivate;
-    cpp = _mesa_get_format_bytes(image->format);
 
+    return image;
+}
+
+static __DRIimage *
+intel_create_image_from_name(__DRIscreen *screen,
+                            int width, int height, int format,
+                            int name, int pitch, void *loaderPrivate)
+{
+    struct intel_screen *intelScreen = screen->driverPrivate;
+    __DRIimage *image;
+    int cpp;
+
+    image = intel_allocate_image(format, loaderPrivate);
+    cpp = _mesa_get_format_bytes(image->format);
     image->region = intel_region_alloc_for_handle(intelScreen,
                                                  cpp, width, height,
                                                  pitch, name, "image");
@@ -300,41 +309,11 @@ intel_create_image(__DRIscreen *screen,
        use != (__DRI_IMAGE_USE_WRITE | __DRI_IMAGE_USE_CURSOR))
       return NULL;
 
-   image = CALLOC(sizeof *image);
-   if (image == NULL)
-      return NULL;
-
+   image = intel_allocate_image(format, loaderPrivate);
    image->usage = use;
-   image->dri_format = format;
-
-   switch (format) {
-   case __DRI_IMAGE_FORMAT_RGB565:
-      image->format = MESA_FORMAT_RGB565;
-      break;
-   case __DRI_IMAGE_FORMAT_XRGB8888:
-      image->format = MESA_FORMAT_XRGB8888;
-      break;
-   case __DRI_IMAGE_FORMAT_ARGB8888:
-      image->format = MESA_FORMAT_ARGB8888;
-      break;
-    case __DRI_IMAGE_FORMAT_ABGR8888:
-       image->format = MESA_FORMAT_RGBA8888_REV;
-       break;
-    case __DRI_IMAGE_FORMAT_XBGR8888:
-       image->format = MESA_FORMAT_RGBX8888_REV;
-       break;
-   default:
-      free(image);
-      return NULL;
-   }
-
-   image->internal_format = _mesa_get_format_base_format(image->format);
-   image->data = loaderPrivate;
    cpp = _mesa_get_format_bytes(image->format);
-
    image->region =
-      intel_region_alloc(intelScreen, tiling,
-                        cpp, width, height, true);
+      intel_region_alloc(intelScreen, tiling, cpp, width, height, true);
    if (image->region == NULL) {
       FREE(image);
       return NULL;