From b6dc194f29968969d40790a2eb3b9b11ca508643 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 8 Dec 2021 10:46:47 -0800 Subject: [PATCH 1/5] Variable refresh rate display --- ci/licenses_golden/licenses_flutter | 4 ++ shell/common/BUILD.gn | 4 ++ shell/common/animator.cc | 4 ++ shell/common/animator.h | 2 + shell/common/display.h | 1 + shell/common/engine.cc | 4 ++ shell/common/engine.h | 2 + shell/common/shell.cc | 4 ++ shell/common/shell.h | 2 + shell/common/variable_refresh_rate_display.cc | 25 +++++++++++++ shell/common/variable_refresh_rate_display.h | 37 +++++++++++++++++++ ...variable_refresh_rate_display_unittests.cc | 27 ++++++++++++++ shell/common/variable_refresh_rate_reporter.h | 28 ++++++++++++++ shell/common/vsync_waiters_test.cc | 11 ++++++ shell/common/vsync_waiters_test.h | 12 ++++++ .../ios/framework/Source/FlutterEngine.mm | 6 ++- .../ios/framework/Source/vsync_waiter_ios.h | 8 +++- .../ios/framework/Source/vsync_waiter_ios.mm | 14 +++++++ 18 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 shell/common/variable_refresh_rate_display.cc create mode 100644 shell/common/variable_refresh_rate_display.h create mode 100644 shell/common/variable_refresh_rate_display_unittests.cc create mode 100644 shell/common/variable_refresh_rate_reporter.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 471fd44324ffd..3929acde06528 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -765,6 +765,10 @@ FILE: ../../../flutter/shell/common/switches.h FILE: ../../../flutter/shell/common/switches_unittests.cc FILE: ../../../flutter/shell/common/thread_host.cc FILE: ../../../flutter/shell/common/thread_host.h +FILE: ../../../flutter/shell/common/variable_refresh_rate_display.cc +FILE: ../../../flutter/shell/common/variable_refresh_rate_display.h +FILE: ../../../flutter/shell/common/variable_refresh_rate_display_unittests.cc +FILE: ../../../flutter/shell/common/variable_refresh_rate_reporter.h FILE: ../../../flutter/shell/common/vsync_waiter.cc FILE: ../../../flutter/shell/common/vsync_waiter.h FILE: ../../../flutter/shell/common/vsync_waiter_fallback.cc diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 62112b4b9d917..c1f816331339e 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -96,6 +96,9 @@ source_set("common") { "switches.h", "thread_host.cc", "thread_host.h", + "variable_refresh_rate_display.cc", + "variable_refresh_rate_display.h", + "variable_refresh_rate_reporter.h", "vsync_waiter.cc", "vsync_waiter.h", "vsync_waiter_fallback.cc", @@ -266,6 +269,7 @@ if (enable_unittests) { "shell_unittests.cc", "skp_shader_warmup_unittests.cc", "switches_unittests.cc", + "variable_refresh_rate_display_unittests.cc", ] deps = [ diff --git a/shell/common/animator.cc b/shell/common/animator.cc index 32403f1c2e70a..60bd3bac594b7 100644 --- a/shell/common/animator.cc +++ b/shell/common/animator.cc @@ -206,6 +206,10 @@ void Animator::Render(std::unique_ptr layer_tree) { std::move(frame_timings_recorder_)); } +const std::shared_ptr Animator::GetVsyncWaiter() const { + return waiter_; +} + bool Animator::CanReuseLastLayerTree() { return !regenerate_layer_tree_; } diff --git a/shell/common/animator.h b/shell/common/animator.h index 85f940700dbc6..492fca36b4b7b 100644 --- a/shell/common/animator.h +++ b/shell/common/animator.h @@ -54,6 +54,8 @@ class Animator final { void Render(std::unique_ptr layer_tree); + const std::shared_ptr GetVsyncWaiter() const; + //-------------------------------------------------------------------------- /// @brief Schedule a secondary callback to be executed right after the /// main `VsyncWaiter::AsyncWaitForVsync` callback (which is added diff --git a/shell/common/display.h b/shell/common/display.h index 37e964a217f34..a4cd5aa0863e0 100644 --- a/shell/common/display.h +++ b/shell/common/display.h @@ -8,6 +8,7 @@ #include #include "flutter/fml/macros.h" +#include "flutter/shell/common/variable_refresh_rate_reporter.h" namespace flutter { diff --git a/shell/common/engine.cc b/shell/common/engine.cc index d0e28aa233899..c06ca332f0a03 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -600,4 +600,8 @@ void Engine::LoadDartDeferredLibraryError(intptr_t loading_unit_id, } } +const std::shared_ptr Engine::GetVsyncWaiter() const { + return animator_->GetVsyncWaiter(); +} + } // namespace flutter diff --git a/shell/common/engine.h b/shell/common/engine.h index 0c37d176d6edd..8bcb0b0faca19 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -903,6 +903,8 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { return runtime_controller_.get(); } + const std::shared_ptr GetVsyncWaiter() const; + private: // |RuntimeDelegate| std::string DefaultRouteName() override; diff --git a/shell/common/shell.cc b/shell/common/shell.cc index ff891ffbcac17..26bca810d361f 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -1872,4 +1872,8 @@ Shell::GetPlatformMessageHandler() const { return platform_message_handler_; } +const std::shared_ptr Shell::GetVsyncWaiter() const { + return engine_->GetVsyncWaiter(); +} + } // namespace flutter diff --git a/shell/common/shell.h b/shell/common/shell.h index 0448da1c424d7..1e31aa5cfe7b5 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -401,6 +401,8 @@ class Shell final : public PlatformView::Delegate, const std::shared_ptr& GetPlatformMessageHandler() const; + const std::shared_ptr GetVsyncWaiter() const; + private: using ServiceProtocolHandler = std::function refresh_rate_reporter) + : Display(display_id, refresh_rate_reporter->GetRefreshRate()), + refresh_rate_reporter_(refresh_rate_reporter) {} + +VariableRefreshRateDisplay::VariableRefreshRateDisplay( + std::shared_ptr refresh_rate_reporter) + : Display(refresh_rate_reporter->GetRefreshRate()), + refresh_rate_reporter_(refresh_rate_reporter) {} + +double VariableRefreshRateDisplay::GetRefreshRate() const { + return refresh_rate_reporter_->GetRefreshRate(); +} + +} // namespace flutter diff --git a/shell/common/variable_refresh_rate_display.h b/shell/common/variable_refresh_rate_display.h new file mode 100644 index 0000000000000..e473291b754ef --- /dev/null +++ b/shell/common/variable_refresh_rate_display.h @@ -0,0 +1,37 @@ +// 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. + +#ifndef FLUTTER_SHELL_COMMON_VARIABLE_REFRESH_RATE_DISPLAY_H_ +#define FLUTTER_SHELL_COMMON_VARIABLE_REFRESH_RATE_DISPLAY_H_ + +#include + +#include "display.h" +#include "flutter/fml/macros.h" +#include "variable_refresh_rate_reporter.h" + +namespace flutter { + +/// A Display where the refresh rate can change over time. +class VariableRefreshRateDisplay : public Display { + public: + explicit VariableRefreshRateDisplay( + DisplayId display_id, + std::shared_ptr refresh_rate_reporter); + explicit VariableRefreshRateDisplay( + std::shared_ptr refresh_rate_reporter); + ~VariableRefreshRateDisplay() = default; + + // |Display| + double GetRefreshRate() const override; + + private: + std::shared_ptr refresh_rate_reporter_; + + FML_DISALLOW_COPY_AND_ASSIGN(VariableRefreshRateDisplay); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_COMMON_VARIABLE_REFRESH_RATE_DISPLAY_H_ diff --git a/shell/common/variable_refresh_rate_display_unittests.cc b/shell/common/variable_refresh_rate_display_unittests.cc new file mode 100644 index 0000000000000..6488f13e978df --- /dev/null +++ b/shell/common/variable_refresh_rate_display_unittests.cc @@ -0,0 +1,27 @@ +// 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. + +#include "variable_refresh_rate_display.h" +#include "vsync_waiters_test.h" + +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { + +TEST(VariableRefreshRateDisplayTest, ReportCorrectInitialRefreshRate) { + auto refresh_rate_reporter = std::make_shared(60); + auto display = flutter::VariableRefreshRateDisplay(refresh_rate_reporter); + ASSERT_EQ(display.GetRefreshRate(), 60); +} + +TEST(VariableRefreshRateDisplayTest, ReportCorrectRefreshRateWhenUpdated) { + auto refresh_rate_reporter = std::make_shared(60); + auto display = flutter::VariableRefreshRateDisplay(refresh_rate_reporter); + refresh_rate_reporter->UpdateRefreshRate(30); + ASSERT_EQ(display.GetRefreshRate(), 30); +} + +} // namespace testing +} // namespace flutter diff --git a/shell/common/variable_refresh_rate_reporter.h b/shell/common/variable_refresh_rate_reporter.h new file mode 100644 index 0000000000000..882eea2279749 --- /dev/null +++ b/shell/common/variable_refresh_rate_reporter.h @@ -0,0 +1,28 @@ +// 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. + +#ifndef FLUTTER_SHELL_COMMON_VARIABLE_REFRESH_RATE_REPORTER_H_ +#define FLUTTER_SHELL_COMMON_VARIABLE_REFRESH_RATE_REPORTER_H_ + +#include +#include +#include +#include + +namespace flutter { + +/// Abstract class that reprents a platform specific mechanism to report current +/// refresh rates. +class VariableRefreshRateReporter { + public: + VariableRefreshRateReporter() = default; + + virtual double GetRefreshRate() const = 0; + + FML_DISALLOW_COPY_AND_ASSIGN(VariableRefreshRateReporter); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_COMMON_VARIABLE_REFRESH_RATE_REPORTER_H_ diff --git a/shell/common/vsync_waiters_test.cc b/shell/common/vsync_waiters_test.cc index 762f9f58c0cac..7869e98f62ca5 100644 --- a/shell/common/vsync_waiters_test.cc +++ b/shell/common/vsync_waiters_test.cc @@ -64,5 +64,16 @@ void ConstantFiringVsyncWaiter::AwaitVSync() { }); } +TestRefreshRateReporter::TestRefreshRateReporter(double refresh_rate) + : refresh_rate_(refresh_rate) {} + +void TestRefreshRateReporter::UpdateRefreshRate(double refresh_rate) { + refresh_rate_ = refresh_rate; +} + +double TestRefreshRateReporter::GetRefreshRate() { + return refresh_rate_; +} + } // namespace testing } // namespace flutter diff --git a/shell/common/vsync_waiters_test.h b/shell/common/vsync_waiters_test.h index 66f474b765b82..80fa3abfb6c24 100644 --- a/shell/common/vsync_waiters_test.h +++ b/shell/common/vsync_waiters_test.h @@ -56,6 +56,18 @@ class ConstantFiringVsyncWaiter : public VsyncWaiter { void AwaitVSync() override; }; +class TestRefreshRateReporter final : public VariableRefreshRateReporter { + public: + explicit TestRefreshRateReporter(double refresh_rate); + void UpdateRefreshRate(double refresh_rate); + + // |RefreshRateReporter| + double GetRefreshRate() const override; + + private: + double refresh_rate_; +}; + } // namespace testing } // namespace flutter diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 0a7d8ddc4b41d..bd37d27f57dc3 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -17,6 +17,7 @@ #include "flutter/shell/common/shell.h" #include "flutter/shell/common/switches.h" #include "flutter/shell/common/thread_host.h" +#include "flutter/shell/common/variable_refresh_rate_display.h" #import "flutter/shell/platform/darwin/common/command_line.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h" @@ -699,9 +700,10 @@ - (BOOL)createShell:(NSString*)entrypoint } - (void)initializeDisplays { - double refresh_rate = [DisplayLinkManager displayRefreshRate]; + std::shared_ptr vsync_waiter_ios = + std::static_pointer_cast(_shell->GetVsyncWaiter()); std::vector> displays; - displays.push_back(std::make_unique(refresh_rate)); + displays.push_back(std::make_unique(vsync_waiter_ios)); _shell->OnDisplayUpdates(flutter::DisplayUpdateType::kStartup, std::move(displays)); } diff --git a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h index f20bb26ef47d4..f5c3e656b258c 100644 --- a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h +++ b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h @@ -8,6 +8,7 @@ #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" +#include "flutter/shell/common/variable_refresh_rate_reporter.h" #include "flutter/shell/common/vsync_waiter.h" @interface DisplayLinkManager : NSObject @@ -34,16 +35,21 @@ - (void)invalidate; +- (double)getRefreshRate; + @end namespace flutter { -class VsyncWaiterIOS final : public VsyncWaiter { +class VsyncWaiterIOS final : public VsyncWaiter, public VariableRefreshRateReporter { public: explicit VsyncWaiterIOS(flutter::TaskRunners task_runners); ~VsyncWaiterIOS() override; + // |VariableRefreshRateReporter| + double GetRefreshRate() const override; + private: fml::scoped_nsobject client_; diff --git a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm index 7877f438b2eea..7a0a8c3d1eea3 100644 --- a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm +++ b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm @@ -39,11 +39,17 @@ [client_.get() await]; } +// |VariableRefreshRateReporter| +double VsyncWaiterIOS::GetRefreshRate() { + return [client_.get() getRefreshRate]; +} + } // namespace flutter @implementation VSyncClient { flutter::VsyncWaiter::Callback callback_; fml::scoped_nsobject display_link_; + double current_refresh_rate_; } - (instancetype)initWithTaskRunner:(fml::RefPtr)task_runner @@ -51,6 +57,7 @@ - (instancetype)initWithTaskRunner:(fml::RefPtr)task_runner self = [super init]; if (self) { + current_refresh_rate_ = [DisplayLinkManager displayRefreshRate]; callback_ = std::move(callback); display_link_ = fml::scoped_nsobject { [[CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)] retain] @@ -87,6 +94,9 @@ - (void)onDisplayLink:(CADisplayLink*)link { std::unique_ptr recorder = std::make_unique(); + + current_refresh_rate_ = round(1 / (frame_target_time - frame_start_time).ToSecondsF()); + recorder->RecordVsync(frame_start_time, frame_target_time); display_link_.get().paused = YES; @@ -103,6 +113,10 @@ - (void)dealloc { [super dealloc]; } +- (double)getRefreshRate { + return current_refresh_rate_; +} + @end @implementation DisplayLinkManager From e5c4c5bd2a657f3d31aba073a7fc2fa318470568 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 10 Jan 2022 10:17:29 -0800 Subject: [PATCH 2/5] fix --- shell/common/vsync_waiters_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/common/vsync_waiters_test.cc b/shell/common/vsync_waiters_test.cc index 7869e98f62ca5..ff26cc6775270 100644 --- a/shell/common/vsync_waiters_test.cc +++ b/shell/common/vsync_waiters_test.cc @@ -71,7 +71,7 @@ void TestRefreshRateReporter::UpdateRefreshRate(double refresh_rate) { refresh_rate_ = refresh_rate; } -double TestRefreshRateReporter::GetRefreshRate() { +double TestRefreshRateReporter::GetRefreshRate() const { return refresh_rate_; } From cd5c49406f8def8c65cfad65df78129c2dcb2135 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 10 Jan 2022 14:37:20 -0800 Subject: [PATCH 3/5] review --- shell/common/animator.cc | 4 ++-- shell/common/animator.h | 2 +- shell/common/engine.cc | 2 +- shell/common/engine.h | 2 +- shell/common/shell.cc | 2 +- shell/common/shell.h | 2 +- shell/common/variable_refresh_rate_display.cc | 10 +++++----- shell/common/variable_refresh_rate_display.h | 6 +++--- .../common/variable_refresh_rate_display_unittests.cc | 4 ++-- .../darwin/ios/framework/Source/FlutterEngine.mm | 3 +-- .../darwin/ios/framework/Source/vsync_waiter_ios.mm | 2 +- 11 files changed, 19 insertions(+), 20 deletions(-) diff --git a/shell/common/animator.cc b/shell/common/animator.cc index 60bd3bac594b7..08d216d89ed0b 100644 --- a/shell/common/animator.cc +++ b/shell/common/animator.cc @@ -206,8 +206,8 @@ void Animator::Render(std::unique_ptr layer_tree) { std::move(frame_timings_recorder_)); } -const std::shared_ptr Animator::GetVsyncWaiter() const { - return waiter_; +const VsyncWaiter& Animator::GetVsyncWaiter() const { + return *waiter_.get(); } bool Animator::CanReuseLastLayerTree() { diff --git a/shell/common/animator.h b/shell/common/animator.h index 492fca36b4b7b..06dfdb3f297e3 100644 --- a/shell/common/animator.h +++ b/shell/common/animator.h @@ -54,7 +54,7 @@ class Animator final { void Render(std::unique_ptr layer_tree); - const std::shared_ptr GetVsyncWaiter() const; + const VsyncWaiter& GetVsyncWaiter() const; //-------------------------------------------------------------------------- /// @brief Schedule a secondary callback to be executed right after the diff --git a/shell/common/engine.cc b/shell/common/engine.cc index c06ca332f0a03..d382e5e94c8a0 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -600,7 +600,7 @@ void Engine::LoadDartDeferredLibraryError(intptr_t loading_unit_id, } } -const std::shared_ptr Engine::GetVsyncWaiter() const { +const VsyncWaiter& Engine::GetVsyncWaiter() const { return animator_->GetVsyncWaiter(); } diff --git a/shell/common/engine.h b/shell/common/engine.h index 8bcb0b0faca19..b0444abdaa907 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -903,7 +903,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { return runtime_controller_.get(); } - const std::shared_ptr GetVsyncWaiter() const; + const VsyncWaiter& GetVsyncWaiter() const; private: // |RuntimeDelegate| diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 26bca810d361f..91b238324a6dc 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -1872,7 +1872,7 @@ Shell::GetPlatformMessageHandler() const { return platform_message_handler_; } -const std::shared_ptr Shell::GetVsyncWaiter() const { +const VsyncWaiter& Shell::GetVsyncWaiter() const { return engine_->GetVsyncWaiter(); } diff --git a/shell/common/shell.h b/shell/common/shell.h index 1e31aa5cfe7b5..38f343d3b6ddd 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -401,7 +401,7 @@ class Shell final : public PlatformView::Delegate, const std::shared_ptr& GetPlatformMessageHandler() const; - const std::shared_ptr GetVsyncWaiter() const; + const VsyncWaiter& GetVsyncWaiter() const; private: using ServiceProtocolHandler = diff --git a/shell/common/variable_refresh_rate_display.cc b/shell/common/variable_refresh_rate_display.cc index 81d717238d20d..4957fbdee48f5 100644 --- a/shell/common/variable_refresh_rate_display.cc +++ b/shell/common/variable_refresh_rate_display.cc @@ -9,17 +9,17 @@ namespace flutter { VariableRefreshRateDisplay::VariableRefreshRateDisplay( DisplayId display_id, - std::shared_ptr refresh_rate_reporter) - : Display(display_id, refresh_rate_reporter->GetRefreshRate()), + const VariableRefreshRateReporter& refresh_rate_reporter) + : Display(display_id, refresh_rate_reporter.GetRefreshRate()), refresh_rate_reporter_(refresh_rate_reporter) {} VariableRefreshRateDisplay::VariableRefreshRateDisplay( - std::shared_ptr refresh_rate_reporter) - : Display(refresh_rate_reporter->GetRefreshRate()), + const VariableRefreshRateReporter& refresh_rate_reporter) + : Display(refresh_rate_reporter.GetRefreshRate()), refresh_rate_reporter_(refresh_rate_reporter) {} double VariableRefreshRateDisplay::GetRefreshRate() const { - return refresh_rate_reporter_->GetRefreshRate(); + return refresh_rate_reporter_.GetRefreshRate(); } } // namespace flutter diff --git a/shell/common/variable_refresh_rate_display.h b/shell/common/variable_refresh_rate_display.h index e473291b754ef..5ba0a571af39a 100644 --- a/shell/common/variable_refresh_rate_display.h +++ b/shell/common/variable_refresh_rate_display.h @@ -18,16 +18,16 @@ class VariableRefreshRateDisplay : public Display { public: explicit VariableRefreshRateDisplay( DisplayId display_id, - std::shared_ptr refresh_rate_reporter); + const VariableRefreshRateReporter& refresh_rate_reporter); explicit VariableRefreshRateDisplay( - std::shared_ptr refresh_rate_reporter); + const VariableRefreshRateReporter& refresh_rate_reporter); ~VariableRefreshRateDisplay() = default; // |Display| double GetRefreshRate() const override; private: - std::shared_ptr refresh_rate_reporter_; + const VariableRefreshRateReporter& refresh_rate_reporter_; FML_DISALLOW_COPY_AND_ASSIGN(VariableRefreshRateDisplay); }; diff --git a/shell/common/variable_refresh_rate_display_unittests.cc b/shell/common/variable_refresh_rate_display_unittests.cc index 6488f13e978df..f3b3f69adbdae 100644 --- a/shell/common/variable_refresh_rate_display_unittests.cc +++ b/shell/common/variable_refresh_rate_display_unittests.cc @@ -12,13 +12,13 @@ namespace testing { TEST(VariableRefreshRateDisplayTest, ReportCorrectInitialRefreshRate) { auto refresh_rate_reporter = std::make_shared(60); - auto display = flutter::VariableRefreshRateDisplay(refresh_rate_reporter); + auto display = flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); ASSERT_EQ(display.GetRefreshRate(), 60); } TEST(VariableRefreshRateDisplayTest, ReportCorrectRefreshRateWhenUpdated) { auto refresh_rate_reporter = std::make_shared(60); - auto display = flutter::VariableRefreshRateDisplay(refresh_rate_reporter); + auto display = flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); refresh_rate_reporter->UpdateRefreshRate(30); ASSERT_EQ(display.GetRefreshRate(), 30); } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index bd37d27f57dc3..ae90bba93d0f2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -700,8 +700,7 @@ - (BOOL)createShell:(NSString*)entrypoint } - (void)initializeDisplays { - std::shared_ptr vsync_waiter_ios = - std::static_pointer_cast(_shell->GetVsyncWaiter()); + const flutter::VsyncWaiterIOS& vsync_waiter_ios = static_cast(_shell->GetVsyncWaiter()); std::vector> displays; displays.push_back(std::make_unique(vsync_waiter_ios)); _shell->OnDisplayUpdates(flutter::DisplayUpdateType::kStartup, std::move(displays)); diff --git a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm index 7a0a8c3d1eea3..91cabc13dd985 100644 --- a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm +++ b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm @@ -40,7 +40,7 @@ } // |VariableRefreshRateReporter| -double VsyncWaiterIOS::GetRefreshRate() { +double VsyncWaiterIOS::GetRefreshRate() const { return [client_.get() getRefreshRate]; } From 7a1f9afb7d9240fdd52674906e1d28821e875be4 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 10 Jan 2022 14:37:34 -0800 Subject: [PATCH 4/5] format --- shell/common/variable_refresh_rate_display_unittests.cc | 6 ++++-- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/shell/common/variable_refresh_rate_display_unittests.cc b/shell/common/variable_refresh_rate_display_unittests.cc index f3b3f69adbdae..be9554685f92d 100644 --- a/shell/common/variable_refresh_rate_display_unittests.cc +++ b/shell/common/variable_refresh_rate_display_unittests.cc @@ -12,13 +12,15 @@ namespace testing { TEST(VariableRefreshRateDisplayTest, ReportCorrectInitialRefreshRate) { auto refresh_rate_reporter = std::make_shared(60); - auto display = flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); + auto display = + flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); ASSERT_EQ(display.GetRefreshRate(), 60); } TEST(VariableRefreshRateDisplayTest, ReportCorrectRefreshRateWhenUpdated) { auto refresh_rate_reporter = std::make_shared(60); - auto display = flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); + auto display = + flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); refresh_rate_reporter->UpdateRefreshRate(30); ASSERT_EQ(display.GetRefreshRate(), 30); } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index ae90bba93d0f2..748fae734e681 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -700,7 +700,8 @@ - (BOOL)createShell:(NSString*)entrypoint } - (void)initializeDisplays { - const flutter::VsyncWaiterIOS& vsync_waiter_ios = static_cast(_shell->GetVsyncWaiter()); + const flutter::VsyncWaiterIOS& vsync_waiter_ios = + static_cast(_shell->GetVsyncWaiter()); std::vector> displays; displays.push_back(std::make_unique(vsync_waiter_ios)); _shell->OnDisplayUpdates(flutter::DisplayUpdateType::kStartup, std::move(displays)); From 19ecb23dbfa8e29b3a59133b5e27a29a1ccd4f22 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 11 Jan 2022 09:51:18 -0800 Subject: [PATCH 5/5] review --- shell/common/variable_refresh_rate_display_unittests.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/common/variable_refresh_rate_display_unittests.cc b/shell/common/variable_refresh_rate_display_unittests.cc index be9554685f92d..25d24afc09d7d 100644 --- a/shell/common/variable_refresh_rate_display_unittests.cc +++ b/shell/common/variable_refresh_rate_display_unittests.cc @@ -11,14 +11,14 @@ namespace flutter { namespace testing { TEST(VariableRefreshRateDisplayTest, ReportCorrectInitialRefreshRate) { - auto refresh_rate_reporter = std::make_shared(60); + auto refresh_rate_reporter = std::make_unique(60); auto display = flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); ASSERT_EQ(display.GetRefreshRate(), 60); } TEST(VariableRefreshRateDisplayTest, ReportCorrectRefreshRateWhenUpdated) { - auto refresh_rate_reporter = std::make_shared(60); + auto refresh_rate_reporter = std::make_unique(60); auto display = flutter::VariableRefreshRateDisplay(*refresh_rate_reporter.get()); refresh_rate_reporter->UpdateRefreshRate(30);