[Pkg-javascript-commits] [pdf.js] 105/210: Uses rAF to interrupt the operator list execution
David Prévot
taffit at moszumanska.debian.org
Thu Jun 5 14:21:07 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch upstream
in repository pdf.js.
commit c5eb058b09de57fa06777a66a60c8126eadb53ba
Author: Yury Delendik <ydelendik at mozilla.com>
Date: Fri May 9 07:00:47 2014 -0500
Uses rAF to interrupt the operator list execution
---
src/display/api.js | 16 ++++++++++++----
src/display/canvas.js | 8 +++-----
web/compatibility.js | 12 ++++++++++++
web/viewer.js | 10 +---------
4 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/display/api.js b/src/display/api.js
index 977fb8c..004411a 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -1271,6 +1271,10 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
this.graphicsReady = false;
this.cancelled = false;
this.capability = createPromiseCapability();
+ // caching this-bound methods
+ this._continueBound = this._continue.bind(this);
+ this._scheduleNextBound = this._scheduleNext.bind(this);
+ this._nextBound = this._next.bind(this);
}
InternalRenderTask.prototype = {
@@ -1309,7 +1313,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
operatorListChanged: function InternalRenderTask_operatorListChanged() {
if (!this.graphicsReady) {
if (!this.graphicsReadyCallback) {
- this.graphicsReadyCallback = this._continue.bind(this);
+ this.graphicsReadyCallback = this._continueBound;
}
return;
}
@@ -1330,19 +1334,23 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
return;
}
if (this.params.continueCallback) {
- this.params.continueCallback(this._next.bind(this));
+ this.params.continueCallback(this._scheduleNextBound);
} else {
- this._next();
+ this._scheduleNext();
}
},
+ _scheduleNext: function InternalRenderTask__scheduleNext() {
+ window.requestAnimationFrame(this._nextBound);
+ },
+
_next: function InternalRenderTask__next() {
if (this.cancelled) {
return;
}
this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
this.operatorListIdx,
- this._continue.bind(this),
+ this._continueBound,
this.stepper);
if (this.operatorListIdx === this.operatorList.argsArray.length) {
this.running = false;
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 350dfb9..505e105 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -746,7 +746,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var commonObjs = this.commonObjs;
var objs = this.objs;
var fnId;
- var deferred = Promise.resolve();
while (true) {
if (stepper && i === stepper.nextBreakPoint) {
@@ -784,11 +783,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
return i;
}
- // If the execution took longer then a certain amount of time, schedule
- // to continue exeution after a short delay.
- // However, this is only possible if a 'continueCallback' is passed in.
+ // If the execution took longer then a certain amount of time and
+ // `continueCallback` is specified, interrupt the execution.
if (continueCallback && Date.now() > endTime) {
- deferred.then(continueCallback);
+ continueCallback();
return i;
}
diff --git a/web/compatibility.js b/web/compatibility.js
index 31b6356..0e2dba1 100644
--- a/web/compatibility.js
+++ b/web/compatibility.js
@@ -564,3 +564,15 @@ if (typeof PDFJS === 'undefined') {
console.log('Unable to create polyfill for localStorage');
}
})();
+
+(function checkRequestAnimationFrame() {
+ if ('requestAnimationFrame' in window) {
+ return;
+ }
+ window.requestAnimationFrame =
+ window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
+ window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
+ (function fakeRequestAnimationFrame(callback) {
+ window.setTimeout(callback, 20);
+ });
+})();
diff --git a/web/viewer.js b/web/viewer.js
index b1c5162..755d54b 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -2410,16 +2410,8 @@ window.addEventListener('afterprint', function afterPrint(evt) {
(function animationStartedClosure() {
// The offsetParent is not set until the pdf.js iframe or object is visible.
// Waiting for first animation.
- var requestAnimationFrame = window.requestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.oRequestAnimationFrame ||
- window.msRequestAnimationFrame ||
- function startAtOnce(callback) { callback(); };
PDFView.animationStartedPromise = new Promise(function (resolve) {
- requestAnimationFrame(function onAnimationFrame() {
- resolve();
- });
+ window.requestAnimationFrame(resolve);
});
})();
--
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