[gegl] buffer: simplify tilebus command dispatch by storing vfunc in instance



commit ca076603d158a9829c51204b7fbdf24b70480a03
Author: �yvind Kolås <pippin gimp org>
Date:   Tue Jul 20 02:13:45 2010 +0100

    buffer: simplify tilebus command dispatch by storing vfunc in instance

 gegl/buffer/gegl-buffer.c               |    4 +--
 gegl/buffer/gegl-tile-backend-file.c    |    3 +-
 gegl/buffer/gegl-tile-backend-ram.c     |    4 +--
 gegl/buffer/gegl-tile-backend-tiledir.c |    5 +--
 gegl/buffer/gegl-tile-handler-cache.c   |    4 +--
 gegl/buffer/gegl-tile-handler-chain.c   |    7 +----
 gegl/buffer/gegl-tile-handler-empty.c   |    4 +--
 gegl/buffer/gegl-tile-handler-log.c     |    4 +--
 gegl/buffer/gegl-tile-handler-zoom.c    |    3 +-
 gegl/buffer/gegl-tile-handler.c         |    4 +--
 gegl/buffer/gegl-tile-source.c          |    2 +-
 gegl/buffer/gegl-tile-source.h          |   14 ++++-----
 gegl/buffer/gegl-tile-storage.c         |   50 ++++++++++++++----------------
 13 files changed, 40 insertions(+), 68 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index 2dfdf1a..e68c687 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -767,15 +767,12 @@ static void
 gegl_buffer_class_init (GeglBufferClass *class)
 {
   GObjectClass      *gobject_class       = G_OBJECT_CLASS (class);
-  GeglTileSourceClass *tile_source_class = GEGL_TILE_SOURCE_CLASS (class);
-
   parent_class                = g_type_class_peek_parent (class);
   gobject_class->dispose      = gegl_buffer_dispose;
   gobject_class->finalize     = gegl_buffer_finalize;
   gobject_class->constructor  = gegl_buffer_constructor;
   gobject_class->set_property = gegl_buffer_set_property;
   gobject_class->get_property = gegl_buffer_get_property;
-  tile_source_class->command = gegl_buffer_command;
 
   g_object_class_install_property (gobject_class, PROP_PX_SIZE,
                                    g_param_spec_int ("px-size", "pixel-size", "size of a single pixel in bytes.",
@@ -941,6 +938,7 @@ gegl_buffer_init (GeglBuffer *buffer)
   buffer->path = NULL;
   buffer->tile_width = 128;
   buffer->tile_height = 64;
+  ((GeglTileSource*)buffer)->command = gegl_buffer_command;
 
   allocated_buffers++;
 
diff --git a/gegl/buffer/gegl-tile-backend-file.c b/gegl/buffer/gegl-tile-backend-file.c
index 5e82adb..2165b1a 100644
--- a/gegl/buffer/gegl-tile-backend-file.c
+++ b/gegl/buffer/gegl-tile-backend-file.c
@@ -1062,7 +1062,6 @@ static void
 gegl_tile_backend_file_class_init (GeglTileBackendFileClass *klass)
 {
   GObjectClass    *gobject_class     = G_OBJECT_CLASS (klass);
-  GeglTileSourceClass *gegl_tile_source_class = GEGL_TILE_SOURCE_CLASS (klass);
 
   parent_class = g_type_class_peek_parent (klass);
 
@@ -1071,7 +1070,6 @@ gegl_tile_backend_file_class_init (GeglTileBackendFileClass *klass)
   gobject_class->constructor  = gegl_tile_backend_file_constructor;
   gobject_class->finalize     = gegl_tile_backend_file_finalize;
 
-  gegl_tile_source_class->command = gegl_tile_backend_file_command;
 
   GEGL_BUFFER_STRUCT_CHECK_PADDING;
 
@@ -1087,6 +1085,7 @@ gegl_tile_backend_file_class_init (GeglTileBackendFileClass *klass)
 static void
 gegl_tile_backend_file_init (GeglTileBackendFile *self)
 {
+  ((GeglTileSource*)self)->command = gegl_tile_backend_file_command;
   self->path           = NULL;
 #if HAVE_GIO
   self->file           = NULL;
diff --git a/gegl/buffer/gegl-tile-backend-ram.c b/gegl/buffer/gegl-tile-backend-ram.c
index 580fac9..f585bd7 100644
--- a/gegl/buffer/gegl-tile-backend-ram.c
+++ b/gegl/buffer/gegl-tile-backend-ram.c
@@ -358,7 +358,6 @@ static void
 gegl_tile_backend_ram_class_init (GeglTileBackendRamClass *klass)
 {
   GObjectClass    *gobject_class     = G_OBJECT_CLASS (klass);
-  GeglTileSourceClass *gegl_tile_source_class = GEGL_TILE_SOURCE_CLASS (klass);
 
   parent_class = g_type_class_peek_parent (klass);
 
@@ -366,12 +365,11 @@ gegl_tile_backend_ram_class_init (GeglTileBackendRamClass *klass)
   gobject_class->set_property = set_property;
   gobject_class->constructor  = gegl_tile_backend_ram_constructor;
   gobject_class->finalize     = finalize;
-
-  gegl_tile_source_class->command  = gegl_tile_backend_ram_command;
 }
 
 static void
 gegl_tile_backend_ram_init (GeglTileBackendRam *self)
 {
+  ((GeglTileSource*)self)->command = gegl_tile_backend_ram_command;
   self->entries = NULL;
 }
diff --git a/gegl/buffer/gegl-tile-backend-tiledir.c b/gegl/buffer/gegl-tile-backend-tiledir.c
index e0a1d8f..75d28f3 100644
--- a/gegl/buffer/gegl-tile-backend-tiledir.c
+++ b/gegl/buffer/gegl-tile-backend-tiledir.c
@@ -355,6 +355,7 @@ gegl_tile_backend_tiledir_constructor (GType                  type,
 
   gio->buffer_dir = g_file_new_for_commandline_arg (gio->path);
   g_file_make_directory (gio->buffer_dir, NULL, NULL);
+  ((GeglTileSource*)(object))->command = gegl_tile_backend_tiledir_command;
   return object;
 }
 
@@ -362,7 +363,6 @@ static void
 gegl_tile_backend_tiledir_class_init (GeglTileBackendTileDirClass *klass)
 {
   GObjectClass    *gobject_class     = G_OBJECT_CLASS (klass);
-  GeglTileSourceClass *gegl_tile_source_class = GEGL_TILE_SOURCE_CLASS (klass);
 
   parent_class = g_type_class_peek_parent (klass);
 
@@ -371,9 +371,6 @@ gegl_tile_backend_tiledir_class_init (GeglTileBackendTileDirClass *klass)
   gobject_class->constructor  = gegl_tile_backend_tiledir_constructor;
   gobject_class->finalize     = finalize;
 
-  gegl_tile_source_class->command = gegl_tile_backend_tiledir_command;
-
-
   g_object_class_install_property (gobject_class, PROP_PATH,
                                    g_param_spec_string ("path",
                                                         "path",
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index a8345a7..aae0e5a 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -302,16 +302,14 @@ static void
 gegl_tile_handler_cache_class_init (GeglTileHandlerCacheClass *class)
 {
   GObjectClass        *gobject_class = G_OBJECT_CLASS (class);
-  GeglTileSourceClass *source_class  = GEGL_TILE_SOURCE_CLASS (class);
-
   gobject_class->finalize = finalize;
   gobject_class->dispose  = dispose;
-  source_class->command   = gegl_tile_handler_cache_command;
 }
 
 static void
 gegl_tile_handler_cache_init (GeglTileHandlerCache *cache)
 {
+  ((GeglTileSource*)cache)->command = gegl_tile_handler_cache_command;
   gegl_tile_cache_init ();
 }
 
diff --git a/gegl/buffer/gegl-tile-handler-chain.c b/gegl/buffer/gegl-tile-handler-chain.c
index 5d598a6..c84826e 100644
--- a/gegl/buffer/gegl-tile-handler-chain.c
+++ b/gegl/buffer/gegl-tile-handler-chain.c
@@ -112,12 +112,7 @@ static void
 gegl_tile_handler_chain_class_init (GeglTileHandlerChainClass *class)
 {
   GObjectClass      *gobject_class;
-  GeglTileSourceClass *tile_store_class;
-
   gobject_class    = (GObjectClass *) class;
-  tile_store_class = (GeglTileSourceClass *) class;
-
-  tile_store_class->command = gegl_tile_handler_chain_command;
 
   gobject_class->finalize = finalize;
   gobject_class->dispose  = dispose;
@@ -126,10 +121,10 @@ gegl_tile_handler_chain_class_init (GeglTileHandlerChainClass *class)
 static void
 gegl_tile_handler_chain_init (GeglTileHandlerChain *self)
 {
+  ((GeglTileSource*)self)->command = gegl_tile_handler_chain_command;
   self->chain = NULL;
 }
 
-
 void
 gegl_tile_handler_chain_bind (GeglTileHandlerChain *tile_handler_chain)
 {
diff --git a/gegl/buffer/gegl-tile-handler-empty.c b/gegl/buffer/gegl-tile-handler-empty.c
index 515d492..56b8b08 100644
--- a/gegl/buffer/gegl-tile-handler-empty.c
+++ b/gegl/buffer/gegl-tile-handler-empty.c
@@ -81,15 +81,13 @@ static void
 gegl_tile_handler_empty_class_init (GeglTileHandlerEmptyClass *klass)
 {
   GObjectClass        *gobject_class = G_OBJECT_CLASS (klass);
-  GeglTileSourceClass *source_class  = GEGL_TILE_SOURCE_CLASS (klass);
-
   gobject_class->finalize     = finalize;
-  source_class->command = gegl_tile_handler_empty_command;
 }
 
 static void
 gegl_tile_handler_empty_init (GeglTileHandlerEmpty *self)
 {
+  ((GeglTileSource*)self)->command = gegl_tile_handler_empty_command;
 }
 
 GeglTileHandler *
diff --git a/gegl/buffer/gegl-tile-handler-log.c b/gegl/buffer/gegl-tile-handler-log.c
index e73fded..ac6c581 100644
--- a/gegl/buffer/gegl-tile-handler-log.c
+++ b/gegl/buffer/gegl-tile-handler-log.c
@@ -74,12 +74,10 @@ gegl_tile_handler_log_command (GeglTileSource  *gegl_tile_source,
 static void
 gegl_tile_handler_log_class_init (GeglTileHandlerLogClass *klass)
 {
-  GeglTileSourceClass *source_class = GEGL_TILE_SOURCE_CLASS (klass);
-
-  source_class->command = gegl_tile_handler_log_command;
 }
 
 static void
 gegl_tile_handler_log_init (GeglTileHandlerLog *self)
 {
+  ((GeglTileSource*)self)->command = gegl_tile_handler_log_command;
 }
diff --git a/gegl/buffer/gegl-tile-handler-zoom.c b/gegl/buffer/gegl-tile-handler-zoom.c
index b9fb065..81f1c5c 100644
--- a/gegl/buffer/gegl-tile-handler-zoom.c
+++ b/gegl/buffer/gegl-tile-handler-zoom.c
@@ -312,13 +312,12 @@ gegl_tile_handler_zoom_command (GeglTileSource  *tile_store,
 static void
 gegl_tile_handler_zoom_class_init (GeglTileHandlerZoomClass *klass)
 {
-  GeglTileSourceClass *source_class = GEGL_TILE_SOURCE_CLASS (klass);
-  source_class->command = gegl_tile_handler_zoom_command;
 }
 
 static void
 gegl_tile_handler_zoom_init (GeglTileHandlerZoom *self)
 {
+  ((GeglTileSource*)self)->command = gegl_tile_handler_zoom_command;
   self->backend = NULL;
   self->tile_storage = NULL;
 }
diff --git a/gegl/buffer/gegl-tile-handler.c b/gegl/buffer/gegl-tile-handler.c
index 65a20e5..7943c29 100644
--- a/gegl/buffer/gegl-tile-handler.c
+++ b/gegl/buffer/gegl-tile-handler.c
@@ -136,14 +136,11 @@ static void
 gegl_tile_handler_class_init (GeglTileHandlerClass *klass)
 {
   GObjectClass    *gobject_class  = G_OBJECT_CLASS (klass);
-  GeglTileSourceClass *source_class = GEGL_TILE_SOURCE_CLASS (klass);
 
   gobject_class->set_property = set_property;
   gobject_class->get_property = get_property;
   gobject_class->dispose      = dispose;
 
-  source_class->command = gegl_tile_handler_command;
-
   g_object_class_install_property (gobject_class, PROP_SOURCE,
                                    g_param_spec_object ("source",
                                                         "GeglBuffer",
@@ -155,6 +152,7 @@ gegl_tile_handler_class_init (GeglTileHandlerClass *klass)
 static void
 gegl_tile_handler_init (GeglTileHandler *self)
 {
+  ((GeglTileSource*)self)->command = gegl_tile_handler_command;
   self->source = NULL;
 }
 
diff --git a/gegl/buffer/gegl-tile-source.c b/gegl/buffer/gegl-tile-source.c
index 9fb52a5..d30de3d 100644
--- a/gegl/buffer/gegl-tile-source.c
+++ b/gegl/buffer/gegl-tile-source.c
@@ -37,10 +37,10 @@ gegl_tile_source_command_eek (GeglTileSource  *gegl_tile_source,
 static void
 gegl_tile_source_class_init (GeglTileSourceClass *klass)
 {  
-  klass->command = gegl_tile_source_command_eek;
 }
 
 static void
 gegl_tile_source_init (GeglTileSource *self)
 {
+  self->command = gegl_tile_source_command_eek;
 }
diff --git a/gegl/buffer/gegl-tile-source.h b/gegl/buffer/gegl-tile-source.h
index 55750d8..96d4160 100644
--- a/gegl/buffer/gegl-tile-source.h
+++ b/gegl/buffer/gegl-tile-source.h
@@ -38,12 +38,6 @@ typedef gint GeglTileCommand;
 struct _GeglTileSource
 {
   GObject  parent_instance;
-};
-
-struct _GeglTileSourceClass
-{
-  GObjectClass  parent_class;
-
   gpointer      (*command)  (GeglTileSource  *gegl_tile_source,
                              GeglTileCommand command,
                              gint            x,
@@ -52,6 +46,11 @@ struct _GeglTileSourceClass
                              gpointer        data);
 };
 
+struct _GeglTileSourceClass
+{
+  GObjectClass  parent_class;
+};
+
 GType      gegl_tile_source_get_type (void) G_GNUC_CONST;
 
 /* All commands have the ability to pass commands to all tiles the handlers
@@ -179,8 +178,7 @@ gboolean  gegl_tile_source_idle      (GeglTileSource *source);
 #endif
 
 #define gegl_tile_source_command(source,cmd,x,y,z,tile)\
-(GEGL_TILE_SOURCE_GET_CLASS(source)->command(source,cmd,x,y,z,tile))
-
+(GEGL_TILE_SOURCE(source)->command(source,cmd,x,y,z,tile))
 
 #define gegl_tile_source_set_tile(source,x,y,z,tile) \
    (gboolean)GPOINTER_TO_INT(gegl_tile_source_command(source,GEGL_TILE_SET,x,y,z,tile))
diff --git a/gegl/buffer/gegl-tile-storage.c b/gegl/buffer/gegl-tile-storage.c
index 68a914c..02c6c32 100644
--- a/gegl/buffer/gegl-tile-storage.c
+++ b/gegl/buffer/gegl-tile-storage.c
@@ -185,7 +185,7 @@ gegl_tile_storage_constructor (GType                  type,
   GeglTileStorage       *tile_storage;
   GeglTileHandlerChain  *tile_handler_chain;
   GeglTileHandler       *handler;
-  GeglTileBackend       *backend;
+  GeglTileBackend       *backend = NULL;
   GeglTileHandler       *empty = NULL;
   GeglTileHandler       *zoom = NULL;
   GeglTileHandlerCache  *cache = NULL;
@@ -200,37 +200,33 @@ gegl_tile_storage_constructor (GType                  type,
   if (tile_storage->path != NULL)
     {
 #if 1
-      gegl_tile_handler_set_source (handler,
-                              g_object_new (GEGL_TYPE_TILE_BACKEND_FILE,
-                                            "tile-width", tile_storage->tile_width,
-                                            "tile-height", tile_storage->tile_height,
-                                            "format", tile_storage->format,
-                                            "path", tile_storage->path,
-                                            NULL));
+      backend = g_object_new (GEGL_TYPE_TILE_BACKEND_FILE,
+                              "tile-width", tile_storage->tile_width,
+                              "tile-height", tile_storage->tile_height,
+                              "format", tile_storage->format,
+                              "path", tile_storage->path,
+                              NULL);
 #else
-      gegl_tile_handler_set_source (handler,
-                    g_object_new (GEGL_TYPE_TILE_BACKEND_TILEDIR,
-                                            "tile-width", tile_storage->tile_width,
-                                            "tile-height", tile_storage->tile_height,
-                                            "format", tile_storage->format,
-                                            "path", tile_storage->path,
-                                            NULL));
+      backend = g_object_new (GEGL_TYPE_TILE_BACKEND_TILEDIR,
+                              "tile-width", tile_storage->tile_width,
+                              "tile-height", tile_storage->tile_height,
+                              "format", tile_storage->format,
+                              "path", tile_storage->path,
+                              NULL);
 #endif
     }
   else
     {
-      gegl_tile_handler_set_source (handler,
-                              g_object_new (GEGL_TYPE_TILE_BACKEND_RAM,
-                                            "tile-width", tile_storage->tile_width,
-                                            "tile-height", tile_storage->tile_height,
-                                            "format", tile_storage->format,
-                                            NULL));
+      backend = g_object_new (GEGL_TYPE_TILE_BACKEND_RAM,
+                              "tile-width", tile_storage->tile_width,
+                              "tile-height", tile_storage->tile_height,
+                              "format", tile_storage->format,
+                              NULL);
     }
 
-  g_object_get (handler->source,
-                "tile-size", &tile_storage->tile_size,
-                "px-size",   &tile_storage->px_size,
-                NULL);
+  tile_storage->tile_size = backend->tile_size;
+  tile_storage->px_size = backend->px_size;
+  gegl_tile_handler_set_source (handler, (void*)backend);
 
   g_object_unref (handler->source); /* eeek */
   backend = GEGL_TILE_BACKEND (handler->source);
@@ -250,7 +246,7 @@ gegl_tile_storage_constructor (GType                  type,
 
   if (g_getenv("GEGL_LOG_TILE_CACHE"))
     gegl_tile_handler_chain_add (tile_handler_chain,
-                              g_object_new (GEGL_TYPE_TILE_HANDLER_LOG, NULL));
+                                 g_object_new (GEGL_TYPE_TILE_HANDLER_LOG, NULL));
   tile_storage->cache = cache;
 
   gegl_tile_handler_chain_bind (tile_handler_chain);
@@ -266,7 +262,7 @@ gegl_tile_storage_constructor (GType                  type,
                                               tile_storage_idle,
                                               tile_storage,
                                               NULL);
-  tile_storage->seen_zoom = FALSE;
+  tile_storage->seen_zoom = 0;
   tile_storage->mutex = g_mutex_new ();
 
   return object;



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