Stop GIF animations when they are no longer in use, instead of waiting until they are destroyed.

This commit is contained in:
Chris Young 2015-10-31 14:32:22 +00:00
parent 90f65814c6
commit a0e41a46a3
3 changed files with 36 additions and 0 deletions

View File

@ -670,6 +670,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;
}
@ -699,6 +702,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);

View File

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

View File

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