Bug 1101974. Part 2: Access VsyncDispatcher through nsIWidget interface. r=benwa

This commit is contained in:
Mason Chang 2014-12-18 08:30:06 -08:00
parent 5780d4d046
commit 511631c675
2 changed files with 31 additions and 25 deletions

View File

@ -196,23 +196,30 @@ static void SetThreadPriority()
hal::SetCurrentThreadPriority(hal::THREAD_PRIORITY_COMPOSITOR);
}
CompositorVsyncObserver::CompositorVsyncObserver(CompositorParent* aCompositorParent)
CompositorVsyncObserver::CompositorVsyncObserver(CompositorParent* aCompositorParent, nsIWidget* aWidget)
: mNeedsComposite(false)
, mIsObservingVsync(false)
, mCompositorParent(aCompositorParent)
, mCurrentCompositeTaskMonitor("CurrentCompositeTaskMonitor")
, mCurrentCompositeTask(nullptr)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aWidget != nullptr);
mVsyncDispatcher = aWidget->GetVsyncDispatcher();
#ifdef MOZ_WIDGET_GONK
GeckoTouchDispatcher::SetCompositorVsyncObserver(this);
#endif
}
CompositorVsyncObserver::~CompositorVsyncObserver()
{
MOZ_ASSERT(NS_IsMainThread());
UnobserveVsync();
mCompositorParent = nullptr;
mNeedsComposite = false;
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
MOZ_ASSERT(!mIsObservingVsync);
// The VsyncDispatcher is cleaned up before this in the nsBaseWidget, which stops vsync listeners
CancelCurrentCompositeTask();
mCompositorParent = nullptr;
mVsyncDispatcher = nullptr;
mNeedsComposite = false;
}
/**
@ -225,9 +232,14 @@ CompositorVsyncObserver::~CompositorVsyncObserver()
void
CompositorVsyncObserver::SetNeedsComposite(bool aNeedsComposite)
{
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
mNeedsComposite = aNeedsComposite;
if (aNeedsComposite && !CompositorParent::IsInCompositorThread()) {
CompositorParent::CompositorLoop()->PostTask(FROM_HERE,
NewRunnableMethod(this,
&CompositorVsyncObserver::SetNeedsComposite,
aNeedsComposite));
}
mNeedsComposite = aNeedsComposite;
if (!mIsObservingVsync && mNeedsComposite) {
ObserveVsync();
}
@ -273,10 +285,6 @@ CompositorVsyncObserver::Composite(TimeStamp aVsyncTimestamp)
if (mNeedsComposite && mCompositorParent) {
mNeedsComposite = false;
mCompositorParent->CompositeCallback(aVsyncTimestamp);
} else {
// We're getting vsync notifications but we don't need to composite so
// unregister the vsync.
UnobserveVsync();
}
DispatchTouchEvents(aVsyncTimestamp);
@ -289,15 +297,11 @@ CompositorVsyncObserver::NeedsComposite()
return mNeedsComposite;
}
/**
* Since the vsync thread has its own locks before notifying us of vsync
* we can't register/unregister from the vsync thread. Any other thread is fine
*/
void
CompositorVsyncObserver::ObserveVsync()
{
MOZ_ASSERT(CompositorParent::IsInCompositorThread());
VsyncDispatcher::GetInstance()->AddCompositorVsyncObserver(this);
mVsyncDispatcher->SetCompositorVsyncObserver(this);
mIsObservingVsync = true;
}
@ -305,7 +309,7 @@ void
CompositorVsyncObserver::UnobserveVsync()
{
MOZ_ASSERT(CompositorParent::IsInCompositorThread() || NS_IsMainThread());
VsyncDispatcher::GetInstance()->RemoveCompositorVsyncObserver(this);
mVsyncDispatcher->SetCompositorVsyncObserver(nullptr);
mIsObservingVsync = false;
}
@ -313,9 +317,7 @@ void
CompositorVsyncObserver::DispatchTouchEvents(TimeStamp aVsyncTimestamp)
{
#ifdef MOZ_WIDGET_GONK
if (gfxPrefs::TouchResampling()) {
GeckoTouchDispatcher::NotifyVsync(aVsyncTimestamp);
}
GeckoTouchDispatcher::NotifyVsync(aVsyncTimestamp);
#endif
}
@ -385,7 +387,7 @@ CompositorParent::CompositorParent(nsIWidget* aWidget,
}
if (gfxPrefs::VsyncAlignedCompositor()) {
mCompositorVsyncObserver = new CompositorVsyncObserver(this);
mCompositorVsyncObserver = new CompositorVsyncObserver(this, aWidget);
}
gfxPlatform::GetPlatform()->ComputeTileSize();
@ -428,7 +430,10 @@ CompositorParent::Destroy()
mApzcTreeManager = nullptr;
}
sIndirectLayerTrees.erase(mRootLayerTreeID);
mCompositorVsyncObserver = nullptr;
if (mCompositorVsyncObserver) {
mCompositorVsyncObserver->UnobserveVsync();
mCompositorVsyncObserver = nullptr;
}
}
void

View File

@ -100,12 +100,12 @@ class CompositorVsyncObserver MOZ_FINAL : public VsyncObserver
friend class CompositorParent;
public:
explicit CompositorVsyncObserver(CompositorParent* aCompositorParent);
explicit CompositorVsyncObserver(CompositorParent* aCompositorParent, nsIWidget* aWidget);
virtual bool NotifyVsync(TimeStamp aVsyncTimestamp) MOZ_OVERRIDE;
void SetNeedsComposite(bool aSchedule);
bool NeedsComposite();
void CancelCurrentCompositeTask();
private:
virtual ~CompositorVsyncObserver();
@ -118,6 +118,7 @@ private:
bool mNeedsComposite;
bool mIsObservingVsync;
nsRefPtr<CompositorParent> mCompositorParent;
nsRefPtr<VsyncDispatcher> mVsyncDispatcher;
mozilla::Monitor mCurrentCompositeTaskMonitor;
CancelableTask* mCurrentCompositeTask;