Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Re-enable fast blur path for elliptical rrects #53704

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 62 additions & 0 deletions impeller/display_list/dl_golden_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "impeller/display_list/dl_golden_unittests.h"

#include "flutter/display_list/dl_builder.h"
#include "flutter/impeller/geometry/path_builder.h"
#include "flutter/testing/testing.h"
#include "gtest/gtest.h"

Expand Down Expand Up @@ -182,6 +183,67 @@ TEST_P(DlGoldenTest, GaussianVsRRectBlurScaledRotated) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(DlGoldenTest, FastVsGeneralGaussianMaskBlur) {
DisplayListBuilder builder;
builder.Scale(GetContentScale().x, GetContentScale().y);
builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);

auto blur_sigmas = std::array{5.0f, 10.0f, 20.0f};
auto blur_colors = std::array{
DlColor::kBlue(),
DlColor::kGreen(),
DlColor::kMaroon(),
};

auto make_rrect_path = [](const SkRect& rect, DlScalar rx, DlScalar ry) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an explicit return type here please? It's a bit of a hunt to understand the signature of this closure.

https://google.github.io/styleguide/cppguide.html#Type_deduction

auto add_corner = [](SkPath& path, SkPoint rCorner, SkPoint rEnd) {
static const auto magic = impeller::PathBuilder::kArcApproximationMagic;
path.rCubicTo(rCorner.fX * (1.0f - magic), rCorner.fY * (1.0f - magic),
rCorner.fX + rEnd.fX * magic, rCorner.fY + rEnd.fY * magic,
rCorner.fX + rEnd.fX, rCorner.fY + rEnd.fY);
};

SkPath path;
path.moveTo(rect.fRight - rx, rect.fTop);
add_corner(path, {rx, 0.0f}, {0.0f, ry});
path.lineTo(rect.fRight, rect.fBottom - ry);
add_corner(path, {0.0f, ry}, {-rx, 0.0f});
path.lineTo(rect.fLeft + rx, rect.fBottom);
add_corner(path, {-rx, 0.0f}, {0.0f, -ry});
path.lineTo(rect.fLeft, rect.fTop + ry);
add_corner(path, {0.0f, -ry}, {rx, 0.0f});
path.close();
return path;
};

for (size_t i = 0; i < blur_sigmas.size(); i++) {
auto rect = SkRect::MakeXYWH(i * 320.0f + 50.0f, 50.0f, 100.0f, 100.0f);
DlPaint paint = DlPaint() //
.setColor(blur_colors[i])
.setMaskFilter(DlBlurMaskFilter::Make(
DlBlurStyle::kNormal, blur_sigmas[i]));

builder.DrawRRect(SkRRect::MakeRectXY(rect, 10.0f, 10.0f), paint);
rect = rect.makeOffset(150.0f, 0.0f);
builder.DrawPath(make_rrect_path(rect, 10.0f, 10.0f), paint);
rect = rect.makeOffset(-150.0f, 0.0f);

rect = rect.makeOffset(0.0f, 200.0f);
builder.DrawRRect(SkRRect::MakeRectXY(rect, 10.0f, 30.0f), paint);
rect = rect.makeOffset(150.0f, 0.0f);
builder.DrawPath(make_rrect_path(rect, 10.0f, 20.0f), paint);
rect = rect.makeOffset(-150.0f, 0.0f);

rect = rect.makeOffset(0.0f, 200.0f);
builder.DrawRRect(SkRRect::MakeRectXY(rect, 30.0f, 10.0f), paint);
rect = rect.makeOffset(150.0f, 0.0f);
builder.DrawPath(make_rrect_path(rect, 20.0f, 10.0f), paint);
rect = rect.makeOffset(-150.0f, 0.0f);
}

ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(DlGoldenTest, DashedLinesTest) {
Point content_scale = GetContentScale();
auto draw = [content_scale](DlCanvas* canvas,
Expand Down
24 changes: 14 additions & 10 deletions impeller/display_list/skia_conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
namespace impeller {
namespace skia_conversions {

bool IsNearlySimpleRRect(const SkRRect& rr) {
auto [a, b] = rr.radii(SkRRect::kUpperLeft_Corner);
auto [c, d] = rr.radii(SkRRect::kLowerLeft_Corner);
auto [e, f] = rr.radii(SkRRect::kUpperRight_Corner);
auto [g, h] = rr.radii(SkRRect::kLowerRight_Corner);
static inline bool SkScalarsNearlyEqual(SkScalar a,
SkScalar b,
SkScalar c,
SkScalar d) {
return SkScalarNearlyEqual(a, b, kEhCloseEnough) &&
SkScalarNearlyEqual(a, c, kEhCloseEnough) &&
SkScalarNearlyEqual(a, d, kEhCloseEnough) &&
SkScalarNearlyEqual(a, e, kEhCloseEnough) &&
SkScalarNearlyEqual(a, f, kEhCloseEnough) &&
SkScalarNearlyEqual(a, g, kEhCloseEnough) &&
SkScalarNearlyEqual(a, h, kEhCloseEnough);
SkScalarNearlyEqual(a, d, kEhCloseEnough);
}

bool IsNearlySimpleRRect(const SkRRect& rr) {
auto [xa, ya] = rr.radii(SkRRect::kUpperLeft_Corner);
auto [xb, yb] = rr.radii(SkRRect::kLowerLeft_Corner);
auto [xc, yc] = rr.radii(SkRRect::kUpperRight_Corner);
auto [xd, yd] = rr.radii(SkRRect::kLowerRight_Corner);
return SkScalarsNearlyEqual(xa, xb, xc, xd) &&
SkScalarsNearlyEqual(ya, yb, yc, yd);
}

Rect ToRect(const SkRect& rect) {
Expand Down