From 3e5bdac801f3887122e2cc73ecdfb6e1566d99d2 Mon Sep 17 00:00:00 2001 From: luckysmg <2539699336@qq.com> Date: Sun, 25 Dec 2022 21:25:01 +0800 Subject: [PATCH 1/2] Add tolerance when rendering FillPathGeometry --- impeller/entity/entity_unittests.cc | 53 +++++++++++++++++------------ impeller/entity/geometry.cc | 5 ++- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index ed89d7f9c9254..31bd009a123db 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -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) { diff --git a/impeller/entity/geometry.cc b/impeller/entity/geometry.cc index 8bc37b352a978..8ae78b53de8e3 100644 --- a/impeller/entity/geometry.cc +++ b/impeller/entity/geometry.cc @@ -53,10 +53,13 @@ GeometryResult FillPathGeometry::GetPositionBuffer( const ContentContext& renderer, const Entity& entity, RenderPass& pass) { + auto tolerance = + kDefaultCurveTolerance / (entity.GetTransformation().GetMaxBasisLength()); + 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) { From 21fe1fc1eb695ac0e7d5bdf85fb464d330dbb7be Mon Sep 17 00:00:00 2001 From: luckysmg <2539699336@qq.com> Date: Mon, 26 Dec 2022 10:36:06 +0800 Subject: [PATCH 2/2] ++ --- impeller/entity/geometry.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/entity/geometry.cc b/impeller/entity/geometry.cc index 8ae78b53de8e3..177fc3dc90d20 100644 --- a/impeller/entity/geometry.cc +++ b/impeller/entity/geometry.cc @@ -54,7 +54,7 @@ GeometryResult FillPathGeometry::GetPositionBuffer( const Entity& entity, RenderPass& pass) { auto tolerance = - kDefaultCurveTolerance / (entity.GetTransformation().GetMaxBasisLength()); + kDefaultCurveTolerance / entity.GetTransformation().GetMaxBasisLength(); VertexBuffer vertex_buffer; auto& host_buffer = pass.GetTransientsBuffer();