Repository navigation
[stable] [Linux] Fix synchronization and locking with subsurfaces - #197353
robert-ancell wants to merge 2 commits into
Conversation
…he GTK window (flutter#195287) The Wayland subsurface renderer (flutter#191389) presents each frame to a `wl_subsurface` from the raster thread, but leaves the subsurface in synchronized mode, so a frame is only shown when the parent (GTK) surface is next committed. To make that happen the renderer queued a GTK redraw of the view for every frame. That repaints the whole window with cairo on the GTK thread and damages the parent surface in full, which the compositor then has to re-upload, and none of what GTK paints is visible since it is behind the subsurface. This change desynchronizes the subsurface, so a frame is shown as soon as the raster thread commits it, and stops queuing a redraw per frame. Window and content still change size in the same compositor update: the subsurface is synchronized again from `size_allocate` (before `FlView` sends the new window metrics to the engine, so the frame rendered at the new size is held back) until GTK has committed the resized parent surface, which it does from its own `after-paint` handler. Views sized to their content keep the subsurface synchronized and redraw per frame as before, since their window is resized to fit each frame. Measured with a release build of an app showing a `CircularProgressIndicator` in a 2560x1400 window on GNOME 50.1 (Wayland, Mesa 26.0.8 radeonsi), CPU as a percentage of one core: | | app | gnome-shell | |---|---|---| | master (66b3ad9) | 16.4% | 13.4% | | this PR | 3.2% | 2.8% | | 3.47 stable, for reference | 33.6% | 5.9% | gnome-shell's idle baseline is 1.9%. An empty animating game (flame-engine/flame#4143) goes from 15.6% to 2.3%. A `perf` profile of master showed the cost as `pixman_fill` and `cairo_fill` under `gdk_window_begin_draw_frame` on the GTK thread, which is the per-frame repaint. Addresses the Wayland case of flutter#101591. The X11 renderer (`FlViewRendererOpenGL`) still draws frames through GTK and is unchanged by this PR. Tests: `fl_subsurface_test.cc` covers the new default and `fl_subsurface_set_synchronized()`. The renderer's behaviour around a resize is not unit tested, as `FlViewRendererSubsurface` needs a Wayland display and the tests run on X11 (as for the existing renderer tests). Checked manually on GNOME: continuous animation, drag resize, maximize and restore, minimize and restore, with no warnings logged. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md (cherry picked from commit ec58d3f)
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
The raster thread held frame_mutex while presenting. With a synchronized subsurface the EGL driver can block until GTK commits the parent surface, while GTK is blocked on frame_mutex. Present without holding the mutex, with the EGL context owned by the raster thread. Fixes flutter#196529 (cherry picked from commit 7a76e16)
There was a problem hiding this comment.
Code Review
This pull request introduces synchronized resizing for the Linux subsurface renderer by adding APIs to synchronize and desynchronize the subsurface with its parent. It updates FlViewRendererSubsurface to synchronize during resizes until GTK has painted, and to remain desynchronized otherwise. Feedback highlights a potential GLib critical assertion failure in create_subsurface if self->subsurface is null, suggesting a defensive null check before calling the synchronization functions.
Issue Link:
What is the link to the issue this cherry-pick is addressing?
#101591
#196529
Impact Description:
High CPU usage and occasional deadlocks running with subsurfaces.
Changelog Description:
Fix performance and lockup issues with new Linux rendering
Workaround:
Is there a workaround for this issue?
No.
Risk:
What is the risk level of this cherry-pick?
This is changing complicated context and threading relationships and could risk introducing new issues.
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
Follow steps in:
#101591
#196529