From: Kristian Høgsberg Date: Thu, 5 Jul 2012 04:17:47 +0000 (-0400) Subject: intel: Share common __DRIimage allocation code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1bb15c0a089cb268960d164d354ee6d942b4238f;p=mesa.git intel: Share common __DRIimage allocation code We have the same switch and allocation code in two places. Signed-off-by: Kristian Høgsberg Reviewed-by: Kenneth Graunke --- diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c index 5fc56f7ca20..2b70aa4ebdd 100644 --- a/src/mesa/drivers/dri/intel/intel_screen.c +++ b/src/mesa/drivers/dri/intel/intel_screen.c @@ -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;