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.
This commit is contained in:
xdavidwu
2020-03-06 14:03:45 +08:00
committed by GitHub
parent db78b3a28c
commit 1bd626ffbc

View File

@@ -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