Flutter iOS Embedder
vsync_waiter_ios.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_VSYNC_WAITER_IOS_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_VSYNC_WAITER_IOS_H_
7 
8 #include <QuartzCore/CADisplayLink.h>
9 
10 #include "flutter/fml/macros.h"
11 #include "flutter/shell/common/variable_refresh_rate_reporter.h"
12 #include "flutter/shell/common/vsync_waiter.h"
13 
14 //------------------------------------------------------------------------------
15 /// @brief Info.plist key enabling the full range of ProMotion refresh rates for CADisplayLink
16 /// callbacks and CAAnimation animations in the app.
17 ///
18 /// @see
19 /// https://developer.apple.com/documentation/quartzcore/optimizing_promotion_refresh_rates_for_iphone_13_pro_and_ipad_pro#3885321
20 ///
21 extern NSString* const kCADisableMinimumFrameDurationOnPhoneKey;
22 
23 @interface DisplayLinkManager : NSObject
24 
25 //------------------------------------------------------------------------------
26 /// @brief Whether the max refresh rate on iPhone ProMotion devices are enabled. This reflects
27 /// the value of `CADisableMinimumFrameDurationOnPhone` in the info.plist file. On iPads
28 /// that support ProMotion, the max refresh rate is always enabled.
29 ///
30 /// @return YES if the max refresh rate on ProMotion devices is enabled.
31 ///
32 @property(class, nonatomic, readonly) BOOL maxRefreshRateEnabledOnIPhone;
33 
34 //------------------------------------------------------------------------------
35 /// @brief The display refresh rate used for reporting purposes. The engine does not care
36 /// about this for frame scheduling. It is only used by tools for instrumentation. The
37 /// engine uses the duration field of the link per frame for frame scheduling.
38 ///
39 /// @attention Do not use the this call in frame scheduling. It is only meant for reporting.
40 ///
41 /// @return The refresh rate in frames per second.
42 ///
43 @property(class, nonatomic, readonly) double displayRefreshRate;
44 
45 @end
46 
47 @interface VSyncClient : NSObject
48 
49 //------------------------------------------------------------------------------
50 /// @brief Default value is YES. Vsync client will pause vsync callback after receiving
51 /// a vsync signal. Setting this property to NO can avoid this and vsync client
52 /// will trigger vsync callback continuously.
53 ///
54 ///
55 /// @param allowPauseAfterVsync Allow vsync client to pause after receiving a vsync signal.
56 ///
57 @property(nonatomic, assign) BOOL allowPauseAfterVsync;
58 
59 - (instancetype)initWithTaskRunner:(fml::RefPtr<fml::TaskRunner>)task_runner
60  callback:(flutter::VsyncWaiter::Callback)callback;
61 
62 - (void)await;
63 
64 - (void)pause;
65 
66 //------------------------------------------------------------------------------
67 /// @brief Call invalidate before releasing this object to remove from runloops.
68 ///
69 - (void)invalidate;
70 
71 - (void)setMaxRefreshRate:(double)refreshRate;
72 
73 @end
74 
75 namespace flutter {
76 
77 class VsyncWaiterIOS final : public VsyncWaiter, public VariableRefreshRateReporter {
78  public:
79  explicit VsyncWaiterIOS(const flutter::TaskRunners& task_runners);
80 
81  ~VsyncWaiterIOS() override;
82 
83  // |VariableRefreshRateReporter|
84  double GetRefreshRate() const override;
85 
86  // |VsyncWaiter|
87  // Made public for testing.
88  void AwaitVSync() override;
89 
90  private:
91  VSyncClient* client_;
92  double max_refresh_rate_;
93 
94  FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
95 };
96 
97 } // namespace flutter
98 
99 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_VSYNC_WAITER_IOS_H_
flutter::VsyncWaiterIOS
Definition: vsync_waiter_ios.h:77
flutter
Definition: accessibility_bridge.h:27
kCADisableMinimumFrameDurationOnPhoneKey
NSString *const kCADisableMinimumFrameDurationOnPhoneKey
Info.plist key enabling the full range of ProMotion refresh rates for CADisplayLink callbacks and CAA...
Definition: vsync_waiter_ios.mm:21
VSyncClient
Definition: vsync_waiter_ios.h:47