1 | var FrameHandlerImpl = (function (_super) {
|
2 | __extends(FrameHandlerImpl, _super);
|
3 | function FrameHandlerImpl() {
|
4 | return _super !== null && _super.apply(this, arguments) || this;
|
5 | }
|
6 | FrameHandlerImpl.initWithOwner = function (owner) {
|
7 | var handler = FrameHandlerImpl.new();
|
8 | handler._owner = owner;
|
9 | return handler;
|
10 | };
|
11 | FrameHandlerImpl.prototype.handleFrame = function (sender) {
|
12 | var _a;
|
13 | var owner = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.deref();
|
14 | if (owner) {
|
15 | owner._handleFrame(sender);
|
16 | }
|
17 | };
|
18 | FrameHandlerImpl.ObjCExposedMethods = {
|
19 | handleFrame: { returns: interop.types.void, params: [CADisplayLink] },
|
20 | };
|
21 | return FrameHandlerImpl;
|
22 | }(NSObject));
|
23 | export class FPSCallback {
|
24 | constructor(onFrame) {
|
25 | this.onFrame = onFrame;
|
26 | this.impl = FrameHandlerImpl.initWithOwner(new WeakRef(this));
|
27 | this.displayLink = CADisplayLink.displayLinkWithTargetSelector(this.impl, 'handleFrame');
|
28 | this.displayLink.paused = true;
|
29 | this.displayLink.addToRunLoopForMode(NSRunLoop.currentRunLoop, NSDefaultRunLoopMode);
|
30 |
|
31 |
|
32 | this.displayLink.addToRunLoopForMode(NSRunLoop.currentRunLoop, UITrackingRunLoopMode);
|
33 | }
|
34 | start() {
|
35 | if (this.running) {
|
36 | return;
|
37 | }
|
38 | this.running = true;
|
39 | this.displayLink.paused = false;
|
40 | }
|
41 | stop() {
|
42 | if (!this.running) {
|
43 | return;
|
44 | }
|
45 | this.displayLink.paused = true;
|
46 | this.running = false;
|
47 | }
|
48 | _handleFrame(sender) {
|
49 | if (!this.running) {
|
50 | return;
|
51 | }
|
52 |
|
53 | this.onFrame(sender.timestamp * 1000);
|
54 | }
|
55 | }
|
56 |
|
\ | No newline at end of file |