Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 | |
| 5 #ifndef WorkletAnimation_h | |
| 6 #define WorkletAnimation_h | |
| 7 | |
| 8 #include "bindings/core/v8/serialization/SerializedScriptValue.h" | |
| 9 #include "bindings/modules/v8/DocumentTimelineOrScrollTimeline.h" | |
| 10 #include "core/animation/KeyframeEffectReadOnly.h" | |
| 11 #include "core/animation/WorkletAnimationBase.h" | |
| 12 #include "modules/ModulesExport.h" | |
| 13 #include "platform/animation/CompositorAnimationDelegate.h" | |
| 14 #include "platform/animation/CompositorAnimationPlayerClient.h" | |
| 15 #include "platform/bindings/ScriptWrappable.h" | |
| 16 | |
| 17 namespace blink { | |
| 18 | |
| 19 class MODULES_EXPORT WorkletAnimation : public WorkletAnimationBase, | |
| 20 public ScriptWrappable, | |
| 21 public CompositorAnimationPlayerClient, | |
| 22 public CompositorAnimationDelegate { | |
| 23 DEFINE_WRAPPERTYPEINFO(); | |
| 24 | |
| 25 public: | |
| 26 enum AnimationPlayState { | |
| 27 kIdle, | |
| 28 kPending, | |
| 29 kRunning, | |
| 30 }; | |
| 31 | |
| 32 static WorkletAnimation* Create( | |
| 33 String animator_name, | |
| 34 const HeapVector<Member<KeyframeEffectReadOnly>>&, | |
| 35 HeapVector<DocumentTimelineOrScrollTimeline>&, | |
| 36 RefPtr<SerializedScriptValue>, | |
| 37 ExceptionState&); | |
| 38 | |
| 39 virtual ~WorkletAnimation() {} | |
| 40 | |
| 41 String playState(); | |
| 42 void play(); | |
| 43 void cancel(); | |
| 44 | |
| 45 // WorkletAnimationBase implementation. | |
| 46 bool StartOnCompositor() override; | |
| 47 | |
| 48 // CompositorAnimationPlayerClient implementation. | |
| 49 CompositorAnimationPlayer* CompositorPlayer() const override { | |
| 50 return compositor_player_ ? compositor_player_->Player() : nullptr; | |
| 51 } | |
| 52 | |
| 53 // CompositorAnimationDelegate implementation. | |
| 54 void NotifyAnimationStarted(double monotonic_time, int group) override {} | |
| 55 void NotifyAnimationFinished(double monotonic_time, int group) override {} | |
| 56 void NotifyAnimationAborted(double monotonic_time, int group) override {} | |
| 57 | |
| 58 void Dispose(); | |
| 59 | |
| 60 String Name() { return animator_name_; } | |
| 61 | |
| 62 const HeapVector<DocumentTimelineOrScrollTimeline>& Timelines() { | |
| 63 return timelines_; | |
| 64 } | |
| 65 | |
| 66 const RefPtr<SerializedScriptValue> Options() { return options_; } | |
| 67 | |
| 68 DECLARE_VIRTUAL_TRACE(); | |
| 69 | |
| 70 private: | |
| 71 WorkletAnimation(String animator_name, | |
| 72 Document&, | |
| 73 const HeapVector<Member<KeyframeEffectReadOnly>>&, | |
| 74 HeapVector<DocumentTimelineOrScrollTimeline>&, | |
| 75 RefPtr<SerializedScriptValue>); | |
| 76 | |
| 77 // TODO(smcgruer): This pattern was copied from Animation.h. Document why we | |
| 78 // do this, or remove the layer of indirection. | |
|
flackr
2017/07/19 19:23:48
I'm thinking we should not copy this pattern unles
smcgruer
2017/07/24 14:48:58
Done.
| |
| 79 class CompositorAnimationPlayerHolder | |
| 80 : public GarbageCollectedFinalized<CompositorAnimationPlayerHolder> { | |
| 81 USING_PRE_FINALIZER(CompositorAnimationPlayerHolder, Dispose); | |
| 82 | |
| 83 public: | |
| 84 static CompositorAnimationPlayerHolder* Create(WorkletAnimation*); | |
| 85 | |
| 86 void Detach(); | |
| 87 | |
| 88 DEFINE_INLINE_TRACE() { visitor->Trace(animation_); } | |
| 89 | |
| 90 CompositorAnimationPlayer* Player() const { | |
| 91 return compositor_player_.get(); | |
| 92 } | |
| 93 | |
| 94 private: | |
| 95 explicit CompositorAnimationPlayerHolder(WorkletAnimation*); | |
| 96 | |
| 97 void Dispose(); | |
| 98 | |
| 99 std::unique_ptr<CompositorAnimationPlayer> compositor_player_; | |
| 100 Member<WorkletAnimation> animation_; | |
| 101 }; | |
| 102 | |
| 103 String animator_name_; | |
| 104 AnimationPlayState play_state_; | |
| 105 | |
| 106 Member<Document> document_; | |
| 107 | |
| 108 HeapVector<Member<KeyframeEffectReadOnly>> effects_; | |
| 109 HeapVector<DocumentTimelineOrScrollTimeline> timelines_; | |
| 110 RefPtr<SerializedScriptValue> options_; | |
| 111 | |
| 112 Member<CompositorAnimationPlayerHolder> compositor_player_; | |
| 113 }; | |
| 114 | |
| 115 } // namespace blink | |
| 116 | |
| 117 #endif | |
| OLD | NEW |