Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 35b7dee

Browse files
authored
[Impeller] Set adaptive tolerance when rendering FillPathGeometry (#38497)
* Add tolerance when rendering FillPathGeometry * ++
1 parent 6051576 commit 35b7dee

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

impeller/entity/entity_unittests.cc

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -807,28 +807,37 @@ TEST_P(EntityTest, BlendingModeOptions) {
807807
}
808808

809809
TEST_P(EntityTest, BezierCircleScaled) {
810-
Entity entity;
811-
entity.SetTransformation(Matrix::MakeScale(GetContentScale()));
812-
auto path = PathBuilder{}
813-
.MoveTo({97.325, 34.818})
814-
.CubicCurveTo({98.50862885295136, 34.81812293973836},
815-
{99.46822048142015, 33.85863261475589},
816-
{99.46822048142015, 32.67499810206613})
817-
.CubicCurveTo({99.46822048142015, 31.491363589376355},
818-
{98.50862885295136, 30.53187326439389},
819-
{97.32499434685802, 30.531998226542708})
820-
.CubicCurveTo({96.14153655073771, 30.532123170035373},
821-
{95.18222070648729, 31.491540299350355},
822-
{95.18222070648729, 32.67499810206613})
823-
.CubicCurveTo({95.18222070648729, 33.85845590478189},
824-
{96.14153655073771, 34.81787303409686},
825-
{97.32499434685802, 34.81799797758954})
826-
.Close()
827-
.TakePath();
828-
entity.SetTransformation(
829-
Matrix::MakeScale({20.0, 20.0, 1.0}).Translate({-80, -15, 0}));
830-
entity.SetContents(SolidColorContents::Make(path, Color::Red()));
831-
ASSERT_TRUE(OpenPlaygroundHere(entity));
810+
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
811+
static float scale = 20;
812+
813+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
814+
ImGui::SliderFloat("Scale", &scale, 1, 100);
815+
ImGui::End();
816+
817+
Entity entity;
818+
entity.SetTransformation(Matrix::MakeScale(GetContentScale()));
819+
auto path = PathBuilder{}
820+
.MoveTo({97.325, 34.818})
821+
.CubicCurveTo({98.50862885295136, 34.81812293973836},
822+
{99.46822048142015, 33.85863261475589},
823+
{99.46822048142015, 32.67499810206613})
824+
.CubicCurveTo({99.46822048142015, 31.491363589376355},
825+
{98.50862885295136, 30.53187326439389},
826+
{97.32499434685802, 30.531998226542708})
827+
.CubicCurveTo({96.14153655073771, 30.532123170035373},
828+
{95.18222070648729, 31.491540299350355},
829+
{95.18222070648729, 32.67499810206613})
830+
.CubicCurveTo({95.18222070648729, 33.85845590478189},
831+
{96.14153655073771, 34.81787303409686},
832+
{97.32499434685802, 34.81799797758954})
833+
.Close()
834+
.TakePath();
835+
entity.SetTransformation(
836+
Matrix::MakeScale({scale, scale, 1.0}).Translate({-90, -20, 0}));
837+
entity.SetContents(SolidColorContents::Make(path, Color::Red()));
838+
return entity.Render(context, pass);
839+
};
840+
ASSERT_TRUE(OpenPlaygroundHere(callback));
832841
}
833842

834843
TEST_P(EntityTest, Filters) {

impeller/entity/geometry.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ GeometryResult FillPathGeometry::GetPositionBuffer(
5353
const ContentContext& renderer,
5454
const Entity& entity,
5555
RenderPass& pass) {
56+
auto tolerance =
57+
kDefaultCurveTolerance / entity.GetTransformation().GetMaxBasisLength();
58+
5659
VertexBuffer vertex_buffer;
5760
auto& host_buffer = pass.GetTransientsBuffer();
5861
auto tesselation_result = renderer.GetTessellator()->Tessellate(
59-
path_.GetFillType(), path_.CreatePolyline(),
62+
path_.GetFillType(), path_.CreatePolyline(tolerance),
6063
[&vertex_buffer, &host_buffer](
6164
const float* vertices, size_t vertices_count, const uint16_t* indices,
6265
size_t indices_count) {

0 commit comments

Comments
 (0)