Repository navigation
[Linux] Fix deadlock presenting to a Wayland subsurface - #196945
auto-submit[bot] merged 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces synchronized resizing for Wayland subsurfaces on Linux, allowing subsurface frames to stay in step with GTK parent surface commits and preventing deadlocks by releasing the frame mutex during presentation. It adds subsurface synchronization APIs, updates EGL context management to run on the raster thread, and includes corresponding unit tests. The review feedback highlights critical thread-safety concerns, recommending that EGL and subsurface reference releases be deferred to the GTK main thread to avoid destroying Wayland resources on the raster thread. Additionally, the feedback suggests restoring the engine's OpenGL context after presentation, adding defensive null checks for Wayland subsurfaces, and verifying the success of eglMakeCurrent before deleting framebuffers.
| eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, | ||
| self->egl_context); | ||
| glDeleteFramebuffers(1, &self->read_framebuffer); | ||
| self->read_framebuffer = 0; |
There was a problem hiding this comment.
We should check the return value of eglMakeCurrent before calling OpenGL functions like glDeleteFramebuffers. If eglMakeCurrent fails (e.g., due to the context being current on another thread or driver state issues), calling OpenGL functions can result in undefined behavior or state corruption in other active contexts.
if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
self->egl_context)) {
glDeleteFramebuffers(1, &self->read_framebuffer);
self->read_framebuffer = 0;
}There was a problem hiding this comment.
Aware of this, but I don't want to include it in this PR as it is existing behaviour. I don't think it's urgent.
|
Builds on top of #195287, will wait for that to land first. |
Under Wayland, Flutter 3.50 presents frames through a synchronized subsurface, and the raster thread can wait on the compositor while holding the lock GTK needs to resize the view. Going fullscreen then freezes the app for good (flutter/flutter#196529, fix pending in flutter/flutter#196945). The reader went fullscreen as it opened by default, so opening any chapter froze it. - Under Wayland, neither the reader nor the video player switches the window to fullscreen on its own; the user still can. - The fullscreen settings say so under Wayland. - Wayland is detected as GDK picks its backend: GDK_BACKEND first, then a Wayland display to connect to. Refs #1176 Co-Authored-By: Claude Opus 5.5 <[email protected]>
That one was merged, so maybe this PR is ready for action? |
…, to test it (#277)" (#279) This reverts commit 919b2c2. The pin did not help: the nightly built at f154927a716 starts and presents nothing just the same. flutter/flutter ec58d3f3224 is not the cause. The blank shell is the Wayland subsurface renderer itself (flutter/flutter#191389, Aug 24), which the snap first picked up when it moved to master in #272: the raster thread holds the renderer's frame mutex while presenting, the EGL driver blocks until GTK commits the parent surface, and GTK is blocked in size_allocate on that same mutex. flutter/flutter#196945 fixes that deadlock and is still open. So the snap goes back to building the head of Flutter master, and picks up the upstream fix the night it lands. CLAUDE.md keeps #278's portal-restart wording; only the pin's sentence is reverted. Claude-Session: https://claude.ai/code/session_01CX14JWaYWz18TJftbxYtaN Co-authored-by: Claude <[email protected]>
c67c721 to
9c8833b
Compare
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
9c8833b to
4ebf327
Compare
|
@spydon would be interested in your review / testing, thanks! |
There was a problem hiding this comment.
Code Review
This pull request refactors Wayland subsurface management in the Linux embedding, introducing explicit subsurface destruction, tracking of presented frame sizes, and lazy EGL context recreation on the raster thread to handle GTK replacing the subsurface. It also adds a test to ensure resizing does not deadlock when presenting is blocked. The review feedback highlights critical thread-safety issues in fl_view_renderer_subsurface.cc, pointing out potential data races where self->egl and self->egl_subsurface are accessed or modified outside of self->frame_mutex (specifically in present_layers, release_egl, and finalize), and suggests synchronizing these operations under the mutex.
spydon
left a comment
There was a problem hiding this comment.
Looks good to me code-wise, couldn't test it since I'm in India for FlutterCon India.
|
This fixes |
mattkae
left a comment
There was a problem hiding this comment.
This looks good on my end and is working for me again! Although I will admit that the subsurface stuff gets a bit tricky
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)
|
Cherry-picked to 3.50 in #197353 |
Resolve conflicts with flutter#195287 and flutter#196945 in FlViewRendererSubsurface and MockGtk, retain self->opengl_manager in release_egl() and lazy FlSubsurfaceEGL creation, and update Wayland renderer lifetime tests for raster-owned FlSubsurfaceEGL.
Roll Flutter from b75c5b30406a to 06f1c24345a2 (37 revisions) flutter/flutter@b75c5b3...06f1c24 2026-11-25 [email protected] Roll Skia from a60d883b3fe3 to e84ecd98d9f2 (2 revisions) (flutter/flutter#197375) 2026-11-25 [email protected] Roll Skia from ca229e319550 to a60d883b3fe3 (4 revisions) (flutter/flutter#197371) 2026-11-25 [email protected] Roll Skia from 6f75212e5a23 to ca229e319550 (2 revisions) (flutter/flutter#197369) 2026-11-25 [email protected] Roll Skia from 75d95595f14e to 6f75212e5a23 (1 revision) (flutter/flutter#197364) 2026-11-25 [email protected] [Windows] Fix Korean 3-beolsik IME dropping space, digits and punctuation (flutter/flutter#194270) 2026-11-25 [email protected] [flutter_tools] Strip embedded credentials from repository URLs (flutter/flutter#197219) 2026-11-25 [email protected] [flutter_tools] Add structured extension.log notifications for tool extensions (flutter/flutter#196714) 2026-11-25 [email protected] [flutter_tools] Share Depfile in flutter_tools_core and make BuildTarget.targetPlatform optional (flutter/flutter#194965) 2026-11-25 [email protected] Reply null asynchronously to ignored web platform messages and unskip missing-asset tests (flutter/flutter#197267) 2026-11-25 [email protected] Roll Dart SDK from 87f515c52de9 to 5202130a51b8 (1 revision) (flutter/flutter#197363) 2026-11-25 [email protected] [web] Retain queued scene pictures via ContainerLayer render pinning (flutter/flutter#196748) 2026-11-25 [email protected] [flutter_tools] Include dependency manifests in copyAssets depfile (flutter/flutter#196596) 2026-11-25 [email protected] Print the Intel Mac deprecation warning on every command (flutter/flutter#194071) 2026-11-25 [email protected] Roll Skia from 243c0dc9f662 to 75d95595f14e (2 revisions) (flutter/flutter#197351) 2026-11-25 [email protected] iOS: Ignore platform messages after the engine is destroyed (flutter/flutter#197310) 2026-11-24 [email protected] Bump customer tests to pick up material_ui cache extent test updates (flutter/flutter#197266) 2026-11-24 [email protected] [flutter_tools] Use refreshed FlutterVersion for flutter doctor feature flags (flutter/flutter#196944) 2026-11-24 [email protected] [flutter_tools] Do not crash if buildXcodeProject temporary directory is deleted before cleanup (flutter/flutter#195918) 2026-11-24 [email protected] Fix some `parameter_assignments` warnings (flutter/flutter#196815) 2026-11-24 [email protected] [flutter_tools] Extract PlatformDebuggingOptions and move WebDebugConfig (flutter/flutter#197229) 2026-11-24 [email protected] Fix desktop apps installing to the system prefix after a failed build (flutter/flutter#196482) 2026-11-24 [email protected] [flutter_tools] Write flutter test native_assets.json outside targetDir (flutter/flutter#196300) 2026-11-24 [email protected] iOS: Check the presented composition order in platform view tests (flutter/flutter#197302) 2026-11-24 [email protected] Run the shared Vulkan embedder tests under Impeller as well as Skia (flutter/flutter#193004) 2026-11-24 [email protected] Roll Fuchsia Linux SDK from BOgXtIYxLYcCkRou2... to HtAKfFLbfAQ6g96RY... (flutter/flutter#197334) 2026-11-24 [email protected] Roll Skia from b3dec9325fe1 to 243c0dc9f662 (6 revisions) (flutter/flutter#197333) 2026-11-24 [email protected] [flutter_tools] Delete globals.dart and context_runner.dart (flutter/flutter#196095) 2026-11-24 [email protected] Update viewInsets docs for translucent and rounded system UI (flutter/flutter#196355) 2026-11-24 [email protected] [flutter_tools] Check that dartaotruntime can run before starting the frontend server (flutter/flutter#194206) 2026-11-24 [email protected] [framework] Fix DraggableScrollableSheet '_hold == null' assertion when touch lifts during snap (flutter/flutter#195771) 2026-11-24 [email protected] [web] Release ImageSource on GC and fix Picture finalizer cycles (flutter/flutter#197245) 2026-11-24 [email protected] [flutter_tools] Fix web compiler output tracking in web builds (flutter/flutter#196563) 2026-11-24 [email protected] Upgrade CI to Xcode 27.2 (flutter/flutter#196807) 2026-11-24 [email protected] Roll Packages from 5b93485 to f455dfa (6 revisions) (flutter/flutter#197316) 2026-11-24 [email protected] [Linux] Fix deadlock presenting to a Wayland subsurface (flutter/flutter#196945) 2026-11-24 [email protected] Roll Skia from 2140958ee284 to b3dec9325fe1 (1 revision) (flutter/flutter#197309) 2026-11-24 [email protected] Roll Fuchsia Test Scripts from oEU515sDqSTvD8Spx... to GPtykFNizlaauBqzs... (flutter/flutter#197313) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose ...
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 #196529