Skip to content

[web] Support Skwasm rendering without bitmap capture - #195103

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
MarlonJD:skwasm-surface-callbacks
Nov 5, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
MarlonJD:skwasm-surface-callbacks

Conversation

@MarlonJD

@MarlonJD MarlonJD commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Related: #187660. Part 2 of 5, split from #188628. This change can land independently of the hybrid rasterizer.

Makes Skwasm callback IDs unique across surfaces and adds an explicit bitmap-capture parameter to the native render call. Existing Dart rendering still requests bitmaps; the new option allows a later onscreen path to complete without clearing its backing canvas through bitmap export.

Verified locally: Skwasm and Wimp native release builds; overlapping-surface, context-loss and capture/no-capture tests in ST and MT. The matching engine prebuilts must be available before dependent Dart-only changes land.

Pre-launch Checklist

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

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team labels Oct 22, 2026
yexuan910812 pushed a commit to yexuan910812/flutter that referenced this pull request Oct 30, 2026
…188628)

Related: flutter#187660. Part 1 of 5 from the original hybrid-rasterizer
change. This PR is now limited to the independent benchmark
instrumentation.

Adds `presentation_duration` around preparation and frame submission,
including asynchronous raster work, and records it in the web benchmark
harness. The timer stops before reporting, and benchmark listeners are
cleaned up even when startup fails. The existing profile JSON schema is
unchanged.

Verified locally: two engine timing tests cover enabled/disabled
profiling and delayed preparation/rasterization; a browser regression
test covers listener cleanup after synchronous startup failures. Static
analysis and formatting pass. This change is independent of the hybrid
rasterizer.

The remaining pieces are separate drafts:

- flutter#195103: native callback IDs and optional bitmap capture.
- flutter#195104: platform-view DOM commit after rasterization.
- flutter#195105: opt-in hybrid presentation, depending on the two changes
above.
- flutter#195106: desktop default policy and benchmark results, depending on
the opt-in implementation.

The duplicate semaphore and codec changes were dropped on rebase because
master already includes flutter#194139 and flutter#193187.

## 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 in-code documentation (doc comments with
`///`).
- [ ] 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).
- [ ] 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.

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

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- 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
@MarlonJD
MarlonJD marked this pull request as ready for review October 30, 2026 01:53

@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 captureImageBitmaps parameter to the Skwasm picture rendering pipeline, allowing rendering to complete without exporting image bitmaps when they are not required. Additionally, it transitions callback ID generation to a global sequence to ensure uniqueness across all surfaces. Feedback suggests handling potential integer overflow in NextCallbackId to prevent returning 0 as a valid callback ID.

Comment on lines +54 to +57
uint32_t NextCallbackId() {
assert(emscripten_is_main_browser_thread());
return ++g_next_callback_id;
}

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

If g_next_callback_id overflows and wraps around to 0, returning 0 as a callback ID could cause issues if 0 is treated as an invalid or uninitialized ID. It is safer to skip 0 on overflow to ensure callback IDs remain non-zero.

uint32_t NextCallbackId() {
  assert(emscripten_is_main_browser_thread());
  g_next_callback_id++;
  if (g_next_callback_id == 0) {
    g_next_callback_id = 1;
  }
  return g_next_callback_id;
}

Zero marks an unset context-loss callback. Skip it when the shared uint32_t callback sequence wraps so context-loss notifications remain registered.
@MarlonJD

MarlonJD commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi @harryterkelsen, could you review this second part when you have a chance? I've added the zero-ID guard and verified the Skwasm/Wimp callback tests locally in both ST and MT. Thanks!

@flutter-zl flutter-zl added the CICD Run CI/CD label Nov 4, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 4, 2026
Comment thread engine/src/flutter/skwasm/surface.cc Resolved
Comment thread engine/src/flutter/skwasm/surface.cc Outdated
Comment on lines +115 to +117

// Allocated here instead of on the worker so that current_callback_id_ is
// only ever modified on the main thread.
context_lost_callback_id_ = ++current_callback_id_;
// Allocated here instead of on the worker so that callback IDs are unique
// across all surfaces sharing the callback handler.

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.

Nit: cross-surface uniqueness comes from g_next_callback_id being module-global rather than allocating on the main thread vs. the worker — allocating here is still so g_next_callback_id is only ever modified on the main thread (and since g_next_callback_id at line 52 sits under the comment for the atomic raster-thread global, a short comment noting it is main-thread-only would be helpful).

Require a single picture when bitmap capture is disabled, clarify callback ID ownership, and close test bitmaps even when assertions fail.
@harryterkelsen
harryterkelsen self-requested a review November 4, 2026 23:48
@harryterkelsen harryterkelsen added the CICD Run CI/CD label Nov 4, 2026
@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 5, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 5, 2026
Merged via the queue into flutter:master with commit c3f332d Nov 5, 2026
26 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 5, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 6, 2026
Roll Flutter from 3623d2d34543 to 09175cdeac89 (61 revisions)

flutter/flutter@3623d2d...09175cd

2026-11-06 [email protected] Roll Skia from ae35b7b2221f to 793b8ac73d4b (3 revisions) (flutter/flutter#196091)
2026-11-06 [email protected] [web] Rasterize scenes at the size passed to `FlutterView.render` (flutter/flutter#196052)
2026-11-06 [email protected] Roll Skia from 4aa043a81e0c to ae35b7b2221f (1 revision) (flutter/flutter#196086)
2026-11-06 [email protected] Roll Fuchsia Linux SDK from Fqe3UlLwAohsPbsCS... to KIc0XZbhLmvDpTluZ... (flutter/flutter#196085)
2026-11-06 [email protected] Allow a zero scale change in InteractiveViewer (flutter/flutter#194949)
2026-11-06 [email protected] Roll Skia from dd5c2553a856 to 4aa043a81e0c (2 revisions) (flutter/flutter#196079)
2026-11-06 [email protected] [web] Keep ImageFilter.blur bounds in equality and description (flutter/flutter#196013)
2026-11-06 [email protected] iOS: Remove unused PlatformViewIOS setup from FlutterPlatformViewsTest (flutter/flutter#196033)
2026-11-06 [email protected] Serialize LoggerTests that mutate the shared Logger (flutter/flutter#196028)
2026-11-06 [email protected] Use reverseDuration for the AnimatedCrossFade size animation (flutter/flutter#194860)
2026-11-05 [email protected] Roll Skia from a5aacd103e68 to dd5c2553a856 (8 revisions) (flutter/flutter#196073)
2026-11-05 [email protected] Fix ListWheelScrollView null check error when it reads itemIndex before content dimensions are set (flutter/flutter#194859)
2026-11-05 [email protected] Allow zero cross axis extent in SliverGridDelegateWithMaxCrossAxisExtent (flutter/flutter#194858)
2026-11-05 [email protected] Revert: Allow color delta tolerance in in-memory fuzzy image comparator (flutter/flutter#196067)
2026-11-05 [email protected] Revert: Mitigate snapshot race in 3D transform test by reducing loop density (flutter/flutter#196066)
2026-11-05 [email protected] Delegate createStream in ResizeImage and ScrollAwareImageProvider (flutter/flutter#194756)
2026-11-05 [email protected] [iOS] Introduce FlutterShell and move thread host and profiler (flutter/flutter#195388)
2026-11-05 [email protected] [web] Support FragmentShader.getImageSampler on CanvasKit and Skwasm (flutter/flutter#195854)
2026-11-05 [email protected] Deprecates setFloat API (flutter/flutter#195505)
2026-11-05 [email protected] [flutter_tools] Remove public GlobalToolContext and globals from runner (flutter/flutter#195561)
2026-11-05 [email protected] Defer TLHC PlatformViewWrapper frame post and avoid initial 1x1 buffer resize (flutter/flutter#195861)
2026-11-05 [email protected] Roll Skia from b5abed66da86 to a5aacd103e68 (17 revisions) (flutter/flutter#196054)
2026-11-05 [email protected] Made `FlutterWindowControllerSizeTest.SizedToContentNotResizable` more robust (flutter/flutter#195845)
2026-11-05 [email protected] Update docs for contributor ladder (flutter/flutter#196011)
2026-11-05 [email protected] [Impeller] Use the transfer stage for the Vulkan readback barrier (flutter/flutter#194991)
2026-11-05 [email protected] Remove Mac mac_unopt builder (flutter/flutter#196027)
2026-11-05 [email protected] Updated Instructions for Determining Gradle Version for `gradle_dists` in CIPD (flutter/flutter#193310)
2026-11-05 [email protected] Move ios_app_with_extensions_test into the tool integration shard (flutter/flutter#195609)
2026-11-05 [email protected] [web] Respect Uint8List view bounds when detecting animated WebP/GIF (flutter/flutter#196010)
2026-11-05 [email protected] Add platform_views_layout to build_tests so iOS/Android build breaks are caught in presubmit (flutter/flutter#192985)
2026-11-05 [email protected] [flutter_tools] Detect macOS TCC permission crashes and provide diagnostic guidance (flutter/flutter#192432)
2026-11-05 [email protected] Roll Packages from 670b30e to 0478162 (15 revisions) (flutter/flutter#196047)
2026-11-05 [email protected] [web] Support Skwasm rendering without bitmap capture (flutter/flutter#195103)
2026-11-05 [email protected] [flutter_tools] Reland fix for local CanvasKit asset paths on Windows (flutter/flutter#195770)
2026-11-05 [email protected] Roll Skia from f96be51af95d to b5abed66da86 (14 revisions) (flutter/flutter#196017)
2026-11-05 [email protected] Split chrome web engine test drone (flutter/flutter#195873)
2026-11-05 [email protected] Roll Dart SDK from c9153304136a to 6623b84628f3 (1 revision) (flutter/flutter#196026)
2026-11-05 [email protected] Roll ICU from 4fe960221710 to a0ea93436c52 (6 revisions) (flutter/flutter#196025)
2026-11-05 [email protected] Add more guidance in README and AGENTS for contributing to flutter_tools (flutter/flutter#195998)
2026-11-05 [email protected] Roll Fuchsia Linux SDK from p0HDXLISPIElJfSz7... to Fqe3UlLwAohsPbsCS... (flutter/flutter#196019)
2026-11-05 [email protected] Roll Dart SDK from e362a23e9738 to c9153304136a (18 revisions) (flutter/flutter#196014)
2026-11-05 [email protected] [Impeller] Fix dilation input bounds when clipping saveLayers (flutter/flutter#195652)
2026-11-05 [email protected] Add `variantOf` to the M3E migration checklist (flutter/flutter#195099)
2026-11-05 [email protected] [flutter_tools] Eliminate globals from remaining subsystem files (flutter/flutter#195555)
2026-11-05 [email protected] Fix gap flipping when dragging variable height reorderable items (flutter/flutter#194478)
2026-11-05 [email protected] [A11y] Send un-merged SemanticsNodes in the same update that first references them (flutter/flutter#195829)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants