1 | "use strict";
|
2 | var constants = require("@pixi/constants"), extensions = require("@pixi/extensions");
|
3 | const _TextureGCSystem = class _TextureGCSystem2 {
|
4 |
|
5 | constructor(renderer) {
|
6 | this.renderer = renderer, this.count = 0, this.checkCount = 0, this.maxIdle = _TextureGCSystem2.defaultMaxIdle, this.checkCountMax = _TextureGCSystem2.defaultCheckCountMax, this.mode = _TextureGCSystem2.defaultMode;
|
7 | }
|
8 | |
9 |
|
10 |
|
11 |
|
12 | postrender() {
|
13 | this.renderer.objectRenderer.renderingToScreen && (this.count++, this.mode !== constants.GC_MODES.MANUAL && (this.checkCount++, this.checkCount > this.checkCountMax && (this.checkCount = 0, this.run())));
|
14 | }
|
15 | |
16 |
|
17 |
|
18 |
|
19 | run() {
|
20 | const tm = this.renderer.texture, managedTextures = tm.managedTextures;
|
21 | let wasRemoved = !1;
|
22 | for (let i = 0; i < managedTextures.length; i++) {
|
23 | const texture = managedTextures[i];
|
24 | texture.resource && this.count - texture.touched > this.maxIdle && (tm.destroyTexture(texture, !0), managedTextures[i] = null, wasRemoved = !0);
|
25 | }
|
26 | if (wasRemoved) {
|
27 | let j = 0;
|
28 | for (let i = 0; i < managedTextures.length; i++)
|
29 | managedTextures[i] !== null && (managedTextures[j++] = managedTextures[i]);
|
30 | managedTextures.length = j;
|
31 | }
|
32 | }
|
33 | |
34 |
|
35 |
|
36 |
|
37 | unload(displayObject) {
|
38 | const tm = this.renderer.texture, texture = displayObject._texture;
|
39 | texture && !texture.framebuffer && tm.destroyTexture(texture);
|
40 | for (let i = displayObject.children.length - 1; i >= 0; i--)
|
41 | this.unload(displayObject.children[i]);
|
42 | }
|
43 | destroy() {
|
44 | this.renderer = null;
|
45 | }
|
46 | };
|
47 | _TextureGCSystem.defaultMode = constants.GC_MODES.AUTO, |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | _TextureGCSystem.defaultMaxIdle = 60 * 60, |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | _TextureGCSystem.defaultCheckCountMax = 60 * 10,
|
60 | _TextureGCSystem.extension = {
|
61 | type: extensions.ExtensionType.RendererSystem,
|
62 | name: "textureGC"
|
63 | };
|
64 | let TextureGCSystem = _TextureGCSystem;
|
65 | extensions.extensions.add(TextureGCSystem);
|
66 | exports.TextureGCSystem = TextureGCSystem;
|
67 |
|