From 30dae6761bae0ba3ccbba98d98ea8d0f03a1dbfb Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Wed, 18 Aug 2010 19:30:42 -0700 Subject: [PATCH] Bug 588452 - Don't render to zoom snapshot canvas before prior render finishes [r=stechz] --HG-- extra : rebase_source : f4994456ae0bd2704aa8ae52f80810607a6c2bbd --- mobile/chrome/content/AnimatedZoom.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mobile/chrome/content/AnimatedZoom.js b/mobile/chrome/content/AnimatedZoom.js index 3d45eb053d4e..a43de28bbc46 100644 --- a/mobile/chrome/content/AnimatedZoom.js +++ b/mobile/chrome/content/AnimatedZoom.js @@ -51,6 +51,10 @@ let Cu = Components.utils; function AnimatedZoom(aBrowserView) { this.bv = aBrowserView; + this.snapshot = AnimatedZoom.createCanvas(); + if (this.snapshot.pending_render) + return; + // Render a snapshot of the viewport contents around the visible rect let [w, h] = this.bv.getViewportDimensions(); let viewportRect = new Rect(0, 0, w, h); @@ -61,8 +65,6 @@ function AnimatedZoom(aBrowserView) { // sanitize the snapshot rectangle to fit inside viewport this.snapshotRect.translateInside(viewportRect).restrictTo(viewportRect).expandToIntegers(); - - this.snapshot = AnimatedZoom.createCanvas(); this.snapshotRect.width = Math.min(this.snapshotRect.width, this.snapshot.width); this.snapshotRect.height = Math.min(this.snapshotRect.height, this.snapshot.height); @@ -74,6 +76,7 @@ function AnimatedZoom(aBrowserView) { if (remote) { this.canvasReady = false; this.snapshot.addEventListener("MozAsyncCanvasRender", this, false); + this.snapshot.pending_render = true; } else { this.canvasReady = true; this.startAnimation(); @@ -82,8 +85,11 @@ function AnimatedZoom(aBrowserView) { AnimatedZoom.prototype.handleEvent = function(aEvent) { if (aEvent.type == "MozAsyncCanvasRender") { - this.snapshot.removeEventListener("MozAsyncCanvasRender", this, false); - if (aEvent.originalTarget == this.snapshot) { + let snapshot = aEvent.originalTarget; + snapshot.pending_render = false; + snapshot.removeEventListener("MozAsyncCanvasRender", this, false); + + if (this.snapshot == snapshot) { this.canvasReady = true; this.startAnimation(); } @@ -150,6 +156,9 @@ AnimatedZoom.prototype.startAnimation = function() AnimatedZoom.prototype.updateTo = function(nextRect) { this.zoomRect = nextRect; + if (this.snapshot.pending_render) + return; + // prepare to draw to the zoom canvas let canvasRect = new Rect(0, 0, Elements.viewBuffer.width, Elements.viewBuffer.height); let ctx = Elements.viewBuffer.getContext("2d");