Skip to content

Commit

Permalink
[HTML5] Fix DPI-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 26, 2022
1 parent 7ffa86c commit a0db16d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Backends/HTML5/kha/SystemImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,22 @@ class SystemImpl {

if (canvas.getContext != null) {
if (lastCanvasClientWidth != canvas.clientWidth || lastCanvasClientHeight != canvas.clientHeight) {
// canvas.width is the actual backbuffer-size.
// canvas.clientWidth (which is read-only and equivalent to
// canvas.style.width in pixels) is the output-size
// and by default gets scaled by devicePixelRatio.
// We revert that scale so backbuffer and output-size
// are the same.

var scale = Browser.window.devicePixelRatio;
canvas.width = Std.int(canvas.clientWidth * scale);
canvas.height = Std.int(canvas.clientHeight * scale);
var clientWidth = canvas.clientWidth;
var clientHeight = canvas.clientHeight;
canvas.width = clientWidth;
canvas.height = clientHeight;
if (scale != 1) {
canvas.style.width = Std.int(clientWidth / scale) + "px";
canvas.style.height = Std.int(clientHeight / scale) + "px";
}
lastCanvasClientWidth = canvas.clientWidth;
lastCanvasClientHeight = canvas.clientHeight;
}
Expand Down

0 comments on commit a0db16d

Please sign in to comment.