mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Preventing from using the same canvas for multiple render()
This commit is contained in:
parent
0ca6132ad2
commit
24f14d44cb
2 changed files with 45 additions and 1 deletions
|
@ -901,7 +901,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
stats.time('Rendering');
|
||||
internalRenderTask.initializeGraphics(transparency);
|
||||
internalRenderTask.operatorListChanged();
|
||||
}, complete);
|
||||
}).catch(complete);
|
||||
|
||||
return renderTask;
|
||||
},
|
||||
|
@ -2103,6 +2103,7 @@ var RenderTask = (function RenderTaskClosure() {
|
|||
* @ignore
|
||||
*/
|
||||
var InternalRenderTask = (function InternalRenderTaskClosure() {
|
||||
let canvasInRendering = new WeakMap();
|
||||
|
||||
function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
|
||||
pageNumber, canvasFactory) {
|
||||
|
@ -2125,6 +2126,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||
this._continueBound = this._continue.bind(this);
|
||||
this._scheduleNextBound = this._scheduleNext.bind(this);
|
||||
this._nextBound = this._next.bind(this);
|
||||
this._canvas = params.canvasContext.canvas;
|
||||
}
|
||||
|
||||
InternalRenderTask.prototype = {
|
||||
|
@ -2132,6 +2134,16 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||
initializeGraphics:
|
||||
function InternalRenderTask_initializeGraphics(transparency) {
|
||||
|
||||
if (this._canvas) {
|
||||
if (canvasInRendering.has(this._canvas)) {
|
||||
throw new Error(
|
||||
'Cannot use the same canvas during multiple render() operations. ' +
|
||||
'Use different canvas or ensure previous operations were ' +
|
||||
'cancelled or completed.');
|
||||
}
|
||||
canvasInRendering.set(this._canvas, this);
|
||||
}
|
||||
|
||||
if (this.cancelled) {
|
||||
return;
|
||||
}
|
||||
|
@ -2163,6 +2175,9 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||
cancel: function InternalRenderTask_cancel() {
|
||||
this.running = false;
|
||||
this.cancelled = true;
|
||||
if (this._canvas) {
|
||||
canvasInRendering.delete(this._canvas);
|
||||
}
|
||||
|
||||
if ((typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PDFJS_NEXT')) ||
|
||||
getDefaultSetting('pdfjsNext')) {
|
||||
|
@ -2223,6 +2238,9 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||
this.running = false;
|
||||
if (this.operatorList.lastChunk) {
|
||||
this.gfx.endDrawing();
|
||||
if (this._canvas) {
|
||||
canvasInRendering.delete(this._canvas);
|
||||
}
|
||||
this.callback();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue