Bug 1129133 - Clean up GeckoTouchDispatcher so that it's a real singleton. r=kats,mwu

This commit is contained in:
Mason Chang 2015-02-24 12:52:16 -08:00
parent 232b9291f8
commit d81b5a205d
4 changed files with 26 additions and 23 deletions

View File

@ -232,7 +232,7 @@ CompositorVsyncObserver::CompositorVsyncObserver(CompositorParent* aCompositorPa
MOZ_ASSERT(aWidget != nullptr);
mCompositorVsyncDispatcher = aWidget->GetCompositorVsyncDispatcher();
#ifdef MOZ_WIDGET_GONK
GeckoTouchDispatcher::SetCompositorVsyncObserver(this);
GeckoTouchDispatcher::GetInstance()->SetCompositorVsyncObserver(this);
#endif
}
@ -370,7 +370,7 @@ void
CompositorVsyncObserver::DispatchTouchEvents(TimeStamp aVsyncTimestamp)
{
#ifdef MOZ_WIDGET_GONK
GeckoTouchDispatcher::NotifyVsync(aVsyncTimestamp);
GeckoTouchDispatcher::GetInstance()->NotifyVsync(aVsyncTimestamp);
#endif
}

View File

@ -51,6 +51,16 @@ static const uint64_t kInputExpirationThresholdMs = 1000;
static StaticRefPtr<GeckoTouchDispatcher> sTouchDispatcher;
/* static */ GeckoTouchDispatcher*
GeckoTouchDispatcher::GetInstance()
{
if (!sTouchDispatcher) {
sTouchDispatcher = new GeckoTouchDispatcher();
ClearOnShutdown(&sTouchDispatcher);
}
return sTouchDispatcher;
}
GeckoTouchDispatcher::GeckoTouchDispatcher()
: mTouchQueueLock("GeckoTouchDispatcher::mTouchQueueLock")
, mTouchEventsFiltered(false)
@ -70,40 +80,32 @@ GeckoTouchDispatcher::GeckoTouchDispatcher()
mMaxPredict = TimeDuration::FromMilliseconds(gfxPrefs::TouchResampleMaxPredict());
mOldTouchThreshold = TimeDuration::FromMilliseconds(gfxPrefs::TouchResampleOldTouchThreshold());
mDelayedVsyncThreshold = TimeDuration::FromMilliseconds(gfxPrefs::TouchResampleVsyncDelayThreshold());
sTouchDispatcher = this;
ClearOnShutdown(&sTouchDispatcher);
}
/* static */ void
void
GeckoTouchDispatcher::SetCompositorVsyncObserver(mozilla::layers::CompositorVsyncObserver *aObserver)
{
MOZ_ASSERT(sTouchDispatcher != nullptr);
MOZ_ASSERT(NS_IsMainThread());
// We assume on b2g that there is only 1 CompositorParent
MOZ_ASSERT(sTouchDispatcher->mCompositorVsyncObserver == nullptr);
if (sTouchDispatcher->mResamplingEnabled) {
sTouchDispatcher->mCompositorVsyncObserver = aObserver;
MOZ_ASSERT(mCompositorVsyncObserver == nullptr);
if (mResamplingEnabled) {
mCompositorVsyncObserver = aObserver;
}
}
// Timestamp is in nanoseconds
/* static */ bool
bool
GeckoTouchDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
{
if (sTouchDispatcher == nullptr) {
return false;
}
MOZ_ASSERT(sTouchDispatcher->mResamplingEnabled);
MOZ_ASSERT(mResamplingEnabled);
bool haveTouchData = false;
{
MutexAutoLock lock(sTouchDispatcher->mTouchQueueLock);
haveTouchData = !sTouchDispatcher->mTouchMoveEvents.empty();
MutexAutoLock lock(mTouchQueueLock);
haveTouchData = !mTouchMoveEvents.empty();
}
if (haveTouchData) {
layers::APZThreadUtils::AssertOnControllerThread();
sTouchDispatcher->DispatchTouchMoveEvents(aVsyncTimestamp);
DispatchTouchMoveEvents(aVsyncTimestamp);
}
return haveTouchData;

View File

@ -46,14 +46,15 @@ class GeckoTouchDispatcher
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GeckoTouchDispatcher)
public:
GeckoTouchDispatcher();
static GeckoTouchDispatcher* GetInstance();
void NotifyTouch(MultiTouchInput& aTouch, TimeStamp aEventTime);
void DispatchTouchEvent(MultiTouchInput aMultiTouch);
void DispatchTouchMoveEvents(TimeStamp aVsyncTime);
static bool NotifyVsync(TimeStamp aVsyncTimestamp);
static void SetCompositorVsyncObserver(layers::CompositorVsyncObserver* aObserver);
bool NotifyVsync(TimeStamp aVsyncTimestamp);
void SetCompositorVsyncObserver(layers::CompositorVsyncObserver* aObserver);
private:
GeckoTouchDispatcher();
void ResampleTouchMoves(MultiTouchInput& aOutTouch, TimeStamp vsyncTime);
void SendTouchEvent(MultiTouchInput& aData);
void DispatchMouseEvent(MultiTouchInput& aMultiTouch,

View File

@ -506,7 +506,7 @@ public:
, mKeyEventsFiltered(false)
, mPowerWakelock(false)
{
mTouchDispatcher = new GeckoTouchDispatcher();
mTouchDispatcher = GeckoTouchDispatcher::GetInstance();
}
virtual void dump(String8& dump);