OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/animation/animation_player.h" |
| 6 |
| 7 #include "cc/animation/animation_delegate.h" |
| 8 #include "cc/animation/animation_host.h" |
| 9 #include "cc/animation/animation_id_provider.h" |
| 10 #include "cc/animation/animation_registrar.h" |
| 11 #include "cc/animation/animation_timeline.h" |
| 12 #include "cc/animation/element_animations.h" |
| 13 #include "cc/test/animation_test_common.h" |
| 14 #include "cc/test/animation_timelines_test_common.h" |
| 15 |
| 16 namespace cc { |
| 17 namespace { |
| 18 |
| 19 class AnimationPlayerTest : public AnimationTimelinesTest { |
| 20 public: |
| 21 AnimationPlayerTest() {} |
| 22 ~AnimationPlayerTest() override {} |
| 23 }; |
| 24 |
| 25 // See element_animations_unittest.cc for active/pending observers tests. |
| 26 |
| 27 TEST_F(AnimationPlayerTest, AttachDetachLayerIfTimelineAttached) { |
| 28 host_->AddAnimationTimeline(timeline_); |
| 29 timeline_->AttachPlayer(player_); |
| 30 EXPECT_FALSE(player_->element_animations()); |
| 31 EXPECT_FALSE(player_->layer_id()); |
| 32 |
| 33 host_->PushPropertiesTo(host_impl_); |
| 34 |
| 35 EXPECT_FALSE(GetImplPlayerForLayerId(layer_id_)); |
| 36 |
| 37 GetImplTimelineAndPlayerByID(); |
| 38 |
| 39 EXPECT_FALSE(player_impl_->element_animations()); |
| 40 EXPECT_FALSE(player_impl_->layer_id()); |
| 41 |
| 42 player_->AttachLayer(layer_id_); |
| 43 EXPECT_EQ(player_, GetPlayerForLayerId(layer_id_)); |
| 44 EXPECT_TRUE(player_->element_animations()); |
| 45 EXPECT_EQ(player_->layer_id(), layer_id_); |
| 46 |
| 47 host_->PushPropertiesTo(host_impl_); |
| 48 |
| 49 EXPECT_EQ(player_impl_, GetImplPlayerForLayerId(layer_id_)); |
| 50 EXPECT_TRUE(player_impl_->element_animations()); |
| 51 EXPECT_EQ(player_impl_->layer_id(), layer_id_); |
| 52 |
| 53 player_->DetachLayer(); |
| 54 EXPECT_FALSE(GetPlayerForLayerId(layer_id_)); |
| 55 EXPECT_FALSE(player_->element_animations()); |
| 56 EXPECT_FALSE(player_->layer_id()); |
| 57 |
| 58 host_->PushPropertiesTo(host_impl_); |
| 59 |
| 60 EXPECT_FALSE(GetImplPlayerForLayerId(layer_id_)); |
| 61 EXPECT_FALSE(player_impl_->element_animations()); |
| 62 EXPECT_FALSE(player_impl_->layer_id()); |
| 63 |
| 64 timeline_->DetachPlayer(player_); |
| 65 EXPECT_FALSE(player_->animation_timeline()); |
| 66 EXPECT_FALSE(player_->element_animations()); |
| 67 EXPECT_FALSE(player_->layer_id()); |
| 68 } |
| 69 |
| 70 TEST_F(AnimationPlayerTest, AttachDetachTimelineIfLayerAttached) { |
| 71 host_->AddAnimationTimeline(timeline_); |
| 72 |
| 73 EXPECT_FALSE(player_->element_animations()); |
| 74 EXPECT_FALSE(player_->layer_id()); |
| 75 |
| 76 player_->AttachLayer(layer_id_); |
| 77 EXPECT_FALSE(player_->animation_timeline()); |
| 78 EXPECT_FALSE(GetPlayerForLayerId(layer_id_)); |
| 79 EXPECT_FALSE(player_->element_animations()); |
| 80 EXPECT_EQ(player_->layer_id(), layer_id_); |
| 81 |
| 82 timeline_->AttachPlayer(player_); |
| 83 EXPECT_EQ(timeline_, player_->animation_timeline()); |
| 84 EXPECT_EQ(player_, GetPlayerForLayerId(layer_id_)); |
| 85 EXPECT_TRUE(player_->element_animations()); |
| 86 EXPECT_EQ(player_->layer_id(), layer_id_); |
| 87 |
| 88 // Removing player from timeline detaches layer. |
| 89 timeline_->DetachPlayer(player_); |
| 90 EXPECT_FALSE(player_->animation_timeline()); |
| 91 EXPECT_FALSE(GetPlayerForLayerId(layer_id_)); |
| 92 EXPECT_FALSE(player_->element_animations()); |
| 93 EXPECT_FALSE(player_->layer_id()); |
| 94 } |
| 95 |
| 96 TEST_F(AnimationPlayerTest, PropertiesMutate) { |
| 97 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 98 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); |
| 99 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 100 |
| 101 host_->AddAnimationTimeline(timeline_); |
| 102 timeline_->AttachPlayer(player_); |
| 103 player_->AttachLayer(layer_id_); |
| 104 |
| 105 const float start_opacity = .7f; |
| 106 const float end_opacity = .3f; |
| 107 |
| 108 const float start_brightness = .6f; |
| 109 const float end_brightness = .4f; |
| 110 |
| 111 const int transform_x = 10; |
| 112 const int transform_y = 20; |
| 113 |
| 114 const double duration = 1.; |
| 115 |
| 116 AddOpacityTransitionToPlayer(player_.get(), duration, start_opacity, |
| 117 end_opacity, false); |
| 118 AddAnimatedTransformToPlayer(player_.get(), duration, transform_x, |
| 119 transform_y); |
| 120 AddAnimatedFilterToPlayer(player_.get(), duration, start_brightness, |
| 121 end_brightness); |
| 122 |
| 123 host_->PushPropertiesTo(host_impl_); |
| 124 |
| 125 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 126 Animation::OPACITY)); |
| 127 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 128 Animation::TRANSFORM)); |
| 129 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 130 Animation::FILTER)); |
| 131 |
| 132 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 133 Animation::OPACITY)); |
| 134 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 135 Animation::TRANSFORM)); |
| 136 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 137 Animation::FILTER)); |
| 138 |
| 139 host_impl_->animation_registrar()->ActivateAnimations(); |
| 140 |
| 141 base::TimeTicks time; |
| 142 time += base::TimeDelta::FromSecondsD(0.1); |
| 143 AnimateLayersTransferEvents(time, 3u); |
| 144 |
| 145 time += base::TimeDelta::FromSecondsD(duration); |
| 146 AnimateLayersTransferEvents(time, 3u); |
| 147 |
| 148 client_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 149 end_opacity); |
| 150 client_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 151 transform_x, transform_y); |
| 152 client_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 153 end_brightness); |
| 154 |
| 155 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 156 end_opacity); |
| 157 client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 158 transform_x, transform_y); |
| 159 client_impl_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 160 end_brightness); |
| 161 |
| 162 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::PENDING, |
| 163 end_opacity); |
| 164 client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::PENDING, |
| 165 transform_x, transform_y); |
| 166 client_impl_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::PENDING, |
| 167 end_brightness); |
| 168 } |
| 169 |
| 170 TEST_F(AnimationPlayerTest, AttachTwoPlayersToOneLayer) { |
| 171 TestAnimationDelegate delegate1; |
| 172 TestAnimationDelegate delegate2; |
| 173 |
| 174 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 175 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); |
| 176 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 177 |
| 178 scoped_refptr<AnimationPlayer> player1 = |
| 179 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 180 scoped_refptr<AnimationPlayer> player2 = |
| 181 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 182 |
| 183 host_->AddAnimationTimeline(timeline_); |
| 184 timeline_->AttachPlayer(player1); |
| 185 timeline_->AttachPlayer(player2); |
| 186 |
| 187 player1->set_layer_animation_delegate(&delegate1); |
| 188 player2->set_layer_animation_delegate(&delegate2); |
| 189 |
| 190 // Attach players to the same layer. |
| 191 player1->AttachLayer(layer_id_); |
| 192 player2->AttachLayer(layer_id_); |
| 193 |
| 194 const float start_opacity = .7f; |
| 195 const float end_opacity = .3f; |
| 196 |
| 197 const int transform_x = 10; |
| 198 const int transform_y = 20; |
| 199 |
| 200 const double duration = 1.; |
| 201 |
| 202 AddOpacityTransitionToPlayer(player1.get(), duration, start_opacity, |
| 203 end_opacity, false); |
| 204 AddAnimatedTransformToPlayer(player2.get(), duration, transform_x, |
| 205 transform_y); |
| 206 |
| 207 host_->PushPropertiesTo(host_impl_); |
| 208 host_impl_->animation_registrar()->ActivateAnimations(); |
| 209 |
| 210 EXPECT_FALSE(delegate1.started_); |
| 211 EXPECT_FALSE(delegate1.finished_); |
| 212 |
| 213 EXPECT_FALSE(delegate2.started_); |
| 214 EXPECT_FALSE(delegate2.finished_); |
| 215 |
| 216 base::TimeTicks time; |
| 217 time += base::TimeDelta::FromSecondsD(0.1); |
| 218 AnimateLayersTransferEvents(time, 2u); |
| 219 |
| 220 EXPECT_TRUE(delegate1.started_); |
| 221 EXPECT_FALSE(delegate1.finished_); |
| 222 |
| 223 EXPECT_TRUE(delegate2.started_); |
| 224 EXPECT_FALSE(delegate2.finished_); |
| 225 |
| 226 time += base::TimeDelta::FromSecondsD(duration); |
| 227 AnimateLayersTransferEvents(time, 2u); |
| 228 |
| 229 EXPECT_TRUE(delegate1.finished_); |
| 230 EXPECT_TRUE(delegate2.finished_); |
| 231 |
| 232 client_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 233 end_opacity); |
| 234 client_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 235 transform_x, transform_y); |
| 236 |
| 237 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 238 end_opacity); |
| 239 client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 240 transform_x, transform_y); |
| 241 |
| 242 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::PENDING, |
| 243 end_opacity); |
| 244 client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::PENDING, |
| 245 transform_x, transform_y); |
| 246 } |
| 247 |
| 248 TEST_F(AnimationPlayerTest, AddRemoveAnimationToNonAttachedPlayer) { |
| 249 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 250 client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING); |
| 251 client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 252 |
| 253 const double duration = 1.; |
| 254 const float start_opacity = .7f; |
| 255 const float end_opacity = .3f; |
| 256 |
| 257 const int filter_id = |
| 258 AddAnimatedFilterToPlayer(player_.get(), duration, 0.1f, 0.9f); |
| 259 const int opacity_id = AddOpacityTransitionToPlayer( |
| 260 player_.get(), duration, start_opacity, end_opacity, false); |
| 261 |
| 262 host_->AddAnimationTimeline(timeline_); |
| 263 timeline_->AttachPlayer(player_); |
| 264 |
| 265 EXPECT_FALSE(player_->element_animations()); |
| 266 player_->RemoveAnimation(filter_id); |
| 267 |
| 268 player_->AttachLayer(layer_id_); |
| 269 |
| 270 EXPECT_TRUE(player_->element_animations()); |
| 271 EXPECT_FALSE(player_->element_animations() |
| 272 ->layer_animation_controller() |
| 273 ->GetAnimationById(filter_id)); |
| 274 EXPECT_TRUE(player_->element_animations() |
| 275 ->layer_animation_controller() |
| 276 ->GetAnimationById(opacity_id)); |
| 277 |
| 278 host_->PushPropertiesTo(host_impl_); |
| 279 |
| 280 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 281 Animation::OPACITY)); |
| 282 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 283 Animation::OPACITY)); |
| 284 |
| 285 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 286 Animation::FILTER)); |
| 287 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 288 Animation::FILTER)); |
| 289 |
| 290 host_impl_->animation_registrar()->ActivateAnimations(); |
| 291 |
| 292 base::TimeTicks time; |
| 293 time += base::TimeDelta::FromSecondsD(0.1); |
| 294 AnimateLayersTransferEvents(time, 1u); |
| 295 |
| 296 time += base::TimeDelta::FromSecondsD(duration); |
| 297 AnimateLayersTransferEvents(time, 1u); |
| 298 |
| 299 client_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 300 end_opacity); |
| 301 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 302 end_opacity); |
| 303 client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::PENDING, |
| 304 end_opacity); |
| 305 |
| 306 EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 307 Animation::FILTER)); |
| 308 EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE, |
| 309 Animation::FILTER)); |
| 310 } |
| 311 |
| 312 TEST_F(AnimationPlayerTest, AddRemoveAnimationCausesSetNeedsCommit) { |
| 313 client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE); |
| 314 host_->AddAnimationTimeline(timeline_); |
| 315 timeline_->AttachPlayer(player_); |
| 316 player_->AttachLayer(layer_id_); |
| 317 |
| 318 EXPECT_FALSE(client_.mutators_need_commit()); |
| 319 |
| 320 const int animation_id = |
| 321 AddOpacityTransitionToPlayer(player_.get(), 1., .7f, .3f, false); |
| 322 |
| 323 EXPECT_TRUE(client_.mutators_need_commit()); |
| 324 client_.set_mutators_need_commit(false); |
| 325 |
| 326 player_->PauseAnimation(animation_id, 1.); |
| 327 EXPECT_TRUE(client_.mutators_need_commit()); |
| 328 client_.set_mutators_need_commit(false); |
| 329 |
| 330 player_->RemoveAnimation(animation_id); |
| 331 EXPECT_TRUE(client_.mutators_need_commit()); |
| 332 client_.set_mutators_need_commit(false); |
| 333 } |
| 334 |
| 335 } // namespace |
| 336 } // namespace cc |
OLD | NEW |