| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef AnimationPlayer_h | |
| 32 #define AnimationPlayer_h | |
| 33 | |
| 34 #include "bindings/core/v8/ScriptPromise.h" | |
| 35 #include "bindings/core/v8/ScriptPromiseProperty.h" | |
| 36 #include "core/CSSPropertyNames.h" | |
| 37 #include "core/CoreExport.h" | |
| 38 #include "core/animation/AnimationNode.h" | |
| 39 #include "core/dom/ActiveDOMObject.h" | |
| 40 #include "core/dom/DOMException.h" | |
| 41 #include "core/events/EventTarget.h" | |
| 42 #include "platform/heap/Handle.h" | |
| 43 #include "public/platform/WebCompositorAnimationDelegate.h" | |
| 44 #include "public/platform/WebCompositorAnimationPlayerClient.h" | |
| 45 #include "wtf/RefPtr.h" | |
| 46 | |
| 47 namespace blink { | |
| 48 | |
| 49 class AnimationTimeline; | |
| 50 class Element; | |
| 51 class ExceptionState; | |
| 52 class WebCompositorAnimationPlayer; | |
| 53 | |
| 54 class CORE_EXPORT AnimationPlayer final | |
| 55 : public EventTargetWithInlineData | |
| 56 , public RefCountedWillBeNoBase<AnimationPlayer> | |
| 57 , public ActiveDOMObject | |
| 58 , public WebCompositorAnimationDelegate | |
| 59 , public WebCompositorAnimationPlayerClient { | |
| 60 DEFINE_WRAPPERTYPEINFO(); | |
| 61 REFCOUNTED_EVENT_TARGET(AnimationPlayer); | |
| 62 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AnimationPlayer); | |
| 63 public: | |
| 64 enum AnimationPlayState { | |
| 65 Idle, | |
| 66 Pending, | |
| 67 Running, | |
| 68 Paused, | |
| 69 Finished | |
| 70 }; | |
| 71 | |
| 72 ~AnimationPlayer(); | |
| 73 static PassRefPtrWillBeRawPtr<AnimationPlayer> create(AnimationNode*, Animat
ionTimeline*); | |
| 74 | |
| 75 // Returns whether the player is finished. | |
| 76 bool update(TimingUpdateReason); | |
| 77 | |
| 78 // timeToEffectChange returns: | |
| 79 // infinity - if this player is no longer in effect | |
| 80 // 0 - if this player requires an update on the next frame | |
| 81 // n - if this player requires an update after 'n' units of time | |
| 82 double timeToEffectChange(); | |
| 83 | |
| 84 void cancel(); | |
| 85 | |
| 86 double currentTime(bool& isNull); | |
| 87 double currentTime(); | |
| 88 void setCurrentTime(double newCurrentTime); | |
| 89 | |
| 90 double currentTimeInternal() const; | |
| 91 double unlimitedCurrentTimeInternal() const; | |
| 92 | |
| 93 void setCurrentTimeInternal(double newCurrentTime, TimingUpdateReason = Timi
ngUpdateOnDemand); | |
| 94 bool paused() const { return m_paused && !m_isPausedForTesting; } | |
| 95 static const char* playStateString(AnimationPlayState); | |
| 96 String playState() const { return playStateString(playStateInternal()); } | |
| 97 AnimationPlayState playStateInternal() const; | |
| 98 | |
| 99 void pause(); | |
| 100 void play(); | |
| 101 void reverse(); | |
| 102 void finish(ExceptionState&); | |
| 103 | |
| 104 ScriptPromise finished(ScriptState*); | |
| 105 ScriptPromise ready(ScriptState*); | |
| 106 | |
| 107 bool playing() const { return !(playStateInternal() == Idle || limited() ||
m_paused || m_isPausedForTesting); } | |
| 108 bool limited() const { return limited(currentTimeInternal()); } | |
| 109 bool finishedInternal() const { return m_finished; } | |
| 110 | |
| 111 DEFINE_ATTRIBUTE_EVENT_LISTENER(finish); | |
| 112 | |
| 113 virtual const AtomicString& interfaceName() const override; | |
| 114 virtual ExecutionContext* executionContext() const override; | |
| 115 virtual bool hasPendingActivity() const override; | |
| 116 virtual void stop() override; | |
| 117 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>) override; | |
| 118 | |
| 119 double playbackRate() const; | |
| 120 void setPlaybackRate(double); | |
| 121 const AnimationTimeline* timeline() const { return m_timeline; } | |
| 122 AnimationTimeline* timeline() { return m_timeline; } | |
| 123 | |
| 124 #if !ENABLE(OILPAN) | |
| 125 void detachFromTimeline(); | |
| 126 #endif | |
| 127 | |
| 128 double calculateStartTime(double currentTime) const; | |
| 129 bool hasStartTime() const { return !isNull(m_startTime); } | |
| 130 double startTime(bool& isNull) const; | |
| 131 double startTime() const; | |
| 132 double startTimeInternal() const { return m_startTime; } | |
| 133 void setStartTime(double); | |
| 134 void setStartTimeInternal(double); | |
| 135 | |
| 136 const AnimationNode* source() const { return m_content.get(); } | |
| 137 AnimationNode* source() { return m_content.get(); } | |
| 138 void setSource(AnimationNode*); | |
| 139 | |
| 140 // Pausing via this method is not reflected in the value returned by | |
| 141 // paused() and must never overlap with pausing via pause(). | |
| 142 void pauseForTesting(double pauseTime); | |
| 143 // This should only be used for CSS | |
| 144 void unpause(); | |
| 145 | |
| 146 void setOutdated(); | |
| 147 bool outdated() { return m_outdated; } | |
| 148 | |
| 149 bool canStartAnimationOnCompositor() const; | |
| 150 bool isCandidateForAnimationOnCompositor() const; | |
| 151 bool maybeStartAnimationOnCompositor(); | |
| 152 void cancelAnimationOnCompositor(); | |
| 153 void restartAnimationOnCompositor(); | |
| 154 void cancelIncompatibleAnimationsOnCompositor(); | |
| 155 bool hasActiveAnimationsOnCompositor(); | |
| 156 void setCompositorPending(bool sourceChanged = false); | |
| 157 void notifyCompositorStartTime(double timelineTime); | |
| 158 void notifyStartTime(double timelineTime); | |
| 159 // WebCompositorAnimationPlayerClient implementation. | |
| 160 WebCompositorAnimationPlayer* compositorPlayer() const override { return m_c
ompositorPlayer.get(); } | |
| 161 | |
| 162 bool affects(const Element&, CSSPropertyID) const; | |
| 163 | |
| 164 void preCommit(int compositorGroup, bool startOnCompositor); | |
| 165 void postCommit(double timelineTime); | |
| 166 | |
| 167 unsigned sequenceNumber() const { return m_sequenceNumber; } | |
| 168 int compositorGroup() const { return m_compositorGroup; } | |
| 169 | |
| 170 static bool hasLowerPriority(const AnimationPlayer* player1, const Animation
Player* player2) | |
| 171 { | |
| 172 return player1->sequenceNumber() < player2->sequenceNumber(); | |
| 173 } | |
| 174 | |
| 175 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<Even
tListener>, bool useCapture = false) override; | |
| 176 | |
| 177 DECLARE_VIRTUAL_TRACE(); | |
| 178 | |
| 179 private: | |
| 180 AnimationPlayer(ExecutionContext*, AnimationTimeline&, AnimationNode*); | |
| 181 | |
| 182 double sourceEnd() const; | |
| 183 bool limited(double currentTime) const; | |
| 184 | |
| 185 AnimationPlayState calculatePlayState(); | |
| 186 double calculateCurrentTime() const; | |
| 187 | |
| 188 void unpauseInternal(); | |
| 189 void setPlaybackRateInternal(double); | |
| 190 void updateCurrentTimingState(TimingUpdateReason); | |
| 191 | |
| 192 void beginUpdatingState(); | |
| 193 void endUpdatingState(); | |
| 194 | |
| 195 void createCompositorPlayer(); | |
| 196 void destroyCompositorPlayer(); | |
| 197 void attachCompositorTimeline(); | |
| 198 void detachCompositorTimeline(); | |
| 199 void attachCompositedLayers(); | |
| 200 void detachCompositedLayers(); | |
| 201 // WebCompositorAnimationDelegate implementation. | |
| 202 void notifyAnimationStarted(double monotonicTime, int group) override; | |
| 203 void notifyAnimationFinished(double monotonicTime, int group) override { } | |
| 204 | |
| 205 AnimationPlayState m_playState; | |
| 206 double m_playbackRate; | |
| 207 double m_startTime; | |
| 208 double m_holdTime; | |
| 209 | |
| 210 unsigned m_sequenceNumber; | |
| 211 | |
| 212 typedef ScriptPromiseProperty<RawPtrWillBeMember<AnimationPlayer>, RawPtrWil
lBeMember<AnimationPlayer>, Member<DOMException>> AnimationPlayerPromise; | |
| 213 PersistentWillBeMember<AnimationPlayerPromise> m_finishedPromise; | |
| 214 PersistentWillBeMember<AnimationPlayerPromise> m_readyPromise; | |
| 215 | |
| 216 RefPtrWillBeMember<AnimationNode> m_content; | |
| 217 RawPtrWillBeMember<AnimationTimeline> m_timeline; | |
| 218 // Reflects all pausing, including via pauseForTesting(). | |
| 219 bool m_paused; | |
| 220 bool m_held; | |
| 221 bool m_isPausedForTesting; | |
| 222 | |
| 223 // This indicates timing information relevant to the player's effect | |
| 224 // has changed by means other than the ordinary progression of time | |
| 225 bool m_outdated; | |
| 226 | |
| 227 bool m_finished; | |
| 228 // Holds a 'finished' event queued for asynchronous dispatch via the | |
| 229 // ScriptedAnimationController. This object remains active until the | |
| 230 // event is actually dispatched. | |
| 231 RefPtrWillBeMember<Event> m_pendingFinishedEvent; | |
| 232 | |
| 233 enum CompositorAction { | |
| 234 None, | |
| 235 Pause, | |
| 236 Start, | |
| 237 PauseThenStart | |
| 238 }; | |
| 239 | |
| 240 class CompositorState { | |
| 241 public: | |
| 242 CompositorState(AnimationPlayer& player) | |
| 243 : startTime(player.m_startTime) | |
| 244 , holdTime(player.m_holdTime) | |
| 245 , playbackRate(player.m_playbackRate) | |
| 246 , sourceChanged(false) | |
| 247 , pendingAction(Start) | |
| 248 { } | |
| 249 double startTime; | |
| 250 double holdTime; | |
| 251 double playbackRate; | |
| 252 bool sourceChanged; | |
| 253 CompositorAction pendingAction; | |
| 254 }; | |
| 255 | |
| 256 enum CompositorPendingChange { | |
| 257 SetCompositorPending, | |
| 258 SetCompositorPendingWithSourceChanged, | |
| 259 DoNotSetCompositorPending, | |
| 260 }; | |
| 261 | |
| 262 class PlayStateUpdateScope { | |
| 263 STACK_ALLOCATED(); | |
| 264 public: | |
| 265 PlayStateUpdateScope(AnimationPlayer&, TimingUpdateReason, CompositorPen
dingChange = SetCompositorPending); | |
| 266 ~PlayStateUpdateScope(); | |
| 267 private: | |
| 268 RawPtrWillBeMember<AnimationPlayer> m_player; | |
| 269 AnimationPlayState m_initialPlayState; | |
| 270 CompositorPendingChange m_compositorPendingChange; | |
| 271 }; | |
| 272 | |
| 273 // This mirrors the known compositor state. It is created when a compositor | |
| 274 // animation is started. Updated once the start time is known and each time | |
| 275 // modifications are pushed to the compositor. | |
| 276 OwnPtr<CompositorState> m_compositorState; | |
| 277 bool m_compositorPending; | |
| 278 int m_compositorGroup; | |
| 279 | |
| 280 OwnPtr<WebCompositorAnimationPlayer> m_compositorPlayer; | |
| 281 | |
| 282 bool m_currentTimePending; | |
| 283 bool m_stateIsBeingUpdated; | |
| 284 }; | |
| 285 | |
| 286 } // namespace blink | |
| 287 | |
| 288 #endif // AnimationPlayer_h | |
| OLD | NEW |