Open Bug 2073312 Opened 2 months ago Updated 10 days ago

Wayland opaque region is sometimes too small with fractional scaling

Categories

(Core :: Widget: Gtk, defect)

Firefox 155
defect

Tracking

()

ASSIGNED

People

(Reporter: xaver.hugl, Assigned: stransky, NeedInfo)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 external file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:155.0) Gecko/20100101 Firefox/155.0

Steps to reproduce:

Run Firefox with

WAYLAND_DEBUG=1 firefox 2>&1 | grep -E 'opaque|region|set_destination'
and slowly resize it.
The scale of my screen is set to 160%, in case it matters.

Actual results:

With some sizes, the opaque region is off by one pixel, which prevents offloading the surface to an underlay:

[23:36:46.632717] {Default Queue} -> wl_compositor#4.create_region(new id wl_region#99)
[23:36:46.632719] {Default Queue} -> wl_region#99.add(0, 0, 1713, 1056)
[23:36:46.632721] {Default Queue} -> wl_surface#74.set_opaque_region(wl_region#99)
[23:36:46.632723] {Default Queue} -> wl_region#99.destroy()
[23:36:46.636767] {Default Queue} -> wp_viewport#73.set_destination(1714, 1056)

Expected results:

The opaque region should match the surface size.

The Bugbug bot thinks this bug should belong to the 'Core::Widget: Gtk' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Widget: Gtk
Product: Firefox → Core
Severity: -- → S3

Looks like a rounding error. Xaver, does it help if we create opaque region larger than the surface as a workaround?
Thanks.

Flags: needinfo?(stransky)
Flags: needinfo?(xaver.hugl)

Yeah, if you know the whole surface is opaque, you can set the opaque region to something like -INT_MIN/2, -INT_MIN/2, INT_MAX, INT_MAX and the compositor will clip it as needed.

Flags: needinfo?(xaver.hugl)

The current code is rounding in to get a smaller region for safety. If an opaque region is too large, the compositor may ignore the alpha channel of pixels wrongly on edges. So, we may need to consider if the window is maximized to have no shadow and round corners, and make opaque region taking whole surface if the window is maximized, no shadow and round corners.

Xaver, can you please run on terminal with MOZ_LOG="Widget:5,WaylandWayland:5" reproduce the issue and attach the log here?
I guess we're talking about toplevel and fullscreen/maximized state, right?
Thanks.

Flags: needinfo?(stransky) → needinfo?(xaver.hugl)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #5)

Xaver, can you please run on terminal with MOZ_LOG="Widget:5,WaylandWayland:5" reproduce the issue and attach the log here?
Sure.

I guess we're talking about toplevel and fullscreen/maximized state, right?
Yes, toplevel, but not maximized or fullscreen (though they might also be affected). This is windowed mode with a server side decoration.

Flags: needinfo?(xaver.hugl)
Attached file firefox-log.txt —

I resized Firefox to a size where it would trigger the issue, then closed it and started it again with the debug flag set

(In reply to Xaver Hugl from comment #6)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #5)

Xaver, can you please run on terminal with MOZ_LOG="Widget:5,WaylandWayland:5" reproduce the issue and attach the log here?
Sure.

I guess we're talking about toplevel and fullscreen/maximized state, right?
Yes, toplevel, but not maximized or fullscreen (though they might also be affected). This is windowed mode with a server side decoration.

server side decoration? Do we really use that? I expect we're running in CSD by default i.e. the decoration is painted by us (but by Gtk underlying window). Firefox manages only the overlay GdkWindow.

I guess browser.tabs.inTitlebar=0. I have saw some people prefer not having tabs in the titlebar.

browser.tabs.inTitlebar only switches widget titlebar rendering by Gtk3 but doesn't change toplevel decoration style.

Flags: needinfo?(xaver.hugl)

Theres' the relevant part:

nsWindow::ResizeInt w:1652 h:1023
resized 0 aSize [1652, 1023] mLastSizeRequest [1652, 1023] bounds [1652, 1023]
   not moved or resized, quit
nsWindow::GetRestoredBounds() (x=0, y=0, w=2643, h=1637)
nsWindow::UpdateOpaqueRegionInternal() set opaque region [0,0] -> [1651 x 1023]
Flags: needinfo?(xaver.hugl)
Assignee: nobody → stransky
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

server side decoration? Do we really use that? I expect we're running in CSD by default i.e. the decoration is painted by us

Yes. It can be turned on in the "customize toolbar" settings.

About rounding the region, fully solving that is a difficult problem... fractional-scale-v2 might help, since it's pixels instead of logical units.

In general though, fully opaque vs. not fully opaque makes the biggest difference, so maybe that could be special-cased, to ensure a fully opaque buffer also gets a full Wayland opaque region?

The stable rounding can't be reversed to the recent implementation is just an approximation. But I reproduced that with 133% scale / CSD too for maximized window. Will try to make something based on upscale.

Flags: needinfo?(stransky)
Duplicate of this bug: 2089302

Looks like we upscale/donwnscale the opaque region coordinates at WaylandSurface and nsWindow. We should use single approach and perhaps keep downscaled coordinates and upscale on request.

The fix may also contain Bug 2089544.

Flags: needinfo?(stransky)
See Also: → 2089544
Flags: needinfo?(stransky)

Xaver, how KWin calculates logical -> pixel coordinates for opaque region? Is it the same as for buffer size, i.e. just round(x * scale), round(width * scale) ?

Flags: needinfo?(stransky) → needinfo?(xaver.hugl)
Flags: needinfo?(stransky)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #18)

Xaver, how KWin calculates logical -> pixel coordinates for opaque region? Is it the same as for buffer size, i.e. just round(x * scale), round(width * scale) ?

Currently the same way as it maps coordinates for rendering, which is to say, round(x * scale), round((x + width) * scale).

I think ultimately this bug boils down to your current code implicitly assuming that everything outside of the buffer "leaks" transparency into it.
If you map the translucent region instead of the opaque one, it should no longer happen:

translucent = fullRect - opaque
logicalTranslucent = roundOut(translucent / scale) & fullLogicalRect
logicalOpaque = fullLogicalRect - translucent

(or when mapping the region, explicitly check for top/bottom/left/right edges and don't round them inwards)

Also, I feel like we should add a buffer_opaque region to Wayland, all this mapping back and forth really shouldn't be necessary. Even with fractional-scale-v2 you could use a different viewport and the opaque region is kinda meaningless again.

Flags: needinfo?(xaver.hugl)

We're slowly moving to painting the decoration by Firefox itself so it should be useful for fullscreen/maximized mode only. But I'm bit hesitant to hardcode the window states there.

No longer duplicate of this bug: 2089302
See Also: → 2089302
See Also: → 2089948
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: