[Mesa-dev] [PATCH 3/7] util: add util_format_is_subset() function

Brian Paul brian.e.paul at gmail.com
Mon Feb 27 19:29:58 PST 2012


From: Brian Paul <brianp at vmware.com>

Helpful for checking if we can directly blit an RGBA surface to RGBX surface,
for example.
---
 src/gallium/auxiliary/util/u_format.c |   55 +++++++++++++++++++++++++++++++++
 src/gallium/auxiliary/util/u_format.h |    5 +++
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index cfc4a17..68995d3 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -214,6 +214,61 @@ util_format_is_supported(enum pipe_format format, unsigned bind)
 }
 
 
+/**
+ * Is format1 a subset of format2?  That is, do format1 and format2 only
+ * differ by an 'X' (undefined) channel in format1?
+ * For example, B8G8R8X8 is considered to be a subset of B8G8R8A8.
+ */
+boolean
+util_format_is_subset(enum pipe_format format1, enum pipe_format format2)
+{
+   if (format1 == format2)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_B8G8R8X8_UNORM &&
+       format2 == PIPE_FORMAT_B8G8R8A8_UNORM)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_X8B8G8R8_UNORM &&
+       format2 == PIPE_FORMAT_A8B8G8R8_UNORM)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_X8R8G8B8_UNORM &&
+       format2 == PIPE_FORMAT_A8R8G8B8_UNORM)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_R8G8B8X8_UNORM &&
+       format2 == PIPE_FORMAT_R8G8B8A8_UNORM)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_X8B8G8R8_SRGB &&
+       format2 == PIPE_FORMAT_A8B8G8R8_SRGB)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_B8G8R8X8_SRGB &&
+       format2 == PIPE_FORMAT_B8G8R8A8_SRGB)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_X8R8G8B8_SRGB &&
+       format2 == PIPE_FORMAT_A8R8G8B8_SRGB)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_B4G4R4X4_UNORM &&
+       format2 == PIPE_FORMAT_B4G4R4A4_UNORM)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_Z24X8_UNORM &&
+       format2 == PIPE_FORMAT_Z24_UNORM_S8_UINT)
+      return TRUE;
+
+   if (format1 == PIPE_FORMAT_X8Z24_UNORM &&
+       format2 == PIPE_FORMAT_S8_UINT_Z24_UNORM)
+      return TRUE;
+
+   return FALSE;
+}
+
+
 void
 util_format_read_4f(enum pipe_format format,
                     float *dst, unsigned dst_stride,
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 874ea7e..c984c37 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -891,6 +891,11 @@ util_format_get_first_non_void_channel(enum pipe_format format)
    return i;
 }
 
+
+boolean
+util_format_is_subset(enum pipe_format format1, enum pipe_format format2);
+
+
 /*
  * Format access functions.
  */
-- 
1.7.1



More information about the mesa-dev mailing list