[Pkg-javascript-commits] [pdf.js] 77/116: Enable cancelling of thumbnail drawing

David Prévot taffit at moszumanska.debian.org
Fri Mar 6 16:20:03 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit b7041f81f478d2b89eb640451f303140e72271df
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Sun Jan 25 16:59:57 2015 +0100

    Enable cancelling of thumbnail drawing
    
    This is useful if thumbnails are being rendered when the document is rotated, since it let us abort the current rendering.
---
 web/pdf_thumbnail_view.js | 57 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 16 deletions(-)

diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 26a2a52..9a1e23d 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -130,6 +130,9 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
     },
 
     reset: function PDFThumbnailView_reset() {
+      if (this.renderTask) {
+        this.renderTask.cancel();
+      }
       this.hasImage = false;
       this.resume = null;
       this.renderingState = RenderingStates.INITIAL;
@@ -213,31 +216,53 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
       });
 
       var self = this;
+      function thumbnailDrawCallback(error) {
+        // The renderTask may have been replaced by a new one, so only remove
+        // the reference to the renderTask if it matches the one that is
+        // triggering this callback.
+        if (renderTask === self.renderTask) {
+          self.renderTask = null;
+        }
+        if (error === 'cancelled') {
+          rejectRenderPromise(error);
+          return;
+        }
+        self.renderingState = RenderingStates.FINISHED;
+
+        if (!error) {
+          resolveRenderPromise(undefined);
+        } else {
+          rejectRenderPromise(error);
+        }
+      }
+
       var ctx = this._getPageDrawContext();
       var drawViewport = this.viewport.clone({ scale: this.scale });
+      var renderContinueCallback = function renderContinueCallback(cont) {
+        if (!self.renderingQueue.isHighestPriority(self)) {
+          self.renderingState = RenderingStates.PAUSED;
+          self.resume = function resumeCallback() {
+            self.renderingState = RenderingStates.RUNNING;
+            cont();
+          };
+          return;
+        }
+        cont();
+      };
+
       var renderContext = {
         canvasContext: ctx,
         viewport: drawViewport,
-        continueCallback: function renderContinueCallback(cont) {
-          if (!self.renderingQueue.isHighestPriority(self)) {
-            self.renderingState = RenderingStates.PAUSED;
-            self.resume = function() {
-              self.renderingState = RenderingStates.RUNNING;
-              cont();
-            };
-            return;
-          }
-          cont();
-        }
+        continueCallback: renderContinueCallback
       };
-      this.pdfPage.render(renderContext).promise.then(
+      var renderTask = this.renderTask = this.pdfPage.render(renderContext);
+
+      renderTask.promise.then(
         function pdfPageRenderCallback() {
-          self.renderingState = RenderingStates.FINISHED;
-          resolveRenderPromise(undefined);
+          thumbnailDrawCallback(null);
         },
         function pdfPageRenderError(error) {
-          self.renderingState = RenderingStates.FINISHED;
-          rejectRenderPromise(error);
+          thumbnailDrawCallback(error);
         }
       );
       return promise;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list