зеркало из https://github.com/mozilla/pjs.git
merge
This commit is contained in:
Коммит
1dd50deefa
|
@ -1360,7 +1360,7 @@ protected:
|
||||||
|
|
||||||
#ifdef MOZ_SMIL
|
#ifdef MOZ_SMIL
|
||||||
// SMIL Animation Controller, lazily-initialized in GetAnimationController
|
// SMIL Animation Controller, lazily-initialized in GetAnimationController
|
||||||
nsRefPtr<nsSMILAnimationController> mAnimationController;
|
nsAutoPtr<nsSMILAnimationController> mAnimationController;
|
||||||
#endif // MOZ_SMIL
|
#endif // MOZ_SMIL
|
||||||
|
|
||||||
// Table of element properties for this document.
|
// Table of element properties for this document.
|
||||||
|
|
|
@ -51,14 +51,16 @@
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// nsSMILAnimationController implementation
|
// nsSMILAnimationController implementation
|
||||||
|
|
||||||
// Helper method
|
// In my testing the minimum needed for smooth animation is 36 frames per
|
||||||
static nsPresContext*
|
// second which seems like a lot (Flash traditionally uses 14fps).
|
||||||
GetPresContextForDoc(nsIDocument* aDoc)
|
//
|
||||||
{
|
// Redrawing is synchronous. This is deliberate so that later we can tune the
|
||||||
nsIPresShell* shell = aDoc->GetPrimaryShell();
|
// timer based on how long the callback takes. To achieve 36fps we'd need 28ms
|
||||||
return shell ? shell->GetPresContext() : nsnull;
|
// between frames. For now we set the timer interval to be a little less than
|
||||||
}
|
// this (to allow for the render itself) and then let performance decay as the
|
||||||
|
// image gets more complicated and render times increase.
|
||||||
|
//
|
||||||
|
const PRUint32 nsSMILAnimationController::kTimerInterval = 22;
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// ctors, dtors, factory methods
|
// ctors, dtors, factory methods
|
||||||
|
@ -73,7 +75,11 @@ nsSMILAnimationController::nsSMILAnimationController()
|
||||||
|
|
||||||
nsSMILAnimationController::~nsSMILAnimationController()
|
nsSMILAnimationController::~nsSMILAnimationController()
|
||||||
{
|
{
|
||||||
StopTimer();
|
if (mTimer) {
|
||||||
|
mTimer->Cancel();
|
||||||
|
mTimer = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
NS_ASSERTION(mAnimationElementTable.Count() == 0,
|
NS_ASSERTION(mAnimationElementTable.Count() == 0,
|
||||||
"Animation controller shouldn't be tracking any animation"
|
"Animation controller shouldn't be tracking any animation"
|
||||||
" elements when it dies");
|
" elements when it dies");
|
||||||
|
@ -99,6 +105,9 @@ nsSMILAnimationController::Init(nsIDocument* aDoc)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(aDoc);
|
NS_ENSURE_ARG_POINTER(aDoc);
|
||||||
|
|
||||||
|
mTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||||
|
NS_ENSURE_TRUE(mTimer, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
// Keep track of document, so we can traverse its set of animation elements
|
// Keep track of document, so we can traverse its set of animation elements
|
||||||
mDocument = aDoc;
|
mDocument = aDoc;
|
||||||
|
|
||||||
|
@ -139,20 +148,6 @@ nsSMILAnimationController::GetParentTime() const
|
||||||
return PR_Now() / PR_USEC_PER_MSEC;
|
return PR_Now() / PR_USEC_PER_MSEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
// nsARefreshObserver methods:
|
|
||||||
NS_IMPL_ADDREF(nsSMILAnimationController)
|
|
||||||
NS_IMPL_RELEASE(nsSMILAnimationController)
|
|
||||||
|
|
||||||
void
|
|
||||||
nsSMILAnimationController::WillRefresh(mozilla::TimeStamp aTime)
|
|
||||||
{
|
|
||||||
// XXXdholbert Eventually we should be sampling based on aTime. For now,
|
|
||||||
// though, we keep track of the time on our own, and we just use
|
|
||||||
// nsRefreshDriver for scheduling samples.
|
|
||||||
Sample();
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Animation element registration methods:
|
// Animation element registration methods:
|
||||||
|
|
||||||
|
@ -219,38 +214,42 @@ nsSMILAnimationController::Unlink()
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Timer-related implementation helpers
|
// Timer-related implementation helpers
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
nsSMILAnimationController::Notify(nsITimer* timer, void* aClosure)
|
||||||
|
{
|
||||||
|
nsSMILAnimationController* controller = (nsSMILAnimationController*)aClosure;
|
||||||
|
|
||||||
|
NS_ASSERTION(controller->mTimer == timer,
|
||||||
|
"nsSMILAnimationController::Notify called with incorrect timer");
|
||||||
|
|
||||||
|
controller->Sample();
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsSMILAnimationController::StartTimer()
|
nsSMILAnimationController::StartTimer()
|
||||||
{
|
{
|
||||||
|
NS_ENSURE_TRUE(mTimer, NS_ERROR_FAILURE);
|
||||||
NS_ASSERTION(mPauseState == 0, "Starting timer but controller is paused");
|
NS_ASSERTION(mPauseState == 0, "Starting timer but controller is paused");
|
||||||
|
|
||||||
// Run the first sample manually
|
// Run the first sample manually
|
||||||
Sample();
|
Sample();
|
||||||
|
|
||||||
// Register with PresContext's refresh driver for future samples
|
//
|
||||||
nsPresContext* presContext = GetPresContextForDoc(mDocument);
|
// XXX Make this self-tuning. Sounds like control theory to me and not
|
||||||
if (!presContext) {
|
// something I'm familiar with.
|
||||||
NS_WARNING("Starting timer but have no pres context");
|
//
|
||||||
return NS_ERROR_FAILURE;
|
return mTimer->InitWithFuncCallback(nsSMILAnimationController::Notify,
|
||||||
}
|
this,
|
||||||
|
kTimerInterval,
|
||||||
nsRefreshDriver* rd = presContext->RefreshDriver();
|
nsITimer::TYPE_REPEATING_SLACK);
|
||||||
return rd->AddRefreshObserver(this, Flush_Style) ?
|
|
||||||
NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsSMILAnimationController::StopTimer()
|
nsSMILAnimationController::StopTimer()
|
||||||
{
|
{
|
||||||
nsPresContext* presContext = GetPresContextForDoc(mDocument);
|
NS_ENSURE_TRUE(mTimer, NS_ERROR_FAILURE);
|
||||||
if (!presContext) {
|
|
||||||
NS_WARNING("Stopping timer but have no pres context");
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
nsRefreshDriver* rd = presContext->RefreshDriver();
|
|
||||||
rd->RemoveRefreshObserver(this, Flush_Style); // may fail, if already stopped
|
|
||||||
|
|
||||||
return NS_OK;
|
return mTimer->Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
#include "nsSMILTimeContainer.h"
|
#include "nsSMILTimeContainer.h"
|
||||||
#include "nsSMILCompositorTable.h"
|
#include "nsSMILCompositorTable.h"
|
||||||
#include "nsSMILMilestone.h"
|
#include "nsSMILMilestone.h"
|
||||||
#include "nsRefreshDriver.h"
|
|
||||||
|
|
||||||
struct nsSMILTargetIdentifier;
|
struct nsSMILTargetIdentifier;
|
||||||
class nsISMILAnimationElement;
|
class nsISMILAnimationElement;
|
||||||
|
@ -67,8 +66,7 @@ class nsIDocument;
|
||||||
// a compound document. These time containers can be paused individually or
|
// a compound document. These time containers can be paused individually or
|
||||||
// here, at the document level.
|
// here, at the document level.
|
||||||
//
|
//
|
||||||
class nsSMILAnimationController : public nsSMILTimeContainer,
|
class nsSMILAnimationController : public nsSMILTimeContainer
|
||||||
public nsARefreshObserver
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsSMILAnimationController();
|
nsSMILAnimationController();
|
||||||
|
@ -79,12 +77,6 @@ public:
|
||||||
virtual void Resume(PRUint32 aType);
|
virtual void Resume(PRUint32 aType);
|
||||||
virtual nsSMILTime GetParentTime() const;
|
virtual nsSMILTime GetParentTime() const;
|
||||||
|
|
||||||
// nsARefreshObserver
|
|
||||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
||||||
NS_IMETHOD_(nsrefcnt) Release();
|
|
||||||
|
|
||||||
virtual void WillRefresh(mozilla::TimeStamp aTime);
|
|
||||||
|
|
||||||
// Methods for registering and enumerating animation elements
|
// Methods for registering and enumerating animation elements
|
||||||
void RegisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
|
void RegisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
|
||||||
void UnregisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
|
void UnregisterAnimationElement(nsISMILAnimationElement* aAnimationElement);
|
||||||
|
@ -173,10 +165,8 @@ protected:
|
||||||
virtual void RemoveChild(nsSMILTimeContainer& aChild);
|
virtual void RemoveChild(nsSMILTimeContainer& aChild);
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
nsAutoRefCnt mRefCnt;
|
|
||||||
NS_DECL_OWNINGTHREAD
|
|
||||||
|
|
||||||
static const PRUint32 kTimerInterval;
|
static const PRUint32 kTimerInterval;
|
||||||
|
nsCOMPtr<nsITimer> mTimer;
|
||||||
AnimationElementHashtable mAnimationElementTable;
|
AnimationElementHashtable mAnimationElementTable;
|
||||||
TimeContainerHashtable mChildContainerTable;
|
TimeContainerHashtable mChildContainerTable;
|
||||||
PRPackedBool mResampleNeeded;
|
PRPackedBool mResampleNeeded;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче