layer_animator_test_controller.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2013 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. #include <stddef.h>
  5. #include "ui/compositor/layer_animation_sequence.h"
  6. #include "ui/compositor/test/layer_animator_test_controller.h"
  7. #include "ui/gfx/geometry/rect.h"
  8. namespace ui {
  9. LayerAnimatorTestController::LayerAnimatorTestController(
  10. scoped_refptr<LayerAnimator> animator)
  11. : animator_(animator) {
  12. }
  13. LayerAnimatorTestController::~LayerAnimatorTestController() {
  14. }
  15. LayerAnimationSequence* LayerAnimatorTestController::GetRunningSequence(
  16. LayerAnimationElement::AnimatableProperty property) {
  17. LayerAnimator::RunningAnimation* running_animation =
  18. animator_->GetRunningAnimation(property);
  19. if (running_animation)
  20. return running_animation->sequence();
  21. else
  22. return NULL;
  23. }
  24. void LayerAnimatorTestController::StartThreadedAnimationsIfNeeded(
  25. base::TimeTicks started_time) {
  26. std::vector<cc::TargetProperty::Type> threaded_properties;
  27. threaded_properties.push_back(cc::TargetProperty::OPACITY);
  28. threaded_properties.push_back(cc::TargetProperty::TRANSFORM);
  29. for (size_t i = 0; i < threaded_properties.size(); i++) {
  30. LayerAnimationElement::AnimatableProperty animatable_property =
  31. LayerAnimationElement::ToAnimatableProperty(threaded_properties[i]);
  32. LayerAnimationSequence* sequence = GetRunningSequence(animatable_property);
  33. if (!sequence)
  34. continue;
  35. LayerAnimationElement* element = sequence->CurrentElement();
  36. if (!(element->properties() & animatable_property))
  37. continue;
  38. if (!element->Started() ||
  39. element->effective_start_time() != base::TimeTicks())
  40. continue;
  41. animator_->OnThreadedAnimationStarted(started_time, threaded_properties[i],
  42. element->animation_group_id());
  43. }
  44. }
  45. void LayerAnimatorTestController::Step(const base::TimeDelta& duration) {
  46. animator_->Step(animator_->last_step_time() + duration);
  47. }
  48. } // namespace ui