From 7b97df83e29e416327c5518f278c357ec9fb52c1 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 28 May 2024 10:11:42 -0700 Subject: [PATCH 1/4] [Impeller] make strokes slightly lighter. --- impeller/entity/geometry/stroke_path_geometry.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/impeller/entity/geometry/stroke_path_geometry.cc b/impeller/entity/geometry/stroke_path_geometry.cc index 3ccf294cbb334..6d9f603e81df4 100644 --- a/impeller/entity/geometry/stroke_path_geometry.cc +++ b/impeller/entity/geometry/stroke_path_geometry.cc @@ -15,6 +15,11 @@ using VS = SolidFillVertexShader; namespace { +/// @brief The minimum stroke size can be less than one physical pixel because +/// of MSAA, but no less that half a physical pixel otherwise we might +/// not hit one of the sample positions. +static constexpr Scalar kMinStrokeSize = 0.5f; + template using CapProc = std::function StrokePathGeometry::GetCoverage( if (determinant == 0) { return std::nullopt; } - Scalar min_size = 1.0f / sqrt(std::abs(determinant)); + Scalar min_size = kMinStrokeSize / sqrt(std::abs(determinant)); max_radius *= std::max(stroke_width_, min_size); return path_bounds->Expand(max_radius).TransformBounds(transform); } From 8da50df5ef4b8f7d184c93cea35345b596a62c11 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 28 May 2024 11:46:33 -0700 Subject: [PATCH 2/4] add thin stroke test case. --- impeller/aiks/aiks_path_unittests.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/impeller/aiks/aiks_path_unittests.cc b/impeller/aiks/aiks_path_unittests.cc index 0aa9ed990338d..1cfb658d769a5 100644 --- a/impeller/aiks/aiks_path_unittests.cc +++ b/impeller/aiks/aiks_path_unittests.cc @@ -48,6 +48,18 @@ TEST_P(AiksTest, CanRenderThickCurvedStrokes) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, CanRenderThinCurvedStrokes) { + Canvas canvas; + Paint paint; + paint.color = Color::Red(); + // Impeller doesn't support hairlines yet, but size this guarantees + // the smallest possible stroke width. + paint.stroke_width = 0.01; + paint.style = Paint::Style::kStroke; + canvas.DrawPath(PathBuilder{}.AddCircle({100, 100}, 50).TakePath(), paint); + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + TEST_P(AiksTest, CanRenderStrokePathThatEndsAtSharpTurn) { Canvas canvas; From e11e7f524682c1e5366e7a3abba28a4534e5e972 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 28 May 2024 12:18:38 -0700 Subject: [PATCH 3/4] fix golden diffs. --- testing/impeller_golden_tests_output.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index 8adb5b267b375..cee7f44d467b0 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -460,6 +460,9 @@ impeller_Play_AiksTest_CanRenderTextWithLargePerspectiveTransform_Vulkan.png impeller_Play_AiksTest_CanRenderThickCurvedStrokes_Metal.png impeller_Play_AiksTest_CanRenderThickCurvedStrokes_OpenGLES.png impeller_Play_AiksTest_CanRenderThickCurvedStrokes_Vulkan.png +impeller_Play_AiksTest_CanRenderThinCurvedStrokes_Metal.png +impeller_Play_AiksTest_CanRenderThinCurvedStrokes_OpenGLES.png +impeller_Play_AiksTest_CanRenderThinCurvedStrokes_Vulkan.png impeller_Play_AiksTest_CanRenderTiledTextureClampWithTranslate_Metal.png impeller_Play_AiksTest_CanRenderTiledTextureClampWithTranslate_OpenGLES.png impeller_Play_AiksTest_CanRenderTiledTextureClampWithTranslate_Vulkan.png From ac6a7b661e28408ef1317922443c6e136b0ea37b Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 28 May 2024 13:22:38 -0700 Subject: [PATCH 4/4] try wider stroke width for non-msaa. --- impeller/entity/geometry/stroke_path_geometry.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/impeller/entity/geometry/stroke_path_geometry.cc b/impeller/entity/geometry/stroke_path_geometry.cc index 6d9f603e81df4..ba9a92bb9c1e1 100644 --- a/impeller/entity/geometry/stroke_path_geometry.cc +++ b/impeller/entity/geometry/stroke_path_geometry.cc @@ -18,7 +18,9 @@ namespace { /// @brief The minimum stroke size can be less than one physical pixel because /// of MSAA, but no less that half a physical pixel otherwise we might /// not hit one of the sample positions. -static constexpr Scalar kMinStrokeSize = 0.5f; +static constexpr Scalar kMinStrokeSizeMSAA = 0.5f; + +static constexpr Scalar kMinStrokeSize = 1.0f; template using CapProc = std::function StrokePathGeometry::GetCoverage( if (determinant == 0) { return std::nullopt; } + // Use the most conervative coverage setting. Scalar min_size = kMinStrokeSize / sqrt(std::abs(determinant)); max_radius *= std::max(stroke_width_, min_size); return path_bounds->Expand(max_radius).TransformBounds(transform);