[cogl] cogl-bitmask: Add _cogl_bitmask_set_flags



commit 4e760d51f108dfcd2ca8033799d441edfb82f041
Author: Neil Roberts <neil linux intel com>
Date:   Thu Nov 3 16:50:39 2011 +0000

    cogl-bitmask: Add _cogl_bitmask_set_flags
    
    This adds a _cogl_bitmask_set_flags function which can be used to copy
    the values from a CoglBitmask to an array of unsigned longs which can
    be used with the COGL_FLAGS_* macros. The values are or'd in so that
    in can be used multiple times to combine multiple bitmasks.
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 cogl/cogl-bitmask.c |   11 +++++++++++
 cogl/cogl-bitmask.h |   22 +++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/cogl/cogl-bitmask.c b/cogl/cogl-bitmask.c
index ec69625..5e2ff92 100644
--- a/cogl/cogl-bitmask.c
+++ b/cogl/cogl-bitmask.c
@@ -260,3 +260,14 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask,
       COGL_FLAGS_FOREACH_END;
     }
 }
+
+void
+_cogl_bitmask_set_flags_array (const CoglBitmask *bitmask,
+                               unsigned long *flags)
+{
+  const GArray *array = (const GArray *) *bitmask;
+  int i;
+
+  for (i = 0; i < array->len; i++)
+    flags[i] |= g_array_index (array, unsigned long, i);
+}
diff --git a/cogl/cogl-bitmask.h b/cogl/cogl-bitmask.h
index e36a551..479ac4a 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);
 
+void
+_cogl_bitmask_set_flags_array (const CoglBitmask *bitmask,
+                               unsigned long *flags);
 /*
  * cogl_bitmask_set_bits:
  * @dst: The bitmask to modify
@@ -233,7 +236,24 @@ _cogl_bitmask_clear_all (CoglBitmask *bitmask)
     *bitmask = _cogl_bitmask_from_bits (0);
 }
 
+/*
+ * _cogl_bitmask_set_flags:
+ * @bitmask: A pointer to a bitmask
+ * @flags: An array of flags
+ *
+ * Bitwise or's the bits from @bitmask into the flags array (see
+ * cogl-flags) pointed to by @flags.
+ */
+static inline void
+_cogl_bitmask_set_flags (const CoglBitmask *bitmask,
+                         unsigned long *flags)
+{
+  if (_cogl_bitmask_has_array (bitmask))
+    return _cogl_bitmask_set_flags_array (bitmask, flags);
+  else
+    flags[0] |= _cogl_bitmask_to_bits (bitmask);
+}
+
 G_END_DECLS
 
 #endif /* __COGL_BITMASK_H */
-



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]