diff options
author | Neil Roberts <neil@linux.intel.com> | 2011-11-03 16:50:39 +0000 |
---|---|---|
committer | Neil Roberts <neil@linux.intel.com> | 2011-11-16 16:32:11 +0000 |
commit | 4e760d51f108dfcd2ca8033799d441edfb82f041 (patch) | |
tree | 2161ffff08a7def92bfd5109e6b64d096ce5524b | |
parent | d2fd168351aa86949fc84b7be95ec786eb739261 (diff) | |
download | cogl-4e760d51f108dfcd2ca8033799d441edfb82f041.tar.gz |
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>
-rw-r--r-- | cogl/cogl-bitmask.c | 11 | ||||
-rw-r--r-- | 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 ec69625d..5e2ff92c 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 e36a5511..479ac4a1 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 */ - |