summaryrefslogtreecommitdiffstats
path: root/ui/compositor
diff options
context:
space:
mode:
authorjonross <jonross@chromium.org>2015-05-19 19:09:25 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-20 02:09:36 +0000
commit31048b60684f840102adffa211f746ec4218abbd (patch)
treed05cc1ec5e2815159b6b32a87dc8f8f245a73a26 /ui/compositor
parenta429208d1c11c1330801fca7420d8796e97f8a5a (diff)
downloadchromium_src-31048b60684f840102adffa211f746ec4218abbd.zip
chromium_src-31048b60684f840102adffa211f746ec4218abbd.tar.gz
chromium_src-31048b60684f840102adffa211f746ec4218abbd.tar.bz2
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}
Diffstat (limited to 'ui/compositor')
-rw-r--r--ui/compositor/layer.cc4
-rw-r--r--ui/compositor/layer_owner_unittest.cc24
-rw-r--r--ui/compositor/layer_unittest.cc73
3 files changed, 100 insertions, 1 deletions
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index a46c6b9..c013cb7 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -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 {
diff --git a/ui/compositor/layer_owner_unittest.cc b/ui/compositor/layer_owner_unittest.cc
index e3a3220..c813324 100644
--- a/ui/compositor/layer_owner_unittest.cc
+++ b/ui/compositor/layer_owner_unittest.cc
@@ -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;
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc
index 6efe2d2..bb3c63d 100644
--- a/ui/compositor/layer_unittest.cc
+++ b/ui/compositor/layer_unittest.cc
@@ -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) {