Show browser frames at one frame pixel for each screen pixel
The built-in browser looked blurry at Windows display scaling above 100%. The engine rendered sharp frames, but the host stretched each frame to the surface. The stretch resampled every pixel and blended text and images. - The engine crops the extra frame edge and sends the frame scale. - The view shows each frame at its CSS size, at a device pixel edge, on its own compositor layer, with nearest-pixel sampling. - Pointer input subtracts the frame offset. - The view sends a new scale when the display scale changes. - A new smoke test, browser/scale, measures stripe contrast at 100%, 125%, 150%, and 200%, and after a scale change. It also tests click positions. Measured contrast at 150%: 92 of 255 before, 255 after. (cherry picked from commit e98a65de536111b5365d1c6f863a897a8e38e505)
This commit is contained in:
@@ -115,7 +115,7 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
|
||||
webPreferences: { ...REMOTE_PREFERENCES, session: ses, offscreen: { deviceScaleFactor: 1 }, backgroundThrottling: false } });
|
||||
win.setMenu(null);
|
||||
const item = { id, profileId, epoch: 0, view: win, title: 'Browser', favicon: null, iconRequest: null, blocked: 0, find: null, findRequest: 0,
|
||||
delivery: new FrameDelivery(), context: null, downloads: new Set(), settle: null, retryFrame: null, latestImage: null, scale: 1 };
|
||||
delivery: new FrameDelivery(), context: null, downloads: new Set(), settle: null, retryFrame: null, latestImage: null, latestScale: 1, scale: 1 };
|
||||
tabs.set(item.id, item);
|
||||
const wc = win.webContents;
|
||||
wc.setFrameRate(60); wc.setWebRTCIPHandlingPolicy('disable_non_proxied_udp');
|
||||
@@ -158,7 +158,11 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
|
||||
wc.on('did-finish-load', () => emulateViewport(item));
|
||||
wc.on('did-fail-load', (_event, code, _description, _url, main) => { if (main && code !== -3) emit({ event: 'error', tabId: item.id, message: `Page load failed (${code}).` }); });
|
||||
wc.on('paint', (_event, _dirty, image) => {
|
||||
item.latestImage = image;
|
||||
// Offscreen frames can be one pixel larger than the viewport. The host shows each frame pixel on one screen pixel, so crop the extra edge.
|
||||
const size = image.getSize(), width = Math.min(size.width, Math.round((item.viewport?.width ?? size.width) * item.scale)),
|
||||
height = Math.min(size.height, Math.round((item.viewport?.height ?? size.height) * item.scale));
|
||||
item.latestImage = width < size.width || height < size.height ? image.crop({ x: 0, y: 0, width, height }) : image;
|
||||
item.latestScale = item.scale;
|
||||
clearTimeout(item.settle);
|
||||
clearTimeout(item.retryFrame);
|
||||
const frame = (lossless = false) => {
|
||||
@@ -170,7 +174,7 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
|
||||
}
|
||||
const data = lossless ? item.latestImage.toPNG() : item.latestImage.toJPEG(90);
|
||||
if (data.length && data.length <= 4_000_000) emit({ event: 'frame', tabId: item.id, frameId: item.delivery.sent(),
|
||||
mime: lossless ? 'image/png' : 'image/jpeg', data: data.toString('base64'), ...item.latestImage.getSize() });
|
||||
mime: lossless ? 'image/png' : 'image/jpeg', data: data.toString('base64'), scale: item.latestScale, ...item.latestImage.getSize() });
|
||||
};
|
||||
frame();
|
||||
// Send a lossless final frame for sharp text when the page stops changing.
|
||||
|
||||
Reference in New Issue
Block a user