Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Windows] Fix EGL surface destruction race #51781

Merged
merged 2 commits into from
Mar 29, 2024

Conversation

loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Mar 29, 2024

This fixes the WindowsTest.EngineCanTransitionToHeadless flakiness reported by @matanlurey.

EGL surfaces can only be used by a single thread at a time. Concurrent operations are unsafe.

Previously, the EGL surface was destroyed on the platform thread. This was safe as this always happened after the engine was shutdown and the raster thread was stopped. However, in a multi-view world a view can be destroyed while the engine is running. There may be pending raster tasks that operate on the render surface. Thus, the EGL surfaces should be destroyed on the raster thread when it is available.

This bug was introduced by #51681
Part of flutter/flutter#142845

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@loic-sharma loic-sharma marked this pull request as ready for review March 29, 2024 20:03
@matanlurey matanlurey added the warning: land on red to fix tree breakage Override tree-status signal (land even with closed tree), combine with the autosubmit label. label Mar 29, 2024
Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSLGTM, mostly to unblock the tree.

The code looks good (like, it's readable and the names and docs are good), I just can't tell you if it's "correct" for the domain, so defer to you on whether to land as-is or wait for more reviews.

Copy link
Contributor

@yaakovschectman yaakovschectman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM mod one question

fml::AutoResetWaitableEvent latch;
engine.PostRasterThreadTask([&]() {
surface.Destroy();
latch.Signal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this latch accomplish? Does this prevent the engine from destructing before this task runs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. This runs in the FlutterWindowsView destructor, which owns the std::unique<egl::WindowSurface>. The latch forced the destructor to wait until the surface was destroyed.

A cleaner version would be to just move the surface's ownership to the raster thread. I've updated it to that insead!

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 29, 2024
@auto-submit auto-submit bot merged commit 0ca0ef6 into flutter:main Mar 29, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 30, 2024
…146020)

flutter/engine@8ec35b6...0a75166

2024-03-29 skia-flutter-autoroll@skia.org Roll Skia from a12e40efacea to df005a80da32 (1 revision) (flutter/engine#51777)
2024-03-29 737941+loic-sharma@users.noreply.github.com [Windows] Fix EGL surface destruction race (flutter/engine#51781)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jacksongardner@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-windows warning: land on red to fix tree breakage Override tree-status signal (land even with closed tree), combine with the autosubmit label.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants