Stop the execution if it takes longer then a certain amount of time and reshedule it

This commit is contained in:
Julian Viereck 2011-09-09 09:58:44 -07:00
parent a228753414
commit 32ae879219

71
pdf.js
View File

@ -4849,6 +4849,11 @@ function ScratchCanvas(width, height) {
} }
var CanvasGraphics = (function() { var CanvasGraphics = (function() {
var kScalePrecision = 50;
var kRasterizerMin = 14;
var kExecutionTime = 50;
var kExecutionTimeCheck = 500;
function constructor(canvasCtx, imageCanvas) { function constructor(canvasCtx, imageCanvas) {
this.ctx = canvasCtx; this.ctx = canvasCtx;
this.current = new CanvasExtraState(); this.current = new CanvasExtraState();
@ -4885,34 +4890,54 @@ var CanvasGraphics = (function() {
this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height); this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height);
}, },
executeIRQueue: function(codeIR, startIdx, continueCallback) { executeIRQueue: function(codeIR, executionStartIdx, continueCallback) {
var argsArray = codeIR.argsArray; var argsArray = codeIR.argsArray;
var fnArray = codeIR.fnArray; var fnArray = codeIR.fnArray;
var i = startIdx || 0; var i = executionStartIdx || 0;
var length = argsArray.length; var argsArrayLen = argsArray.length;
for (i; i < length; i++) {
if (fnArray[i] !== "dependency") { var executionEndIdx;
this[fnArray[i]].apply(this, argsArray[i]); var startTime = Date.now();
} else {
var deps = argsArray[i]; do {
for (var n = 0; n < deps.length; n++) { executionEndIdx = Math.min(argsArrayLen, i + kExecutionTimeCheck);
var depObjId = deps[n];
var promise; for (i; i < executionEndIdx; i++) {
if (!Objects[depObjId]) { if (fnArray[i] !== "dependency") {
promise = Objects[depObjId] = new Promise(); this[fnArray[i]].apply(this, argsArray[i]);
} else { } else {
promise = Objects[depObjId]; var deps = argsArray[i];
} for (var n = 0; n < deps.length; n++) {
// If the promise isn't resolved yet, add the continueCallback var depObjId = deps[n];
// to the promise and bail out. var promise;
if (!promise.isResolved) { if (!Objects[depObjId]) {
promise.then(continueCallback); promise = Objects[depObjId] = new Promise();
return i; } else {
promise = Objects[depObjId];
}
// If the promise isn't resolved yet, add the continueCallback
// to the promise and bail out.
if (!promise.isResolved) {
promise.then(continueCallback);
return i;
}
} }
} }
} }
}
return i; // If the entire IRQueue was executed, stop as were done.
if (i == argsArrayLen) {
return i;
}
// If the execution took longer then a certain amount of time, shedule
// to continue exeution after a short delay.
else if ((Date.now() - startTime) > kExecutionTime) {
setTimeout(continueCallback, 0);
return i;
}
// If the IRQueue isn't executed completly yet OR the execution time
// was short enough, do another execution round.
} while (true);
}, },
endDrawing: function() { endDrawing: function() {