Commit c0e80e68 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

Simplify logic of computing main thread compositable animations

A main thread compositable animation means that this animation should
be composited such as an opacity or 2d transform, but it is not due to
certain check such as
RuntimeEnabledFeatures::TurnOff2DAndOpacityCompositorAnimationsEnabled
which is designed to be used for an experiment described in
crbug.com/754471.

Currently our logic is:
1. Check if the effect (such as opacity) can start on compositor or not
2. If 1 is true, and the target element is not paint into its own
   backing + the target element is not a SVG, then it is a main thread
   compositable animation.

This logic is over complicated. We should really just check whether the
run time flag is enabled or not. So this CL simplifies it. We already have
unit test in CompositorAnimationsTest to ensure that this change is
fine.

Bug: 781305
Change-Id: I8f9a1d82fa60eea79018c6cf777a1b45bd565022
Reviewed-on: https://chromium-review.googlesource.com/919316
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537351}
parent dd9167fe
......@@ -153,6 +153,23 @@ CompositorAnimations::CheckCanStartEffectOnCompositor(
const Animation* animation_to_add,
const EffectModel& effect,
double animation_playback_rate) {
// Check whether this animation is main thread compositable or not.
// If this runtime feature is on + we have either opacity or 2d transform
// animation, then this animation is main thread compositable.
if (RuntimeEnabledFeatures::
TurnOff2DAndOpacityCompositorAnimationsEnabled()) {
LayoutObject* layout_object = target_element.GetLayoutObject();
if (layout_object) {
const ComputedStyle* style = layout_object->Style();
if (style && (style->HasCurrentOpacityAnimation() ||
(style->HasCurrentTransformAnimation() &&
!style->Has3DTransform()))) {
return FailureCode::AcceleratableAnimNotAccelerated(
"Acceleratable animation not accelerated due to an experiment");
}
}
}
const KeyframeEffectModelBase& keyframe_effect =
ToKeyframeEffectModelBase(effect);
......@@ -294,24 +311,9 @@ CompositorAnimations::CheckCanStartElementOnCompositor(
bool paints_into_own_backing =
layout_object &&
layout_object->GetCompositingState() == kPaintsIntoOwnBacking;
// This function is called in CheckCanStartAnimationOnCompositor(), after
// CheckCanStartEffectOnCompositor returns code.Ok(), which means that we
// know the effect (such as transform) could be accelerated. If the target
// element is SVG, then we should not return code.Ok() because a SVG
// animation cannot be composited. If the target element is not SVG, and
// |!paints_into_own_backing|, then we know that the animation is not
// composited due to certain check, such as the
// ComputedStyle::ShouldCompositeForCurrentAnimations(), for a running
// experiment.
bool is_svg_element = layout_object && layout_object->IsSVG();
if (!paints_into_own_backing) {
if (!is_svg_element) {
return FailureCode::AcceleratableAnimNotAccelerated(
"Acceleratable animation not accelerated due to an experiment");
} else {
return FailureCode::NonActionable(
"Element does not paint into own backing");
}
return FailureCode::NonActionable(
"Element does not paint into own backing");
}
}
......
......@@ -1358,7 +1358,7 @@ TEST_F(AnimationCompositorAnimationsTest,
}
TEST_F(AnimationCompositorAnimationsTest,
cannotStartElementOnCompositorEffectWithRuntimeFeature) {
cannotStartAnimationOnCompositorWithRuntimeFeature) {
ScopedTurnOff2DAndOpacityCompositorAnimationsForTest
turn_off_2d_and_opacity_compositors_animation(true);
LoadTestData("transform-animation.html");
......@@ -1367,8 +1367,12 @@ TEST_F(AnimationCompositorAnimationsTest,
const ObjectPaintProperties* properties =
target->GetLayoutObject()->FirstFragment().PaintProperties();
EXPECT_TRUE(properties->Transform()->HasDirectCompositingReasons());
Timing timing;
KeyframeEffectModelBase* effect =
StringKeyframeEffectModel::Create(StringKeyframeVector());
CompositorAnimations::FailureCode code =
CompositorAnimations::CheckCanStartElementOnCompositor(*target);
CompositorAnimations::CheckCanStartAnimationOnCompositor(
timing, *target, nullptr, *effect, 1.0);
EXPECT_EQ(
code,
CompositorAnimations::FailureCode::AcceleratableAnimNotAccelerated(
......
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