Skip to content

Commit

Permalink
iOS: Extract constant for CADisableMinimumFrameDurationOnPhone (flutt…
Browse files Browse the repository at this point in the history
…er#56659)

In our vsync waiter and related tests, we hardcode the "CADisableMinimumFrameDurationOnPhone" key in several places. This pulls those into a constant kCADisableMinimumFrameDurationOnPhoneKey declared in the vsync waiter header, which is non-public, and uses that instead.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
cbracken authored Nov 17, 2024
1 parent e3e1619 commit 99e332b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ - (void)testLifeCycleNotificationCancelledInvalidResumed {

- (void)testSetupKeyboardAnimationVsyncClientWillCreateNewVsyncClientForFlutterViewController {
id bundleMock = OCMPartialMock([NSBundle mainBundle]);
OCMStub([bundleMock objectForInfoDictionaryKey:@"CADisableMinimumFrameDurationOnPhone"])
OCMStub([bundleMock objectForInfoDictionaryKey:kCADisableMinimumFrameDurationOnPhoneKey])
.andReturn(@YES);
id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]];
double maxFrameRate = 120;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)testSetCorrectVariableRefreshRates {
auto thread_task_runner = CreateNewThread("VsyncWaiterIosTest");
auto callback = [](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {};
id bundleMock = OCMPartialMock([NSBundle mainBundle]);
OCMStub([bundleMock objectForInfoDictionaryKey:@"CADisableMinimumFrameDurationOnPhone"])
OCMStub([bundleMock objectForInfoDictionaryKey:kCADisableMinimumFrameDurationOnPhoneKey])
.andReturn(@YES);
id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]];
double maxFrameRate = 120;
Expand All @@ -75,7 +75,7 @@ - (void)testDoNotSetVariableRefreshRatesIfCADisableMinimumFrameDurationOnPhoneIs
auto thread_task_runner = CreateNewThread("VsyncWaiterIosTest");
auto callback = [](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {};
id bundleMock = OCMPartialMock([NSBundle mainBundle]);
OCMStub([bundleMock objectForInfoDictionaryKey:@"CADisableMinimumFrameDurationOnPhone"])
OCMStub([bundleMock objectForInfoDictionaryKey:kCADisableMinimumFrameDurationOnPhoneKey])
.andReturn(@NO);
id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]];
double maxFrameRate = 120;
Expand Down
21 changes: 16 additions & 5 deletions shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@
#include "flutter/shell/common/variable_refresh_rate_reporter.h"
#include "flutter/shell/common/vsync_waiter.h"

//------------------------------------------------------------------------------
/// @brief Info.plist key enabling the full range of ProMotion refresh rates for CADisplayLink
/// callbacks and CAAnimation animations in the app.
///
/// @see
/// https://developer.apple.com/documentation/quartzcore/optimizing_promotion_refresh_rates_for_iphone_13_pro_and_ipad_pro#3885321
///
extern NSString* const kCADisableMinimumFrameDurationOnPhoneKey;

@interface DisplayLinkManager : NSObject

// Whether the max refresh rate on iPhone Pro-motion devices are enabled.
// This reflects the value of `CADisableMinimumFrameDurationOnPhone` in the
// info.plist file.
//
// Note on iPads that support Pro-motion, the max refresh rate is always enabled.
//------------------------------------------------------------------------------
/// @brief Whether the max refresh rate on iPhone ProMotion devices are enabled. This reflects
/// the value of `CADisableMinimumFrameDurationOnPhone` in the info.plist file. On iPads
/// that support ProMotion, the max refresh rate is always enabled.
///
/// @return YES if the max refresh rate on ProMotion devices is enabled.
///
@property(class, nonatomic, readonly) BOOL maxRefreshRateEnabledOnIPhone;

//------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

FLUTTER_ASSERT_ARC

NSString* const kCADisableMinimumFrameDurationOnPhoneKey = @"CADisableMinimumFrameDurationOnPhone";

@interface VSyncClient ()
@property(nonatomic, assign, readonly) double refreshRate;
@end
Expand Down Expand Up @@ -170,7 +172,7 @@ - (void)onDisplayLink:(CADisplayLink*)link {
}

+ (BOOL)maxRefreshRateEnabledOnIPhone {
return [[NSBundle.mainBundle objectForInfoDictionaryKey:@"CADisableMinimumFrameDurationOnPhone"]
return [[NSBundle.mainBundle objectForInfoDictionaryKey:kCADisableMinimumFrameDurationOnPhoneKey]
boolValue];
}

Expand Down

0 comments on commit 99e332b

Please sign in to comment.