Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class VsyncWaiterIOS final : public VsyncWaiter {
// |VsyncWaiter|
void AwaitVSync() override;

// |VsyncWaiter|
float GetDisplayRefreshRate() const override;

FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
};

Expand Down
36 changes: 36 additions & 0 deletions shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <Foundation/Foundation.h>
#include <QuartzCore/CADisplayLink.h>
#include <UIKit/UIKit.h>
#include <mach/mach_time.h>

#include "flutter/common/task_runners.h"
Expand All @@ -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 {
Expand All @@ -45,6 +57,11 @@ - (void)invalidate;
[client_.get() await];
}

// |VsyncWaiter|
float VsyncWaiterIOS::GetDisplayRefreshRate() const {
return [client_.get() displayRefreshRate];
}

} // namespace flutter

@implementation VSyncClient {
Expand Down Expand Up @@ -73,6 +90,25 @@ - (instancetype)initWithTaskRunner:(fml::RefPtr<fml::TaskRunner>)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;
}
Expand Down