-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] better handle allocation herustics of Android slide in page transition. #56762
Changes from 4 commits
d1bff72
71fd81a
dbde61e
b0bdeaa
ca684e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| #include "impeller/entity/save_layer_utils.h" | ||
| #include "impeller/geometry/scalar.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
|
|
@@ -106,8 +107,34 @@ std::optional<Rect> ComputeSaveLayerCoverage( | |
|
|
||
| // Transform the input coverage into the global coordinate space before | ||
| // computing the bounds limit intersection. | ||
| return coverage.TransformBounds(effect_transform) | ||
| .Intersection(coverage_limit); | ||
| Rect transformed_coverage = coverage.TransformBounds(effect_transform); | ||
| std::optional<Rect> intersection = | ||
| transformed_coverage.Intersection(coverage_limit); | ||
| if (!intersection.has_value()) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| // Sometimes a saveLayer is only slightly shifted outside of the cull rect, | ||
| // but is being animated in. This is common for the Android slide in page | ||
| // transitions. In these cases, computing a cull that is too tight can cause | ||
| // thrasing of the texture cache. Instead, we try to determine the | ||
| // intersection using only the sizing by shifting the coverage rect into the | ||
| // cull rect origin. | ||
| Point delta = coverage_limit.GetOrigin() - transformed_coverage.GetOrigin(); | ||
| if (ScalarNearlyEqual(delta.y, 0) || ScalarNearlyEqual(delta.x, 0)) { | ||
|
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. Not sure if this needs a code comment. My first reading of this line was "wait, we only do this if there is very nearly no delta?" before I realized it was looking for horizontal or vertical transitions.
Contributor
Author
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. Added more documentation
gaaclarke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Scalar threshold = std::max(std::abs(delta.x / coverage_limit.GetWidth()), | ||
| std::abs(delta.y / coverage_limit.GetHeight())); | ||
| if (threshold < 0.3) { | ||
|
||
| std::optional<Rect> shifted_intersected_value = | ||
| transformed_coverage.Shift(delta).Intersection(coverage_limit); | ||
|
|
||
| if (shifted_intersected_value.has_value()) { | ||
| return shifted_intersected_value.value().Shift(-delta); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return intersection; | ||
| } | ||
|
|
||
| } // namespace impeller | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,49 @@ TEST(SaveLayerUtilsTest, | |
| EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 0, 50, 50)); | ||
| } | ||
|
|
||
| TEST(SaveLayerUtilsTest, | ||
| PartiallyIntersectingCoverageIgnoresOriginWithSlideSemanticsX) { | ||
| // X varies, translation is performed on coverage. | ||
| auto coverage = ComputeSaveLayerCoverage( | ||
| /*content_coverage=*/Rect::MakeLTRB(5, 0, 210, 210), // | ||
| /*effect_transform=*/{}, // | ||
| /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), // | ||
| /*image_filter=*/nullptr // | ||
| ); | ||
|
|
||
| ASSERT_TRUE(coverage.has_value()); | ||
| // Size that matches coverage limit | ||
| EXPECT_EQ(coverage.value(), Rect::MakeLTRB(5, 0, 105, 100)); | ||
| } | ||
|
|
||
| TEST(SaveLayerUtilsTest, | ||
| PartiallyIntersectingCoverageIgnoresOriginWithSlideSemanticsY) { | ||
| // Y varies, translation is performed on coverage. | ||
| auto coverage = ComputeSaveLayerCoverage( | ||
| /*content_coverage=*/Rect::MakeLTRB(0, 5, 210, 210), // | ||
| /*effect_transform=*/{}, // | ||
| /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), // | ||
| /*image_filter=*/nullptr // | ||
| ); | ||
|
|
||
| ASSERT_TRUE(coverage.has_value()); | ||
| // Size that matches coverage limit | ||
| EXPECT_EQ(coverage.value(), Rect::MakeLTRB(0, 5, 100, 105)); | ||
| } | ||
|
|
||
| TEST(SaveLayerUtilsTest, PartiallyIntersectingCoverageIgnoresOriginBothXAndY) { | ||
| // Both X and Y vary, no transation is performed. | ||
| auto coverage = ComputeSaveLayerCoverage( | ||
| /*content_coverage=*/Rect::MakeLTRB(5, 5, 210, 210), // | ||
| /*effect_transform=*/{}, // | ||
| /*coverage_limit=*/Rect::MakeLTRB(0, 0, 100, 100), // | ||
| /*image_filter=*/nullptr // | ||
| ); | ||
|
|
||
| ASSERT_TRUE(coverage.has_value()); | ||
| EXPECT_EQ(coverage.value(), Rect::MakeLTRB(5, 5, 100, 100)); | ||
| } | ||
|
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. Perhaps add a test where the threshold is too large in X and another in Y.
Contributor
Author
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. Done |
||
|
|
||
| } // namespace testing | ||
| } // namespace impeller | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it cause thrashing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the intersected size is different each frame, while the original size is stable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add that to the comment please?