diff --git a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h index 29097da8f7ad9..7cd01d2dfad5f 100644 --- a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h +++ b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h @@ -26,6 +26,9 @@ class VsyncWaiterIOS final : public VsyncWaiter { // |VsyncWaiter| void AwaitVSync() override; + // |VsyncWaiter| + float GetDisplayRefreshRate() const override; + FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS); }; diff --git a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm index f16c656c075ef..8fbe25c8690d6 100644 --- a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm +++ b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm @@ -8,6 +8,7 @@ #include #include +#include #include #include "flutter/common/task_runners.h" @@ -23,6 +24,17 @@ - (void)await; - (void)invalidate; +//------------------------------------------------------------------------------ +/// @brief The display refresh rate used for reporting purposes. The engine does not care +/// about this for frame scheduling. It is only used by tools for instrumentation. The +/// engine uses the duration field of the link per frame for frame scheduling. +/// +/// @attention Do not use the this call in frame scheduling. It is only meant for reporting. +/// +/// @return The refresh rate in frames per second. +/// +- (float)displayRefreshRate; + @end namespace flutter { @@ -45,6 +57,11 @@ - (void)invalidate; [client_.get() await]; } +// |VsyncWaiter| +float VsyncWaiterIOS::GetDisplayRefreshRate() const { + return [client_.get() displayRefreshRate]; +} + } // namespace flutter @implementation VSyncClient { @@ -73,6 +90,25 @@ - (instancetype)initWithTaskRunner:(fml::RefPtr)task_runner return self; } +- (float)displayRefreshRate { + if (@available(iOS 10.3, *)) { + auto preferredFPS = display_link_.get().preferredFramesPerSecond; // iOS 10.0 + + // From Docs: + // The default value for preferredFramesPerSecond is 0. When this value is 0, the preferred + // frame rate is equal to the maximum refresh rate of the display, as indicated by the + // maximumFramesPerSecond property. + + if (preferredFPS != 0) { + return preferredFPS; + } + + return [UIScreen mainScreen].maximumFramesPerSecond; // iOS 10.3 + } else { + return 60.0; + } +} + - (void)await { display_link_.get().paused = NO; }