[gegl] Made GeglTile be a struct instead of an object



commit 5d7bd409395525bdc038e58cb161b62f96f96f4c
Author: �yvind Kolås <pippin gimp org>
Date:   Sat Nov 21 20:38:10 2009 +0000

    Made GeglTile be a struct instead of an object
    
    Added a ref_count member that is used instead.

 gegl/buffer/gegl-buffer-access.c      |    2 +-
 gegl/buffer/gegl-buffer-iterator.c    |    2 +-
 gegl/buffer/gegl-buffer-linear.c      |    2 +-
 gegl/buffer/gegl-buffer.c             |    5 +-
 gegl/buffer/gegl-tile-handler-cache.c |    8 +-
 gegl/buffer/gegl-tile-handler-empty.c |    2 +-
 gegl/buffer/gegl-tile.c               |  143 +++++----------------------------
 gegl/buffer/gegl-tile.h               |   30 +++-----
 8 files changed, 45 insertions(+), 149 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index a91a1f1..7589a62 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -570,7 +570,7 @@ gegl_buffer_iterate (GeglBuffer          *buffer,
                         bp += buf_stride;
                       }
                   }
-                g_object_unref (tile);
+                gegl_tile_unref (tile);
               }
             bufx += (tile_width - offsetx);
           }
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index 619c0a6..0ebcbea 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -156,7 +156,7 @@ gulp:
         {
           gegl_tile_unlock (i->tile);
         }
-      g_object_unref (i->tile);
+      gegl_tile_unref (i->tile);
       i->tile = NULL;
     }
 
diff --git a/gegl/buffer/gegl-buffer-linear.c b/gegl/buffer/gegl-buffer-linear.c
index cf28831..7a7a32d 100644
--- a/gegl/buffer/gegl-buffer-linear.c
+++ b/gegl/buffer/gegl-buffer-linear.c
@@ -82,7 +82,7 @@ gegl_buffer_linear_new_from_data (const gpointer       data,
     buffer = gegl_buffer_linear_new2 (extent, format, rowstride);
 
   {
-    GeglTile *tile = g_object_new (GEGL_TYPE_TILE, NULL);
+    GeglTile *tile = gegl_tile_new_bare (); 
 
     tile->rev        = 1;
     tile->stored_rev = 1;
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index cc2399d..5a97c3d 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -375,7 +375,7 @@ gegl_buffer_dispose (GObject *object)
 
   if (buffer->hot_tile)
     {
-      g_object_unref (buffer->hot_tile);
+      gegl_tile_unref (buffer->hot_tile);
       buffer->hot_tile = NULL;
     }
 
@@ -1078,6 +1078,7 @@ gegl_buffer_new_from_format (const void *babl_format,
   else
     {
       static gint no = 1;
+      static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
 
       gchar *filename;
       gchar *path;
@@ -1089,7 +1090,9 @@ gegl_buffer_new_from_format (const void *babl_format,
                                   no++);
 #endif
 
+      g_static_mutex_lock (&mutex);
       filename = g_strdup_printf ("%i-%i", getpid(), no++);
+      g_static_mutex_unlock (&mutex);
       path = g_build_filename (gegl_config()->swap, filename, NULL);
       g_free (filename);
 
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index c494f25..adaaed8 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -196,7 +196,7 @@ dispose (GObject *object)
         if (item->tile)
           {
             cache_total -= item->tile->size;
-            g_object_unref (item->tile);
+            gegl_tile_unref (item->tile);
           }
         g_queue_remove (cache_queue, item);
         g_hash_table_remove (cache_ht, item);
@@ -384,7 +384,7 @@ gegl_tile_handler_cache_get_tile (GeglTileHandlerCache *cache,
 #ifdef ENABLE_MT
       g_static_mutex_unlock (&mutex);
 #endif
-      return g_object_ref (result->tile);
+      return gegl_tile_ref (result->tile);
     }
 #ifdef ENABLE_MT
   g_static_mutex_unlock (&mutex);
@@ -505,7 +505,7 @@ gegl_tile_handler_cache_void (GeglTileHandlerCache *cache,
         {
           gegl_tile_void (tile);
           cache_total -= item->tile->size;
-          g_object_unref (tile);
+          gegl_tile_unref (tile);
           g_hash_table_remove (cache_ht, item);
           g_slice_free (CacheItem, item);
           g_queue_delete_link (cache_queue, link);
@@ -531,7 +531,7 @@ gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
   guint      count;
 
   item->handler = cache;
-  item->tile    = g_object_ref (tile);
+  item->tile    = gegl_tile_ref (tile);
   item->x       = x;
   item->y       = y;
   item->z       = z;
diff --git a/gegl/buffer/gegl-tile-handler-empty.c b/gegl/buffer/gegl-tile-handler-empty.c
index b958350..32280bf 100644
--- a/gegl/buffer/gegl-tile-handler-empty.c
+++ b/gegl/buffer/gegl-tile-handler-empty.c
@@ -38,7 +38,7 @@ finalize (GObject *object)
   GeglTileHandlerEmpty *empty = GEGL_TILE_HANDLER_EMPTY (object);
 
   if (empty->tile)
-    g_object_unref (empty->tile);
+    gegl_tile_unref (empty->tile);
 
   G_OBJECT_CLASS (gegl_tile_handler_empty_parent_class)->finalize (object);
 }
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index f642306..5014af4 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -13,7 +13,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
  *
- * Copyright 2006,2007 �yvind Kolås <pippin gimp org>
+ * Copyright 2006-2009 �yvind Kolås <pippin gimp org>
  */
 
 #include "config.h"
@@ -35,79 +35,6 @@
 #include "gegl-tile-source.h"
 #include "gegl-tile-storage.h"
 
-
-G_DEFINE_TYPE (GeglTile, gegl_tile, G_TYPE_OBJECT)
-enum
-{
-  PROP_0,
-  PROP_X,
-  PROP_Y,
-  PROP_Z,
-  PROP_SIZE
-};
-static GObjectClass *parent_class = NULL;
-
-
-static void
-get_property (GObject    *gobject,
-              guint       property_id,
-              GValue     *value,
-              GParamSpec *pspec)
-{
-  GeglTile *tile = GEGL_TILE (gobject);
-
-  switch (property_id)
-    {
-      case PROP_X:
-        g_value_set_int (value, tile->x);
-        break;
-
-      case PROP_Y:
-        g_value_set_int (value, tile->y);
-        break;
-
-      case PROP_Z:
-        g_value_set_int (value, tile->z);
-        break;
-
-      case PROP_SIZE:
-        g_value_set_int (value, tile->size);
-        break;
-
-      default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
-        break;
-    }
-}
-
-static void
-set_property (GObject      *gobject,
-              guint         property_id,
-              const GValue *value,
-              GParamSpec   *pspec)
-{
-  GeglTile *tile = GEGL_TILE (gobject);
-
-  switch (property_id)
-    {
-      case PROP_X:
-        tile->x = g_value_get_int (value);
-        return;
-
-      case PROP_Y:
-        tile->y = g_value_get_int (value);
-        return;
-
-      case PROP_Z:
-        tile->z = g_value_get_int (value);
-        return;
-
-      default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
-        break;
-    }
-}
-
 #include "gegl-utils.h"
 
 static void default_free (gpointer data,
@@ -116,10 +43,17 @@ static void default_free (gpointer data,
   gegl_free (data);
 }
 
-static void
-dispose (GObject *object)
+GeglTile *gegl_tile_ref (GeglTile *tile)
 {
-  GeglTile *tile = (GeglTile *) object;
+  tile->ref_count++;
+  return tile;
+}
+
+void gegl_tile_unref (GeglTile *tile)
+{
+  tile->ref_count --;
+  if (tile->ref_count > 0)
+    return;
 
   if (!gegl_tile_is_stored (tile))
     gegl_tile_store (tile);
@@ -139,7 +73,6 @@ dispose (GObject *object)
         }
     }
 
-//#define ENABLE_MT 1
 #if ENABLE_MT
   if (tile->mutex)
     {
@@ -147,45 +80,15 @@ dispose (GObject *object)
       tile->mutex = NULL;
     }
 #endif
-
-  (*G_OBJECT_CLASS (parent_class)->dispose)(object);
-}
-
-static void
-gegl_tile_class_init (GeglTileClass *class)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-
-  gobject_class->set_property = set_property;
-  gobject_class->get_property = get_property;
-  gobject_class->dispose      = dispose;
-  parent_class                = g_type_class_peek_parent (class);
-
-  g_object_class_install_property (gobject_class, PROP_X,
-                                   g_param_spec_int ("x", "x", "Horizontal index",
-                                                     G_MININT / 2, G_MAXINT / 2, 0,
-                                                     G_PARAM_READWRITE));
-
-  g_object_class_install_property (gobject_class, PROP_Y,
-                                   g_param_spec_int ("y", "y", "Vertical index",
-                                                     G_MININT / 2, G_MAXINT / 2, 0,
-                                                     G_PARAM_READWRITE));
-
-  g_object_class_install_property (gobject_class, PROP_Z,
-                                   g_param_spec_int ("z", "z", "Pyramid level 0=100% 1=50% 2=25%",
-                                                     0, 256, 0,
-                                                     G_PARAM_READWRITE));
-
-  g_object_class_install_property (gobject_class, PROP_SIZE,
-                                   g_param_spec_int ("size", "size", "size of linear memory buffer in bytes.",
-                                                     0, 0, 0,
-                                                     G_PARAM_READABLE));
+  g_slice_free (GeglTile, tile);
 }
 
-static void
-gegl_tile_init (GeglTile *tile)
+GeglTile *
+gegl_tile_new_bare (void)
 {
-  tile->tile_storage    = NULL;
+  GeglTile *tile = g_slice_new0 (GeglTile);
+  tile->ref_count = 1;
+  tile->tile_storage = NULL;
   tile->stored_rev = 0;
   tile->rev        = 0;
   tile->lock       = 0;
@@ -198,12 +101,14 @@ gegl_tile_init (GeglTile *tile)
   tile->mutex = g_mutex_new ();
 #endif
   tile->destroy_notify = default_free;
+
+  return tile;
 }
 
 GeglTile *
 gegl_tile_dup (GeglTile *src)
 {
-  GeglTile *tile = g_object_new (GEGL_TYPE_TILE, NULL);
+  GeglTile *tile = gegl_tile_new_bare ();
 
   tile->rev        = 1;
   tile->stored_rev = 1;
@@ -234,7 +139,7 @@ gegl_tile_dup (GeglTile *src)
 GeglTile *
 gegl_tile_new (gint size)
 {
-  GeglTile *tile = g_object_new (GEGL_TYPE_TILE, NULL);
+  GeglTile *tile = gegl_tile_new_bare ();
 
   tile->data       = gegl_malloc (size);
   tile->size       = size;
@@ -391,7 +296,7 @@ gegl_tile_swp (GeglTile *a,
   gegl_tile_unclone (a);
   gegl_tile_unclone (b);
 
-/*  gegl_buffer_add_dirty (a->buffer, a->x, a->y);
+/* gegl_buffer_add_dirty (a->buffer, a->x, a->y);
    gegl_buffer_add_dirty (b->buffer, b->x, b->y);*/
 
   g_assert (a->size == b->size);
@@ -413,7 +318,3 @@ gboolean gegl_tile_store (GeglTile *tile)
                                     tile->z,
                                     tile);
 }
-
-
-
-
diff --git a/gegl/buffer/gegl-tile.h b/gegl/buffer/gegl-tile.h
index 70725cc..403652b 100644
--- a/gegl/buffer/gegl-tile.h
+++ b/gegl/buffer/gegl-tile.h
@@ -13,7 +13,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
  *
- * Copyright 2006,2007 �yvind Kolås <pippin gimp org>
+ * Copyright 2006-2009 �yvind Kolås <pippin gimp org>
  */
 
 #ifndef __GEGL_TILE_H__
@@ -23,20 +23,13 @@
 
 #include "gegl-buffer-types.h"
 
-#define GEGL_TYPE_TILE            (gegl_tile_get_type ())
-#define GEGL_TILE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_TILE, GeglTile))
-#define GEGL_TILE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GEGL_TYPE_TILE, GeglTileClass))
-#define GEGL_IS_TILE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_TILE))
-#define GEGL_IS_TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GEGL_TYPE_TILE))
-#define GEGL_TILE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GEGL_TYPE_TILE, GeglTileClass))
-
-
 /* the instance size of a GeglTile is a bit large, and should if possible be
  * trimmed down
  */
 struct _GeglTile
 {
-  GObject          parent_instance;
+ /* GObject          parent_instance;*/
+  gint             ref_count;
 
   guchar          *data;        /* actual pixel data for tile, a linear buffer*/
   gint             size;        /* The size of the linear buffer */
@@ -66,17 +59,13 @@ struct _GeglTile
 
   void (*destroy_notify) (gpointer pixels,
                           gpointer data);
-  gpointer destroy_notify_data;
+  gpointer         destroy_notify_data;
 };
 
-struct _GeglTileClass
-{
-  GObjectClass parent_class;
-};
-
-GType        gegl_tile_get_type   (void) G_GNUC_CONST;
-
 GeglTile   * gegl_tile_new        (gint     size);
+GeglTile   * gegl_tile_new_bare   (void); /* special hack for linear bufs */
+GeglTile   * gegl_tile_ref        (GeglTile *tile);
+void         gegl_tile_unref      (GeglTile *tile);
 void       * gegl_tile_get_format (GeglTile *tile);
 
 
@@ -117,7 +106,10 @@ GeglTile    *gegl_tile_dup        (GeglTile *tile);
       (coordinate) / (stride):\
       ((((coordinate) + 1) /(stride)) - 1))
 
-/* utility low-level functions used by undo system */
+/* utility low-level functions used by an undo system in horizon
+ * where the geglbufer originated, kept around in case they
+ * become useful again
+ */
 void         gegl_tile_swp        (GeglTile *a,
                                    GeglTile *b);
 void         gegl_tile_cpy        (GeglTile *src,



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