Permalink
Browse files

adding the canvas hack for animated gifs. We add an invisible copy of…

… the image to the dom, and then use that to draw on the canvas. The animation frames should continue to drive.
  • Loading branch information...
1 parent 23527d5 commit ba4d4b576c2ae7c8e2e3d9b421b5aedf89dba110 Danny Yoo committed Aug 5, 2011
Showing with 22 additions and 4 deletions.
  1. +22 −4 war/js/mzscheme-vm/support.js
@@ -10240,6 +10240,10 @@ var FileImage = function(src, rawImage) {
var self = this;
this.src = src;
this.isLoaded = false;
+
+ // animationHack: see installHackToSupportAnimatedGifs() for details.
+ this.animationHackImg = undefined;
+
if (rawImage && rawImage.complete) {
this.img = rawImage;
this.isLoaded = true;
@@ -10264,7 +10268,6 @@ var FileImage = function(src, rawImage) {
}
}
FileImage.prototype = heir(BaseImage.prototype);
-// world.Kernel.FileImage = FileImage;
var imageCache = {};
@@ -10287,10 +10290,24 @@ FileImage.installBrokenImage = function(path) {
FileImage.prototype.render = function(ctx, x, y) {
- ctx.drawImage(this.img, x, y);
+ this.installHackToSupportAnimatedGifs();
+
+ ctx.drawImage(this.animationHackImg, x, y);
+};
+
+
+// The following is a hack that we use to allow animated gifs to show
+// as animating on the canvas.
+FileImage.prototype.installHackToSupportAnimatedGifs = function() {
+ if (this.animationHackImg) { return; }
+ this.animationHackImg = this.img.cloneNode(true);
+ document.body.appendChild(this.animationHackImg);
+ this.animationHackImg.width = 0;
+ this.animationHackImg.height = 0;
};
+
FileImage.prototype.getWidth = function() {
return this.img.width;
};
@@ -10300,7 +10317,9 @@ FileImage.prototype.getHeight = function() {
return this.img.height;
};
-// Override toDomNode: we don't need a full-fledged canvas here.
+// Override toDomNode: we don't need a full-fledged canvas here, and
+// we want to clone the image so that we can have multiple instances
+// of the image attached to a document.
FileImage.prototype.toDomNode = function(cache) {
return this.img.cloneNode(true);
};
@@ -12353,7 +12372,6 @@ world.Kernel.isFileVideo = function(x) { return x instanceof FileVideo; };
};
-
var handleError = function(e) {
// helpers.reportError(e);
// When something bad happens, shut down

0 comments on commit ba4d4b5

Please sign in to comment.