From 1bd626ffbcfe9b6223a16dc8cfd460def1a7b44a Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Fri, 6 Mar 2020 14:03:45 +0800 Subject: [PATCH] tab: support hidpi device (#106) This commit make canvas in full device pixel size and set proper scale on it, so that drawWindow draws all pixels instead of scaling down to normal dpi. --- ext/src/senders/mirroring.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ext/src/senders/mirroring.ts b/ext/src/senders/mirroring.ts index f4ead03..1d3fb2e 100644 --- a/ext/src/senders/mirroring.ts +++ b/ext/src/senders/mirroring.ts @@ -81,13 +81,16 @@ async function onRequestSessionSuccess (newSession: cast.Session) { } // Set initial size - canvas.width = window.innerWidth; - canvas.height = window.innerHeight; + canvas.width = window.innerWidth * window.devicePixelRatio; + canvas.height = window.innerHeight * window.devicePixelRatio; + ctx.scale(window.devicePixelRatio, window.devicePixelRatio); // Resize canvas whenever the window resizes window.addEventListener("resize", () => { - canvas.width = window.innerWidth; - canvas.height = window.innerHeight; + canvas.width = window.innerWidth * window.devicePixelRatio; + canvas.height = window.innerHeight * window.devicePixelRatio; + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.scale(window.devicePixelRatio, window.devicePixelRatio); }); // TODO: Test performance