From 2df41aacc8e7d590017da32b3648ab02767a3ac9 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Fri, 8 May 2020 20:46:13 +0000 Subject: [PATCH] Bug 1635001 - P2. Don't use MessageLoop threads with APZ. r=kats,geckoview-reviewers,snorp It is unclear on why MessageLoop was ever used with this code. Differential Revision: https://phabricator.services.mozilla.com/D73829 --- gfx/ipc/GPUParent.cpp | 2 +- .../apz/public/GeckoContentController.h | 2 +- gfx/layers/apz/src/AsyncPanZoomAnimation.h | 1 - gfx/layers/apz/src/AsyncPanZoomController.h | 2 - gfx/layers/apz/test/gtest/APZCBasicTester.h | 2 +- .../apz/test/gtest/APZCTreeManagerTester.h | 2 +- gfx/layers/apz/util/APZThreadUtils.cpp | 26 ++++---- gfx/layers/apz/util/APZThreadUtils.h | 5 +- gfx/layers/apz/util/ActiveElementManager.cpp | 4 +- .../apz/util/ChromeProcessController.cpp | 60 +++++++++--------- gfx/layers/apz/util/ChromeProcessController.h | 5 +- gfx/layers/ipc/RemoteContentController.cpp | 63 +++++++++---------- gfx/layers/ipc/RemoteContentController.h | 2 +- widget/android/nsWindow.cpp | 3 +- widget/nsBaseWidget.cpp | 2 +- 15 files changed, 89 insertions(+), 92 deletions(-) diff --git a/gfx/ipc/GPUParent.cpp b/gfx/ipc/GPUParent.cpp index c4a3a987a9f7..066579329dd8 100644 --- a/gfx/ipc/GPUParent.cpp +++ b/gfx/ipc/GPUParent.cpp @@ -132,7 +132,7 @@ bool GPUParent::Init(base::ProcessId aParentPid, const char* aParentBuildID, #endif CompositorThreadHolder::Start(); - APZThreadUtils::SetControllerThread(MessageLoop::current()); + APZThreadUtils::SetControllerThread(NS_GetCurrentThread()); apz::InitializeGlobalState(); LayerTreeOwnerTracker::Initialize(); CompositorBridgeParent::InitializeStatics(); diff --git a/gfx/layers/apz/public/GeckoContentController.h b/gfx/layers/apz/public/GeckoContentController.h index a0619cc5af30..82d171860bf8 100644 --- a/gfx/layers/apz/public/GeckoContentController.h +++ b/gfx/layers/apz/public/GeckoContentController.h @@ -111,7 +111,7 @@ class GeckoContentController { */ virtual void PostDelayedTask(already_AddRefed aRunnable, int aDelayMs) { - APZThreadUtils::PostDelayedTask(std::move(aRunnable), aDelayMs); + APZThreadUtils::DelayedDispatch(std::move(aRunnable), aDelayMs); } /** diff --git a/gfx/layers/apz/src/AsyncPanZoomAnimation.h b/gfx/layers/apz/src/AsyncPanZoomAnimation.h index 2c602d104ad9..7b8b0e492ac2 100644 --- a/gfx/layers/apz/src/AsyncPanZoomAnimation.h +++ b/gfx/layers/apz/src/AsyncPanZoomAnimation.h @@ -8,7 +8,6 @@ #define mozilla_layers_AsyncPanZoomAnimation_h_ #include "APZUtils.h" -#include "base/message_loop.h" #include "mozilla/RefPtr.h" #include "mozilla/TimeStamp.h" #include "nsISupportsImpl.h" diff --git a/gfx/layers/apz/src/AsyncPanZoomController.h b/gfx/layers/apz/src/AsyncPanZoomController.h index e39ed23d0938..f4e62e8dd791 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.h +++ b/gfx/layers/apz/src/AsyncPanZoomController.h @@ -33,8 +33,6 @@ #include "RecentEventsBuffer.h" // for RecentEventsBuffer #include "SampledAPZCState.h" -#include "base/message_loop.h" - namespace mozilla { namespace ipc { diff --git a/gfx/layers/apz/test/gtest/APZCBasicTester.h b/gfx/layers/apz/test/gtest/APZCBasicTester.h index 75947179141c..ab097f460b03 100644 --- a/gfx/layers/apz/test/gtest/APZCBasicTester.h +++ b/gfx/layers/apz/test/gtest/APZCBasicTester.h @@ -26,7 +26,7 @@ class APZCBasicTester : public APZCTesterBase { protected: virtual void SetUp() { APZThreadUtils::SetThreadAssertionsEnabled(false); - APZThreadUtils::SetControllerThread(MessageLoop::current()); + APZThreadUtils::SetControllerThread(NS_GetCurrentThread()); tm = new TestAPZCTreeManager(mcc); updater = new APZUpdater(tm, false); diff --git a/gfx/layers/apz/test/gtest/APZCTreeManagerTester.h b/gfx/layers/apz/test/gtest/APZCTreeManagerTester.h index f50e1545eefc..7c48a2114545 100644 --- a/gfx/layers/apz/test/gtest/APZCTreeManagerTester.h +++ b/gfx/layers/apz/test/gtest/APZCTreeManagerTester.h @@ -23,7 +23,7 @@ class APZCTreeManagerTester : public APZCTesterBase { virtual void SetUp() { gfxPlatform::GetPlatform(); APZThreadUtils::SetThreadAssertionsEnabled(false); - APZThreadUtils::SetControllerThread(MessageLoop::current()); + APZThreadUtils::SetControllerThread(NS_GetCurrentThread()); manager = new TestAPZCTreeManager(mcc); updater = new APZUpdater(manager, false); diff --git a/gfx/layers/apz/util/APZThreadUtils.cpp b/gfx/layers/apz/util/APZThreadUtils.cpp index fb4872835b6a..89ec28b1fa1e 100644 --- a/gfx/layers/apz/util/APZThreadUtils.cpp +++ b/gfx/layers/apz/util/APZThreadUtils.cpp @@ -10,7 +10,7 @@ namespace mozilla { namespace layers { static bool sThreadAssertionsEnabled = true; -static MessageLoop* sControllerThread; +static nsISerialEventTarget* sControllerThread; /*static*/ void APZThreadUtils::SetThreadAssertionsEnabled(bool aEnabled) { @@ -23,11 +23,11 @@ bool APZThreadUtils::GetThreadAssertionsEnabled() { } /*static*/ -void APZThreadUtils::SetControllerThread(MessageLoop* aLoop) { +void APZThreadUtils::SetControllerThread(nsISerialEventTarget* aThread) { // We must either be setting the initial controller thread, or removing it, // or re-using an existing controller thread. - MOZ_ASSERT(!sControllerThread || !aLoop || sControllerThread == aLoop); - sControllerThread = aLoop; + MOZ_ASSERT(!sControllerThread || !aThread || sControllerThread == aThread); + sControllerThread = aThread; } /*static*/ @@ -36,7 +36,7 @@ void APZThreadUtils::AssertOnControllerThread() { return; } - MOZ_ASSERT(sControllerThread == MessageLoop::current()); + MOZ_ASSERT(sControllerThread->IsOnCurrentThread()); } /*static*/ @@ -49,25 +49,29 @@ void APZThreadUtils::RunOnControllerThread(RefPtr&& aTask) { return; } - if (sControllerThread == MessageLoop::current()) { + if (sControllerThread->IsOnCurrentThread()) { task->Run(); } else { - sControllerThread->PostTask(task.forget()); + sControllerThread->Dispatch(task.forget()); } } /*static*/ bool APZThreadUtils::IsControllerThread() { - return sControllerThread == MessageLoop::current(); + return sControllerThread == NS_GetCurrentThread(); } /*static*/ -void APZThreadUtils::PostDelayedTask(already_AddRefed aRunnable, +void APZThreadUtils::DelayedDispatch(already_AddRefed aRunnable, int aDelayMs) { - MOZ_ASSERT(sControllerThread && sControllerThread == MessageLoop::current()); + MOZ_ASSERT(sControllerThread && sControllerThread->IsOnCurrentThread()); MOZ_ASSERT(!XRE_IsContentProcess(), "ContentProcessController should only be used remotely."); - sControllerThread->PostDelayedTask(std::move(aRunnable), aDelayMs); + if (aDelayMs) { + sControllerThread->DelayedDispatch(std::move(aRunnable), aDelayMs); + } else { + sControllerThread->Dispatch(std::move(aRunnable)); + } } NS_IMPL_ISUPPORTS(GenericNamedTimerCallbackBase, nsITimerCallback, nsINamed) diff --git a/gfx/layers/apz/util/APZThreadUtils.h b/gfx/layers/apz/util/APZThreadUtils.h index 22ac9885a0ad..ac242b5b51e1 100644 --- a/gfx/layers/apz/util/APZThreadUtils.h +++ b/gfx/layers/apz/util/APZThreadUtils.h @@ -7,7 +7,6 @@ #ifndef mozilla_layers_APZThreadUtils_h #define mozilla_layers_APZThreadUtils_h -#include "base/message_loop.h" #include "nsINamed.h" #include "nsITimer.h" @@ -30,7 +29,7 @@ class APZThreadUtils { /** * Set the controller thread. */ - static void SetControllerThread(MessageLoop* aLoop); + static void SetControllerThread(nsISerialEventTarget* aThread); /** * This can be used to assert that the current thread is the @@ -56,7 +55,7 @@ class APZThreadUtils { * in the future. * This method must always be called on the controller thread. */ - static void PostDelayedTask(already_AddRefed aRunnable, + static void DelayedDispatch(already_AddRefed aRunnable, int aDelayMs); }; diff --git a/gfx/layers/apz/util/ActiveElementManager.cpp b/gfx/layers/apz/util/ActiveElementManager.cpp index 3fa4aec23ece..ed485c3a1d74 100644 --- a/gfx/layers/apz/util/ActiveElementManager.cpp +++ b/gfx/layers/apz/util/ActiveElementManager.cpp @@ -9,8 +9,6 @@ #include "mozilla/EventStates.h" #include "mozilla/PresShell.h" #include "mozilla/StaticPrefs_ui.h" -#include "base/message_loop.h" -#include "base/task.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/Document.h" @@ -78,7 +76,7 @@ void ActiveElementManager::TriggerElementActivation() { "layers::ActiveElementManager::SetActiveTask", this, &ActiveElementManager::SetActiveTask, mTarget); mSetActiveTask = task; - MessageLoop::current()->PostDelayedTask( + NS_GetCurrentThread()->DelayedDispatch( task.forget(), StaticPrefs::ui_touch_activation_delay_ms()); AEM_LOG("Scheduling mSetActiveTask %p\n", mSetActiveTask.get()); } diff --git a/gfx/layers/apz/util/ChromeProcessController.cpp b/gfx/layers/apz/util/ChromeProcessController.cpp index 6db21fe5beea..8b2f36b7d3f3 100644 --- a/gfx/layers/apz/util/ChromeProcessController.cpp +++ b/gfx/layers/apz/util/ChromeProcessController.cpp @@ -7,7 +7,6 @@ #include "ChromeProcessController.h" #include "MainThreadUtils.h" // for NS_IsMainThread() -#include "base/message_loop.h" // for MessageLoop #include "mozilla/PresShell.h" #include "mozilla/dom/Element.h" #include "mozilla/layers/CompositorBridgeParent.h" @@ -34,13 +33,13 @@ ChromeProcessController::ChromeProcessController( : mWidget(aWidget), mAPZEventState(aAPZEventState), mAPZCTreeManager(aAPZCTreeManager), - mUILoop(MessageLoop::current()) { - // Otherwise we're initializing mUILoop incorrectly. + mUIThread(NS_GetCurrentThread()) { + // Otherwise we're initializing mUIThread incorrectly. MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aAPZEventState); MOZ_ASSERT(aAPZCTreeManager); - mUILoop->PostTask( + mUIThread->Dispatch( NewRunnableMethod("layers::ChromeProcessController::InitializeRoot", this, &ChromeProcessController::InitializeRoot)); } @@ -53,8 +52,8 @@ void ChromeProcessController::InitializeRoot() { void ChromeProcessController::NotifyLayerTransforms( const nsTArray& aTransforms) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod>( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch(NewRunnableMethod>( "layers::ChromeProcessController::NotifyLayerTransforms", this, &ChromeProcessController::NotifyLayerTransforms, aTransforms)); return; @@ -82,14 +81,14 @@ void ChromeProcessController::DispatchToRepaintThread( } void ChromeProcessController::Destroy() { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch( NewRunnableMethod("layers::ChromeProcessController::Destroy", this, &ChromeProcessController::Destroy)); return; } - MOZ_ASSERT(MessageLoop::current() == mUILoop); + MOZ_ASSERT(mUIThread->IsOnCurrentThread()); mWidget = nullptr; mAPZEventState = nullptr; } @@ -128,7 +127,7 @@ dom::Document* ChromeProcessController::GetRootContentDocument( void ChromeProcessController::HandleDoubleTap( const mozilla::CSSPoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid) { - MOZ_ASSERT(MessageLoop::current() == mUILoop); + MOZ_ASSERT(mUIThread->IsOnCurrentThread()); RefPtr document = GetRootContentDocument(aGuid.mScrollId); if (!document.get()) { @@ -156,9 +155,9 @@ void ChromeProcessController::HandleTap( uint64_t aInputBlockId) { MOZ_LOG(sApzChromeLog, LogLevel::Debug, ("HandleTap called with %d\n", (int)aType)); - if (MessageLoop::current() != mUILoop) { + if (!mUIThread->IsOnCurrentThread()) { MOZ_LOG(sApzChromeLog, LogLevel::Debug, ("HandleTap redispatching\n")); - mUILoop->PostTask( + mUIThread->Dispatch( NewRunnableMethod( "layers::ChromeProcessController::HandleTap", this, @@ -216,8 +215,8 @@ void ChromeProcessController::HandleTap( void ChromeProcessController::NotifyPinchGesture( PinchGestureInput::PinchGestureType aType, const ScrollableLayerGuid& aGuid, LayoutDeviceCoord aSpanChange, Modifiers aModifiers) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch( NewRunnableMethod( "layers::ChromeProcessController::NotifyPinchGesture", this, @@ -234,8 +233,8 @@ void ChromeProcessController::NotifyPinchGesture( void ChromeProcessController::NotifyAPZStateChange( const ScrollableLayerGuid& aGuid, APZStateChange aChange, int aArg) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch( NewRunnableMethod( "layers::ChromeProcessController::NotifyAPZStateChange", this, &ChromeProcessController::NotifyAPZStateChange, aGuid, aChange, @@ -252,11 +251,12 @@ void ChromeProcessController::NotifyAPZStateChange( void ChromeProcessController::NotifyMozMouseScrollEvent( const ScrollableLayerGuid::ViewID& aScrollId, const nsString& aEvent) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod( - "layers::ChromeProcessController::NotifyMozMouseScrollEvent", this, - &ChromeProcessController::NotifyMozMouseScrollEvent, aScrollId, - aEvent)); + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch( + NewRunnableMethod( + "layers::ChromeProcessController::NotifyMozMouseScrollEvent", this, + &ChromeProcessController::NotifyMozMouseScrollEvent, aScrollId, + aEvent)); return; } @@ -272,9 +272,9 @@ void ChromeProcessController::NotifyFlushComplete() { void ChromeProcessController::NotifyAsyncScrollbarDragInitiated( uint64_t aDragBlockId, const ScrollableLayerGuid::ViewID& aScrollId, ScrollDirection aDirection) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch(NewRunnableMethod( "layers::ChromeProcessController::NotifyAsyncScrollbarDragInitiated", this, &ChromeProcessController::NotifyAsyncScrollbarDragInitiated, aDragBlockId, aScrollId, aDirection)); @@ -287,8 +287,8 @@ void ChromeProcessController::NotifyAsyncScrollbarDragInitiated( void ChromeProcessController::NotifyAsyncScrollbarDragRejected( const ScrollableLayerGuid::ViewID& aScrollId) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch(NewRunnableMethod( "layers::ChromeProcessController::NotifyAsyncScrollbarDragRejected", this, &ChromeProcessController::NotifyAsyncScrollbarDragRejected, aScrollId)); @@ -300,8 +300,8 @@ void ChromeProcessController::NotifyAsyncScrollbarDragRejected( void ChromeProcessController::NotifyAsyncAutoscrollRejected( const ScrollableLayerGuid::ViewID& aScrollId) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch(NewRunnableMethod( "layers::ChromeProcessController::NotifyAsyncAutoscrollRejected", this, &ChromeProcessController::NotifyAsyncAutoscrollRejected, aScrollId)); return; @@ -312,8 +312,8 @@ void ChromeProcessController::NotifyAsyncAutoscrollRejected( void ChromeProcessController::CancelAutoscroll( const ScrollableLayerGuid& aGuid) { - if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod( + if (!mUIThread->IsOnCurrentThread()) { + mUIThread->Dispatch(NewRunnableMethod( "layers::ChromeProcessController::CancelAutoscroll", this, &ChromeProcessController::CancelAutoscroll, aGuid)); return; diff --git a/gfx/layers/apz/util/ChromeProcessController.h b/gfx/layers/apz/util/ChromeProcessController.h index 6663d564cdeb..a470572d240e 100644 --- a/gfx/layers/apz/util/ChromeProcessController.h +++ b/gfx/layers/apz/util/ChromeProcessController.h @@ -13,9 +13,8 @@ #include "mozilla/layers/MatrixMessage.h" class nsIDOMWindowUtils; - +class nsISerialEventTarget; class nsIWidget; -class MessageLoop; namespace mozilla { class PresShell; @@ -81,7 +80,7 @@ class ChromeProcessController : public mozilla::layers::GeckoContentController { nsCOMPtr mWidget; RefPtr mAPZEventState; RefPtr mAPZCTreeManager; - MessageLoop* mUILoop; + nsCOMPtr mUIThread; void InitializeRoot(); PresShell* GetPresShell() const; diff --git a/gfx/layers/ipc/RemoteContentController.cpp b/gfx/layers/ipc/RemoteContentController.cpp index 24d7f0962305..a007d792897c 100644 --- a/gfx/layers/ipc/RemoteContentController.cpp +++ b/gfx/layers/ipc/RemoteContentController.cpp @@ -6,8 +6,6 @@ #include "mozilla/layers/RemoteContentController.h" -#include "base/message_loop.h" -#include "base/task.h" #include "MainThreadUtils.h" #include "mozilla/dom/BrowserParent.h" #include "mozilla/layers/APZCCallbackHelper.h" @@ -29,18 +27,19 @@ namespace layers { using namespace mozilla::gfx; RemoteContentController::RemoteContentController() - : mCompositorThread(MessageLoop::current()), mCanSend(true) {} + : mCompositorThread(NS_GetCurrentThread()), mCanSend(true) { + MOZ_ASSERT(CompositorThread()->IsOnCurrentThread()); +} RemoteContentController::~RemoteContentController() = default; void RemoteContentController::NotifyLayerTransforms( const nsTArray& aTransforms) { - if (MessageLoop::current() != mCompositorThread) { + if (!mCompositorThread->IsOnCurrentThread()) { // We have to send messages from the compositor thread - mCompositorThread->PostTask( - NewRunnableMethod>( - "layers::RemoteContentController::NotifyLayerTransforms", this, - &RemoteContentController::NotifyLayerTransforms, aTransforms)); + mCompositorThread->Dispatch(NewRunnableMethod>( + "layers::RemoteContentController::NotifyLayerTransforms", this, + &RemoteContentController::NotifyLayerTransforms, aTransforms)); return; } @@ -78,7 +77,7 @@ void RemoteContentController::HandleTapOnCompositorThread( TapType aTapType, LayoutDevicePoint aPoint, Modifiers aModifiers, ScrollableLayerGuid aGuid, uint64_t aInputBlockId) { MOZ_ASSERT(XRE_IsGPUProcess()); - MOZ_ASSERT(MessageLoop::current() == mCompositorThread); + MOZ_ASSERT(mCompositorThread->IsOnCurrentThread()); // The raw pointer to APZCTreeManagerParent is ok here because we are on the // compositor thread. @@ -99,12 +98,12 @@ void RemoteContentController::HandleTap(TapType aTapType, APZThreadUtils::AssertOnControllerThread(); if (XRE_GetProcessType() == GeckoProcessType_GPU) { - if (MessageLoop::current() == mCompositorThread) { + if (mCompositorThread->IsOnCurrentThread()) { HandleTapOnCompositorThread(aTapType, aPoint, aModifiers, aGuid, aInputBlockId); } else { // We have to send messages from the compositor thread - mCompositorThread->PostTask( + mCompositorThread->Dispatch( NewRunnableMethod( "layers::RemoteContentController::HandleTapOnCompositorThread", @@ -144,7 +143,7 @@ void RemoteContentController::HandleTap(TapType aTapType, void RemoteContentController::NotifyPinchGestureOnCompositorThread( PinchGestureInput::PinchGestureType aType, const ScrollableLayerGuid& aGuid, LayoutDeviceCoord aSpanChange, Modifiers aModifiers) { - MOZ_ASSERT(MessageLoop::current() == mCompositorThread); + MOZ_ASSERT(mCompositorThread->IsOnCurrentThread()); // The raw pointer to APZCTreeManagerParent is ok here because we are on the // compositor thread. @@ -167,11 +166,11 @@ void RemoteContentController::NotifyPinchGesture( // If we're in the GPU process, try to find a handle to the parent process // and send it there. if (XRE_IsGPUProcess()) { - if (MessageLoop::current() == mCompositorThread) { + if (mCompositorThread->IsOnCurrentThread()) { NotifyPinchGestureOnCompositorThread(aType, aGuid, aSpanChange, aModifiers); } else { - mCompositorThread->PostTask( + mCompositorThread->Dispatch( NewRunnableMethod( "layers::RemoteContentController::" @@ -198,19 +197,19 @@ void RemoteContentController::NotifyPinchGesture( } bool RemoteContentController::IsRepaintThread() { - return MessageLoop::current() == mCompositorThread; + return mCompositorThread->IsOnCurrentThread(); } void RemoteContentController::DispatchToRepaintThread( already_AddRefed aTask) { - mCompositorThread->PostTask(std::move(aTask)); + mCompositorThread->Dispatch(std::move(aTask)); } void RemoteContentController::NotifyAPZStateChange( const ScrollableLayerGuid& aGuid, APZStateChange aChange, int aArg) { - if (MessageLoop::current() != mCompositorThread) { + if (!mCompositorThread->IsOnCurrentThread()) { // We have to send messages from the compositor thread - mCompositorThread->PostTask( + mCompositorThread->Dispatch( NewRunnableMethod( "layers::RemoteContentController::NotifyAPZStateChange", this, &RemoteContentController::NotifyAPZStateChange, aGuid, aChange, @@ -225,8 +224,8 @@ void RemoteContentController::NotifyAPZStateChange( void RemoteContentController::UpdateOverscrollVelocity(float aX, float aY, bool aIsRootContent) { - if (MessageLoop::current() != mCompositorThread) { - mCompositorThread->PostTask(NewRunnableMethod( + if (!mCompositorThread->IsOnCurrentThread()) { + mCompositorThread->Dispatch(NewRunnableMethod( "layers::RemoteContentController::UpdateOverscrollVelocity", this, &RemoteContentController::UpdateOverscrollVelocity, aX, aY, aIsRootContent)); @@ -239,8 +238,8 @@ void RemoteContentController::UpdateOverscrollVelocity(float aX, float aY, void RemoteContentController::UpdateOverscrollOffset(float aX, float aY, bool aIsRootContent) { - if (MessageLoop::current() != mCompositorThread) { - mCompositorThread->PostTask(NewRunnableMethod( + if (!mCompositorThread->IsOnCurrentThread()) { + mCompositorThread->Dispatch(NewRunnableMethod( "layers::RemoteContentController::UpdateOverscrollOffset", this, &RemoteContentController::UpdateOverscrollOffset, aX, aY, aIsRootContent)); @@ -253,9 +252,9 @@ void RemoteContentController::UpdateOverscrollOffset(float aX, float aY, void RemoteContentController::NotifyMozMouseScrollEvent( const ScrollableLayerGuid::ViewID& aScrollId, const nsString& aEvent) { - if (MessageLoop::current() != mCompositorThread) { + if (!mCompositorThread->IsOnCurrentThread()) { // We have to send messages from the compositor thread - mCompositorThread->PostTask( + mCompositorThread->Dispatch( NewRunnableMethod( "layers::RemoteContentController::NotifyMozMouseScrollEvent", this, &RemoteContentController::NotifyMozMouseScrollEvent, aScrollId, @@ -279,9 +278,9 @@ void RemoteContentController::NotifyFlushComplete() { void RemoteContentController::NotifyAsyncScrollbarDragInitiated( uint64_t aDragBlockId, const ScrollableLayerGuid::ViewID& aScrollId, ScrollDirection aDirection) { - if (MessageLoop::current() != mCompositorThread) { + if (!mCompositorThread->IsOnCurrentThread()) { // We have to send messages from the compositor thread - mCompositorThread->PostTask(NewRunnableMethodDispatch(NewRunnableMethod( "layers::RemoteContentController::NotifyAsyncScrollbarDragInitiated", @@ -298,9 +297,9 @@ void RemoteContentController::NotifyAsyncScrollbarDragInitiated( void RemoteContentController::NotifyAsyncScrollbarDragRejected( const ScrollableLayerGuid::ViewID& aScrollId) { - if (MessageLoop::current() != mCompositorThread) { + if (!mCompositorThread->IsOnCurrentThread()) { // We have to send messages from the compositor thread - mCompositorThread->PostTask(NewRunnableMethod( + mCompositorThread->Dispatch(NewRunnableMethod( "layers::RemoteContentController::NotifyAsyncScrollbarDragRejected", this, &RemoteContentController::NotifyAsyncScrollbarDragRejected, aScrollId)); @@ -314,9 +313,9 @@ void RemoteContentController::NotifyAsyncScrollbarDragRejected( void RemoteContentController::NotifyAsyncAutoscrollRejected( const ScrollableLayerGuid::ViewID& aScrollId) { - if (MessageLoop::current() != mCompositorThread) { + if (!mCompositorThread->IsOnCurrentThread()) { // We have to send messages from the compositor thread - mCompositorThread->PostTask(NewRunnableMethod( + mCompositorThread->Dispatch(NewRunnableMethod( "layers::RemoteContentController::NotifyAsyncAutoscrollRejected", this, &RemoteContentController::NotifyAsyncAutoscrollRejected, aScrollId)); return; @@ -354,8 +353,8 @@ void RemoteContentController::CancelAutoscrollCrossProcess( const ScrollableLayerGuid& aGuid) { MOZ_ASSERT(XRE_IsGPUProcess()); - if (MessageLoop::current() != mCompositorThread) { - mCompositorThread->PostTask(NewRunnableMethod( + if (!mCompositorThread->IsOnCurrentThread()) { + mCompositorThread->Dispatch(NewRunnableMethod( "layers::RemoteContentController::CancelAutoscrollCrossProcess", this, &RemoteContentController::CancelAutoscrollCrossProcess, aGuid)); return; diff --git a/gfx/layers/ipc/RemoteContentController.h b/gfx/layers/ipc/RemoteContentController.h index 55fc6d9a8f69..efd710ad8221 100644 --- a/gfx/layers/ipc/RemoteContentController.h +++ b/gfx/layers/ipc/RemoteContentController.h @@ -88,7 +88,7 @@ class RemoteContentController : public GeckoContentController, bool IsRemote() override; private: - MessageLoop* mCompositorThread; + nsCOMPtr mCompositorThread; bool mCanSend; void HandleTapOnMainThread(TapType aType, LayoutDevicePoint aPoint, diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index c32db127ee55..fe7aa459de54 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -2291,7 +2291,8 @@ bool nsWindow::NeedsPaint() { } void nsWindow::ConfigureAPZControllerThread() { - APZThreadUtils::SetControllerThread(mozilla::GetAndroidUiThreadMessageLoop()); + nsCOMPtr thread = mozilla::GetAndroidUiThread(); + APZThreadUtils::SetControllerThread(thread); } already_AddRefed diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 9869ca3d151e..1fd1bb2bbe93 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -907,7 +907,7 @@ void nsBaseWidget::ConfigureAPZCTreeManager() { void nsBaseWidget::ConfigureAPZControllerThread() { // By default the controller thread is the main thread. - APZThreadUtils::SetControllerThread(MessageLoop::current()); + APZThreadUtils::SetControllerThread(NS_GetCurrentThread()); } void nsBaseWidget::SetConfirmedTargetAPZC(