Skip to content

Replace rendering for solid color circles (both filled and stroked) to use SDFs#177482

Merged
walley892 merged 4 commits intoflutter:masterfrom
walley892:sdf-circles
Nov 4, 2025
Merged

Replace rendering for solid color circles (both filled and stroked) to use SDFs#177482
walley892 merged 4 commits intoflutter:masterfrom
walley892:sdf-circles

Conversation

@walley892
Copy link
Contributor

Replace rendering for solid color circles (both filled and stroked) to use SDFs. This change improves the visual quality of circle borders, especially on platforms without MSAA support.

  • Adds a vertex and fragment shader that support SDF rendering for both filled and stroked circles.

  • Adds a Contents subclass, CircleContents that uses these shaders for rendering

  • Modifies Canvas::DrawCircle to use this new contents for drawing circles

  • Only supports circles with a solid color paint. Everything else continues to use the existing behavior

  • Adds a playground test that interactively scales circles to ensure fidelity at all scales.

  • Partially fixes [Impeller] Aliasing artifacts when rendering some SVGs on some Android emulators. #167181

Before (Android emulator):

Screenshot 2025-10-23 at 4 26 18 PM Screenshot 2025-10-23 at 4 29 32 PM

After (Android emulator):

Screenshot 2025-10-23 at 8 48 17 PM Screenshot 2025-10-23 at 4 24 44 PM

Pre-launch Checklist

@walley892 walley892 requested a review from gaaclarke October 24, 2025 04:37
@google-cla
Copy link

google-cla bot commented Oct 24, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Oct 24, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 introduces SDF-based rendering for solid color circles to improve anti-aliasing quality, which is a great enhancement. The changes include new vertex and fragment shaders, a CircleContents class to use these shaders, and modifications in Canvas::DrawCircle to leverage this new path. A new interactive playground test is also added. The implementation looks solid, but I've found a couple of critical duplication issues that will cause build failures, along with several opportunities to improve code clarity and remove dead code.

@gaaclarke
Copy link
Member

@walley892 you're going to have to sign the CLA. if you click that presubmit failure it should link you to getting that resolved

@gaaclarke
Copy link
Member

the ci.yaml validation issue should be able to be resolved by updating your branch (either by merging main or rebasing against main)

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

This is looking really good. Thanks Mr. Walley892. The concerns are:

  1. Usage of fwidth
  2. I want to see how it behaves when scaled
  3. Let's get the ci happy so golden tests run

@walley892 walley892 force-pushed the sdf-circles branch 8 times, most recently from 97fa29e to eb2560a Compare October 24, 2025 21:12
Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Okay, looks good to me. Let's just get CI happy. I think you need to copyright and the others may have been flakes.

Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

I have serious misgivings about the direction here. So far, we have avoided having the fragment shaders be concerned about coverage in most cases. This is a notable departure from that approach. That it is being done for cases where there exists a broken MSAA implementation (emulators) makes me question if this is worthwhile.

I think what I am (hopefully incorrectly) concerned about is what happens when such shapes are used in operations where the coverage matters (like clipping). Won't that affect stenciling operations?

This also adds to the pipeline load which makes startup slower (again for the purpose of addressing emulators with broken MSAA).

@gaaclarke
Copy link
Member

I have serious misgivings about the direction here. So far, we have avoided having the fragment shaders be concerned about coverage in most cases. This is a notable departure from that approach. That it is being done for cases where there exists a broken MSAA implementation (emulators) makes me question if this is worthwhile.

I think what I am (hopefully incorrectly) concerned about is what happens when such shapes are used in operations where the coverage matters (like clipping). Won't that affect stenciling operations?

This also adds to the pipeline load which makes startup slower (again for the purpose of addressing emulators with broken MSAA).

I had those conversations with Evan already, I'll throw something on your calendar to discuss it.

@chinmaygarde
Copy link
Contributor

From the conversation, I was mistaken about the coverage geometry changing. The additional pipeline variant is unfortunate but Aaron says this is a one off. Looks good to me! Thanks for giving the additional context.

@walley892 walley892 force-pushed the sdf-circles branch 2 times, most recently from 2cea4fe to 08326c1 Compare October 28, 2025 18:58
@gaaclarke
Copy link
Member

FYI I'm happy with the code right now. I'm ready to approve when we are happy with the goldens. I think there were a few that mr wally892 wanted to look at. Particularly relating to think tiny rings evaporating from the anti-aliasing.

@walley892
Copy link
Contributor Author

FYI I'm happy with the code right now. I'm ready to approve when we are happy with the goldens. I think there were a few that mr wally892 wanted to look at. Particularly relating to think tiny rings evaporating from the anti-aliasing.

Changed the fragment shader to handle this case. Stroked circles that would be drawn just one pixel wide are just rendered as is with no fading.

@@ -51,12 +51,19 @@ void main() {

float pixelDerivativeSDF = fwidth(sdfDistance);
Copy link
Member

@gaaclarke gaaclarke Oct 29, 2025

Choose a reason for hiding this comment

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

Can you change this file to have consistent variable naming following the c++ style guide? ex pixel_deriviative_sdf

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

lgtm as long as the goldens are happy

@github-actions github-actions bot removed f: focus Focus traversal, gaining or losing focus team-ecosystem Owned by Ecosystem team team-android Owned by Android platform team team-ios Owned by iOS platform team d: docs/ flutter/flutter/docs, for contributors labels Oct 30, 2025
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #177482 at sha 8dd29b8

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Oct 30, 2025
Copy link
Member

@jtmcdole jtmcdole left a comment

Choose a reason for hiding this comment

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

![awesome-computer-kid-computer-lgtm](

Warning

This asset could not be copied from your saved reply. Please try again later.

)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[Impeller] Aliasing artifacts when rendering some SVGs on some Android emulators.

5 participants