Commit 1d625d9e authored by sohan's avatar sohan Committed by Commit Bot

cc: Reset ImageAnimationController maps.

This clears animation state maps maintained in IAC, on navigaion.
The navigaiton signal is recieved from LTH and the entries without
driver/recordings are cleared on activation. A new LTHI func is
introduced ::DidNavigate, which takes care of clearing both animation
and decode cache.

BUG=789715

Change-Id: I8c6b37a6c2783ff727931e9812ff41c4321ab855
Reviewed-on: https://chromium-review.googlesource.com/919265
Commit-Queue: Sohan Jyoti Ghosh <sohan.jyoti@huawei.com>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542613}
parent 349799e3
......@@ -139,8 +139,21 @@ void ImageAnimationController::DidActivate() {
DCHECK(it != animation_state_map_.end());
it->second.PushPendingToActive();
}
images_animated_on_sync_tree_.clear();
// We would retain state for images with no drivers (no recordings) to allow
// resuming of animations. However, since the animation will be re-started
// from the beginning after navigation, we can avoid maintaining the state.
if (did_navigate_) {
for (auto it = animation_state_map_.begin();
it != animation_state_map_.end();) {
if (it->second.has_drivers())
it++;
else
it = animation_state_map_.erase(it);
}
did_navigate_ = false;
}
}
size_t ImageAnimationController::GetFrameIndexForImage(
......
......@@ -99,11 +99,17 @@ class CC_EXPORT ImageAnimationController {
size_t GetFrameIndexForImage(PaintImage::Id paint_image_id,
WhichTree tree) const;
void set_did_navigate() { did_navigate_ = true; };
const base::flat_set<AnimationDriver*>& GetDriversForTesting(
PaintImage::Id paint_image_id) const;
size_t GetLastNumOfFramesSkippedForTesting(
PaintImage::Id paint_image_id) const;
size_t animation_state_map_size_for_testing() {
return animation_state_map_.size();
}
private:
class AnimationState {
public:
......@@ -236,6 +242,8 @@ class CC_EXPORT ImageAnimationController {
DelayedNotifier notifier_;
const bool enable_image_animation_resync_;
bool did_navigate_ = false;
};
} // namespace cc
......
......@@ -737,6 +737,48 @@ TEST_F(ImageAnimationControllerTest, ResetAnimations) {
controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
}
TEST_F(ImageAnimationControllerTest, ResetAnimationStateMapOnNavigation) {
std::vector<FrameMetadata> first_image_frames = {
FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
DiscardableImageMap::AnimatedImageMetadata first_data(
PaintImage::GetNextId(), PaintImage::CompletionState::DONE,
first_image_frames, kAnimationLoopOnce, 0);
controller_->UpdateAnimatedImage(first_data);
FakeAnimationDriver first_driver;
controller_->RegisterAnimationDriver(first_data.paint_image_id,
&first_driver);
std::vector<FrameMetadata> second_image_frames = {
FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)),
FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
DiscardableImageMap::AnimatedImageMetadata second_data(
PaintImage::GetNextId(), PaintImage::CompletionState::DONE,
second_image_frames, kAnimationLoopOnce, 0);
controller_->UpdateAnimatedImage(second_data);
FakeAnimationDriver second_driver;
controller_->RegisterAnimationDriver(second_data.paint_image_id,
&second_driver);
controller_->AnimateForSyncTree(now_);
controller_->UnregisterAnimationDriver(first_data.paint_image_id,
&first_driver);
EXPECT_EQ(controller_->animation_state_map_size_for_testing(), 2u);
// Fake navigation and activation.
controller_->set_did_navigate();
controller_->DidActivate();
// Animation state map entries without drivers will be purged on navigation.
EXPECT_EQ(controller_->animation_state_map_size_for_testing(), 1u);
controller_->UnregisterAnimationDriver(second_data.paint_image_id,
&second_driver);
EXPECT_EQ(controller_->animation_state_map_size_for_testing(), 1u);
}
class ImageAnimationControllerNoResyncTest
: public ImageAnimationControllerTest {
protected:
......
......@@ -337,7 +337,7 @@ void LayerTreeHost::FinishCommitOnImplThread(
if (did_navigate) {
TRACE_EVENT0("cc,benchmark", "LayerTreeHost::DidNavigate");
proxy_->ClearHistoryOnNavigation();
host_impl->ClearImageCacheOnNavigation();
host_impl->DidNavigate();
}
{
......
......@@ -2703,13 +2703,14 @@ LayerTreeHostImpl::TakeCompletedImageDecodeRequests() {
return result;
}
void LayerTreeHostImpl::ClearImageCacheOnNavigation() {
void LayerTreeHostImpl::DidNavigate() {
// It is safe to clear the decode policy tracking on navigations since it
// comes with an invalidation and the image ids are never re-used.
bool can_clear_decode_policy_tracking = true;
tile_manager_.ClearCheckerImageTracking(can_clear_decode_policy_tracking);
if (image_decode_cache_)
image_decode_cache_->ClearCache();
image_animation_controller_.set_did_navigate();
}
void LayerTreeHostImpl::DidChangeScrollbarVisibility() {
......
......@@ -644,7 +644,7 @@ class CC_EXPORT LayerTreeHostImpl
void QueueImageDecode(int request_id, const PaintImage& image);
std::vector<std::pair<int, bool>> TakeCompletedImageDecodeRequests();
void ClearImageCacheOnNavigation();
void DidNavigate();
bool CanConsumeDelta(const ScrollNode& scroll_node,
const ScrollState& scroll_state);
......
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