On iOS report the preferred frames per second to tools via service protocol. (flutter/engine#11006)

This commit is contained in:
Chinmay Garde 2019-08-14 16:47:57 -07:00 committed by GitHub
parent afab9f34b1
commit 3ad272ccda
2 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,9 @@ class VsyncWaiterIOS final : public VsyncWaiter {
// |VsyncWaiter|
void AwaitVSync() override;
// |VsyncWaiter|
float GetDisplayRefreshRate() const override;
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
};

View File

@ -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"
@ -23,6 +24,17 @@
- (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 VsyncWaiterIOS::AwaitVSync() {
[client_.get() await];
}
// |VsyncWaiter|
float VsyncWaiterIOS::GetDisplayRefreshRate() const {
return [client_.get() displayRefreshRate];
}
} // namespace flutter
@implementation VSyncClient {
@ -73,6 +90,25 @@ void VsyncWaiterIOS::AwaitVSync() {
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;
}