Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::VsyncWaiterIOS Class Referencefinal

#include <vsync_waiter_ios.h>

Inheritance diagram for flutter::VsyncWaiterIOS:
flutter::VsyncWaiter flutter::VariableRefreshRateReporter

Public Member Functions

 VsyncWaiterIOS (const flutter::TaskRunners &task_runners, FlutterDisplayLinkManager *display_link_manager)
 
 ~VsyncWaiterIOS () override
 
double GetRefreshRate () const override
 
void AwaitVSync () override
 
double GetMaxRefreshRateForTesting () const
 
- Public Member Functions inherited from flutter::VsyncWaiter
virtual ~VsyncWaiter ()
 
void AsyncWaitForVsync (const Callback &callback)
 
void ScheduleSecondaryCallback (uintptr_t id, const fml::closure &callback)
 
- Public Member Functions inherited from flutter::VariableRefreshRateReporter
 VariableRefreshRateReporter ()=default
 
 FML_DISALLOW_COPY_AND_ASSIGN (VariableRefreshRateReporter)
 

Static Public Member Functions

static CFTimeInterval SnapDuration (CFTimeInterval duration, double max_refresh_rate)
 

Additional Inherited Members

- Public Types inherited from flutter::VsyncWaiter
using Callback = std::function< void(std::unique_ptr< FrameTimingsRecorder >)>
 
- Protected Member Functions inherited from flutter::VsyncWaiter
 VsyncWaiter (const TaskRunners &task_runners)
 
virtual void AwaitVSyncForSecondaryCallback ()
 
void FireCallback (fml::TimePoint frame_start_time, fml::TimePoint frame_target_time, bool pause_secondary_tasks=true)
 
- Protected Attributes inherited from flutter::VsyncWaiter
const TaskRunners task_runners_
 

Detailed Description

Definition at line 19 of file vsync_waiter_ios.h.

Constructor & Destructor Documentation

◆ VsyncWaiterIOS()

flutter::VsyncWaiterIOS::VsyncWaiterIOS ( const flutter::TaskRunners task_runners,
FlutterDisplayLinkManager *  display_link_manager 
)

Definition at line 18 of file vsync_waiter_ios.mm.

20 : VsyncWaiter(task_runners), display_link_manager_(display_link_manager) {
21 FML_DCHECK(display_link_manager);
22 auto vsyncCallback = ^(CFTimeInterval startTime, CFTimeInterval targetTime) {
23 // Compute delay using the same CACurrentMediaTime() clock.
24 CFTimeInterval delay = CACurrentMediaTime() - startTime;
25 if (delay < 0.0) {
26 delay = 0.0;
27 }
28
29 // Align the start time to the C++ steady_clock used by fml::TimePoint.
31
32 // Snap to the nearest whole Hz value to avoid floating point errors.
33 CFTimeInterval duration =
34 VsyncWaiterIOS::SnapDuration(targetTime - startTime, max_refresh_rate_);
35
36 // Align target time to the C++ steady_clock used by fml::TimePoint.
37 fml::TimePoint target_time = start_time + fml::TimeDelta::FromSecondsF(duration);
38 FireCallback(start_time, target_time, true);
39 };
40 FlutterFMLTaskRunner* uiTaskRunner =
41 [[FlutterFMLTaskRunner alloc] initWithTaskRunner:task_runners_.GetUITaskRunner()];
42 client_ = [[FlutterVSyncClient alloc]
43 initWithTaskRunner:uiTaskRunner
44 isVariableRefreshRateEnabled:display_link_manager_.maxRefreshRateEnabledOnIPhone
45 maxRefreshRate:display_link_manager_.displayRefreshRate
46 callback:vsyncCallback];
47 max_refresh_rate_ = display_link_manager_.displayRefreshRate;
48}
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
VsyncWaiter(const TaskRunners &task_runners)
void FireCallback(fml::TimePoint frame_start_time, fml::TimePoint frame_target_time, bool pause_secondary_tasks=true)
const TaskRunners task_runners_
static CFTimeInterval SnapDuration(CFTimeInterval duration, double max_refresh_rate)
static constexpr TimeDelta FromSecondsF(double seconds)
Definition time_delta.h:53
static TimePoint Now()
Definition time_point.cc:49
FlutterDesktopBinaryReply callback
#define FML_DCHECK(condition)
Definition logging.h:122

References callback, flutter::VsyncWaiter::FireCallback(), FML_DCHECK, fml::TimeDelta::FromSecondsF(), flutter::TaskRunners::GetUITaskRunner(), fml::TimePoint::Now(), SnapDuration(), and flutter::VsyncWaiter::task_runners_.

◆ ~VsyncWaiterIOS()

flutter::VsyncWaiterIOS::~VsyncWaiterIOS ( )
override

Definition at line 50 of file vsync_waiter_ios.mm.

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

Member Function Documentation

◆ AwaitVSync()

void flutter::VsyncWaiterIOS::AwaitVSync ( )
overridevirtual

Implements flutter::VsyncWaiter.

Definition at line 56 of file vsync_waiter_ios.mm.

56 {
57 double new_max_refresh_rate = display_link_manager_.displayRefreshRate;
58 if (fabs(new_max_refresh_rate - max_refresh_rate_) > kRefreshRateDiffToIgnore) {
59 max_refresh_rate_ = new_max_refresh_rate;
60 [client_ setMaxRefreshRate:max_refresh_rate_];
61 }
62 [client_ await];
63}
FLUTTER_ASSERT_ARC static const double kRefreshRateDiffToIgnore

References kRefreshRateDiffToIgnore.

◆ GetMaxRefreshRateForTesting()

double flutter::VsyncWaiterIOS::GetMaxRefreshRateForTesting ( ) const
inline

Definition at line 45 of file vsync_waiter_ios.h.

45{ return max_refresh_rate_; }

◆ GetRefreshRate()

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

Implements flutter::VariableRefreshRateReporter.

Definition at line 66 of file vsync_waiter_ios.mm.

66 {
67 return client_.refreshRate;
68}

◆ SnapDuration()

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

Definition at line 70 of file vsync_waiter_ios.mm.

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

Referenced by VsyncWaiterIOS().


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