Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 865e0619 authored by Carmelo Messina's avatar Carmelo Messina
Browse files

Set the screen frame rate to 60 Hz: temporarily disabled in Android

Due to issues detected in #2336, changes in Android require further investigation. A revert to the Chromium version is performed, but this only works for 120Hz devices.
parent af4b790e
Loading
Loading
Loading
Loading
+49 −25
Original line number Original line Diff line number Diff line
@@ -9,24 +9,26 @@ The feature can be disabled using the throttle-main-thread-to-60hz flag (enabled


License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
---
---
 cc/base/features.cc                             | 2 ++
 cc/base/features.cc                           |  4 +++
 cc/scheduler/scheduler_state_machine.cc         | 7 +++----
 cc/scheduler/scheduler_state_machine.cc       | 26 +++++++++++++++++++
 chrome/browser/chrome_content_browser_client.cc | 8 ++++++++
 .../browser/chrome_content_browser_client.cc  | 11 ++++++++
 third_party/blink/common/features.cc          |  1 +
 third_party/blink/common/features.cc          |  1 +
 4 files changed, 14 insertions(+), 4 deletions(-)
 4 files changed, 42 insertions(+)


diff --git a/cc/base/features.cc b/cc/base/features.cc
diff --git a/cc/base/features.cc b/cc/base/features.cc
--- a/cc/base/features.cc
--- a/cc/base/features.cc
+++ b/cc/base/features.cc
+++ b/cc/base/features.cc
@@ -180,6 +180,7 @@ BASE_FEATURE(kInitImageDecodeLastUseTime,
@@ -180,6 +180,9 @@ BASE_FEATURE(kInitImageDecodeLastUseTime,
 BASE_FEATURE(kThrottleMainFrameTo60Hz,
 BASE_FEATURE(kThrottleMainFrameTo60Hz,
              "ThrottleMainFrameTo60Hz",
              "ThrottleMainFrameTo60Hz",
              base::FEATURE_DISABLED_BY_DEFAULT);
              base::FEATURE_DISABLED_BY_DEFAULT);
+#if !BUILDFLAG(IS_ANDROID)
+SET_CROMITE_FEATURE_ENABLED(kThrottleMainFrameTo60Hz);
+SET_CROMITE_FEATURE_ENABLED(kThrottleMainFrameTo60Hz);
+#endif
 
 
 void SetIsEligibleForThrottleMainFrameTo60Hz(bool is_eligible) {
 void SetIsEligibleForThrottleMainFrameTo60Hz(bool is_eligible) {
   s_is_eligible_for_throttle_main_frame_to_60hz.store(
   s_is_eligible_for_throttle_main_frame_to_60hz.store(
@@ -209,6 +210,7 @@ BASE_FEATURE(kRenderThrottleFrameRate,
@@ -209,6 +212,7 @@ BASE_FEATURE(kRenderThrottleFrameRate,
              base::FEATURE_ENABLED_BY_DEFAULT);
              base::FEATURE_ENABLED_BY_DEFAULT);
 const base::FeatureParam<int> kRenderThrottledFrameIntervalHz{
 const base::FeatureParam<int> kRenderThrottledFrameIntervalHz{
     &kRenderThrottleFrameRate, "render-throttled-frame-interval-hz", 30};
     &kRenderThrottleFrameRate, "render-throttled-frame-interval-hz", 30};
@@ -37,32 +39,51 @@ diff --git a/cc/base/features.cc b/cc/base/features.cc
diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc
diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc
--- a/cc/scheduler/scheduler_state_machine.cc
--- a/cc/scheduler/scheduler_state_machine.cc
+++ b/cc/scheduler/scheduler_state_machine.cc
+++ b/cc/scheduler/scheduler_state_machine.cc
@@ -1535,9 +1535,8 @@ void SchedulerStateMachine::FrameIntervalUpdated(
@@ -1535,6 +1535,7 @@ void SchedulerStateMachine::FrameIntervalUpdated(
   //
   //
   // Apply some slack, so that if for some reason the interval is a bit larger
   // Apply some slack, so that if for some reason the interval is a bit larger
   // than 8.33333333333333ms, then we catch it still.
   // than 8.33333333333333ms, then we catch it still.
-  constexpr float kSlackFactor = .9;
+#if BUILDFLAG(IS_ANDROID)
   constexpr float kSlackFactor = .9;
   bool fast_vsync_interval =
   bool fast_vsync_interval =
-      frame_interval < base::Hertz(120) * (1 / kSlackFactor);
       frame_interval < base::Hertz(120) * (1 / kSlackFactor);
+      base::FeatureList::IsEnabled(features::kThrottleMainFrameTo60Hz);
@@ -1555,6 +1556,27 @@ void SchedulerStateMachine::FrameIntervalUpdated(
   if (fast_vsync_interval) {
   } else {
     features::SetIsEligibleForThrottleMainFrameTo60Hz(true);
     main_frame_throttled_interval_ = base::TimeDelta();
   }
   }
@@ -1549,7 +1548,7 @@ void SchedulerStateMachine::FrameIntervalUpdated(
+#else
     // Use interval / 2 rather than an actual interval as refresh rates are
+  bool fast_vsync_interval =
     // not necessarily 120: it could be something really close, or it could be
+      base::FeatureList::IsEnabled(features::kThrottleMainFrameTo60Hz);
     // 144Hz for instance.
+  if (fast_vsync_interval) {
-    main_frame_throttled_interval_ = kSlackFactor * frame_interval * 2;
+    features::SetIsEligibleForThrottleMainFrameTo60Hz(true);
+  }
+  if (fast_vsync_interval &&
+      base::FeatureList::IsEnabled(features::kThrottleMainFrameTo60Hz)) {
+    // Here as well, use a slack factor, to make sure that small timing
+    // variations don't result in uneven pacing.
+    //
+    // Use interval / 2 rather than an actual interval as refresh rates are
+    // not necessarily 120: it could be something really close, or it could be
+    // 144Hz for instance.
+    main_frame_throttled_interval_ = base::Hertz(60);
+    main_frame_throttled_interval_ = base::Hertz(60);
     TRACE_EVENT("cc", "ThrottleMainFrame", "interval",
+    TRACE_EVENT("cc", "ThrottleMainFrame", "interval",
                 main_frame_throttled_interval_);
+                main_frame_throttled_interval_);
   } else {
+  } else {
@@ -1841,7 +1840,7 @@ void SchedulerStateMachine::SetShouldThrottleFrameRate(bool flag) {
+    main_frame_throttled_interval_ = base::TimeDelta();
+  }
+#endif
 }
 
 bool SchedulerStateMachine::IsDrawThrottled() const {
@@ -1841,7 +1863,11 @@ void SchedulerStateMachine::SetShouldThrottleFrameRate(bool flag) {
 }
 }
 
 
 base::TimeDelta SchedulerStateMachine::MainFrameThrottledInterval() const {
 base::TimeDelta SchedulerStateMachine::MainFrameThrottledInterval() const {
-  if (!throttle_frame_rate_) {
+#if BUILDFLAG(IS_ANDROID)
   if (!throttle_frame_rate_) {
+#else
+  if (!throttle_frame_rate_ || base::FeatureList::IsEnabled(features::kThrottleMainFrameTo60Hz)) {
+  if (!throttle_frame_rate_ || base::FeatureList::IsEnabled(features::kThrottleMainFrameTo60Hz)) {
+#endif
     return main_frame_throttled_interval_;
     return main_frame_throttled_interval_;
   } else {
   } else {
     auto throttled_interval =
     auto throttled_interval =
@@ -85,15 +106,18 @@ diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/ch
 #include "components/webapps/common/web_app_id.h"
 #include "components/webapps/common/web_app_id.h"
 #include "components/webui/chrome_urls/pref_names.h"
 #include "components/webui/chrome_urls/pref_names.h"
 #include "content/public/browser/attribution_data_model.h"
 #include "content/public/browser/attribution_data_model.h"
@@ -2775,6 +2777,12 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
@@ -2775,6 +2777,15 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
   command_line->AppendSwitchASCII(ash::switches::kHomedir, homedir.value());
   command_line->AppendSwitchASCII(ash::switches::kHomedir, homedir.value());
 #endif
 #endif
 
 
+  if (base::FeatureList::IsEnabled(::features::kThrottleMainFrameTo60Hz)
+#if !BUILDFLAG(IS_ANDROID)
+  if (child_process_id != -1
+       && base::FeatureList::IsEnabled(::features::kThrottleMainFrameTo60Hz)
+       && !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableFrameRateLimit)) {
+       && !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableFrameRateLimit)) {
+    base::CommandLine::ForCurrentProcess()->
+    base::CommandLine::ForCurrentProcess()->
+      AppendSwitch(switches::kDisableFrameRateLimit);
+      AppendSwitch(switches::kDisableFrameRateLimit);
+  }
+  }
+#endif
+
+
   if (process_type == switches::kRendererProcess) {
   if (process_type == switches::kRendererProcess) {
     content::RenderProcessHost* process =
     content::RenderProcessHost* process =