[mutter] MetaShadowFactory: convert to a GObject



commit d56d267f7df8c4b9dceec2f8a4e8e15655046d60
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Thu Nov 4 17:26:24 2010 -0400

    MetaShadowFactory: convert to a GObject
    
    https://bugzilla.gnome.org/show_bug.cgi?id=592382

 src/compositor/meta-shadow-factory.c |   45 +++++++++++++++++++++++++---------
 src/compositor/meta-shadow-factory.h |   13 ++++++++-
 2 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/src/compositor/meta-shadow-factory.c b/src/compositor/meta-shadow-factory.c
index 30e82b8..11431c6 100644
--- a/src/compositor/meta-shadow-factory.c
+++ b/src/compositor/meta-shadow-factory.c
@@ -84,11 +84,20 @@ struct _MetaShadow
 
 struct _MetaShadowFactory
 {
+  GObject parent_instance;
+
   /* MetaShadowCacheKey => MetaShadow; the shadows are not referenced
    * by the factory, they are simply removed from the table when freed */
   GHashTable *shadows;
 };
 
+struct _MetaShadowFactoryClass
+{
+  GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (MetaShadowFactory, meta_shadow_factory, G_TYPE_OBJECT);
+
 static guint
 meta_shadow_cache_key_hash (gconstpointer val)
 {
@@ -253,27 +262,22 @@ meta_shadow_get_bounds  (MetaShadow            *shadow,
   bounds->height = window_height + shadow->outer_border_top + shadow->outer_border_bottom;
 }
 
-MetaShadowFactory *
-meta_shadow_factory_new (void)
+static void
+meta_shadow_factory_init (MetaShadowFactory *factory)
 {
-  MetaShadowFactory *factory;
-
-  factory = g_slice_new0 (MetaShadowFactory);
-
   factory->shadows = g_hash_table_new (meta_shadow_cache_key_hash,
                                        meta_shadow_cache_key_equal);
-
-  return factory;
 }
 
-void
-meta_shadow_factory_free (MetaShadowFactory *factory)
+static void
+meta_shadow_factory_finalize (GObject *object)
 {
+  MetaShadowFactory *factory = META_SHADOW_FACTORY (object);
   GHashTableIter iter;
   gpointer key, value;
 
   /* Detach from the shadows in the table so we won't try to
-   * remove them when they freed. */
+   * remove them when they're freed. */
   g_hash_table_iter_init (&iter, factory->shadows);
   while (g_hash_table_iter_next (&iter, &key, &value))
     {
@@ -283,7 +287,21 @@ meta_shadow_factory_free (MetaShadowFactory *factory)
 
   g_hash_table_destroy (factory->shadows);
 
-  g_slice_free (MetaShadowFactory, factory);
+  G_OBJECT_CLASS (meta_shadow_factory_parent_class)->finalize (object);
+}
+
+static void
+meta_shadow_factory_class_init (MetaShadowFactoryClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = meta_shadow_factory_finalize;
+}
+
+MetaShadowFactory *
+meta_shadow_factory_new (void)
+{
+  return g_object_new (META_TYPE_SHADOW_FACTORY, NULL);
 }
 
 MetaShadowFactory *
@@ -672,6 +690,9 @@ meta_shadow_factory_get_shadow (MetaShadowFactory  *factory,
   gboolean cacheable;
   int center_width, center_height;
 
+  g_return_val_if_fail (META_IS_SHADOW_FACTORY (factory), NULL);
+  g_return_val_if_fail (shape != NULL, NULL);
+
   /* Using a single shadow texture for different window sizes only works
    * when there is a central scaled area that is greater than twice
    * the spread of the gaussian blur we are applying to get to the
diff --git a/src/compositor/meta-shadow-factory.h b/src/compositor/meta-shadow-factory.h
index 8c2c336..8dc9e95 100644
--- a/src/compositor/meta-shadow-factory.h
+++ b/src/compositor/meta-shadow-factory.h
@@ -28,6 +28,13 @@
 #include <clutter/clutter.h>
 #include "meta-window-shape.h"
 
+#define META_TYPE_SHADOW_FACTORY            (meta_shadow_factory_get_type ())
+#define META_SHADOW_FACTORY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SHADOW_FACTORY, MetaShadowFactory))
+#define META_SHADOW_FACTORY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  META_TYPE_SHADOW_FACTORY, MetaShadowFactoryClass))
+#define META_IS_SHADOW_FACTORY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_SHADOW_FACTORY))
+#define META_IS_SHADOW_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  META_TYPE_SHADOW_FACTORY))
+#define META_SHADOW_FACTORY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  META_TYPE_SHADOW_FACTORY, MetaShadowFactoryClass))
+
 /**
  * MetaShadow:
  * #MetaShadow holds a shadow texture along with information about how to
@@ -58,12 +65,14 @@ void        meta_shadow_get_bounds  (MetaShadow            *shadow,
  * so that multiple shadows created for the same shape with the same radius will
  * share the same MetaShadow.
  */
-typedef struct _MetaShadowFactory MetaShadowFactory;
+typedef struct _MetaShadowFactory      MetaShadowFactory;
+typedef struct _MetaShadowFactoryClass MetaShadowFactoryClass;
 
 MetaShadowFactory *meta_shadow_factory_get_default (void);
 
+GType meta_shadow_factory_get_type (void);
+
 MetaShadowFactory *meta_shadow_factory_new        (void);
-void               meta_shadow_factory_free       (MetaShadowFactory *factory);
 MetaShadow *       meta_shadow_factory_get_shadow (MetaShadowFactory *factory,
                                                    MetaWindowShape   *shape,
                                                    int                width,



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