[cogl/wip/neil/pipeline-uniforms: 10/17] Add _cogl_bitmask_is_empty
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/neil/pipeline-uniforms: 10/17] Add _cogl_bitmask_is_empty
- Date: Wed, 2 Nov 2011 14:05:47 +0000 (UTC)
commit 75d5c69e8de8d79638f9d454bc54df72f252b807
Author: Neil Roberts <neil linux intel com>
Date: Fri Oct 28 18:41:54 2011 +0100
Add _cogl_bitmask_is_empty
This just checks whether any of the bits are set.
cogl/cogl-bitmask.c | 13 +++++++++++++
cogl/cogl-bitmask.h | 18 ++++++++++++++++++
tests/conform/test-bitmask.c | 2 ++
3 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/cogl/cogl-bitmask.c b/cogl/cogl-bitmask.c
index ec69625..abac435 100644
--- a/cogl/cogl-bitmask.c
+++ b/cogl/cogl-bitmask.c
@@ -260,3 +260,16 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask,
COGL_FLAGS_FOREACH_END;
}
}
+
+gboolean
+_cogl_bitmask_is_empty_array (const CoglBitmask *bitmask)
+{
+ const GArray *array = (const GArray *) *bitmask;
+ int i;
+
+ for (i = 0; i < array->len; i++)
+ if (g_array_index (array, unsigned long, i))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/cogl/cogl-bitmask.h b/cogl/cogl-bitmask.h
index e36a551..e94f367 100644
--- a/cogl/cogl-bitmask.h
+++ b/cogl/cogl-bitmask.h
@@ -101,6 +101,9 @@ _cogl_bitmask_set_range_in_array (CoglBitmask *bitmask,
void
_cogl_bitmask_clear_all_in_array (CoglBitmask *bitmask);
+gboolean
+_cogl_bitmask_is_empty_array (const CoglBitmask *bitmask);
+
/*
* cogl_bitmask_set_bits:
* @dst: The bitmask to modify
@@ -233,6 +236,21 @@ _cogl_bitmask_clear_all (CoglBitmask *bitmask)
*bitmask = _cogl_bitmask_from_bits (0);
}
+/*
+ * _cogl_bitmask_is_empty:
+ * @bitmask: A pointer to a bitmask
+ *
+ * Return value: whether the bitmask has any bits set
+ */
+static inline gboolean
+_cogl_bitmask_is_empty (const CoglBitmask *bitmask)
+{
+ if (_cogl_bitmask_has_array (bitmask))
+ return _cogl_bitmask_is_empty_array (bitmask);
+ else
+ return *bitmask == _cogl_bitmask_from_bits (0);
+}
+
G_END_DECLS
#endif /* __COGL_BITMASK_H */
diff --git a/tests/conform/test-bitmask.c b/tests/conform/test-bitmask.c
index 1c98662..ca62a2a 100644
--- a/tests/conform/test-bitmask.c
+++ b/tests/conform/test-bitmask.c
@@ -74,6 +74,8 @@ verify_bits (const CoglBitmask *bitmask,
g_assert_cmpint (_cogl_bitmask_get (bitmask, i), ==, (j < data.n_bits));
}
+
+ g_assert_cmpint (_cogl_bitmask_is_empty (bitmask), ==, (data.n_bits == 0));
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]