2010-05-20 16:31:42 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-05-30 14:06:24 +00:00
|
|
|
#include <test-fixtures/test-unit.h>
|
|
|
|
|
2010-05-20 16:31:42 +00:00
|
|
|
#include "cogl-bitmask.h"
|
2011-10-28 19:09:53 +00:00
|
|
|
#include "cogl-util.h"
|
2011-11-02 13:41:32 +00:00
|
|
|
#include "cogl-flags.h"
|
2010-05-20 16:31:42 +00:00
|
|
|
|
2011-10-28 13:58:02 +00:00
|
|
|
/* This code assumes that we can cast an unsigned long to a pointer
|
|
|
|
and back without losing any data */
|
2012-04-16 16:23:15 +00:00
|
|
|
_COGL_STATIC_ASSERT (sizeof (unsigned long) <= sizeof (void *),
|
|
|
|
"This toolchain breaks Cogl's assumption that it can "
|
|
|
|
"safely cast an unsigned long to a pointer without "
|
|
|
|
"loosing data");
|
2011-10-28 13:58:02 +00:00
|
|
|
|
|
|
|
#define ARRAY_INDEX(bit_num) \
|
|
|
|
((bit_num) / (sizeof (unsigned long) * 8))
|
|
|
|
#define BIT_INDEX(bit_num) \
|
|
|
|
((bit_num) & (sizeof (unsigned long) * 8 - 1))
|
|
|
|
#define BIT_MASK(bit_num) \
|
|
|
|
(1UL << BIT_INDEX (bit_num))
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2010-05-20 16:31:42 +00:00
|
|
|
_cogl_bitmask_get_from_array (const CoglBitmask *bitmask,
|
|
|
|
unsigned int bit_num)
|
|
|
|
{
|
|
|
|
GArray *array = (GArray *) *bitmask;
|
|
|
|
|
|
|
|
/* If the index is off the end of the array then assume the bit is
|
|
|
|
not set */
|
2011-10-28 13:58:02 +00:00
|
|
|
if (bit_num >= sizeof (unsigned long) * 8 * array->len)
|
2010-05-20 16:31:42 +00:00
|
|
|
return FALSE;
|
|
|
|
else
|
2011-10-28 13:58:02 +00:00
|
|
|
return !!(g_array_index (array, unsigned long, ARRAY_INDEX (bit_num)) &
|
|
|
|
BIT_MASK (bit_num));
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_bitmask_convert_to_array (CoglBitmask *bitmask)
|
|
|
|
{
|
|
|
|
GArray *array;
|
2011-10-28 13:58:02 +00:00
|
|
|
/* Fetch the old values */
|
|
|
|
unsigned long old_values = _cogl_bitmask_to_bits (bitmask);
|
2010-05-20 16:31:42 +00:00
|
|
|
|
2011-10-28 13:58:02 +00:00
|
|
|
array = g_array_new (FALSE, /* not zero-terminated */
|
|
|
|
TRUE, /* do clear new entries */
|
|
|
|
sizeof (unsigned long));
|
2010-05-20 16:31:42 +00:00
|
|
|
/* Copy the old values back in */
|
|
|
|
g_array_append_val (array, old_values);
|
|
|
|
|
|
|
|
*bitmask = (struct _CoglBitmaskImaginaryType *) array;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_bitmask_set_in_array (CoglBitmask *bitmask,
|
|
|
|
unsigned int bit_num,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool value)
|
2010-05-20 16:31:42 +00:00
|
|
|
{
|
|
|
|
GArray *array;
|
2011-10-28 13:58:02 +00:00
|
|
|
unsigned int array_index;
|
|
|
|
unsigned long new_value_mask;
|
2010-05-20 16:31:42 +00:00
|
|
|
|
|
|
|
/* If the bitmask is not already an array then we need to allocate one */
|
|
|
|
if (!_cogl_bitmask_has_array (bitmask))
|
|
|
|
_cogl_bitmask_convert_to_array (bitmask);
|
|
|
|
|
|
|
|
array = (GArray *) *bitmask;
|
|
|
|
|
2011-10-28 13:58:02 +00:00
|
|
|
array_index = ARRAY_INDEX (bit_num);
|
2010-05-20 16:31:42 +00:00
|
|
|
/* Grow the array if necessary. This will clear the new data */
|
|
|
|
if (array_index >= array->len)
|
|
|
|
g_array_set_size (array, array_index + 1);
|
|
|
|
|
2011-10-28 13:58:02 +00:00
|
|
|
new_value_mask = BIT_MASK (bit_num);
|
2010-05-20 16:31:42 +00:00
|
|
|
|
|
|
|
if (value)
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (array, unsigned long, array_index) |= new_value_mask;
|
2010-05-20 16:31:42 +00:00
|
|
|
else
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (array, unsigned long, array_index) &= ~new_value_mask;
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_bitmask_set_bits (CoglBitmask *dst,
|
|
|
|
const CoglBitmask *src)
|
|
|
|
{
|
|
|
|
if (_cogl_bitmask_has_array (src))
|
|
|
|
{
|
|
|
|
GArray *src_array, *dst_array;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!_cogl_bitmask_has_array (dst))
|
|
|
|
_cogl_bitmask_convert_to_array (dst);
|
|
|
|
|
|
|
|
dst_array = (GArray *) *dst;
|
|
|
|
src_array = (GArray *) *src;
|
|
|
|
|
|
|
|
if (dst_array->len < src_array->len)
|
|
|
|
g_array_set_size (dst_array, src_array->len);
|
|
|
|
|
|
|
|
for (i = 0; i < src_array->len; i++)
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (dst_array, unsigned long, i) |=
|
|
|
|
g_array_index (src_array, unsigned long, i);
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
else if (_cogl_bitmask_has_array (dst))
|
|
|
|
{
|
|
|
|
GArray *dst_array;
|
|
|
|
|
|
|
|
dst_array = (GArray *) *dst;
|
|
|
|
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (dst_array, unsigned long, 0) |=
|
|
|
|
_cogl_bitmask_to_bits (src);
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
else
|
2011-10-28 13:58:02 +00:00
|
|
|
*dst = _cogl_bitmask_from_bits (_cogl_bitmask_to_bits (dst) |
|
|
|
|
_cogl_bitmask_to_bits (src));
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_bitmask_set_range_in_array (CoglBitmask *bitmask,
|
|
|
|
unsigned int n_bits,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool value)
|
2010-05-20 16:31:42 +00:00
|
|
|
{
|
|
|
|
GArray *array;
|
|
|
|
unsigned int array_index, bit_index;
|
|
|
|
|
|
|
|
if (n_bits == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If the bitmask is not already an array then we need to allocate one */
|
|
|
|
if (!_cogl_bitmask_has_array (bitmask))
|
|
|
|
_cogl_bitmask_convert_to_array (bitmask);
|
|
|
|
|
|
|
|
array = (GArray *) *bitmask;
|
|
|
|
|
|
|
|
/* Get the array index of the top most value that will be touched */
|
2011-10-28 13:58:02 +00:00
|
|
|
array_index = ARRAY_INDEX (n_bits - 1);
|
2010-05-20 16:31:42 +00:00
|
|
|
/* Get the bit index of the top most value */
|
2011-10-28 13:58:02 +00:00
|
|
|
bit_index = BIT_INDEX (n_bits - 1);
|
2010-05-20 16:31:42 +00:00
|
|
|
/* Grow the array if necessary. This will clear the new data */
|
|
|
|
if (array_index >= array->len)
|
|
|
|
g_array_set_size (array, array_index + 1);
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
/* Set the bits that are touching this index */
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (array, unsigned long, array_index) |=
|
|
|
|
~0UL >> (sizeof (unsigned long) * 8 - 1 - bit_index);
|
2010-05-20 16:31:42 +00:00
|
|
|
|
|
|
|
/* Set all of the bits in any lesser indices */
|
2011-10-28 13:58:02 +00:00
|
|
|
memset (array->data, 0xff, sizeof (unsigned long) * array_index);
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Clear the bits that are touching this index */
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (array, unsigned long, array_index) &= ~1UL << bit_index;
|
2010-05-20 16:31:42 +00:00
|
|
|
|
|
|
|
/* Clear all of the bits in any lesser indices */
|
2011-10-28 13:58:02 +00:00
|
|
|
memset (array->data, 0x00, sizeof (unsigned long) * array_index);
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-03 17:46:16 +00:00
|
|
|
_cogl_bitmask_xor_bits (CoglBitmask *dst,
|
|
|
|
const CoglBitmask *src)
|
2010-05-20 16:31:42 +00:00
|
|
|
{
|
|
|
|
if (_cogl_bitmask_has_array (src))
|
|
|
|
{
|
|
|
|
GArray *src_array, *dst_array;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!_cogl_bitmask_has_array (dst))
|
|
|
|
_cogl_bitmask_convert_to_array (dst);
|
|
|
|
|
|
|
|
dst_array = (GArray *) *dst;
|
|
|
|
src_array = (GArray *) *src;
|
|
|
|
|
|
|
|
if (dst_array->len < src_array->len)
|
|
|
|
g_array_set_size (dst_array, src_array->len);
|
|
|
|
|
|
|
|
for (i = 0; i < src_array->len; i++)
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (dst_array, unsigned long, i) ^=
|
|
|
|
g_array_index (src_array, unsigned long, i);
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
else if (_cogl_bitmask_has_array (dst))
|
|
|
|
{
|
|
|
|
GArray *dst_array;
|
|
|
|
|
|
|
|
dst_array = (GArray *) *dst;
|
|
|
|
|
2011-10-28 13:58:02 +00:00
|
|
|
g_array_index (dst_array, unsigned long, 0) ^=
|
|
|
|
_cogl_bitmask_to_bits (src);
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
else
|
2011-10-28 13:58:02 +00:00
|
|
|
*dst = _cogl_bitmask_from_bits (_cogl_bitmask_to_bits (dst) ^
|
|
|
|
_cogl_bitmask_to_bits (src));
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_bitmask_clear_all_in_array (CoglBitmask *bitmask)
|
|
|
|
{
|
|
|
|
GArray *array = (GArray *) *bitmask;
|
|
|
|
|
2011-10-28 13:58:02 +00:00
|
|
|
memset (array->data, 0, sizeof (unsigned long) * array->len);
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_bitmask_foreach (const CoglBitmask *bitmask,
|
|
|
|
CoglBitmaskForeachFunc func,
|
2011-10-26 17:43:21 +00:00
|
|
|
void *user_data)
|
2010-05-20 16:31:42 +00:00
|
|
|
{
|
|
|
|
if (_cogl_bitmask_has_array (bitmask))
|
|
|
|
{
|
|
|
|
GArray *array = (GArray *) *bitmask;
|
2011-11-02 13:41:32 +00:00
|
|
|
const unsigned long *values = &g_array_index (array, unsigned long, 0);
|
|
|
|
int bit_num;
|
2010-05-20 16:31:42 +00:00
|
|
|
|
2011-11-02 13:41:32 +00:00
|
|
|
COGL_FLAGS_FOREACH_START (values, array->len, bit_num)
|
2010-05-20 16:31:42 +00:00
|
|
|
{
|
2011-11-02 13:41:32 +00:00
|
|
|
if (!func (bit_num, user_data))
|
|
|
|
return;
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
2011-11-02 13:41:32 +00:00
|
|
|
COGL_FLAGS_FOREACH_END;
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-28 13:58:02 +00:00
|
|
|
unsigned long mask = _cogl_bitmask_to_bits (bitmask);
|
2011-11-02 13:41:32 +00:00
|
|
|
int bit_num;
|
2010-05-20 16:31:42 +00:00
|
|
|
|
2011-11-02 13:41:32 +00:00
|
|
|
COGL_FLAGS_FOREACH_START (&mask, 1, bit_num)
|
2010-05-20 16:31:42 +00:00
|
|
|
{
|
2011-11-02 13:41:32 +00:00
|
|
|
if (!func (bit_num, user_data))
|
2011-10-26 17:43:21 +00:00
|
|
|
return;
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
2011-11-02 13:41:32 +00:00
|
|
|
COGL_FLAGS_FOREACH_END;
|
2010-05-20 16:31:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 16:50:39 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2011-11-04 17:11:50 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
_cogl_bitmask_popcount_in_array (const CoglBitmask *bitmask)
|
|
|
|
{
|
|
|
|
const GArray *array = (const GArray *) *bitmask;
|
|
|
|
int pop = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < array->len; i++)
|
|
|
|
pop += _cogl_util_popcountl (g_array_index (array, unsigned long, i));
|
|
|
|
|
|
|
|
return pop;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_cogl_bitmask_popcount_upto_in_array (const CoglBitmask *bitmask,
|
|
|
|
int upto)
|
|
|
|
{
|
|
|
|
const GArray *array = (const GArray *) *bitmask;
|
|
|
|
|
|
|
|
if (upto >= array->len * sizeof (unsigned long) * 8)
|
|
|
|
return _cogl_bitmask_popcount_in_array (bitmask);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned long top_mask;
|
|
|
|
int array_index = ARRAY_INDEX (upto);
|
|
|
|
int bit_index = BIT_INDEX (upto);
|
|
|
|
int pop = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < array_index; i++)
|
|
|
|
pop += _cogl_util_popcountl (g_array_index (array, unsigned long, i));
|
|
|
|
|
|
|
|
top_mask = g_array_index (array, unsigned long, array_index);
|
|
|
|
|
|
|
|
return pop + _cogl_util_popcountl (top_mask & ((1UL << bit_index) - 1));
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 14:06:24 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int n_bits;
|
|
|
|
int *bits;
|
|
|
|
} CheckData;
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
check_bit (int bit_num, void *user_data)
|
|
|
|
{
|
|
|
|
CheckData *data = user_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < data->n_bits; i++)
|
|
|
|
if (data->bits[i] == bit_num)
|
|
|
|
{
|
|
|
|
data->bits[i] = -1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
verify_bits (const CoglBitmask *bitmask,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
CheckData data;
|
|
|
|
va_list ap, ap_copy;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start (ap, bitmask);
|
|
|
|
G_VA_COPY (ap_copy, ap);
|
|
|
|
|
|
|
|
for (data.n_bits = 0; va_arg (ap, int) != -1; data.n_bits++);
|
|
|
|
|
|
|
|
data.bits = alloca (data.n_bits * (sizeof (int)));
|
|
|
|
|
|
|
|
G_VA_COPY (ap, ap_copy);
|
|
|
|
|
|
|
|
for (i = 0; i < data.n_bits; i++)
|
|
|
|
data.bits[i] = va_arg (ap, int);
|
|
|
|
|
|
|
|
_cogl_bitmask_foreach (bitmask, check_bit, &data);
|
|
|
|
|
|
|
|
for (i = 0; i < data.n_bits; i++)
|
|
|
|
g_assert_cmpint (data.bits[i], ==, -1);
|
|
|
|
|
|
|
|
g_assert_cmpint (_cogl_bitmask_popcount (bitmask), ==, data.n_bits);
|
|
|
|
|
|
|
|
for (i = 0; i < 1024; i++)
|
|
|
|
{
|
|
|
|
int upto_popcount = 0;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
G_VA_COPY (ap, ap_copy);
|
|
|
|
|
|
|
|
for (j = 0; j < data.n_bits; j++)
|
|
|
|
if (va_arg (ap, int) < i)
|
|
|
|
upto_popcount++;
|
|
|
|
|
|
|
|
g_assert_cmpint (_cogl_bitmask_popcount_upto (bitmask, i),
|
|
|
|
==,
|
|
|
|
upto_popcount);
|
|
|
|
|
|
|
|
G_VA_COPY (ap, ap_copy);
|
|
|
|
|
|
|
|
for (j = 0; j < data.n_bits; j++)
|
|
|
|
if (va_arg (ap, int) == i)
|
|
|
|
break;
|
|
|
|
|
|
|
|
g_assert_cmpint (_cogl_bitmask_get (bitmask, i), ==, (j < data.n_bits));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UNIT_TEST (check_bitmask_api,
|
|
|
|
0 /* no requirements */,
|
|
|
|
0 /* no failure cases */)
|
|
|
|
{
|
|
|
|
CoglBitmask bitmask;
|
|
|
|
CoglBitmask other_bitmask;
|
|
|
|
/* A dummy bit to make it use arrays sometimes */
|
|
|
|
int dummy_bit;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (dummy_bit = -1; dummy_bit < 256; dummy_bit += 40)
|
|
|
|
{
|
|
|
|
_cogl_bitmask_init (&bitmask);
|
|
|
|
_cogl_bitmask_init (&other_bitmask);
|
|
|
|
|
|
|
|
if (dummy_bit != -1)
|
|
|
|
_cogl_bitmask_set (&bitmask, dummy_bit, TRUE);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, dummy_bit, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_set (&bitmask, 1, TRUE);
|
|
|
|
_cogl_bitmask_set (&bitmask, 4, TRUE);
|
|
|
|
_cogl_bitmask_set (&bitmask, 5, TRUE);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, 1, 4, 5, dummy_bit, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_set (&bitmask, 4, FALSE);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, 1, 5, dummy_bit, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_clear_all (&bitmask);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, -1);
|
|
|
|
|
|
|
|
if (dummy_bit != -1)
|
|
|
|
_cogl_bitmask_set (&bitmask, dummy_bit, TRUE);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, dummy_bit, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_set (&bitmask, 1, TRUE);
|
|
|
|
_cogl_bitmask_set (&bitmask, 4, TRUE);
|
|
|
|
_cogl_bitmask_set (&bitmask, 5, TRUE);
|
|
|
|
_cogl_bitmask_set (&other_bitmask, 5, TRUE);
|
|
|
|
_cogl_bitmask_set (&other_bitmask, 6, TRUE);
|
|
|
|
|
|
|
|
_cogl_bitmask_set_bits (&bitmask, &other_bitmask);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, 1, 4, 5, 6, dummy_bit, -1);
|
|
|
|
verify_bits (&other_bitmask, 5, 6, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_set (&bitmask, 6, FALSE);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, 1, 4, 5, dummy_bit, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_xor_bits (&bitmask, &other_bitmask);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, 1, 4, 6, dummy_bit, -1);
|
|
|
|
verify_bits (&other_bitmask, 5, 6, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_set_range (&bitmask, 5, TRUE);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, 0, 1, 2, 3, 4, 6, dummy_bit, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_set_range (&bitmask, 4, FALSE);
|
|
|
|
|
|
|
|
verify_bits (&bitmask, 4, 6, dummy_bit, -1);
|
|
|
|
|
|
|
|
_cogl_bitmask_destroy (&other_bitmask);
|
|
|
|
_cogl_bitmask_destroy (&bitmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extra tests for really long bitmasks */
|
|
|
|
_cogl_bitmask_init (&bitmask);
|
|
|
|
_cogl_bitmask_set_range (&bitmask, 400, TRUE);
|
|
|
|
_cogl_bitmask_init (&other_bitmask);
|
|
|
|
_cogl_bitmask_set (&other_bitmask, 5, TRUE);
|
|
|
|
_cogl_bitmask_xor_bits (&bitmask, &other_bitmask);
|
|
|
|
|
|
|
|
for (i = 0; i < 1024; i++)
|
|
|
|
g_assert_cmpint (_cogl_bitmask_get (&bitmask, i),
|
|
|
|
==,
|
|
|
|
(i == 5 ? FALSE :
|
|
|
|
i < 400 ? TRUE :
|
|
|
|
FALSE));
|
|
|
|
|
|
|
|
_cogl_bitmask_set_range (&other_bitmask, 500, TRUE);
|
|
|
|
_cogl_bitmask_set_bits (&bitmask, &other_bitmask);
|
|
|
|
|
|
|
|
for (i = 0; i < 1024; i++)
|
|
|
|
g_assert_cmpint (_cogl_bitmask_get (&bitmask, i), ==, (i < 500));
|
|
|
|
}
|