Repository navigation
[CP-Beta] Fix Rect::ExpandToMinTransformedSize to return the input rectangle when no expansion is needed, and remove 1-pixel roundrect to rect simplification - #189885
Conversation
…when no expansion is needed, and remove 1-pixel roundrect to rect simplification (flutter#189808) Fixes flutter#189807 See the issue for more context. Adds a unit test that fails without this change, and passes with this change. Verified the demo app in the issue renders properly with this change. From the issue: ## Root cause and fix [Rect::ExpandToMinTransformedSize](https://github.com/flutter/flutter/blob/1c8b3088238220102df66761685f3a4718b5aa15/engine/src/flutter/impeller/geometry/rect.h#L705) always constructs a new expanded rectangle from the input Rect from its center point and half-extents. If the input rectangle is already large enough and does not need expansion, this should return an identical rectangle. The returned rectangle is equality-checked against the input in [Canvas::DrawRoundRect](https://github.com/flutter/flutter/blob/1c8b3088238220102df66761685f3a4718b5aa15/engine/src/flutter/impeller/display_list/canvas.cc#L1129) to determine whether expansion happened. That code assumes that if the output does not equal the input, pixel-expansion happened, which means that the rounded rect had sub-pixel dimensions and can be safely drawn as a non-rounded rectangle. The issue is that for certain cases, particularly with non-integer sizes, ExpandToMinTransformedSize returns a different rectangle even if no expansion happened. This is due to small floating point imprecisions when constructing the new rectangle using the input rectangle's center and half-extents. To fix this, ExpandToMinTransformedSize should not construct a new rectangle unless expansion is actually needed. ## Removal of 1-pixel roundrect to rect simplification This PR also removes the 1-pixel roundrect to rect simplification in `Canvas::DrawRoundRect`. As described in flutter#189807 (comment), this optimization resulted in slightly different colors at the tips of thin roundrects. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] 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/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [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 [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
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request refactors the rect expansion logic in Impeller. It introduces an early return in TRect when the size is already larger than or equal to the minimum local size, simplifying the 1-pixel minimum expansion in Canvas::DrawRoundRect. Additionally, a regression test has been added to verify this behavior with fractional sizes. No review comments were provided, and there is no additional feedback.
|
CICD will likely fail until #189888 lands |
4937835
into
flutter:flutter-3.47-candidate.0
This was a manual cherry pick of #189808.
Issue Link:
What is the link to the issue this cherry-pick is addressing?
#189807
Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.
Rounded rectangles are sometimes incorrectly rendered as non-rounded rectangles.
This issue is present when impeller is enabled Impeller with SDF rendering. In the beta channel, Impeller with SDF rendering is the default when building apps for desktop platforms: macOS, Linux, and Windows.
Changelog Description:
Explain this cherry pick:
See best practices for examples.
< Replace with changelog description here >
flutter/189807: Rounded rectangles are sometimes incorrectly rendered as non-rounded rectangles.
Workaround:
Is there a workaround for this issue?
Disable Impeller, falling back to Skia rendering.
Risk:
What is the risk level of this cherry-pick?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
What are the steps to validate that this fix works?
The demo app at #189807 should render two rounded rectangles, rather than one normal rectangle and one rounded rectangle.