[gegl/gsoc2009-gpu] Add gegl_operation_class_get_gpu_processor() method



commit 2392382dfce170779cd39ae2696b2f9c7ebaf0ed
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Mon Jun 29 23:28:20 2009 +0800

    Add gegl_operation_class_get_gpu_processor() method
    
    This method returns the best suited GPU operation processor previously
    registered through gegl_operation_class_add_processor().  This method
    works almost similarly to the dispatch() method found inside the same
    source file, only that instead of raising a g_error when it fails to find a
    dispatch data for the current operation class, this method returns NULL.
    
    This method chooses between four possible GPU implementation
    candidates (i.e. gegl:reference, gegl:fast, gegl:good, gegl:best)
    depending on GEGL's current settings.

 gegl/operation/gegl-operation-processors.c |   61 ++++++++++++++++++++++++++++
 gegl/operation/gegl-operation.h            |    8 ++-
 2 files changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-processors.c b/gegl/operation/gegl-operation-processors.c
index 94baf2b..1c8693f 100644
--- a/gegl/operation/gegl-operation-processors.c
+++ b/gegl/operation/gegl-operation-processors.c
@@ -221,6 +221,67 @@ gegl_class_register_alternate_vfunc (GObjectClass *cclass,
     }
 }
 
+GCallback
+gegl_operation_class_get_gpu_processor (GeglOperationClass *cclass)
+{
+  gint cnt;
+
+  VFuncData *data;
+
+  gint reference = 0;
+  gint fast      = 0;
+  gint good      = 0;
+  gint best      = 0;
+
+  gint choice;
+
+  data = g_type_get_qdata (G_TYPE_FROM_CLASS (cclass),
+                           g_quark_from_string ("gpu-dispatch-data"));
+
+  if (data == NULL)
+    return NULL;
+  else if (gegl_config()->quality == data->cached_quality)
+    return data->callback[data->cached];
+
+  for (cnt = 0; cnt < MAX_PROCESSOR; cnt++)
+    {
+      const gchar *string = data->string[cnt];
+      GCallback cb = data->callback[cnt];
+
+      if (string && cb != NULL)
+        {
+          if (g_str_equal (string, "gpu:best"))
+            best = cnt;
+          else if (g_str_equal (string, "gpu:good"))
+            good = cnt;
+          else if (g_str_equal (string, "gpu:fast"))
+            fast = cnt;
+          else if (g_str_equal (string, "gpu:reference"))
+            reference = cnt;
+        }
+    }
+
+  g_assert (data->callback[reference]);
+  choice = reference;
+
+  if (gegl_config()->quality <= 1.0  && best)
+    choice = best;
+  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_TYPE_FROM_CLASS (cclass)));
+
+  data->cached = choice;
+  data->cached_quality = gegl_config()->quality;
+
+  return data->callback[data->cached];
+}
+
 void
 gegl_operation_class_add_processor (GeglOperationClass *cclass,
                                     GCallback           process,
diff --git a/gegl/operation/gegl-operation.h b/gegl/operation/gegl-operation.h
index d15953c..3f2dfe0 100644
--- a/gegl/operation/gegl-operation.h
+++ b/gegl/operation/gegl-operation.h
@@ -64,9 +64,11 @@ struct _GeglOperation
 
 #define MAX_PROCESSOR 4
 
-void gegl_operation_class_add_processor (GeglOperationClass *cclass,
-                                         GCallback           process,
-                                         const gchar        *string);
+void      gegl_operation_class_add_processor     (GeglOperationClass *cclass,
+                                                  GCallback           process,
+                                                  const gchar        *string);
+
+GCallback gegl_operation_class_get_gpu_processor (GeglOperationClass *cclass);
 
 struct _GeglOperationClass
 {



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