2009-01-15 04:38:07 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
#ifndef NS_SMILANIMATIONCONTROLLER_H_
|
|
|
|
#define NS_SMILANIMATIONCONTROLLER_H_
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsSMILTimeContainer.h"
|
|
|
|
#include "nsSMILCompositorTable.h"
|
2010-01-12 20:00:49 +00:00
|
|
|
#include "nsSMILMilestone.h"
|
2010-03-19 04:14:40 +00:00
|
|
|
#include "nsRefreshDriver.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-02-20 21:13:11 +00:00
|
|
|
struct nsSMILTargetIdentifier;
|
2009-01-15 04:38:07 +00:00
|
|
|
class nsIDocument;
|
|
|
|
|
2013-03-19 03:18:45 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class SVGAnimationElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSMILAnimationController
|
2009-07-15 18:33:31 +00:00
|
|
|
//
|
2009-01-15 04:38:07 +00:00
|
|
|
// The animation controller maintains the animation timer and determines the
|
|
|
|
// sample times and sample rate for all SMIL animations in a document. There is
|
|
|
|
// at most one animation controller per nsDocument so that frame-rate tuning can
|
|
|
|
// be performed at a document-level.
|
|
|
|
//
|
|
|
|
// The animation controller can contain many child time containers (timed
|
|
|
|
// document root objects) which may correspond to SVG document fragments within
|
|
|
|
// a compound document. These time containers can be paused individually or
|
|
|
|
// here, at the document level.
|
|
|
|
//
|
2014-08-27 18:26:48 +00:00
|
|
|
class nsSMILAnimationController MOZ_FINAL : public nsSMILTimeContainer,
|
|
|
|
public nsARefreshObserver
|
2009-01-15 04:38:07 +00:00
|
|
|
{
|
2010-09-18 03:46:48 +00:00
|
|
|
public:
|
2014-08-08 13:49:39 +00:00
|
|
|
explicit nsSMILAnimationController(nsIDocument* aDoc);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-04-28 19:02:20 +00:00
|
|
|
// Clears mDocument pointer. (Called by our nsIDocument when it's going away)
|
|
|
|
void Disconnect();
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
// nsSMILContainer
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual void Pause(uint32_t aType) MOZ_OVERRIDE;
|
|
|
|
virtual void Resume(uint32_t aType) MOZ_OVERRIDE;
|
|
|
|
virtual nsSMILTime GetParentTime() const MOZ_OVERRIDE;
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2010-03-19 04:14:40 +00:00
|
|
|
// nsARefreshObserver
|
2014-03-27 20:38:33 +00:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
|
2010-03-19 04:14:40 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;
|
2010-03-19 04:14:40 +00:00
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
// Methods for registering and enumerating animation elements
|
2013-03-19 03:18:45 +00:00
|
|
|
void RegisterAnimationElement(mozilla::dom::SVGAnimationElement* aAnimationElement);
|
|
|
|
void UnregisterAnimationElement(mozilla::dom::SVGAnimationElement* aAnimationElement);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2009-01-22 01:00:27 +00:00
|
|
|
// Methods for resampling all animations
|
|
|
|
// (A resample performs the same operations as a sample but doesn't advance
|
|
|
|
// the current time and doesn't check if the container is paused)
|
2012-03-20 18:02:38 +00:00
|
|
|
// This will flush pending style changes for the document.
|
2011-10-17 14:59:28 +00:00
|
|
|
void Resample() { DoSample(false); }
|
2011-12-15 04:42:15 +00:00
|
|
|
|
2010-11-09 23:21:03 +00:00
|
|
|
void SetResampleNeeded()
|
|
|
|
{
|
|
|
|
if (!mRunningSample) {
|
2011-12-15 04:42:15 +00:00
|
|
|
if (!mResampleNeeded) {
|
|
|
|
FlagDocumentNeedsFlush();
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mResampleNeeded = true;
|
2010-11-09 23:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-20 18:02:38 +00:00
|
|
|
|
|
|
|
// This will flush pending style changes for the document.
|
2009-01-22 01:00:27 +00:00
|
|
|
void FlushResampleRequests()
|
|
|
|
{
|
|
|
|
if (!mResampleNeeded)
|
|
|
|
return;
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
Resample();
|
2009-01-22 01:00:27 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
// Methods for handling page transitions
|
2009-01-22 01:00:27 +00:00
|
|
|
void OnPageShow();
|
|
|
|
void OnPageHide();
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
// Methods for supporting cycle-collection
|
2009-01-22 01:00:27 +00:00
|
|
|
void Traverse(nsCycleCollectionTraversalCallback* aCallback);
|
|
|
|
void Unlink();
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2010-10-19 23:53:52 +00:00
|
|
|
// Methods for relaying the availability of the refresh driver
|
|
|
|
void NotifyRefreshDriverCreated(nsRefreshDriver* aRefreshDriver);
|
|
|
|
void NotifyRefreshDriverDestroying(nsRefreshDriver* aRefreshDriver);
|
2010-03-19 04:14:40 +00:00
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
// Helper to check if we have any animation elements at all
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HasRegisteredAnimations()
|
2010-09-08 20:40:39 +00:00
|
|
|
{ return mAnimationElementTable.Count() != 0; }
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
protected:
|
2014-06-23 19:56:07 +00:00
|
|
|
~nsSMILAnimationController();
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
// Typedefs
|
|
|
|
typedef nsPtrHashKey<nsSMILTimeContainer> TimeContainerPtrKey;
|
|
|
|
typedef nsTHashtable<TimeContainerPtrKey> TimeContainerHashtable;
|
2013-03-19 03:18:45 +00:00
|
|
|
typedef nsPtrHashKey<mozilla::dom::SVGAnimationElement> AnimationElementPtrKey;
|
2009-01-15 04:38:07 +00:00
|
|
|
typedef nsTHashtable<AnimationElementPtrKey> AnimationElementHashtable;
|
|
|
|
|
2009-01-22 01:00:27 +00:00
|
|
|
struct SampleTimeContainerParams
|
|
|
|
{
|
|
|
|
TimeContainerHashtable* mActiveContainers;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mSkipUnchangedContainers;
|
2009-01-15 04:38:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SampleAnimationParams
|
|
|
|
{
|
|
|
|
TimeContainerHashtable* mActiveContainers;
|
|
|
|
nsSMILCompositorTable* mCompositorTable;
|
|
|
|
};
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
struct GetMilestoneElementsParams
|
|
|
|
{
|
2013-03-19 03:18:45 +00:00
|
|
|
nsTArray<nsRefPtr<mozilla::dom::SVGAnimationElement> > mElements;
|
|
|
|
nsSMILMilestone mMilestone;
|
2010-01-12 20:00:49 +00:00
|
|
|
};
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
// Cycle-collection implementation helpers
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator CompositorTableEntryTraverse(
|
2009-01-15 04:38:07 +00:00
|
|
|
nsSMILCompositor* aCompositor, void* aArg);
|
|
|
|
|
2011-04-28 19:05:24 +00:00
|
|
|
// Returns mDocument's refresh driver, if it's got one.
|
|
|
|
nsRefreshDriver* GetRefreshDriver();
|
|
|
|
|
2010-10-19 23:53:52 +00:00
|
|
|
// Methods for controlling whether we're sampling
|
|
|
|
void StartSampling(nsRefreshDriver* aRefreshDriver);
|
|
|
|
void StopSampling(nsRefreshDriver* aRefreshDriver);
|
|
|
|
|
2011-04-01 20:33:20 +00:00
|
|
|
// Wrapper for StartSampling that defers if no animations are registered.
|
|
|
|
void MaybeStartSampling(nsRefreshDriver* aRefreshDriver);
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
// Sample-related callbacks and implementation helpers
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual void DoSample() MOZ_OVERRIDE;
|
2011-09-29 06:19:26 +00:00
|
|
|
void DoSample(bool aSkipUnchangedContainers);
|
2010-07-03 05:52:51 +00:00
|
|
|
|
|
|
|
void RewindElements();
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator RewindNeeded(
|
2010-07-03 05:52:51 +00:00
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator RewindAnimation(
|
2010-07-03 05:52:51 +00:00
|
|
|
AnimationElementPtrKey* aKey, void* aData);
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator ClearRewindNeeded(
|
2010-07-03 05:52:51 +00:00
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
|
|
|
|
2010-01-12 20:00:49 +00:00
|
|
|
void DoMilestoneSamples();
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator GetNextMilestone(
|
2010-01-12 20:00:49 +00:00
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator GetMilestoneElements(
|
2010-01-12 20:00:49 +00:00
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
2010-07-03 05:52:51 +00:00
|
|
|
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator SampleTimeContainer(
|
2009-01-15 04:38:07 +00:00
|
|
|
TimeContainerPtrKey* aKey, void* aData);
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator SampleAnimation(
|
2009-01-15 04:38:07 +00:00
|
|
|
AnimationElementPtrKey* aKey, void* aData);
|
2013-03-19 03:18:45 +00:00
|
|
|
static void SampleTimedElement(mozilla::dom::SVGAnimationElement* aElement,
|
2009-01-15 04:38:07 +00:00
|
|
|
TimeContainerHashtable* aActiveContainers);
|
|
|
|
static void AddAnimationToCompositorTable(
|
2013-03-19 03:18:45 +00:00
|
|
|
mozilla::dom::SVGAnimationElement* aElement, nsSMILCompositorTable* aCompositorTable);
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool GetTargetIdentifierForAnimation(
|
2013-03-19 03:18:45 +00:00
|
|
|
mozilla::dom::SVGAnimationElement* aAnimElem, nsSMILTargetIdentifier& aResult);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
|
|
|
// Methods for adding/removing time containers
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual nsresult AddChild(nsSMILTimeContainer& aChild) MOZ_OVERRIDE;
|
|
|
|
virtual void RemoveChild(nsSMILTimeContainer& aChild) MOZ_OVERRIDE;
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-12-15 04:42:15 +00:00
|
|
|
void FlagDocumentNeedsFlush();
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
// Members
|
2010-03-19 04:14:40 +00:00
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
AnimationElementHashtable mAnimationElementTable;
|
|
|
|
TimeContainerHashtable mChildContainerTable;
|
2010-09-18 03:46:48 +00:00
|
|
|
mozilla::TimeStamp mCurrentSampleTime;
|
|
|
|
mozilla::TimeStamp mStartTime;
|
2010-11-23 23:31:17 +00:00
|
|
|
|
|
|
|
// Average time between samples from the refresh driver. This is used to
|
|
|
|
// detect large unexpected gaps between samples such as can occur when the
|
|
|
|
// computer sleeps. The nature of the SMIL model means that catching up these
|
|
|
|
// large gaps can be expensive as, for example, many events may need to be
|
|
|
|
// dispatched for the intervening time when no samples were received.
|
|
|
|
//
|
|
|
|
// In such cases, we ignore the intervening gap and continue sampling from
|
|
|
|
// when we were expecting the next sample to arrive.
|
|
|
|
//
|
|
|
|
// Note that we only do this for SMIL and not CSS transitions (which doesn't
|
|
|
|
// have so much work to do to catch up) nor scripted animations (which expect
|
|
|
|
// animation time to follow real time).
|
|
|
|
//
|
|
|
|
// This behaviour does not affect pausing (since we're not *expecting* any
|
|
|
|
// samples then) nor seeking (where the SMIL model behaves somewhat
|
|
|
|
// differently such as not dispatching events).
|
|
|
|
nsSMILTime mAvgTimeBetweenSamples;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mResampleNeeded;
|
2010-10-19 23:52:49 +00:00
|
|
|
// If we're told to start sampling but there are no animation elements we just
|
|
|
|
// record the time, set the following flag, and then wait until we have an
|
|
|
|
// animation element. Then we'll reset this flag and actually start sampling.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDeferredStartSampling;
|
|
|
|
bool mRunningSample;
|
2009-07-15 18:33:31 +00:00
|
|
|
|
2014-05-20 12:34:26 +00:00
|
|
|
// Are we registered with our document's refresh driver?
|
|
|
|
bool mRegisteredWithRefreshDriver;
|
|
|
|
|
2009-01-15 04:38:07 +00:00
|
|
|
// Store raw ptr to mDocument. It owns the controller, so controller
|
|
|
|
// shouldn't outlive it
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
|
|
|
|
// Contains compositors used in our last sample. We keep this around
|
|
|
|
// so we can detect when an element/attribute used to be animated,
|
2009-07-15 18:33:31 +00:00
|
|
|
// but isn't anymore for some reason. (e.g. if its <animate> element is
|
2009-01-15 04:38:07 +00:00
|
|
|
// removed or retargeted)
|
|
|
|
nsAutoPtr<nsSMILCompositorTable> mLastCompositorTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NS_SMILANIMATIONCONTROLLER_H_
|