Commit c61cdacd authored by Khushal's avatar Khushal Committed by Commit Bot

blink/images: Respect both the repetition count and animation policy.

Use the conservative of the repetition count specified by the image and
the animation policy when selecting the final repetition count for
animated images.

R=chrishtr@chromium.org

Bug: 892683
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I32507feca552302cca43db4ccbbb0ba9c82ca152
Reviewed-on: https://chromium-review.googlesource.com/c/1265080Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597344}
parent 4be572b9
...@@ -53,19 +53,16 @@ namespace blink { ...@@ -53,19 +53,16 @@ namespace blink {
int GetRepetitionCountWithPolicyOverride(int actual_count, int GetRepetitionCountWithPolicyOverride(int actual_count,
ImageAnimationPolicy policy) { ImageAnimationPolicy policy) {
switch (policy) { if (actual_count == kAnimationNone ||
case kImageAnimationPolicyAllowed: policy == kImageAnimationPolicyNoAnimation) {
// Default policy, no count override. return kAnimationNone;
return actual_count; }
case kImageAnimationPolicyAnimateOnce:
// Only a single loop allowed. if (actual_count == kAnimationLoopOnce ||
return kAnimationLoopOnce; policy == kImageAnimationPolicyAnimateOnce) {
case kImageAnimationPolicyNoAnimation: return kAnimationLoopOnce;
// Dont animate.
return kAnimationNone;
} }
NOTREACHED();
return actual_count; return actual_count;
} }
......
...@@ -652,7 +652,65 @@ TEST_F(BitmapImageTestWithMockDecoder, ImageMetadataTracking) { ...@@ -652,7 +652,65 @@ TEST_F(BitmapImageTestWithMockDecoder, ImageMetadataTracking) {
} }
}; };
TEST_F(BitmapImageTestWithMockDecoder, AnimationPolicyOverride) { TEST_F(BitmapImageTestWithMockDecoder,
AnimationPolicyOverrideOriginalRepetitionNone) {
repetition_count_ = kAnimationNone;
frame_count_ = 4u;
last_frame_complete_ = true;
image_->SetData(SharedBuffer::Create("data", sizeof("data")), false);
PaintImage image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), repetition_count_);
// In all cases, the image shouldn't animate.
// Only one loop allowed.
image_->SetAnimationPolicy(kImageAnimationPolicyAnimateOnce);
image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), kAnimationNone);
// No animation allowed.
image_->SetAnimationPolicy(kImageAnimationPolicyNoAnimation);
image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), kAnimationNone);
// Default policy.
image_->SetAnimationPolicy(kImageAnimationPolicyAllowed);
image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), kAnimationNone);
}
TEST_F(BitmapImageTestWithMockDecoder,
AnimationPolicyOverrideOriginalRepetitionOnce) {
repetition_count_ = kAnimationLoopOnce;
frame_count_ = 4u;
last_frame_complete_ = true;
image_->SetData(SharedBuffer::Create("data", sizeof("data")), false);
PaintImage image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), repetition_count_);
// If the policy is no animation, then the repetition count is none. In all
// other cases, it remains loop once.
// Only one loop allowed.
image_->SetAnimationPolicy(kImageAnimationPolicyAnimateOnce);
image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), kAnimationLoopOnce);
// No animation allowed.
image_->SetAnimationPolicy(kImageAnimationPolicyNoAnimation);
image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), kAnimationNone);
// Default policy.
image_->SetAnimationPolicy(kImageAnimationPolicyAllowed);
image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), kAnimationLoopOnce);
}
TEST_F(BitmapImageTestWithMockDecoder,
AnimationPolicyOverrideOriginalRepetitionInfinite) {
repetition_count_ = kAnimationLoopInfinite; repetition_count_ = kAnimationLoopInfinite;
frame_count_ = 4u; frame_count_ = 4u;
last_frame_complete_ = true; last_frame_complete_ = true;
...@@ -661,6 +719,8 @@ TEST_F(BitmapImageTestWithMockDecoder, AnimationPolicyOverride) { ...@@ -661,6 +719,8 @@ TEST_F(BitmapImageTestWithMockDecoder, AnimationPolicyOverride) {
PaintImage image = image_->PaintImageForCurrentFrame(); PaintImage image = image_->PaintImageForCurrentFrame();
EXPECT_EQ(image.repetition_count(), repetition_count_); EXPECT_EQ(image.repetition_count(), repetition_count_);
// The repetition count is determined by the animation policy.
// Only one loop allowed. // Only one loop allowed.
image_->SetAnimationPolicy(kImageAnimationPolicyAnimateOnce); image_->SetAnimationPolicy(kImageAnimationPolicyAnimateOnce);
image = image_->PaintImageForCurrentFrame(); image = image_->PaintImageForCurrentFrame();
......
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