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

[Impeller] make strokes slightly lighter. #53067

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions impeller/aiks/aiks_path_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 13 additions & 2 deletions impeller/entity/geometry/stroke_path_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ 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 kMinStrokeSizeMSAA = 0.5f;

static constexpr Scalar kMinStrokeSize = 1.0f;

template <typename VertexWriter>
using CapProc = std::function<void(VertexWriter& vtx_builder,
const Point& position,
Expand Down Expand Up @@ -530,7 +537,10 @@ GeometryResult StrokePathGeometry::GetPositionBuffer(
return {};
}

Scalar min_size = 1.0f / sqrt(std::abs(determinant));
Scalar min_size =
(pass.GetSampleCount() == SampleCount::kCount4 ? kMinStrokeSizeMSAA
: kMinStrokeSize) /
sqrt(std::abs(determinant));
Scalar stroke_width = std::max(stroke_width_, min_size);

auto& host_buffer = renderer.GetTransientsBuffer();
Expand Down Expand Up @@ -584,7 +594,8 @@ std::optional<Rect> StrokePathGeometry::GetCoverage(
if (determinant == 0) {
return std::nullopt;
}
Scalar min_size = 1.0f / sqrt(std::abs(determinant));
// 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);
}
Expand Down
3 changes: 3 additions & 0 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down