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] relax conditions for SkRRect.isSimple conversion to impeller::RRect. #53083

Merged
merged 4 commits into from
May 29, 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
2 changes: 1 addition & 1 deletion impeller/display_list/dl_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ void DlDispatcherBase::drawCircle(const SkPoint& center, SkScalar radius) {

// |flutter::DlOpReceiver|
void DlDispatcherBase::drawRRect(const SkRRect& rrect) {
if (rrect.isSimple()) {
if (skia_conversions::IsNearlySimpleRRect(rrect)) {
GetCanvas().DrawRRect(skia_conversions::ToRect(rrect.rect()),
skia_conversions::ToSize(rrect.getSimpleRadii()),
paint_);
Expand Down
14 changes: 14 additions & 0 deletions impeller/display_list/skia_conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
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);
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);
}

Rect ToRect(const SkRect& rect) {
return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
}
Expand Down
7 changes: 7 additions & 0 deletions impeller/display_list/skia_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
namespace impeller {
namespace skia_conversions {

/// @brief Like SkRRect.isSimple, but allows the corners to differ by
/// kEhCloseEnough.
///
/// An RRect is simple if all corner radii are approximately
/// equal.
bool IsNearlySimpleRRect(const SkRRect& rr);

Rect ToRect(const SkRect& rect);

std::optional<Rect> ToRect(const SkRect* rect);
Expand Down
10 changes: 10 additions & 0 deletions impeller/display_list/skia_conversions_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "flutter/testing/testing.h"
#include "impeller/display_list/skia_conversions.h"
#include "impeller/geometry/scalar.h"
#include "include/core/SkRRect.h"

namespace impeller {
namespace testing {
Expand Down Expand Up @@ -174,5 +175,14 @@ TEST(SkiaConversionsTest, GradientConversionNonMonotonic) {
ASSERT_TRUE(ScalarNearlyEqual(converted_stops[3], 1.0f));
}

TEST(SkiaConversionsTest, IsNearlySimpleRRect) {
EXPECT_TRUE(skia_conversions::IsNearlySimpleRRect(
SkRRect::MakeRectXY(SkRect::MakeLTRB(0, 0, 10, 10), 10, 10)));
EXPECT_TRUE(skia_conversions::IsNearlySimpleRRect(
SkRRect::MakeRectXY(SkRect::MakeLTRB(0, 0, 10, 10), 10, 9.999)));
EXPECT_FALSE(skia_conversions::IsNearlySimpleRRect(
SkRRect::MakeRectXY(SkRect::MakeLTRB(0, 0, 10, 10), 10, 9)));
}

} // namespace testing
} // namespace impeller
Loading