MetaShadowFactory: convert to a GObject

https://bugzilla.gnome.org/show_bug.cgi?id=592382
This commit is contained in:
Owen W. Taylor 2010-11-04 17:26:24 -04:00
parent 825fc2c0c8
commit a846434bcf
2 changed files with 44 additions and 14 deletions

View File

@ -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

View File

@ -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
@ -59,11 +66,13 @@ void meta_shadow_get_bounds (MetaShadow *shadow,
* share the same MetaShadow.
*/
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,