[gegl] removing some globals and compiler warnings



commit 515734145187e44b7caa6ce2d895a530c0e10a7a
Author: Victor Oliveira <victormatheus gmail com>
Date:   Wed Mar 21 14:54:40 2012 -0300

    removing some globals and compiler warnings

 gegl/buffer/gegl-buffer-access.c               |    4 +-
 gegl/buffer/gegl-buffer-cl-iterator.c          |   12 ++++----
 gegl/buffer/gegl-buffer-iterator.c             |    2 +
 gegl/buffer/gegl-buffer.c                      |    2 +-
 gegl/gegl-init.c                               |    2 +-
 gegl/opencl/gegl-cl-init.c                     |   31 +++++++++++++++++------
 gegl/opencl/gegl-cl-init.h                     |   14 ++++------
 gegl/operation/gegl-operation-point-composer.c |    2 +-
 gegl/operation/gegl-operation-point-filter.c   |    2 +-
 gegl/operation/gegl-operation-sink.c           |    2 +-
 gegl/process/gegl-processor.c                  |    2 +-
 operations/common/box-blur.c                   |    2 +-
 12 files changed, 46 insertions(+), 31 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 601d1cd..fd5aae6 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -948,7 +948,7 @@ gegl_buffer_get_unlocked (GeglBuffer          *buffer,
     }
 #endif
 
-  if (cl_state.is_accelerated)
+  if (gegl_cl_is_accelerated ())
     {
       if (GEGL_FLOAT_EQUAL (scale, 1.0))
         {
@@ -1196,7 +1196,7 @@ gegl_buffer_clear (GeglBuffer          *dst,
 
   pxsize = babl_format_get_bytes_per_pixel (dst->format);
 
-  if (cl_state.is_accelerated)
+  if (gegl_cl_is_accelerated ())
     gegl_buffer_cl_cache_invalidate (dst, dst_rect);
 
   /* FIXME: this can be even further optimized by special casing it so
diff --git a/gegl/buffer/gegl-buffer-cl-iterator.c b/gegl/buffer/gegl-buffer-cl-iterator.c
index fdf2427..7a8cf2c 100644
--- a/gegl/buffer/gegl-buffer-cl-iterator.c
+++ b/gegl/buffer/gegl-buffer-cl-iterator.c
@@ -142,20 +142,20 @@ gegl_buffer_cl_iterator_add_2 (GeglBufferClIterator  *iterator,
       gint x, y, j;
 
       i->rois = 0;
-      for (y=result->y; y < result->y + result->height; y += cl_state.max_image_height)
-        for (x=result->x; x < result->x + result->width;  x += cl_state.max_image_width)
+      for (y=result->y; y < result->y + result->height; y += gegl_cl_get_iter_height ())
+        for (x=result->x; x < result->x + result->width;  x += gegl_cl_get_iter_width ())
           i->rois++;
 
       i->roi_no = 0;
       i->roi_all = g_new0 (GeglRectangle, i->rois);
 
       j = 0;
-      for (y=0; y < result->height; y += cl_state.max_image_height)
-        for (x=0; x < result->width;  x += cl_state.max_image_width)
+      for (y=0; y < result->height; y += gegl_cl_get_iter_height ())
+        for (x=0; x < result->width;  x += gegl_cl_get_iter_width ())
           {
             GeglRectangle r = {x, y,
-                               MIN(cl_state.max_image_width,  result->width  - x),
-                               MIN(cl_state.max_image_height, result->height - y)};
+                               MIN(gegl_cl_get_iter_width (),  result->width  - x),
+                               MIN(gegl_cl_get_iter_height (), result->height - y)};
             i->roi_all[j] = r;
             j++;
           }
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index d05fd2d..5b7a174 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -32,6 +32,8 @@
 #include "gegl-tile-storage.h"
 #include "gegl-utils.h"
 
+#include "gegl-buffer-cl-cache.h"
+
 typedef struct GeglBufferTileIterator
 {
   GeglBuffer    *buffer;
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index af2f7d9..2053b3c 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -373,7 +373,7 @@ gegl_buffer_dispose (GObject *object)
 
   gegl_buffer_sample_cleanup (buffer);
 
-  if (cl_state.is_accelerated)
+  if (gegl_cl_is_accelerated ())
     gegl_buffer_cl_cache_remove (GEGL_BUFFER (object), NULL);
 
   if (handler->source &&
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 869a9c9..89e12d0 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -598,7 +598,7 @@ gegl_post_parse_hook (GOptionContext *context,
   if (gegl_config()->use_opencl)
     gegl_cl_init (NULL);
 
-  g_printf("[OpenCL] Using OpenCL: %d\n", gegl_config()->use_opencl && cl_state.is_accelerated);
+  g_printf("[OpenCL] Using OpenCL: %d\n", gegl_config()->use_opencl && gegl_cl_is_accelerated ());
 
   return TRUE;
 }
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 2cfbcf6..35e7a4d 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -82,6 +82,9 @@ const char *gegl_cl_errstring(cl_int err) {
   return strings[-err];
 }
 
+static gegl_cl_state cl_state = {FALSE, NULL, NULL, NULL, NULL, FALSE, 0, 0, 0, 0, "", "", "", ""};
+static GHashTable *cl_program_hash = NULL;
+
 gboolean
 gegl_cl_is_accelerated (void)
 {
@@ -118,6 +121,18 @@ gegl_cl_get_local_mem_size (void)
   return cl_state.local_mem_size;
 }
 
+size_t
+gegl_cl_get_iter_width (void)
+{
+  return cl_state.iter_width;
+}
+
+size_t
+gegl_cl_get_iter_height (void)
+{
+  return cl_state.iter_height;
+}
+
 #ifdef G_OS_WIN32
 
 #include <windows.h>
@@ -241,8 +256,8 @@ gegl_cl_init (GError **error)
       gegl_clGetDeviceInfo (cl_state.device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(cl_ulong), &cl_state.max_mem_alloc,    NULL);
       gegl_clGetDeviceInfo (cl_state.device, CL_DEVICE_LOCAL_MEM_SIZE,     sizeof(cl_ulong), &cl_state.local_mem_size,   NULL);
 
-      cl_state.max_image_width  = 4096;
-      cl_state.max_image_height = 4096;
+      cl_state.iter_width  = 4096;
+      cl_state.iter_height = 4096;
 
       g_printf("[OpenCL] Platform Name:%s\n",       cl_state.platform_name);
       g_printf("[OpenCL] Version:%s\n",             cl_state.platform_version);
@@ -251,16 +266,16 @@ gegl_cl_init (GError **error)
       g_printf("[OpenCL] Max Alloc: %lu bytes\n",   (unsigned long)cl_state.max_mem_alloc);
       g_printf("[OpenCL] Local Mem: %lu bytes\n",   (unsigned long)cl_state.local_mem_size);
 
-      while (cl_state.max_image_width * cl_state.max_image_height * 16 > cl_state.max_mem_alloc)
+      while (cl_state.iter_width * cl_state.iter_height * 16 > cl_state.max_mem_alloc)
         {
-          if (cl_state.max_image_height < cl_state.max_image_width)
-            cl_state.max_image_width  /= 2;
+          if (cl_state.iter_height < cl_state.iter_width)
+            cl_state.iter_width  /= 2;
           else
-            cl_state.max_image_height /= 2;
+            cl_state.iter_height /= 2;
         }
-      cl_state.max_image_width  /= 2;
+      cl_state.iter_width  /= 2;
 
-      g_printf("[OpenCL] Iteration size: (%d, %d)\n", cl_state.max_image_width, cl_state.max_image_height);
+      g_printf("[OpenCL] Iteration size: (%d, %d)\n", cl_state.iter_width, cl_state.iter_height);
 
       if (cl_state.image_support)
         {
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index f77984b..a50d62a 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -19,8 +19,8 @@ typedef struct
     cl_device_id device;
     cl_command_queue cq;
     cl_bool image_support;
-    size_t max_image_height;
-    size_t max_image_width;
+    size_t iter_height;
+    size_t iter_width;
     cl_ulong max_mem_alloc;
     cl_ulong local_mem_size;
 
@@ -47,6 +47,10 @@ cl_command_queue gegl_cl_get_command_queue (void);
 
 cl_ulong gegl_cl_get_local_mem_size (void);
 
+size_t gegl_cl_get_iter_width (void);
+
+size_t gegl_cl_get_iter_height (void);
+
 typedef struct
 {
   cl_program program;
@@ -58,9 +62,6 @@ gegl_cl_run_data *gegl_cl_compile_and_build (const char *program_source,
 
 #ifdef __GEGL_CL_INIT_MAIN__
 
-gegl_cl_state cl_state = {FALSE, NULL, NULL, NULL, NULL, FALSE, 0, 0, 0, 0, "", "", "", ""};
-GHashTable *cl_program_hash = NULL;
-
 t_clGetPlatformIDs  gegl_clGetPlatformIDs  = NULL;
 t_clGetPlatformInfo gegl_clGetPlatformInfo = NULL;
 t_clGetDeviceIDs    gegl_clGetDeviceIDs    = NULL;
@@ -104,9 +105,6 @@ t_clReleaseMemObject    gegl_clReleaseMemObject    = NULL;
 
 #else
 
-extern gegl_cl_state cl_state;
-extern GHashTable *cl_program_hash;
-
 extern t_clGetPlatformIDs  gegl_clGetPlatformIDs;
 extern t_clGetPlatformInfo gegl_clGetPlatformInfo;
 extern t_clGetDeviceIDs    gegl_clGetDeviceIDs;
diff --git a/gegl/operation/gegl-operation-point-composer.c b/gegl/operation/gegl-operation-point-composer.c
index 24d94da..a26c8a2 100644
--- a/gegl/operation/gegl-operation-point-composer.c
+++ b/gegl/operation/gegl-operation-point-composer.c
@@ -220,7 +220,7 @@ gegl_operation_point_composer_process (GeglOperation       *operation,
 
   if ((result->width > 0) && (result->height > 0))
     {
-      if (cl_state.is_accelerated && point_composer_class->cl_process)
+      if (gegl_cl_is_accelerated () && point_composer_class->cl_process)
         {
           if (gegl_operation_point_composer_cl_process (operation, input, aux, output, result))
             return TRUE;
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index 0d2f55b..db694ad 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -140,7 +140,7 @@ gegl_operation_point_filter_process (GeglOperation       *operation,
 
   if ((result->width > 0) && (result->height > 0))
     {
-      if (cl_state.is_accelerated && point_filter_class->cl_process)
+      if (gegl_cl_is_accelerated () && point_filter_class->cl_process)
         {
           if (gegl_operation_point_filter_cl_process (operation, input, output, result))
             return TRUE;
diff --git a/gegl/operation/gegl-operation-sink.c b/gegl/operation/gegl-operation-sink.c
index a018e06..7c2b995 100644
--- a/gegl/operation/gegl-operation-sink.c
+++ b/gegl/operation/gegl-operation-sink.c
@@ -132,7 +132,7 @@ gegl_operation_sink_process (GeglOperation        *operation,
   input = gegl_operation_context_get_source (context, "input");
   if (input)
     {
-      if (cl_state.is_accelerated)
+      if (gegl_cl_is_accelerated ())
         gegl_buffer_cl_cache_invalidate (input, NULL);
 
       success = klass->process (operation, input, result);
diff --git a/gegl/process/gegl-processor.c b/gegl/process/gegl-processor.c
index c7c92e5..1c69be7 100644
--- a/gegl/process/gegl-processor.c
+++ b/gegl/process/gegl-processor.c
@@ -757,7 +757,7 @@ gegl_processor_work (GeglProcessor *processor,
   gegl_visitor_dfs_traverse (visitor, GEGL_VISITABLE (processor->node));
   visits_list = gegl_visitor_get_visits_list (visitor);
 
-  if (gegl_config()->use_opencl && cl_state.is_accelerated)
+  if (gegl_cl_is_accelerated () && gegl_config()->use_opencl)
     for (iterator = visits_list; iterator; iterator = iterator->next)
       {
         GeglNode *node = (GeglNode*) iterator->data;
diff --git a/operations/common/box-blur.c b/operations/common/box-blur.c
index 8a0e4d2..150aeba 100644
--- a/operations/common/box-blur.c
+++ b/operations/common/box-blur.c
@@ -369,7 +369,7 @@ process (GeglOperation       *operation,
   GeglOperationAreaFilter *op_area;
   op_area = GEGL_OPERATION_AREA_FILTER (operation);
 
-  if (cl_state.is_accelerated)
+  if (gegl_cl_is_accelerated ())
     if (cl_process (operation, input, output, result))
       return TRUE;
 



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