1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #105585 from marcosc90/fix-web-update-size

[Web] Prevent unnecessary canvas resizes by flooring scaled dimensions
This commit is contained in:
Thaddeus Crews
2025-05-14 09:44:13 -05:00

View File

@@ -306,11 +306,11 @@ const GodotDisplayScreen = {
const scale = GodotDisplayScreen.getPixelRatio(); const scale = GodotDisplayScreen.getPixelRatio();
if (isFullscreen || wantsFullWindow) { if (isFullscreen || wantsFullWindow) {
// We need to match screen size. // We need to match screen size.
width = window.innerWidth * scale; width = Math.floor(window.innerWidth * scale);
height = window.innerHeight * scale; height = Math.floor(window.innerHeight * scale);
} }
const csw = `${width / scale}px`; const csw = `${Math.floor(width / scale)}px`;
const csh = `${height / scale}px`; const csh = `${Math.floor(height / scale)}px`;
if (canvas.style.width !== csw || canvas.style.height !== csh || canvas.width !== width || canvas.height !== height) { if (canvas.style.width !== csw || canvas.style.height !== csh || canvas.width !== width || canvas.height !== height) {
// Size doesn't match. // Size doesn't match.
// Resize canvas, set correct CSS pixel size, update GL. // Resize canvas, set correct CSS pixel size, update GL.