Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
45 changes: 45 additions & 0 deletions impeller/display_list/aiks_dl_basic_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1534,5 +1534,50 @@ TEST_P(AiksTest, MassiveScalingMatrixImageFilter) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(AiksTest, NoDimplesInRRectPath) {
Scalar width = 200.f;
Scalar height = 60.f;
Scalar corner = 1.f;
auto callback = [&]() -> sk_sp<DisplayList> {
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("width", &width, 0, 200);
ImGui::SliderFloat("height", &height, 0, 200);
ImGui::SliderFloat("corner", &corner, 0, 1);
ImGui::End();
}

DisplayListBuilder builder;
builder.Scale(GetContentScale().x, GetContentScale().y);

DlPaint background_paint;
background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
builder.DrawPaint(background_paint);

std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
std::vector<Scalar> stops = {0.0, 1.0};

DlPaint paint;
auto gradient = DlColorSource::MakeLinear(
{0, 0}, {200, 200}, 2, colors.data(), stops.data(), DlTileMode::kClamp);
paint.setColorSource(gradient);
paint.setColor(DlColor::kWhite());
paint.setDrawStyle(DlDrawStyle::kStroke);
paint.setStrokeWidth(20);

builder.Save();
builder.Translate(100, 100);

Scalar corner_x = ((1 - corner) * 50) + 50;
Scalar corner_y = corner * 50 + 50;
SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(0, 0, width, height),
corner_x, corner_y);
builder.DrawRRect(rrect, paint);
builder.Restore();
return builder.Build();
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

} // namespace testing
} // namespace impeller
16 changes: 12 additions & 4 deletions impeller/geometry/path_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
//----------------------------------------------------------------------------
// Top line.
//
AddLinearComponent(
AddLinearComponentIfNeeded(
{rect_origin.x + radii.top_left.x, rect_origin.y},
{rect_origin.x + rect_size.width - radii.top_right.x, rect_origin.y});

Expand All @@ -177,7 +177,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
//----------------------------------------------------------------------------
// Right line.
//
AddLinearComponent(
AddLinearComponentIfNeeded(
{rect_origin.x + rect_size.width, rect_origin.y + radii.top_right.y},
{rect_origin.x + rect_size.width,
rect_origin.y + rect_size.height - radii.bottom_right.y});
Expand All @@ -190,7 +190,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
//----------------------------------------------------------------------------
// Bottom line.
//
AddLinearComponent(
AddLinearComponentIfNeeded(
{rect_origin.x + rect_size.width - radii.bottom_right.x,
rect_origin.y + rect_size.height},
{rect_origin.x + radii.bottom_left.x, rect_origin.y + rect_size.height});
Expand All @@ -203,7 +203,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
//----------------------------------------------------------------------------
// Left line.
//
AddLinearComponent(
AddLinearComponentIfNeeded(
{rect_origin.x, rect_origin.y + rect_size.height - radii.bottom_left.y},
{rect_origin.x, rect_origin.y + radii.top_left.y});

Expand Down Expand Up @@ -283,6 +283,14 @@ void PathBuilder::AddContourComponent(const Point& destination,
prototype_.bounds.reset();
}

void PathBuilder::AddLinearComponentIfNeeded(const Point& p1, const Point& p2) {
if (ScalarNearlyEqual(p1.x, p2.x, 1e-4f) &&
ScalarNearlyEqual(p1.y, p2.y, 1e-4f)) {
return;
}
AddLinearComponent(p1, p2);
}

void PathBuilder::AddLinearComponent(const Point& p1, const Point& p2) {
auto& points = prototype_.points;
points.push_back(p1);
Expand Down
2 changes: 2 additions & 0 deletions impeller/geometry/path_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class PathBuilder {

void AddLinearComponent(const Point& p1, const Point& p2);

void AddLinearComponentIfNeeded(const Point& p1, const Point& p2);

void AddQuadraticComponent(const Point& p1, const Point& cp, const Point& p2);

void AddCubicComponent(const Point& p1,
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 @@ -807,6 +807,9 @@ impeller_Play_AiksTest_MatrixSaveLayerFilter_Vulkan.png
impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Metal.png
impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_OpenGLES.png
impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Vulkan.png
impeller_Play_AiksTest_NoDimplesInRRectPath_Metal.png
impeller_Play_AiksTest_NoDimplesInRRectPath_OpenGLES.png
impeller_Play_AiksTest_NoDimplesInRRectPath_Vulkan.png
impeller_Play_AiksTest_PaintBlendModeIsRespected_Metal.png
impeller_Play_AiksTest_PaintBlendModeIsRespected_OpenGLES.png
impeller_Play_AiksTest_PaintBlendModeIsRespected_Vulkan.png
Expand Down