From f943b8c940386f196a10cf490ad9122d83ec59f5 Mon Sep 17 00:00:00 2001 From: Bruno Henrique da Silva Date: Wed, 27 Sep 2023 11:42:46 -0300 Subject: [PATCH] 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 --- .../ui/win/electron_desktop_window_tree_host_win.cc | 10 ++++++++++ .../ui/win/electron_desktop_window_tree_host_win.h | 1 + 2 files changed, 11 insertions(+) diff --git a/shell/browser/ui/win/electron_desktop_window_tree_host_win.cc b/shell/browser/ui/win/electron_desktop_window_tree_host_win.cc index dbed46d56e..d60675f31f 100644 --- a/shell/browser/ui/win/electron_desktop_window_tree_host_win.cc +++ b/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 diff --git a/shell/browser/ui/win/electron_desktop_window_tree_host_win.h b/shell/browser/ui/win/electron_desktop_window_tree_host_win.h index 1901cad02f..2c627ceeb0 100644 --- a/shell/browser/ui/win/electron_desktop_window_tree_host_win.h +++ b/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 native_window_view_; // weak ref