Skip to content

Commit

Permalink
Merge pull request #10601 from Snuffleupagus/TextLayer-canvas-cleanup
Browse files Browse the repository at this point in the history
Zero the width/height of the temporary canvas used during `TextLayer` rendering
  • Loading branch information
timvandermeij authored Mar 1, 2019
2 parents 34022d2 + d7d1f23 commit 7208f0f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,34 @@ var renderTextLayer = (function renderTextLayerClosure() {
this._capability = createPromiseCapability();
this._renderTimer = null;
this._bounds = [];

// Always clean-up the temporary canvas once rendering is no longer pending.
this._capability.promise.finally(() => {
if (this._layoutTextCtx) {
// Zeroing the width and height cause Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
this._layoutTextCtx.canvas.width = 0;
this._layoutTextCtx.canvas.height = 0;
this._layoutTextCtx = null;
}
});
}
TextLayerRenderTask.prototype = {
get promise() {
return this._capability.promise;
},

cancel: function TextLayer_cancel() {
this._canceled = true;
if (this._reader) {
this._reader.cancel(new AbortException('text layer task cancelled'));
this._reader.cancel(new AbortException('TextLayer task cancelled.'));
this._reader = null;
}
this._canceled = true;
if (this._renderTimer !== null) {
clearTimeout(this._renderTimer);
this._renderTimer = null;
}
this._capability.reject('canceled');
this._capability.reject(new Error('TextLayer task cancelled.'));
},

_processItems(items, styleCache) {
Expand Down

0 comments on commit 7208f0f

Please sign in to comment.