Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
FlutterVSyncClient Class Reference

A client that wraps a CADisplayLink to deliver synchronized vsync signals. More...

#include <FlutterVSyncClient.h>

Inheritance diagram for FlutterVSyncClient:

Instance Methods

(instancetype) - initWithTaskRunner:isVariableRefreshRateEnabled:maxRefreshRate:callback:
 Initializes the vsync client.
 
(void) - await
 Requests a vsync signal.
 
(void) - pause
 Pauses the vsync client.
 
(void) - invalidate
 Call invalidate before releasing this object to remove from runloops.
 
(void) - setMaxRefreshRate:
 Dynamically configures the display link's frame rate ranges.
 
(void) - onDisplayLink:
 

Properties

double refreshRate
 The current display refresh rate in Hertz, rounded to the nearest integer value.
 
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.
 
CADisplayLink * displayLink
 

Detailed Description

A client that wraps a CADisplayLink to deliver synchronized vsync signals.

        Schedules on-demand vsync signals using a request-and-pause cycle to maintain CPU
        and battery efficiency. Adds additional logic around the wrapped CADisplayLink to
        ensure consistent frame timings both on display link startup and at steady state.

Definition at line 64 of file FlutterVSyncClient.h.

Method Documentation

◆ await

- (void) await

Requests a vsync signal.

        Unpauses the underlying `CADisplayLink` to schedule the next vsync callback.
        Once the vsync callback executes, the client automatically pauses the display
        link if `allowPauseAfterVsync` is `YES`.

Definition at line 21 of file FlutterVSyncClient.mm.

70 {
71 _displayLink.paused = NO;
CADisplayLink * _displayLink

◆ initWithTaskRunner:isVariableRefreshRateEnabled:maxRefreshRate:callback:

- (instancetype) initWithTaskRunner: (FlutterFMLTaskRunner*)  taskRunner
isVariableRefreshRateEnabled: (BOOL isVariableRefreshRateEnabled
maxRefreshRate: (double)  maxRefreshRate
callback: (void(^)(CFTimeInterval startTime, CFTimeInterval targetTime))  callback 

Initializes the vsync client.

Parameters
taskRunnerThe task runner to use for posting tasks.
isVariableRefreshRateEnabledWhether variable refresh rate should be enabled.
maxRefreshRateThe maximum refresh rate to configure the display link with.
callbackThe callback to invoke when a vsync signal is received.

Definition at line 21 of file FlutterVSyncClient.mm.

24 :(FlutterFMLTaskRunner*)taskRunner
25 isVariableRefreshRateEnabled:(BOOL)isVariableRefreshRateEnabled
26 maxRefreshRate:(double)maxRefreshRate
27 callback:(void (^)(CFTimeInterval startTime,
28 CFTimeInterval targetTime))callback {
29 NSAssert(callback, @"callback must not be nil");
30 NSAssert(taskRunner, @"taskRunner must not be nil");
31
32 if (self = [super init]) {
33 _refreshRate = maxRefreshRate;
34 _isVariableRefreshRateEnabled = isVariableRefreshRateEnabled;
35 _allowPauseAfterVsync = YES;
36 _callback = callback;
37 _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)];
38 _displayLink.paused = YES;
39
40 [self setMaxRefreshRate:maxRefreshRate];
41
42 // Capture a weak reference to self to ensure we don't add the display link
43 // to the run loop if the client has already been deallocated.
44 __weak FlutterVSyncClient* weakSelf = self;
45 [taskRunner postTask:^{
46 FlutterVSyncClient* strongSelf = weakSelf;
47 if (strongSelf) {
48 [strongSelf.displayLink addToRunLoop:NSRunLoop.currentRunLoop forMode:NSRunLoopCommonModes];
49 }
50 }];
51 }
52
53 return self;
BOOL _isVariableRefreshRateEnabled
FlutterDesktopBinaryReply callback
void postTask:(void(^ task)(void))
A client that wraps a CADisplayLink to deliver synchronized vsync signals.
int BOOL

◆ invalidate

- (void) invalidate

Call invalidate before releasing this object to remove from runloops.

Definition at line 21 of file FlutterVSyncClient.mm.

128 {
129 [_displayLink invalidate];
130 _displayLink = nil;

◆ onDisplayLink:

- (void) onDisplayLink: (CADisplayLink *)  link

Manually triggers the display link callback for testing without waiting for actual vsyncs.

Provided by category FlutterVSyncClient(Testing).

◆ pause

- (void) pause

Pauses the vsync client.

        Pauses the underlying `CADisplayLink` to stop receiving vsync signals immediately.

Definition at line 21 of file FlutterVSyncClient.mm.

74 {
75 _displayLink.paused = YES;

◆ setMaxRefreshRate:

- (void) setMaxRefreshRate: (double)  refreshRate

Dynamically configures the display link's frame rate ranges.

        Adjusts the target and minimum FPS limits of the display link to support variable
        refresh rates (e.g. on ProMotion displays) when dynamic rate changes are enabled.
Parameters
refreshRateThe target maximum refresh rate in Hz.

Definition at line 21 of file FlutterVSyncClient.mm.

56 :(double)refreshRate {
58 return;
59 }
60 double maxFrameRate = fmax(refreshRate, kDefaultRefreshRate);
61 double minFrameRate = fmax(maxFrameRate / 2, kDefaultRefreshRate);
62 if (@available(iOS 15.0, *)) {
63 _displayLink.preferredFrameRateRange =
64 CAFrameRateRangeMake(minFrameRate, maxFrameRate, maxFrameRate);
65 } else {
66 _displayLink.preferredFramesPerSecond = maxFrameRate;
67 }
static const double kDefaultRefreshRate
double refreshRate
The current display refresh rate in Hertz, rounded to the nearest integer value.

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 85 of file FlutterVSyncClient.h.

◆ displayLink

- (CADisplayLink*) displayLink
readnonatomicassign

The underlying CADisplayLink instance.

Provided by category FlutterVSyncClient(Testing).

Definition at line 20 of file FlutterVSyncClient+Testing.h.

◆ refreshRate

- (double) refreshRate
readnonatomicassign

The current display refresh rate in Hertz, rounded to the nearest integer value.

        This value is calculated during each vsync callback as the inverse of the
        frame duration (the time between the current frame and the target next frame). The
        resulting frequency is rounded to the nearest whole number to smooth out minor
        hardware timestamp variations.

Definition at line 74 of file FlutterVSyncClient.h.

Referenced by flutter::VsyncWaiterIOS::GetRefreshRate().


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