[gegl/gsoc2011-opencl: 8/10] support for GeglClTexture in GeglTile



commit 5b2d2be56c2ea0a3a7512bfc0731d6e9952904bc
Author: Victor Oliveira <victormatheus gmail com>
Date:   Wed Jun 1 17:18:08 2011 -0300

    support for GeglClTexture in GeglTile

 gegl/buffer/gegl-buffer-private.h |    8 +++++
 gegl/buffer/gegl-tile.c           |   63 ++++++++++++++++++++++++++++++++++---
 2 files changed, 66 insertions(+), 5 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index dec56e1..fcf11ce 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -26,6 +26,9 @@
 #include "gegl-tile-handler.h"
 #include "gegl-buffer-iterator.h"
 
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
 #define GEGL_BUFFER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GEGL_TYPE_BUFFER, GeglBufferClass))
 #define GEGL_IS_BUFFER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_BUFFER))
 #define GEGL_IS_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GEGL_TYPE_BUFFER))
@@ -145,6 +148,8 @@ struct _GeglTile
   guchar          *data;        /* actual pixel data for tile, a linear buffer*/
   gint             size;        /* The size of the linear buffer */
 
+  GeglClTexture   *cl_data;     /* OpenCL pixel data for tile */
+
   GeglTileStorage *tile_storage; /* the buffer from which this tile was
                                   * retrieved needed for the tile to be able to
                                   * store itself back (for instance when it is
@@ -154,6 +159,7 @@ struct _GeglTile
 
 
   guint            rev;         /* this tile revision */
+  guint            cl_rev;      /* this tile revision for OpenCL buffer*/
   guint            stored_rev;  /* what revision was we when we from tile_storage?
                                    (currently set to 1 when loaded from disk */
 
@@ -167,7 +173,9 @@ struct _GeglTile
   GeglTile        *prev_shared;
 
   void (*destroy_notify) (gpointer pixels,
+                          GeglClTexture *cl_data,
                           gpointer data);
+
   gpointer         destroy_notify_data;
 };
 
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index 79ac438..4ed9005 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -39,10 +39,17 @@
 
 #include "gegl-utils.h"
 
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
 static void default_free (gpointer data,
+                          GeglClTexture *cl_data,
                           gpointer userdata)
 {
   gegl_free (data);
+
+  if (cl_data)
+    gegl_cl_texture_free(cl_data);
 }
 
 GeglTile *gegl_tile_ref (GeglTile *tile)
@@ -63,13 +70,14 @@ void gegl_tile_unref (GeglTile *tile)
   if (!gegl_tile_is_stored (tile))
     gegl_tile_store (tile);
 
-  if (tile->data)
+  if (tile->data || tile->cl_data)
     {
       if (tile->next_shared == tile)
         { /* no clones */
           if (tile->destroy_notify)
-            tile->destroy_notify (tile->data, tile->destroy_notify_data);
+            tile->destroy_notify (tile->data, tile->cl_data, tile->destroy_notify_data);
           tile->data = NULL;
+          tile->cl_data = NULL;
         }
       else
         {
@@ -94,8 +102,10 @@ gegl_tile_new_bare (void)
   tile->tile_storage = NULL;
   tile->stored_rev = 1;
   tile->rev        = 1;
+  tile->cl_rev     = 0;
   tile->lock       = 0;
   tile->data       = NULL;
+  tile->cl_data    = NULL;
 
   tile->next_shared = tile;
   tile->prev_shared = tile;
@@ -111,6 +121,20 @@ gegl_tile_dup (GeglTile *src)
 {
   GeglTile *tile = gegl_tile_new_bare ();
 
+  if (gegl_cl_is_accelerated ())
+    {
+      if (src->rev > src->cl_rev)
+        {
+          gegl_cl_texture_set (src->cl_data, src->data, src->size);
+          src->cl_rev = src->rev;
+        }
+      else if (src->cl_rev > src->rev)
+        {
+          gegl_cl_texture_get (src->cl_data, src->data, src->size);
+          src->rev = src->cl_rev;
+        }
+    }
+
   tile->tile_storage    = src->tile_storage;
   tile->data       = src->data;
   tile->size       = src->size;
@@ -139,6 +163,9 @@ gegl_tile_new (gint size)
   tile->data = gegl_malloc (size);
   tile->size = size;
 
+  if (gegl_cl_is_accelerated ())
+    tile->cl_data = gegl_cl_texture_new (size);
+
   return tile;
 }
 
@@ -164,6 +191,10 @@ gegl_tile_unclone (GeglTile *tile)
       tile->next_shared->prev_shared = tile->prev_shared;
       tile->prev_shared              = tile;
       tile->next_shared              = tile;
+
+      if (gegl_cl_is_accelerated ())
+          tile->cl_data = gegl_cl_texture_dup (tile->cl_data);
+
     }
 }
 #if 0
@@ -191,6 +222,20 @@ gegl_tile_lock (GeglTile *tile)
   /*fprintf (stderr, "global tile locking: %i %i\n", locks, unlocks);*/
 
   gegl_tile_unclone (tile);
+
+  if (gegl_cl_is_accelerated ())
+    {
+      if (tile->rev > tile->cl_rev)
+        {
+          gegl_cl_texture_set (tile->cl_data, tile->data, tile->size);
+          tile->cl_rev = tile->rev;
+        }
+      else if (tile->cl_rev > tile->rev)
+        {
+          gegl_cl_texture_get (tile->cl_data, tile->data, tile->size);
+          tile->rev = tile->cl_rev;
+        }
+    }
 }
 
 static void
@@ -231,13 +276,21 @@ gegl_tile_unlock (GeglTile *tile)
       g_warning ("unlocked a tile with lock count == 0");
     }
   tile->lock--;
+
   if (tile->lock == 0 &&
       tile->z == 0)
     {
       gegl_tile_void_pyramid (tile);
     }
+
   if (tile->lock==0)
-    tile->rev++;
+    {
+      if (gegl_cl_is_accelerated ())
+          tile->rev = tile->cl_rev = MAX(tile->rev, tile->cl_rev)+1;
+      else
+          tile->rev++;
+    }
+
   g_mutex_unlock (tile->mutex);
 }
 
@@ -251,13 +304,13 @@ gegl_tile_mark_as_stored (GeglTile *tile)
 gboolean
 gegl_tile_is_stored (GeglTile *tile)
 {
-  return tile->stored_rev == tile->rev;
+  return tile->stored_rev == MAX(tile->rev, tile->cl_rev);
 }
 
 void
 gegl_tile_void (GeglTile *tile)
 {
-  tile->stored_rev = tile->rev;
+  tile->stored_rev = MAX(tile->rev, tile->cl_rev);
   tile->tile_storage = NULL;
   if (tile->z==0)
     gegl_tile_void_pyramid (tile);



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