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
Report correct refresh rate if updated in a new frame #30054
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
22377e7
refresh frame rate reporting
3fa91af
Merge branch 'main' into vsync_update
390cc4e
draft
1a8c4d0
use display_manager to update displays
0b09ae4
cleanup
87a4dc8
add import
1548935
test
cad7e7d
tests
d39b74e
return early
253554e
Merge branch 'main' into vsync_update
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include "display.h" | ||
| #include "display_manager.h" | ||
|
|
||
| #include "flutter/fml/time/time_point.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| TEST(DisplayManagerTest, SetsDisplayOnStartup) { | ||
| DisplayManager manager; | ||
| const double refresh_rate = 60; | ||
| std::vector<std::unique_ptr<flutter::Display>> displays; | ||
| displays.push_back(std::make_unique<flutter::Display>(refresh_rate)); | ||
| manager.HandleDisplayUpdates(flutter::DisplayUpdateType::kStartup, | ||
| std::move(displays)); | ||
| ASSERT_EQ(manager.GetMainDisplayRefreshRate(), refresh_rate); | ||
| } | ||
|
|
||
| TEST(DisplayManagerTest, UpdatesDisplayIfTypeIsUpdateRefreshRate) { | ||
| DisplayManager manager; | ||
| const double refresh_rate = 60; | ||
| std::vector<std::unique_ptr<flutter::Display>> displays1; | ||
| displays1.push_back(std::make_unique<flutter::Display>(refresh_rate)); | ||
| manager.HandleDisplayUpdates(flutter::DisplayUpdateType::kStartup, | ||
| std::move(displays1)); | ||
|
|
||
| const double new_refresh_rate = 120; | ||
| std::vector<std::unique_ptr<flutter::Display>> displays2; | ||
| displays2.push_back(std::make_unique<flutter::Display>(new_refresh_rate)); | ||
| manager.HandleDisplayUpdates(flutter::DisplayUpdateType::kUpdateRefreshRate, | ||
| std::move(displays2)); | ||
| ASSERT_EQ(manager.GetMainDisplayRefreshRate(), new_refresh_rate); | ||
| } | ||
|
|
||
| TEST(DisplayManagerTest, UpdatesDisplayIfNewlyCalculatedRefreshRateChanged) { | ||
| DisplayManager manager; | ||
| const double refresh_rate = 60; | ||
| std::vector<std::unique_ptr<flutter::Display>> displays; | ||
| displays.push_back(std::make_unique<flutter::Display>(refresh_rate)); | ||
| manager.HandleDisplayUpdates(flutter::DisplayUpdateType::kStartup, | ||
| std::move(displays)); | ||
| fml::TimePoint vsync_start = | ||
| fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromMilliseconds(0)); | ||
| fml::TimePoint vsync_target = | ||
| fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromMilliseconds(8)); | ||
|
|
||
| manager.UpdateRefreshRateIfNecessary( | ||
| flutter::DisplayUpdateType::kUpdateRefreshRate, vsync_start, | ||
| vsync_target); | ||
|
|
||
| const double kRefreshRateCompareEpsilon = 0.1; | ||
| ASSERT_NEAR(manager.GetMainDisplayRefreshRate(), | ||
| round(1 / (vsync_target - vsync_start).ToSecondsF()), | ||
| kRefreshRateCompareEpsilon); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter |
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.
What's the cost of this on iOS? We know for sure that on some Android platforms it's pretty expensive (e.g. 2-5ms) and this is during frameworkload.
Can we instead listen to refresh rate updates from the OS somehow?
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.
Could you elaborate how this is expensive on Android. This method is essentially a no-op if framerate doesn't change. See: https://github.com/flutter/engine/pull/30054/files#diff-c9141b5122b7cb9dcc29a05b1660dbb92c1c6ea8e0df831c96b42708fa1e20b5R66
(I should probably need to update the code to return early so it is clearer)