Repository navigation
[engine] Release the Skia OpenGL resource context on shutdown - #193592
Conversation
Clear the Skia resource context on its owning IO thread through the existing release hook. Add a native regression that verifies successful context release during synchronous engine shutdown. Fixes flutter#193591.
There was a problem hiding this comment.
Code Review
This pull request implements ReleaseResourceContext in EmbedderSurfaceGLSkia to release the OpenGL resource context on the IO thread during shutdown, and adds a corresponding unit test to verify this behavior. Feedback on the changes suggests checking if gl_clear_current_callback is valid before invoking it to prevent potential crashes, as this callback is optional in the embedder API.
| if (!valid_ || !gl_dispatch_table_.gl_make_resource_current_callback) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
The gl_clear_current_callback is an optional callback in the Flutter OpenGL embedder API. If an embedder does not provide a clear_current callback, gl_dispatch_table_.gl_clear_current_callback will be null/empty. Calling it on line 135 without checking if it is valid will cause a crash (or throw std::bad_function_call). We should defensively check that gl_clear_current_callback is valid before attempting to invoke it.
| if (!valid_ || !gl_dispatch_table_.gl_make_resource_current_callback) { | |
| return; | |
| } | |
| if (!valid_ || !gl_dispatch_table_.gl_make_resource_current_callback || | |
| !gl_dispatch_table_.gl_clear_current_callback) { | |
| return; | |
| } |
There was a problem hiding this comment.
The constructor already checks gl_clear_current_callback before setting valid_ = true (lines 21–29). Since this method returns when !valid_, a missing callback cannot reach the call below. The Impeller constructor performs the same validation, so an additional null check here would be redundant.
|
Hi @walley892, could you please reapply the CICD label? It was removed after I updated the branch with master, and the latest Google testing check reports “Engine artifacts not found.” Once the engine builds complete, could you also rerun the internal tests? Thanks for your help and review. |
|
autosubmit label was removed for flutter/flutter/193592, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
|
autosubmit label was removed for flutter/flutter/193592, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
|
thanks for trying auto submit, @walley892. I’ve updated the branch with master as requested by the bot. |
|
Hi @gaaclarke you previously helped route this to @walley892. Could you help with the additional member review and restoring CICD? The October 23 revision passed local Windows validation, with details above. I can refresh master and rerun tests when you’re ready if the base has become stale. Thanks! |
gaaclarke
left a comment
There was a problem hiding this comment.
looking good, just a few style requests
| public: | ||
| explicit ResourceReleaseTestContext(std::string assets_path) | ||
| : EmbedderTestContextGL(std::move(assets_path)) { | ||
| auto& config = GetRendererConfig().open_gl; |
There was a problem hiding this comment.
| self->resource_current = false; | ||
| self->resource_released = true; |
There was a problem hiding this comment.
with atomics, google wants you to use explicit load and store calls
|
Thanks for the review and approval, @gaaclarke! Both style requests are fixed in b22338b. The Windows native suite passed: 188 tests passed, 8 skipped, and 1 pre-existing disabled test, with no failures. The shutdown regression also passed 100/100 repetitions. Could you please restore CICD so the upstream checks can run? |
|
autosubmit label was removed for flutter/flutter/193592, because - The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Thanks again for updating the branch, @gaaclarke. The latest revision is still awaiting CICD after the bot removed the label following the merge. Could you please restore it so the checks can run? |
|
Hi @gaaclarke @walley892 — following up as this is still awaiting CICD with both approvals in place. Could either of you restore the label so the checks can run? Please let me know if you need a fresh master update first. Thanks! |
…13653) Manual roll Flutter from 9c427b5d7b1c to 1b9585481095 (32 revisions) Manual roll requested by [email protected] flutter/flutter@9c427b5...1b95854 2026-11-13 [email protected] Roll pub packages (flutter/flutter#196541) 2026-11-13 [email protected] Do not route PRs for review without cla, convert to draft (flutter/flutter#196341) 2026-11-13 [email protected] Roll Skia from d87a6c04da74 to 11f46cfe8838 (13 revisions) (flutter/flutter#196533) 2026-11-13 [email protected] [flutter_tools, flutter_test] Deprecate --experimental-faster-testing (flutter/flutter#196123) 2026-11-13 [email protected] [flutter_tools] Handle RPCError in ScreenshotCommand.runSkia (flutter/flutter#196132) 2026-11-13 [email protected] Roll Dart SDK from a8b961fd48bb to c91e8b6674e2 (2 revisions) (flutter/flutter#196502) 2026-11-13 [email protected] Roll Skia from 0c5ce4960cef to d87a6c04da74 (12 revisions) (flutter/flutter#196497) 2026-11-13 [email protected] Don't call `skia_image()` for raster-owned images in `DlImage::Equals` (flutter/flutter#196473) 2026-11-13 [email protected] [flutter_tools] Require FlutterCommandRunner DI fields and extract findCommandName (flutter/flutter#196331) 2026-11-13 [email protected] [web] Unify ui.Canvas behind a shared EngineCanvas frontend (flutter/flutter#196348) 2026-11-13 [email protected] Link to MediaQuery.displayFeaturesOf from DisplayFeatures (flutter/flutter#193728) 2026-11-13 [email protected] Removes reference to unnecessary ensureSemantics call in doc (flutter/flutter#195831) 2026-11-13 [email protected] [flutter_tools] Register trackWidgetCreation in AppleBuildOptionsBundle (flutter/flutter#196078) 2026-11-12 [email protected] [Android] Skip the HardwareBuffer defect fallback for platform views (flutter/flutter#193441) 2026-11-12 [email protected] Fix supports_decal check in framebuffer_blend.frag (flutter/flutter#196227) 2026-11-12 [email protected] [ios] Update the screen in didUpdateEffectiveGeometry (flutter/flutter#195508) 2026-11-12 [email protected] [flutter_tools] Add `Cache-Control` headers for web test assets (flutter/flutter#196414) 2026-11-12 [email protected] Roll Skia from 3b71ec08218f to 0c5ce4960cef (16 revisions) (flutter/flutter#196472) 2026-11-12 [email protected] [web] Render bounded ImageFilter.blur on wimp (flutter/flutter#196081) 2026-11-12 [email protected] Roll Dart SDK from 69567bd3c427 to a8b961fd48bb (2 revisions) (flutter/flutter#196464) 2026-11-12 [email protected] [engine] Release the Skia OpenGL resource context on shutdown (flutter/flutter#193592) 2026-11-12 [email protected] [web] Fix decoding of still AVIF images on Chrome (flutter/flutter#195958) 2026-11-12 [email protected] Gate SurfaceControl context setting on API 34+ (flutter/flutter#196394) 2026-11-12 [email protected] [flutter_tools] Only pass on a valid root tool in DASH__TOOL (flutter/flutter#196228) 2026-11-12 [email protected] Support GL_TEXTURE_EXTERNAL_OES embedder textures in Impeller (flutter/flutter#195857) 2026-11-12 [email protected] Stop building linux/wasm_release in local_engine_builds (flutter/flutter#196345) 2026-11-12 [email protected] Split flame out of Linux customer_testing (flutter/flutter#196347) 2026-11-12 Jiwon Lee [Windows] Fix Space input after Alt+Space with previous Microsoft IME (flutter/flutter#192105) 2026-11-12 [email protected] [flutter_tools] Add ToolExtensionException, exit() guard, graceful shutdown, and base modifiers (flutter/flutter#195908) 2026-11-12 [email protected] Roll Packages from 653628e to 14f9933 (9 revisions) (flutter/flutter#196450) 2026-11-12 [email protected] Roll Dart SDK from e5add7a25b32 to 69567bd3c427 (2 revisions) (flutter/flutter#196437) 2026-11-12 [email protected] Roll Skia from 9aa2513a4ac9 to 3b71ec08218f (1 revision) (flutter/flutter#196436) 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 To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 ...
The Skia OpenGL embedder leaves its resource context current on the I/O thread during shutdown. EGL defers destruction while a context remains current, which can retain native graphics resources after engine destruction.
Implement
EmbedderSurfaceGLSkia::ReleaseResourceContextthrough the existing embedder cleanup callback. The shell already invokes this hook on the I/O thread after releasing the last IO manager. The GLES Impeller surface already implements analogous cleanup.Compatibility: for Skia GL embedders that provide
make_resource_current, this adds aclear_currentcall on the I/O thread when the last I/O manager is released during shutdown, so third-party callbacks that assume raster-thread-only execution need review;embedder.hcurrently givesclear_currentno thread contract.Add
ShutdownReleasesOpenGLResourceContextOnItsThread. It wraps the fixture's real graphics callbacks, records the successful resource binding's thread, and verifies that synchronous shutdown clears the context on that thread. The change does not add a public API or alter the embedder ABI.Fixes #193591.
Related: flutter/flutter#138893 identified the same EGL thread-binding mechanism on December 12, 2023. The reporter closed the issue on July 18, 2024, and it was locked on August 1, 2024; no fixing PR is linked there. The linked focused issue provides a standalone native reproduction of the missing Skia resource-context release at
3829a944235cd8e25142d72302dc89db4cd16934.Validation
Windows x64,
host_debug_unopt(--unoptimized --no-lto), source3829a944235cd8e25142d72302dc89db4cd16934:embedder_unittests: 180 passed, 8 skipped, 1 pre-existing disabled test; no failures (exit 0).git diff --check: passed.The eight skips are five AOT-only checks in this JIT build and three golden checks restricted to Linux. No test was disabled or skip condition changed by this patch. Other platforms remain for upstream CI.
A C++ lifecycle comment documents the cleanup. No website documentation update or Dart data-driven fix is included. Public API signatures and ABI layouts are unchanged; third-party callback thread assumptions are called out for compatibility review. The CLA is verified by the passing
cla/googlecheck.Earlier downstream evidence, on Flutter
4cf24164269a5ebf0c16a028a00727d0e77bbb05: stock Windows Skia reached 1,121,796,096 private bytes after 200 window cycles; the repaired build settled at 243,449,856 bytes after 1,000 cycles. These are measurements from that pinned engine, not benchmarks of the upstream revision tested here. The linked issue contains the standalone native reproduction.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-assistbot 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.