mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #4763 from yurydelendik/canvas-rAF
Uses rAF to interrupt the operator list execution
This commit is contained in:
commit
fd4fc89213
4 changed files with 28 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue