ambient_animation_view.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_VIEW_H_
  5. #define ASH_AMBIENT_UI_AMBIENT_ANIMATION_VIEW_H_
  6. #include <memory>
  7. #include "ash/ambient/model/ambient_animation_photo_provider.h"
  8. #include "ash/ambient/ui/jitter_calculator.h"
  9. #include "ash/ash_export.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/scoped_observation.h"
  12. #include "base/time/time.h"
  13. #include "base/timer/timer.h"
  14. #include "third_party/abseil-cpp/absl/types/optional.h"
  15. #include "ui/compositor/throughput_tracker.h"
  16. #include "ui/lottie/animation.h"
  17. #include "ui/lottie/animation_observer.h"
  18. #include "ui/views/view.h"
  19. #include "ui/views/view_observer.h"
  20. namespace views {
  21. class AnimatedImageView;
  22. class BoxLayoutView;
  23. } // namespace views
  24. namespace ash {
  25. class AmbientAnimationAttributionProvider;
  26. class AmbientAnimationPlayer;
  27. class AmbientAnimationProgressTracker;
  28. class AmbientAnimationStaticResources;
  29. class AmbientAnimationShieldController;
  30. class AmbientMultiScreenMetricsRecorder;
  31. class AmbientViewDelegateImpl;
  32. class ASH_EXPORT AmbientAnimationView : public views::View,
  33. public lottie::AnimationObserver,
  34. public views::ViewObserver {
  35. public:
  36. METADATA_HEADER(AmbientAnimationView);
  37. AmbientAnimationView(
  38. AmbientViewDelegateImpl* view_delegate,
  39. AmbientAnimationProgressTracker* progress_tracker,
  40. std::unique_ptr<const AmbientAnimationStaticResources> static_resources,
  41. AmbientMultiScreenMetricsRecorder* multi_screen_metrics_recorder);
  42. AmbientAnimationView(const AmbientAnimationView&) = delete;
  43. AmbientAnimationView& operator=(AmbientAnimationView&) = delete;
  44. ~AmbientAnimationView() override;
  45. private:
  46. void Init(AmbientMultiScreenMetricsRecorder* multi_screen_metrics_recorder);
  47. void AnimationCycleEnded(const lottie::Animation* animation) override;
  48. void OnViewBoundsChanged(View* observed_view) override;
  49. void StartPlayingAnimation();
  50. void StartThroughputTracking();
  51. void RestartThroughputTracking();
  52. void ApplyJitter();
  53. const base::raw_ptr<AmbientViewDelegateImpl> view_delegate_;
  54. const base::raw_ptr<AmbientAnimationProgressTracker> progress_tracker_;
  55. const std::unique_ptr<const AmbientAnimationStaticResources>
  56. static_resources_;
  57. AmbientAnimationPhotoProvider animation_photo_provider_;
  58. std::unique_ptr<AmbientAnimationAttributionProvider>
  59. animation_attribution_provider_;
  60. views::AnimatedImageView* animated_image_view_ = nullptr;
  61. views::BoxLayoutView* glanceable_info_container_ = nullptr;
  62. views::BoxLayoutView* media_string_container_ = nullptr;
  63. std::unique_ptr<AmbientAnimationShieldController> shield_view_controller_;
  64. std::unique_ptr<AmbientAnimationPlayer> animation_player_;
  65. base::ScopedObservation<View, ViewObserver> animated_image_view_observer_{
  66. this};
  67. base::ScopedObservation<lottie::Animation, lottie::AnimationObserver>
  68. animation_observer_{this};
  69. absl::optional<ui::ThroughputTracker> throughput_tracker_;
  70. base::RepeatingTimer throughput_tracker_restart_timer_;
  71. JitterCalculator animation_jitter_calculator_;
  72. base::TimeTicks last_jitter_timestamp_;
  73. base::WeakPtrFactory<AmbientAnimationView> weak_factory_{this};
  74. };
  75. } // namespace ash
  76. #endif // ASH_AMBIENT_UI_AMBIENT_ANIMATION_VIEW_H_