-
Notifications
You must be signed in to change notification settings - Fork 946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect change of devicePixelRatio (hidpi scaling) on web target #1659
Detect change of devicePixelRatio (hidpi scaling) on web target #1659
Conversation
I was reading the long thread in the WebGL repo and it seems that there is finally a way to get a 1-to-1 pixel-accurate canvas: KhronosGroup/WebGL#2460 (comment) (check the linked comment and several after). It relies on The downside is that this API is pretty new so not very widespread, and it also requires sizing based on a parent element. |
Feel free to stub out the |
@ryanisaacg How would you suggest to handle the But then a problem arises. The canvas element automatically keeps its logical size in CSS pixels when the An alternative is that we defer all the above until Still, if a program relies on |
Let me know if this doesn't work, it's been a little while since I had to dig around in the event handling internals:
This probably will require some custom logic in the event handling internals, because it is the only event that passes a mutable value and reacts based on the result. Additionally, for the reasons you mentioned, it's probably best to not wait for the control flow to pick up the method (because we don't want this sitting in a queue and the newer events getting stale.) This means that you'll want a custom event-scheduling method just for scale factor changes, which may be nontrivial work. |
@ryanisaacg thanks for the suggestion. I think this should be doable, but as the docs for
Sending all events when |
Yup, in this case the docs are descriptive and not prescriptive. |
I decided to create a new PR #1690 since it has become quite different. |
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to usersThe WASM web target did not handle change of the
devicePixelRatio
(changing the browser zoom level also causes it to change). This results in the canvas becoming wonky.The change of
devicePixelRatio
can be detected using aMediaQueryList
, so this is what I used. The tricky part is that a media query can only be used to detect whether a specificdevicePixelRatio
matches, which means a newMediaQueryList
will be needed whenever the scaling has changed. I added a helper typeDevicePixelRatioChangeDetector
to manage this.Outstanding issues:
console.log
debug messagesnew_inner_size
field inWindowEvent::ScaleFactorChanged
I have no idea how it should be handled.
Fix issue where canvas become blurry at certain scales?It seems that whenever the CSS width/height in pixels is not an integer, the canvas becomes blurry in that dimension (e.g. when
devicePixelRatio == 1.3333333333333333
and the physical width is1067
, the CSS width becomes800.25
and the rendering is somehow not aligned to the physical pixels). I do wonder if it is more appropriate to handle this in a separate PR.Edit: I just realized that this is probably due to
winit
not firingWindowEvent::Resized
events that could be causing some of the UI code to lay out things incorrectly. However I don't believe this is the only reason.Edit 2: False alarm, after adding
WindowEvent::Resized
it seems to work fine.Also make the change forstdweb
Would be nice if someone else can do it as I really don't know if I can make the change correctly for
stdweb
.Is there a possibility for this change to be implemented forweb-sys
only at first and stub out thestdweb
side and fix it later in a separate PR?stdweb
.This change is incomplete but functionally working on
web-sys
. I would really like some comments and pointers.