From b7818b8c36f9850acb17402d05593cff6c2532f0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 4 Nov 2013 17:29:08 -0800 Subject: [PATCH] dri/common: Add functions mapping MESA_FORMAT_* <-> __DRI_IMAGE_FORMAT_* MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The __DRI_IMAGE_FORMAT codes are used by the image extension, drivers need to be able to translate between them. Instead of duplicating this translation in each driver, create a shared version. Signed-off-by: Keith Packard Reviewed-by: Jordan Justen Reviewed-by: Kristian Høgsberg --- src/mesa/drivers/dri/common/dri_util.c | 62 ++++++++++++++++++++++++++ src/mesa/drivers/dri/common/dri_util.h | 6 +++ 2 files changed, 68 insertions(+) diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index a694114358a..46a2da4cb59 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -797,3 +797,65 @@ driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv) assert(fb->Height == dPriv->h); } } + +uint32_t +driGLFormatToImageFormat(gl_format format) +{ + switch (format) { + case MESA_FORMAT_RGB565: + return __DRI_IMAGE_FORMAT_RGB565; + case MESA_FORMAT_XRGB8888: + return __DRI_IMAGE_FORMAT_XRGB8888; + case MESA_FORMAT_ARGB2101010: + return __DRI_IMAGE_FORMAT_ARGB2101010; + case MESA_FORMAT_XRGB2101010_UNORM: + return __DRI_IMAGE_FORMAT_XRGB2101010; + case MESA_FORMAT_ARGB8888: + return __DRI_IMAGE_FORMAT_ARGB8888; + case MESA_FORMAT_RGBA8888_REV: + return __DRI_IMAGE_FORMAT_ABGR8888; + case MESA_FORMAT_RGBX8888_REV: + return __DRI_IMAGE_FORMAT_XBGR8888; + case MESA_FORMAT_R8: + return __DRI_IMAGE_FORMAT_R8; + case MESA_FORMAT_GR88: + return __DRI_IMAGE_FORMAT_GR88; + case MESA_FORMAT_NONE: + return __DRI_IMAGE_FORMAT_NONE; + case MESA_FORMAT_SARGB8: + return __DRI_IMAGE_FORMAT_SARGB8; + default: + return 0; + } +} + +gl_format +driImageFormatToGLFormat(uint32_t image_format) +{ + switch (image_format) { + case __DRI_IMAGE_FORMAT_RGB565: + return MESA_FORMAT_RGB565; + case __DRI_IMAGE_FORMAT_XRGB8888: + return MESA_FORMAT_XRGB8888; + case __DRI_IMAGE_FORMAT_ARGB2101010: + return MESA_FORMAT_ARGB2101010; + case __DRI_IMAGE_FORMAT_XRGB2101010: + return MESA_FORMAT_XRGB2101010_UNORM; + case __DRI_IMAGE_FORMAT_ARGB8888: + return MESA_FORMAT_ARGB8888; + case __DRI_IMAGE_FORMAT_ABGR8888: + return MESA_FORMAT_RGBA8888_REV; + case __DRI_IMAGE_FORMAT_XBGR8888: + return MESA_FORMAT_RGBX8888_REV; + case __DRI_IMAGE_FORMAT_R8: + return MESA_FORMAT_R8; + case __DRI_IMAGE_FORMAT_GR88: + return MESA_FORMAT_GR88; + case __DRI_IMAGE_FORMAT_SARGB8: + return MESA_FORMAT_SARGB8; + case __DRI_IMAGE_FORMAT_NONE: + return MESA_FORMAT_NONE; + default: + return MESA_FORMAT_NONE; + } +} diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h index b3c21651611..7fab3e5f720 100644 --- a/src/mesa/drivers/dri/common/dri_util.h +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -273,6 +273,12 @@ struct __DRIdrawableRec { } dri2; }; +extern uint32_t +driGLFormatToImageFormat(gl_format format); + +extern gl_format +driImageFormatToGLFormat(uint32_t image_format); + extern void dri2InvalidateDrawable(__DRIdrawable *drawable); -- 2.30.2