Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/609ef2c6b2792cbd4aa10...
...commit
http://git.netsurf-browser.org/netsurf.git/commit/609ef2c6b2792cbd4aa10d0...
...tree
http://git.netsurf-browser.org/netsurf.git/tree/609ef2c6b2792cbd4aa10d009...
The branch, chris/stop-gif-anim has been created
at 609ef2c6b2792cbd4aa10d0099e40b33ebbe350f (commit)
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=609ef2c6b2792cbd4aa...
commit 609ef2c6b2792cbd4aa10d0099e40b33ebbe350f
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Ensure that stopped GIF anims stay stopped
Guards against a possible race condition with the scheduler
diff --git a/image/gif.c b/image/gif.c
index 4455ff2..7aa7bf3 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -56,6 +56,7 @@ typedef struct nsgif_content {
struct gif_animation *gif; /**< GIF animation data */
int current_frame; /**< current frame to display [0...(max-1)] */
+ bool animating; /**< whether gif is currently animating */
} nsgif_content;
@@ -159,7 +160,7 @@ static void nsgif_animate(void *p)
}
/* Continue animating if we should */
- if (gif->gif->loop_count >= 0) {
+ if ((gif->gif->loop_count >= 0) && (gif->animating == true)) {
delay = gif->gif->frames[gif->current_frame].frame_delay;
if (delay < nsoption_int(minimum_gif_delay))
delay = nsoption_int(minimum_gif_delay);
@@ -295,10 +296,12 @@ static bool nsgif_convert(struct content *c)
/* Schedule the animation if we have one */
gif->current_frame = 0;
- if (gif->gif->frame_count_partial > 1)
+ if (gif->gif->frame_count_partial > 1) {
guit->browser->schedule(gif->gif->frames[0].frame_delay * 10,
nsgif_animate,
c);
+ gif->animating = true;
+ }
/* Exit as a success */
content_set_ready(c);
@@ -412,15 +415,19 @@ static void nsgif_add_user(struct content *c)
guit->browser->schedule(gif->gif->frames[0].frame_delay * 10,
nsgif_animate,
c);
+ gif->animating = true;
}
}
}
static void nsgif_remove_user(struct content *c)
{
+ nsgif_content *gif = (nsgif_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);
+ gif->animating = false;
}
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=1113ce117d5b860220b...
commit 1113ce117d5b860220bd979bd02dd067b8a9415e
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Start and stop GIF animation on first/last user.
diff --git a/content/content.c b/content/content.c
index a27647b..1a249e7 100644
--- a/content/content.c
+++ b/content/content.c
@@ -605,6 +605,9 @@ bool content_add_user(struct content *c,
user->next = c->user_list->next;
c->user_list->next = user;
+ if (c->handler->add_user != NULL)
+ c->handler->add_user(c);
+
return true;
}
@@ -636,6 +639,10 @@ void content_remove_user(struct content *c,
assert(0);
return;
}
+
+ if (c->handler->remove_user != NULL)
+ c->handler->remove_user(c);
+
next = user->next;
user->next = next->next;
free(next);
diff --git a/content/content_protected.h b/content/content_protected.h
index 7311da6..e5ff1ca 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -82,6 +82,8 @@ struct content_handler {
bool (*matches_quirks)(const struct content *c, bool quirks);
const char *(*get_encoding)(const struct content *c, enum content_encoding_type op);
content_type (*type)(void);
+ void (*add_user)(struct content *c);
+ void (*remove_user)(struct content *c);
/** handler dependant content sensitive internal data interface. */
void * (*get_internal)(const struct content *c, void *context);
diff --git a/image/gif.c b/image/gif.c
index c2f0ae4..4455ff2 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -398,6 +398,32 @@ 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;
@@ -421,6 +447,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,
-----------------------------------------------------------------------
--
NetSurf Browser