#include "ui/lottie/animation.h"
#include <algorithm>
#include <optional>
#include <utility>
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/numerics/safe_conversions.h"
#include "base/observer_list.h"
#include "base/trace_event/trace_event.h"
#include "cc/paint/skottie_wrapper.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSamplingOptions.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/lottie/animation_observer.h"
namespace lottie {
namespace {
bool IsCycleValid(const Animation::CycleBoundaries& boundaries,
const Animation& animation) { … }
bool IsInCycleBoundaries(base::TimeDelta offset,
const Animation::CycleBoundaries& boundaries) { … }
Animation::CycleBoundaries GetCycleAtIndex(
const std::vector<Animation::CycleBoundaries>& scheduled_cycles,
int cycle_idx) { … }
}
Animation::TimerControl::TimerControl(
std::vector<CycleBoundaries> scheduled_cycles,
base::TimeDelta initial_offset,
int initial_completed_cycles,
const base::TimeDelta& total_duration,
const base::TimeTicks& start_timestamp,
bool should_reverse,
float playback_speed)
: … { … }
Animation::TimerControl::~TimerControl() = default;
void Animation::TimerControl::SetPlaybackSpeed(float playback_speed) { … }
void Animation::TimerControl::Step(const base::TimeTicks& timestamp) { … }
void Animation::TimerControl::Resume(const base::TimeTicks& timestamp) { … }
double Animation::TimerControl::GetNormalizedCurrentCycleProgress() const { … }
double Animation::TimerControl::GetNormalizedStartOffset() const { … }
double Animation::TimerControl::GetNormalizedEndOffset() const { … }
bool Animation::TimerControl::IsPlayingInReverse() const { … }
Animation::CycleBoundaries Animation::CycleBoundaries::FullCycle(
const Animation& animation) { … }
Animation::PlaybackConfig Animation::PlaybackConfig::CreateDefault(
const Animation& animation) { … }
Animation::PlaybackConfig Animation::PlaybackConfig::CreateWithStyle(
Style style,
const Animation& animation) { … }
Animation::PlaybackConfig::PlaybackConfig() = default;
Animation::PlaybackConfig::PlaybackConfig(
std::vector<CycleBoundaries> scheduled_cycles,
base::TimeDelta initial_offset,
int initial_completed_cycles,
Style style)
: … { … }
Animation::PlaybackConfig::PlaybackConfig(const PlaybackConfig& other) =
default;
Animation::PlaybackConfig& Animation::PlaybackConfig::operator=(
const PlaybackConfig& other) = default;
Animation::PlaybackConfig::~PlaybackConfig() = default;
Animation::Animation(scoped_refptr<cc::SkottieWrapper> skottie,
cc::SkottieColorMap color_map,
cc::SkottieFrameDataProvider* frame_data_provider)
: … { … }
Animation::~Animation() { … }
void Animation::AddObserver(AnimationObserver* observer) { … }
void Animation::RemoveObserver(AnimationObserver* observer) { … }
base::TimeDelta Animation::GetAnimationDuration() const { … }
gfx::Size Animation::GetOriginalSize() const { … }
void Animation::Start(std::optional<PlaybackConfig> playback_config) { … }
void Animation::Pause() { … }
void Animation::ResumePlaying() { … }
void Animation::Stop() { … }
std::optional<float> Animation::GetCurrentProgress() const { … }
std::optional<int> Animation::GetNumCompletedCycles() const { … }
std::optional<Animation::PlaybackConfig> Animation::GetPlaybackConfig() const { … }
std::optional<Animation::CycleBoundaries> Animation::GetCurrentCycleBoundaries()
const { … }
void Animation::Paint(gfx::Canvas* canvas,
const base::TimeTicks& timestamp,
const gfx::Size& size) { … }
void Animation::PaintFrame(gfx::Canvas* canvas,
float t,
const gfx::Size& size) { … }
void Animation::SetPlaybackSpeed(float playback_speed) { … }
cc::SkottieWrapper::FrameDataFetchResult Animation::LoadImageForAsset(
gfx::Canvas* canvas,
cc::SkottieFrameDataMap& all_frame_data,
cc::SkottieResourceIdHash asset_id,
float t,
sk_sp<SkImage>&,
SkSamplingOptions&) { … }
void Animation::InitTimer(const base::TimeTicks& timestamp) { … }
void Animation::TryNotifyAnimationCycleEnded() const { … }
void Animation::VerifyPlaybackConfigIsValid(
const PlaybackConfig& playback_config) const { … }
}