From 96d762282321591a9bb331a76d8afa18aed8123e Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 7 May 2020 05:03:42 +0000 Subject: [PATCH] Bug 1634253 - P6. Remove MessageLoop use from gfx. r=kats,mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D73825 --- build/clang-plugin/ThreadAllows.txt | 2 + .../MediaSystemResourceManager.cpp | 10 +- dom/plugins/ipc/PluginInstanceParent.cpp | 16 ++-- gfx/ipc/VsyncBridgeParent.cpp | 10 +- gfx/layers/TextureSync.cpp | 2 +- gfx/layers/apz/src/APZUpdater.cpp | 4 +- gfx/layers/client/CompositableClient.cpp | 3 +- gfx/layers/client/TextureClient.cpp | 82 ++++++++-------- .../client/TextureClientRecycleAllocator.cpp | 2 +- gfx/layers/ipc/CanvasThread.cpp | 18 ++-- gfx/layers/ipc/CompositorBridgeChild.cpp | 25 +++-- gfx/layers/ipc/CompositorBridgeChild.h | 4 +- gfx/layers/ipc/CompositorBridgeParent.cpp | 95 +++++++++---------- gfx/layers/ipc/CompositorBridgeParent.h | 1 - gfx/layers/ipc/CompositorManagerChild.cpp | 3 +- gfx/layers/ipc/CompositorManagerParent.cpp | 6 +- gfx/layers/ipc/CompositorThread.cpp | 68 +++++-------- gfx/layers/ipc/CompositorThread.h | 20 ++-- gfx/layers/ipc/CompositorVsyncScheduler.cpp | 14 +-- gfx/layers/ipc/CompositorVsyncScheduler.h | 3 - gfx/layers/ipc/ImageBridgeChild.cpp | 74 +++++++-------- gfx/layers/ipc/ImageBridgeChild.h | 15 +-- gfx/layers/ipc/ImageBridgeParent.cpp | 27 +++--- gfx/layers/ipc/ImageBridgeParent.h | 12 +-- gfx/layers/ipc/ShadowLayers.cpp | 6 +- gfx/layers/ipc/ShadowLayers.h | 2 +- gfx/layers/ipc/TextureForwarder.h | 3 +- .../ipc/UiCompositorControllerChild.cpp | 7 +- .../ipc/UiCompositorControllerParent.cpp | 15 ++- gfx/layers/ipc/VideoBridgeChild.cpp | 12 +-- gfx/layers/ipc/VideoBridgeChild.h | 4 +- gfx/layers/ipc/VideoBridgeParent.cpp | 2 +- gfx/layers/wr/AsyncImagePipelineManager.cpp | 2 +- gfx/layers/wr/WebRenderBridgeParent.cpp | 6 +- gfx/thebes/DeviceManagerDx.cpp | 5 +- gfx/vr/VRManager.cpp | 10 +- gfx/vr/VRThread.cpp | 1 + gfx/vr/ipc/VRGPUChild.cpp | 2 +- gfx/vr/ipc/VRManagerChild.cpp | 4 +- gfx/vr/ipc/VRManagerChild.h | 2 - gfx/vr/ipc/VRManagerParent.cpp | 14 +-- gfx/webrender_bindings/RenderThread.cpp | 8 +- gfx/webrender_bindings/RendererOGL.cpp | 4 +- .../src/media-conduit/VideoConduit.h | 1 - widget/windows/CompositorWidgetParent.cpp | 2 +- 45 files changed, 273 insertions(+), 355 deletions(-) diff --git a/build/clang-plugin/ThreadAllows.txt b/build/clang-plugin/ThreadAllows.txt index 934d226d4b62..b09bb32b7920 100644 --- a/build/clang-plugin/ThreadAllows.txt +++ b/build/clang-plugin/ThreadAllows.txt @@ -17,6 +17,7 @@ Cameras IPC ChainedPipePump ChainedPipeRecv Checker Test +Compositor Cookie CrashRep Inject DDMediaLogs @@ -41,6 +42,7 @@ IMAP IPC Launch IPDL Background IdentityCrypto +ImageBridgeChld LS Thread LayerScope MDCDMThread diff --git a/dom/media/systemservices/MediaSystemResourceManager.cpp b/dom/media/systemservices/MediaSystemResourceManager.cpp index 8d0a797c4be2..ff02a10ed245 100644 --- a/dom/media/systemservices/MediaSystemResourceManager.cpp +++ b/dom/media/systemservices/MediaSystemResourceManager.cpp @@ -71,7 +71,7 @@ void MediaSystemResourceManager::Init() { barrier.NotifyAll(); }); - imageBridge->GetMessageLoop()->PostTask(runnable.forget()); + imageBridge->GetThread()->Dispatch(runnable.forget()); // should stop the thread until done. while (!done) { @@ -178,7 +178,7 @@ void MediaSystemResourceManager::Acquire(MediaSystemResourceClient* aClient) { return; } aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_WAITING; - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch( NewRunnableMethod("MediaSystemResourceManager::DoAcquire", this, &MediaSystemResourceManager::DoAcquire, aClient->mId)); @@ -220,7 +220,7 @@ bool MediaSystemResourceManager::AcquireSyncNoWait( aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_WAITING; } - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch( NewRunnableMethod("MediaSystemResourceManager::DoAcquire", this, &MediaSystemResourceManager::DoAcquire, aClient->mId)); @@ -282,7 +282,7 @@ void MediaSystemResourceManager::ReleaseResource( aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_END; - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch( NewRunnableMethod( "MediaSystemResourceManager::DoRelease", this, &MediaSystemResourceManager::DoRelease, aClient->mId)); @@ -304,7 +304,7 @@ void MediaSystemResourceManager::RecvResponse(uint32_t aId, bool aSuccess) { void MediaSystemResourceManager::HandleAcquireResult(uint32_t aId, bool aSuccess) { if (!InImageBridgeChildThread()) { - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch( NewRunnableMethod( "MediaSystemResourceManager::HandleAcquireResult", this, &MediaSystemResourceManager::HandleAcquireResult, aId, aSuccess)); diff --git a/dom/plugins/ipc/PluginInstanceParent.cpp b/dom/plugins/ipc/PluginInstanceParent.cpp index 1135dec4a44e..108c9b3a1f0a 100644 --- a/dom/plugins/ipc/PluginInstanceParent.cpp +++ b/dom/plugins/ipc/PluginInstanceParent.cpp @@ -551,7 +551,7 @@ class AsyncPluginSurfaceManager : public IGPUVideoSurfaceManager { if (!InImageBridgeChildThread()) { SynchronousTask task("AsyncPluginSurfaceManager readback sync"); RefPtr result; - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch( NewRunnableFunction("AsyncPluginSurfaceManager readback", &DoSyncReadback, &pluginSD, &result, &task)); task.Wait(); @@ -565,7 +565,7 @@ class AsyncPluginSurfaceManager : public IGPUVideoSurfaceManager { const SurfaceDescriptorGPUVideo& aSD) override { SurfaceDescriptorPlugin pluginSD = aSD; if (!InImageBridgeChildThread()) { - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch( NewRunnableFunction("AsyncPluginSurfaceManager dealloc", &DoDealloc, &pluginSD)); return; @@ -739,7 +739,7 @@ mozilla::ipc::IPCResult PluginInstanceParent::RecvInitDXGISurface( // render to. SurfaceDescriptorPlugin sd; SynchronousTask task("SendMakeAsyncPluginSurfaces sync"); - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch( NewRunnableFunction("SendingMakeAsyncPluginSurfaces", &InitDXGISurface, format, size, &sd, &task)); task.Wait(); @@ -781,9 +781,8 @@ mozilla::ipc::IPCResult PluginInstanceParent::RecvFinalizeDXGISurface( // Release the plugin surface but keep the display surface since it may // still be displayed. Also let the display surface know that it should // not receive further requests to copy from the plugin surface. - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - NewRunnableFunction("SendingRemoveAsyncPluginSurface", - &FinalizeDXGISurface, asi.mSD)); + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch(NewRunnableFunction( + "SendingRemoveAsyncPluginSurface", &FinalizeDXGISurface, asi.mSD)); mAsyncSurfaceMap.remove(asiIt); #endif @@ -897,9 +896,8 @@ mozilla::ipc::IPCResult PluginInstanceParent::RecvShowDirectDXGISurface( // Tell the ImageBridge to copy from the plugin surface to the display surface SynchronousTask task("SendUpdateAsyncPluginSurface sync"); - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - NewRunnableFunction("SendingUpdateAsyncPluginSurface", &CopyDXGISurface, - asi.mSD, &task)); + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch(NewRunnableFunction( + "SendingUpdateAsyncPluginSurface", &CopyDXGISurface, asi.mSD, &task)); task.Wait(); // Make sure we have an ImageContainer for SetCurrentImage. diff --git a/gfx/ipc/VsyncBridgeParent.cpp b/gfx/ipc/VsyncBridgeParent.cpp index 96eac4ae4dcb..9631d75b9883 100644 --- a/gfx/ipc/VsyncBridgeParent.cpp +++ b/gfx/ipc/VsyncBridgeParent.cpp @@ -20,7 +20,7 @@ RefPtr VsyncBridgeParent::Start( RefPtr task = NewRunnableMethod&&>( "gfx::VsyncBridgeParent::Open", parent, &VsyncBridgeParent::Open, std::move(aEndpoint)); - CompositorThreadHolder::Loop()->PostTask(task.forget()); + CompositorThread()->Dispatch(task.forget()); return parent; } @@ -48,10 +48,10 @@ mozilla::ipc::IPCResult VsyncBridgeParent::RecvNotifyVsync( } void VsyncBridgeParent::Shutdown() { - MessageLoop* ccloop = CompositorThreadHolder::Loop(); - if (MessageLoop::current() != ccloop) { - ccloop->PostTask(NewRunnableMethod("gfx::VsyncBridgeParent::ShutdownImpl", - this, &VsyncBridgeParent::ShutdownImpl)); + if (!CompositorThreadHolder::IsInCompositorThread()) { + CompositorThread()->Dispatch( + NewRunnableMethod("gfx::VsyncBridgeParent::ShutdownImpl", this, + &VsyncBridgeParent::ShutdownImpl)); return; } diff --git a/gfx/layers/TextureSync.cpp b/gfx/layers/TextureSync.cpp index b24ac7101342..7c3847b079a0 100644 --- a/gfx/layers/TextureSync.cpp +++ b/gfx/layers/TextureSync.cpp @@ -111,7 +111,7 @@ static void CheckTexturesForUnlock() { void TextureSync::DispatchCheckTexturesForUnlock() { RefPtr task = NS_NewRunnableFunction("CheckTexturesForUnlock", &CheckTexturesForUnlock); - CompositorThreadHolder::Loop()->PostTask(task.forget()); + CompositorThread()->Dispatch(task.forget()); } void TextureSync::HandleWaitForTexturesMessage(MachReceiveMessage* rmsg, diff --git a/gfx/layers/apz/src/APZUpdater.cpp b/gfx/layers/apz/src/APZUpdater.cpp index 3a5080b7c013..91660929188c 100644 --- a/gfx/layers/apz/src/APZUpdater.cpp +++ b/gfx/layers/apz/src/APZUpdater.cpp @@ -373,8 +373,8 @@ void APZUpdater::RunOnUpdaterThread(LayersId aLayersId, return; } - if (MessageLoop* loop = CompositorThreadHolder::Loop()) { - loop->PostTask(task.forget()); + if (CompositorThread()) { + CompositorThread()->Dispatch(task.forget()); } else { // Could happen during startup NS_WARNING("Dropping task posted to updater thread"); diff --git a/gfx/layers/client/CompositableClient.cpp b/gfx/layers/client/CompositableClient.cpp index f9e3ab25cfc4..3a15a36dc742 100644 --- a/gfx/layers/client/CompositableClient.cpp +++ b/gfx/layers/client/CompositableClient.cpp @@ -169,8 +169,7 @@ TextureClientRecycleAllocator* CompositableClient::GetTextureClientRecycler() { barrier.NotifyAll(); }); - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - runnable.forget()); + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch(runnable.forget()); // should stop the thread until done. while (!done) { diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index 2d0b9df09033..dbcefb088395 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -5,57 +5,61 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/layers/TextureClient.h" + #include // for uint8_t, uint32_t, etc -#include "Layers.h" // for Layer, etc + +#include "BufferTexture.h" +#include "IPDLActor.h" +#include "ImageContainer.h" // for PlanarYCbCrData, etc +#include "Layers.h" // for Layer, etc +#include "LayersLogging.h" // for AppendToString +#include "MainThreadUtils.h" #include "gfx2DGlue.h" #include "gfxPlatform.h" // for gfxPlatform -#include "MainThreadUtils.h" +#include "gfxUtils.h" // for gfxUtils::GetAsLZ4Base64Str #include "mozilla/Atomics.h" +#include "mozilla/Mutex.h" #include "mozilla/SchedulerGroup.h" #include "mozilla/StaticPrefs_gfx.h" #include "mozilla/StaticPrefs_layers.h" +#include "mozilla/gfx/2D.h" +#include "mozilla/gfx/DataSurfaceHelpers.h" // for CreateDataSourceSurfaceByCloning +#include "mozilla/gfx/Logging.h" // for gfxDebug #include "mozilla/gfx/gfxVars.h" +#include "mozilla/ipc/CrossProcessSemaphore.h" #include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc #include "mozilla/layers/CompositableForwarder.h" #include "mozilla/layers/ISurfaceAllocator.h" #include "mozilla/layers/ImageBridgeChild.h" #include "mozilla/layers/ImageDataSerializer.h" +#include "mozilla/layers/PTextureChild.h" #include "mozilla/layers/PaintThread.h" +#include "mozilla/layers/ShadowLayers.h" +#include "mozilla/layers/TextureClientOGL.h" #include "mozilla/layers/TextureClientRecycleAllocator.h" #include "mozilla/layers/TextureRecorded.h" -#include "mozilla/Mutex.h" #include "nsDebug.h" // for NS_ASSERTION, NS_WARNING, etc +#include "nsISerialEventTarget.h" #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc -#include "ImageContainer.h" // for PlanarYCbCrData, etc -#include "mozilla/gfx/2D.h" -#include "mozilla/gfx/Logging.h" // for gfxDebug -#include "mozilla/layers/TextureClientOGL.h" -#include "mozilla/layers/PTextureChild.h" -#include "mozilla/gfx/DataSurfaceHelpers.h" // for CreateDataSourceSurfaceByCloning -#include "nsPrintfCString.h" // for nsPrintfCString -#include "LayersLogging.h" // for AppendToString -#include "gfxUtils.h" // for gfxUtils::GetAsLZ4Base64Str -#include "IPDLActor.h" -#include "BufferTexture.h" -#include "mozilla/layers/ShadowLayers.h" -#include "mozilla/ipc/CrossProcessSemaphore.h" +#include "nsPrintfCString.h" // for nsPrintfCString #ifdef XP_WIN +# include "gfx2DGlue.h" +# include "gfxWindowsPlatform.h" # include "mozilla/gfx/DeviceManagerDx.h" # include "mozilla/layers/TextureD3D11.h" # include "mozilla/layers/TextureDIB.h" -# include "gfxWindowsPlatform.h" -# include "gfx2DGlue.h" #endif #ifdef MOZ_X11 -# include "mozilla/layers/TextureClientX11.h" # include "GLXLibrary.h" +# include "mozilla/layers/TextureClientX11.h" #endif #ifdef MOZ_WAYLAND # include -# include "mozilla/widget/nsWaylandDisplay.h" -# include "mozilla/layers/WaylandDMABUFTextureClientOGL.h" + # include "gfxPlatformGtk.h" +# include "mozilla/layers/WaylandDMABUFTextureClientOGL.h" +# include "mozilla/widget/nsWaylandDisplay.h" #endif #ifdef XP_MACOSX @@ -490,12 +494,12 @@ void DeallocateTextureClient(TextureDeallocParams params) { } TextureChild* actor = params.actor; - MessageLoop* ipdlMsgLoop = nullptr; + nsCOMPtr ipdlThread; if (params.allocator) { - ipdlMsgLoop = params.allocator->GetMessageLoop(); - if (!ipdlMsgLoop) { - // An allocator with no message loop means we are too late in the shutdown + ipdlThread = params.allocator->GetThread(); + if (!ipdlThread) { + // An allocator with no thread means we are too late in the shutdown // sequence. gfxCriticalError() << "Texture deallocated too late during shutdown"; return; @@ -503,19 +507,19 @@ void DeallocateTextureClient(TextureDeallocParams params) { } // First make sure that the work is happening on the IPDL thread. - if (ipdlMsgLoop && MessageLoop::current() != ipdlMsgLoop) { + if (ipdlThread && !ipdlThread->IsOnCurrentThread()) { if (params.syncDeallocation) { bool done = false; ReentrantMonitor barrier("DeallocateTextureClient"); ReentrantMonitorAutoEnter autoMon(barrier); - ipdlMsgLoop->PostTask(NewRunnableFunction( + ipdlThread->Dispatch(NewRunnableFunction( "DeallocateTextureClientSyncProxyRunnable", DeallocateTextureClientSyncProxy, params, &barrier, &done)); while (!done) { barrier.Wait(); } } else { - ipdlMsgLoop->PostTask(NewRunnableFunction( + ipdlThread->Dispatch(NewRunnableFunction( "DeallocateTextureClientRunnable", DeallocateTextureClient, params)); } // The work has been forwarded to the IPDL thread, we are done. @@ -525,8 +529,8 @@ void DeallocateTextureClient(TextureDeallocParams params) { // Below this line, we are either in the IPDL thread or ther is no IPDL // thread anymore. - if (!ipdlMsgLoop) { - // If we don't have a message loop we can't know for sure that we are in + if (!ipdlThread) { + // If we don't have a thread we can't know for sure that we are in // the IPDL thread and use the LayersIPCChannel. // This should ideally not happen outside of gtest, but some shutdown // raciness could put us in this situation. @@ -978,15 +982,14 @@ static void CancelTextureClientNotifyNotUsed(uint64_t aTextureId, if (!aAllocator) { return; } - MessageLoop* msgLoop = nullptr; - msgLoop = aAllocator->GetMessageLoop(); - if (!msgLoop) { + nsCOMPtr thread = aAllocator->GetThread(); + if (!thread) { return; } - if (MessageLoop::current() == msgLoop) { + if (thread->IsOnCurrentThread()) { aAllocator->CancelWaitForNotifyNotUsed(aTextureId); } else { - msgLoop->PostTask(NewRunnableFunction( + thread->Dispatch(NewRunnableFunction( "CancelTextureClientNotifyNotUsedRunnable", CancelTextureClientNotifyNotUsed, aTextureId, aAllocator)); } @@ -1017,9 +1020,8 @@ void TextureClient::SetRecycleAllocator( } bool TextureClient::InitIPDLActor(CompositableForwarder* aForwarder) { - MOZ_ASSERT(aForwarder && - aForwarder->GetTextureForwarder()->GetMessageLoop() == - mAllocator->GetMessageLoop()); + MOZ_ASSERT(aForwarder && aForwarder->GetTextureForwarder()->GetThread() == + mAllocator->GetThread()); if (mActor && !mActor->IPCOpen()) { return false; @@ -1112,8 +1114,8 @@ bool TextureClient::InitIPDLActor(CompositableForwarder* aForwarder) { bool TextureClient::InitIPDLActor(KnowsCompositor* aKnowsCompositor) { MOZ_ASSERT(aKnowsCompositor && - aKnowsCompositor->GetTextureForwarder()->GetMessageLoop() == - mAllocator->GetMessageLoop()); + aKnowsCompositor->GetTextureForwarder()->GetThread() == + mAllocator->GetThread()); TextureForwarder* fwd = aKnowsCompositor->GetTextureForwarder(); if (mActor && !mActor->mDestroyed) { CompositableForwarder* currentFwd = mActor->mCompositableForwarder; diff --git a/gfx/layers/client/TextureClientRecycleAllocator.cpp b/gfx/layers/client/TextureClientRecycleAllocator.cpp index b7c09235bbd9..f1f1aac82233 100644 --- a/gfx/layers/client/TextureClientRecycleAllocator.cpp +++ b/gfx/layers/client/TextureClientRecycleAllocator.cpp @@ -153,7 +153,7 @@ already_AddRefed TextureClientRecycleAllocator::CreateOrRecycle( new TextureClientReleaseTask(textureHolder->GetTextureClient()); textureHolder->ClearTextureClient(); textureHolder = nullptr; - mKnowsCompositor->GetTextureForwarder()->GetMessageLoop()->PostTask( + mKnowsCompositor->GetTextureForwarder()->GetThread()->Dispatch( task.forget()); } else { textureHolder->GetTextureClient()->RecycleTexture( diff --git a/gfx/layers/ipc/CanvasThread.cpp b/gfx/layers/ipc/CanvasThread.cpp index dd2ca8a19f65..c6d66b76fae1 100644 --- a/gfx/layers/ipc/CanvasThread.cpp +++ b/gfx/layers/ipc/CanvasThread.cpp @@ -34,8 +34,8 @@ CanvasThreadHolder::CanvasThreadHolder( CanvasThreadHolder::~CanvasThreadHolder() { // Note we can't just use NS_IsInCompositorThread() here because // sCompositorThreadHolder might have already gone. - MOZ_ASSERT(mCompositorThreadKeepAlive->GetCompositorThread()->thread_id() == - PlatformThread::CurrentId()); + MOZ_ASSERT( + mCompositorThreadKeepAlive->GetCompositorThread()->IsOnCurrentThread()); } /* static */ @@ -75,8 +75,7 @@ void CanvasThreadHolder::StaticRelease( RefPtr threadHolder = aCanvasThreadHolder; // Note we can't just use NS_IsInCompositorThread() here because // sCompositorThreadHolder might have already gone. - MOZ_ASSERT(threadHolder->mCompositorThreadKeepAlive->GetCompositorThread() - ->thread_id() == PlatformThread::CurrentId()); + MOZ_ASSERT(threadHolder->mCompositorThreadKeepAlive->IsInCompositorThread()); threadHolder = nullptr; auto lockedCanvasThreadHolder = sCanvasThreadHolder.Lock(); @@ -89,12 +88,11 @@ void CanvasThreadHolder::StaticRelease( void CanvasThreadHolder::ReleaseOnCompositorThread( already_AddRefed aCanvasThreadHolder) { auto lockedCanvasThreadHolder = sCanvasThreadHolder.Lock(); - base::Thread* compositorThread = - lockedCanvasThreadHolder.ref() - ->mCompositorThreadKeepAlive->GetCompositorThread(); - compositorThread->message_loop()->PostTask(NewRunnableFunction( - "CanvasThreadHolder::StaticRelease", CanvasThreadHolder::StaticRelease, - std::move(aCanvasThreadHolder))); + lockedCanvasThreadHolder.ref() + ->mCompositorThreadKeepAlive->GetCompositorThread() + ->Dispatch(NewRunnableFunction("CanvasThreadHolder::StaticRelease", + CanvasThreadHolder::StaticRelease, + std::move(aCanvasThreadHolder))); } /* static */ diff --git a/gfx/layers/ipc/CompositorBridgeChild.cpp b/gfx/layers/ipc/CompositorBridgeChild.cpp index f3ec57613d64..b972ee416506 100644 --- a/gfx/layers/ipc/CompositorBridgeChild.cpp +++ b/gfx/layers/ipc/CompositorBridgeChild.cpp @@ -9,7 +9,6 @@ #include "mozilla/layers/CompositorThread.h" #include // for size_t #include "ClientLayerManager.h" // for ClientLayerManager -#include "base/message_loop.h" // for MessageLoop #include "base/task.h" // for NewRunnableMethod, etc #include "mozilla/StaticPrefs_layers.h" #include "mozilla/layers/CompositorManagerChild.h" @@ -36,7 +35,6 @@ #include "nsDebug.h" // for NS_WARNING #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc #include "nsTArray.h" // for nsTArray, nsTArray_Impl -#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop, etc #include "FrameLayerBuilder.h" #include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/BrowserParent.h" @@ -85,7 +83,7 @@ CompositorBridgeChild::CompositorBridgeChild(CompositorManagerChild* aManager) mCanSend(false), mActorDestroyed(false), mFwdTransactionId(0), - mMessageLoop(MessageLoop::current()), + mThread(NS_GetCurrentThread()), mProcessToken(0), mSectionAllocator(nullptr), mPaintLock("CompositorBridgeChild.mPaintLock"), @@ -168,7 +166,7 @@ void CompositorBridgeChild::Destroy() { // We may have already called destroy but still have lingering references // or CompositorBridgeChild::ActorDestroy was called. Ensure that we do our // post destroy clean up no matter what. It is safe to call multiple times. - MessageLoop::current()->PostTask( + NS_GetCurrentThread()->Dispatch( NewRunnableMethod("CompositorBridgeChild::PrepareFinalDestroy", selfRef, &CompositorBridgeChild::PrepareFinalDestroy)); return; @@ -225,12 +223,12 @@ void CompositorBridgeChild::Destroy() { // CompositorBridgeParent to the CompositorBridgeChild (e.g. caused by the // destruction of shared memory). We need to ensure this gets processed by the // CompositorBridgeChild before it gets destroyed. It suffices to ensure that - // events already in the MessageLoop get processed before the - // CompositorBridgeChild is destroyed, so we add a task to the MessageLoop to + // events already in the thread get processed before the + // CompositorBridgeChild is destroyed, so we add a task to the thread to // handle compositor destruction. // From now on we can't send any message message. - MessageLoop::current()->PostTask( + NS_GetCurrentThread()->Dispatch( NewRunnableMethod("CompositorBridgeChild::PrepareFinalDestroy", selfRef, &CompositorBridgeChild::PrepareFinalDestroy)); } @@ -470,8 +468,8 @@ mozilla::ipc::IPCResult CompositorBridgeChild::RecvUpdatePluginConfigurations( #if defined(XP_WIN) static void ScheduleSendAllPluginsCaptured(CompositorBridgeChild* aThis, - MessageLoop* aLoop) { - aLoop->PostTask(NewNonOwningRunnableMethod( + nsISerialEventTarget* aThread) { + aThread->Dispatch(NewNonOwningRunnableMethod( "CompositorBridgeChild::SendAllPluginsCaptured", aThis, &CompositorBridgeChild::SendAllPluginsCaptured)); } @@ -483,12 +481,11 @@ mozilla::ipc::IPCResult CompositorBridgeChild::RecvCaptureAllPlugins( MOZ_ASSERT(NS_IsMainThread()); nsIWidget::CaptureRegisteredPlugins(aParentWidget); - // Bounce the call to SendAllPluginsCaptured off the ImageBridgeChild loop, + // Bounce the call to SendAllPluginsCaptured off the ImageBridgeChild thread, // to make sure that the image updates on that thread have been processed. - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - NewRunnableFunction("ScheduleSendAllPluginsCapturedRunnable", - &ScheduleSendAllPluginsCaptured, this, - MessageLoop::current())); + ImageBridgeChild::GetSingleton()->GetThread()->Dispatch(NewRunnableFunction( + "ScheduleSendAllPluginsCapturedRunnable", &ScheduleSendAllPluginsCaptured, + this, NS_GetCurrentThread())); return IPC_OK(); #else MOZ_ASSERT_UNREACHABLE( diff --git a/gfx/layers/ipc/CompositorBridgeChild.h b/gfx/layers/ipc/CompositorBridgeChild.h index c215fe70f9de..71c9d6ec706d 100644 --- a/gfx/layers/ipc/CompositorBridgeChild.h +++ b/gfx/layers/ipc/CompositorBridgeChild.h @@ -200,7 +200,7 @@ class CompositorBridgeChild final : public PCompositorBridgeChild, void HandleMemoryPressure(); - MessageLoop* GetMessageLoop() const override { return mMessageLoop; } + nsISerialEventTarget* GetThread() const override { return mThread; } base::ProcessId GetParentPid() const override { return OtherPid(); } @@ -373,7 +373,7 @@ class CompositorBridgeChild final : public PCompositorBridgeChild, std::unordered_map> mTexturesWaitingNotifyNotUsed; - MessageLoop* mMessageLoop; + nsCOMPtr mThread; AutoTArray, 2> mTexturePools; diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index f959a25c8ea0..6e5478358c5a 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -14,10 +14,7 @@ #include "apz/src/APZCTreeManager.h" // for APZCTreeManager #include "LayerTransactionParent.h" // for LayerTransactionParent #include "RenderTrace.h" // for RenderTraceLayers -#include "base/message_loop.h" // for MessageLoop #include "base/process.h" // for ProcessId -#include "base/task.h" // for CancelableTask, etc -#include "base/thread.h" // for Thread #include "gfxContext.h" // for gfxContext #include "gfxPlatform.h" // for gfxPlatform #include "TreeTraversal.h" // for ForEachNode @@ -80,7 +77,6 @@ #include "nsIWidget.h" // for nsIWidget #include "nsTArray.h" // for nsTArray #include "nsThreadUtils.h" // for NS_IsMainThread -#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop #ifdef XP_WIN # include "mozilla/layers/CompositorD3D11.h" # include "mozilla/widget/WinCompositorWidget.h" @@ -174,10 +170,6 @@ bool CompositorBridgeParentBase::DeallocShmem(ipc::Shmem& aShmem) { return PCompositorBridgeParent::DeallocShmem(aShmem); } -static inline MessageLoop* CompositorLoop() { - return CompositorThreadHolder::Loop(); -} - base::ProcessId CompositorBridgeParentBase::RemotePid() { return OtherPid(); } bool CompositorBridgeParentBase::StartSharingMetrics( @@ -185,8 +177,8 @@ bool CompositorBridgeParentBase::StartSharingMetrics( CrossProcessMutexHandle aMutexHandle, LayersId aLayersId, uint32_t aApzcId) { if (!CompositorThreadHolder::IsInCompositorThread()) { - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch( NewRunnableMethod( "layers::CompositorBridgeParent::StartSharingMetrics", this, @@ -206,8 +198,8 @@ bool CompositorBridgeParentBase::StartSharingMetrics( bool CompositorBridgeParentBase::StopSharingMetrics( ScrollableLayerGuid::ViewID aScrollId, uint32_t aApzcId) { if (!CompositorThreadHolder::IsInCompositorThread()) { - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch( NewRunnableMethod( "layers::CompositorBridgeParent::StopSharingMetrics", this, &CompositorBridgeParentBase::StopSharingMetrics, aScrollId, @@ -404,8 +396,8 @@ void CompositorBridgeParent::Initialize() { // FIXME: This holds on the the fact that right now the only thing that // can destroy this instance is initialized on the compositor thread after // this task has been processed. - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableFunction( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch(NewRunnableFunction( "AddCompositorRunnable", &AddCompositor, this, &mCompositorBridgeID)); { // scope lock @@ -680,22 +672,22 @@ void CompositorBridgeParent::ActorDestroy(ActorDestroyReason why) { // on this thread. We must keep the compositor parent alive untill the code // handling message reception is finished on this thread. mSelfRef = this; - MessageLoop::current()->PostTask( + NS_GetCurrentThread()->Dispatch( NewRunnableMethod("layers::CompositorBridgeParent::DeferredDestroy", this, &CompositorBridgeParent::DeferredDestroy)); } void CompositorBridgeParent::ScheduleRenderOnCompositorThread( const wr::RenderRootSet& aRenderRoots) { - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch(NewRunnableMethod( "layers::CompositorBridgeParent::ScheduleComposition", this, &CompositorBridgeParent::ScheduleComposition, aRenderRoots)); } void CompositorBridgeParent::InvalidateOnCompositorThread() { - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch( NewRunnableMethod("layers::CompositorBridgeParent::Invalidate", this, &CompositorBridgeParent::Invalidate)); } @@ -793,8 +785,8 @@ void CompositorBridgeParent::ResumeCompositionAndResize(int x, int y, int width, void CompositorBridgeParent::SchedulePauseOnCompositorThread() { MonitorAutoLock lock(mPauseCompositionMonitor); - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch( NewRunnableMethod("layers::CompositorBridgeParent::PauseComposition", this, &CompositorBridgeParent::PauseComposition)); @@ -805,8 +797,8 @@ void CompositorBridgeParent::SchedulePauseOnCompositorThread() { bool CompositorBridgeParent::ScheduleResumeOnCompositorThread() { MonitorAutoLock lock(mResumeCompositionMonitor); - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch( NewRunnableMethod("layers::CompositorBridgeParent::ResumeComposition", this, &CompositorBridgeParent::ResumeComposition)); @@ -821,8 +813,8 @@ bool CompositorBridgeParent::ScheduleResumeOnCompositorThread(int x, int y, int height) { MonitorAutoLock lock(mResumeCompositionMonitor); - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch(NewRunnableMethod( "layers::CompositorBridgeParent::ResumeCompositionAndResize", this, &CompositorBridgeParent::ResumeCompositionAndResize, x, y, width, height)); @@ -1226,9 +1218,9 @@ void CompositorBridgeParent::ScheduleRotationOnCompositorThread( &CompositorBridgeParent::ForceComposition); mForceCompositionTask = task; if (StaticPrefs::layers_orientation_sync_timeout() == 0) { - CompositorThreadHolder::Loop()->PostTask(task.forget()); + CompositorThread()->Dispatch(task.forget()); } else { - CompositorThreadHolder::Loop()->PostDelayedTask( + CompositorThread()->DelayedDispatch( task.forget(), StaticPrefs::layers_orientation_sync_timeout()); } } @@ -1987,13 +1979,13 @@ void CompositorBridgeParent::InitializeStatics() { /*static*/ void CompositorBridgeParent::UpdateQualitySettings() { if (!CompositorThreadHolder::IsInCompositorThread()) { - if (CompositorLoop()) { - CompositorLoop()->PostTask( + if (CompositorThread()) { + CompositorThread()->Dispatch( NewRunnableFunction("CompositorBridgeParent::UpdateQualitySettings", &CompositorBridgeParent::UpdateQualitySettings)); } - // If there is no compositor loop, e.g. due to shutdown, then we can + // If there is no compositor thread, e.g. due to shutdown, then we can // safefully just ignore this request. return; } @@ -2007,13 +1999,13 @@ void CompositorBridgeParent::UpdateQualitySettings() { /*static*/ void CompositorBridgeParent::UpdateDebugFlags() { if (!CompositorThreadHolder::IsInCompositorThread()) { - if (CompositorLoop()) { - CompositorLoop()->PostTask( + if (CompositorThread()) { + CompositorThread()->Dispatch( NewRunnableFunction("CompositorBridgeParent::UpdateDebugFlags", &CompositorBridgeParent::UpdateDebugFlags)); } - // If there is no compositor loop, e.g. due to shutdown, then we can + // If there is no compositor thread, e.g. due to shutdown, then we can // safefully just ignore this request. return; } @@ -2027,8 +2019,8 @@ void CompositorBridgeParent::UpdateDebugFlags() { /*static*/ void CompositorBridgeParent::UpdateWebRenderMultithreading() { if (!CompositorThreadHolder::IsInCompositorThread()) { - if (CompositorLoop()) { - CompositorLoop()->PostTask(NewRunnableFunction( + if (CompositorThread()) { + CompositorThread()->Dispatch(NewRunnableFunction( "CompositorBridgeParent::UpdateWebRenderMultithreading", &CompositorBridgeParent::UpdateWebRenderMultithreading)); } @@ -2045,8 +2037,8 @@ void CompositorBridgeParent::UpdateWebRenderMultithreading() { /*static*/ void CompositorBridgeParent::UpdateWebRenderBatchingParameters() { if (!CompositorThreadHolder::IsInCompositorThread()) { - if (CompositorLoop()) { - CompositorLoop()->PostTask(NewRunnableFunction( + if (CompositorThread()) { + CompositorThread()->Dispatch(NewRunnableFunction( "CompositorBridgeParent::UpdateWebRenderBatchingParameters", &CompositorBridgeParent::UpdateWebRenderBatchingParameters)); } @@ -2095,11 +2087,11 @@ void CompositorBridgeParent::DeallocateLayerTreeId(LayersId aId) { // Here main thread notifies compositor to remove an element from // sIndirectLayerTrees. This removed element might be queried soon. // Checking the elements of sIndirectLayerTrees exist or not before using. - if (!CompositorLoop()) { - gfxCriticalError() << "Attempting to post to a invalid Compositor Loop"; + if (!CompositorThread()) { + gfxCriticalError() << "Attempting to post to an invalid Compositor Thread"; return; } - CompositorLoop()->PostTask( + CompositorThread()->Dispatch( NewRunnableFunction("EraseLayerStateRunnable", &EraseLayerState, aId)); } @@ -2131,7 +2123,7 @@ void CompositorBridgeParent::SetControllerForLayerTree( LayersId aLayersId, GeckoContentController* aController) { // This ref is adopted by UpdateControllerForLayersId(). aController->AddRef(); - CompositorLoop()->PostTask(NewRunnableFunction( + CompositorThread()->Dispatch(NewRunnableFunction( "UpdateControllerForLayersIdRunnable", &UpdateControllerForLayersId, aLayersId, aController)); } @@ -2168,7 +2160,7 @@ void CompositorBridgeParent::PostInsertVsyncProfilerMarker( #if defined(MOZ_GECKO_PROFILER) // Called in the vsync thread if (profiler_is_active() && CompositorThreadHolder::IsActive()) { - CompositorLoop()->PostTask( + CompositorThread()->Dispatch( NewRunnableFunction("InsertVsyncProfilerMarkerRunnable", InsertVsyncProfilerMarker, aVsyncTimestamp)); } @@ -2391,7 +2383,7 @@ void CompositorBridgeParent::NotifyDidComposite(TransactionId aTransactionId, } void CompositorBridgeParent::InvalidateRemoteLayers() { - MOZ_ASSERT(CompositorLoop() == MessageLoop::current()); + MOZ_ASSERT(CompositorThread()->IsOnCurrentThread()); Unused << PCompositorBridgeParent::SendInvalidateLayers(LayersId{0}); @@ -2513,13 +2505,12 @@ bool CompositorBridgeParent::IsSameProcess() const { } void CompositorBridgeParent::NotifyWebRenderContextPurge() { - MOZ_ASSERT(CompositorLoop() == MessageLoop::current()); + MOZ_ASSERT(CompositorThread()->IsOnCurrentThread()); RefPtr api = mWrBridge->GetWebRenderAPI(); - api->ClearAllCaches(); } void CompositorBridgeParent::NotifyWebRenderDisableNativeCompositor() { - MOZ_ASSERT(CompositorLoop() == MessageLoop::current()); + MOZ_ASSERT(CompositorThread()->IsOnCurrentThread()); if (mWrBridge) { mWrBridge->DisableNativeCompositor(); } @@ -2651,8 +2642,8 @@ bool CompositorBridgeParent::UpdatePluginWindowState(LayersId aId) { } void CompositorBridgeParent::ScheduleShowAllPluginWindows() { - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch( NewRunnableMethod("layers::CompositorBridgeParent::ShowAllPluginWindows", this, &CompositorBridgeParent::ShowAllPluginWindows)); } @@ -2664,8 +2655,8 @@ void CompositorBridgeParent::ShowAllPluginWindows() { } void CompositorBridgeParent::ScheduleHideAllPluginWindows() { - MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask( + MOZ_ASSERT(CompositorThread()); + CompositorThread()->Dispatch( NewRunnableMethod("layers::CompositorBridgeParent::HideAllPluginWindows", this, &CompositorBridgeParent::HideAllPluginWindows)); } @@ -2892,7 +2883,7 @@ mozilla::ipc::IPCResult CompositorBridgeParent::RecvEndRecordingToDisk( aResolve(true); } else if (mWrBridge) { mWrBridge->WriteCollectedFrames()->Then( - MessageLoop::current()->SerialEventTarget(), __func__, + NS_GetCurrentThread(), __func__, [resolve{aResolve}](const bool success) { resolve(success); }, [resolve{aResolve}]() { resolve(false); }); } else { @@ -2921,7 +2912,7 @@ mozilla::ipc::IPCResult CompositorBridgeParent::RecvEndRecordingToMemory( } else if (mWrBridge) { RefPtr self = this; mWrBridge->GetCollectedFrames()->Then( - MessageLoop::current()->SerialEventTarget(), __func__, + NS_GetCurrentThread(), __func__, [self, resolve{aResolve}](CollectedFrames&& frames) { resolve(self->WrapCollectedFrames(std::move(frames))); }, diff --git a/gfx/layers/ipc/CompositorBridgeParent.h b/gfx/layers/ipc/CompositorBridgeParent.h index adf3c25bb70f..3722da384fb8 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.h +++ b/gfx/layers/ipc/CompositorBridgeParent.h @@ -47,7 +47,6 @@ #include "mozilla/layers/UiCompositorControllerParent.h" #include "mozilla/VsyncDispatcher.h" -class MessageLoop; class nsIWidget; namespace mozilla { diff --git a/gfx/layers/ipc/CompositorManagerChild.cpp b/gfx/layers/ipc/CompositorManagerChild.cpp index cadfb1088cdf..c01b2fa5db60 100644 --- a/gfx/layers/ipc/CompositorManagerChild.cpp +++ b/gfx/layers/ipc/CompositorManagerChild.cpp @@ -173,9 +173,8 @@ CompositorManagerChild::CompositorManagerChild(CompositorManagerParent* aParent, MOZ_ASSERT(aParent); SetOtherProcessId(base::GetCurrentProcId()); - MessageLoop* loop = CompositorThreadHolder::Loop(); ipc::MessageChannel* channel = aParent->GetIPCChannel(); - if (NS_WARN_IF(!Open(channel, loop, ipc::ChildSide))) { + if (NS_WARN_IF(!Open(channel, CompositorThread(), ipc::ChildSide))) { return; } diff --git a/gfx/layers/ipc/CompositorManagerParent.cpp b/gfx/layers/ipc/CompositorManagerParent.cpp index 3c997c9f4364..6ffaebc445f1 100644 --- a/gfx/layers/ipc/CompositorManagerParent.cpp +++ b/gfx/layers/ipc/CompositorManagerParent.cpp @@ -68,7 +68,7 @@ bool CompositorManagerParent::Create( NewRunnableMethod&&, bool>( "CompositorManagerParent::Bind", bridge, &CompositorManagerParent::Bind, std::move(aEndpoint), aIsRoot); - CompositorThreadHolder::Loop()->PostTask(runnable.forget()); + CompositorThread()->Dispatch(runnable.forget()); return true; } @@ -201,7 +201,7 @@ void CompositorManagerParent::Shutdown() { MOZ_ASSERT(NS_IsMainThread()); #ifdef COMPOSITOR_MANAGER_PARENT_EXPLICIT_SHUTDOWN - CompositorThreadHolder::Loop()->PostTask(NS_NewRunnableFunction( + CompositorThread()->Dispatch(NS_NewRunnableFunction( "layers::CompositorManagerParent::Shutdown", []() -> void { CompositorManagerParent::ShutdownInternal(); })); #endif @@ -307,7 +307,7 @@ mozilla::ipc::IPCResult CompositorManagerParent::RecvReportMemory( // thread, so we can't just pass it over to the renderer thread. We use // an intermediate MozPromise instead. wr::RenderThread::AccumulateMemoryReport(aggregate)->Then( - CompositorThreadHolder::Loop()->SerialEventTarget(), __func__, + CompositorThread(), __func__, [resolver = std::move(aResolver)](MemoryReport aReport) { resolver(aReport); }, diff --git a/gfx/layers/ipc/CompositorThread.cpp b/gfx/layers/ipc/CompositorThread.cpp index 9fc9eaa1438d..b1ccf8f2409c 100644 --- a/gfx/layers/ipc/CompositorThread.cpp +++ b/gfx/layers/ipc/CompositorThread.cpp @@ -19,17 +19,12 @@ namespace layers { static StaticRefPtr sCompositorThreadHolder; static bool sFinishedCompositorShutDown = false; -base::Thread* CompositorThread() { +nsISerialEventTarget* CompositorThread() { return sCompositorThreadHolder ? sCompositorThreadHolder->GetCompositorThread() : nullptr; } -/* static */ -MessageLoop* CompositorThreadHolder::Loop() { - return CompositorThread() ? CompositorThread()->message_loop() : nullptr; -} - CompositorThreadHolder* CompositorThreadHolder::GetSingleton() { return sCompositorThreadHolder; } @@ -41,57 +36,40 @@ CompositorThreadHolder::CompositorThreadHolder() CompositorThreadHolder::~CompositorThreadHolder() { MOZ_ASSERT(NS_IsMainThread()); - if (mCompositorThread) { - DestroyCompositorThread(mCompositorThread); - } -} - -/* static */ -void CompositorThreadHolder::DestroyCompositorThread( - base::Thread* aCompositorThread) { - MOZ_ASSERT(NS_IsMainThread()); - - MOZ_ASSERT(!sCompositorThreadHolder, - "We shouldn't be destroying the compositor thread yet."); - - delete aCompositorThread; sFinishedCompositorShutDown = true; } -/* static */ base::Thread* CompositorThreadHolder::CreateCompositorThread() { +/* static */ already_AddRefed +CompositorThreadHolder::CreateCompositorThread() { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!sCompositorThreadHolder, "The compositor thread has already been started!"); - base::Thread* compositorThread = new base::Thread("Compositor"); + nsCOMPtr compositorThread; + nsresult rv = + NS_NewNamedThread("Compositor", getter_AddRefs(compositorThread)); - base::Thread::Options options; - /* Timeout values are powers-of-two to enable us get better data. - 128ms is chosen for transient hangs because 8Hz should be the minimally - acceptable goal for Compositor responsiveness (normal goal is 60Hz). */ - options.transient_hang_timeout = 128; // milliseconds - /* 2048ms is chosen for permanent hangs because it's longer than most - * Compositor hangs seen in the wild, but is short enough to not miss getting - * native hang stacks. */ - options.permanent_hang_timeout = 2048; // milliseconds -#if defined(_WIN32) - /* With d3d9 the compositor thread creates native ui, see DeviceManagerD3D9. - * As such the thread is a gui thread, and must process a windows message - * queue or - * risk deadlocks. Chromium message loop TYPE_UI does exactly what we need. */ - options.message_loop_type = MessageLoop::TYPE_UI; -#endif + // TODO re-enable hangout monitor. Will be done in a follow-up thread + // base::Thread::Options options; + // /* Timeout values are powers-of-two to enable us get better data. + // 128ms is chosen for transient hangs because 8Hz should be the minimally + // acceptable goal for Compositor responsiveness (normal goal is 60Hz). */ + // options.transient_hang_timeout = 128; // milliseconds + // /* 2048ms is chosen for permanent hangs because it's longer than most + // * Compositor hangs seen in the wild, but is short enough to not miss + // getting + // * native hang stacks. */ + // options.permanent_hang_timeout = 2048; // milliseconds - if (!compositorThread->StartWithOptions(options)) { - delete compositorThread; + if (NS_FAILED(rv)) { return nullptr; } CompositorBridgeParent::Setup(); ImageBridgeParent::Setup(); - return compositorThread; + return compositorThread.forget(); } void CompositorThreadHolder::Start() { @@ -136,8 +114,12 @@ void CompositorThreadHolder::Shutdown() { /* static */ bool CompositorThreadHolder::IsInCompositorThread() { - return CompositorThread() && - CompositorThread()->thread_id() == PlatformThread::CurrentId(); + if (!CompositorThread()) { + return false; + } + bool in = false; + MOZ_ALWAYS_SUCCEEDS(CompositorThread()->IsOnCurrentThread(&in)); + return in; } } // namespace layers diff --git a/gfx/layers/ipc/CompositorThread.h b/gfx/layers/ipc/CompositorThread.h index 831d42ad47b0..f45e31c90baf 100644 --- a/gfx/layers/ipc/CompositorThread.h +++ b/gfx/layers/ipc/CompositorThread.h @@ -6,13 +6,12 @@ #ifndef mozilla_layers_CompositorThread_h #define mozilla_layers_CompositorThread_h -#include "base/basictypes.h" // for DISALLOW_EVIL_CONSTRUCTORS -#include "base/platform_thread.h" // for PlatformThreadId -#include "base/thread.h" // for Thread -#include "base/message_loop.h" #include "nsISupportsImpl.h" #include "ThreadSafeRefcountingWithMainThreadDestruction.h" +class nsISerialEventTarget; +class nsIThread; + namespace mozilla { namespace layers { @@ -23,7 +22,9 @@ class CompositorThreadHolder final { public: CompositorThreadHolder(); - base::Thread* GetCompositorThread() const { return mCompositorThread; } + nsISerialEventTarget* GetCompositorThread() const { + return mCompositorThread; + } static CompositorThreadHolder* GetSingleton(); @@ -40,23 +41,20 @@ class CompositorThreadHolder final { */ static void Shutdown(); - static MessageLoop* Loop(); - // Returns true if the calling thread is the compositor thread. static bool IsInCompositorThread(); private: ~CompositorThreadHolder(); - base::Thread* const mCompositorThread; + nsCOMPtr mCompositorThread; - static base::Thread* CreateCompositorThread(); - static void DestroyCompositorThread(base::Thread* aCompositorThread); + static already_AddRefed CreateCompositorThread(); friend class CompositorBridgeParent; }; -base::Thread* CompositorThread(); +nsISerialEventTarget* CompositorThread(); } // namespace layers } // namespace mozilla diff --git a/gfx/layers/ipc/CompositorVsyncScheduler.cpp b/gfx/layers/ipc/CompositorVsyncScheduler.cpp index 911ac3c182d4..d00a7fae73ea 100644 --- a/gfx/layers/ipc/CompositorVsyncScheduler.cpp +++ b/gfx/layers/ipc/CompositorVsyncScheduler.cpp @@ -110,24 +110,24 @@ void CompositorVsyncScheduler::Destroy() { void CompositorVsyncScheduler::PostCompositeTask( VsyncId aId, TimeStamp aCompositeTimestamp) { MonitorAutoLock lock(mCurrentCompositeTaskMonitor); - if (mCurrentCompositeTask == nullptr && CompositorThreadHolder::Loop()) { + if (mCurrentCompositeTask == nullptr && CompositorThread()) { RefPtr task = NewCancelableRunnableMethod( "layers::CompositorVsyncScheduler::Composite", this, &CompositorVsyncScheduler::Composite, aId, aCompositeTimestamp); mCurrentCompositeTask = task; - ScheduleTask(task.forget()); + CompositorThread()->Dispatch(task.forget()); } } void CompositorVsyncScheduler::PostVRTask(TimeStamp aTimestamp) { MonitorAutoLock lockVR(mCurrentVRTaskMonitor); - if (mCurrentVRTask == nullptr && CompositorThreadHolder::Loop()) { + if (mCurrentVRTask == nullptr && CompositorThread()) { RefPtr task = NewCancelableRunnableMethod( "layers::CompositorVsyncScheduler::DispatchVREvents", this, &CompositorVsyncScheduler::DispatchVREvents, aTimestamp); mCurrentVRTask = task; - CompositorThreadHolder::Loop()->PostDelayedTask(task.forget(), 0); + CompositorThread()->Dispatch(task.forget()); } } @@ -329,12 +329,6 @@ void CompositorVsyncScheduler::DispatchVREvents(TimeStamp aVsyncTimestamp) { vm->NotifyVsync(aVsyncTimestamp); } -void CompositorVsyncScheduler::ScheduleTask( - already_AddRefed aTask) { - MOZ_ASSERT(CompositorThreadHolder::Loop()); - CompositorThreadHolder::Loop()->PostDelayedTask(std::move(aTask), 0); -} - const TimeStamp& CompositorVsyncScheduler::GetLastComposeTime() const { MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); return mLastCompose; diff --git a/gfx/layers/ipc/CompositorVsyncScheduler.h b/gfx/layers/ipc/CompositorVsyncScheduler.h index c4393324ee4c..bb033404aefb 100644 --- a/gfx/layers/ipc/CompositorVsyncScheduler.h +++ b/gfx/layers/ipc/CompositorVsyncScheduler.h @@ -109,9 +109,6 @@ class CompositorVsyncScheduler { private: virtual ~CompositorVsyncScheduler(); - // Schedule a task to run on the compositor thread. - void ScheduleTask(already_AddRefed); - // Post a task to run Composite() on the compositor thread, if there isn't // such a task already queued. Can be called from any thread. void PostCompositeTask(VsyncId aId, TimeStamp aCompositeTimestamp); diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index 9a09dbd88135..271ec4913dd3 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -10,7 +10,6 @@ #include "ImageContainer.h" // for ImageContainer #include "Layers.h" // for Layer, etc #include "ShadowLayers.h" // for ShadowLayerForwarder -#include "base/message_loop.h" // for MessageLoop #include "base/platform_thread.h" // for PlatformThread #include "base/process.h" // for ProcessId #include "base/task.h" // for NewRunnableFunction, etc @@ -38,8 +37,8 @@ #include "nsISupportsImpl.h" // for ImageContainer::AddRef, etc #include "nsTArray.h" // for AutoTArray, nsTArray, etc #include "nsTArrayForwardDeclare.h" // for AutoTArray +#include "nsThread.h" #include "nsThreadUtils.h" // for NS_IsMainThread -#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop #include "mozilla/StaticMutex.h" #include "mozilla/StaticPtr.h" // for StaticRefPtr #include "mozilla/layers/TextureClient.h" @@ -172,7 +171,10 @@ void ImageBridgeChild::CancelWaitForNotifyNotUsed(uint64_t aTextureId) { // Singleton static StaticMutex sImageBridgeSingletonLock; static StaticRefPtr sImageBridgeChildSingleton; -static Thread* sImageBridgeChildThread = nullptr; +// sImageBridgeChildThread cannot be converted to use a generic +// nsISerialEventTarget (which may be backed by a threadpool) until bug 1634846 +// is addressed. Therefore we keep it as an nsIThread here. +static StaticRefPtr sImageBridgeChildThread; // dispatched function void ImageBridgeChild::ShutdownStep1(SynchronousTask* aTask) { @@ -293,8 +295,6 @@ void ImageBridgeChild::ForgetImageContainer(const CompositableHandle& aHandle) { mImageContainerListeners.erase(aHandle.Value()); } -Thread* ImageBridgeChild::GetThread() const { return sImageBridgeChildThread; } - /* static */ RefPtr ImageBridgeChild::GetSingleton() { StaticMutexAutoLock lock(sImageBridgeSingletonLock); @@ -310,7 +310,7 @@ void ImageBridgeChild::UpdateImageClient(RefPtr aContainer) { RefPtr runnable = WrapRunnable(RefPtr(this), &ImageBridgeChild::UpdateImageClient, aContainer); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); return; } @@ -355,7 +355,7 @@ void ImageBridgeChild::UpdateAsyncCanvasRenderer( RefPtr runnable = WrapRunnable( RefPtr(this), &ImageBridgeChild::UpdateAsyncCanvasRendererSync, &task, aWrapper); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); } @@ -409,7 +409,7 @@ void ImageBridgeChild::FlushAllImages(ImageClient* aClient, RefPtr runnable = WrapRunnable( RefPtr(this), &ImageBridgeChild::FlushAllImagesSync, &task, aClient, aContainer); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); } @@ -454,9 +454,11 @@ bool ImageBridgeChild::InitForContent(Endpoint&& aEndpoint, gfxPlatform::GetPlatform(); if (!sImageBridgeChildThread) { - sImageBridgeChildThread = new Thread("ImageBridgeChild"); - bool success = sImageBridgeChildThread->Start(); - MOZ_RELEASE_ASSERT(success, "Failed to start ImageBridgeChild thread!"); + nsCOMPtr thread; + nsresult rv = NS_NewNamedThread("ImageBridgeChld", getter_AddRefs(thread)); + MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv), + "Failed to start ImageBridgeChild thread!"); + sImageBridgeChildThread = thread.forget(); } RefPtr child = new ImageBridgeChild(aNamespace); @@ -464,7 +466,7 @@ bool ImageBridgeChild::InitForContent(Endpoint&& aEndpoint, RefPtr runnable = NewRunnableMethod&&>( "layers::ImageBridgeChild::Bind", child, &ImageBridgeChild::Bind, std::move(aEndpoint)); - child->GetMessageLoop()->PostTask(runnable.forget()); + child->GetThread()->Dispatch(runnable.forget()); // Assign this after so other threads can't post messages before we connect to // IPDL. @@ -501,9 +503,8 @@ void ImageBridgeChild::Bind(Endpoint&& aEndpoint) { } void ImageBridgeChild::BindSameProcess(RefPtr aParent) { - MessageLoop* parentMsgLoop = aParent->GetMessageLoop(); ipc::MessageChannel* parentChannel = aParent->GetIPCChannel(); - Open(parentChannel, parentMsgLoop, mozilla::ipc::ChildSide); + Open(parentChannel, aParent->GetThread(), mozilla::ipc::ChildSide); // This reference is dropped in DeallocPImageBridgeChild. this->AddRef(); @@ -517,7 +518,6 @@ void ImageBridgeChild::ShutDown() { ShutdownSingleton(); - delete sImageBridgeChildThread; sImageBridgeChildThread = nullptr; } @@ -540,7 +540,7 @@ void ImageBridgeChild::WillShutdown() { RefPtr runnable = WrapRunnable(RefPtr(this), &ImageBridgeChild::ShutdownStep1, &task); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); } @@ -551,7 +551,7 @@ void ImageBridgeChild::WillShutdown() { RefPtr runnable = WrapRunnable(RefPtr(this), &ImageBridgeChild::ShutdownStep2, &task); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); } @@ -563,17 +563,18 @@ void ImageBridgeChild::InitSameProcess(uint32_t aNamespace) { MOZ_ASSERT(!sImageBridgeChildSingleton); MOZ_ASSERT(!sImageBridgeChildThread); - sImageBridgeChildThread = new Thread("ImageBridgeChild"); - if (!sImageBridgeChildThread->IsRunning()) { - sImageBridgeChildThread->Start(); - } + nsCOMPtr thread; + nsresult rv = NS_NewNamedThread("ImageBridgeChld", getter_AddRefs(thread)); + MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv), + "Failed to start ImageBridgeChild thread!"); + sImageBridgeChildThread = thread.forget(); RefPtr child = new ImageBridgeChild(aNamespace); RefPtr parent = ImageBridgeParent::CreateSameProcess(); RefPtr runnable = WrapRunnable(child, &ImageBridgeChild::BindSameProcess, parent); - child->GetMessageLoop()->PostTask(runnable.forget()); + child->GetThread()->Dispatch(runnable.forget()); // Assign this after so other threads can't post messages before we connect to // IPDL. @@ -590,15 +591,15 @@ void ImageBridgeChild::InitWithGPUProcess( MOZ_ASSERT(!sImageBridgeChildSingleton); MOZ_ASSERT(!sImageBridgeChildThread); - sImageBridgeChildThread = new Thread("ImageBridgeChild"); - if (!sImageBridgeChildThread->IsRunning()) { - sImageBridgeChildThread->Start(); - } + nsCOMPtr thread; + nsresult rv = NS_NewNamedThread("ImageBridgeChld", getter_AddRefs(thread)); + MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv), + "Failed to start ImageBridgeChild thread!"); + sImageBridgeChildThread = thread.forget(); RefPtr child = new ImageBridgeChild(aNamespace); - MessageLoop* loop = child->GetMessageLoop(); - loop->PostTask(NewRunnableMethod&&>( + child->GetThread()->Dispatch(NewRunnableMethod&&>( "layers::ImageBridgeChild::Bind", child, &ImageBridgeChild::Bind, std::move(aEndpoint))); @@ -612,12 +613,11 @@ void ImageBridgeChild::InitWithGPUProcess( bool InImageBridgeChildThread() { return sImageBridgeChildThread && - sImageBridgeChildThread->thread_id() == PlatformThread::CurrentId(); + sImageBridgeChildThread->IsOnCurrentThread(); } -MessageLoop* ImageBridgeChild::GetMessageLoop() const { - return sImageBridgeChildThread ? sImageBridgeChildThread->message_loop() - : nullptr; +nsISerialEventTarget* ImageBridgeChild::GetThread() const { + return sImageBridgeChildThread; } /* static */ @@ -697,7 +697,7 @@ RefPtr ImageBridgeChild::CreateImageClient( RefPtr runnable = WrapRunnable( RefPtr(this), &ImageBridgeChild::CreateImageClientSync, &task, &result, aType, aImageContainer); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); @@ -733,7 +733,7 @@ already_AddRefed ImageBridgeChild::CreateCanvasClient( RefPtr runnable = WrapRunnable( RefPtr(this), &ImageBridgeChild::CreateCanvasClientSync, &task, aType, aFlag, &result); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); @@ -807,7 +807,7 @@ bool ImageBridgeChild::DispatchAllocShmemInternal( RefPtr runnable = WrapRunnable( RefPtr(this), &ImageBridgeChild::ProxyAllocShmemNow, &task, aSize, aType, aShmem, aUnsafe, &success); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); @@ -844,7 +844,7 @@ bool ImageBridgeChild::DeallocShmem(ipc::Shmem& aShmem) { RefPtr runnable = WrapRunnable( RefPtr(this), &ImageBridgeChild::ProxyDeallocShmemNow, &task, &aShmem, &result); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); return result; @@ -999,7 +999,7 @@ void ImageBridgeChild::ReleaseCompositable(const CompositableHandle& aHandle) { RefPtr runnable = WrapRunnable(RefPtr(this), &ImageBridgeChild::ReleaseCompositable, aHandle); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); return; } diff --git a/gfx/layers/ipc/ImageBridgeChild.h b/gfx/layers/ipc/ImageBridgeChild.h index 646a2a3eccc1..be0fa22a2d9d 100644 --- a/gfx/layers/ipc/ImageBridgeChild.h +++ b/gfx/layers/ipc/ImageBridgeChild.h @@ -25,12 +25,6 @@ #include "mozilla/gfx/Rect.h" #include "mozilla/ReentrantMonitor.h" // for ReentrantMonitor, etc -class MessageLoop; - -namespace base { -class Thread; -} // namespace base - namespace mozilla { namespace ipc { class Shmem; @@ -166,14 +160,7 @@ class ImageBridgeChild final : public PImageBridgeChild, * * Can be called from any thread. */ - base::Thread* GetThread() const; - - /** - * Returns the ImageBridgeChild's message loop. - * - * Can be called from any thread. - */ - MessageLoop* GetMessageLoop() const override; + nsISerialEventTarget* GetThread() const override; base::ProcessId GetParentPid() const override { return OtherPid(); } diff --git a/gfx/layers/ipc/ImageBridgeParent.cpp b/gfx/layers/ipc/ImageBridgeParent.cpp index 2686da89f3d5..b9fd0c8d0df7 100644 --- a/gfx/layers/ipc/ImageBridgeParent.cpp +++ b/gfx/layers/ipc/ImageBridgeParent.cpp @@ -7,7 +7,6 @@ #include "ImageBridgeParent.h" #include // for uint64_t, uint32_t #include "CompositableHost.h" // for CompositableParent, Create -#include "base/message_loop.h" // for MessageLoop #include "base/process.h" // for ProcessId #include "base/task.h" // for CancelableTask, DeleteTask, etc #include "mozilla/ClearOnShutdown.h" @@ -62,9 +61,9 @@ void ImageBridgeParent::Setup() { } } -ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop, +ImageBridgeParent::ImageBridgeParent(nsISerialEventTarget* aThread, ProcessId aChildProcessId) - : mMessageLoop(aLoop), + : mThread(aThread), mClosed(false), mCompositorThreadHolder(CompositorThreadHolder::GetSingleton()) { MOZ_ASSERT(NS_IsMainThread()); @@ -77,7 +76,7 @@ ImageBridgeParent::~ImageBridgeParent() = default; ImageBridgeParent* ImageBridgeParent::CreateSameProcess() { base::ProcessId pid = base::GetCurrentProcId(); RefPtr parent = - new ImageBridgeParent(CompositorThreadHolder::Loop(), pid); + new ImageBridgeParent(CompositorThread(), pid); parent->mSelfRef = parent; { @@ -95,15 +94,15 @@ bool ImageBridgeParent::CreateForGPUProcess( Endpoint&& aEndpoint) { MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_GPU); - MessageLoop* loop = CompositorThreadHolder::Loop(); - if (!loop) { + nsCOMPtr compositorThread = CompositorThread(); + if (!compositorThread) { return false; } RefPtr parent = - new ImageBridgeParent(loop, aEndpoint.OtherPid()); + new ImageBridgeParent(compositorThread, aEndpoint.OtherPid()); - loop->PostTask(NewRunnableMethod&&>( + compositorThread->Dispatch(NewRunnableMethod&&>( "layers::ImageBridgeParent::Bind", parent, &ImageBridgeParent::Bind, std::move(aEndpoint))); @@ -133,7 +132,7 @@ void ImageBridgeParent::ShutdownInternal() { /* static */ void ImageBridgeParent::Shutdown() { - CompositorThreadHolder::Loop()->PostTask(NS_NewRunnableFunction( + CompositorThread()->Dispatch(NS_NewRunnableFunction( "ImageBridgeParent::Shutdown", []() -> void { ImageBridgeParent::ShutdownInternal(); })); } @@ -146,7 +145,7 @@ void ImageBridgeParent::ActorDestroy(ActorDestroyReason aWhy) { MonitorAutoLock lock(*sImageBridgesLock); sImageBridges.erase(OtherPid()); } - MessageLoop::current()->PostTask( + GetThread()->Dispatch( NewRunnableMethod("layers::ImageBridgeParent::DeferredDestroy", this, &ImageBridgeParent::DeferredDestroy)); @@ -219,14 +218,14 @@ mozilla::ipc::IPCResult ImageBridgeParent::RecvUpdate( /* static */ bool ImageBridgeParent::CreateForContent( Endpoint&& aEndpoint) { - MessageLoop* loop = CompositorThreadHolder::Loop(); - if (!loop) { + nsCOMPtr compositorThread = CompositorThread(); + if (!compositorThread) { return false; } RefPtr bridge = - new ImageBridgeParent(loop, aEndpoint.OtherPid()); - loop->PostTask(NewRunnableMethod&&>( + new ImageBridgeParent(compositorThread, aEndpoint.OtherPid()); + compositorThread->Dispatch(NewRunnableMethod&&>( "layers::ImageBridgeParent::Bind", bridge, &ImageBridgeParent::Bind, std::move(aEndpoint))); diff --git a/gfx/layers/ipc/ImageBridgeParent.h b/gfx/layers/ipc/ImageBridgeParent.h index 1c5a30512819..7c5e5cd2d424 100644 --- a/gfx/layers/ipc/ImageBridgeParent.h +++ b/gfx/layers/ipc/ImageBridgeParent.h @@ -19,12 +19,6 @@ #include "nsISupportsImpl.h" #include "nsTArrayForwardDeclare.h" // for nsTArray -class MessageLoop; - -namespace base { -class Thread; -} // namespace base - namespace mozilla { namespace ipc { class Shmem; @@ -45,7 +39,7 @@ class ImageBridgeParent final : public PImageBridgeParent, typedef nsTArray OpDestroyArray; protected: - ImageBridgeParent(MessageLoop* aLoop, ProcessId aChildProcessId); + ImageBridgeParent(nsISerialEventTarget* aThread, ProcessId aChildProcessId); public: virtual ~ImageBridgeParent(); @@ -98,7 +92,7 @@ class ImageBridgeParent final : public PImageBridgeParent, // Shutdown step 1 mozilla::ipc::IPCResult RecvWillClose(); - MessageLoop* GetMessageLoop() const { return mMessageLoop; } + nsISerialEventTarget* GetThread() const { return mThread; } // IShmemAllocator @@ -142,7 +136,7 @@ class ImageBridgeParent final : public PImageBridgeParent, static void ShutdownInternal(); void DeferredDestroy(); - MessageLoop* mMessageLoop; + nsCOMPtr mThread; // This keeps us alive until ActorDestroy(), at which point we do a // deferred destruction of ourselves. RefPtr mSelfRef; diff --git a/gfx/layers/ipc/ShadowLayers.cpp b/gfx/layers/ipc/ShadowLayers.cpp index f686b1e1b681..1e8dcc8d91ba 100644 --- a/gfx/layers/ipc/ShadowLayers.cpp +++ b/gfx/layers/ipc/ShadowLayers.cpp @@ -189,7 +189,7 @@ RefPtr ShadowLayerForwarder::GetForMedia() { ShadowLayerForwarder::ShadowLayerForwarder( ClientLayerManager* aClientLayerManager) : mClientLayerManager(aClientLayerManager), - mMessageLoop(MessageLoop::current()), + mThread(NS_GetCurrentThread()), mDiagnosticTypes(DiagnosticTypes::NO_DIAGNOSTIC), mIsFirstPaint(false), mNextLayerHandle(1) { @@ -500,9 +500,7 @@ void ShadowLayerForwarder::RemoveTextureFromCompositable( } bool ShadowLayerForwarder::InWorkerThread() { - return MessageLoop::current() && - (GetTextureForwarder()->GetMessageLoop()->id() == - MessageLoop::current()->id()); + return GetTextureForwarder()->GetThread()->IsOnCurrentThread(); } void ShadowLayerForwarder::StorePluginWidgetConfigurations( diff --git a/gfx/layers/ipc/ShadowLayers.h b/gfx/layers/ipc/ShadowLayers.h index f1e811dac4aa..fa7e3da201d1 100644 --- a/gfx/layers/ipc/ShadowLayers.h +++ b/gfx/layers/ipc/ShadowLayers.h @@ -418,7 +418,7 @@ class ShadowLayerForwarder final : public LayersIPCActor, private: ClientLayerManager* mClientLayerManager; Transaction* mTxn; - MessageLoop* mMessageLoop; + nsCOMPtr mThread; DiagnosticTypes mDiagnosticTypes; bool mIsFirstPaint; FocusTarget mFocusTarget; diff --git a/gfx/layers/ipc/TextureForwarder.h b/gfx/layers/ipc/TextureForwarder.h index 49fd4a5ed013..09ad0a12add5 100644 --- a/gfx/layers/ipc/TextureForwarder.h +++ b/gfx/layers/ipc/TextureForwarder.h @@ -13,6 +13,7 @@ #include "mozilla/layers/LayersTypes.h" // for LayersBackend #include "mozilla/layers/TextureClient.h" // for TextureClient #include "mozilla/layers/KnowsCompositor.h" +#include "nsISerialEventTarget.h" namespace mozilla { namespace ipc { @@ -47,7 +48,7 @@ class LayersIPCChannel : public LayersIPCActor, virtual base::ProcessId GetParentPid() const = 0; - virtual MessageLoop* GetMessageLoop() const = 0; + virtual nsISerialEventTarget* GetThread() const = 0; virtual FixedSizeSmallShmemSectionAllocator* GetTileLockAllocator() { return nullptr; diff --git a/gfx/layers/ipc/UiCompositorControllerChild.cpp b/gfx/layers/ipc/UiCompositorControllerChild.cpp index be67b4940b48..0225cb8b9db6 100644 --- a/gfx/layers/ipc/UiCompositorControllerChild.cpp +++ b/gfx/layers/ipc/UiCompositorControllerChild.cpp @@ -27,9 +27,7 @@ static RefPtr GetUiThread() { } #endif // defined(MOZ_WIDGET_ANDROID) -static bool IsOnUiThread() { - return GetUiThread()->SerialEventTarget()->IsOnCurrentThread(); -} +static bool IsOnUiThread() { return GetUiThread()->IsOnCurrentThread(); } namespace mozilla { namespace layers { @@ -262,8 +260,7 @@ UiCompositorControllerChild::~UiCompositorControllerChild() = default; void UiCompositorControllerChild::OpenForSameProcess() { MOZ_ASSERT(IsOnUiThread()); - mIsOpen = Open(mParent->GetIPCChannel(), - mozilla::layers::CompositorThreadHolder::Loop(), + mIsOpen = Open(mParent->GetIPCChannel(), mozilla::layers::CompositorThread(), mozilla::ipc::ChildSide); if (!mIsOpen) { diff --git a/gfx/layers/ipc/UiCompositorControllerParent.cpp b/gfx/layers/ipc/UiCompositorControllerParent.cpp index 954e2ee725b4..8150e3682b84 100644 --- a/gfx/layers/ipc/UiCompositorControllerParent.cpp +++ b/gfx/layers/ipc/UiCompositorControllerParent.cpp @@ -50,7 +50,7 @@ RefPtr UiCompositorControllerParent::Start( NewRunnableMethod&&>( "layers::UiCompositorControllerParent::Open", parent, &UiCompositorControllerParent::Open, std::move(aEndpoint)); - CompositorThreadHolder::Loop()->PostTask(task.forget()); + CompositorThread()->Dispatch(task.forget()); return parent; } @@ -181,7 +181,7 @@ void UiCompositorControllerParent::ToolbarAnimatorMessageFromCompositor( int32_t aMessage) { // This function can be call from ether compositor or controller thread. if (!CompositorThreadHolder::IsInCompositorThread()) { - CompositorThreadHolder::Loop()->PostTask(NewRunnableMethod( + CompositorThread()->Dispatch(NewRunnableMethod( "layers::UiCompositorControllerParent::" "ToolbarAnimatorMessageFromCompositor", this, @@ -218,11 +218,10 @@ void UiCompositorControllerParent::NotifyUpdateScreenMetrics( aMetrics.GetZoom().ToScaleFactor(), PixelCastJustification::ScreenIsParentLayerForRoot); ScreenPoint scrollOffset = aMetrics.GetScrollOffset() * scale; - CompositorThreadHolder::Loop()->PostTask( - NewRunnableMethod( - "UiCompositorControllerParent::SendRootFrameMetrics", this, - &UiCompositorControllerParent::SendRootFrameMetrics, scrollOffset, - scale)); + CompositorThread()->Dispatch(NewRunnableMethod( + "UiCompositorControllerParent::SendRootFrameMetrics", this, + &UiCompositorControllerParent::SendRootFrameMetrics, scrollOffset, + scale)); #endif } @@ -249,7 +248,7 @@ void UiCompositorControllerParent::InitializeForSameProcess() { SynchronousTask task( "UiCompositorControllerParent::InitializeForSameProcess"); - CompositorThreadHolder::Loop()->PostTask(NS_NewRunnableFunction( + CompositorThread()->Dispatch(NS_NewRunnableFunction( "UiCompositorControllerParent::InitializeForSameProcess", [&]() { AutoCompleteTask complete(&task); InitializeForSameProcess(); diff --git a/gfx/layers/ipc/VideoBridgeChild.cpp b/gfx/layers/ipc/VideoBridgeChild.cpp index a60c37de02b8..7529c29318a0 100644 --- a/gfx/layers/ipc/VideoBridgeChild.cpp +++ b/gfx/layers/ipc/VideoBridgeChild.cpp @@ -48,9 +48,7 @@ void VideoBridgeChild::Shutdown() { } VideoBridgeChild::VideoBridgeChild() - : mIPDLSelfRef(this), - mMessageLoop(MessageLoop::current()), - mCanSend(true) {} + : mIPDLSelfRef(this), mThread(NS_GetCurrentThread()), mCanSend(true) {} VideoBridgeChild::~VideoBridgeChild() = default; @@ -59,7 +57,7 @@ VideoBridgeChild* VideoBridgeChild::GetSingleton() { return sVideoBridge; } bool VideoBridgeChild::AllocUnsafeShmem( size_t aSize, ipc::SharedMemory::SharedMemoryType aType, ipc::Shmem* aShmem) { - if (MessageLoop::current() != mMessageLoop) { + if (!mThread->IsOnCurrentThread()) { return DispatchAllocShmemInternal(aSize, aType, aShmem, true); // true: unsafe } @@ -106,7 +104,7 @@ bool VideoBridgeChild::DispatchAllocShmemInternal( RefPtr runnable = WrapRunnable( RefPtr(this), &VideoBridgeChild::ProxyAllocShmemNow, &task, aSize, aType, aShmem, aUnsafe, &success); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); @@ -124,7 +122,7 @@ void VideoBridgeChild::ProxyDeallocShmemNow(SynchronousTask* aTask, } bool VideoBridgeChild::DeallocShmem(ipc::Shmem& aShmem) { - if (MessageLoop::current() == mMessageLoop) { + if (GetThread()->IsOnCurrentThread()) { if (!CanSend()) { return false; } @@ -137,7 +135,7 @@ bool VideoBridgeChild::DeallocShmem(ipc::Shmem& aShmem) { RefPtr runnable = WrapRunnable( RefPtr(this), &VideoBridgeChild::ProxyDeallocShmemNow, &task, &aShmem, &result); - GetMessageLoop()->PostTask(runnable.forget()); + GetThread()->Dispatch(runnable.forget()); task.Wait(); return result; diff --git a/gfx/layers/ipc/VideoBridgeChild.h b/gfx/layers/ipc/VideoBridgeChild.h index 1e5b3920ed2a..69f1642d1223 100644 --- a/gfx/layers/ipc/VideoBridgeChild.h +++ b/gfx/layers/ipc/VideoBridgeChild.h @@ -57,7 +57,7 @@ class VideoBridgeChild final : public PVideoBridgeChild, // ClientIPCAllocator base::ProcessId GetParentPid() const override { return OtherPid(); } - MessageLoop* GetMessageLoop() const override { return mMessageLoop; } + nsISerialEventTarget* GetThread() const override { return mThread; } void CancelWaitForNotifyNotUsed(uint64_t aTextureId) override { MOZ_ASSERT(false, "NO RECYCLING HERE"); } @@ -86,7 +86,7 @@ class VideoBridgeChild final : public PVideoBridgeChild, virtual ~VideoBridgeChild(); RefPtr mIPDLSelfRef; - MessageLoop* mMessageLoop; + nsCOMPtr mThread; bool mCanSend; }; diff --git a/gfx/layers/ipc/VideoBridgeParent.cpp b/gfx/layers/ipc/VideoBridgeParent.cpp index f18585041fd0..d8791ed9fbc0 100644 --- a/gfx/layers/ipc/VideoBridgeParent.cpp +++ b/gfx/layers/ipc/VideoBridgeParent.cpp @@ -48,7 +48,7 @@ void VideoBridgeParent::Open(Endpoint&& aEndpoint, VideoBridgeSource aSource) { RefPtr parent = new VideoBridgeParent(aSource); - CompositorThreadHolder::Loop()->PostTask( + CompositorThread()->Dispatch( NewRunnableMethod&&>( "gfx::layers::VideoBridgeParent::Bind", parent, &VideoBridgeParent::Bind, std::move(aEndpoint))); diff --git a/gfx/layers/wr/AsyncImagePipelineManager.cpp b/gfx/layers/wr/AsyncImagePipelineManager.cpp index abc24a7150bb..cdc1fb1c379d 100644 --- a/gfx/layers/wr/AsyncImagePipelineManager.cpp +++ b/gfx/layers/wr/AsyncImagePipelineManager.cpp @@ -551,7 +551,7 @@ void AsyncImagePipelineManager::NotifyPipelinesUpdated( // Queue a runnable on the compositor thread to process the updates. // This will also call CheckForTextureHostsNotUsedByGPU. - layers::CompositorThreadHolder::Loop()->PostTask( + layers::CompositorThread()->Dispatch( NewRunnableMethod("ProcessPipelineUpdates", this, &AsyncImagePipelineManager::ProcessPipelineUpdates)); } diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index 984237e5641f..e7643948d399 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -193,7 +193,7 @@ class ScheduleObserveLayersUpdate : public wr::NotificationHandler { mIsActive(aIsActive) {} void Notify(wr::Checkpoint) override { - CompositorThreadHolder::Loop()->PostTask( + CompositorThread()->Dispatch( NewRunnableMethod( "ObserveLayersUpdate", mBridge, &CompositorBridgeParentBase::ObserveLayersUpdate, mLayersId, @@ -217,7 +217,7 @@ class SceneBuiltNotification : public wr::NotificationHandler { auto startTime = this->mTxnStartTime; RefPtr parent = mParent; wr::Epoch epoch = mEpoch; - CompositorThreadHolder::Loop()->PostTask(NS_NewRunnableFunction( + CompositorThread()->Dispatch(NS_NewRunnableFunction( "SceneBuiltNotificationRunnable", [parent, epoch, startTime]() { auto endTime = TimeStamp::Now(); #ifdef MOZ_GECKO_PROFILER @@ -287,7 +287,7 @@ class WebRenderBridgeParent::ScheduleSharedSurfaceRelease final } void Notify(wr::Checkpoint) override { - CompositorThreadHolder::Loop()->PostTask( + CompositorThread()->Dispatch( NewRunnableMethod>( "ObserveSharedSurfaceRelease", mWrBridge, &WebRenderBridgeParent::ObserveSharedSurfaceRelease, diff --git a/gfx/thebes/DeviceManagerDx.cpp b/gfx/thebes/DeviceManagerDx.cpp index 04be5837311e..07da4f2bcc48 100644 --- a/gfx/thebes/DeviceManagerDx.cpp +++ b/gfx/thebes/DeviceManagerDx.cpp @@ -1384,8 +1384,7 @@ void DeviceManagerDx::GetCompositorDevices( /* static */ void DeviceManagerDx::PreloadAttachmentsOnCompositorThread() { - MessageLoop* loop = layers::CompositorThreadHolder::Loop(); - if (!loop) { + if (!CompositorThread()) { return; } @@ -1404,7 +1403,7 @@ void DeviceManagerDx::PreloadAttachmentsOnCompositorThread() { } } }); - loop->PostTask(task.forget()); + CompositorThread()->Dispatch(task.forget()); } } // namespace gfx diff --git a/gfx/vr/VRManager.cpp b/gfx/vr/VRManager.cpp index 7f4eff393831..85416ffed497 100644 --- a/gfx/vr/VRManager.cpp +++ b/gfx/vr/VRManager.cpp @@ -309,7 +309,7 @@ void VRManager::StartTasks() { if (!mTaskTimer) { mTaskInterval = GetOptimalTaskInterval(); mTaskTimer = NS_NewTimer(); - mTaskTimer->SetTarget(CompositorThreadHolder::Loop()->SerialEventTarget()); + mTaskTimer->SetTarget(CompositorThread()); mTaskTimer->InitWithNamedFuncCallback( TaskTimerCallback, this, mTaskInterval, nsITimer::TYPE_REPEATING_PRECISE_CAN_SKIP, @@ -1380,7 +1380,7 @@ void VRManager::SubmitFrame(VRLayerParent* aLayer, mSubmitThread->Start(); mSubmitThread->PostTask(task.forget()); #else - CompositorThreadHolder::Loop()->PostTask(task.forget()); + CompositorThread()->Dispatch(task.forget()); #endif // defined(MOZ_WIDGET_ANDROID) } } @@ -1514,10 +1514,8 @@ void VRManager::SubmitFrameInternal(const layers::SurfaceDescriptor& aTexture, * frames to continue at a lower refresh rate until frame submission * succeeds again. */ - MessageLoop* loop = CompositorThreadHolder::Loop(); - - loop->PostTask(NewRunnableMethod("gfx::VRManager::StartFrame", this, - &VRManager::StartFrame)); + CompositorThread()->Dispatch(NewRunnableMethod("gfx::VRManager::StartFrame", + this, &VRManager::StartFrame)); #elif defined(MOZ_WIDGET_ANDROID) // We are already in the CompositorThreadHolder event loop on Android. StartFrame(); diff --git a/gfx/vr/VRThread.cpp b/gfx/vr/VRThread.cpp index ee972226a6b5..37748544441a 100644 --- a/gfx/vr/VRThread.cpp +++ b/gfx/vr/VRThread.cpp @@ -7,6 +7,7 @@ #include "VRThread.h" #include "nsDebug.h" #include "nsThreadManager.h" +#include "nsThread.h" #include "nsThreadUtils.h" #include "VRManager.h" diff --git a/gfx/vr/ipc/VRGPUChild.cpp b/gfx/vr/ipc/VRGPUChild.cpp index 4deadbe47a1f..715c3e3c8abb 100644 --- a/gfx/vr/ipc/VRGPUChild.cpp +++ b/gfx/vr/ipc/VRGPUChild.cpp @@ -56,7 +56,7 @@ void VRGPUChild::Shutdown() { void VRGPUChild::ActorDestroy(ActorDestroyReason aWhy) { VRManager* vm = VRManager::Get(); - mozilla::layers::CompositorThreadHolder::Loop()->PostTask( + mozilla::layers::CompositorThread()->Dispatch( NewRunnableMethod("VRGPUChild::ActorDestroy", vm, &VRManager::Shutdown)); mClosed = true; diff --git a/gfx/vr/ipc/VRManagerChild.cpp b/gfx/vr/ipc/VRManagerChild.cpp index fc2f62197cd7..1dcdf6012543 100644 --- a/gfx/vr/ipc/VRManagerChild.cpp +++ b/gfx/vr/ipc/VRManagerChild.cpp @@ -40,7 +40,6 @@ void ReleaseVRManagerParentSingleton() { sVRManagerParentSingleton = nullptr; } VRManagerChild::VRManagerChild() : mRuntimeCapabilities(VRDisplayCapabilityFlags::Cap_None), - mMessageLoop(MessageLoop::current()), mFrameRequestCallbackCounter(0), mWaitingForEnumeration(false), mBackend(layers::LayersBackend::LAYERS_NONE) { @@ -112,8 +111,7 @@ void VRManagerChild::InitSameProcess() { sVRManagerChildSingleton = new VRManagerChild(); sVRManagerParentSingleton = VRManagerParent::CreateSameProcess(); sVRManagerChildSingleton->Open(sVRManagerParentSingleton->GetIPCChannel(), - CompositorThreadHolder::Loop(), - mozilla::ipc::ChildSide); + CompositorThread(), mozilla::ipc::ChildSide); } /* static */ diff --git a/gfx/vr/ipc/VRManagerChild.h b/gfx/vr/ipc/VRManagerChild.h index 5ccc432b6705..06dcae94b3ab 100644 --- a/gfx/vr/ipc/VRManagerChild.h +++ b/gfx/vr/ipc/VRManagerChild.h @@ -158,8 +158,6 @@ class VRManagerChild : public PVRManagerChild { bool mDisplaysInitialized; nsTArray mNavigatorCallbacks; - MessageLoop* mMessageLoop; - struct XRFrameRequest { XRFrameRequest(mozilla::dom::FrameRequestCallback& aCallback, int32_t aHandle) diff --git a/gfx/vr/ipc/VRManagerParent.cpp b/gfx/vr/ipc/VRManagerParent.cpp index 9da0fa6f1f5a..609e489ec305 100644 --- a/gfx/vr/ipc/VRManagerParent.cpp +++ b/gfx/vr/ipc/VRManagerParent.cpp @@ -72,13 +72,12 @@ void VRManagerParent::UnregisterFromManager() { /* static */ bool VRManagerParent::CreateForContent(Endpoint&& aEndpoint) { - MessageLoop* loop = CompositorThreadHolder::Loop(); - if (!loop) { + if (!CompositorThread()) { return false; } RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid(), true); - loop->PostTask(NewRunnableMethod&&>( + CompositorThread()->Dispatch(NewRunnableMethod&&>( "gfx::VRManagerParent::Bind", vmp, &VRManagerParent::Bind, std::move(aEndpoint))); @@ -102,12 +101,11 @@ void VRManagerParent::RegisterVRManagerInCompositorThread( /*static*/ VRManagerParent* VRManagerParent::CreateSameProcess() { - MessageLoop* loop = CompositorThreadHolder::Loop(); RefPtr vmp = new VRManagerParent(base::GetCurrentProcId(), false); vmp->mCompositorThreadHolder = CompositorThreadHolder::GetSingleton(); vmp->mSelfRef = vmp; - loop->PostTask( + CompositorThread()->Dispatch( NewRunnableFunction("RegisterVRManagerIncompositorThreadRunnable", RegisterVRManagerInCompositorThread, vmp.get())); return vmp.get(); @@ -115,13 +113,11 @@ VRManagerParent* VRManagerParent::CreateSameProcess() { bool VRManagerParent::CreateForGPUProcess( Endpoint&& aEndpoint) { - MessageLoop* loop = CompositorThreadHolder::Loop(); - RefPtr vmp = new VRManagerParent(aEndpoint.OtherPid(), false); vmp->mCompositorThreadHolder = CompositorThreadHolder::GetSingleton(); vmp->mSelfRef = vmp; - loop->PostTask(NewRunnableMethod&&>( + CompositorThread()->Dispatch(NewRunnableMethod&&>( "gfx::VRManagerParent::Bind", vmp, &VRManagerParent::Bind, std::move(aEndpoint))); return true; @@ -130,7 +126,7 @@ bool VRManagerParent::CreateForGPUProcess( /*static*/ void VRManagerParent::Shutdown() { ReleaseVRManagerParentSingleton(); - CompositorThreadHolder::Loop()->PostTask(NS_NewRunnableFunction( + CompositorThread()->Dispatch(NS_NewRunnableFunction( "VRManagerParent::Shutdown", []() -> void { VRManagerParent::ShutdownInternal(); })); } diff --git a/gfx/webrender_bindings/RenderThread.cpp b/gfx/webrender_bindings/RenderThread.cpp index 91431c0f542d..b5803bdeec8c 100644 --- a/gfx/webrender_bindings/RenderThread.cpp +++ b/gfx/webrender_bindings/RenderThread.cpp @@ -469,7 +469,7 @@ void RenderThread::UpdateAndRender( auto& renderer = it->second; - layers::CompositorThreadHolder::Loop()->PostTask( + layers::CompositorThread()->Dispatch( NewRunnableFunction("NotifyDidStartRenderRunnable", &NotifyDidStartRender, renderer->GetCompositorBridge())); @@ -487,7 +487,7 @@ void RenderThread::UpdateAndRender( TimeStamp end = TimeStamp::Now(); RefPtr info = renderer->FlushPipelineInfo(); - layers::CompositorThreadHolder::Loop()->PostTask( + layers::CompositorThread()->Dispatch( NewRunnableFunction("NotifyDidRenderRunnable", &NotifyDidRender, renderer->GetCompositorBridge(), info, aStartId, aStartTime, start, end, aRender, stats)); @@ -821,7 +821,7 @@ void RenderThread::HandleWebRenderError(WebRenderError aError) { return; } - layers::CompositorThreadHolder::Loop()->PostTask(NewRunnableFunction( + layers::CompositorThread()->Dispatch(NewRunnableFunction( "DoNotifyWebRenderErrorRunnable", &DoNotifyWebRenderError, aError)); { MutexAutoLock lock(mRenderTextureMapLock); @@ -1114,7 +1114,7 @@ void wr_finished_scene_build(mozilla::wr::WrWindowId aWindowId, for (size_t i = 0; i < aDocumentIdsCount; ++i) { renderRoots[i] = wr::RenderRootFromId(aDocumentIds[i]); } - layers::CompositorThreadHolder::Loop()->PostTask( + layers::CompositorThread()->Dispatch( NewRunnableFunction("NotifyDidSceneBuild", &NotifyDidSceneBuild, cbp, std::move(renderRoots), info)); } diff --git a/gfx/webrender_bindings/RendererOGL.cpp b/gfx/webrender_bindings/RendererOGL.cpp index d6cc5f843634..fd03d91cb1b6 100644 --- a/gfx/webrender_bindings/RendererOGL.cpp +++ b/gfx/webrender_bindings/RendererOGL.cpp @@ -200,7 +200,7 @@ bool RendererOGL::EnsureAsyncScreenshot() { return true; } if (!mDisableNativeCompositor) { - layers::CompositorThreadHolder::Loop()->PostTask( + layers::CompositorThread()->Dispatch( NewRunnableFunction("DoWebRenderDisableNativeCompositorRunnable", &DoWebRenderDisableNativeCompositor, mBridge)); @@ -219,7 +219,7 @@ void RendererOGL::CheckGraphicsResetStatus() { if (gl->IsSupported(gl::GLFeature::robustness)) { GLenum resetStatus = gl->fGetGraphicsResetStatus(); if (resetStatus == LOCAL_GL_PURGED_CONTEXT_RESET_NV) { - layers::CompositorThreadHolder::Loop()->PostTask( + layers::CompositorThread()->Dispatch( NewRunnableFunction("DoNotifyWebRenderContextPurgeRunnable", &DoNotifyWebRenderContextPurge, mBridge)); } diff --git a/media/webrtc/signaling/src/media-conduit/VideoConduit.h b/media/webrtc/signaling/src/media-conduit/VideoConduit.h index f372ecad5da1..7ab648f3e8a3 100644 --- a/media/webrtc/signaling/src/media-conduit/VideoConduit.h +++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.h @@ -54,7 +54,6 @@ T MinIgnoreZero(const T& a, const T& b); class VideoStreamFactory; class WebrtcAudioConduit; -class nsThread; // Interface of external video encoder for WebRTC. class WebrtcVideoEncoder : public VideoEncoder, public webrtc::VideoEncoder {}; diff --git a/widget/windows/CompositorWidgetParent.cpp b/widget/windows/CompositorWidgetParent.cpp index 1bc839f2b729..d59dce6905e2 100644 --- a/widget/windows/CompositorWidgetParent.cpp +++ b/widget/windows/CompositorWidgetParent.cpp @@ -216,7 +216,7 @@ void CompositorWidgetParent::UpdateCompositorWnd(const HWND aCompositorWnd, SendUpdateCompositorWnd(reinterpret_cast(aCompositorWnd), reinterpret_cast(aParentWnd)) ->Then( - layers::CompositorThreadHolder::Loop()->SerialEventTarget(), __func__, + layers::CompositorThread(), __func__, [self](const bool& aSuccess) { if (aSuccess && self->mRootLayerTreeID.isSome()) { self->mSetParentCompleted = true;