[Wayland] Follow "stable rounding" algorithm for fractionaly scaled subsurfaces
Categories
(Core :: Widget: Gtk, enhancement, P3)
Tracking
()
People
(Reporter: stransky, Assigned: stransky)
References
(Blocks 1 open bug, )
Details
Attachments
(2 files, 1 external file)
I've been pointed out at https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/143#note_1343171
which suggests subsurface rounding as:
Parent position independent subsurface position rounding: Scale and round subsurface positions and add the scaled and rounded parent position afterwards (pos = round(subsurface_pos * scale) + (parent_pos * scale), making subsurface position rounding independent of the position of its parent.
Subsurface position dependent subsurface dimension rounding: Scale and round subsurface dimensions after adding the position, then substracting the position in both compositor and client (size = round((subsurface_size + subsurface_pos) * scale) - round(subsurface_pos * scale), called "scale_length" in wlroots/sway). This is only made possible due to the parent position independent rounding, as the client would otherwise not know what position to use and so the compositor and client would never be able to agree (hence why I previously referred to this as a bug).
It's claimed to work for all cases. Let's investigate it. It may save us new v2 fractional scale protocol extension.
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 1•1 year ago
|
||
Would be great to get info how Mutter/KWin actually rounds the subsurfaces now. But with latest Firefix nightly, both Kwin and Mutter produces better results than before Firefox scale fixes. There may be very slight blur on Mutter for some window sizes, will check on different monitor when it's available.
| Assignee | ||
Updated•1 year ago
|
Comment 2•1 year ago
|
||
stale -> stable
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 4•1 year ago
|
||
So let's look at the rounding here, parent_pos is always zero as we use toplevel, so:
pos = round(subsurface_pos * scale)
size = round((subsurface_size + subsurface_pos) * scale) - round(subsurface_pos * scale)
| Assignee | ||
Comment 5•1 year ago
|
||
I resized toplevel Firefox window until it's very blurry on mutter / Fedora 43 / 125% scale.
Actual Firefox rounding / subsurface sizing:
[Parent 148068: Main Thread]: D/Widget [7f1f380c2e00]: RecomputeBoundsWayland(1) GetBounds(mGdkWindow) [26,23] -> [971 x 851]
[Parent 148068: Main Thread]: V/WidgetWayland [7f1f380c2e00]: WaylandSurface::GetScale() fractional scale 1.250000
[Parent 148068: Main Thread]: D/Widget [7f1f380c2e00]: nsWindow::DispatchResized() client size [1213, 1064]
[Parent 148068: Main Thread]: D/Widget [7f1f380c2e00]: GtkCompositorWidget::NotifyClientSizeChanged() to 1213 x 1064
recalc according to stable algorithm:
pos = [26,23] -> [32.5, 28.75]
size = round([1246.25, 1092.5]) - round ([32.5, 28.75]) = [1246,1093] - [33,29] = [1213, 1064]
so Firefox produces the same values (for one subsurface placed at [26,23]) but mutter fails to follow it and produces extra blurry output.
| Assignee | ||
Comment 6•1 year ago
|
||
Unfortunately I can't catch the difference on screenshot - mutter blurs the fonts when trying to get one.
| Assignee | ||
Comment 7•1 year ago
|
||
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 8•1 year ago
|
||
Hold a moment here - I found another rounding bug in Firefox EGL window size. Will investigate first (related to Bug 1988717).
Comment 9•1 year ago
|
||
(In reply to Martin Stránský [:stransky] (ni? me) from comment #1)
Would be great to get info how Mutter/KWin actually rounds the subsurfaces now. But with latest Firefix nightly, both Kwin and Mutter produces better results than before Firefox scale fixes. There may be very slight blur on Mutter for some window sizes, will check on different monitor when it's available.
regarding kwin, it's
subsurface_top_left_x = round(subsurface.x * scale)
subsurface_top_left_y = round(subsurface.y * scale)
subsurface_bottom_right_x = subsurface_top_left_x + round(subsurface.width * scale)
= round(subsurface.x * scale) + round(subsurface.width * scale)
subsurface_bottom_right_y = subsurface_top_left_y + round(subsurface.height * scale)
= round(subsurface.y * scale) + round(subsurface.height * scale)
if it's a grand child surface (grandparent <- parent <- subsurface)
subsurface_top_left_x = round(grandparent.x * scale) + round(parent.x * scale) + round(subsurface.x * scale)
subsurface_top_left_y = round(grandparent.y * scale) + round(parent.y * scale) + round(subsurface.y * scale)
subsurface_bottom_right_x = subsurface_top_left_x + round(subsurface.width * scale)
= round(grandparent.x * scale) + round(parent.x * scale) + round(subsurface.x * scale) + round(subsurface.width * scale)
subsurface_bottom_right_y = subsurface_top_left_y + round(subsurface.height * scale)
= round(grandparent.y * scale) + round(parent.y * scale) + round(subsurface.y * scale) + round(subsurface.height * scale)
kwin rounds the position at every level in the scene graph up until the root node
Comment 10•1 year ago
•
|
||
if firefox makes x, y, w, and h of each surface integers (no fractions) after scaling, is it still matter how or when the compositor rounds? Usually, scale factor are 1.25, 1.5, 2.0, ... rational numbers.
Updated•1 year ago
|
| Assignee | ||
Comment 11•1 year ago
|
||
(In reply to Thinker Li [:sinker] from comment #10)
if firefox makes x, y, w, and h of each surface integers (no fractions) after scaling, is it still matter how or when the compositor rounds? Usually, scale factor are 1.25, 1.5, 2.0, ... rational numbers.
The problem here is subsurface rounding while toplevel window has different size than the subsurface (child) and we need to match both together with the fractional scale.
Comment 12•1 year ago
|
||
Unfortunately I can't catch the difference on screenshot - mutter blurs the fonts when trying to get one.
Screenshots with fractional scaling enabled are kinda tricky on GNOME. You should:
- Ensure all monitors are using the same scale factor, if you have multiple monitors
- Use the "Selection" or "Screen" selection method, not "Window"
That was you get a screenshot which is a 1:1 mapping to physical pixels on the display.
If you use the "window" selection method, Mutter will take an "unscaled" screenshot of the window by using the buffer size of the toplevel surface as the screenshot image size. With Firefox, the toplevel is at an integer scale because that's what Gtk 3 supports, so the fractionally scaled subsurface will get upscaled to match.
Comment 13•11 months ago
|
||
Hold a moment here - I found another rounding bug in Firefox EGL window size. Will investigate first (related to Bug 1988717).
I just got an update on Nightly to build 20251125095327, and I found that it seems to make the rounding behaviour worse on GNOME, specifically in the vertical direction. It looks like (at 150% scale) at some vertical window sizes the top of the Firefox subsurface is placed 1 logical pixel too low, and is downscaled vertically to be 1 logical pixel smaller.
Comment 14•11 months ago
|
||
Screenshot of Firefox nightly 20251125095327 with blurred content on GNOME 49 (Fedora 43) at 150% fractional scaling.
There is a 2 physical pixel gap between the window shadow and the top of the firefox subsurface, and a 1 physical pixel gap between the window shadow and the bottom of the firefox subsurface. The window contents are blurred vertically due to buffer size mismatch (I think the buffer is 1px taller than Mutter thinks it should be, so it's downscaled by 1px)
Comment 15•11 months ago
|
||
Same window, but resized vertically slightly. At this window size there is a 1 physical pixel gap visible between the shadow and the top of the firefox subsurface, and no gap at the bottom of the window. The contents of the subsurface are sharp (Mutter and Firefox agree on the buffer size)
| Assignee | ||
Comment 16•11 months ago
|
||
Thanks. If you run it on terminal with MOZ_LOG="Widget:5,WidgetWayland:5" env variables you can check how the subsurface is placed by firefox.
| Assignee | ||
Comment 17•11 months ago
|
||
Looks like we compute the WaylandSurface size wrongly - without subsurface origin. Should be 1603 but we pass 1604.
[Parent 132826: Main Thread]: D/Widget [7fdc1c96db00]: RecomputeBoundsWayland(1) GetBounds(mGdkWindow) [26,23] -> [1283 x 1040]
[Parent 132826: Main Thread]: D/Widget [7fdc1c96db00]: nsWindow::DispatchResized() client scaled size [1603, 1300]
[Parent 132826: Main Thread]: V/WidgetWayland [7fdc1c96db00]: WaylandSurface::SetSize() size [1283 x 1040] scale 1.250000 scaled [1604 x 1300]
| Assignee | ||
Comment 18•11 months ago
|
||
Looks like I need to rework the WaylandSurface sizing a bit to consider subsurface position for sizing/rounding.
| Assignee | ||
Comment 19•11 months ago
|
||
Vlad, do you think Kwin may also use the 'stable' [1] rounding if Mutter/Sway(WLRoots) use that? It looks promising and would be great to have all three major compositors on the same boat here.
I'd like to fix all issues for Firefox 147+ to have sharp fractional rendering there with it implemented. (but it's not finished yet - I'd like to just keep you up to date).
[1] https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/143#note_1343171
| Assignee | ||
Updated•11 months ago
|
| Assignee | ||
Comment 20•11 months ago
|
||
KWin claims to use stable already.
| Assignee | ||
Updated•11 months ago
|
| Assignee | ||
Comment 21•11 months ago
|
||
Comment 22•11 months ago
|
||
Got build failure with this type conversion error trying to build with the attachment:
30:29.82 /var/tmp/portage/www-client/firefox-147.0_beta0/work/firefox-147.0/widget/gtk/WaylandSurface.cpp:1098:41: error: cannot convert 'mozilla::DesktopIntRect' {aka 'mozilla::gfx::IntRectTyped<mozilla::DesktopPixel>'} to 'mozilla::DesktopIntSize' {aka 'mozilla::gfx::IntSizeTyped<mozilla::DesktopPixel>'}
30:29.82 1098 | SetViewPortDestLocked(aSurfaceLock, viewportSize);
30:29.82 | ^~~~~~~~~~~~
30:29.82 | |
30:29.82 | mozilla::DesktopIntRect {aka mozilla::gfx::IntRectTyped<mozilla::DesktopPixel>}
Updated•11 months ago
|
| Assignee | ||
Updated•11 months ago
|
Comment 23•11 months ago
|
||
Comment 24•11 months ago
|
||
| bugherder | ||
| Assignee | ||
Comment 25•11 months ago
|
||
Not sure what's going on but tested on my office monitor and it's broken/blurred on both KDE and Mutter now...so not a great improvement.
| Assignee | ||
Comment 26•11 months ago
|
||
Resize artifacts affects EGLWindow only - filed Bug 2004002 for it.
| Assignee | ||
Comment 27•11 months ago
|
||
Release Note Request (optional, but appreciated)
[Why is this notable]: Updates window and rendering surface sizes to match actual pixel grid so Firefox delivers sharp rendering on fractionally scaled displays regardless of actual window size.
[Affects Firefox for Android]:
[Suggested wording]:
[Links (documentation, blog post, etc)]:
Comment 28•11 months ago
|
||
Added to the Fx147 relnotes.
For Linux GNOME Mutter users, window and rendering surface sizes were updated to match the actual pixel grid so Firefox delivers sharp rendering on fractionally scaled displays regardless of actual window size.
| Assignee | ||
Comment 29•11 months ago
|
||
(In reply to Ryan VanderMeulen [:RyanVM] from comment #28)
Added to the Fx147 relnotes.
For Linux GNOME Mutter users, window and rendering surface sizes were updated to match the actual pixel grid so Firefox delivers sharp rendering on fractionally scaled displays regardless of actual window size.
When Bug 2005160 is fixed it will work for KDE too.
Description
•