[gegl] opencl: delaying OpenCL initialization



commit ef7224280784ee09ced5a564c30f805a25863c43
Author: Victor Oliveira <victormatheus gmail com>
Date:   Mon Apr 23 12:36:30 2012 -0300

    opencl: delaying OpenCL initialization
    
    we delay as possible opencl initialization, so we can turn
    opencl on and off at will.

 gegl/gegl-init.c              |    6 ------
 gegl/opencl/gegl-cl-init.c    |   15 +++++++--------
 gegl/process/gegl-processor.c |   38 ++++++++++++++++++++++----------------
 3 files changed, 29 insertions(+), 30 deletions(-)
---
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 3e2ea46..13546e5 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -594,12 +594,6 @@ gegl_post_parse_hook (GOptionContext *context,
 
   swap_clean ();
 
-  /* Initialize OpenCL if wanted and possible */
-  if (gegl_cl_is_accelerated ())
-    gegl_cl_init (NULL);
-
-  GEGL_NOTE (GEGL_DEBUG_OPENCL, "Using OpenCL: %d\n", gegl_cl_is_accelerated ());
-
   return TRUE;
 }
 
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 67885ed..34d1ece 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -306,17 +306,16 @@ gegl_cl_init (GError **error)
           return FALSE;
         }
 
-    }
-
-  cl_state.is_accelerated = TRUE;
+      cl_state.is_accelerated = TRUE;
 
-  /* XXX: this dict is being leaked */
-  cl_program_hash = g_hash_table_new (g_str_hash, g_str_equal);
+      /* XXX: this dict is being leaked */
+      cl_program_hash = g_hash_table_new (g_str_hash, g_str_equal);
 
-  if (cl_state.is_accelerated)
-    gegl_cl_color_compile_kernels();
+      if (cl_state.is_accelerated)
+        gegl_cl_color_compile_kernels();
 
-  GEGL_NOTE (GEGL_DEBUG_OPENCL, "OK");
+      GEGL_NOTE (GEGL_DEBUG_OPENCL, "OK");
+    }
 
   return TRUE;
 }
diff --git a/gegl/process/gegl-processor.c b/gegl/process/gegl-processor.c
index 69b1247..2a22a22 100644
--- a/gegl/process/gegl-processor.c
+++ b/gegl/process/gegl-processor.c
@@ -749,27 +749,33 @@ gegl_processor_work (GeglProcessor *processor,
   gboolean   more_work = FALSE;
   GeglCache *cache     = gegl_node_get_cache (processor->input);
 
-  if (gegl_cl_is_accelerated ()
-      && processor->chunk_size != GEGL_CL_CHUNK_SIZE)
+  if (gegl_config()->use_opencl)
     {
-      GeglVisitor *visitor = g_object_new (GEGL_TYPE_VISITOR, NULL);
-      GSList *iterator = NULL;
-      GSList *visits_list = NULL;
-      gegl_visitor_reset (visitor);
-      gegl_visitor_dfs_traverse (visitor, GEGL_VISITABLE (processor->node));
-      visits_list = gegl_visitor_get_visits_list (visitor);
-
-      for (iterator = visits_list; iterator; iterator = iterator->next)
+      /* Initialize OpenCL if wanted and possible */
+      gegl_cl_init (NULL);
+
+      if (gegl_cl_is_accelerated ()
+          && processor->chunk_size != GEGL_CL_CHUNK_SIZE)
         {
-          GeglNode *node = (GeglNode*) iterator->data;
-          if (GEGL_OPERATION_GET_CLASS(node->operation)->cl_data)
+          GeglVisitor *visitor = g_object_new (GEGL_TYPE_VISITOR, NULL);
+          GSList *iterator = NULL;
+          GSList *visits_list = NULL;
+          gegl_visitor_reset (visitor);
+          gegl_visitor_dfs_traverse (visitor, GEGL_VISITABLE (processor->node));
+          visits_list = gegl_visitor_get_visits_list (visitor);
+
+          for (iterator = visits_list; iterator; iterator = iterator->next)
             {
-              processor->chunk_size = GEGL_CL_CHUNK_SIZE;
-              break;
+              GeglNode *node = (GeglNode*) iterator->data;
+              if (GEGL_OPERATION_GET_CLASS(node->operation)->cl_data)
+                {
+                  processor->chunk_size = GEGL_CL_CHUNK_SIZE;
+                  break;
+                }
             }
-        }
 
-      g_object_unref (visitor);
+          g_object_unref (visitor);
+        }
     }
 
   more_work = gegl_processor_render (processor, &processor->rectangle, progress);



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