ambient_animation_player.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2022 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. #ifndef ASH_AMBIENT_UI_AMBIENT_ANIMATION_PLAYER_H_
  5. #define ASH_AMBIENT_UI_AMBIENT_ANIMATION_PLAYER_H_
  6. #include "ash/ash_export.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/time/time.h"
  9. #include "ui/lottie/animation.h"
  10. namespace views {
  11. class AnimatedImageView;
  12. } // namespace views
  13. namespace ash {
  14. class AmbientAnimationProgressTracker;
  15. // Plays an AnimatedImageView in a loop until destruction. The "looping" logic
  16. // meets ambient mode's custom requirements: The lottie animation may optionally
  17. // have a "marker" embedded in it. The "marker" is a timestamp set by the motion
  18. // designer, which in this case, indicates where the animation should restart
  19. // after each cycle ends. If the marker timestamp is M and the total animation
  20. // cycle duration is D (where 0 < M < D), then the animation cycles look
  21. // like this:
  22. // [0, D]
  23. // [M, D]
  24. // [M, D]
  25. // ...
  26. //
  27. // Note the very first animation cycle is always played starting at time 0 (the
  28. // very first frame in the animation).
  29. //
  30. // If the animation does not have a marker embedded in it, the default behavior
  31. // is to restart at the beginning of the animation each time (M is effectively
  32. // 0):
  33. // [0, D]
  34. // [0, D]
  35. // [0, D]
  36. // ...
  37. class ASH_EXPORT AmbientAnimationPlayer {
  38. public:
  39. // Starts playing the |animated_image_view| immediately upon construction.
  40. explicit AmbientAnimationPlayer(
  41. views::AnimatedImageView* animated_image_view,
  42. AmbientAnimationProgressTracker* progress_tracker);
  43. AmbientAnimationPlayer(const AmbientAnimationPlayer&) = delete;
  44. AmbientAnimationPlayer& operator=(const AmbientAnimationPlayer&) = delete;
  45. ~AmbientAnimationPlayer();
  46. private:
  47. const base::raw_ptr<views::AnimatedImageView> animated_image_view_;
  48. const base::raw_ptr<AmbientAnimationProgressTracker> progress_tracker_;
  49. base::TimeDelta cycle_restart_timestamp_;
  50. };
  51. } // namespace ash
  52. #endif // ASH_AMBIENT_UI_AMBIENT_ANIMATION_PLAYER_H_