Improve non rect platform view rendering #182662
Conversation
| TEST(ViewSlicerTest, PreservesUnderlayForSelectedViews) { | ||
| std::vector<int64_t> composition_order = {1}; | ||
| std::unordered_map<int64_t, DlRect> view_rects = { | ||
| {1, DlRect::MakeLTRB(0, 0, 100, 100)}}; | ||
|
|
||
| std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> | ||
| baseline_slices; | ||
| AddSliceOfSize(baseline_slices, 1, DlRect::MakeLTRB(0, 0, 50, 50)); | ||
| DisplayListBuilder baseline_builder(DlRect::MakeLTRB(0, 0, 100, 100)); | ||
| auto baseline_overlays = SliceViews(&baseline_builder, composition_order, | ||
| baseline_slices, view_rects); | ||
| EXPECT_EQ(baseline_overlays.size(), 1u); | ||
| auto baseline_dl = baseline_builder.Build(); | ||
| EXPECT_TRUE(ContainsClipDifferenceRect(baseline_dl)); | ||
|
|
||
| std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> | ||
| preserve_slices; | ||
| AddSliceOfSize(preserve_slices, 1, DlRect::MakeLTRB(0, 0, 50, 50)); | ||
| std::unordered_set<int64_t> preserve_underlay_for_views = {1}; | ||
| DisplayListBuilder preserve_builder(DlRect::MakeLTRB(0, 0, 100, 100)); | ||
| auto preserve_overlays = | ||
| SliceViews(&preserve_builder, composition_order, preserve_slices, | ||
| view_rects, &preserve_underlay_for_views); | ||
| EXPECT_EQ(preserve_overlays.size(), 1u); | ||
| auto preserve_dl = preserve_builder.Build(); | ||
| EXPECT_FALSE(ContainsClipDifferenceRect(preserve_dl)); | ||
| } | ||
|
|
There was a problem hiding this comment.
I was unsure how to test this, and got help from AI to write this test, just to be transparent
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where non-rectangular platform views were not rendering correctly by introducing clip-aware handling for different clip types. The changes involve modifying view_slicer.cc and view_slicer.h to accept a set of view IDs for which the underlay should be preserved, and updating FlutterPlatformViewsController.mm to identify and apply complex clips to the overlay canvas. A new unittest PreservesUnderlayForSelectedViews has been added to verify this new functionality. The changes improve the visual correctness of platform views with complex clips, especially in scenarios involving blurred text and backdrop filters.
| #define FLUTTER_FLOW_VIEW_SLICER_H_ | ||
|
|
||
| #include <unordered_map> | ||
| #include <unordered_set> |
There was a problem hiding this comment.
There was a problem hiding this comment.
@hellohuanlin have done this manually but I think this should happen through et format automatically if its an expectation
There was a problem hiding this comment.
i haven't tried et format, but ./ci/format.sh --fix should work
|
fyi @hellohuanlin (I think you've worked with this previously) |
|
Hi @Hari-07, for ease of review & future reference, could you clarify (in PR description) what the blues and reds are in the screenshots? Also please address the gemini comments first? Thanks! |
Sure yeah I just added the code snippet, had forgotten that. Will address the gemini comments when I get some time next |
|
The android changes are just to handle the signature change. I think its better to have explicit empty arg than have it be optional and implicit. Happy to revert that if any of you would prefer that |
eba02e3 to
e3901aa
Compare
|
Hey @Hari-07, thanks for continuing to drill down on the platform view issues. Based on your previous contributions would you be interested in being sponsored for commit access? In addition to other rights, this means only one reviewer is required for your code, not two: https://github.com/flutter/flutter/blob/master/docs/contributing/Contributor-access.md |
|
Hey sure that sounds great , I tried messaging you on discord now too and it said that you only receive messages from friends, and it didn't let me send a friend request either. Not sure what's up there |
|
@Hari-07 hi, could you clarify in the PR description which screenshot is BEFORE and which is AFTER? and could you elaborate what "overlay" and "underlay" are in the PR description? |
gmackall
left a comment
There was a problem hiding this comment.
from android triage, the android plumbing lgtm
|
Hi, I am still a bit confused by the PR description.
By underlay, are you referring to the blue background with "Some random text"? What's the incorrect result of "clipped in a rectangular shape"? The blue background widget with text seems to render correctly.
By overlay do you mean the center blue box?
Which blurred text? The upper left corner or the center text?
which blur text? Also in your code example, the backdrop filter does not contain a platform view, but rather it's a sibling of the platform view on a |
e3901aa to
0f0db8a
Compare
There was a problem hiding this comment.
Thank you for providing the detailed!
I wonder have you thought about blurring the overlay, rather than clipping off part of the overlay and show the underlay?
I ask this because this PR doesn't cover the case where an overlay region that needs to be blurred sits inside the platform view's shape. For example, if there's a Flutter widget (green box below) inside the platform view's shape (red circle), but outside of the backdrop filter, it also needs to be blurred.
| #define FLUTTER_FLOW_VIEW_SLICER_H_ | ||
|
|
||
| #include <unordered_map> | ||
| #include <unordered_set> |
There was a problem hiding this comment.
i haven't tried et format, but ./ci/format.sh --fix should work
|
I did actually think about that case. There are a couple issues. What I showed above is actually a slight simplification. Cos actually the background image isn't part of the overlay at all. The overlay only contains objects drawn in front of the platform view. In the current scenario when overlay is transparent in the region that's inside the rect but outside platform view (4 corners) and we clip the underlay as well, its actually a different layer that's drawn even behind the underlay that shows up. So blurring the overlay wouldn't solve the bug that I originally pointed out. The issue you pointed out is separete To solve that I did think about blurring the overlay as well. As far I can say, that's a one line change here to not skip on applying the blur (not sure what other side effects that may have) but there are some issues with that
I used a different image to hopefully make it clearer
|
|
Thanks for providing new details. This will be on the top of my review stack. Will try to get to it this week. |
|
For blurring over the platform and solving the edge at once, I did find a solution that I posted about here. But that's a wider change I need to think about more |
Could you provide a similar diagram to what was provided? I will be very helpful for future reference. Thanks! |
|
Hey @hellohuanlin , have made the nit changes and marked as ready again. Apologies for the delays |
There was a problem hiding this comment.
Code Review
This pull request modifies the SliceViews function to allow preserving the underlay for specific platform views, primarily to support non-rectangular clips on iOS. It includes updates to the view slicer, unit tests, and the iOS platform views controller. Review feedback highlights a compilation error caused by a function name mismatch in FlutterPlatformViewsController.mm and recommends consistent naming for the new SliceViews parameter across the header and implementation files.
hellohuanlin
left a comment
There was a problem hiding this comment.
LGTM. Thanks for addressing feedbacks. 🚢








Test setup:
Before
After

Definitions:
List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.
Fixes #150660
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
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.