-
Notifications
You must be signed in to change notification settings - Fork 279
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
Possibly outdated examples: LayoutSize
should be equal to DeviceSize
in value?
#4759
Comments
Layout coordinates are in a local space (relative to their parent transform), while device coordinates are global they should have all transformations applied and should map to actual pixels. WebRender initially had a global scale factor which was applied towards the end of the rendering pipeline, but as mentioned in the commit you linked, it was difficult to handle pixel snapping correctly (at least for the requirements of the browser), and we ended up removing it. What Firefox does (and by extension what I'd recommend doing), is to apply the window's scaling via a transform in the display list. |
Thanks for the clarification! I managed to fix the problem following your advice. By the way, do you think the examples could also be improved by adopting this transformation? Also, the default window size is currently set to 1920x1080 (logical), which is probably too big. On my laptop for example, I have a 2560x1440 screen with Windows global scale factor set to 1.5, so the window is larger than my whole display area. The template in |
given that I'm new to webrender and have just run into exactly this, +1 for a transformation example. |
I am currently experimenting with WebRender, and I am following the examples. Specifically, I replicated the logic in
examples/boilerplate.rs
and had some problems with the following line:webrender/examples/common/boilerplate.rs
Line 195 in d451d22
Since methods like
DisplayListBuilder::push_rect
acceptsLayoutSize
as well, I presume that they should also be scaled in the same manner. Here is what my toy example looks like (on Windows 11):Note: 1.5 is the system scale factor. The two versions differ in the way
DeviceSize
is transformed intoLayoutSize
. The left one usesScale::new(window.scale_factor() as f32)
, and the right one usesScale::identity()
.The reddish rectangle has bounds
LayoutRect::from_size(layout_size)
, and the text is laid out with the same bounds. It should be clear from the screenshot that in thescale = 1.0
version the rectangle is correctly covering the whole window, while thescale = 1.5
version is incorrectly scaled down.Searching in this repository I found 25f674b, where the
device_pixel_ratio
option is removed fromWebRenderOptions
, and uses of such value is replaced by a hardcoded1.0
.Now I wonder, is the examples doing the correct thing? To add to the point, I see an extremely large window (larger than my screen so I cannot take a screenshot) when I
cargo run --bin basic
. Could someone please educate me on thisLayoutSize
/DeviceSize
/Scale
situation? Thanks in advance!The text was updated successfully, but these errors were encountered: