summaryrefslogtreecommitdiff
path: root/image/gif.c
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2015-10-31 14:32:22 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2016-02-11 19:23:32 +0000
commita0e41a46a3b9b1f94c0449adeda18ff46fdf6a66 (patch)
tree55c2ce4e2fb3dbc613c8b9ecab9e80316f4c8606 /image/gif.c
parent90f65814c68b898117ea5cbccfd3221c72074c84 (diff)
downloadnetsurf-a0e41a46a3b9b1f94c0449adeda18ff46fdf6a66.tar.gz
netsurf-a0e41a46a3b9b1f94c0449adeda18ff46fdf6a66.tar.bz2
Stop GIF animations when they are no longer in use, instead of waiting until they are destroyed.
Diffstat (limited to 'image/gif.c')
-rw-r--r--image/gif.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/image/gif.c b/image/gif.c
index 3f5f6307e..fb0985a45 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -392,6 +392,31 @@ static nserror nsgif_clone(const struct content *old, struct content **newc)
return NSERROR_OK;
}
+static void nsgif_add_user(struct content *c)
+{
+ nsgif_content *gif = (nsgif_content *) c;
+
+ /* Ensure this content has already been converted.
+ * If it hasn't, the animation will start at the conversion phase instead. */
+ if (gif->gif == NULL) return;
+
+ if (content_count_users(c) == 1) {
+ /* First user, and content already converted, so start the animation. */
+ if (gif->gif->frame_count_partial > 1) {
+ guit->browser->schedule(gif->gif->frames[0].frame_delay * 10,
+ nsgif_animate, c);
+ }
+ }
+}
+
+static void nsgif_remove_user(struct content *c)
+{
+ if (content_count_users(c) == 1) {
+ /* Last user is about to be removed from this content, so stop the animation. */
+ guit->browser->schedule(-1, nsgif_animate, c);
+ }
+}
+
static void *nsgif_get_internal(const struct content *c, void *context)
{
nsgif_content *gif = (nsgif_content *) c;
@@ -415,6 +440,8 @@ static const content_handler nsgif_content_handler = {
.destroy = nsgif_destroy,
.redraw = nsgif_redraw,
.clone = nsgif_clone,
+ .add_user = nsgif_add_user,
+ .remove_user = nsgif_remove_user,
.get_internal = nsgif_get_internal,
.type = nsgif_content_type,
.no_share = false,