libpag 4.5.3 → 4.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/libpag.cjs.js +5409 -5528
- package/lib/libpag.cjs.js.map +1 -1
- package/lib/libpag.esm.js +5409 -5528
- package/lib/libpag.esm.js.map +1 -1
- package/lib/libpag.min.js +1 -1
- package/lib/libpag.min.js.map +1 -1
- package/lib/libpag.umd.js +5409 -5528
- package/lib/libpag.umd.js.map +1 -1
- package/lib/libpag.wasm +0 -0
- package/package.json +10 -1
- package/src/.pag.wasm-mt.md5 +1 -1
- package/src/.pag.wasm.md5 +1 -1
- package/src/binding.ts +1 -0
- package/src/constant.ts +1 -1
- package/src/core/video-reader.ts +277 -261
- package/src/interfaces.ts +14 -7
- package/src/pag-composition.ts +185 -165
- package/src/pag-player.ts +390 -309
- package/src/pag-view.ts +11 -9
- package/src/types.ts +7 -1
- package/src/utils/mixin.ts +1 -0
- package/src/video-reader-manager.ts +140 -0
- package/src/wasm/libpag.js +7 -6
- package/src/wasm/libpag.wasm +0 -0
- package/src/wasm-mt/libpag.js +2 -18
- package/src/wasm-mt/libpag.wasm +0 -0
- package/src/wechat/binding.ts +1 -0
- package/src/wechat/pag-view.ts +6 -1
- package/src/wechat/scaler-context.ts +32 -2
- package/src/wechat/video-reader.ts +37 -11
- package/types/web/src/constant.d.ts +1 -1
- package/types/web/src/core/video-reader.d.ts +3 -1
- package/types/web/src/interfaces.d.ts +7 -1
- package/types/web/src/pag-player.d.ts +12 -1
- package/types/web/src/pag-view.d.ts +1 -1
- package/types/web/src/types.d.ts +7 -0
- package/types/web/src/video-reader-manager.d.ts +60 -0
package/src/pag-player.ts
CHANGED
|
@@ -1,313 +1,394 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import type {
|
|
10
|
-
import {PAGScaleMode, Rect, VecArray} from './types';
|
|
11
|
-
import type {
|
|
1
|
+
import {PAGModule} from './pag-module';
|
|
2
|
+
import {PAGFile} from './pag-file';
|
|
3
|
+
import {PAGSurface} from './pag-surface';
|
|
4
|
+
import {destroyVerify} from './utils/decorators';
|
|
5
|
+
import {getWasmIns, layer2typeLayer, proxyVector} from './utils/type-utils';
|
|
6
|
+
import {Matrix} from './core/matrix';
|
|
7
|
+
|
|
8
|
+
import {PAGComposition} from './pag-composition';
|
|
9
|
+
import type {PAGLayer} from './pag-layer';
|
|
10
|
+
import {type PAGScaleMode, type Rect, VecArray} from './types';
|
|
11
|
+
import type {VideoReader} from './interfaces';
|
|
12
|
+
import {VideoReaderManager} from "./video-reader-manager";
|
|
12
13
|
|
|
13
14
|
@destroyVerify
|
|
14
15
|
export class PAGPlayer {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
16
|
+
public static create(): PAGPlayer {
|
|
17
|
+
const wasmIns = new PAGModule._PAGPlayer();
|
|
18
|
+
if (!wasmIns) throw new Error('Create PAGPlayer fail!');
|
|
19
|
+
return new PAGPlayer(wasmIns);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public wasmIns;
|
|
23
|
+
public isDestroyed = false;
|
|
24
|
+
public videoReaders: VideoReader[] = [];
|
|
25
|
+
|
|
26
|
+
protected pagComposition: PAGComposition | null = null;
|
|
27
|
+
protected videoReaderManager: VideoReaderManager | null = null;
|
|
28
|
+
|
|
29
|
+
public constructor(wasmIns: any) {
|
|
30
|
+
this.wasmIns = wasmIns;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Set the progress of play position, the value is from 0.0 to 1.0.
|
|
35
|
+
*/
|
|
36
|
+
public setProgress(progress: number): void {
|
|
37
|
+
this.wasmIns._setProgress(progress);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Apply all pending changes to the target surface immediately. Returns true if the content has
|
|
42
|
+
* changed.
|
|
43
|
+
*/
|
|
44
|
+
public async flush() {
|
|
45
|
+
PAGModule.currentPlayer = this;
|
|
46
|
+
await this.prepareVideoFrame();
|
|
47
|
+
return PAGModule.webAssemblyQueue.exec<boolean>(async () => {
|
|
48
|
+
const res = await this.wasmIns._flush();
|
|
49
|
+
PAGModule.currentPlayer = null;
|
|
50
|
+
return res;
|
|
51
|
+
}, this.wasmIns);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* [Internal] Apply all pending changes to the target surface immediately. Returns true if the content has
|
|
56
|
+
* changed.
|
|
57
|
+
*/
|
|
58
|
+
public async flushInternal(callback: (res: boolean) => void) {
|
|
59
|
+
PAGModule.currentPlayer = this;
|
|
60
|
+
await this.prepareVideoFrame();
|
|
61
|
+
const res = await PAGModule.webAssemblyQueue.exec<boolean>(async () => {
|
|
62
|
+
const res = await this.wasmIns._flush();
|
|
63
|
+
PAGModule.currentPlayer = null;
|
|
64
|
+
callback(res);
|
|
65
|
+
return res;
|
|
66
|
+
}, this.wasmIns);
|
|
67
|
+
// Check if any video reader has error.
|
|
68
|
+
for (const videoReader of this.videoReaders) {
|
|
69
|
+
const error = await videoReader.getError();
|
|
70
|
+
if (error !== null) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The duration of current composition in microseconds.
|
|
79
|
+
*/
|
|
80
|
+
public duration(): number {
|
|
81
|
+
return this.wasmIns._duration() as number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the current progress of play position, the value is from 0.0 to 1.0.
|
|
86
|
+
*/
|
|
87
|
+
public getProgress(): number {
|
|
88
|
+
return this.wasmIns._getProgress() as number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the current frame.
|
|
93
|
+
*/
|
|
94
|
+
public currentFrame(): number {
|
|
95
|
+
return this.wasmIns._currentFrame() as number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* If set to false, the player skips rendering for video composition.
|
|
100
|
+
*/
|
|
101
|
+
public videoEnabled(): boolean {
|
|
102
|
+
return this.wasmIns._videoEnabled() as boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Set the value of videoEnabled property.
|
|
107
|
+
*/
|
|
108
|
+
public setVideoEnabled(enabled: boolean): void {
|
|
109
|
+
this.wasmIns._setVideoEnabled(enabled);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* If set to true, PAGPlayer caches an internal bitmap representation of the static content for each
|
|
114
|
+
* layer. This caching can increase performance for layers that contain complex vector content. The
|
|
115
|
+
* execution speed can be significantly faster depending on the complexity of the content, but it
|
|
116
|
+
* requires extra graphics memory. The default value is true.
|
|
117
|
+
*/
|
|
118
|
+
public cacheEnabled(): boolean {
|
|
119
|
+
return this.wasmIns._cacheEnabled() as boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Set the value of cacheEnabled property.
|
|
124
|
+
*/
|
|
125
|
+
public setCacheEnabled(enabled: boolean): void {
|
|
126
|
+
this.wasmIns._setCacheEnabled(enabled);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* This value defines the scale factor for internal graphics caches, ranges from 0.0 to 1.0. The
|
|
131
|
+
* scale factors less than 1.0 may result in blurred output, but it can reduce the usage of graphics
|
|
132
|
+
* memory which leads to better performance. The default value is 1.0.
|
|
133
|
+
*/
|
|
134
|
+
public cacheScale(): number {
|
|
135
|
+
return this.wasmIns._cacheScale() as number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Set the value of cacheScale property.
|
|
140
|
+
*/
|
|
141
|
+
public setCacheScale(value: number): void {
|
|
142
|
+
this.wasmIns._setCacheScale(value);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The maximum frame rate for rendering, ranges from 1 to 60. If set to a value less than the actual
|
|
147
|
+
* frame rate from composition, it drops frames but increases performance. Otherwise, it has no
|
|
148
|
+
* effect. The default value is 60.
|
|
149
|
+
*/
|
|
150
|
+
public maxFrameRate(): number {
|
|
151
|
+
return this.wasmIns._maxFrameRate() as number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Set the maximum frame rate for rendering.
|
|
156
|
+
*/
|
|
157
|
+
public setMaxFrameRate(value: number): void {
|
|
158
|
+
this.wasmIns._setMaxFrameRate(value);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Returns the current scale mode.
|
|
163
|
+
*/
|
|
164
|
+
public scaleMode(): PAGScaleMode {
|
|
165
|
+
return this.wasmIns._scaleMode() as PAGScaleMode;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Specifies the rule of how to scale the pag content to fit the surface size. The matrix
|
|
170
|
+
* changes when this method is called.
|
|
171
|
+
*/
|
|
172
|
+
public setScaleMode(value: PAGScaleMode): void {
|
|
173
|
+
this.wasmIns._setScaleMode(value);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Set the PAGSurface object for PAGPlayer to render onto.
|
|
178
|
+
*/
|
|
179
|
+
public setSurface(pagSurface: PAGSurface | null): void {
|
|
180
|
+
this.wasmIns._setSurface(getWasmIns(pagSurface));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
*
|
|
185
|
+
* Returns the current PAGComposition for PAGPlayer to render as content.
|
|
186
|
+
*/
|
|
187
|
+
public getComposition(): PAGComposition {
|
|
188
|
+
const wasmIns = this.wasmIns._getComposition();
|
|
189
|
+
if (!wasmIns) throw new Error('Get composition fail!');
|
|
190
|
+
if (wasmIns._isPAGFile()) {
|
|
191
|
+
return new PAGFile(wasmIns);
|
|
192
|
+
}
|
|
193
|
+
return new PAGComposition(wasmIns);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* Sets a new PAGComposition for PAGPlayer to render as content.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
public setComposition(pagComposition: PAGComposition | null) {
|
|
202
|
+
this.destroyVideoReaderManager();
|
|
203
|
+
this.pagComposition = pagComposition;
|
|
204
|
+
this.wasmIns._setComposition(getWasmIns(pagComposition));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns the PAGSurface object for PAGPlayer to render onto.
|
|
209
|
+
*/
|
|
210
|
+
public getSurface(): PAGSurface {
|
|
211
|
+
const wasmIns = this.wasmIns._getSurface();
|
|
212
|
+
if (!wasmIns) throw new Error('Get surface fail!');
|
|
213
|
+
return new PAGSurface(wasmIns);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Returns a copy of current matrix.
|
|
218
|
+
*/
|
|
219
|
+
public matrix(): Matrix {
|
|
220
|
+
const wasmIns = this.wasmIns._matrix();
|
|
221
|
+
if (!wasmIns) throw new Error('Get matrix fail!');
|
|
222
|
+
return new Matrix(wasmIns);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Set the transformation which will be applied to the composition. The scaleMode property
|
|
227
|
+
* will be set to PAGScaleMode::None when this method is called.
|
|
228
|
+
*/
|
|
229
|
+
public setMatrix(matrix: Matrix) {
|
|
230
|
+
this.wasmIns._setMatrix(matrix.wasmIns);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Set the progress of play position to next frame. It is applied only when the composition is not
|
|
235
|
+
* null.
|
|
236
|
+
*/
|
|
237
|
+
public nextFrame() {
|
|
238
|
+
this.wasmIns._nextFrame();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Set the progress of play position to previous frame. It is applied only when the composition is
|
|
243
|
+
* not null.
|
|
244
|
+
*/
|
|
245
|
+
public preFrame() {
|
|
246
|
+
this.wasmIns._preFrame();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* If true, PAGPlayer clears the whole content of PAGSurface before drawing anything new to it.
|
|
251
|
+
* The default value is true.
|
|
252
|
+
*/
|
|
253
|
+
public autoClear(): boolean {
|
|
254
|
+
return this.wasmIns._autoClear() as boolean;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Sets the autoClear property.
|
|
259
|
+
*/
|
|
260
|
+
public setAutoClear(value: boolean) {
|
|
261
|
+
this.wasmIns._setAutoClear(value);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Returns a rectangle that defines the original area of the layer, which is not transformed by
|
|
266
|
+
* the matrix.
|
|
267
|
+
*/
|
|
268
|
+
public getBounds(pagLayer: PAGLayer): Rect {
|
|
269
|
+
return this.wasmIns._getBounds(pagLayer.wasmIns) as Rect;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Returns an array of layers that lie under the specified point. The point is in pixels and from
|
|
274
|
+
*
|
|
275
|
+
* this PAGComposition's local coordinates.
|
|
276
|
+
*/
|
|
277
|
+
public getLayersUnderPoint(localX: number, localY: number) {
|
|
278
|
+
const wasmIns = this.wasmIns._getLayersUnderPoint(localX, localY);
|
|
279
|
+
if (!wasmIns) throw new Error(`Get layers under point, x: ${localX} y:${localY} fail!`);
|
|
280
|
+
const layerArray = VecArray.create();
|
|
281
|
+
for (const wasmIn of wasmIns) {
|
|
282
|
+
layerArray.push(layer2typeLayer(wasmIn));
|
|
283
|
+
}
|
|
284
|
+
return layerArray;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Evaluates the PAGLayer to see if it overlaps or intersects with the specified point. The point
|
|
289
|
+
*
|
|
290
|
+
* is in the coordinate space of the PAGSurface, not the PAGComposition that contains the
|
|
291
|
+
* PAGLayer. It always returns false if the PAGLayer or its parent (or parent's parent...) has not
|
|
292
|
+
* been added to this PAGPlayer. The pixelHitTest parameter indicates whether or not to check
|
|
293
|
+
* against the actual pixels of the object (true) or the bounding box (false). Returns true if the
|
|
294
|
+
* PAGLayer overlaps or intersects with the specified point.
|
|
295
|
+
*/
|
|
296
|
+
public hitTestPoint(pagLayer: PAGLayer, surfaceX: number, surfaceY: number, pixelHitTest = false): boolean {
|
|
297
|
+
return this.wasmIns._hitTestPoint(pagLayer.wasmIns, surfaceX, surfaceY, pixelHitTest) as boolean;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The time cost by rendering in microseconds.
|
|
302
|
+
*/
|
|
303
|
+
public renderingTime(): number {
|
|
304
|
+
return this.wasmIns._renderingTime() as number;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The time cost by image decoding in microseconds.
|
|
309
|
+
*/
|
|
310
|
+
public imageDecodingTime(): number {
|
|
311
|
+
return this.wasmIns._imageDecodingTime() as number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* The time cost by presenting in microseconds.
|
|
316
|
+
*/
|
|
317
|
+
public presentingTime(): number {
|
|
318
|
+
return this.wasmIns._presentingTime() as number;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* The memory cost by graphics in bytes.
|
|
323
|
+
*/
|
|
324
|
+
public graphicsMemory(): number {
|
|
325
|
+
return this.wasmIns._graphicsMemory() as number;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Prepares the player for the next flush() call. It collects all CPU tasks from the current
|
|
330
|
+
* progress of the composition and runs them asynchronously in parallel. It is usually used for
|
|
331
|
+
* speeding up the first frame rendering.
|
|
332
|
+
*/
|
|
333
|
+
public prepare(): Promise<void> {
|
|
334
|
+
return PAGModule.webAssemblyQueue.exec(async () => {
|
|
335
|
+
PAGModule.currentPlayer = this;
|
|
336
|
+
await this.wasmIns._prepare();
|
|
337
|
+
PAGModule.currentPlayer = null;
|
|
338
|
+
}, this.wasmIns);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
public destroy() {
|
|
342
|
+
this.destroyVideoReaderManager();
|
|
343
|
+
this.wasmIns.delete();
|
|
344
|
+
this.isDestroyed = true;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Link VideoReader to PAGPlayer.
|
|
349
|
+
*/
|
|
350
|
+
public linkVideoReader(videoReader: VideoReader) {
|
|
351
|
+
this.videoReaders.push(videoReader);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Unlink VideoReader from PAGPlayer.
|
|
356
|
+
*/
|
|
357
|
+
public unlinkVideoReader(videoReader: VideoReader) {
|
|
358
|
+
const index = this.videoReaders.indexOf(videoReader);
|
|
359
|
+
if (index !== -1) {
|
|
360
|
+
this.videoReaders.splice(index, 1);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Prepares the video frame for the current composition before rendering.
|
|
366
|
+
*/
|
|
367
|
+
private async prepareVideoFrame() {
|
|
368
|
+
if (PAGModule._useSoftwareDecoder !== undefined && !PAGModule._useSoftwareDecoder) {
|
|
369
|
+
if (this.pagComposition !== null) {
|
|
370
|
+
if (this.videoReaderManager === null && VideoReaderManager.HasVideo(this.pagComposition?.wasmIns)) {
|
|
371
|
+
this.videoReaderManager = await VideoReaderManager.make(this.pagComposition?.wasmIns);
|
|
372
|
+
PAGModule.videoReaderManager = this.videoReaderManager;
|
|
373
|
+
}
|
|
374
|
+
if (this.videoReaderManager !== null) {
|
|
375
|
+
await this.videoReaderManager.prepareTargetFrame();
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
console.error("PAGComposition is null. A valid PAG file is missing.");
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Destroys the video reader manager and releases all associated resources.
|
|
385
|
+
*/
|
|
386
|
+
public destroyVideoReaderManager() {
|
|
387
|
+
if (this.videoReaderManager !== null) {
|
|
388
|
+
this.videoReaderManager.destroy();
|
|
389
|
+
this.videoReaderManager = null;
|
|
390
|
+
PAGModule.videoReaderManage = null;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
313
394
|
}
|