[cogl/wip/neil/pipeline-uniforms: 1/9] cogl-bitmask: Add a return value for the foreach callback



commit d3627038776a26196ee14f89c18540cc0538cd3c
Author: Neil Roberts <neil linux intel com>
Date:   Wed Oct 26 18:43:21 2011 +0100

    cogl-bitmask: Add a return value for the foreach callback
    
    The foreach callback can now return FALSE to stop the iteration.

 cogl/cogl-attribute.c |    6 ++++--
 cogl/cogl-bitmask.c   |   12 +++++++-----
 cogl/cogl-bitmask.h   |    5 +++--
 3 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c
index 700d05c..350ebf0 100644
--- a/cogl/cogl-attribute.c
+++ b/cogl/cogl-attribute.c
@@ -427,13 +427,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)
     {
@@ -453,6 +453,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 568d549..1c9a348 100644
--- a/cogl/cogl-bitmask.c
+++ b/cogl/cogl-bitmask.c
@@ -218,7 +218,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))
     {
@@ -232,8 +232,10 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask,
 
           while (mask)
             {
-              if (mask & 1)
-                func (array_index * sizeof (unsigned int) * 8 + bit, user_data);
+              if ((mask & 1) &&
+                  !func (array_index * sizeof (unsigned int) * 8 + bit,
+                         user_data))
+                return;
 
               bit++;
               mask >>= 1;
@@ -247,8 +249,8 @@ _cogl_bitmask_foreach (const CoglBitmask *bitmask,
 
       while (mask)
         {
-          if (mask & 1)
-            func (bit, user_data);
+          if ((mask & 1) && !func (bit, user_data))
+            return;
 
           bit++;
           mask >>= 1;
diff --git a/cogl/cogl-bitmask.h b/cogl/cogl-bitmask.h
index d3c36a4..2a078ca 100644
--- a/cogl/cogl-bitmask.h
+++ b/cogl/cogl-bitmask.h
@@ -114,7 +114,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:
@@ -127,7 +128,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:



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