This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Set iOS default frame rate to screen max. #29797
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ae2d3ff
defualt to 120
452e9fe
fix tests
a285d49
format
9eeee4f
gn format
1f420f4
review
4c3dabc
cleanup
f4fd0d6
fix license
400c2e2
release
019a38d
format
683f740
use category to hide testing only method
844f919
fix typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import <OCMock/OCMock.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
#include "flutter/fml/thread.h" | ||
|
||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" | ||
#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h" | ||
|
||
FLUTTER_ASSERT_NOT_ARC | ||
namespace { | ||
fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) { | ||
auto thread = std::make_unique<fml::Thread>(name); | ||
auto runner = thread->GetTaskRunner(); | ||
return runner; | ||
} | ||
} | ||
|
||
@interface VSyncClient (Testing) | ||
|
||
- (CADisplayLink*)getDisplayLink; | ||
|
||
@end | ||
|
||
@interface VsyncWaiterIosTest : XCTestCase | ||
@end | ||
|
||
@implementation VsyncWaiterIosTest | ||
|
||
- (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"]) | ||
.andReturn(@YES); | ||
id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; | ||
double maxFrameRate = 120; | ||
[[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; | ||
|
||
VSyncClient* vsyncClient = [[[VSyncClient alloc] initWithTaskRunner:thread_task_runner | ||
callback:callback] autorelease]; | ||
CADisplayLink* link = [vsyncClient getDisplayLink]; | ||
if (@available(iOS 15.0, *)) { | ||
XCTAssertEqual(link.preferredFrameRateRange.maximum, maxFrameRate); | ||
XCTAssertEqual(link.preferredFrameRateRange.preferred, maxFrameRate); | ||
XCTAssertEqual(link.preferredFrameRateRange.minimum, maxFrameRate / 2); | ||
} else if (@available(iOS 10.0, *)) { | ||
XCTAssertEqual(link.preferredFramesPerSecond, maxFrameRate); | ||
} | ||
[vsyncClient release]; | ||
} | ||
|
||
- (void)testDoNotSetVariableRefreshRatesIfCADisableMinimumFrameDurationOnPhoneIsNotOn { | ||
auto thread_task_runner = CreateNewThread("VsyncWaiterIosTest"); | ||
auto callback = [](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {}; | ||
id bundleMock = OCMPartialMock([NSBundle mainBundle]); | ||
OCMStub([bundleMock objectForInfoDictionaryKey:@"CADisableMinimumFrameDurationOnPhone"]) | ||
.andReturn(@NO); | ||
id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; | ||
double maxFrameRate = 120; | ||
[[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; | ||
|
||
VSyncClient* vsyncClient = [[[VSyncClient alloc] initWithTaskRunner:thread_task_runner | ||
callback:callback] autorelease]; | ||
CADisplayLink* link = [vsyncClient getDisplayLink]; | ||
if (@available(iOS 15.0, *)) { | ||
XCTAssertEqual(link.preferredFrameRateRange.maximum, 0); | ||
XCTAssertEqual(link.preferredFrameRateRange.preferred, 0); | ||
XCTAssertEqual(link.preferredFrameRateRange.minimum, 0); | ||
} else if (@available(iOS 10.0, *)) { | ||
XCTAssertEqual(link.preferredFramesPerSecond, 0); | ||
} | ||
[vsyncClient release]; | ||
} | ||
|
||
- (void)testDoNotSetVariableRefreshRatesIfCADisableMinimumFrameDurationOnPhoneIsNotSet { | ||
auto thread_task_runner = CreateNewThread("VsyncWaiterIosTest"); | ||
auto callback = [](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {}; | ||
id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; | ||
double maxFrameRate = 120; | ||
[[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; | ||
VSyncClient* vsyncClient = [[[VSyncClient alloc] initWithTaskRunner:thread_task_runner | ||
callback:callback] autorelease]; | ||
CADisplayLink* link = [vsyncClient getDisplayLink]; | ||
if (@available(iOS 15.0, *)) { | ||
XCTAssertEqual(link.preferredFrameRateRange.maximum, 0); | ||
XCTAssertEqual(link.preferredFrameRateRange.preferred, 0); | ||
XCTAssertEqual(link.preferredFrameRateRange.minimum, 0); | ||
} else if (@available(iOS 10.0, *)) { | ||
XCTAssertEqual(link.preferredFramesPerSecond, 0); | ||
} | ||
[vsyncClient release]; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this test need to use mrc? Can it be moved to
ios_test_flutter
? Your test as written isn't releasing everything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got compiling issue trying to use ARC due to
scoped_nsobject
used in the header."flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang.