From d81b5a205d11a538b954f154f07efea984c8886d Mon Sep 17 00:00:00 2001 From: Mason Chang Date: Tue, 24 Feb 2015 12:52:16 -0800 Subject: [PATCH] Bug 1129133 - Clean up GeckoTouchDispatcher so that it's a real singleton. r=kats,mwu --- gfx/layers/ipc/CompositorParent.cpp | 4 ++-- widget/gonk/GeckoTouchDispatcher.cpp | 36 +++++++++++++++------------- widget/gonk/GeckoTouchDispatcher.h | 7 +++--- widget/gonk/nsAppShell.cpp | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/gfx/layers/ipc/CompositorParent.cpp b/gfx/layers/ipc/CompositorParent.cpp index dbfdbf3b82be..24a372b894e0 100644 --- a/gfx/layers/ipc/CompositorParent.cpp +++ b/gfx/layers/ipc/CompositorParent.cpp @@ -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 } diff --git a/widget/gonk/GeckoTouchDispatcher.cpp b/widget/gonk/GeckoTouchDispatcher.cpp index 0cef897fc6e6..a73d25c1ba15 100644 --- a/widget/gonk/GeckoTouchDispatcher.cpp +++ b/widget/gonk/GeckoTouchDispatcher.cpp @@ -51,6 +51,16 @@ static const uint64_t kInputExpirationThresholdMs = 1000; static StaticRefPtr 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; diff --git a/widget/gonk/GeckoTouchDispatcher.h b/widget/gonk/GeckoTouchDispatcher.h index 8e6531db4418..7cda7b744184 100644 --- a/widget/gonk/GeckoTouchDispatcher.h +++ b/widget/gonk/GeckoTouchDispatcher.h @@ -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, diff --git a/widget/gonk/nsAppShell.cpp b/widget/gonk/nsAppShell.cpp index 951c59c9b976..40d0c86408fe 100644 --- a/widget/gonk/nsAppShell.cpp +++ b/widget/gonk/nsAppShell.cpp @@ -506,7 +506,7 @@ public: , mKeyEventsFiltered(false) , mPowerWakelock(false) { - mTouchDispatcher = new GeckoTouchDispatcher(); + mTouchDispatcher = GeckoTouchDispatcher::GetInstance(); } virtual void dump(String8& dump);