Skip to content

Commit c8abb2b

Browse files
Chris YangJsouLiang
authored andcommitted
Variable Refresh Rate Display (flutter#30223)
1 parent 51ee0db commit c8abb2b

18 files changed

+194
-3
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,10 @@ FILE: ../../../flutter/shell/common/switches.h
765765
FILE: ../../../flutter/shell/common/switches_unittests.cc
766766
FILE: ../../../flutter/shell/common/thread_host.cc
767767
FILE: ../../../flutter/shell/common/thread_host.h
768+
FILE: ../../../flutter/shell/common/variable_refresh_rate_display.cc
769+
FILE: ../../../flutter/shell/common/variable_refresh_rate_display.h
770+
FILE: ../../../flutter/shell/common/variable_refresh_rate_display_unittests.cc
771+
FILE: ../../../flutter/shell/common/variable_refresh_rate_reporter.h
768772
FILE: ../../../flutter/shell/common/vsync_waiter.cc
769773
FILE: ../../../flutter/shell/common/vsync_waiter.h
770774
FILE: ../../../flutter/shell/common/vsync_waiter_fallback.cc

shell/common/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ source_set("common") {
9696
"switches.h",
9797
"thread_host.cc",
9898
"thread_host.h",
99+
"variable_refresh_rate_display.cc",
100+
"variable_refresh_rate_display.h",
101+
"variable_refresh_rate_reporter.h",
99102
"vsync_waiter.cc",
100103
"vsync_waiter.h",
101104
"vsync_waiter_fallback.cc",
@@ -266,6 +269,7 @@ if (enable_unittests) {
266269
"shell_unittests.cc",
267270
"skp_shader_warmup_unittests.cc",
268271
"switches_unittests.cc",
272+
"variable_refresh_rate_display_unittests.cc",
269273
]
270274

271275
deps = [

shell/common/animator.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ void Animator::Render(std::unique_ptr<flutter::LayerTree> layer_tree) {
206206
std::move(frame_timings_recorder_));
207207
}
208208

209+
const VsyncWaiter& Animator::GetVsyncWaiter() const {
210+
return *waiter_.get();
211+
}
212+
209213
bool Animator::CanReuseLastLayerTree() {
210214
return !regenerate_layer_tree_;
211215
}

shell/common/animator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class Animator final {
5454

5555
void Render(std::unique_ptr<flutter::LayerTree> layer_tree);
5656

57+
const VsyncWaiter& GetVsyncWaiter() const;
58+
5759
//--------------------------------------------------------------------------
5860
/// @brief Schedule a secondary callback to be executed right after the
5961
/// main `VsyncWaiter::AsyncWaitForVsync` callback (which is added

shell/common/display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <optional>
99

1010
#include "flutter/fml/macros.h"
11+
#include "flutter/shell/common/variable_refresh_rate_reporter.h"
1112

1213
namespace flutter {
1314

shell/common/engine.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,8 @@ void Engine::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
600600
}
601601
}
602602

603+
const VsyncWaiter& Engine::GetVsyncWaiter() const {
604+
return animator_->GetVsyncWaiter();
605+
}
606+
603607
} // namespace flutter

shell/common/engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
903903
return runtime_controller_.get();
904904
}
905905

906+
const VsyncWaiter& GetVsyncWaiter() const;
907+
906908
private:
907909
// |RuntimeDelegate|
908910
std::string DefaultRouteName() override;

shell/common/shell.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,4 +1872,8 @@ Shell::GetPlatformMessageHandler() const {
18721872
return platform_message_handler_;
18731873
}
18741874

1875+
const VsyncWaiter& Shell::GetVsyncWaiter() const {
1876+
return engine_->GetVsyncWaiter();
1877+
}
1878+
18751879
} // namespace flutter

shell/common/shell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ class Shell final : public PlatformView::Delegate,
401401
const std::shared_ptr<PlatformMessageHandler>& GetPlatformMessageHandler()
402402
const;
403403

404+
const VsyncWaiter& GetVsyncWaiter() const;
405+
404406
private:
405407
using ServiceProtocolHandler =
406408
std::function<bool(const ServiceProtocol::Handler::ServiceProtocolMap&,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/shell/common/variable_refresh_rate_display.h"
6+
#include "flutter/fml/logging.h"
7+
8+
namespace flutter {
9+
10+
VariableRefreshRateDisplay::VariableRefreshRateDisplay(
11+
DisplayId display_id,
12+
const VariableRefreshRateReporter& refresh_rate_reporter)
13+
: Display(display_id, refresh_rate_reporter.GetRefreshRate()),
14+
refresh_rate_reporter_(refresh_rate_reporter) {}
15+
16+
VariableRefreshRateDisplay::VariableRefreshRateDisplay(
17+
const VariableRefreshRateReporter& refresh_rate_reporter)
18+
: Display(refresh_rate_reporter.GetRefreshRate()),
19+
refresh_rate_reporter_(refresh_rate_reporter) {}
20+
21+
double VariableRefreshRateDisplay::GetRefreshRate() const {
22+
return refresh_rate_reporter_.GetRefreshRate();
23+
}
24+
25+
} // namespace flutter

0 commit comments

Comments
 (0)