OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "cc/animation/animation_host.h" | 5 #include "cc/animation/animation_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/animation/animation_player.h" | 9 #include "cc/animation/animation_player.h" |
10 #include "cc/animation/animation_registrar.h" | 10 #include "cc/animation/animation_registrar.h" |
11 #include "cc/animation/animation_timeline.h" | 11 #include "cc/animation/animation_timeline.h" |
12 #include "cc/trees/layer_tree_mutators_client.h" | 12 #include "cc/trees/layer_tree_mutators_client.h" |
| 13 #include "ui/gfx/geometry/box_f.h" |
13 | 14 |
14 namespace cc { | 15 namespace cc { |
15 | 16 |
16 scoped_ptr<AnimationHost> AnimationHost::Create(bool is_impl_instance) { | 17 scoped_ptr<AnimationHost> AnimationHost::Create(bool is_impl_instance) { |
17 return make_scoped_ptr(new AnimationHost(is_impl_instance)); | 18 return make_scoped_ptr(new AnimationHost(is_impl_instance)); |
18 } | 19 } |
19 | 20 |
20 AnimationHost::AnimationHost(bool is_impl_instance) | 21 AnimationHost::AnimationHost(bool is_impl_instance) |
21 : animation_registrar_(AnimationRegistrar::Create()), | 22 : animation_registrar_(AnimationRegistrar::Create()), |
22 layer_tree_mutators_client_(), | 23 layer_tree_mutators_client_(), |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 timeline->PushPropertiesTo(timeline_impl); | 147 timeline->PushPropertiesTo(timeline_impl); |
147 } | 148 } |
148 } | 149 } |
149 | 150 |
150 AnimationPlayer* AnimationHost::GetPlayerForLayerId(int layer_id) const { | 151 AnimationPlayer* AnimationHost::GetPlayerForLayerId(int layer_id) const { |
151 DCHECK(layer_id); | 152 DCHECK(layer_id); |
152 auto iter = layer_to_player_map_.find(layer_id); | 153 auto iter = layer_to_player_map_.find(layer_id); |
153 return iter == layer_to_player_map_.end() ? nullptr : iter->second; | 154 return iter == layer_to_player_map_.end() ? nullptr : iter->second; |
154 } | 155 } |
155 | 156 |
| 157 void AnimationHost::SetSupportsScrollAnimations( |
| 158 bool supports_scroll_animations) { |
| 159 animation_registrar_->set_supports_scroll_animations( |
| 160 supports_scroll_animations); |
| 161 } |
| 162 |
| 163 bool AnimationHost::SupportsScrollAnimations() const { |
| 164 return animation_registrar_->supports_scroll_animations(); |
| 165 } |
| 166 |
| 167 bool AnimationHost::NeedsAnimateLayers() const { |
| 168 return animation_registrar_->needs_animate_layers(); |
| 169 } |
| 170 |
| 171 bool AnimationHost::ActivateAnimations() { |
| 172 return animation_registrar_->ActivateAnimations(); |
| 173 } |
| 174 |
| 175 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) { |
| 176 return animation_registrar_->AnimateLayers(monotonic_time); |
| 177 } |
| 178 |
| 179 bool AnimationHost::UpdateAnimationState(bool start_ready_animations, |
| 180 AnimationEventsVector* events) { |
| 181 return animation_registrar_->UpdateAnimationState(start_ready_animations, |
| 182 events); |
| 183 } |
| 184 |
| 185 scoped_ptr<AnimationEventsVector> AnimationHost::CreateEvents() { |
| 186 return animation_registrar_->CreateEvents(); |
| 187 } |
| 188 |
| 189 void AnimationHost::SetAnimationEvents( |
| 190 scoped_ptr<AnimationEventsVector> events) { |
| 191 return animation_registrar_->SetAnimationEvents(events.Pass()); |
| 192 } |
| 193 |
| 194 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const { |
| 195 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 196 return player |
| 197 ? player->layer_animation_controller() |
| 198 ->scroll_offset_animation_was_interrupted() |
| 199 : false; |
| 200 } |
| 201 |
| 202 bool AnimationHost::IsAnimatingFilterProperty(int layer_id) const { |
| 203 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 204 return player |
| 205 ? player->layer_animation_controller()->IsAnimatingProperty( |
| 206 Animation::FILTER) |
| 207 : false; |
| 208 } |
| 209 |
| 210 bool AnimationHost::IsAnimatingOpacityProperty(int layer_id) const { |
| 211 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 212 return player |
| 213 ? player->layer_animation_controller()->IsAnimatingProperty( |
| 214 Animation::OPACITY) |
| 215 : false; |
| 216 } |
| 217 |
| 218 bool AnimationHost::IsAnimatingTransformProperty(int layer_id) const { |
| 219 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 220 return player |
| 221 ? player->layer_animation_controller()->IsAnimatingProperty( |
| 222 Animation::TRANSFORM) |
| 223 : false; |
| 224 } |
| 225 |
| 226 bool AnimationHost::HasPotentiallyRunningOpacityAnimation(int layer_id) const { |
| 227 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 228 if (player) { |
| 229 if (Animation* animation = |
| 230 player->layer_animation_controller()->GetAnimation( |
| 231 Animation::OPACITY)) { |
| 232 return !animation->is_finished(); |
| 233 } |
| 234 } |
| 235 return false; |
| 236 } |
| 237 |
| 238 bool AnimationHost::HasPotentiallyRunningTransformAnimation( |
| 239 int layer_id) const { |
| 240 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 241 if (player) { |
| 242 if (Animation* animation = |
| 243 player->layer_animation_controller()->GetAnimation( |
| 244 Animation::TRANSFORM)) { |
| 245 return !animation->is_finished(); |
| 246 } |
| 247 } |
| 248 return false; |
| 249 } |
| 250 |
| 251 bool AnimationHost::FilterIsAnimatingOnImplOnly(int layer_id) const { |
| 252 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 253 if (!player) |
| 254 return false; |
| 255 |
| 256 Animation* animation = |
| 257 player->layer_animation_controller()->GetAnimation(Animation::FILTER); |
| 258 return animation && animation->is_impl_only(); |
| 259 } |
| 260 |
| 261 bool AnimationHost::OpacityIsAnimatingOnImplOnly(int layer_id) const { |
| 262 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 263 if (!player) |
| 264 return false; |
| 265 |
| 266 Animation* animation = |
| 267 player->layer_animation_controller()->GetAnimation(Animation::OPACITY); |
| 268 return animation && animation->is_impl_only(); |
| 269 } |
| 270 |
| 271 bool AnimationHost::TransformIsAnimatingOnImplOnly(int layer_id) const { |
| 272 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 273 if (!player) |
| 274 return false; |
| 275 |
| 276 Animation* animation = |
| 277 player->layer_animation_controller()->GetAnimation(Animation::TRANSFORM); |
| 278 return animation && animation->is_impl_only(); |
| 279 } |
| 280 |
| 281 bool AnimationHost::HasFilterAnimationThatInflatesBounds(int layer_id) const { |
| 282 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 283 return player |
| 284 ? player->layer_animation_controller() |
| 285 ->HasFilterAnimationThatInflatesBounds() |
| 286 : false; |
| 287 } |
| 288 |
| 289 bool AnimationHost::HasTransformAnimationThatInflatesBounds( |
| 290 int layer_id) const { |
| 291 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 292 return player |
| 293 ? player->layer_animation_controller() |
| 294 ->HasTransformAnimationThatInflatesBounds() |
| 295 : false; |
| 296 } |
| 297 |
| 298 bool AnimationHost::HasAnimationThatInflatesBounds(int layer_id) const { |
| 299 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 300 return player |
| 301 ? player->layer_animation_controller() |
| 302 ->HasAnimationThatInflatesBounds() |
| 303 : false; |
| 304 } |
| 305 |
| 306 bool AnimationHost::FilterAnimationBoundsForBox(int layer_id, |
| 307 const gfx::BoxF& box, |
| 308 gfx::BoxF* bounds) const { |
| 309 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 310 return player |
| 311 ? player->layer_animation_controller() |
| 312 ->FilterAnimationBoundsForBox(box, bounds) |
| 313 : false; |
| 314 } |
| 315 |
| 316 bool AnimationHost::TransformAnimationBoundsForBox(int layer_id, |
| 317 const gfx::BoxF& box, |
| 318 gfx::BoxF* bounds) const { |
| 319 *bounds = gfx::BoxF(); |
| 320 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 321 return player |
| 322 ? player->layer_animation_controller() |
| 323 ->TransformAnimationBoundsForBox(box, bounds) |
| 324 : true; |
| 325 } |
| 326 |
| 327 bool AnimationHost::HasOnlyTranslationTransforms(int layer_id) const { |
| 328 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 329 return player |
| 330 ? player->layer_animation_controller() |
| 331 ->HasOnlyTranslationTransforms() |
| 332 : true; |
| 333 } |
| 334 |
| 335 bool AnimationHost::AnimationsPreserveAxisAlignment(int layer_id) const { |
| 336 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 337 return player |
| 338 ? player->layer_animation_controller() |
| 339 ->AnimationsPreserveAxisAlignment() |
| 340 : true; |
| 341 } |
| 342 |
| 343 bool AnimationHost::MaximumTargetScale(int layer_id, float* max_scale) const { |
| 344 *max_scale = 0.f; |
| 345 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 346 return player |
| 347 ? player->layer_animation_controller()->MaximumTargetScale( |
| 348 max_scale) |
| 349 : true; |
| 350 } |
| 351 |
| 352 bool AnimationHost::HasAnyAnimation(int layer_id) const { |
| 353 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 354 return player ? player->layer_animation_controller()->has_any_animation() |
| 355 : false; |
| 356 } |
| 357 |
| 358 bool AnimationHost::HasActiveAnimation(int layer_id) const { |
| 359 AnimationPlayer* player = GetPlayerForLayerId(layer_id); |
| 360 return player ? player->layer_animation_controller()->HasActiveAnimation() |
| 361 : false; |
| 362 } |
| 363 |
156 } // namespace cc | 364 } // namespace cc |
OLD | NEW |