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 
16 namespace flutter {
17 
18 class VsyncWaiterIOS final : public VsyncWaiter, public VariableRefreshRateReporter {
19  public:
20  explicit VsyncWaiterIOS(const flutter::TaskRunners& task_runners);
21 
22  ~VsyncWaiterIOS() override;
23 
24  // |VariableRefreshRateReporter|
25  double GetRefreshRate() const override;
26 
27  // @brief Snaps the duration to the nearest whole Hz value and provides safe
28  // fallbacks. This ensures we don't introduce frame timing issues due
29  // to floating point error. e.g.
30  // 59.998, 60.004, 59.995, ... --> 60.000
31  //
32  // Additionally, guards against divide-by-zero and non-positive
33  // durations, which can occur on paused/unpaused transitions.
34  //
35  // Visible for testing.
36  static CFTimeInterval SnapDuration(CFTimeInterval duration, double max_refresh_rate);
37 
38  private:
39  // |VsyncWaiter|
40  // Made public for testing.
41  void AwaitVSync() override;
42 
43  private:
44  FlutterVSyncClient* client_;
45  double max_refresh_rate_;
46 
47  FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
48 };
49 
50 } // namespace flutter
51 
52 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_VSYNC_WAITER_IOS_H_
static CFTimeInterval SnapDuration(CFTimeInterval duration, double max_refresh_rate)
double GetRefreshRate() const override
VsyncWaiterIOS(const flutter::TaskRunners &task_runners)