diff mbox

[5/8] dri/common: Add functions mapping MESA_FORMAT_* <-> __DRI_IMAGE_FORMAT_*

Message ID 1383618208-21310-6-git-send-email-keithp@keithp.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Keith Packard Nov. 5, 2013, 2:23 a.m. UTC
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 <keithp@keithp.com>
---
 src/mesa/drivers/dri/common/dri_util.c | 62 ++++++++++++++++++++++++++++++++++
 src/mesa/drivers/dri/common/dri_util.h |  6 ++++
 2 files changed, 68 insertions(+)

Comments

Jordan Justen Nov. 5, 2013, 3:01 a.m. UTC | #1
On Mon, Nov 4, 2013 at 6:23 PM, Keith Packard <keithp@keithp.com> wrote:
> 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 <keithp@keithp.com>
> ---
>  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 95c8b41..76c8ae5 100644
> --- a/src/mesa/drivers/dri/common/dri_util.c
> +++ b/src/mesa/drivers/dri/common/dri_util.c
> @@ -792,3 +792,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;

After patch 6, this will add SARGB8, right? So, maybe add this to the
commit message, or separate out adding SARGB8 into a separate commit?

Patches 1-6: Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

-Jordan

> +   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 5b56061..fd40769 100644
> --- a/src/mesa/drivers/dri/common/dri_util.h
> +++ b/src/mesa/drivers/dri/common/dri_util.h
> @@ -271,6 +271,12 @@ struct __DRIdrawableRec {
>      } dri2;
>  };
>
> +extern uint32_t
> +driGLFormatToImageFormat(gl_format format);
> +
> +extern gl_format
> +driImageFormatToGLFormat(uint32_t image_format);
> +
>  extern void
>  dri2InvalidateDrawable(__DRIdrawable *drawable);
>
> --
> 1.8.4.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
Keith Packard Nov. 5, 2013, 4:11 a.m. UTC | #2
Jordan Justen <jljusten@gmail.com> writes:


> After patch 6, this will add SARGB8, right? So, maybe add this to the
> commit message, or separate out adding SARGB8 into a separate commit?

I added the SARGB8 define in patch 4; is there some other separation you
think would be warranted?

Oh, just so everyone knows -- krh and I chatted for a while this morning
and decided that this whole __DRI_IMAGE_FORMAT_* stuff is just a bad
idea and we should remove it all and just use __DRI_IMAGE_FOURCC_*
everywhere. I didn't want to mix that change up with this series though.

> Patches 1-6: Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

Thanks!
Kristian Høgsberg Nov. 5, 2013, 10:35 p.m. UTC | #3
On Mon, Nov 04, 2013 at 06:23:25PM -0800, Keith Packard wrote:
> 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.

I'll take the bait... before the i915/i965 split, this code was only
needed in this one place.  All other drivers are gallium drivers which
need to convert to galliums enum pipe_format instead of the gl_format
enum.  Anyway, the code certainly looks more at home in dri_util.c.

Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>

> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
>  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 95c8b41..76c8ae5 100644
> --- a/src/mesa/drivers/dri/common/dri_util.c
> +++ b/src/mesa/drivers/dri/common/dri_util.c
> @@ -792,3 +792,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 5b56061..fd40769 100644
> --- a/src/mesa/drivers/dri/common/dri_util.h
> +++ b/src/mesa/drivers/dri/common/dri_util.h
> @@ -271,6 +271,12 @@ struct __DRIdrawableRec {
>      } dri2;
>  };
>  
> +extern uint32_t
> +driGLFormatToImageFormat(gl_format format);
> +
> +extern gl_format
> +driImageFormatToGLFormat(uint32_t image_format);
> +
>  extern void
>  dri2InvalidateDrawable(__DRIdrawable *drawable);
>  
> -- 
> 1.8.4.2
>
Jordan Justen Nov. 5, 2013, 10:53 p.m. UTC | #4
On Mon, Nov 4, 2013 at 8:11 PM, Keith Packard <keithp@keithp.com> wrote:
> Jordan Justen <jljusten@gmail.com> writes:
>> After patch 6, this will add SARGB8, right? So, maybe add this to the
>> commit message, or separate out adding SARGB8 into a separate commit?
>
> I added the SARGB8 define in patch 4; is there some other separation you
> think would be warranted?

I was just noting that a side effect of patch five is adding support
for SARGB8. When you remove the code in patch 6, and use these, you've
now added support for this new format.

Not important, but I thought it might be worth noting in the commit
message. Actually probably noting it in the commit message for patch 6
is better since the change happens at that point.

-Jordan
Keith Packard Nov. 6, 2013, 12:54 a.m. UTC | #5
Kristian Høgsberg <hoegsberg@gmail.com> writes:

> I'll take the bait... before the i915/i965 split, this code was only
> needed in this one place.  All other drivers are gallium drivers which
> need to convert to galliums enum pipe_format instead of the gl_format
> enum.  Anyway, the code certainly looks more at home in dri_util.c.

Yeah, the i915/i965 split wasn't fun to rebase across at all. Oh well,
I'm sure it was for the best :-)

> Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>

Thanks!
diff mbox

Patch

diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index 95c8b41..76c8ae5 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -792,3 +792,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 5b56061..fd40769 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -271,6 +271,12 @@  struct __DRIdrawableRec {
     } dri2;
 };
 
+extern uint32_t
+driGLFormatToImageFormat(gl_format format);
+
+extern gl_format
+driImageFormatToGLFormat(uint32_t image_format);
+
 extern void
 dri2InvalidateDrawable(__DRIdrawable *drawable);