Skip to content

Makes sure impeller context's are plumbed through to LayerTree::Flatten. - #191017

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
gaaclarke:flatten-impeller-gles
Aug 17, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
gaaclarke:flatten-impeller-gles

Conversation

@gaaclarke

@gaaclarke gaaclarke commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

fixes #190774

There was just some required plumbing that had to happen for impeller with external textures in certain cases.

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 the engine flutter/engine related. See also e: labels. label Aug 12, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Aug 12, 2026
@gaaclarke

Copy link
Copy Markdown
Member Author

/gemini review

@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 updates LayerTree::Flatten to accept an optional impeller::AiksContext parameter, propagating it to the PaintContext to support Impeller-enabled rendering. These changes are integrated into DlDeferredImageGPUImpeller and Picture rasterization, and null-safety checks are added to EmbedderExternalTextureGL along with corresponding unit tests. The feedback suggests simplifying redundant ternary checks on aiks_context to directly call aiks_context.get() in display_list_deferred_image_gpu_impeller.cc and picture.cc to improve readability.

@gaaclarke
gaaclarke force-pushed the flatten-impeller-gles branch from 8a1357c to 65b7bb5 Compare August 12, 2026 22:37
@gaaclarke
gaaclarke force-pushed the flatten-impeller-gles branch from fa05d57 to e9687d8 Compare August 12, 2026 22:41
@gaaclarke
gaaclarke marked this pull request as ready for review August 12, 2026 22:43
@gaaclarke

Copy link
Copy Markdown
Member Author

we might want to consider this for cherry-pickin

@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 updates LayerTree::Flatten to accept an impeller::AiksContext parameter, enabling the propagation of Impeller context information during layer tree flattening. These changes are integrated into DlDeferredImageGPUImpeller and Picture::DoRasterizeToImage. Additionally, safety checks are added to EmbedderExternalTextureGL to prevent crashes when the context is null, supported by new unit tests. The review feedback suggests simplifying the implementation in picture.cc and display_list_deferred_image_gpu_impeller.cc by passing the AiksContext pointer directly to Flatten to avoid unnecessary local variables and complex ternary expressions.

Comment on lines +254 to +261
auto aiks_context = is_impeller_enabled
? snapshot_delegate->GetAiksContext()
: nullptr;
snapshot_display_list = layer_tree->Flatten(
DlRect::MakeWH(width, height),
snapshot_delegate->GetTextureRegistry(),
is_impeller_enabled ? nullptr : snapshot_delegate->GetGrContext(),
aiks_context.get());

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

We can simplify this code and avoid the ternary operator type deduction issue with auto and nullptr by passing the AiksContext pointer directly to Flatten. Since the ternary operator uses short-circuit evaluation, GetAiksContext() will only be called if is_impeller_enabled is true, and the temporary std::shared_ptr returned will remain alive until the end of the statement.

          snapshot_display_list = layer_tree->Flatten(
              DlRect::MakeWH(width, height),
              snapshot_delegate->GetTextureRegistry(),
              is_impeller_enabled ? nullptr : snapshot_delegate->GetGrContext(),
              is_impeller_enabled ? snapshot_delegate->GetAiksContext().get() : nullptr);
References
  1. Suggest simplification and refactoring to enhance readability and maintainability. (link)

@andywolff andywolff 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.

LGTM, makes sense to me why this would fix the issue. I confirmed the new unit test fails without the change and passes with it

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 17, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 17, 2026
Merged via the queue into flutter:master with commit bb85680 Aug 17, 2026
24 checks passed
@gaaclarke gaaclarke added the cp: stable cherry pick this pull request to stable release candidate branch label Aug 17, 2026
purepoorx pushed a commit to purepoorx/dart_simple_live that referenced this pull request Oct 14, 2026
Flutter 3.47.1 在 Windows + Impeller 下渲染 DXGI 共享句柄 GPU 外部纹理
(media_kit 视频输出)时,退出直播间会触发路由退场动画的快照路径:
LayerTree::Flatten 构造的 PaintContext 中 aiks_context 为空且
GrDirectContext 为 null,EmbedderExternalTextureGL::ResolveTextureSkia
未做空值检查直接解引用,导致 flutter_windows.dll 读取地址 0x0 崩溃。

上游 issue: flutter/flutter#190774, flutter/flutter#191468
修复 PR: flutter/flutter#191017(3.47 分支 cherry-pick #191222,
2026-08-24 合入,故 3.47.1 不含修复)

- simple_live_app/.fvmrc: 3.47.1 -> 3.47.7
- simple_live_tv_app/.fvmrc: 3.47.1 -> 3.47.7
- AGENTS.md / README.md: 同步 Flutter 版本说明
knasher added a commit to knasher/flutter-sailfish that referenced this pull request Oct 27, 2026
Flutter renders with Impeller on iOS and Android, but release builds of this embedder could only use Skia. On Jolla Phone 2026, Impeller removes Skia's long stutters on blur-heavy frames: in a menu animation the slowest tenth of frames went from 52 ms to 39 ms, and the worst from 211 ms to 59 ms.

Embedder patch 0015 makes Impeller the default, with FLUTTER_SFOS_IMPELLER=0 to use Skia. Two engine patches make it work here: 0002 applies the embedder's surface transformation in Impeller's OpenGL surface, which ignored it and drew rotated apps sideways, and 0003 backports flutter/flutter#191017, without which a page transition away from a playing video crashed on the raster thread. PORTING has a Rendering section.

Tested on Jolla Phone 2026, SFOS 5.2.0.20, in a sandboxed copy of a real app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: stable cherry pick this pull request to stable release candidate branch engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows][Impeller] Snapshotting a GPU-surface external texture calls ResolveTextureSkia and crashes in GrDirectContext::flush

2 participants