92 lines
4.6 KiB
JavaScript
92 lines
4.6 KiB
JavaScript
shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$text_html$HTMLTextPipe = function(global, require, module, exports) {
|
|
global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
|
|
var Texture = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$Texture"), GCManagedHash = require("module$node_modules$pixi_DOT_js$lib$utils$data$GCManagedHash"), updateTextBounds = require("module$node_modules$pixi_DOT_js$lib$scene$text$utils$updateTextBounds"), BatchableHTMLText = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$BatchableHTMLText");
|
|
"use strict";
|
|
class HTMLTextPipe {
|
|
constructor(renderer) {
|
|
this._renderer = renderer;
|
|
renderer.runners.resolutionChange.add(this);
|
|
this._managedTexts = new GCManagedHash.GCManagedHash({renderer, type:"renderable", onUnload:this.onTextUnload.bind(this), name:"htmlText"});
|
|
}
|
|
resolutionChange() {
|
|
for (const key in this._managedTexts.items) {
|
|
const text = this._managedTexts.items[key];
|
|
if (text?._autoResolution) {
|
|
text.onViewUpdate();
|
|
}
|
|
}
|
|
}
|
|
validateRenderable(htmlText) {
|
|
return this._getGpuText(htmlText).currentKey !== htmlText.styleKey ? !0 : !1;
|
|
}
|
|
addRenderable(htmlText, instructionSet) {
|
|
const batchableHTMLText = this._getGpuText(htmlText);
|
|
if (htmlText._didTextUpdate) {
|
|
const resolution = htmlText._autoResolution ? this._renderer.resolution : htmlText.resolution;
|
|
batchableHTMLText.currentKey === htmlText.styleKey && htmlText.resolution === resolution || this._updateGpuText(htmlText).catch(e => {
|
|
console.error(e);
|
|
});
|
|
htmlText._didTextUpdate = !1;
|
|
updateTextBounds.updateTextBounds(batchableHTMLText, htmlText);
|
|
}
|
|
this._renderer.renderPipes.batch.addToBatch(batchableHTMLText, instructionSet);
|
|
}
|
|
updateRenderable(htmlText) {
|
|
htmlText = this._getGpuText(htmlText);
|
|
htmlText._batcher.updateElement(htmlText);
|
|
}
|
|
async _updateGpuText(htmlText) {
|
|
htmlText._didTextUpdate = !1;
|
|
const batchableHTMLText = this._getGpuText(htmlText);
|
|
if (!batchableHTMLText.generatingTexture) {
|
|
var oldTexturePromise = batchableHTMLText.texturePromise;
|
|
batchableHTMLText.texturePromise = null;
|
|
batchableHTMLText.generatingTexture = !0;
|
|
htmlText._resolution = htmlText._autoResolution ? this._renderer.resolution : htmlText.resolution;
|
|
var texturePromise = this._renderer.htmlText.getTexturePromise(htmlText);
|
|
oldTexturePromise && (texturePromise = texturePromise.finally(() => {
|
|
this._renderer.htmlText.decreaseReferenceCount(batchableHTMLText.currentKey);
|
|
this._renderer.htmlText.returnTexturePromise(oldTexturePromise);
|
|
}));
|
|
batchableHTMLText.texturePromise = texturePromise;
|
|
batchableHTMLText.currentKey = htmlText.styleKey;
|
|
batchableHTMLText.texture = await texturePromise;
|
|
if (texturePromise = htmlText.renderGroup || htmlText.parentRenderGroup) {
|
|
texturePromise.structureDidChange = !0;
|
|
}
|
|
batchableHTMLText.generatingTexture = !1;
|
|
updateTextBounds.updateTextBounds(batchableHTMLText, htmlText);
|
|
}
|
|
}
|
|
_getGpuText(htmlText) {
|
|
return htmlText._gpuData[this._renderer.uid] || this.initGpuText(htmlText);
|
|
}
|
|
initGpuText(htmlText) {
|
|
const batchableHTMLText = new BatchableHTMLText.BatchableHTMLText();
|
|
batchableHTMLText.renderable = htmlText;
|
|
batchableHTMLText.transform = htmlText.groupTransform;
|
|
batchableHTMLText.texture = Texture.Texture.EMPTY;
|
|
batchableHTMLText.bounds = {minX:0, maxX:1, minY:0, maxY:0};
|
|
batchableHTMLText.roundPixels = this._renderer._roundPixels | htmlText._roundPixels;
|
|
htmlText._resolution = htmlText._autoResolution ? this._renderer.resolution : htmlText.resolution;
|
|
htmlText._gpuData[this._renderer.uid] = batchableHTMLText;
|
|
this._managedTexts.add(htmlText);
|
|
return batchableHTMLText;
|
|
}
|
|
onTextUnload(text) {
|
|
if (text = text._gpuData[this._renderer.uid]) {
|
|
var {htmlText} = this._renderer;
|
|
null === htmlText.getReferenceCount(text.currentKey) ? htmlText.returnTexturePromise(text.texturePromise) : htmlText.decreaseReferenceCount(text.currentKey);
|
|
}
|
|
}
|
|
destroy() {
|
|
this._managedTexts.destroy();
|
|
this._renderer = null;
|
|
}
|
|
}
|
|
HTMLTextPipe.extension = {type:[global.ExtensionType.WebGLPipes, global.ExtensionType.WebGPUPipes, global.ExtensionType.CanvasPipes], name:"htmlText"};
|
|
exports.HTMLTextPipe = HTMLTextPipe;
|
|
};
|
|
|
|
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$text_html$HTMLTextPipe.js.map
|