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

[Impeller] Set adaptive tolerance when rendering FillPathGeometry #38497

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -807,28 +807,37 @@ TEST_P(EntityTest, BlendingModeOptions) {
}

TEST_P(EntityTest, BezierCircleScaled) {
Entity entity;
entity.SetTransformation(Matrix::MakeScale(GetContentScale()));
auto path = PathBuilder{}
.MoveTo({97.325, 34.818})
.CubicCurveTo({98.50862885295136, 34.81812293973836},
{99.46822048142015, 33.85863261475589},
{99.46822048142015, 32.67499810206613})
.CubicCurveTo({99.46822048142015, 31.491363589376355},
{98.50862885295136, 30.53187326439389},
{97.32499434685802, 30.531998226542708})
.CubicCurveTo({96.14153655073771, 30.532123170035373},
{95.18222070648729, 31.491540299350355},
{95.18222070648729, 32.67499810206613})
.CubicCurveTo({95.18222070648729, 33.85845590478189},
{96.14153655073771, 34.81787303409686},
{97.32499434685802, 34.81799797758954})
.Close()
.TakePath();
entity.SetTransformation(
Matrix::MakeScale({20.0, 20.0, 1.0}).Translate({-80, -15, 0}));
entity.SetContents(SolidColorContents::Make(path, Color::Red()));
ASSERT_TRUE(OpenPlaygroundHere(entity));
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
static float scale = 20;

ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SliderFloat("Scale", &scale, 1, 100);
ImGui::End();

Entity entity;
entity.SetTransformation(Matrix::MakeScale(GetContentScale()));
auto path = PathBuilder{}
.MoveTo({97.325, 34.818})
.CubicCurveTo({98.50862885295136, 34.81812293973836},
{99.46822048142015, 33.85863261475589},
{99.46822048142015, 32.67499810206613})
.CubicCurveTo({99.46822048142015, 31.491363589376355},
{98.50862885295136, 30.53187326439389},
{97.32499434685802, 30.531998226542708})
.CubicCurveTo({96.14153655073771, 30.532123170035373},
{95.18222070648729, 31.491540299350355},
{95.18222070648729, 32.67499810206613})
.CubicCurveTo({95.18222070648729, 33.85845590478189},
{96.14153655073771, 34.81787303409686},
{97.32499434685802, 34.81799797758954})
.Close()
.TakePath();
entity.SetTransformation(
Matrix::MakeScale({scale, scale, 1.0}).Translate({-90, -20, 0}));
entity.SetContents(SolidColorContents::Make(path, Color::Red()));
return entity.Render(context, pass);
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_P(EntityTest, Filters) {
Expand Down
5 changes: 4 additions & 1 deletion impeller/entity/geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ GeometryResult FillPathGeometry::GetPositionBuffer(
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) {
auto tolerance =
kDefaultCurveTolerance / entity.GetTransformation().GetMaxBasisLength();
Copy link
Member

Choose a reason for hiding this comment

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

Does the max basis length need to be bottom-bound to e.g. 0.1f for this? What happens when the transform is scaled to 0 and the tolerance becomes NaN?

Copy link
Contributor Author

@luckysmg luckysmg Jan 4, 2023

Choose a reason for hiding this comment

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

Hello @bdero
It becomes below when I set auto tolerance = kDefaultCurveTolerance / 0;

And the change in this PR is almost the same like code in StrokePathGeometry
See
https://github.com/flutter/engine/blob/main/impeller/entity/geometry.cc#L420-#L422

So I think it would be better to keep it a same way to compute tolerance ^_^

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for checking! This seems like good behavior.


VertexBuffer vertex_buffer;
auto& host_buffer = pass.GetTransientsBuffer();
auto tesselation_result = renderer.GetTessellator()->Tessellate(
path_.GetFillType(), path_.CreatePolyline(),
path_.GetFillType(), path_.CreatePolyline(tolerance),
[&vertex_buffer, &host_buffer](
const float* vertices, size_t vertices_count, const uint16_t* indices,
size_t indices_count) {
Expand Down