Merge pull request #10601 from Snuffleupagus/TextLayer-canvas-cleanup

Zero the width/height of the temporary canvas used during `TextLayer` rendering
This commit is contained in:
Tim van der Meij 2019-03-01 19:47:03 +01:00 committed by GitHub
commit 7208f0ff67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -490,6 +490,17 @@ var renderTextLayer = (function renderTextLayerClosure() {
this._capability = createPromiseCapability(); this._capability = createPromiseCapability();
this._renderTimer = null; this._renderTimer = null;
this._bounds = []; 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 = { TextLayerRenderTask.prototype = {
get promise() { get promise() {
@ -497,16 +508,16 @@ var renderTextLayer = (function renderTextLayerClosure() {
}, },
cancel: function TextLayer_cancel() { cancel: function TextLayer_cancel() {
this._canceled = true;
if (this._reader) { if (this._reader) {
this._reader.cancel(new AbortException('text layer task cancelled')); this._reader.cancel(new AbortException('TextLayer task cancelled.'));
this._reader = null; this._reader = null;
} }
this._canceled = true;
if (this._renderTimer !== null) { if (this._renderTimer !== null) {
clearTimeout(this._renderTimer); clearTimeout(this._renderTimer);
this._renderTimer = null; this._renderTimer = null;
} }
this._capability.reject('canceled'); this._capability.reject(new Error('TextLayer task cancelled.'));
}, },
_processItems(items, styleCache) { _processItems(items, styleCache) {