Flutter iOS Embedder
flutter::VsyncWaiterIOS Class Referencefinal

#include <vsync_waiter_ios.h>

Inheritance diagram for flutter::VsyncWaiterIOS:

Public Member Functions

 VsyncWaiterIOS (const flutter::TaskRunners &task_runners)
 
 ~VsyncWaiterIOS () override
 
double GetRefreshRate () const override
 

Static Public Member Functions

static CFTimeInterval SnapDuration (CFTimeInterval duration, double max_refresh_rate)
 

Detailed Description

Definition at line 18 of file vsync_waiter_ios.h.

Constructor & Destructor Documentation

◆ VsyncWaiterIOS()

flutter::VsyncWaiterIOS::VsyncWaiterIOS ( const flutter::TaskRunners &  task_runners)
explicit

Definition at line 18 of file vsync_waiter_ios.mm.

19  : VsyncWaiter(task_runners) {
20  auto vsyncCallback = ^(CFTimeInterval startTime, CFTimeInterval targetTime) {
21  // Compute delay using the same CACurrentMediaTime() clock.
22  CFTimeInterval delay = CACurrentMediaTime() - startTime;
23  if (delay < 0.0) {
24  delay = 0.0;
25  }
26 
27  // Align the start time to the C++ steady_clock used by fml::TimePoint.
28  fml::TimePoint start_time = fml::TimePoint::Now() - fml::TimeDelta::FromSecondsF(delay);
29 
30  // Snap to the nearest whole Hz value to avoid floating point errors.
31  CFTimeInterval duration =
32  VsyncWaiterIOS::SnapDuration(targetTime - startTime, max_refresh_rate_);
33 
34  // Align target time to the C++ steady_clock used by fml::TimePoint.
35  fml::TimePoint target_time = start_time + fml::TimeDelta::FromSecondsF(duration);
36  FireCallback(start_time, target_time, true);
37  };
38  FlutterFMLTaskRunner* uiTaskRunner =
39  [[FlutterFMLTaskRunner alloc] initWithTaskRunner:task_runners_.GetUITaskRunner()];
40  client_ = [[FlutterVSyncClient alloc]
41  initWithTaskRunner:uiTaskRunner
42  isVariableRefreshRateEnabled:FlutterDisplayLinkManager.maxRefreshRateEnabledOnIPhone
43  maxRefreshRate:FlutterDisplayLinkManager.displayRefreshRate
44  callback:vsyncCallback];
45  max_refresh_rate_ = FlutterDisplayLinkManager.displayRefreshRate;
46 }
static CFTimeInterval SnapDuration(CFTimeInterval duration, double max_refresh_rate)

References SnapDuration().

◆ ~VsyncWaiterIOS()

flutter::VsyncWaiterIOS::~VsyncWaiterIOS ( )
override

Definition at line 48 of file vsync_waiter_ios.mm.

48  {
49  // This way, we will get no more callbacks from the display link that holds a weak (non-nilling)
50  // reference to this C++ object.
51  [client_ invalidate];
52 }

Member Function Documentation

◆ GetRefreshRate()

double flutter::VsyncWaiterIOS::GetRefreshRate ( ) const
override

Definition at line 64 of file vsync_waiter_ios.mm.

64  {
65  return client_.refreshRate;
66 }

◆ SnapDuration()

CFTimeInterval flutter::VsyncWaiterIOS::SnapDuration ( CFTimeInterval  duration,
double  max_refresh_rate 
)
static

Definition at line 68 of file vsync_waiter_ios.mm.

68  {
69  if (duration > 0.0) {
70  double roundedRefreshRate = round(1.0 / duration);
71  return 1.0 / roundedRefreshRate;
72  }
73  double fallbackRefreshRate = max_refresh_rate > 0.0 ? max_refresh_rate : 60.0;
74  return 1.0 / fallbackRefreshRate;
75 }

Referenced by VsyncWaiterIOS().


The documentation for this class was generated from the following files: