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 <CoreFoundation/CoreFoundation.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 @class FlutterVSyncClient;
15 @class FlutterDisplayLinkManager;
16 
17 namespace flutter {
18 
19 class VsyncWaiterIOS final : public VsyncWaiter, public VariableRefreshRateReporter {
20  public:
21  VsyncWaiterIOS(const flutter::TaskRunners& task_runners,
22  FlutterDisplayLinkManager* display_link_manager);
23 
24  ~VsyncWaiterIOS() override;
25 
26  // |VariableRefreshRateReporter|
27  double GetRefreshRate() const override;
28 
29  // @brief Snaps the duration to the nearest whole Hz value and provides safe
30  // fallbacks. This ensures we don't introduce frame timing issues due
31  // to floating point error. e.g.
32  // 59.998, 60.004, 59.995, ... --> 60.000
33  //
34  // Additionally, guards against divide-by-zero and non-positive
35  // durations, which can occur on paused/unpaused transitions.
36  //
37  // Visible for testing.
38  static CFTimeInterval SnapDuration(CFTimeInterval duration, double max_refresh_rate);
39 
40  // |VsyncWaiter|
41  // Made public for testing.
42  void AwaitVSync() override;
43 
44  // Visible for testing.
45  double GetMaxRefreshRateForTesting() const { return max_refresh_rate_; }
46 
47  // The FlutterEngine sets this flag to true while an event is being dispatched
48  // to the framework.
49  void SetDispatchingEvent(bool dispatching_event) { dispatching_event_ = dispatching_event; }
50 
51  private:
52  FlutterVSyncClient* client_;
53  FlutterDisplayLinkManager* display_link_manager_;
54  double max_refresh_rate_;
55  bool waiting_for_vsync_ = false;
56  bool dispatching_event_ = false;
57 
58  FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
59 };
60 
61 } // namespace flutter
62 
63 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_VSYNC_WAITER_IOS_H_
static CFTimeInterval SnapDuration(CFTimeInterval duration, double max_refresh_rate)
VsyncWaiterIOS(const flutter::TaskRunners &task_runners, FlutterDisplayLinkManager *display_link_manager)
double GetRefreshRate() const override
void AwaitVSync() override
double GetMaxRefreshRateForTesting() const
void SetDispatchingEvent(bool dispatching_event)