Flutter Engine
The Flutter Engine
Instance Methods | Properties | List of all members
VSyncClient Class Reference

#import <vsync_waiter_ios.h>

Inheritance diagram for VSyncClient:

Instance Methods

(instancetype) - initWithTaskRunner:callback:
 
(void) - await
 
(void) - pause
 
(void) - invalidate
 Call invalidate before releasing this object to remove from runloops. More...
 
(void) - setMaxRefreshRate:
 
(void) - onDisplayLink: [implementation]
 
(CADisplayLink *) - getDisplayLink [implementation]
 

Properties

BOOL allowPauseAfterVsync
 Default value is YES. Vsync client will pause vsync callback after receiving a vsync signal. Setting this property to NO can avoid this and vsync client will trigger vsync callback continuously. More...
 
double refreshRate [implementation]
 

Detailed Description

Definition at line 36 of file vsync_waiter_ios.h.

Method Documentation

◆ await

- (void) await

Definition at line 66 of file vsync_waiter_ios.mm.

106 {
107 _displayLink.paused = NO;
108}
CADisplayLink * _displayLink

◆ getDisplayLink

- (CADisplayLink *) getDisplayLink
implementation

Provided by category VSyncClient(Testing).

Definition at line 66 of file vsync_waiter_ios.mm.

142 {
143 return _displayLink;
144}

◆ initWithTaskRunner:callback:

- (instancetype) initWithTaskRunner: (fml::RefPtr<fml::TaskRunner>)  task_runner
callback: (flutter::VsyncWaiter::Callback callback 

Definition at line 66 of file vsync_waiter_ios.mm.

71 self = [super init];
72
73 if (self) {
75 _allowPauseAfterVsync = YES;
76 _callback = std::move(callback);
77 _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)];
78 _displayLink.paused = YES;
79
80 [self setMaxRefreshRate:DisplayLinkManager.displayRefreshRate];
81
82 // Strongly retain the the captured link until it is added to the runloop.
83 CADisplayLink* localDisplayLink = _displayLink;
84 task_runner->PostTask([localDisplayLink]() {
85 [localDisplayLink addToRunLoop:NSRunLoop.currentRunLoop forMode:NSRunLoopCommonModes];
86 });
87 }
88
89 return self;
90}
std::function< void(std::unique_ptr< FrameTimingsRecorder >)> Callback
Definition: vsync_waiter.h:26
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
double displayRefreshRate
The display refresh rate used for reporting purposes. The engine does not care about this for frame s...

◆ invalidate

- (void) invalidate

Call invalidate before releasing this object to remove from runloops.

Definition at line 66 of file vsync_waiter_ios.mm.

137 {
138 [_displayLink invalidate];
139 _displayLink = nil; // Break retain cycle.
140}

◆ onDisplayLink:

- (void) onDisplayLink: (CADisplayLink*)  link
implementation

Provided by category VSyncClient(Testing).

Definition at line 66 of file vsync_waiter_ios.mm.

114 :(CADisplayLink*)link {
115 CFTimeInterval delay = CACurrentMediaTime() - link.timestamp;
116 fml::TimePoint frame_start_time = fml::TimePoint::Now() - fml::TimeDelta::FromSecondsF(delay);
117
118 CFTimeInterval duration = link.targetTimestamp - link.timestamp;
119 fml::TimePoint frame_target_time = frame_start_time + fml::TimeDelta::FromSecondsF(duration);
120
121 TRACE_EVENT2_INT("flutter", "PlatformVsync", "frame_start_time",
122 frame_start_time.ToEpochDelta().ToMicroseconds(), "frame_target_time",
123 frame_target_time.ToEpochDelta().ToMicroseconds());
124
125 std::unique_ptr<flutter::FrameTimingsRecorder> recorder =
126 std::make_unique<flutter::FrameTimingsRecorder>();
127
128 _refreshRate = round(1 / (frame_target_time - frame_start_time).ToSecondsF());
129
130 recorder->RecordVsync(frame_start_time, frame_target_time);
131 if (_allowPauseAfterVsync) {
132 link.paused = YES;
133 }
134 _callback(std::move(recorder));
135}
static void round(SkPoint *p)
constexpr int64_t ToMicroseconds() const
Definition: time_delta.h:62
TimeDelta ToEpochDelta() const
Definition: time_point.h:52
static TimePoint Now()
Definition: time_point.cc:49
double duration
Definition: examples.cpp:30
def link(from_root, to_root)
Definition: dart_pkg.py:44
Definition: ascii_trie.cc:9
#define TRACE_EVENT2_INT(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
Definition: trace_event.h:202

◆ pause

- (void) pause

Definition at line 66 of file vsync_waiter_ios.mm.

110 {
111 _displayLink.paused = YES;
112}

◆ setMaxRefreshRate:

- (void) setMaxRefreshRate: (double)  refreshRate

Definition at line 66 of file vsync_waiter_ios.mm.

92 :(double)refreshRate {
94 return;
95 }
96 double maxFrameRate = fmax(refreshRate, 60);
97 double minFrameRate = fmax(maxFrameRate / 2, 60);
98 if (@available(iOS 15.0, *)) {
99 _displayLink.preferredFrameRateRange =
100 CAFrameRateRangeMake(minFrameRate, maxFrameRate, maxFrameRate);
101 } else {
102 _displayLink.preferredFramesPerSecond = maxFrameRate;
103 }
104}

Property Documentation

◆ allowPauseAfterVsync

- (BOOL) allowPauseAfterVsync
readwritenonatomicassign

Default value is YES. Vsync client will pause vsync callback after receiving a vsync signal. Setting this property to NO can avoid this and vsync client will trigger vsync callback continuously.

Parameters
allowPauseAfterVsyncAllow vsync client to pause after receiving a vsync signal.

Definition at line 46 of file vsync_waiter_ios.h.

◆ refreshRate

- (double) refreshRate
readnonatomicassignimplementation

Definition at line 22 of file vsync_waiter_ios.mm.


The documentation for this class was generated from the following files: