Commit 31048b60 authored by jonross's avatar jonross Committed by Commit bot

Update Layer::GetTargetColor to account for animation state

Layer::GetTargetColor currently always checks the LayerAnimator for a target
color.

When the layer is not animating, the animator's defaults do not necessarily
reflect the current state of the layer. This change updates
Layer::GetTargetColor to return the current color if not animating.

TEST=LayerOwnerTest, RecreateLayerSolidColorWithChangedCCLayerHonorsTargets,
ran compositor_unittests, ash_unittests, views_unittests
BUG=chrome-os-partner:40118

Review URL: https://codereview.chromium.org/1125283015

Cr-Commit-Position: refs/heads/master@{#330679}
parent a429208d
......@@ -653,7 +653,9 @@ void Layer::UpdateNinePatchLayerBorder(const gfx::Rect& border) {
void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); }
SkColor Layer::GetTargetColor() {
return GetAnimator()->GetTargetColor();
if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR))
return GetAnimator()->GetTargetColor();
return cc_layer_->background_color();
}
SkColor Layer::background_color() const {
......
......@@ -101,6 +101,30 @@ TEST(LayerOwnerTest, RecreateLayerHonorsAnimationTargets) {
EXPECT_EQ(SK_ColorGREEN, owner.layer()->background_color());
}
// Tests that when a LAYER_SOLID_COLOR which is not backed by a SolidColorLayer
// that opaqueness and color targets are maintained when the
// LayerOwner::RecreateLayers is called.
TEST(LayerOwnerTest, RecreateLayerSolidColorWithChangedCCLayerHonorsTargets) {
SkColor transparent = SK_ColorTRANSPARENT;
LayerOwner owner;
Layer* layer = new Layer(LAYER_SOLID_COLOR);
owner.SetLayer(layer);
layer->SetFillsBoundsOpaquely(false);
layer->SetColor(transparent);
// Changing the backing layer takes LAYER_SOLID_COLOR off of the normal layer
// flow, need to ensure that set values are maintained.
layer->SwitchCCLayerForTest();
EXPECT_FALSE(layer->fills_bounds_opaquely());
EXPECT_EQ(transparent, layer->background_color());
EXPECT_EQ(transparent, layer->GetTargetColor());
scoped_ptr<Layer> old_layer(owner.RecreateLayer());
EXPECT_FALSE(owner.layer()->fills_bounds_opaquely());
EXPECT_EQ(transparent, owner.layer()->background_color());
EXPECT_EQ(transparent, owner.layer()->GetTargetColor());
}
TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) {
LayerOwner owner;
Layer* layer = new Layer;
......
......@@ -29,6 +29,8 @@
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/compositor/test/context_factories_for_test.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/compositor/test/test_compositor_host.h"
......@@ -1604,6 +1606,77 @@ TEST_F(LayerWithRealCompositorTest, SwitchCCLayerAnimations) {
EXPECT_FLOAT_EQ(l1->opacity(), 0.5f);
}
// Tests that when a LAYER_SOLID_COLOR has its CC layer switched, that
// opaqueness and color set while not animating, are maintained.
TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorNotAnimating) {
SkColor transparent = SK_ColorTRANSPARENT;
scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR));
GetCompositor()->SetRootLayer(root.get());
root->SetFillsBoundsOpaquely(false);
root->SetColor(transparent);
EXPECT_FALSE(root->fills_bounds_opaquely());
EXPECT_FALSE(
root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR));
EXPECT_EQ(transparent, root->background_color());
EXPECT_EQ(transparent, root->GetTargetColor());
// Changing the underlying layer should not affect targets.
root->SwitchCCLayerForTest();
EXPECT_FALSE(root->fills_bounds_opaquely());
EXPECT_FALSE(
root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR));
EXPECT_EQ(transparent, root->background_color());
EXPECT_EQ(transparent, root->GetTargetColor());
}
// Tests that when a LAYER_SOLID_COLOR has its CC layer switched during an
// animation of its opaquness and color, that both the current values, and the
// targets are maintained.
TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorWhileAnimating) {
SkColor transparent = SK_ColorTRANSPARENT;
scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR));
GetCompositor()->SetRootLayer(root.get());
root->SetColor(SK_ColorBLACK);
EXPECT_TRUE(root->fills_bounds_opaquely());
EXPECT_EQ(SK_ColorBLACK, root->GetTargetColor());
scoped_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation(
new ui::ScopedAnimationDurationScaleMode(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
{
ui::ScopedLayerAnimationSettings animation(root->GetAnimator());
animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000));
root->SetFillsBoundsOpaquely(false);
root->SetColor(transparent);
}
EXPECT_TRUE(root->fills_bounds_opaquely());
EXPECT_TRUE(
root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR));
EXPECT_EQ(SK_ColorBLACK, root->background_color());
EXPECT_EQ(transparent, root->GetTargetColor());
// Changing the underlying layer should not affect targets.
root->SwitchCCLayerForTest();
EXPECT_TRUE(root->fills_bounds_opaquely());
EXPECT_TRUE(
root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR));
EXPECT_EQ(SK_ColorBLACK, root->background_color());
EXPECT_EQ(transparent, root->GetTargetColor());
// End all animations.
root->GetAnimator()->StopAnimating();
EXPECT_FALSE(root->fills_bounds_opaquely());
EXPECT_FALSE(
root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR));
EXPECT_EQ(transparent, root->background_color());
EXPECT_EQ(transparent, root->GetTargetColor());
}
// Tests that the animators in the layer tree is added to the
// animator-collection when the root-layer is set to the compositor.
TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) {
......
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