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
|
@ -1029,6 +1029,9 @@ void WebContents::InitWithWebContents(
|
|||
}
|
||||
|
||||
WebContents::~WebContents() {
|
||||
if (owner_window_) {
|
||||
owner_window_->RemoveBackgroundThrottlingSource(this);
|
||||
}
|
||||
if (web_contents()) {
|
||||
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
|
||||
if (host)
|
||||
|
@ -2226,10 +2229,15 @@ void WebContents::SetOwnerWindow(NativeWindow* owner_window) {
|
|||
|
||||
void WebContents::SetOwnerWindow(content::WebContents* web_contents,
|
||||
NativeWindow* owner_window) {
|
||||
if (owner_window_) {
|
||||
owner_window_->RemoveBackgroundThrottlingSource(this);
|
||||
}
|
||||
|
||||
if (owner_window) {
|
||||
owner_window_ = owner_window->GetWeakPtr();
|
||||
NativeWindowRelay::CreateForWebContents(web_contents,
|
||||
owner_window->GetWeakPtr());
|
||||
owner_window_->AddBackgroundThrottlingSource(this);
|
||||
} else {
|
||||
owner_window_ = nullptr;
|
||||
web_contents->RemoveUserData(NativeWindowRelay::UserDataKey());
|
||||
|
@ -2283,6 +2291,10 @@ bool WebContents::GetBackgroundThrottling() const {
|
|||
void WebContents::SetBackgroundThrottling(bool allowed) {
|
||||
background_throttling_ = allowed;
|
||||
|
||||
if (owner_window_) {
|
||||
owner_window_->UpdateBackgroundThrottlingState();
|
||||
}
|
||||
|
||||
auto* rfh = web_contents()->GetPrimaryMainFrame();
|
||||
if (!rfh)
|
||||
return;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "printing/buildflags/buildflags.h"
|
||||
#include "shell/browser/api/frame_subscriber.h"
|
||||
#include "shell/browser/api/save_page_handler.h"
|
||||
#include "shell/browser/background_throttling_source.h"
|
||||
#include "shell/browser/event_emitter_mixin.h"
|
||||
#include "shell/browser/extended_web_contents_observer.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents.h"
|
||||
|
@ -107,7 +108,8 @@ class WebContents : public ExclusiveAccessContext,
|
|||
public content::WebContentsDelegate,
|
||||
public content::RenderWidgetHost::InputEventObserver,
|
||||
public InspectableWebContentsDelegate,
|
||||
public InspectableWebContentsViewDelegate {
|
||||
public InspectableWebContentsViewDelegate,
|
||||
public BackgroundThrottlingSource {
|
||||
public:
|
||||
enum class Type {
|
||||
kBackgroundPage, // An extension background page.
|
||||
|
@ -160,7 +162,7 @@ class WebContents : public ExclusiveAccessContext,
|
|||
void Close(absl::optional<gin_helper::Dictionary> options);
|
||||
base::WeakPtr<WebContents> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
|
||||
|
||||
bool GetBackgroundThrottling() const;
|
||||
bool GetBackgroundThrottling() const override;
|
||||
void SetBackgroundThrottling(bool allowed);
|
||||
int GetProcessID() const;
|
||||
base::ProcessId GetOSProcessID() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue