gecko-dev/dom/animation/AnimationPlayer.h

90 строки
2.6 KiB
C
Исходник Обычный вид История

/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_AnimationPlayer_h
#define mozilla_dom_AnimationPlayer_h
#include <algorithm> // for std::max
#include "nsWrapperCache.h"
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Attributes.h"
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
#include "mozilla/dom/Animation.h" // for Animation
#include "mozilla/dom/AnimationTimeline.h" // for AnimationTimeline
#include "nsCSSProperty.h" // for nsCSSProperty
// X11 has a #define for CurrentTime.
#ifdef CurrentTime
#undef CurrentTime
#endif
struct JSContext;
namespace mozilla {
namespace dom {
class AnimationPlayer MOZ_FINAL : public nsWrapperCache
{
protected:
virtual ~AnimationPlayer() { }
public:
explicit AnimationPlayer(AnimationTimeline* aTimeline)
Bug 1052147 - Initialize AnimationPlayer::mPlayState to running state; r=dbaron The assertion in nsTimeStamp::operator >= occasionally fails due to a null RHS timestamp when called from AnimationPlayer::GetCurrentTimeDuration, which, in turn, is called from AnimationPlayer::SetSource. The issue appears to be that we're not correctly initializing AnimationPlayer.mPlayState. This value can be running (0) or paused (1) but we only ever compare against the paused state (i.e. every other value is effectively treated as running). If we don't initialize this we can end up in the paused state but with mPauseStart not set to a valid (non-null) TimeStamp. This creates an inconsistent state since we assume that when we're paused mPauseStart is non-null, hence the assertion fails. This gets tickled because, since bug 1040543, we call AnimationPlayer::SetSource from nsAnimationManager::BuildAnimations *before* we set mPlayState and mPauseStart. This patch initializes mPlayState to the running state so we don't accidentally end up in an inconsistent state. It also removes some (now unnecessary) initialization of mPlayState and mPauseStart from nsTransitionManager::ConsiderStartingTransition. In future we could also consider reworking nsAnimationManager::BuildAnimations so that we call SetSource on the new animation player *after* setting up its play state. That may be more correct and would further avoid this problem but may not be necessary since all that code is likely to change in the near future.
2014-08-13 13:21:45 +04:00
: mPlayState(NS_STYLE_ANIMATION_PLAY_STATE_RUNNING)
, mIsRunningOnCompositor(false)
, mTimeline(aTimeline)
{
SetIsDOMBinding();
}
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationPlayer)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AnimationPlayer)
AnimationTimeline* GetParentObject() const { return mTimeline; }
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
// AnimationPlayer methods
Animation* GetSource() const { return mSource; }
AnimationTimeline* Timeline() const { return mTimeline; }
Nullable<double> GetStartTime() const;
Nullable<double> GetCurrentTime() const;
bool IsRunningOnCompositor() const { return mIsRunningOnCompositor; }
void SetSource(Animation* aSource);
void Tick();
const nsString& Name() const {
return mSource ? mSource->Name() : EmptyString();
}
bool IsPaused() const {
return mPlayState == NS_STYLE_ANIMATION_PLAY_STATE_PAUSED;
}
bool IsRunning() const;
bool HasCurrentSource() const {
return GetSource() && GetSource()->IsCurrent();
}
// Return the duration since the start time of the player, taking into
// account the pause state. May be negative or null.
Nullable<TimeDuration> GetCurrentTimeDuration() const;
// The beginning of the delay period.
Nullable<TimeDuration> mStartTime;
Nullable<TimeDuration> mHoldTime;
uint8_t mPlayState;
bool mIsRunningOnCompositor;
nsRefPtr<AnimationTimeline> mTimeline;
nsRefPtr<Animation> mSource;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_AnimationPlayer_h