Browse Source

fix: set window contents as opaque to decrease DWM GPU usage (#39895)

* set window contents as opaque to decrease DWM GPU usage

* chore: add more context to ShouldWindowContentsBeTransparent
Bruno Henrique da Silva 1 year ago
parent
commit
f943b8c940

+ 10 - 0
shell/browser/ui/win/electron_desktop_window_tree_host_win.cc

@@ -133,4 +133,14 @@ void ElectronDesktopWindowTreeHostWin::OnNativeThemeUpdated(
   }
 }
 
+bool ElectronDesktopWindowTreeHostWin::ShouldWindowContentsBeTransparent()
+    const {
+  // Window should be marked as opaque if no transparency setting has been set,
+  // otherwise videos rendered in the window will trigger a DirectComposition
+  // redraw for every frame.
+  // https://github.com/electron/electron/pull/39895
+  return native_window_view_->GetOpacity() < 1.0 ||
+         native_window_view_->transparent();
+}
+
 }  // namespace electron

+ 1 - 0
shell/browser/ui/win/electron_desktop_window_tree_host_win.h

@@ -40,6 +40,7 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
 
   // ui::NativeThemeObserver:
   void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
+  bool ShouldWindowContentsBeTransparent() const override;
 
  private:
   raw_ptr<NativeWindowViews> native_window_view_;  // weak ref