Skip to content

Add ClipPath optimizations to backdrop clips as well - #189118

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Hari-07:clipoval-fix
Aug 11, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
Hari-07:clipoval-fix

Conversation

@Hari-07

@Hari-07 Hari-07 commented Jul 8, 2026 •

Copy link
Copy Markdown
Member
  • In clip_path_layer.cc, ApplyClip() has optimizations to convert to more efficient shapes if applicable. This PR extends that behaviour to backdrop clips as well
  • We previously didn't add the backdrop clip pushes to the mock embedder. This extends the mock embedder, adds coverage for the existing push backdrop clip methods as well as the various cases for backdrop path clip added in this PR

Fixes #188971

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.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jul 8, 2026
@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Jul 8, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@Hari-07

Hari-07 commented Jul 8, 2026

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 ClipPathLayer to inspect its clip shape and push the most specific clip type (Rect, Oval, or RoundRect) to the view embedder instead of always pushing a generic path. It also updates MockViewEmbedder and adds corresponding unit tests to verify that the correct clip types are pushed for various clip layers. The feedback suggests refactoring the nested conditional checks in ClipPathLayer::PushClipToEmbeddedNativeViewMutatorStack by caching the clip shape reference and using C++17 init-statements to improve readability.

Comment on lines 35 to 51
void ClipPathLayer::PushClipToEmbeddedNativeViewMutatorStack(
ExternalViewEmbedder* view_embedder) const {
view_embedder->PushClipPathToVisitedPlatformViews(clip_shape());
DlRect rect;
if (clip_shape().IsRect(&rect)) {
view_embedder->PushClipRectToVisitedPlatformViews(rect);
} else if (clip_shape().IsOval(&rect)) {
view_embedder->PushClipRRectToVisitedPlatformViews(
DlRoundRect::MakeOval(rect));
} else {
DlRoundRect rrect;
if (clip_shape().IsRoundRect(&rrect)) {
view_embedder->PushClipRRectToVisitedPlatformViews(rrect);
} else {
view_embedder->PushClipPathToVisitedPlatformViews(clip_shape());
}
}
}

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

The current implementation calls clip_shape() multiple times and uses nested if-else blocks, which increases nesting and reduces readability.\n\nWe can improve this by:\n1. Caching the result of clip_shape() in a local const DlPath& reference.\n2. Flattening the control flow using a C++17 init-statement in the else if block to declare DlRoundRect rrect only where it is needed.\n\nThis simplifies the logic and makes the code much cleaner and easier to read.

void ClipPathLayer::PushClipToEmbeddedNativeViewMutatorStack(\n    ExternalViewEmbedder* view_embedder) const {\n  const DlPath& path = clip_shape();\n  DlRect rect;\n  if (path.IsRect(&rect)) {\n    view_embedder->PushClipRectToVisitedPlatformViews(rect);\n  } else if (path.IsOval(&rect)) {\n    view_embedder->PushClipRRectToVisitedPlatformViews(\n        DlRoundRect::MakeOval(rect));\n  } else if (DlRoundRect rrect; path.IsRoundRect(&rrect)) {\n    view_embedder->PushClipRRectToVisitedPlatformViews(rrect);\n  } else {\n    view_embedder->PushClipPathToVisitedPlatformViews(path);\n  }\n}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

clip_shape() just returns the instance so doesn't matter much. No strong opinion on the C++17 syntax, I wanted to keep the shape consistent with ApplyClip above

@Hari-07
Hari-07 requested a review from hellohuanlin July 8, 2026 07:33

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

sorry for the delay - just one nit

ExternalViewEmbedder* view_embedder) const {
view_embedder->PushClipPathToVisitedPlatformViews(clip_shape());
DlRect rect;
if (clip_shape().IsRect(&rect)) {

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.

can you call clip_shape() once upfront to avoid calling it multiple times?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about doing that but clip_shape() is just a getter and I wanted to match the pattern in ApplyClip but down to change. Should I update both spots?

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.

oh if it's just a getter, then im fine either way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah its just const ClipShape& clip_shape() const { return clip_shape_; }

@Hari-07 Hari-07 added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 8, 2026
@auto-submit

auto-submit Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/189118, 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.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 8, 2026
@Hari-07 Hari-07 added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 11, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 11, 2026
Merged via the queue into flutter:master with commit b5971ca Aug 11, 2026
21 of 22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 11, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BackdropFilter blur ignores ClipOval when a UiKitView is in the tree (Impeller, iOS, regression persists in 3.44.4)

2 participants