diff options
author | Havoc Pennington <hp@pobox.com> | 2000-06-22 15:36:12 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2000-06-22 15:36:12 +0000 |
commit | 3a422541e314126987c24fc1752f94962fad78d5 (patch) | |
tree | 9692c443f5df4063c64c4b72cc9482cb1b342a4b /gdk-pixbuf/gdk-pixbuf-animation.c | |
parent | 7b6c38f544dd6d55123b1a21d6a45da957ee6396 (diff) | |
download | gdk-pixbuf-3a422541e314126987c24fc1752f94962fad78d5.tar.gz |
Convert GdkPixbuf to GObject, leaving it opaque (i.e. derivation is not
2000-06-21 Havoc Pennington <hp@pobox.com>
* gdk-pixbuf.c: Convert GdkPixbuf to GObject, leaving it opaque
(i.e. derivation is not allowed, and there are no virtual methods
anyway).
(gdk_pixbuf_preinit): Call g_type_init() here.
(gdk_pixbuf_init): Add a user-friendly init function, for users
of standalone gdk-pixbuf
* gdk-pixbuf-animation.c: Convert to GObject, in the same
way GdkPixbufAnimation was done.
* gdk-pixbuf.h: Remove gdk_pixbuf_set_unref_handler() and
gdk_pixbuf_finalize() from API, since these are broken and don't
make sense with new GObject stuff.
2000-06-21 Havoc Pennington <hp@pobox.com>
* gdk/gdkwindow.c (_gdk_window_destroy_hierarchy): Fix bug where
we didn't check window->bg_pixmap != GDK_NO_BG.
* gtk/gdk-pixbuf-loader.c: Change to reflect GObject-ification of
gdk-pixbuf
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf-animation.c')
-rw-r--r-- | gdk-pixbuf/gdk-pixbuf-animation.c | 106 |
1 files changed, 72 insertions, 34 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c index beb5b2939..fa6108b89 100644 --- a/gdk-pixbuf/gdk-pixbuf-animation.c +++ b/gdk-pixbuf/gdk-pixbuf-animation.c @@ -25,6 +25,68 @@ #include "gdk-pixbuf-io.h" #include "gdk-pixbuf-private.h" +static void gdk_pixbuf_animation_class_init (GdkPixbufAnimationClass *klass); +static void gdk_pixbuf_animation_finalize (GObject *object); + + + +static gpointer parent_class; + +GType +gdk_pixbuf_animation_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) { + static const GTypeInfo object_info = { + sizeof (GdkPixbufAnimationClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gdk_pixbuf_animation_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GdkPixbufAnimation), + 0, /* n_preallocs */ + (GInstanceInitFunc) NULL, + }; + + object_type = g_type_register_static (G_TYPE_OBJECT, + "GdkPixbufAnimation", + &object_info); + } + + return object_type; +} + +static void +gdk_pixbuf_animation_class_init (GdkPixbufAnimationClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = gdk_pixbuf_animation_finalize; +} + +static void +gdk_pixbuf_animation_finalize (GObject *object) +{ + GdkPixbufAnimation *animation = GDK_PIXBUF_ANIMATION (object); + + GList *l; + GdkPixbufFrame *frame; + + for (l = animation->frames; l; l = l->next) { + frame = l->data; + gdk_pixbuf_unref (frame->pixbuf); + g_free (frame); + } + + g_list_free (animation->frames); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + /** @@ -87,10 +149,8 @@ gdk_pixbuf_animation_new_from_file (const char *filename) pixbuf = (* image_module->load) (f); fclose (f); - if (pixbuf) - g_assert (pixbuf->ref_count > 0); - else - return NULL; + if (pixbuf == NULL) + return NULL; frame = g_new (GdkPixbufFrame, 1); frame->pixbuf = pixbuf; @@ -99,8 +159,8 @@ gdk_pixbuf_animation_new_from_file (const char *filename) frame->delay_time = -1; frame->action = GDK_PIXBUF_FRAME_RETAIN; - animation = g_new0 (GdkPixbufAnimation, 1); - animation->ref_count = 1; + animation = GDK_PIXBUF_ANIMATION (g_type_create_instance (GDK_TYPE_PIXBUF_ANIMATION)); + animation->n_frames = 1; animation->frames = g_list_prepend (NULL, frame); animation->width = gdk_pixbuf_get_width (pixbuf); @@ -118,50 +178,28 @@ gdk_pixbuf_animation_new_from_file (const char *filename) * gdk_pixbuf_animation_ref: * @animation: An animation. * - * Adds a reference to an animation. It must be released afterwards using - * gdk_pixbuf_animation_unref(). + * Adds a reference to an animation. Deprecated; use + * g_object_ref(). The reference must be released afterwards using + * g_object_unref(). * * Return value: The same as the @animation argument. **/ GdkPixbufAnimation * gdk_pixbuf_animation_ref (GdkPixbufAnimation *animation) { - g_return_val_if_fail (animation != NULL, NULL); - g_return_val_if_fail (animation->ref_count > 0, NULL); - - animation->ref_count++; - return animation; + return (GdkPixbufAnimation*) g_object_ref (G_OBJECT (animation)); } /** * gdk_pixbuf_animation_unref: * @animation: An animation. * - * Removes a reference from an animation. It will be destroyed when the - * reference count drops to zero. At that point, all the frames in the - * animation will be freed and their corresponding pixbufs will be unreferenced. + * Removes a reference from an animation. Deprecated; use g_object_unref(). **/ void gdk_pixbuf_animation_unref (GdkPixbufAnimation *animation) { - g_return_if_fail (animation != NULL); - g_return_if_fail (animation->ref_count > 0); - - animation->ref_count--; - - if (animation->ref_count == 0) { - GList *l; - GdkPixbufFrame *frame; - - for (l = animation->frames; l; l = l->next) { - frame = l->data; - gdk_pixbuf_unref (frame->pixbuf); - g_free (frame); - } - - g_list_free (animation->frames); - g_free (animation); - } + g_object_unref (G_OBJECT (animation)); } /** |