forked from electron/electron
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Disable compositor recycling only for attached views
In electron#19873, we completely disabled compositor recycling. This has adverse effects in our tabbed app where switching tabs (i.e. `BrowserView`s) now results in a flicker because we now also switch compositors. To fix this without regressing the original fix, we now recycle the compositor when the view is removed from a window or explicitly marked as hidden. These can only happen with `BrowserView`s so `BrowserWindow`s are unaffected.
- Loading branch information
Showing
1 changed file
with
17 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Andy Locascio <andy@slack-corp.com> | ||
Date: Wed, 21 Aug 2019 12:09:10 -0700 | ||
From: Birunthan Mohanathas <birunthan@mohanathas.com> | ||
Date: Tue, 29 Oct 2019 09:35:45 -0600 | ||
Subject: fix: disabling compositor recycling | ||
|
||
Compositor recycling is useful for Chrome because there can be many tabs and spinning up a compositor for each one would be costly. In practice, Chrome uses the parent compositor code path of browser_compositor_view_mac.mm; the NSView of each tab is detached when it's hidden and attached when it's shown. For Electron, there is no parent compositor, so we're forced into the "own compositor" code path, which seems to be non-optimal and pretty ruthless in terms of the release of resources. Electron has no real concept of multiple tabs per window, so it should be okay to disable this ruthless recycling altogether in Electron. | ||
|
||
diff --git a/content/browser/renderer_host/browser_compositor_view_mac.mm b/content/browser/renderer_host/browser_compositor_view_mac.mm | ||
index 8ddd790decc43af9820c97121a3b359e7cbb49ee..41269301e92d96757066229842333c8981994234 100644 | ||
--- a/content/browser/renderer_host/browser_compositor_view_mac.mm | ||
+++ b/content/browser/renderer_host/browser_compositor_view_mac.mm | ||
@@ -203,7 +203,7 @@ | ||
} | ||
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm | ||
index 32f3f2cceb742065db8b52a9f6aa814cfc30f955..c96b53d3123b933f316865e2af7dfca433b65ce9 100644 | ||
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm | ||
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm | ||
@@ -486,7 +486,12 @@ | ||
return; | ||
|
||
void BrowserCompositorMac::SetRenderWidgetHostIsHidden(bool hidden) { | ||
- render_widget_host_is_hidden_ = hidden; | ||
+ render_widget_host_is_hidden_ = false; | ||
UpdateState(); | ||
host()->WasHidden(); | ||
- browser_compositor_->SetRenderWidgetHostIsHidden(true); | ||
+ // Consider the RWHV occluded only if's explicitly marked hidden or if it | ||
+ // is not attached to window (e.g. unattached BrowserView). Otherwise we | ||
+ // treat it as visible to prevent unnecessary compositor recycling. | ||
+ const bool unattached_or_hidden = | ||
+ ![GetInProcessNSView() window] || [GetInProcessNSView() hidden]; | ||
+ browser_compositor_->SetRenderWidgetHostIsHidden(unattached_or_hidden); | ||
} | ||
|
||
void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { |