Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Engine] RSuperellipse.contains that reuses C++ implementation #164857

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Mar 9, 2025

This PR implements RSuperellipse.contains. Different from the previous attempt #164517, this PR leverages the existing C++ implementation via FFI.

The biggest outcome of this PR is to enable future work that generates RSE paths in the framework.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added engine flutter/engine repository. See also e: labels. platform-web Web applications specifically labels Mar 9, 2025
@dkwingsmt dkwingsmt marked this pull request as ready for review March 10, 2025 17:56
@dkwingsmt
Copy link
Contributor Author

@jonahwilliams Can you take a look and see if this approach is acceptable?

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

I'm not really convinced that subpixel accuracy is necessary for accurate hit testing (which already has a slop of 8-16 px) compared to the rrect approximation.

@jonahwilliams jonahwilliams requested a review from gaaclarke March 10, 2025 18:38
@dkwingsmt
Copy link
Contributor Author

dkwingsmt commented Mar 10, 2025

I'm not really convinced that subpixel accuracy is necessary for accurate hit testing (which already has a slop of 8-16 px) compared to the rrect approximation.

I agree, so I might not apply this to the clipping. However the ability to convert RSE to paths is crucial (such as to create a corresponding class of RoundedRectangleBorder) and we need this FFI to achieve this. This PR is mostly a baby step before the path changes.

@jonahwilliams
Copy link
Member

If you're converting the RSE paths then you're essentially falling back to the RRect or bezier approximation, which seems to defeat the purpose of a high fidelity backend implementation. If that is an acceptable trade off, then you should instead perform the bezier approximation in the framework and remove the engine specific API.

Can we instead adjust the API in the framework where needed to support more than Paths?

@dkwingsmt dkwingsmt marked this pull request as draft March 11, 2025 20:29
@dkwingsmt
Copy link
Contributor Author

dkwingsmt commented Mar 11, 2025

The path is used in ShapeBorder.innerPath and outerPath. The two methods are supposed to be used as fallbacks. I agree that the fallback should be defined by backends, instead being forced upon all shapes.

I'll investigate whether I can deprecate these methods. Meanwhile I'm closing this PR for now.

@dkwingsmt dkwingsmt closed this Mar 11, 2025
@dkwingsmt dkwingsmt reopened this Mar 14, 2025
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

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.

@dkwingsmt
Copy link
Contributor Author

dkwingsmt commented Mar 14, 2025

@jonahwilliams I've searched get(Inner|Outer)Path throughout the repository and the paths are used in a lot of widgets to paint and clip. Although I still agree that these two methods should be refactored away and think it's theoretically possible (I'm also asking the original authors to see if there are any reasons for the current design.), it would be a really big project. For example, some of the acquired paths are stored and used later, which is going to take non-trivial efforts to refactor away.

Therefore I think we should move ahead with the path implementation and seek to perform the refactor in a separate project.

@jonahwilliams
Copy link
Member

Lets talk about this one tomorrow too. I have more questions, it will probably be faster to chat in person.

@github-actions github-actions bot added the e: impeller Impeller rendering backend issues and features requests label Mar 18, 2025
@jonahwilliams
Copy link
Member

KK so I did some profiling of figma_squircle and ... I can't say its any slower? If anything it can be a bit faster on older hardware, possibly because the RSE tessellator is generating more geometry (though I'd need to investigate it).

So If there are no performance issues, its fine to use the bezier appromination - and the RSE geom can just be a specialization of that.

So no changes needed for this PR @dkwingsmt , beyond review feedback

@dkwingsmt
Copy link
Contributor Author

Thank you! I'll take a look at the comments.

@dkwingsmt dkwingsmt marked this pull request as ready for review March 22, 2025 01:55
@dkwingsmt
Copy link
Contributor Author

dkwingsmt commented Mar 22, 2025

I've significantly changed and simplified the design.

  • The native class of Dart RSuperellipse is no longer a subclass RSuperellipse, but is instead a regular native class with no storage, called _NativeRSuperellipse.
  • The Dart RSuperellipse class no longer caches _NativeRSuperellipse, and the C++ RSuperellipse class no longer caches RoundSuperellipseParam. Caching can always be added later (we can store the param as a private field), but such optimization should be added based on benchmark.
  • There are no more getValue. Dart RSuperellipse's values are store twice, both in Dart and in C++.

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 repository. See also e: labels. platform-web Web applications specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants