#53813: fix: give captured page images their device scale factor
Description of Change
Stacked on #53810.
capturePage(), the offscreen paint event and beginFrameSubscription() wrapped their bitmaps with CreateFrom1xBitmap, so the image always claimed a scale factor of 1. On a HiDPI display, or with offscreen.deviceScaleFactor, getSize() returned pixels and the image displayed at the wrong size.
- Mark each image with the view's device scale factor.
getSize(),crop()andresize()are now in DIPs;toBitmap(),toPNG(),toJPEG()andtoDataURL()still return every pixel. - Fix
nativeImage.toJPEG()returning an empty buffer for images with no 1x representation (already broken forcreateFromBitmap(..., { scaleFactor: 2 })). Separate commit, can be split out and backported. - Breaking change entry under 46.0.
| 400×300 window on a 2x display | before | after |
|---|---|---|
getSize() |
800×600 | 400×300 |
getScaleFactors() |
[1] |
[2] |
toPNG() pixels |
800×600 | 800×600 |
Checklist
- PR description included
- I have built and tested this PR
-
npm testpasses - tests are changed or added
- relevant API documentation is changed or added
Release Notes
Notes: webContents.capturePage(), the offscreen paint event and webContents.beginFrameSubscription() now return images with the page's device scale factor, so image.getSize() is in DIPs rather than pixels on HiDPI displays. Also fixed nativeImage.toJPEG() returning an empty buffer for images without a 1x representation.
Backports
No Backports Requested
This pull request doesn't have any backports requested or created for older release branches.
What are backports?
Backports are copies of changes made to the main branch that are applied to older release branches. They ensure that bug fixes and important changes are available in maintained older versions of Electron.
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron