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/fml/memory/weak_ptr.h"
12 #include "flutter/fml/platform/darwin/scoped_nsobject.h"
13 #include "flutter/shell/common/variable_refresh_rate_reporter.h"
14 #include "flutter/shell/common/vsync_waiter.h"
15 
16 @interface DisplayLinkManager : NSObject
17 
18 // Whether the max refresh rate on iPhone Pro-motion devices are enabled.
19 // This reflects the value of `CADisableMinimumFrameDurationOnPhone` in the
20 // info.plist file.
21 //
22 // Note on iPads that support Pro-motion, the max refresh rate is always enabled.
23 @property(class, nonatomic, readonly) BOOL maxRefreshRateEnabledOnIPhone;
24 
25 //------------------------------------------------------------------------------
26 /// @brief The display refresh rate used for reporting purposes. The engine does not care
27 /// about this for frame scheduling. It is only used by tools for instrumentation. The
28 /// engine uses the duration field of the link per frame for frame scheduling.
29 ///
30 /// @attention Do not use the this call in frame scheduling. It is only meant for reporting.
31 ///
32 /// @return The refresh rate in frames per second.
33 ///
34 + (double)displayRefreshRate;
35 
36 @end
37 
38 @interface VSyncClient : NSObject
39 
40 //------------------------------------------------------------------------------
41 /// @brief Default value is YES. Vsync client will pause vsync callback after receiving
42 /// a vsync signal. Setting this property to NO can avoid this and vsync client
43 /// will trigger vsync callback continuously.
44 ///
45 ///
46 /// @param allowPauseAfterVsync Allow vsync client to pause after receiving a vsync signal.
47 ///
48 @property(nonatomic, assign) BOOL allowPauseAfterVsync;
49 
50 - (instancetype)initWithTaskRunner:(fml::RefPtr<fml::TaskRunner>)task_runner
51  callback:(flutter::VsyncWaiter::Callback)callback;
52 
53 - (void)await;
54 
55 - (void)pause;
56 
57 - (void)invalidate;
58 
59 - (double)getRefreshRate;
60 
61 - (void)setMaxRefreshRate:(double)refreshRate;
62 
63 @end
64 
65 namespace flutter {
66 
67 class VsyncWaiterIOS final : public VsyncWaiter, public VariableRefreshRateReporter {
68  public:
69  explicit VsyncWaiterIOS(const flutter::TaskRunners& task_runners);
70 
71  ~VsyncWaiterIOS() override;
72 
73  // |VariableRefreshRateReporter|
74  double GetRefreshRate() const override;
75 
76  // Made public for testing.
77  fml::scoped_nsobject<VSyncClient> GetVsyncClient() const;
78 
79  // |VsyncWaiter|
80  // Made public for testing.
81  void AwaitVSync() override;
82 
83  private:
84  fml::scoped_nsobject<VSyncClient> client_;
85  double max_refresh_rate_;
86 
87  FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
88 };
89 
90 } // namespace flutter
91 
92 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_VSYNC_WAITER_IOS_H_
flutter::VsyncWaiterIOS
Definition: vsync_waiter_ios.h:67
flutter
Definition: accessibility_bridge.h:28
VSyncClient
Definition: vsync_waiter_ios.h:38