[gegl/gsoc2009-gpu] Code cleanup



commit ecdc4946e9ad401b5d5ee3fc8e4d17513fa553bd
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Mon Jun 29 23:39:43 2009 +0800

    Code cleanup

 gegl/operation/gegl-operation-processors.c |  181 +++++++++++++++-------------
 1 files changed, 98 insertions(+), 83 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-processors.c b/gegl/operation/gegl-operation-processors.c
index 1c8693f..a351cac 100644
--- a/gegl/operation/gegl-operation-processors.c
+++ b/gegl/operation/gegl-operation-processors.c
@@ -52,20 +52,21 @@
 typedef struct VFuncData
 {
   GCallback callback[MAX_PROCESSOR];
-  gchar    *string[MAX_PROCESSOR];
+  gchar    *string  [MAX_PROCESSOR];
+
   gdouble   cached_quality;
   gint      cached;
 } VFuncData;
 
 void
 gegl_class_register_alternate_vfunc (GObjectClass *cclass,
-                                     gpointer      vfunc_ptr2,
+                                     gpointer      process_vfunc_ptr,
                                      GCallback     process,
                                      const gchar  *string);
 
-/* this dispatcher allows overriding a callback without checking how many parameters
- * are passed and how many parameters are needed, hopefully in a compiler/archi
- * portable manner.
+/* this dispatcher allows overriding a callback without checking how many
+ * parameters are passed and how many parameters are needed, hopefully in a
+ * compiler/architecture portable manner.
  */
 static void
 dispatch (GObject *object,
@@ -88,69 +89,81 @@ dispatch (GObject *object,
                     gpointer arg6,
                     gpointer arg7,
                     gpointer arg8,
-                    gpointer arg9)=NULL;
+                    gpointer arg9) = NULL;
+
   VFuncData *data;
+
   gint fast      = 0;
   gint good      = 0;
   gint reference = 0;
   gint simd      = 0;
-  gint i;
   gint choice;
 
+  gint cnt;
+
+  data = g_type_get_qdata (G_OBJECT_TYPE (object),
+                           g_quark_from_string ("dispatch-data"));
 
-  data = g_type_get_qdata (G_OBJECT_TYPE(object),
-                           g_quark_from_string("dispatch-data"));
-  if (!data)
-    {
-      g_error ("dispatch called on object without dispatch-data");
-    }
+  if (data == NULL)
+    g_error ("dispatch called on object without dispatch-data");
 
-  if (gegl_config()->quality == data->cached_quality)
+  if (gegl_config ()->quality == data->cached_quality)
     {
-      dispatch = (void*)data->callback[data->cached];
+      dispatch = (void*) data->callback[data->cached];
       dispatch (object, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
       return;
     }
 
-  for (i=0;i<MAX_PROCESSOR;i++)
+  for (cnt = 0; cnt < MAX_PROCESSOR; cnt++)
     {
-      const gchar *string = data->string[i];
-      GCallback cb = data->callback[i];
+      const gchar *string = data->string[cnt];
+      GCallback cb = data->callback[cnt];
 
-      if (string && cb!=NULL)
+      if (string && cb != NULL)
         {
-          if (g_str_equal (string, "fast"))      fast = i;
-          if (g_str_equal (string, "simd"))      simd = i;
-          else if (g_str_equal (string, "good")) good = i;
+          if (g_str_equal (string, "fast"))
+            fast = cnt;
+          else if (g_str_equal (string, "simd"))
+            simd = cnt;
+          else if (g_str_equal (string, "good"))
+            good = cnt;
           else if (g_str_equal (string, "reference"))
-            reference = i;
+            reference = cnt;
         }
     }
+
   reference = 0;
   g_assert (data->callback[reference]);
-
   choice = reference;
-  if (gegl_config()->quality <= 1.0  && simd) choice = simd;
-  if (gegl_config()->quality <= 0.75 && good) choice = good;
-  if (gegl_config()->quality <= 0.25 && fast) choice = fast;
 
-  GEGL_NOTE(GEGL_DEBUG_PROCESSOR, "Using %s implementation for %s", data->string[choice], g_type_name (G_OBJECT_TYPE(object)));
+  if (gegl_config ()->quality <= 1.0  && simd)
+    choice = simd;
+  if (gegl_config ()->quality <= 0.75 && good)
+    choice = good;
+  if (gegl_config ()->quality <= 0.25 && fast)
+    choice = fast;
+
+  GEGL_NOTE(GEGL_DEBUG_PROCESSOR,
+            "Using %s implementation for %s",
+            data->string[choice],
+            g_type_name (G_OBJECT_TYPE (object)));
 
   data->cached = choice;
-  data->cached_quality = gegl_config()->quality;
-  dispatch = (void*)data->callback[data->cached];
+  data->cached_quality = gegl_config ()->quality;
+
+  dispatch = (void*) data->callback[data->cached];
   dispatch (object, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
 }
 
 void
 gegl_class_register_alternate_vfunc (GObjectClass *cclass,
-                                     gpointer      vfunc_ptr2,
+                                     gpointer      process_vfunc_ptr,
                                      GCallback     callback,
                                      const gchar  *string)
 {
   gint cnt;
 
-  GCallback *vfunc_ptr = vfunc_ptr2;
+  GCallback *vfunc_ptr = process_vfunc_ptr;
   GType      type      = G_TYPE_FROM_CLASS (cclass);
 
   GQuark     quark;
@@ -159,7 +172,7 @@ gegl_class_register_alternate_vfunc (GObjectClass *cclass,
   if (g_str_has_prefix (string, "gpu"))
     {
       quark = g_quark_from_string ("gpu-dispatch-data");
-      data = g_type_get_qdata (type, quark);
+      data  = g_type_get_qdata (type, quark);
 
       if (data == NULL)
         {
@@ -176,49 +189,50 @@ gegl_class_register_alternate_vfunc (GObjectClass *cclass,
 
       g_sprintf (tag, "%p", vfunc_ptr);
       quark = g_quark_from_string (tag);
-      data = g_type_get_qdata (type, quark);
-      if (!data)
+      data  = g_type_get_qdata (type, quark);
+
+      if (data == NULL)
         {
           data = g_new0 (VFuncData, 1);
           data->cached_quality = -1.0;
           g_type_set_qdata (type, quark, data);
-          g_type_set_qdata (type, g_quark_from_string("dispatch-data"), data);
+          g_type_set_qdata (type, g_quark_from_string ("dispatch-data"), data);
         }
 
       /* Store the default implementation */
-      if (data->callback[0]==NULL)
+      if (data->callback[0] == NULL)
         {
           if (*vfunc_ptr == NULL)
             g_error ("%s: No existing default () vfunc defined for %s",
                      G_STRFUNC, g_type_name (type));
-          data->callback[0]=*vfunc_ptr;
-          data->string[0]=g_strdup ("reference");
+
+          data->callback[0] = *vfunc_ptr;
+          data->string[0] = g_strdup ("reference");
         }
 
-      *vfunc_ptr = (void*)dispatch; /* make our bootstrap replacement for the
-                                     * reference implementation take over
-                                     * dispatching of arguments, not sure if
-                                     * this is portable C or not.
-                                     */
+      *vfunc_ptr = (void*) dispatch; /* make our bootstrap replacement for the
+                                      * reference implementation take over
+                                      * dispatching of arguments, not sure if
+                                      * this is portable C or not.
+                                      */
       cnt = 1;
     }
 
   /* Find a free slot for this one */
   for (; cnt < MAX_PROCESSOR; cnt++)
     {
-      if (data->callback[cnt]==NULL)
+      if (data->callback[cnt] == NULL)
         {
           /* store the callback and it's given name */
-          data->callback[cnt]=callback;
-          data->string[cnt]=g_strdup (string);
+          data->callback[cnt] = callback;
+          data->string[cnt] = g_strdup (string);
           break;
         }
     }
-  if (cnt>=MAX_PROCESSOR)
-    {
-      g_warning ("Too many callbacks added to %s",
-                 g_type_name (G_TYPE_FROM_CLASS (cclass)));
-    }
+
+  if (cnt >= MAX_PROCESSOR)
+    g_warning ("Too many callbacks added to %s",
+               g_type_name (G_TYPE_FROM_CLASS (cclass)));
 }
 
 GCallback
@@ -240,7 +254,7 @@ gegl_operation_class_get_gpu_processor (GeglOperationClass *cclass)
 
   if (data == NULL)
     return NULL;
-  else if (gegl_config()->quality == data->cached_quality)
+  else if (gegl_config ()->quality == data->cached_quality)
     return data->callback[data->cached];
 
   for (cnt = 0; cnt < MAX_PROCESSOR; cnt++)
@@ -264,11 +278,11 @@ gegl_operation_class_get_gpu_processor (GeglOperationClass *cclass)
   g_assert (data->callback[reference]);
   choice = reference;
 
-  if (gegl_config()->quality <= 1.0  && best)
+  if (gegl_config ()->quality <= 1.0  && best)
     choice = best;
-  if (gegl_config()->quality <= 0.75 && good)
+  if (gegl_config ()->quality <= 0.75 && good)
     choice = good;
-  if (gegl_config()->quality <= 0.25 && fast)
+  if (gegl_config ()->quality <= 0.25 && fast)
     choice = fast;
 
   GEGL_NOTE (GEGL_DEBUG_PROCESSOR,
@@ -277,7 +291,7 @@ gegl_operation_class_get_gpu_processor (GeglOperationClass *cclass)
              g_type_name (G_TYPE_FROM_CLASS (cclass)));
 
   data->cached = choice;
-  data->cached_quality = gegl_config()->quality;
+  data->cached_quality = gegl_config ()->quality;
 
   return data->callback[data->cached];
 }
@@ -289,38 +303,39 @@ gegl_operation_class_add_processor (GeglOperationClass *cclass,
 {
   GType    type        = G_TYPE_FROM_CLASS (cclass);
   GType    parent_type = g_type_parent (type);
+
   gint     vfunc_offset;
   gpointer process_vfunc_ptr;
 
 #define ELSE_IF(type) else if(parent_type==type)
-if(parent_type == GEGL_TYPE_OPERATION)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_SOURCE)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationSourceClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_SINK)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationSinkClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_FILTER)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationFilterClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_AREA_FILTER)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationFilterClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_POINT_FILTER)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointFilterClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_COMPOSER)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationComposerClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_POINT_COMPOSER)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointComposerClass, process);
-ELSE_IF( GEGL_TYPE_OPERATION_COMPOSER3)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationComposer3Class, process);
-ELSE_IF( GEGL_TYPE_OPERATION_POINT_COMPOSER3)
-  vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointComposer3Class, process);
+  if(parent_type == GEGL_TYPE_OPERATION)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_SOURCE)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationSourceClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_SINK)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationSinkClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_FILTER)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationFilterClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_AREA_FILTER)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationFilterClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_POINT_FILTER)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointFilterClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_COMPOSER)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationComposerClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_POINT_COMPOSER)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointComposerClass, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_COMPOSER3)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationComposer3Class, process);
+  ELSE_IF( GEGL_TYPE_OPERATION_POINT_COMPOSER3)
+    vfunc_offset = G_STRUCT_OFFSET (GeglOperationPointComposer3Class, process);
 #undef ELSE_IF
-else
-  {
-     g_error ("%s unable to use %s as parent_type for %s",
-              G_STRFUNC, g_type_name (parent_type), g_type_name(G_TYPE_FROM_CLASS (cclass)));
-  }
+  else
+    g_error ("%s unable to use %s as parent_type for %s",
+             G_STRFUNC,
+             g_type_name (parent_type),
+             g_type_name (G_TYPE_FROM_CLASS (cclass)));
+
   process_vfunc_ptr = G_STRUCT_MEMBER_P(cclass, vfunc_offset);
-#define PROCESS_VFUNC (*(GCallback*) G_STRUCT_MEMBER_P ((cclass), (vfunc_offset)))
 
   gegl_class_register_alternate_vfunc (G_OBJECT_CLASS (cclass),
                                        process_vfunc_ptr,



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