Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
FlutterVSyncClient.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVSYNCCLIENT_H_
6#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVSYNCCLIENT_H_
7
8#include <QuartzCore/CADisplayLink.h>
9
10//------------------------------------------------------------------------------
11/// @brief Info.plist key enabling the full range of ProMotion refresh rates for CADisplayLink
12/// callbacks and CAAnimation animations in the app.
13///
14/// @see
15/// https://developer.apple.com/documentation/quartzcore/optimizing_promotion_refresh_rates_for_iphone_13_pro_and_ipad_pro#3885321
16///
17extern NSString* const kCADisableMinimumFrameDurationOnPhoneKey;
18
20
21//------------------------------------------------------------------------------
22/// @brief A manager type that queries display characteristics, such as high refresh rate
23/// capabilities.
24///
25/// Provides static properties to check whether dynamic refresh rates are supported
26/// on the device and to get the display's maximum refresh rate (either the hardware
27/// maximum or the maximum configured by the user).
28///
29NS_SWIFT_NAME(DisplayLinkManager)
30@interface FlutterDisplayLinkManager : NSObject
31
32//------------------------------------------------------------------------------
33/// @brief Whether the max refresh rate on iPhone ProMotion devices are enabled. This reflects
34/// the value of `CADisableMinimumFrameDurationOnPhone` in the info.plist file. On iPads
35/// that support ProMotion, the max refresh rate is always enabled.
36///
37/// @return YES if the max refresh rate on ProMotion devices is enabled.
38///
39@property(class, nonatomic, readonly) BOOL maxRefreshRateEnabledOnIPhone;
40
41//------------------------------------------------------------------------------
42/// @brief The maximum display refresh rate used for reporting purposes. This is intended to
43/// return either the hardware maximum refresh rate or the maximum configured by the
44/// user (e.g. via an Info.plist setting or custom configuration). The engine does not
45/// care about this for frame scheduling. It is only used by tools for instrumentation.
46/// The engine uses the duration field of the link per frame for frame scheduling.
47///
48/// @attention Do not use this call in frame scheduling. It is only meant for reporting.
49///
50/// @return The maximum refresh rate in frames per second.
51///
52@property(class, nonatomic, readonly) double displayRefreshRate;
53
54@end
55
56//------------------------------------------------------------------------------
57/// @brief A client that wraps a `CADisplayLink` to deliver synchronized vsync signals.
58///
59/// Schedules on-demand vsync signals using a request-and-pause cycle to maintain CPU
60/// and battery efficiency. Adds additional logic around the wrapped CADisplayLink to
61/// ensure consistent frame timings both on display link startup and at steady state.
62///
63NS_SWIFT_NAME(VSyncClient)
64@interface FlutterVSyncClient : NSObject
65
66//------------------------------------------------------------------------------
67/// @brief The current display refresh rate in Hertz, rounded to the nearest integer value.
68///
69/// This value is calculated during each vsync callback as the inverse of the
70/// frame duration (the time between the current frame and the target next frame). The
71/// resulting frequency is rounded to the nearest whole number to smooth out minor
72/// hardware timestamp variations.
73///
74@property(nonatomic, assign, readonly) double refreshRate;
75
76//------------------------------------------------------------------------------
77/// @brief Default value is YES. Vsync client will pause vsync callback after receiving
78/// a vsync signal. Setting this property to NO can avoid this and vsync client
79/// will trigger vsync callback continuously.
80///
81///
82/// @param allowPauseAfterVsync Allow vsync client to pause after receiving a vsync
83/// signal.
84///
85@property(nonatomic, assign) BOOL allowPauseAfterVsync;
86
87//------------------------------------------------------------------------------
88/// @brief Initializes the vsync client.
89///
90/// @param taskRunner The task runner to use for posting tasks.
91/// @param isVariableRefreshRateEnabled Whether variable refresh rate should be enabled.
92/// @param maxRefreshRate The maximum refresh rate to configure the display link
93/// with.
94/// @param callback The callback to invoke when a vsync signal is received.
95///
96- (instancetype)initWithTaskRunner:(FlutterFMLTaskRunner*)taskRunner
97 isVariableRefreshRateEnabled:(BOOL)isVariableRefreshRateEnabled
98 maxRefreshRate:(double)maxRefreshRate
99 callback:(void (^)(CFTimeInterval startTime,
100 CFTimeInterval targetTime))callback;
101
102//------------------------------------------------------------------------------
103/// @brief Requests a vsync signal.
104///
105/// Unpauses the underlying `CADisplayLink` to schedule the next vsync callback.
106/// Once the vsync callback executes, the client automatically pauses the display
107/// link if `allowPauseAfterVsync` is `YES`.
108///
109- (void)await;
110
111//------------------------------------------------------------------------------
112/// @brief Pauses the vsync client.
113///
114/// Pauses the underlying `CADisplayLink` to stop receiving vsync signals immediately.
115///
116- (void)pause;
117
118//------------------------------------------------------------------------------
119/// @brief Call invalidate before releasing this object to remove from runloops.
120///
121- (void)invalidate;
122
123//------------------------------------------------------------------------------
124/// @brief Dynamically configures the display link's frame rate ranges.
125///
126/// Adjusts the target and minimum FPS limits of the display link to support variable
127/// refresh rates (e.g. on ProMotion displays) when dynamic rate changes are enabled.
128///
129/// @param refreshRate The target maximum refresh rate in Hz.
130///
131- (void)setMaxRefreshRate:(double)refreshRate;
132
133@end
134
135#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVSYNCCLIENT_H_
NSString *const kCADisableMinimumFrameDurationOnPhoneKey
Info.plist key enabling the full range of ProMotion refresh rates for CADisplayLink callbacks and CAA...
A client that wraps a CADisplayLink to deliver synchronized vsync signals.
int BOOL