fix: disable background throttling also in the viz::DisplayScheduler
(#38924)
* fix: disable background throttling also in the `viz::DisplayScheduler` `viz::DisplayScheduler` is responsible for drawing and swapping frames in the `DisplayScheduler::DrawAndSwap` which is called from the `DisplayScheduler::AttemptDrawAndSwap` if the `DisplayScheduler::ShouldDraw` returns true. `ShouldDraw` depends on the `DisplayScheduler` visibility and when it is not visible then it returns false. In order to keep producing frames, disabling `backgroundThrottling` should also prevent changing `DisplayScheduler` visibility to false. `DisplayScheduler` lives in the `ui::Compositor` where every `electron::NativewWindow` has its own `Compositor`. `electron::NativewWindow` may be host of the multiple `electron::api::WebContents` instances which may have different `WebPreferences` settings. Therefore if at least one of the `WebContents` requires disabling throttling then all other `WebContents` using the same window will have it disabled in the `ui::Compositor`. BREAKING CHANGE: `backgroundThrottling` set to false will disable frames throttling in the `BrowserWindow` for all `WebContents` displayed by it. Close: [#31016](https://github.com/electron/electron/issues/31016) * fixup! fix: disable background throttling also in the `viz::DisplayScheduler` * fixup! fix: disable background throttling also in the `viz::DisplayScheduler` * fixup! fix: disable background throttling also in the `viz::DisplayScheduler` --------- Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
fa215f1009
commit
2190793fe6
10 changed files with 176 additions and 3 deletions
|
@ -124,6 +124,7 @@ feat_expose_documentloader_setdefersloading_on_webdocumentloader.patch
|
|||
fix_remove_profiles_from_spellcheck_service.patch
|
||||
chore_patch_out_profile_methods_in_chrome_browser_pdf.patch
|
||||
chore_patch_out_profile_methods_in_titlebar_config.patch
|
||||
fix_disabling_background_throttling_in_compositor.patch
|
||||
fix_select_the_first_menu_item_when_opened_via_keyboard.patch
|
||||
fix_return_v8_value_from_localframe_requestexecutescript.patch
|
||||
fix_harden_blink_scriptstate_maybefrom.patch
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Michal Pichlinski <michal.pichlinski@openfin.co>
|
||||
Date: Thu, 15 Jun 2023 23:04:48 +0200
|
||||
Subject: allow disabling throttling in the `viz::DisplayScheduler` per
|
||||
`ui::Compositor`
|
||||
|
||||
In Chromium when the `viz::DisplayScheduler` is invisible it throttles
|
||||
its work by dropping frame draws and swaps.
|
||||
|
||||
This patch allows disbling this throttling by preventing transition to
|
||||
invisible state of the `viz::DisplayScheduler` owned
|
||||
by the `ui::Compositor`.
|
||||
|
||||
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
|
||||
index 623991465edb99ee720c8177c3511e4d025ed890..c94537af56f7de8cd15bd3b3155b79b41ea003f4 100644
|
||||
--- a/ui/compositor/compositor.cc
|
||||
+++ b/ui/compositor/compositor.cc
|
||||
@@ -341,7 +341,8 @@ void Compositor::SetLayerTreeFrameSink(
|
||||
if (display_private_) {
|
||||
disabled_swap_until_resize_ = false;
|
||||
display_private_->Resize(size());
|
||||
- display_private_->SetDisplayVisible(host_->IsVisible());
|
||||
+ // Invisible display is throttling itself.
|
||||
+ display_private_->SetDisplayVisible(background_throttling_ ? host_->IsVisible() : true);
|
||||
display_private_->SetDisplayColorSpaces(display_color_spaces_);
|
||||
display_private_->SetDisplayColorMatrix(
|
||||
gfx::SkM44ToTransform(display_color_matrix_));
|
||||
@@ -533,8 +534,11 @@ void Compositor::SetVisible(bool visible) {
|
||||
host_->SetVisible(visible);
|
||||
// Visibility is reset when the output surface is lost, so this must also be
|
||||
// updated then.
|
||||
- if (display_private_)
|
||||
- display_private_->SetDisplayVisible(visible);
|
||||
+ if (display_private_) {
|
||||
+ // Invisible display is throttling itself.
|
||||
+ display_private_->SetDisplayVisible(
|
||||
+ background_throttling_ ? visible : true);
|
||||
+ }
|
||||
}
|
||||
|
||||
bool Compositor::IsVisible() {
|
||||
@@ -959,4 +963,13 @@ const cc::LayerTreeSettings& Compositor::GetLayerTreeSettings() const {
|
||||
return host_->GetSettings();
|
||||
}
|
||||
|
||||
+void Compositor::SetBackgroundThrottling(bool background_throttling_enabled) {
|
||||
+ background_throttling_ = background_throttling_enabled;
|
||||
+ if (display_private_) {
|
||||
+ // Invisible display is throttling itself.
|
||||
+ display_private_->SetDisplayVisible(
|
||||
+ background_throttling_ ? host_->IsVisible() : true);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
} // namespace ui
|
||||
diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
|
||||
index ddb28fd6f7549759df7e3b7d6b309cd982e199af..7473f3af9bc8cac8db3c30dfbc9b7140f832ac15 100644
|
||||
--- a/ui/compositor/compositor.h
|
||||
+++ b/ui/compositor/compositor.h
|
||||
@@ -511,6 +511,10 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
|
||||
|
||||
const cc::LayerTreeSettings& GetLayerTreeSettings() const;
|
||||
|
||||
+ // Sets |background_throttling_| responsible for suspending drawing
|
||||
+ // and switching frames.
|
||||
+ void SetBackgroundThrottling(bool background_throttling_enabled);
|
||||
+
|
||||
private:
|
||||
friend class base::RefCounted<Compositor>;
|
||||
friend class TotalAnimationThroughputReporter;
|
||||
@@ -617,6 +621,12 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
|
||||
// See go/report-ux-metrics-at-painting for details.
|
||||
bool animation_started_ = false;
|
||||
|
||||
+ // Background throttling is a default Chromium behaviour. It occurs
|
||||
+ // when the |display_private_| is not visible by prevent drawing and swapping
|
||||
+ // frames. When it is disabled we are keeping |display_private_| always
|
||||
+ // visible in order to keep generating frames.
|
||||
+ bool background_throttling_ = true;
|
||||
+
|
||||
TrackerId next_throughput_tracker_id_ = 1u;
|
||||
struct TrackerState {
|
||||
TrackerState();
|
Loading…
Add table
Add a link
Reference in a new issue