1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/animation/compositor_animation.h"
#include "cc/animation/animation_id_provider.h"
#include "cc/animation/animation_timeline.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_delegate.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
std::unique_ptr<CompositorAnimation> CompositorAnimation::Create(
std::optional<int> replaced_cc_animation_id) {
auto compositor_animation = std::make_unique<CompositorAnimation>(
cc::Animation::Create(replaced_cc_animation_id
? *replaced_cc_animation_id
: cc::AnimationIdProvider::NextAnimationId()));
if (replaced_cc_animation_id) {
compositor_animation->CcAnimation()->set_is_replacement();
}
return compositor_animation;
}
std::unique_ptr<CompositorAnimation>
CompositorAnimation::CreateWorkletAnimation(
cc::WorkletAnimationId worklet_animation_id,
const String& name,
double playback_rate,
std::unique_ptr<cc::AnimationOptions> options,
std::unique_ptr<cc::AnimationEffectTimings> effect_timings) {
return std::make_unique<CompositorAnimation>(cc::WorkletAnimation::Create(
worklet_animation_id, name.Utf8(), playback_rate, std::move(options),
std::move(effect_timings)));
}
CompositorAnimation::CompositorAnimation(scoped_refptr<cc::Animation> animation)
: animation_(animation), delegate_() {}
CompositorAnimation::~CompositorAnimation() {
SetAnimationDelegate(nullptr);
// Detach animation from timeline, otherwise it stays there (leaks) until
// compositor shutdown.
if (animation_->animation_timeline())
animation_->animation_timeline()->DetachAnimation(animation_);
}
cc::Animation* CompositorAnimation::CcAnimation() const {
return animation_.get();
}
int CompositorAnimation::CcAnimationId() const {
CHECK(CcAnimation());
return CcAnimation()->id();
}
void CompositorAnimation::SetAnimationDelegate(
CompositorAnimationDelegate* delegate) {
delegate_ = delegate;
animation_->set_animation_delegate(delegate ? this : nullptr);
}
void CompositorAnimation::AttachElement(const CompositorElementId& id) {
animation_->AttachElement(id);
}
void CompositorAnimation::AttachPaintWorkletElement() {
animation_->AttachPaintWorkletElement();
}
void CompositorAnimation::DetachElement() {
animation_->DetachElement();
}
bool CompositorAnimation::IsElementAttached() const {
return !!animation_->element_id();
}
void CompositorAnimation::AddKeyframeModel(
std::unique_ptr<cc::KeyframeModel> keyframe_model) {
keyframe_model->set_needs_synchronized_start_time(true);
animation_->AddKeyframeModel(std::move(keyframe_model));
}
void CompositorAnimation::RemoveKeyframeModel(int keyframe_model_id) {
animation_->RemoveKeyframeModel(keyframe_model_id);
}
void CompositorAnimation::PauseKeyframeModel(int keyframe_model_id,
base::TimeDelta time_offset) {
animation_->PauseKeyframeModel(keyframe_model_id, time_offset);
}
void CompositorAnimation::AbortKeyframeModel(int keyframe_model_id) {
animation_->AbortKeyframeModel(keyframe_model_id);
}
void CompositorAnimation::UpdatePlaybackRate(double playback_rate) {
cc::ToWorkletAnimation(animation_.get())->UpdatePlaybackRate(playback_rate);
}
void CompositorAnimation::NotifyAnimationStarted(base::TimeTicks monotonic_time,
int target_property,
int group) {
if (delegate_) {
delegate_->NotifyAnimationStarted(monotonic_time - base::TimeTicks(),
group);
}
}
void CompositorAnimation::NotifyAnimationFinished(
base::TimeTicks monotonic_time,
int target_property,
int group) {
if (delegate_) {
delegate_->NotifyAnimationFinished(monotonic_time - base::TimeTicks(),
group);
}
}
void CompositorAnimation::NotifyAnimationAborted(base::TimeTicks monotonic_time,
int target_property,
int group) {
if (delegate_) {
delegate_->NotifyAnimationAborted(monotonic_time - base::TimeTicks(),
group);
}
}
void CompositorAnimation::NotifyAnimationTakeover(
base::TimeTicks monotonic_time,
int target_property,
base::TimeTicks animation_start_time,
std::unique_ptr<gfx::AnimationCurve> curve) {
if (delegate_) {
delegate_->NotifyAnimationTakeover(
(monotonic_time - base::TimeTicks()).InSecondsF(),
(animation_start_time - base::TimeTicks()).InSecondsF(),
std::move(curve));
}
}
void CompositorAnimation::NotifyLocalTimeUpdated(
std::optional<base::TimeDelta> local_time) {
if (delegate_) {
delegate_->NotifyLocalTimeUpdated(local_time);
}
}
} // namespace blink
|