Mesa (master): u_format: add inline helper to find first non void channel
Dave Airlie
airlied at kemper.freedesktop.org
Sat Oct 8 16:47:08 UTC 2011
Module: Mesa
Branch: master
Commit: 61285c6cfa9ce6086d62fa08bc9e3813f0b30d3d
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=61285c6cfa9ce6086d62fa08bc9e3813f0b30d3d
Author: Dave Airlie <airlied at redhat.com>
Date: Sat Oct 8 17:41:33 2011 +0100
u_format: add inline helper to find first non void channel
This is used in a few places in drivers as well, also the integer support
can use it as well.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
src/gallium/auxiliary/util/u_format.c | 10 ++--------
src/gallium/auxiliary/util/u_format.h | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index 9bf4258..129b8e9 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -52,14 +52,8 @@ util_format_is_float(enum pipe_format format)
return FALSE;
}
- /* Find the first non-void channel. */
- for (i = 0; i < 4; i++) {
- if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
- break;
- }
- }
-
- if (i == 4) {
+ i = util_format_get_first_non_void_channel(format);
+ if (i == -1) {
return FALSE;
}
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 98528ea..9606653 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -806,6 +806,26 @@ util_format_get_nr_components(enum pipe_format format)
return desc->nr_channels;
}
+/**
+ * Return the index of the first non-void channel
+ * -1 if no non-void channels
+ */
+static INLINE int
+util_format_get_first_non_void_channel(enum pipe_format format)
+{
+ const struct util_format_description *desc = util_format_description(format);
+ int i;
+
+ for (i = 0; i < 4; i++)
+ if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
+ break;
+
+ if (i == 4)
+ return -1;
+
+ return i;
+}
+
/*
* Format access functions.
*/
More information about the mesa-commit
mailing list