diff options
author | Neil Roberts <neil@linux.intel.com> | 2011-10-26 18:43:21 +0100 |
---|---|---|
committer | Neil Roberts <neil@linux.intel.com> | 2011-11-16 16:21:31 +0000 |
commit | dbc31b70cc790833d8926ebad3e03c2d236965ae (patch) | |
tree | b4daad5a83c662bc8b3623fe55083825588ddbd8 | |
parent | f4c1ba9ed9f1555f7a6dbd5bbd84f7b936019ead (diff) | |
download | cogl-dbc31b70cc790833d8926ebad3e03c2d236965ae.tar.gz |
cogl-bitmask: Add a return value for the foreach callback
The foreach callback can now return FALSE to stop the iteration.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
-rw-r--r-- | cogl/cogl-attribute.c | 6 | ||||
-rw-r--r-- | cogl/cogl-bitmask.c | 10 | ||||
-rw-r--r-- | cogl/cogl-bitmask.h | 5 | ||||
-rw-r--r-- | tests/conform/test-bitmask.c | 6 |
4 files changed, 16 insertions, 11 deletions
diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c index 348071da..853d9893 100644 --- a/cogl/cogl-attribute.c +++ b/cogl/cogl-attribute.c @@ -428,13 +428,13 @@ validated: return status; } -static void +static gboolean toggle_enabled_cb (int bit_num, void *user_data) { const CoglBitmask *new_values = user_data; gboolean enabled = _cogl_bitmask_get (new_values, bit_num); - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _COGL_GET_CONTEXT (ctx, FALSE); if (ctx->driver == COGL_DRIVER_GLES2) { @@ -454,6 +454,8 @@ toggle_enabled_cb (int bit_num, void *user_data) GE( ctx, glDisableClientState (GL_TEXTURE_COORD_ARRAY) ); } #endif + + return TRUE; } static void diff --git a/cogl/cogl-bitmask.c b/cogl/cogl-bitmask.c index bdd7b057..1fe21983 100644 --- a/cogl/cogl-bitmask.c +++ b/cogl/cogl-bitmask.c @@ -231,7 +231,7 @@ _cogl_bitmask_clear_all_in_array (CoglBitmask *bitmask) void _cogl_bitmask_foreach (const CoglBitmask *bitmask, CoglBitmaskForeachFunc func, - gpointer user_data) + void *user_data) { if (_cogl_bitmask_has_array (bitmask)) { @@ -251,8 +251,9 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask, bit += next_bit; mask >>= next_bit; - func (array_index * sizeof (unsigned long) * 8 + bit - 1, - user_data); + if (!func (array_index * sizeof (unsigned long) * 8 + bit - 1, + user_data)) + return; } } } @@ -268,7 +269,8 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask, bit += next_bit; mask >>= next_bit; - func (bit - 1, user_data); + if (!func (bit - 1, user_data)) + return; } } } diff --git a/cogl/cogl-bitmask.h b/cogl/cogl-bitmask.h index 42ba3566..e36a5511 100644 --- a/cogl/cogl-bitmask.h +++ b/cogl/cogl-bitmask.h @@ -125,7 +125,8 @@ void _cogl_bitmask_xor_bits (CoglBitmask *dst, const CoglBitmask *src); -typedef void (* CoglBitmaskForeachFunc) (int bit_num, gpointer user_data); +/* The foreach function can return FALSE to stop iteration */ +typedef gboolean (* CoglBitmaskForeachFunc) (int bit_num, void *user_data); /* * cogl_bitmask_foreach: @@ -138,7 +139,7 @@ typedef void (* CoglBitmaskForeachFunc) (int bit_num, gpointer user_data); void _cogl_bitmask_foreach (const CoglBitmask *bitmask, CoglBitmaskForeachFunc func, - gpointer user_data); + void *user_data); /* * _cogl_bitmask_get: diff --git a/tests/conform/test-bitmask.c b/tests/conform/test-bitmask.c index b02a9ba3..613e5ee1 100644 --- a/tests/conform/test-bitmask.c +++ b/tests/conform/test-bitmask.c @@ -19,7 +19,7 @@ typedef struct int *bits; } CheckData; -static void +static gboolean check_bit (int bit_num, void *user_data) { CheckData *data = user_data; @@ -29,12 +29,12 @@ check_bit (int bit_num, void *user_data) if (data->bits[i] == bit_num) { data->bits[i] = -1; - return; + return TRUE; } g_assert_not_reached (); - return; + return TRUE; } static void |