From 61285c6cfa9ce6086d62fa08bc9e3813f0b30d3d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 8 Oct 2011 17:41:33 +0100 Subject: 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 --- src/gallium/auxiliary/util/u_format.c | 10 ++-------- src/gallium/auxiliary/util/u_format.h | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index 9bf42583eec..129b8e93ed3 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 98528ea595f..96066532631 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. */ -- cgit v1.2.3