-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: set window contents as opaque to decrease DWM GPU usage #39895
fix: set window contents as opaque to decrease DWM GPU usage #39895
Conversation
Thanks for the detailed analysis! In case of Electron the title bar are system drawn unlike Chrome, so we get the default behavior defined in https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc;l=533-538. Do we regress with undrawn regions in the titlebar with this change ? |
Yeah I got a bit confused by that comment because I couldn't remember of any app that draws underneath the title bar. Looking further back the commit history, this setting seems to originally come from a requirement from Aero Glass (removed on W8+) Maybe this could be an issue if there was some code using Tried this PR with |
@brhenrique can you rebase on latest main to pull in the depot_tools CI fixes |
50aa344
to
3f40d82
Compare
@MarshallOfSound sure, done. Now |
Release Notes Persisted
|
I have automatically backported this PR to "27-x-y", please check out #40003 |
…n#39895) * set window contents as opaque to decrease DWM GPU usage * chore: add more context to ShouldWindowContentsBeTransparent
Description of Change
The window contents of Electron windows are marked as transparent even though neither
transparent
noropacity
settings are set in theBrowserWindow
options.Debugging DirectComposition redraws
Chromium 118 has a new flag called
DCompDebugVisualization
that uses EnableDrawRegions to display on the screen sections of a window that are redrawn by DirectComposition.The problem
With
DCompDebugVisualization
, we can notice a difference in the frequency of redraws of<video>
elements in Chromium compared to a regular non-transparent window in Electron.While a video stream is rendered on screen, almost no redraws are displayed in Chromium. On Electron, a redraw is displayed for every video frame rendered.
Electron Fiddle gist: https://gist.github.com/brhenrique/100fc28409508d1730fb4216268cf04a
Why it happens?
When the contents of the window are set to be transparent,
DirectCompositionChildSurfaceWin::SetDrawRectangle
will useDXGI_ALPHA_MODE_PREMULTIPLIED
instead ofDXGI_ALPHA_MODE_IGNORE
. This will trigger the DC redraw for every video frame.Solution
If neither
transparent
noropacity
settings are used with aBrowserWindow
, it seems safe to assume the contents of the BrowserWindow won't need alpha blending with other windows. So in this PR we overrideShouldWindowContentsBeTransparent
to take into account the transparency and opacity settings of the native window.Results
Rendering 4 480p video elements in a blank opaque non-fullscreen Electron window on a 2160p display
Before: DWM uses 16-18% GPU
After: DWM uses less than 1%
Rendering 4 480p video elements in a blank opaque non-fullscreen Electron window on a 1080p display
Before: DWM uses 6-8% GPU
After: DWM uses less than 1%
Checklist
npm test
passesRelease Notes
Notes: prevent DWM from redrawing video frames rendered on opaque windows