| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/compositor/layer_owner.h" | 5 #include "ui/compositor/layer_owner.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/test/null_task_runner.h" | 8 #include "base/test/null_task_runner.h" |
| 9 #include "cc/animation/animation_player.h" | 9 #include "cc/animation/animation_player.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 LayerOwnerTestWithCompositor(); | 49 LayerOwnerTestWithCompositor(); |
| 50 ~LayerOwnerTestWithCompositor() override; | 50 ~LayerOwnerTestWithCompositor() override; |
| 51 | 51 |
| 52 void SetUp() override; | 52 void SetUp() override; |
| 53 void TearDown() override; | 53 void TearDown() override; |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 ui::Compositor* compositor() { return compositor_.get(); } | 56 ui::Compositor* compositor() { return compositor_.get(); } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 scoped_ptr<ui::Compositor> compositor_; | 59 std::unique_ptr<ui::Compositor> compositor_; |
| 60 | 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(LayerOwnerTestWithCompositor); | 61 DISALLOW_COPY_AND_ASSIGN(LayerOwnerTestWithCompositor); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 LayerOwnerTestWithCompositor::LayerOwnerTestWithCompositor() { | 64 LayerOwnerTestWithCompositor::LayerOwnerTestWithCompositor() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 LayerOwnerTestWithCompositor::~LayerOwnerTestWithCompositor() { | 67 LayerOwnerTestWithCompositor::~LayerOwnerTestWithCompositor() { |
| 68 } | 68 } |
| 69 | 69 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 95 owner.SetLayer(layer); | 95 owner.SetLayer(layer); |
| 96 | 96 |
| 97 ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 97 ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| 98 layer->SetVisible(false); | 98 layer->SetVisible(false); |
| 99 layer->SetOpacity(0.0f); | 99 layer->SetOpacity(0.0f); |
| 100 layer->SetColor(SK_ColorGREEN); | 100 layer->SetColor(SK_ColorGREEN); |
| 101 EXPECT_TRUE(layer->visible()); | 101 EXPECT_TRUE(layer->visible()); |
| 102 EXPECT_EQ(1.0f, layer->opacity()); | 102 EXPECT_EQ(1.0f, layer->opacity()); |
| 103 EXPECT_EQ(SK_ColorRED, layer->background_color()); | 103 EXPECT_EQ(SK_ColorRED, layer->background_color()); |
| 104 | 104 |
| 105 scoped_ptr<Layer> old_layer(owner.RecreateLayer()); | 105 std::unique_ptr<Layer> old_layer(owner.RecreateLayer()); |
| 106 EXPECT_FALSE(owner.layer()->visible()); | 106 EXPECT_FALSE(owner.layer()->visible()); |
| 107 EXPECT_EQ(0.0f, owner.layer()->opacity()); | 107 EXPECT_EQ(0.0f, owner.layer()->opacity()); |
| 108 EXPECT_EQ(SK_ColorGREEN, owner.layer()->background_color()); | 108 EXPECT_EQ(SK_ColorGREEN, owner.layer()->background_color()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Tests that when a LAYER_SOLID_COLOR which is not backed by a SolidColorLayer | 111 // Tests that when a LAYER_SOLID_COLOR which is not backed by a SolidColorLayer |
| 112 // that opaqueness and color targets are maintained when the | 112 // that opaqueness and color targets are maintained when the |
| 113 // LayerOwner::RecreateLayers is called. | 113 // LayerOwner::RecreateLayers is called. |
| 114 TEST(LayerOwnerTest, RecreateLayerSolidColorWithChangedCCLayerHonorsTargets) { | 114 TEST(LayerOwnerTest, RecreateLayerSolidColorWithChangedCCLayerHonorsTargets) { |
| 115 SkColor transparent = SK_ColorTRANSPARENT; | 115 SkColor transparent = SK_ColorTRANSPARENT; |
| 116 LayerOwner owner; | 116 LayerOwner owner; |
| 117 Layer* layer = new Layer(LAYER_SOLID_COLOR); | 117 Layer* layer = new Layer(LAYER_SOLID_COLOR); |
| 118 owner.SetLayer(layer); | 118 owner.SetLayer(layer); |
| 119 layer->SetFillsBoundsOpaquely(false); | 119 layer->SetFillsBoundsOpaquely(false); |
| 120 layer->SetColor(transparent); | 120 layer->SetColor(transparent); |
| 121 // Changing the backing layer takes LAYER_SOLID_COLOR off of the normal layer | 121 // Changing the backing layer takes LAYER_SOLID_COLOR off of the normal layer |
| 122 // flow, need to ensure that set values are maintained. | 122 // flow, need to ensure that set values are maintained. |
| 123 layer->SwitchCCLayerForTest(); | 123 layer->SwitchCCLayerForTest(); |
| 124 | 124 |
| 125 EXPECT_FALSE(layer->fills_bounds_opaquely()); | 125 EXPECT_FALSE(layer->fills_bounds_opaquely()); |
| 126 EXPECT_EQ(transparent, layer->background_color()); | 126 EXPECT_EQ(transparent, layer->background_color()); |
| 127 EXPECT_EQ(transparent, layer->GetTargetColor()); | 127 EXPECT_EQ(transparent, layer->GetTargetColor()); |
| 128 | 128 |
| 129 scoped_ptr<Layer> old_layer(owner.RecreateLayer()); | 129 std::unique_ptr<Layer> old_layer(owner.RecreateLayer()); |
| 130 EXPECT_FALSE(owner.layer()->fills_bounds_opaquely()); | 130 EXPECT_FALSE(owner.layer()->fills_bounds_opaquely()); |
| 131 EXPECT_EQ(transparent, owner.layer()->background_color()); | 131 EXPECT_EQ(transparent, owner.layer()->background_color()); |
| 132 EXPECT_EQ(transparent, owner.layer()->GetTargetColor()); | 132 EXPECT_EQ(transparent, owner.layer()->GetTargetColor()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) { | 135 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) { |
| 136 LayerOwner owner; | 136 LayerOwner owner; |
| 137 Layer* layer = new Layer; | 137 Layer* layer = new Layer; |
| 138 owner.SetLayer(layer); | 138 owner.SetLayer(layer); |
| 139 | 139 |
| 140 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); | 140 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| 141 | 141 |
| 142 EXPECT_EQ(nullptr, owner.layer()->GetCompositor()); | 142 EXPECT_EQ(nullptr, owner.layer()->GetCompositor()); |
| 143 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); | 143 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST(LayerOwnerTest, InvertPropertyRemainSameWithRecreateLayer) { | 146 TEST(LayerOwnerTest, InvertPropertyRemainSameWithRecreateLayer) { |
| 147 LayerOwner owner; | 147 LayerOwner owner; |
| 148 Layer* layer = new Layer; | 148 Layer* layer = new Layer; |
| 149 owner.SetLayer(layer); | 149 owner.SetLayer(layer); |
| 150 | 150 |
| 151 layer->SetLayerInverted(true); | 151 layer->SetLayerInverted(true); |
| 152 scoped_ptr<Layer> old_layer1 = owner.RecreateLayer(); | 152 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer(); |
| 153 EXPECT_EQ(old_layer1->layer_inverted(), owner.layer()->layer_inverted()); | 153 EXPECT_EQ(old_layer1->layer_inverted(), owner.layer()->layer_inverted()); |
| 154 | 154 |
| 155 old_layer1->SetLayerInverted(false); | 155 old_layer1->SetLayerInverted(false); |
| 156 scoped_ptr<Layer> old_layer2 = owner.RecreateLayer(); | 156 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer(); |
| 157 EXPECT_EQ(old_layer2->layer_inverted(), owner.layer()->layer_inverted()); | 157 EXPECT_EQ(old_layer2->layer_inverted(), owner.layer()->layer_inverted()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 TEST(LayerOwnerTest, RecreateLayerWithTransform) { | 160 TEST(LayerOwnerTest, RecreateLayerWithTransform) { |
| 161 LayerOwner owner; | 161 LayerOwner owner; |
| 162 Layer* layer = new Layer; | 162 Layer* layer = new Layer; |
| 163 owner.SetLayer(layer); | 163 owner.SetLayer(layer); |
| 164 | 164 |
| 165 gfx::Transform transform; | 165 gfx::Transform transform; |
| 166 transform.Scale(2, 1); | 166 transform.Scale(2, 1); |
| 167 transform.Translate(10, 5); | 167 transform.Translate(10, 5); |
| 168 | 168 |
| 169 layer->SetTransform(transform); | 169 layer->SetTransform(transform); |
| 170 | 170 |
| 171 scoped_ptr<Layer> old_layer1 = owner.RecreateLayer(); | 171 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer(); |
| 172 // Both new layer and original layer have the same transform. | 172 // Both new layer and original layer have the same transform. |
| 173 EXPECT_EQ(transform, old_layer1->GetTargetTransform()); | 173 EXPECT_EQ(transform, old_layer1->GetTargetTransform()); |
| 174 EXPECT_EQ(transform, owner.layer()->GetTargetTransform()); | 174 EXPECT_EQ(transform, owner.layer()->GetTargetTransform()); |
| 175 | 175 |
| 176 // But they're now separated, so changing the old layer's transform | 176 // But they're now separated, so changing the old layer's transform |
| 177 // should not affect the owner's. | 177 // should not affect the owner's. |
| 178 owner.layer()->SetTransform(gfx::Transform()); | 178 owner.layer()->SetTransform(gfx::Transform()); |
| 179 EXPECT_EQ(transform, old_layer1->GetTargetTransform()); | 179 EXPECT_EQ(transform, old_layer1->GetTargetTransform()); |
| 180 scoped_ptr<Layer> old_layer2 = owner.RecreateLayer(); | 180 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer(); |
| 181 EXPECT_TRUE(old_layer2->GetTargetTransform().IsIdentity()); | 181 EXPECT_TRUE(old_layer2->GetTargetTransform().IsIdentity()); |
| 182 EXPECT_TRUE(owner.layer()->GetTargetTransform().IsIdentity()); | 182 EXPECT_TRUE(owner.layer()->GetTargetTransform().IsIdentity()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { | 185 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { |
| 186 LayerOwner owner; | 186 LayerOwner owner; |
| 187 Layer* layer = new Layer; | 187 Layer* layer = new Layer; |
| 188 owner.SetLayer(layer); | 188 owner.SetLayer(layer); |
| 189 | 189 |
| 190 compositor()->SetRootLayer(layer); | 190 compositor()->SetRootLayer(layer); |
| 191 | 191 |
| 192 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); | 192 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| 193 | 193 |
| 194 EXPECT_EQ(compositor(), owner.layer()->GetCompositor()); | 194 EXPECT_EQ(compositor(), owner.layer()->GetCompositor()); |
| 195 EXPECT_EQ(owner.layer(), compositor()->root_layer()); | 195 EXPECT_EQ(owner.layer(), compositor()->root_layer()); |
| 196 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); | 196 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // Tests that recreating the root layer, while one of its children is animating, | 199 // Tests that recreating the root layer, while one of its children is animating, |
| 200 // properly updates the compositor. So that compositor is not null for observers | 200 // properly updates the compositor. So that compositor is not null for observers |
| 201 // of animations being cancelled. | 201 // of animations being cancelled. |
| 202 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) { | 202 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) { |
| 203 LayerOwner owner; | 203 LayerOwner owner; |
| 204 Layer* layer = new Layer; | 204 Layer* layer = new Layer; |
| 205 owner.SetLayer(layer); | 205 owner.SetLayer(layer); |
| 206 compositor()->SetRootLayer(layer); | 206 compositor()->SetRootLayer(layer); |
| 207 | 207 |
| 208 scoped_ptr<Layer> child(new Layer); | 208 std::unique_ptr<Layer> child(new Layer); |
| 209 child->SetBounds(gfx::Rect(0, 0, 100, 100)); | 209 child->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 210 layer->Add(child.get()); | 210 layer->Add(child.get()); |
| 211 | 211 |
| 212 // This observer checks that the compositor of |child| is not null upon | 212 // This observer checks that the compositor of |child| is not null upon |
| 213 // animation completion. | 213 // animation completion. |
| 214 scoped_ptr<TestLayerAnimationObserver> observer( | 214 std::unique_ptr<TestLayerAnimationObserver> observer( |
| 215 new TestLayerAnimationObserver(child.get())); | 215 new TestLayerAnimationObserver(child.get())); |
| 216 scoped_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( | 216 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( |
| 217 new ui::ScopedAnimationDurationScaleMode( | 217 new ui::ScopedAnimationDurationScaleMode( |
| 218 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | 218 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); |
| 219 { | 219 { |
| 220 ui::ScopedLayerAnimationSettings animation(child->GetAnimator()); | 220 ui::ScopedLayerAnimationSettings animation(child->GetAnimator()); |
| 221 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | 221 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); |
| 222 animation.AddObserver(observer.get()); | 222 animation.AddObserver(observer.get()); |
| 223 gfx::Transform transform; | 223 gfx::Transform transform; |
| 224 transform.Scale(0.5f, 0.5f); | 224 transform.Scale(0.5f, 0.5f); |
| 225 child->SetTransform(transform); | 225 child->SetTransform(transform); |
| 226 } | 226 } |
| 227 | 227 |
| 228 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); | 228 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Tests that recreating a non-root layer, while one of its children is | 231 // Tests that recreating a non-root layer, while one of its children is |
| 232 // animating, properly updates the compositor. So that compositor is not null | 232 // animating, properly updates the compositor. So that compositor is not null |
| 233 // for observers of animations being cancelled. | 233 // for observers of animations being cancelled. |
| 234 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) { | 234 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) { |
| 235 scoped_ptr<Layer> root_layer(new Layer); | 235 std::unique_ptr<Layer> root_layer(new Layer); |
| 236 compositor()->SetRootLayer(root_layer.get()); | 236 compositor()->SetRootLayer(root_layer.get()); |
| 237 | 237 |
| 238 LayerOwner owner; | 238 LayerOwner owner; |
| 239 Layer* layer = new Layer; | 239 Layer* layer = new Layer; |
| 240 owner.SetLayer(layer); | 240 owner.SetLayer(layer); |
| 241 root_layer->Add(layer); | 241 root_layer->Add(layer); |
| 242 | 242 |
| 243 scoped_ptr<Layer> child(new Layer); | 243 std::unique_ptr<Layer> child(new Layer); |
| 244 child->SetBounds(gfx::Rect(0, 0, 100, 100)); | 244 child->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 245 layer->Add(child.get()); | 245 layer->Add(child.get()); |
| 246 | 246 |
| 247 // This observer checks that the compositor of |child| is not null upon | 247 // This observer checks that the compositor of |child| is not null upon |
| 248 // animation completion. | 248 // animation completion. |
| 249 scoped_ptr<TestLayerAnimationObserver> observer( | 249 std::unique_ptr<TestLayerAnimationObserver> observer( |
| 250 new TestLayerAnimationObserver(child.get())); | 250 new TestLayerAnimationObserver(child.get())); |
| 251 scoped_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( | 251 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( |
| 252 new ui::ScopedAnimationDurationScaleMode( | 252 new ui::ScopedAnimationDurationScaleMode( |
| 253 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | 253 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); |
| 254 { | 254 { |
| 255 ui::ScopedLayerAnimationSettings animation(child->GetAnimator()); | 255 ui::ScopedLayerAnimationSettings animation(child->GetAnimator()); |
| 256 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | 256 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); |
| 257 animation.AddObserver(observer.get()); | 257 animation.AddObserver(observer.get()); |
| 258 gfx::Transform transform; | 258 gfx::Transform transform; |
| 259 transform.Scale(0.5f, 0.5f); | 259 transform.Scale(0.5f, 0.5f); |
| 260 child->SetTransform(transform); | 260 child->SetTransform(transform); |
| 261 } | 261 } |
| 262 | 262 |
| 263 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); | 263 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Tests that if LayerOwner-derived class destroys layer, then | 266 // Tests that if LayerOwner-derived class destroys layer, then |
| 267 // LayerAnimator's player becomes detached from compositor timeline. | 267 // LayerAnimator's player becomes detached from compositor timeline. |
| 268 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) { | 268 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) { |
| 269 scoped_ptr<Layer> root_layer(new Layer); | 269 std::unique_ptr<Layer> root_layer(new Layer); |
| 270 compositor()->SetRootLayer(root_layer.get()); | 270 compositor()->SetRootLayer(root_layer.get()); |
| 271 | 271 |
| 272 LayerOwnerForTesting owner; | 272 LayerOwnerForTesting owner; |
| 273 Layer* layer = new Layer; | 273 Layer* layer = new Layer; |
| 274 owner.SetLayer(layer); | 274 owner.SetLayer(layer); |
| 275 layer->SetOpacity(0.5f); | 275 layer->SetOpacity(0.5f); |
| 276 root_layer->Add(layer); | 276 root_layer->Add(layer); |
| 277 | 277 |
| 278 scoped_refptr<cc::AnimationPlayer> player = | 278 scoped_refptr<cc::AnimationPlayer> player = |
| 279 layer->GetAnimator()->GetAnimationPlayerForTesting(); | 279 layer->GetAnimator()->GetAnimationPlayerForTesting(); |
| 280 EXPECT_TRUE(player); | 280 EXPECT_TRUE(player); |
| 281 EXPECT_TRUE(player->animation_timeline()); | 281 EXPECT_TRUE(player->animation_timeline()); |
| 282 | 282 |
| 283 // Destroying layer/animator must detach animator's player from timeline. | 283 // Destroying layer/animator must detach animator's player from timeline. |
| 284 owner.DestroyLayerForTesting(); | 284 owner.DestroyLayerForTesting(); |
| 285 EXPECT_FALSE(player->animation_timeline()); | 285 EXPECT_FALSE(player->animation_timeline()); |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Tests that if we run threaded opacity animation on already added layer | 288 // Tests that if we run threaded opacity animation on already added layer |
| 289 // then LayerAnimator's player becomes attached to timeline. | 289 // then LayerAnimator's player becomes attached to timeline. |
| 290 TEST_F(LayerOwnerTestWithCompositor, | 290 TEST_F(LayerOwnerTestWithCompositor, |
| 291 AttachTimelineIfAnimatorCreatedAfterSetCompositor) { | 291 AttachTimelineIfAnimatorCreatedAfterSetCompositor) { |
| 292 scoped_ptr<Layer> root_layer(new Layer); | 292 std::unique_ptr<Layer> root_layer(new Layer); |
| 293 compositor()->SetRootLayer(root_layer.get()); | 293 compositor()->SetRootLayer(root_layer.get()); |
| 294 | 294 |
| 295 LayerOwner owner; | 295 LayerOwner owner; |
| 296 Layer* layer = new Layer; | 296 Layer* layer = new Layer; |
| 297 owner.SetLayer(layer); | 297 owner.SetLayer(layer); |
| 298 root_layer->Add(layer); | 298 root_layer->Add(layer); |
| 299 | 299 |
| 300 layer->SetOpacity(0.5f); | 300 layer->SetOpacity(0.5f); |
| 301 | 301 |
| 302 scoped_refptr<cc::AnimationPlayer> player = | 302 scoped_refptr<cc::AnimationPlayer> player = |
| 303 layer->GetAnimator()->GetAnimationPlayerForTesting(); | 303 layer->GetAnimator()->GetAnimationPlayerForTesting(); |
| 304 EXPECT_TRUE(player); | 304 EXPECT_TRUE(player); |
| 305 EXPECT_TRUE(player->animation_timeline()); | 305 EXPECT_TRUE(player->animation_timeline()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 } // namespace ui | 308 } // namespace ui |
| OLD | NEW |