Skip to content

fix: show window after first frame callback#183454

Merged
robert-ancell merged 3 commits into
flutter:masterfrom
rkishan516:multi-window-first-frame
Mar 27, 2026
Merged

fix: show window after first frame callback#183454
robert-ancell merged 3 commits into
flutter:masterfrom
rkishan516:multi-window-first-frame

Conversation

@rkishan516

Copy link
Copy Markdown
Contributor

This PR adds first frame callback to FlutterWindowView such that we only show window after first frame.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@rkishan516 rkishan516 requested a review from a team as a code owner March 10, 2026 15:24
@google-cla

google-cla Bot commented Mar 10, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop team-windows Owned by the Windows platform team labels Mar 10, 2026
@rkishan516 rkishan516 force-pushed the multi-window-first-frame branch from 9ddbef3 to 5aa26d9 Compare March 10, 2026 15:39

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +735 to +740
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));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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));
}

@loic-sharma loic-sharma requested a review from mattkae March 10, 2026 17:34
@rkishan516 rkishan516 force-pushed the multi-window-first-frame branch from 5aa26d9 to ee3a266 Compare March 10, 2026 17:57
@knopp

knopp commented Mar 10, 2026

Copy link
Copy Markdown
Member

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 host_window part :)

@knopp

knopp commented Mar 10, 2026

Copy link
Copy Markdown
Member

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.

@rkishan516

rkishan516 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

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.

@rkishan516 rkishan516 requested a review from knopp March 12, 2026 14:30
robert-ancell
robert-ancell previously approved these changes Mar 25, 2026

@robert-ancell robert-ancell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, thanks!

@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 26, 2026
@rkishan516 rkishan516 added the CICD Run CI/CD label Mar 26, 2026
@robert-ancell robert-ancell added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2026
@robert-ancell robert-ancell added this pull request to the merge queue Mar 27, 2026
Merged via the queue into flutter:master with commit 464d889 Mar 27, 2026
190 of 191 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Mar 27, 2026
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
@rkishan516 rkishan516 deleted the multi-window-first-frame branch April 8, 2026 15:50
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
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.
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants