Commit 561bb1b2 authored by Yue Li's avatar Yue Li Committed by Commit Bot

Fix callback layer animation observer logic

If all the sequences has been detached, the observer should be notified,
otherwise it might wait forever.

Also added unit test cases for this scenario.

Bug: b/141997678
Test: Run CallbackLayerAnimationObserverTest.* in compositor_unittests
Change-Id: I3a025de8e635a383910ef4a3e650683478e8d3fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1938459Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Yue Li <updowndota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721580}
parent 4f7bdf97
...@@ -92,6 +92,8 @@ void CallbackLayerAnimationObserver::OnDetachedFromSequence( ...@@ -92,6 +92,8 @@ void CallbackLayerAnimationObserver::OnDetachedFromSequence(
ui::LayerAnimationSequence* sequence) { ui::LayerAnimationSequence* sequence) {
CHECK_LT(detached_sequence_count_, attached_sequence_count_); CHECK_LT(detached_sequence_count_, attached_sequence_count_);
++detached_sequence_count_; ++detached_sequence_count_;
CheckAllSequencesStarted();
CheckAllSequencesCompleted();
} }
int CallbackLayerAnimationObserver::GetNumSequencesCompleted() { int CallbackLayerAnimationObserver::GetNumSequencesCompleted() {
...@@ -99,12 +101,14 @@ int CallbackLayerAnimationObserver::GetNumSequencesCompleted() { ...@@ -99,12 +101,14 @@ int CallbackLayerAnimationObserver::GetNumSequencesCompleted() {
} }
void CallbackLayerAnimationObserver::CheckAllSequencesStarted() { void CallbackLayerAnimationObserver::CheckAllSequencesStarted() {
if (active_ && attached_sequence_count_ == started_count_) if (active_ && (attached_sequence_count_ == started_count_ ||
detached_sequence_count_ == attached_sequence_count_))
animation_started_callback_.Run(*this); animation_started_callback_.Run(*this);
} }
void CallbackLayerAnimationObserver::CheckAllSequencesCompleted() { void CallbackLayerAnimationObserver::CheckAllSequencesCompleted() {
if (active_ && GetNumSequencesCompleted() == attached_sequence_count_) { if (active_ && (GetNumSequencesCompleted() == attached_sequence_count_ ||
detached_sequence_count_ == attached_sequence_count_)) {
active_ = false; active_ = false;
base::WeakPtr<CallbackLayerAnimationObserver> weak_this = base::WeakPtr<CallbackLayerAnimationObserver> weak_this =
weak_factory_.GetWeakPtr(); weak_factory_.GetWeakPtr();
......
...@@ -641,5 +641,42 @@ TEST_F(CallbackLayerAnimationObserverTest, ...@@ -641,5 +641,42 @@ TEST_F(CallbackLayerAnimationObserverTest,
EXPECT_EQ(4, observer_->successful_count()); EXPECT_EQ(4, observer_->successful_count());
} }
TEST_F(CallbackLayerAnimationObserverTest, DetachBeforeActive) {
LayerAnimationSequence* sequence_1 = CreateLayerAnimationSequence();
LayerAnimationSequence* sequence_2 = CreateLayerAnimationSequence();
observer_test_api_->AttachedToSequence(sequence_1);
observer_test_api_->AttachedToSequence(sequence_2);
observer_->OnLayerAnimationStarted(sequence_1);
observer_->OnLayerAnimationEnded(sequence_1);
observer_test_api_->DetachedFromSequence(sequence_1, true);
observer_test_api_->DetachedFromSequence(sequence_2, true);
observer_->SetActive();
EXPECT_FALSE(observer_->active());
EXPECT_TRUE(callbacks_->animations_started());
EXPECT_TRUE(callbacks_->animations_ended());
}
TEST_F(CallbackLayerAnimationObserverTest, DetachAfterActive) {
LayerAnimationSequence* sequence_1 = CreateLayerAnimationSequence();
LayerAnimationSequence* sequence_2 = CreateLayerAnimationSequence();
observer_test_api_->AttachedToSequence(sequence_1);
observer_test_api_->AttachedToSequence(sequence_2);
observer_->SetActive();
observer_->OnLayerAnimationStarted(sequence_1);
observer_->OnLayerAnimationEnded(sequence_1);
observer_test_api_->DetachedFromSequence(sequence_1, true);
observer_test_api_->DetachedFromSequence(sequence_2, true);
EXPECT_FALSE(observer_->active());
EXPECT_TRUE(callbacks_->animations_started());
EXPECT_TRUE(callbacks_->animations_ended());
}
} // namespace test } // namespace test
} // namespace ui } // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment