// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_LOTTIE_ANIMATION_H_ #define UI_LOTTIE_ANIMATION_H_ #include <functional> #include <memory> #include <optional> #include <vector> #include "base/component_export.h" #include "base/containers/flat_map.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted_memory.h" #include "base/memory/scoped_refptr.h" #include "base/observer_list.h" #include "base/time/time.h" #include "cc/paint/skottie_color_map.h" #include "cc/paint/skottie_frame_data.h" #include "cc/paint/skottie_frame_data_provider.h" #include "cc/paint/skottie_resource_metadata.h" #include "cc/paint/skottie_text_property_value.h" #include "cc/paint/skottie_wrapper.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/modules/skottie/include/Skottie.h" #include "ui/gfx/geometry/size.h" class SkImage; struct SkSamplingOptions; namespace gfx { class Canvas; } // namespace gfx namespace lottie { class AnimationTest; class AnimationObserver; // This class is a wrapper over the Skia object for lottie vector graphic // animations. It has its own timeline manager for the animation controls. The // framerate of the animation and the animation ticks are controlled externally // and hence the consumer must manage the timer and call paint at the desired // frame per second. // This helps keep multiple animations be synchronized by having a common // external tick clock. // // Usage example: // 1. Rendering a single frame on the canvas: // Animation animation_ = Animation(data); // animation_.Paint(canvas, t); // // 2. Playing the animation and rendering each frame: // void SampleClient::Init() { // Animation animation_ = Animation(data); // animation_.Start(Animation::PlaybackConfig::CreateWithStyle( // Animation::Style::kLinear, *animation_)); // } // // // overrides cc::CompositorAnimationObserver // void SampleClient::OnAnimationStep(TimeTicks* timestamp) { // timestamp_ = timestamp; // SchedulePaint(); // } // // void SampleClient::OnPaint(Canvas* canvas) { // animation_.Paint(canvas, timestamp_); // } // // 2. If you only want to play a subsection of the animation: // void SampleClient::Init() { // // This will seek to the 1st second of the animation and from there // // play it for 5 seconds. // Animation animation_ = Animation(data); // animation_.Start(Animation::PlaybackConfig({ // Seconds(1), Seconds(5), Animation::Style::kLinear})); // } // // // overrides cc::CompositorAnimationObserver // void SampleClient::OnAnimationStep(TimeTicks*) { // timestamp_ = timestamp; // SchedulePaint(); // } // // void SampleClient::OnPaint(Canvas* canvas) { // animation_.Paint(canvas, timestamp_, gfx::Size(10, 10)); // } // class COMPONENT_EXPORT(UI_LOTTIE) Animation final { … }; } // namespace lottie #endif // UI_LOTTIE_ANIMATION_H_