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