Reduce the size of TextLayerRenderTask._textDivProperties
in "regular" text-selection mode
While these changes will obviously not have a significant effect on overall memory usage, it cannot hurt as far as I'm concerned. This patch makes the following changes: - Clear out `_textDivProperties` once rendering is done, since those properties are only necessary to keep alive when *enhanced* text-selection is being used. - Reduce the size of the `_textDivProperties`-entries by default, since a majority of the properties are only relevant when *enhanced* text-selection is being used.
This commit is contained in:
parent
1b20f61b56
commit
4c1b586dd2
@ -118,7 +118,8 @@ function getAscent(fontFamily, ctx) {
|
|||||||
function appendText(task, geom, styles, ctx) {
|
function appendText(task, geom, styles, ctx) {
|
||||||
// Initialize all used properties to keep the caches monomorphic.
|
// Initialize all used properties to keep the caches monomorphic.
|
||||||
const textDiv = document.createElement("span");
|
const textDiv = document.createElement("span");
|
||||||
const textDivProperties = {
|
const textDivProperties = task._enhanceTextSelection
|
||||||
|
? {
|
||||||
angle: 0,
|
angle: 0,
|
||||||
canvasWidth: 0,
|
canvasWidth: 0,
|
||||||
hasText: geom.str !== "",
|
hasText: geom.str !== "",
|
||||||
@ -129,6 +130,12 @@ function appendText(task, geom, styles, ctx) {
|
|||||||
paddingRight: 0,
|
paddingRight: 0,
|
||||||
paddingTop: 0,
|
paddingTop: 0,
|
||||||
scale: 1,
|
scale: 1,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
angle: 0,
|
||||||
|
canvasWidth: 0,
|
||||||
|
hasText: geom.str !== "",
|
||||||
|
hasEOL: geom.hasEOL,
|
||||||
};
|
};
|
||||||
|
|
||||||
task._textDivs.push(textDiv);
|
task._textDivs.push(textDiv);
|
||||||
@ -588,6 +595,11 @@ class TextLayerRenderTask {
|
|||||||
// Always clean-up the temporary canvas once rendering is no longer pending.
|
// Always clean-up the temporary canvas once rendering is no longer pending.
|
||||||
this._capability.promise
|
this._capability.promise
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
if (!this._enhanceTextSelection) {
|
||||||
|
// The `textDiv` properties are no longer needed.
|
||||||
|
this._textDivProperties = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (this._layoutTextCtx) {
|
if (this._layoutTextCtx) {
|
||||||
// Zeroing the width and height cause Firefox to release graphics
|
// Zeroing the width and height cause Firefox to release graphics
|
||||||
// resources immediately, which can greatly reduce memory consumption.
|
// resources immediately, which can greatly reduce memory consumption.
|
||||||
@ -679,8 +691,11 @@ class TextLayerRenderTask {
|
|||||||
const { width } = this._layoutTextCtx.measureText(textDiv.textContent);
|
const { width } = this._layoutTextCtx.measureText(textDiv.textContent);
|
||||||
|
|
||||||
if (width > 0) {
|
if (width > 0) {
|
||||||
textDivProperties.scale = textDivProperties.canvasWidth / width;
|
const scale = textDivProperties.canvasWidth / width;
|
||||||
transform = `scaleX(${textDivProperties.scale})`;
|
if (this._enhanceTextSelection) {
|
||||||
|
textDivProperties.scale = scale;
|
||||||
|
}
|
||||||
|
transform = `scaleX(${scale})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (textDivProperties.angle !== 0) {
|
if (textDivProperties.angle !== 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user