-
Notifications
You must be signed in to change notification settings - Fork 932
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
Implement hidpi for web platform #1233
Conversation
src/platform_impl/web/web_sys/mod.rs
Outdated
match document.fullscreen_element() { | ||
Some(elem) => { | ||
let raw: Element = canvas.clone().into(); | ||
raw == elem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was causing a build error (that Element
does not implement PartialEq
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, that's odd. I don't seem to have the same error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll get back to you with my specific versions when I can, but at the time of writing, I had a "clean" lockfile.
Hi, and thanks for working on this. Congratulations on the first PR! Could you rebase this against the |
@Osspial I sure can. Please don't block merging the revamp on this PR--I'm happy to keep this changelist up to date wherever it needs to be, but free time seems to elude me 😕. I'd like to also implement the hidpifactorchanged event as a part of this, as well. I'm also planning on at least hacking together some end-to-end tests that use gfx to do some rasterization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! If you don't have time to rebase against dpi-overhaul, I'll give it a shot if I get a chance.
src/platform_impl/web/web_sys/mod.rs
Outdated
match document.fullscreen_element() { | ||
Some(elem) => { | ||
let raw: Element = canvas.clone().into(); | ||
raw == elem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, that's odd. I don't seem to have the same error?
src/platform_impl/web/stdweb/mod.rs
Outdated
@@ -41,6 +41,14 @@ pub fn window_size() -> LogicalSize { | |||
LogicalSize { width, height } | |||
} | |||
|
|||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio | |||
// TODO: Use media queries to register changes in dpi: https://jsfiddle.net/b6zcg24u/ | |||
// TODO: Where does winit handle DPI changes? we can resize the "backbuffer" (canvas element), but isn't that usually handled by e.g. gfx? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing the "backbuffer" and emitting a DPI change event is sufficient here.
The race is on! I'm hoping to have some time in the next week or so, but please don't wait on me! |
I've rebased my changes onto dpi-overhaul, but web builds on that branch don't seem to be building for me? e.g. dpi-overhaul with I'll take a close look next chance I have, but it unfortunately delays this PR |
@Osspial I'm making some progress on this, but it seems that the dpi overhaul adds a lifetime to |
Afaik, after giving a904386 a quick skim, I'd annotate everything with |
@tangmi Annotating everything with It may be worth modifying enum HiDpiFactorWindowSizeChange<'a> {
Modifiable(&'a mut Option<PhysicalSize<u32>>),
Imposed(PhysicalSize<u32>)
} That way, we can tell the user when the OS is imposing a size change that the user cannot modify. IIRC Wayland has an API along those lines (cc @vberger) as well. |
Hi all! I haven't had time recently to work on this, I apologize! I still do intend to do this work (if nobody else does it first) and polish this PR, hopefully soon! |
Hey @tangmi, it has been a while since we've heard from you. Just checking to make sure everything is alright. Also, merry Christmas! |
Hi @goddessfreya! I'm still around, thanks for checking in 😄! I've been caught up in my day job, but I'm putting some more work into this over the holidays. Currently:
I'm working on resolving compilation errors and auditing each of the web DPI-related functions. Happy holidays! |
@tangmi It looks like the web backend, for most practical purposes, is completely safe Rust! If it compiles, you shouldn't have to worry about soundness issues. |
@tangmi I'm hoping to try and get the full |
I think I can, but I might be cutting it close! Currently I have both web backends building, I'm going to go over my original dpi changes to make sure they're correct. I think I'm going to leave off the "DPI changed" to a later PR |
Don't worry about updating the DPI module docs - I'll manage that |
@ryanisaacg would you be able to do another review pass on this? |
Thanks, I'll clean up this PR a bit, but won't touch the docs. Some points I think may be important for the DPI docs (or on
|
src/platform_impl/web/window.rs
Outdated
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { | ||
// todo: not supported? | ||
// Ok(*self.position.borrow()) | ||
Err(NotSupportedError::new()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why mark as not supported?
FYI will affect/be affected by #1334 |
We can go ahead and merge #1334 after this. It should be a pretty simple change to get this branch's changes working with that. |
…sition in the viewport
Whoops, forgot to mark this as "ready to review". I think I'm happy with the changes here, but don't hesitate to request changes--I'll hopefully get to them shortly after the new year. Happy new years! |
This is great, thanks! |
* fix: use a 'static lifetime for the web backend's `Event` types * implement hidpi for stdweb (web-sys wip?) * fix: make all canvas resizes go through backend::set_canvas_size * update Window docs for web, make `inner/outer_position` return the position in the viewport
* fix: use a 'static lifetime for the web backend's `Event` types * implement hidpi for stdweb (web-sys wip?) * fix: make all canvas resizes go through backend::set_canvas_size * update Window docs for web, make `inner/outer_position` return the position in the viewport
* fix: use a 'static lifetime for the web backend's `Event` types * implement hidpi for stdweb (web-sys wip?) * fix: make all canvas resizes go through backend::set_canvas_size * update Window docs for web, make `inner/outer_position` return the position in the viewport
* fix: use a 'static lifetime for the web backend's `Event` types * implement hidpi for stdweb (web-sys wip?) * fix: make all canvas resizes go through backend::set_canvas_size * update Window docs for web, make `inner/outer_position` return the position in the viewport
* fix: use a 'static lifetime for the web backend's `Event` types * implement hidpi for stdweb (web-sys wip?) * fix: make all canvas resizes go through backend::set_canvas_size * update Window docs for web, make `inner/outer_position` return the position in the viewport
I believe both backends are implemented, but I'm not sure if just the output I'm seeing from doing
cargo web start ...
indicates it's working.This change set it based on the MDN docs for
Window.devicePixelRatio
and this JSFiddle.Some points:
Window.devicePixelRatio
to get thehidpi_factor
hidpi_factor
changes usingmatchMedia
(JSFiddle prototype here https://jsfiddle.net/b6zcg24u/)devicePixelRatio
winit
needs an example that outputs graphics to test this?dpi
mod docs!cargo fmt
has been run on this branchCHANGELOG.md
if knowledge of this change could be valuable to users