-
Notifications
You must be signed in to change notification settings - Fork 6k
Use DlPathEffect Object #32159
Use DlPathEffect Object #32159
Changes from 1 commit
a7c8b30
9ae1876
360ef9b
c024ba9
19bbde9
731e605
42710b3
40cbf6d
4e99e81
48c36d2
d62c744
254893d
81c2dcb
8da4757
0d2a021
938ca82
563d368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| #define FLUTTER_DISPLAY_LIST_DISPLAY_LIST_PATH_EFFECT_H_ | ||
|
|
||
| #include <cstring> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used? |
||
| #include <optional> | ||
| #include "flutter/display_list/display_list_attributes.h" | ||
| #include "flutter/display_list/types.h" | ||
| #include "flutter/fml/logging.h" | ||
|
|
@@ -41,6 +42,8 @@ class DlPathEffect | |
|
|
||
| virtual const DlDashPathEffect* asDash() const { return nullptr; } | ||
|
|
||
| virtual std::optional<SkRect> effect_bounds(SkRect&) const = 0; | ||
|
|
||
| protected: | ||
| DlPathEffect() = default; | ||
|
|
||
|
|
@@ -81,36 +84,36 @@ class DlDashPathEffect final : public DlPathEffect { | |
| } | ||
|
|
||
| std::shared_ptr<DlPathEffect> shared() const override { | ||
| return Make(pods(), count_, phase_); | ||
| return Make(intervals(), count_, phase_); | ||
| } | ||
|
|
||
| const DlDashPathEffect* asDash() const override { return this; } | ||
|
|
||
| sk_sp<SkPathEffect> skia_object() const override { | ||
| return SkDashPathEffect::Make(pods(), count_, phase_); | ||
| return SkDashPathEffect::Make(intervals(), count_, phase_); | ||
| } | ||
|
|
||
| SkScalar* intervals() { return reinterpret_cast<SkScalar*>(this + 1); } | ||
| const SkScalar* intervals() const { | ||
| return reinterpret_cast<const SkScalar*>(this + 1); | ||
| } | ||
|
|
||
| std::optional<SkRect> effect_bounds(SkRect& rect) const override; | ||
|
|
||
| protected: | ||
| bool equals_(DlPathEffect const& other) const override { | ||
| FML_DCHECK(other.type() == DlPathEffectType::kDash); | ||
| auto that = static_cast<DlDashPathEffect const*>(&other); | ||
| return memcmp(pods(), that->pods(), count_) == 0 && | ||
| count_ == that->count_ && phase_ == that->phase_; | ||
| return count_ == that->count_ && | ||
| memcmp(intervals(), that->intervals(), sizeof(SkScalar) * count_) == | ||
| 0 && | ||
| phase_ == that->phase_; | ||
flar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private: | ||
| const SkScalar* pods() const { | ||
| return reinterpret_cast<const SkScalar*>(this + 1); | ||
| } | ||
|
|
||
| bool base_equals_(DlDashPathEffect const* other) const { | ||
| // intervals not nullptr, that has value | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| SkScalar* intervals() { return reinterpret_cast<SkScalar*>(this + 1); } | ||
flar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // DlDashPathEffect constructor assumes the caller has prealloced storage for | ||
| // the intervals. If the intervals is nullptr the intervals will | ||
| // uninitialized. | ||
| DlDashPathEffect(const SkScalar intervals[], int count, SkScalar phase) | ||
flar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| : count_(count), phase_(phase) { | ||
| if (intervals != nullptr) { | ||
|
|
@@ -120,14 +123,15 @@ class DlDashPathEffect final : public DlPathEffect { | |
| } | ||
|
|
||
| DlDashPathEffect(const DlDashPathEffect* dash_effect) | ||
| : DlDashPathEffect(dash_effect->pods(), | ||
| : DlDashPathEffect(dash_effect->intervals(), | ||
| dash_effect->count_, | ||
| dash_effect->phase_) {} | ||
|
|
||
| int count_; | ||
| SkScalar phase_; | ||
|
|
||
| friend class DisplayListBuilder; | ||
| friend class DlPathEffect; | ||
|
|
||
| FML_DISALLOW_COPY_ASSIGN_AND_MOVE(DlDashPathEffect); | ||
| }; | ||
|
|
@@ -152,6 +156,8 @@ class DlUnknownPathEffect final : public DlPathEffect { | |
|
|
||
| virtual ~DlUnknownPathEffect() = default; | ||
|
|
||
| std::optional<SkRect> effect_bounds(SkRect& rect) const override; | ||
|
|
||
| protected: | ||
| bool equals_(const DlPathEffect& other) const override { | ||
| FML_DCHECK(other.type() == DlPathEffectType::kUnknown); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,12 +68,18 @@ TEST(DisplayListPathEffect, DashEffectEquals) { | |
| TEST(DisplayListPathEffect, BlurNotEquals) { | ||
| const SkScalar TestDashes1[] = {4.0, 2.0}; | ||
| const SkScalar TestDashes2[] = {1.0, 1.5}; | ||
|
||
| const SkScalar TestDashes3[] = {4.0, 2.5, 2.0}; | ||
| auto effect1 = DlDashPathEffect::Make(TestDashes1, 2, 0.0); | ||
| auto effect2 = DlDashPathEffect::Make(TestDashes2, 2, 0.0); | ||
| auto effect3 = DlDashPathEffect::Make(TestDashes2, 2, 1.0); | ||
| auto effect3 = DlDashPathEffect::Make(TestDashes3, 3, 1.0); | ||
|
|
||
| ASSERT_NE(effect1, effect2); | ||
| ASSERT_NE(effect2, effect3); | ||
| ASSERT_NE(effect1->shared(), effect2->shared()); | ||
|
|
||
| ASSERT_NE(effect1, effect3); | ||
| ASSERT_NE(effect1->shared(), effect3->shared()); | ||
|
|
||
| ASSERT_NE(effect2, effect3); | ||
| ASSERT_NE(effect2->shared(), effect3->shared()); | ||
| } | ||
|
|
||
|
|
@@ -116,108 +122,5 @@ TEST(DisplayListPathEffect, UnknownNotEquals) { | |
| "SkDashPathEffect instance differs"); | ||
| } | ||
|
|
||
| void testEquals(DlPathEffect* a, DlPathEffect* b) { | ||
| // a and b have the same nullness or values | ||
| ASSERT_TRUE(Equals(a, b)); | ||
| ASSERT_FALSE(NotEquals(a, b)); | ||
| ASSERT_TRUE(Equals(b, a)); | ||
| ASSERT_FALSE(NotEquals(b, a)); | ||
| } | ||
|
|
||
| void testNotEquals(DlPathEffect* a, DlPathEffect* b) { | ||
| // a and b do not have the same nullness or values | ||
| ASSERT_FALSE(Equals(a, b)); | ||
| ASSERT_TRUE(NotEquals(a, b)); | ||
| ASSERT_FALSE(Equals(b, a)); | ||
| ASSERT_TRUE(NotEquals(b, a)); | ||
| } | ||
|
|
||
| void testEquals(std::shared_ptr<const DlPathEffect> a, DlPathEffect* b) { | ||
| // a and b have the same nullness or values | ||
| ASSERT_TRUE(Equals(a, b)); | ||
| ASSERT_FALSE(NotEquals(a, b)); | ||
| ASSERT_TRUE(Equals(b, a)); | ||
| ASSERT_FALSE(NotEquals(b, a)); | ||
| } | ||
|
|
||
| void testNotEquals(std::shared_ptr<const DlPathEffect> a, DlPathEffect* b) { | ||
| // a and b do not have the same nullness or values | ||
| ASSERT_FALSE(Equals(a, b)); | ||
| ASSERT_TRUE(NotEquals(a, b)); | ||
| ASSERT_FALSE(Equals(b, a)); | ||
| ASSERT_TRUE(NotEquals(b, a)); | ||
| } | ||
|
|
||
| void testEquals(std::shared_ptr<const DlPathEffect> a, | ||
| std::shared_ptr<const DlPathEffect> b) { | ||
| // a and b have the same nullness or values | ||
| ASSERT_TRUE(Equals(a, b)); | ||
| ASSERT_FALSE(NotEquals(a, b)); | ||
| ASSERT_TRUE(Equals(b, a)); | ||
| ASSERT_FALSE(NotEquals(b, a)); | ||
| } | ||
|
|
||
| void testNotEquals(std::shared_ptr<const DlPathEffect> a, | ||
| std::shared_ptr<const DlPathEffect> b) { | ||
| // a and b do not have the same nullness or values | ||
| ASSERT_FALSE(Equals(a, b)); | ||
| ASSERT_TRUE(NotEquals(a, b)); | ||
| ASSERT_FALSE(Equals(b, a)); | ||
| ASSERT_TRUE(NotEquals(b, a)); | ||
| } | ||
|
|
||
| TEST(DisplayListPathEffect, ComparableTemplates) { | ||
| const SkScalar TestDashes1[] = {4.0, 2.0}; | ||
| const SkScalar TestDashes2[] = {1.0, 1.5}; | ||
| auto effect1 = DlDashPathEffect::Make(TestDashes1, 2, 0.0); | ||
| auto effect2 = DlDashPathEffect::Make(TestDashes1, 2, 0.0); | ||
| auto effect3 = DlDashPathEffect::Make(TestDashes2, 2, 1.0); | ||
| std::shared_ptr<DlPathEffect> shared_null; | ||
|
|
||
| // null to null | ||
| testEquals(nullptr, nullptr); | ||
| testEquals(shared_null, nullptr); | ||
| testEquals(shared_null, shared_null); | ||
|
|
||
| // ptr to null | ||
| testNotEquals(effect1.get(), nullptr); | ||
| testNotEquals(effect2.get(), nullptr); | ||
| testNotEquals(effect3.get(), nullptr); | ||
|
|
||
| // shared_ptr to null and shared_null to ptr | ||
| testNotEquals(effect1->shared(), nullptr); | ||
| testNotEquals(effect2->shared(), nullptr); | ||
| testNotEquals(effect3->shared(), nullptr); | ||
| testNotEquals(shared_null, effect1.get()); | ||
| testNotEquals(shared_null, effect2.get()); | ||
| testNotEquals(shared_null, effect3.get()); | ||
|
|
||
| // ptr to ptr | ||
| testEquals(effect1, effect1); | ||
| testEquals(effect1, effect2); | ||
| testEquals(effect3, effect3); | ||
| testEquals(effect2, effect2); | ||
|
|
||
| // shared_ptr to ptr | ||
| testEquals(effect1->shared(), effect1); | ||
| testEquals(effect1->shared(), effect2); | ||
| testEquals(effect2->shared(), effect2); | ||
| testEquals(effect3->shared(), effect3); | ||
| testNotEquals(effect1->shared(), effect3); | ||
| testNotEquals(effect2->shared(), effect3); | ||
| testNotEquals(effect3->shared(), effect1); | ||
| testNotEquals(effect3->shared(), effect2); | ||
|
|
||
| // shared_ptr to shared_ptr | ||
| testEquals(effect1->shared(), effect1->shared()); | ||
| testEquals(effect1->shared(), effect2->shared()); | ||
| testEquals(effect2->shared(), effect2->shared()); | ||
| testEquals(effect3->shared(), effect3->shared()); | ||
| testNotEquals(effect1->shared(), effect3->shared()); | ||
| testNotEquals(effect2->shared(), effect3->shared()); | ||
| testNotEquals(effect3->shared(), effect1->shared()); | ||
| testNotEquals(effect3->shared(), effect2->shared()); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
Uh oh!
There was an error while loading. Please reload this page.