Skip to content

Adds sdf rrects (and fixes opacity + color source)#184999

Merged
gaaclarke merged 5 commits into
flutter:masterfrom
gaaclarke:sdf-rrect
Apr 17, 2026
Merged

Adds sdf rrects (and fixes opacity + color source)#184999
gaaclarke merged 5 commits into
flutter:masterfrom
gaaclarke:sdf-rrect

Conversation

@gaaclarke

@gaaclarke gaaclarke commented Apr 13, 2026

Copy link
Copy Markdown
Member

fixes #183038

This also fixes a bug in the color source rendering where if the opacity was something other than 1.0 the opacity value would get doubled. This is avoided by overwriting the opacity value used by the uber sdf.

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 engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Apr 13, 2026
@gaaclarke gaaclarke changed the title Sdf rrect Adds sdf rrects Apr 13, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Apr 13, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 13, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Apr 13, 2026
const RoundingRadii& radii = round_rect.GetRadii();

if (renderer_.GetContext()->GetFlags().use_sdfs &&
!paint.mask_blur_descriptor.has_value() && AreCornersCircular(radii)) {

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'll file a followup issue for non-circular corners. I'm not sure how high of a priority that is though.

@gaaclarke

Copy link
Copy Markdown
Member Author

The crosses in FilledRoundRectPathsRenderCorrectly look much more transparent when drawn with the ubersdf shader.

@gaaclarke

Copy link
Copy Markdown
Member Author

The differences in the colors has to do with drawing things when the paint has opacity (ex paint.setColor(DlColor::kWhite().modulateOpacity(0.5));)

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@gaaclarke gaaclarke changed the title Adds sdf rrects Adds sdf rrects (and fixes opacity + color source) Apr 14, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Apr 14, 2026
@gaaclarke gaaclarke marked this pull request as ready for review April 14, 2026 18:27
@gaaclarke gaaclarke requested review from b-luk and walley892 April 14, 2026 18:27

@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 adds rounded rectangle support to the UberSDF renderer by implementing distanceFromRoundedRect in the fragment shader and updating Canvas::DrawRoundRect to use SDF rendering for circular corners. It also refactors AddRenderSDFEntityToCurrentPass to use UberSDFParameters. Feedback identifies a mismatch in corner radii mapping in Canvas::DrawRoundRect and requests the removal of an unnecessary newline in the shader.

Comment thread engine/src/flutter/impeller/display_list/canvas.cc Outdated
Comment thread engine/src/flutter/impeller/entity/shaders/uber_sdf.frag
Comment thread engine/src/flutter/impeller/entity/shaders/uber_sdf.frag
Comment thread engine/src/flutter/impeller/entity/shaders/uber_sdf.frag
Comment thread engine/src/flutter/impeller/display_list/canvas.cc

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

Couple of comments

Comment thread engine/src/flutter/impeller/entity/contents/uber_sdf_parameters.cc Outdated
Comment thread engine/src/flutter/impeller/entity/shaders/uber_sdf.frag
Comment thread engine/src/flutter/impeller/display_list/canvas.cc
Comment thread engine/src/flutter/impeller/display_list/canvas.cc Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Apr 14, 2026
// https://www.youtube.com/c/InigoQuilez
// https://iquilezles.org

float distanceFromRoundedRect(in vec2 p, in vec2 b, in vec4 r) {

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.

In a followup PR I think we should sort these out into their own file, sdf.glsl.

@gaaclarke gaaclarke requested review from b-luk and walley892 April 14, 2026 20:54
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Apr 14, 2026
Comment thread engine/src/flutter/impeller/entity/contents/uber_sdf_parameters.h Outdated
Comment on lines +189 to +195
bool AreCornersCircular(const RoundingRadii& radii) {
return ScalarNearlyEqual(radii.top_left.width, radii.top_left.height) &&
ScalarNearlyEqual(radii.top_right.width, radii.top_right.height) &&
ScalarNearlyEqual(radii.bottom_left.width, radii.bottom_left.height) &&
ScalarNearlyEqual(radii.bottom_right.width, radii.bottom_right.height);
}

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.

Should this be a method on RoundingRadii like other similar methods?

constexpr bool AreAllCornersEmpty() const {
return top_left.IsEmpty() && //
top_right.IsEmpty() && //
bottom_left.IsEmpty() && //
bottom_right.IsEmpty();
}
constexpr bool AreAllCornersSame(Scalar tolerance = kEhCloseEnough) const {
return ScalarNearlyEqual(top_left.width, top_right.width, tolerance) &&
ScalarNearlyEqual(top_left.width, bottom_right.width, tolerance) &&
ScalarNearlyEqual(top_left.width, bottom_left.width, tolerance) &&
ScalarNearlyEqual(top_left.height, top_right.height, tolerance) &&
ScalarNearlyEqual(top_left.height, bottom_right.height, tolerance) &&
ScalarNearlyEqual(top_left.height, bottom_left.height, tolerance);
}
?

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.

The rule of thumb I kind of follow is that if there is only one client to a function it's better to keep it a free function, if there are more than one then put it in the class. That avoids class bloat.

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.

SGTM

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 17, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Apr 17, 2026
@gaaclarke

Copy link
Copy Markdown
Member Author

One golden looked goofy: impeller_Play_AiksTest_FilledEllipsesRenderCorrectly_MetalSDF. This looks like the problem we had with rrects. Since we had merge conflicts i can take a quick peek otherwise follow up in a different PR.

before

984006b9607c8739f9ff557c4468a32e

after

519a31d30cb23cda4e8ee5931b42abb7

@gaaclarke

Copy link
Copy Markdown
Member Author

One golden looked goofy: impeller_Play_AiksTest_FilledEllipsesRenderCorrectly_MetalSDF. This looks like the problem we had with rrects. Since we had merge conflicts i can take a quick peek otherwise follow up in a different PR.

Okay, turns out this actually is fixing the test. We previously accepted a failure. We need to remove that golden after this lands.

@gaaclarke gaaclarke requested review from b-luk and walley892 April 17, 2026 16:49
@gaaclarke

Copy link
Copy Markdown
Member Author

@b-luk @walley892 flar's refactor happened to collide with my PR before it landed so I'm coming to you yet again, hat in hand, to ask for a review. The only difference is it uses flar's GetStroke function.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 17, 2026
@b-luk

b-luk commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Okay, turns out this actually is fixing the test. We previously accepted a failure. We need to remove that golden after this lands.

Yes, all the different positive goldens make the diffs confusing. Should we actively try to mark every previous golden as untriaged whenever we merge a PR that updates a golden?

@gaaclarke

Copy link
Copy Markdown
Member Author

Yes, all the different positive goldens make the diffs confusing. Should we actively try to mark every previous golden as untriaged whenever we merge a PR that updates a golden?

That's not an absolute rule of thumb. When the baseline of what is acceptable is changing we should. For flux like with blurs and gradients where they look the same to the human eye, no.

@walley892

Copy link
Copy Markdown
Contributor

The impeller_Play_AiksTest_FilledEllipsesRenderCorrectly_MetalSDF golden was changed by the oval PR #184903. This PR correctly fixes the alpha.

@gaaclarke gaaclarke added this pull request to the merge queue Apr 17, 2026
Merged via the queue into flutter:master with commit 6a98710 Apr 17, 2026
198 of 199 checks passed
@gaaclarke gaaclarke deleted the sdf-rrect branch April 17, 2026 19:42
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 19, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 20, 2026
flutter/flutter@8e8a194...2844af6

2026-04-19 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from bWoigpGIb60B6C7hD... to aDbXQm6WA0wFCAUp-... (flutter/flutter#185253)
2026-04-18 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from di3JdYrdE9OFu8Iyl... to bWoigpGIb60B6C7hD... (flutter/flutter#185231)
2026-04-18 rmolivares@renzo-olivares.dev Fix: text selection context menu should reappear after a non-fling scroll on Android and iOS (flutter/flutter#185054)
2026-04-18 flar@google.com Rect constructors for circle bounds (MakeCircle/EllipseBounds) (flutter/flutter#185110)
2026-04-17 97480502+b-luk@users.noreply.github.com Change uber SDF to get pixel size (for AA) using euclidean distance rather than manhattan distance. (flutter/flutter#184984)
2026-04-17 engine-flutter-autoroll@skia.org Roll Dart SDK from 7c2564c18770 to 9648f446f131 (7 revisions) (flutter/flutter#185223)
2026-04-17 47866232+chunhtai@users.noreply.github.com Rewrites no-response workflow to work with pr as well (flutter/flutter#185163)
2026-04-17 15619084+vashworth@users.noreply.github.com Only use LLDB breakpoint in debug mode (flutter/flutter#185158)
2026-04-17 flar@google.com add playground to test SDF primitive rendering under transforms (flutter/flutter#185010)
2026-04-17 30870216+gaaclarke@users.noreply.github.com Adds sdf rrects (and fixes opacity + color source) (flutter/flutter#184999)
2026-04-17 matt.kosarek@canonical.com Implementation of popup windows for Win32 (flutter/flutter#184516)
2026-04-17 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from R2EllDf4DgBXVNuiN... to dQ4PjIJB5kZFU8Y32... (flutter/flutter#185207)
2026-04-17 chris@bracken.jp [iOS] Update previousCompositionOrder to return Obj-C type (flutter/flutter#185136)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com 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

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11531)

flutter/flutter@8e8a194...2844af6

2026-04-19 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from bWoigpGIb60B6C7hD... to aDbXQm6WA0wFCAUp-... (flutter/flutter#185253)
2026-04-18 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from di3JdYrdE9OFu8Iyl... to bWoigpGIb60B6C7hD... (flutter/flutter#185231)
2026-04-18 rmolivares@renzo-olivares.dev Fix: text selection context menu should reappear after a non-fling scroll on Android and iOS (flutter/flutter#185054)
2026-04-18 flar@google.com Rect constructors for circle bounds (MakeCircle/EllipseBounds) (flutter/flutter#185110)
2026-04-17 97480502+b-luk@users.noreply.github.com Change uber SDF to get pixel size (for AA) using euclidean distance rather than manhattan distance. (flutter/flutter#184984)
2026-04-17 engine-flutter-autoroll@skia.org Roll Dart SDK from 7c2564c18770 to 9648f446f131 (7 revisions) (flutter/flutter#185223)
2026-04-17 47866232+chunhtai@users.noreply.github.com Rewrites no-response workflow to work with pr as well (flutter/flutter#185163)
2026-04-17 15619084+vashworth@users.noreply.github.com Only use LLDB breakpoint in debug mode (flutter/flutter#185158)
2026-04-17 flar@google.com add playground to test SDF primitive rendering under transforms (flutter/flutter#185010)
2026-04-17 30870216+gaaclarke@users.noreply.github.com Adds sdf rrects (and fixes opacity + color source) (flutter/flutter#184999)
2026-04-17 matt.kosarek@canonical.com Implementation of popup windows for Win32 (flutter/flutter#184516)
2026-04-17 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from R2EllDf4DgBXVNuiN... to dQ4PjIJB5kZFU8Y32... (flutter/flutter#185207)
2026-04-17 chris@bracken.jp [iOS] Update previousCompositionOrder to return Obj-C type (flutter/flutter#185136)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com 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

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RRect SDF renderer to uber shader

4 participants