-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Impeller] Add rounded superellipse #56726
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really excited to see this work coming along!
|
||
// Points without applying `flip` and `center`. | ||
std::vector<Point> points; | ||
points.reserve(21); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this number from?
// Draw the first quadrant of the shape and store in `points`. It will be | ||
// mirrored to other quadrants later. | ||
std::vector<Point> points; | ||
points.reserve(41); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, what is this number from?
std::vector<Point> points; | ||
points.reserve(41); | ||
|
||
DrawOctantSquareLikeSquircle(points, size.width, corner_radius_, Point{0, -c}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tessellator has a large point area already allocated for temp workloads (ignore name): https://github.com/flutter/engine/blob/main/impeller/tessellator/tessellator.h#L310 . This has 4096 slots of storage. If you can handle overflows by writing to a temp buffer, then its going to be much faster to write there instead of to a newly created vector.
|
||
bool RoundSuperellipseGeometry::CoversArea(const Matrix& transform, | ||
const Rect& rect) const { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd imagine computing a conservative inner rect for the rounded superellipse should be possible, no?
I changed canvas.drawRect to use this geometry and then ran an app that draws a few dozen rectangles to get this profile. It looks like the vast majority of overhead is from temporary allocation. That should disappear if you use the preallocated arenas. Also kAngleStep may be too small for small rectangles. I'm getting ~182 points for a 20x20 squircle. You may want to eyeball some numbers for this based off of the rectangle size. |
Support rounded superellipse.
Part of flutter/flutter#139321 and flutter/flutter#13914, also related to flutter/flutter#91523.
Open questions
corner_radius
:corner_radius
corresponds to SwiftUI parameters. To make the shape definition more generalized, we can instead define thecorner_radius
to be the radius of the corner circles, and make the framework do a look up table.n
) is also mapped from the SwiftUIcornerRadius
, which is not necessary for the shape per se.Demo
Screen.Recording.2024-11-21.at.5.26.56.PM.mp4
Low ratio: (900, 900, 445)
Mid ratio: (900, 650, 180)
High ratio: (900, 650, 17)
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.