Browse Source

Check after each executed command if execution took too long already

Julian Viereck 14 years ago
parent
commit
8991cfad83
  1. 42
      src/canvas.js

42
src/canvas.js

@ -64,10 +64,6 @@ var CanvasGraphics = (function canvasGraphics() {
// before it stops and shedules a continue of execution. // before it stops and shedules a continue of execution.
var kExecutionTime = 50; var kExecutionTime = 50;
// Number of IR commands to execute before checking
// if we execute longer then `kExecutionTime`.
var kExecutionTimeCheck = 500;
function constructor(canvasCtx, objs) { function constructor(canvasCtx, objs) {
this.ctx = canvasCtx; this.ctx = canvasCtx;
this.current = new CanvasExtraState(); this.current = new CanvasExtraState();
@ -112,31 +108,33 @@ var CanvasGraphics = (function canvasGraphics() {
var i = executionStartIdx || 0; var i = executionStartIdx || 0;
var argsArrayLen = argsArray.length; var argsArrayLen = argsArray.length;
// Sometimes the IRQueue to execute is empty.
if (argsArrayLen == i) {
return i;
}
var executionEndIdx; var executionEndIdx;
var startTime = Date.now(); var startTime = Date.now();
var objs = this.objs; var objs = this.objs;
do { while (true) {
executionEndIdx = Math.min(argsArrayLen, i + kExecutionTimeCheck); if (fnArray[i] !== 'dependency') {
this[fnArray[i]].apply(this, argsArray[i]);
for (i; i < executionEndIdx; i++) { } else {
if (fnArray[i] !== 'dependency') { var deps = argsArray[i];
this[fnArray[i]].apply(this, argsArray[i]); for (var n = 0, nn = deps.length; n < nn; n++) {
} else { var depObjId = deps[n];
var deps = argsArray[i];
for (var n = 0, nn = deps.length; n < nn; n++) { // If the promise isn't resolved yet, add the continueCallback
var depObjId = deps[n]; // to the promise and bail out.
if (!objs.isResolved(depObjId)) {
// If the promise isn't resolved yet, add the continueCallback objs.get(depObjId, continueCallback);
// to the promise and bail out. return i;
if (!objs.isResolved(depObjId)) {
objs.get(depObjId, continueCallback);
return i;
}
} }
} }
} }
i++;
// If the entire IRQueue was executed, stop as were done. // If the entire IRQueue was executed, stop as were done.
if (i == argsArrayLen) { if (i == argsArrayLen) {
@ -153,7 +151,7 @@ var CanvasGraphics = (function canvasGraphics() {
// If the IRQueue isn't executed completly yet OR the execution time // If the IRQueue isn't executed completly yet OR the execution time
// was short enough, do another execution round. // was short enough, do another execution round.
} while (true); }
}, },
endDrawing: function canvasGraphicsEndDrawing() { endDrawing: function canvasGraphicsEndDrawing() {

Loading…
Cancel
Save