fix: show window after first frame callback#183454
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
9ddbef3 to
5aa26d9
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to defer showing a window until after the first frame has been rendered, preventing a blank window from flashing. It adds a SetFirstFrameCallback method to FlutterWindowsView, which is invoked from OnFramePresented (for GPU rendering) and PresentSoftwareBitmap (for software rendering). The HostWindow is updated to use this callback to call ShowWindow. The changes are accompanied by a comprehensive set of unit tests.
| std::scoped_lock lock(first_frame_callback_mutex_); | ||
| if (first_frame_callback_) { | ||
| fml::closure callback = std::move(first_frame_callback_); | ||
| first_frame_callback_ = nullptr; | ||
| engine_->task_runner()->PostTask(std::move(callback)); | ||
| } |
There was a problem hiding this comment.
To minimize the duration the mutex is held, it's a good practice to release the lock before performing operations that might block or take time, like posting a task to another thread. You can achieve this by moving the callback out of the locked scope and then posting it. Using std::swap is an idiomatic and safe way to extract the callback while ensuring the member is cleared.
| std::scoped_lock lock(first_frame_callback_mutex_); | |
| if (first_frame_callback_) { | |
| fml::closure callback = std::move(first_frame_callback_); | |
| first_frame_callback_ = nullptr; | |
| engine_->task_runner()->PostTask(std::move(callback)); | |
| } | |
| fml::closure callback_to_fire; | |
| { | |
| std::scoped_lock lock(first_frame_callback_mutex_); | |
| callback_to_fire.swap(first_frame_callback_); | |
| } | |
| if (callback_to_fire) { | |
| engine_->task_runner()->PostTask(std::move(callback_to_fire)); | |
| } |
5aa26d9 to
ee3a266
Compare
|
This adds the callback, but seems to be missing the rest? Also with multi-window, I think this should be happening transparently without user intervention. EDIT: Nevermind, I missed the |
|
One thing to consider here, we now by default show all windows created, with no way to create hidden window. Or to hide window at all. Also this is something we should do on other platforms as long as we figure out the right approach (i.e. opacity vs show/hide, and maybe way to disable the behavior if user wants to create hidden window and show it later). On macOS this is currently done, but only for tooltips and popups. |
I was thinking along the same lines, but that might need discussion on how we want to do it. May be I can create another PR which does add iniitial configuration to RegularWindowController and we can decide, how we want move from there. This is minimal change which just removes the flicker of first frame. I don't think this change should affect adding visible flag decision. |
robert-ancell
left a comment
There was a problem hiding this comment.
Looks good, thanks!
ee3a266 to
3cb3801
Compare
flutter/flutter@e79bf6c...fb03253 2026-03-27 kevmoo@users.noreply.github.com flutter_driver: remove @internal annotation on field (flutter/flutter#184235) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 5299de75c97b to 8c705ac86366 (2 revisions) (flutter/flutter#184245) 2026-03-27 engine-flutter-autoroll@skia.org Roll Packages from 0dd2410 to 7ae082a (5 revisions) (flutter/flutter#184248) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 9beded929d5a to 5299de75c97b (1 revision) (flutter/flutter#184243) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 4f4f07084ef0 to 9beded929d5a (4 revisions) (flutter/flutter#184237) 2026-03-27 engine-flutter-autoroll@skia.org Roll Dart SDK from ea1bce22b45b to dfd1f8af3c52 (2 revisions) (flutter/flutter#184234) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 1b7154852825 to 4f4f07084ef0 (1 revision) (flutter/flutter#184231) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from aec9a7ab7ed9 to 1b7154852825 (1 revision) (flutter/flutter#184230) 2026-03-27 34465683+rkishan516@users.noreply.github.com fix: show window after first frame callback (flutter/flutter#183454) 2026-03-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7587a31814c6 to ea1bce22b45b (1 revision) (flutter/flutter#184228) 2026-03-27 okorohelijah@google.com skip interactive keyboard tests (flutter/flutter#183757) 2026-03-26 git@reb0.org Build engine for windows_arm on beta and stable (flutter/flutter#176385) 2026-03-26 engine-flutter-autoroll@skia.org Roll Skia from bee5a06ef578 to aec9a7ab7ed9 (4 revisions) (flutter/flutter#184222) 2026-03-26 magder@google.com Update iOS/macOS flutter_tools CODEOWNERS (flutter/flutter#183287) 2026-03-26 evanwall@buffalo.edu Update changelog for 3.41.6 stable hotfix (flutter/flutter#184220) 2026-03-26 47866232+chunhtai@users.noreply.github.com Updates scroll cache extent doc (flutter/flutter#184142) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC stuartmorgan@google.com,tarrinneal@google.com 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 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
This PR adds first frame callback to FlutterWindowView such that we only show window after first frame. ## 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 documentation (doc comments with `///`). - [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.
…r#11379) flutter/flutter@e79bf6c...fb03253 2026-03-27 kevmoo@users.noreply.github.com flutter_driver: remove @internal annotation on field (flutter/flutter#184235) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 5299de75c97b to 8c705ac86366 (2 revisions) (flutter/flutter#184245) 2026-03-27 engine-flutter-autoroll@skia.org Roll Packages from 0dd2410 to 7ae082a (5 revisions) (flutter/flutter#184248) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 9beded929d5a to 5299de75c97b (1 revision) (flutter/flutter#184243) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 4f4f07084ef0 to 9beded929d5a (4 revisions) (flutter/flutter#184237) 2026-03-27 engine-flutter-autoroll@skia.org Roll Dart SDK from ea1bce22b45b to dfd1f8af3c52 (2 revisions) (flutter/flutter#184234) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from 1b7154852825 to 4f4f07084ef0 (1 revision) (flutter/flutter#184231) 2026-03-27 engine-flutter-autoroll@skia.org Roll Skia from aec9a7ab7ed9 to 1b7154852825 (1 revision) (flutter/flutter#184230) 2026-03-27 34465683+rkishan516@users.noreply.github.com fix: show window after first frame callback (flutter/flutter#183454) 2026-03-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7587a31814c6 to ea1bce22b45b (1 revision) (flutter/flutter#184228) 2026-03-27 okorohelijah@google.com skip interactive keyboard tests (flutter/flutter#183757) 2026-03-26 git@reb0.org Build engine for windows_arm on beta and stable (flutter/flutter#176385) 2026-03-26 engine-flutter-autoroll@skia.org Roll Skia from bee5a06ef578 to aec9a7ab7ed9 (4 revisions) (flutter/flutter#184222) 2026-03-26 magder@google.com Update iOS/macOS flutter_tools CODEOWNERS (flutter/flutter#183287) 2026-03-26 evanwall@buffalo.edu Update changelog for 3.41.6 stable hotfix (flutter/flutter#184220) 2026-03-26 47866232+chunhtai@users.noreply.github.com Updates scroll cache extent doc (flutter/flutter#184142) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC stuartmorgan@google.com,tarrinneal@google.com 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 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
This PR adds first frame callback to FlutterWindowView such that we only show window after first frame.
Pre-launch Checklist
///).