diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index acb2c5b58f79..6ddac578df36 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -1093,7 +1093,9 @@ mozilla::ipc::IPCResult ContentParent::RecvLaunchRDDProcess( Preferences::GetBool("media.rdd-process.enabled", false)) { RDDProcessManager* rdd = RDDProcessManager::Get(); if (rdd) { - bool rddOpened = rdd->LaunchRDDProcess(OtherPid(), aEndpoint); + rdd->LaunchRDDProcess(); + + bool rddOpened = rdd->CreateContentBridge(OtherPid(), aEndpoint); if (NS_WARN_IF(!rddOpened)) { *aRv = NS_ERROR_NOT_AVAILABLE; diff --git a/dom/media/ipc/PRDD.ipdl b/dom/media/ipc/PRDD.ipdl index db5ec638628e..22cef5b9d5b3 100644 --- a/dom/media/ipc/PRDD.ipdl +++ b/dom/media/ipc/PRDD.ipdl @@ -41,9 +41,11 @@ parent: async UpdateVar(GfxVarUpdate var); - async InitVideoBridge(Endpoint endpoint); + async CreateVideoBridgeToParentProcess(Endpoint endpoint); child: + // args TBD, sent when init complete. Occurs once, after Init(). + async InitComplete(); async InitCrashReporter(Shmem shmem, NativeThreadId threadId); diff --git a/dom/media/ipc/RDDChild.cpp b/dom/media/ipc/RDDChild.cpp index af476af211dd..7a38616b21c7 100644 --- a/dom/media/ipc/RDDChild.cpp +++ b/dom/media/ipc/RDDChild.cpp @@ -5,11 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "RDDChild.h" -#include "mozilla/RDDProcessManager.h" #include "mozilla/dom/MemoryReportRequest.h" #include "mozilla/ipc/CrashReporterHost.h" #include "mozilla/gfx/gfxVars.h" -#include "mozilla/gfx/GPUProcessManager.h" #if defined(XP_LINUX) && defined(MOZ_SANDBOX) # include "mozilla/SandboxBroker.h" @@ -26,7 +24,7 @@ namespace mozilla { using namespace layers; using namespace gfx; -RDDChild::RDDChild(RDDProcessHost* aHost) : mHost(aHost) { +RDDChild::RDDChild(RDDProcessHost* aHost) : mHost(aHost), mRDDReady(false) { MOZ_COUNT_CTOR(RDDChild); } @@ -59,14 +57,29 @@ bool RDDChild::Init(bool aStartMacSandbox) { #endif gfxVars::AddReceiver(this); - auto* gpm = gfx::GPUProcessManager::Get(); - if (gpm) { - gpm->AddListener(this); - } return true; } +bool RDDChild::EnsureRDDReady() { + if (mRDDReady) { + return true; + } + + mRDDReady = true; + return true; +} + +mozilla::ipc::IPCResult RDDChild::RecvInitComplete() { + // We synchronously requested RDD parameters before this arrived. + if (mRDDReady) { + return IPC_OK(); + } + + mRDDReady = true; + return IPC_OK(); +} + bool RDDChild::SendRequestMemoryReport(const uint32_t& aGeneration, const bool& aAnonymize, const bool& aMinimizeMemoryUsage, @@ -77,13 +90,6 @@ bool RDDChild::SendRequestMemoryReport(const uint32_t& aGeneration, return true; } -void RDDChild::OnCompositorUnexpectedShutdown() { - auto* rddm = RDDProcessManager::Get(); - if (rddm) { - rddm->CreateVideoBridge(); - } -} - void RDDChild::OnVarChanged(const GfxVarUpdate& aVar) { SendUpdateVar(aVar); } mozilla::ipc::IPCResult RDDChild::RecvAddMemoryReport( @@ -108,12 +114,6 @@ void RDDChild::ActorDestroy(ActorDestroyReason aWhy) { GenerateCrashReport(OtherPid()); } - auto* gpm = gfx::GPUProcessManager::Get(); - if (gpm) { - // Note: the manager could have shutdown already. - gpm->RemoveListener(this); - } - gfxVars::RemoveReceiver(this); mHost->OnChannelClosed(); } diff --git a/dom/media/ipc/RDDChild.h b/dom/media/ipc/RDDChild.h index 736f2af5627c..e9b8e225bf6e 100644 --- a/dom/media/ipc/RDDChild.h +++ b/dom/media/ipc/RDDChild.h @@ -10,7 +10,6 @@ #include "mozilla/ipc/CrashReporterHelper.h" #include "mozilla/UniquePtr.h" #include "mozilla/gfx/gfxVarReceiver.h" -#include "mozilla/gfx/GPUProcessListener.h" namespace mozilla { @@ -26,8 +25,7 @@ class RDDProcessHost; class RDDChild final : public PRDDChild, public ipc::CrashReporterHelper, - public gfx::gfxVarReceiver, - public gfx::GPUProcessListener { + public gfx::gfxVarReceiver { typedef mozilla::dom::MemoryReportRequestHost MemoryReportRequestHost; public: @@ -36,9 +34,13 @@ class RDDChild final : public PRDDChild, bool Init(bool aStartMacSandbox); - void OnCompositorUnexpectedShutdown() override; + bool EnsureRDDReady(); + void OnVarChanged(const GfxVarUpdate& aVar) override; + // PRDDChild overrides. + mozilla::ipc::IPCResult RecvInitComplete(); + void ActorDestroy(ActorDestroyReason aWhy) override; mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport); @@ -57,6 +59,7 @@ class RDDChild final : public PRDDChild, #if defined(XP_LINUX) && defined(MOZ_SANDBOX) UniquePtr mSandboxBroker; #endif + bool mRDDReady; }; } // namespace mozilla diff --git a/dom/media/ipc/RDDParent.cpp b/dom/media/ipc/RDDParent.cpp index 99ba20db7050..2a88746c1b4d 100644 --- a/dom/media/ipc/RDDParent.cpp +++ b/dom/media/ipc/RDDParent.cpp @@ -121,6 +121,8 @@ static void StartRDDMacSandbox() { mozilla::ipc::IPCResult RDDParent::RecvInit( nsTArray&& vars, const Maybe& aBrokerFd, bool aStartMacSandbox) { + Unused << SendInitComplete(); + for (const auto& var : vars) { gfxVars::ApplyUpdate(var); } @@ -172,9 +174,9 @@ mozilla::ipc::IPCResult RDDParent::RecvNewContentRemoteDecoderManager( return IPC_OK(); } -mozilla::ipc::IPCResult RDDParent::RecvInitVideoBridge( +mozilla::ipc::IPCResult RDDParent::RecvCreateVideoBridgeToParentProcess( Endpoint&& aEndpoint) { - if (!RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess( + if (!RemoteDecoderManagerParent::CreateVideoBridgeToParentProcess( std::move(aEndpoint))) { return IPC_FAIL_NO_REASON(this); } diff --git a/dom/media/ipc/RDDParent.h b/dom/media/ipc/RDDParent.h index 1497f0e14902..a5f5fe5f525b 100644 --- a/dom/media/ipc/RDDParent.h +++ b/dom/media/ipc/RDDParent.h @@ -32,7 +32,7 @@ class RDDParent final : public PRDDParent { mozilla::ipc::IPCResult RecvNewContentRemoteDecoderManager( Endpoint&& aEndpoint); - mozilla::ipc::IPCResult RecvInitVideoBridge( + mozilla::ipc::IPCResult RecvCreateVideoBridgeToParentProcess( Endpoint&& aEndpoint); mozilla::ipc::IPCResult RecvRequestMemoryReport( const uint32_t& generation, const bool& anonymize, diff --git a/dom/media/ipc/RDDProcessManager.cpp b/dom/media/ipc/RDDProcessManager.cpp index fad0748a15f2..65b94fed5ed6 100644 --- a/dom/media/ipc/RDDProcessManager.cpp +++ b/dom/media/ipc/RDDProcessManager.cpp @@ -11,7 +11,6 @@ #include "mozilla/Preferences.h" #include "mozilla/StaticPrefs_media.h" #include "mozilla/dom/ContentParent.h" -#include "mozilla/gfx/GPUProcessManager.h" #include "mozilla/layers/VideoBridgeParent.h" #include "mozilla/layers/CompositorThread.h" #include "nsAppRunner.h" @@ -21,8 +20,7 @@ namespace mozilla { -using namespace gfx; -using namespace layers; +using namespace mozilla::layers; static StaticAutoPtr sRDDSingleton; @@ -103,11 +101,9 @@ void RDDProcessManager::OnPreferenceChange(const char16_t* aData) { } } -bool RDDProcessManager::LaunchRDDProcess( - base::ProcessId aOtherProcess, - ipc::Endpoint* aOutRemoteDecoderManager) { +void RDDProcessManager::LaunchRDDProcess() { if (mProcess) { - return true; + return; } mNumProcessAttempts++; @@ -122,27 +118,30 @@ bool RDDProcessManager::LaunchRDDProcess( mProcess = new RDDProcessHost(this); if (!mProcess->Launch(extraArgs)) { DestroyProcess(); - return false; } - if (!EnsureRDDReady()) { - return false; - } - - bool ok = true; - if (ok) ok = CreateContentBridge(aOtherProcess, aOutRemoteDecoderManager); - if (ok) ok = CreateVideoBridge(); - return ok; } bool RDDProcessManager::EnsureRDDReady() { - if (mProcess && !mProcess->IsConnected() && !mProcess->WaitForLaunch()) { - // If this fails, we should have fired OnProcessLaunchComplete and - // removed the process. - MOZ_ASSERT(!mProcess && !mRDDChild); - return false; + if (mProcess && !mProcess->IsConnected()) { + if (!mProcess->WaitForLaunch()) { + // If this fails, we should have fired OnProcessLaunchComplete and + // removed the process. + MOZ_ASSERT(!mProcess && !mRDDChild); + return false; + } } - return true; + if (mRDDChild) { + if (mRDDChild->EnsureRDDReady()) { + return true; + } + + // If the initialization above fails, we likely have a RDD process teardown + // waiting in our message queue (or will soon). + DestroyProcess(); + } + + return false; } void RDDProcessManager::OnProcessLaunchComplete(RDDProcessHost* aHost) { @@ -163,6 +162,26 @@ void RDDProcessManager::OnProcessLaunchComplete(RDDProcessHost* aHost) { } mQueuedPrefs.Clear(); + ipc::Endpoint parentPipe; + ipc::Endpoint childPipe; + + // Currently hardcoded to use the current process as the parent side, + // we need to add support for the GPU process. + nsresult rv = PVideoBridge::CreateEndpoints( + base::GetCurrentProcId(), mRDDChild->OtherPid(), &parentPipe, &childPipe); + if (NS_FAILED(rv)) { + MOZ_LOG(sPDMLog, LogLevel::Debug, + ("Could not create video bridge: %d", int(rv))); + DestroyProcess(); + return; + } + + mRDDChild->SendCreateVideoBridgeToParentProcess(std::move(childPipe)); + + CompositorThreadHolder::Loop()->PostTask( + NewRunnableFunction("gfx::VideoBridgeParent::Open", + &VideoBridgeParent::Open, std::move(parentPipe))); + CrashReporter::AnnotateCrashReport( CrashReporter::Annotation::RDDProcessStatus, NS_LITERAL_CSTRING("Running")); @@ -223,6 +242,10 @@ void RDDProcessManager::DestroyProcess() { bool RDDProcessManager::CreateContentBridge( base::ProcessId aOtherProcess, ipc::Endpoint* aOutRemoteDecoderManager) { + if (!EnsureRDDReady() || !StaticPrefs::media_rdd_process_enabled()) { + return false; + } + ipc::Endpoint parentPipe; ipc::Endpoint childPipe; @@ -240,39 +263,6 @@ bool RDDProcessManager::CreateContentBridge( return true; } -bool RDDProcessManager::CreateVideoBridge() { - ipc::Endpoint parentPipe; - ipc::Endpoint childPipe; - - GPUProcessManager* gpuManager = GPUProcessManager::Get(); - base::ProcessId gpuProcessPid = gpuManager ? gpuManager->GPUProcessPid() : -1; - - // The child end is the producer of video frames; the parent end is the - // consumer. - base::ProcessId childPid = RDDProcessPid(); - base::ProcessId parentPid = - gpuProcessPid != -1 ? gpuProcessPid : base::GetCurrentProcId(); - - nsresult rv = PVideoBridge::CreateEndpoints(parentPid, childPid, &parentPipe, - &childPipe); - if (NS_FAILED(rv)) { - MOZ_LOG(sPDMLog, LogLevel::Debug, - ("Could not create video bridge: %d", int(rv))); - DestroyProcess(); - return false; - } - - mRDDChild->SendInitVideoBridge(std::move(childPipe)); - if (gpuProcessPid != -1) { - gpuManager->InitVideoBridge(std::move(parentPipe)); - } else { - VideoBridgeParent::Open(std::move(parentPipe), - VideoBridgeSource::RddProcess); - } - - return true; -} - base::ProcessId RDDProcessManager::RDDProcessPid() { base::ProcessId rddPid = mRDDChild ? mRDDChild->OtherPid() : -1; return rddPid; diff --git a/dom/media/ipc/RDDProcessManager.h b/dom/media/ipc/RDDProcessManager.h index c6a357097e97..8da159b56667 100644 --- a/dom/media/ipc/RDDProcessManager.h +++ b/dom/media/ipc/RDDProcessManager.h @@ -19,8 +19,6 @@ class RDDChild; // objects that may live in another process. Currently, it provides access // to the RDD process via ContentParent. class RDDProcessManager final : public RDDProcessHost::Listener { - friend class RDDChild; - public: static void Initialize(); static void Shutdown(); @@ -29,15 +27,17 @@ class RDDProcessManager final : public RDDProcessHost::Listener { ~RDDProcessManager(); // If not using a RDD process, launch a new RDD process asynchronously. - bool LaunchRDDProcess(base::ProcessId aOtherProcess, - mozilla::ipc::Endpoint* - aOutRemoteDecoderManager); + void LaunchRDDProcess(); // Ensure that RDD-bound methods can be used. If no RDD process is being // used, or one is launched and ready, this function returns immediately. // Otherwise it blocks until the RDD process has finished launching. bool EnsureRDDReady(); + bool CreateContentBridge(base::ProcessId aOtherProcess, + mozilla::ipc::Endpoint* + aOutRemoteDecoderManager); + void OnProcessLaunchComplete(RDDProcessHost* aHost) override; void OnProcessUnexpectedShutdown(RDDProcessHost* aHost) override; @@ -65,11 +65,6 @@ class RDDProcessManager final : public RDDProcessHost::Listener { RDDProcessHost* Process() { return mProcess; } private: - bool CreateContentBridge(base::ProcessId aOtherProcess, - mozilla::ipc::Endpoint* - aOutRemoteDecoderManager); - bool CreateVideoBridge(); - // Called from our xpcom-shutdown observer. void OnXPCOMShutdown(); void OnPreferenceChange(const char16_t* aData); diff --git a/dom/media/ipc/RemoteDecoderManagerChild.cpp b/dom/media/ipc/RemoteDecoderManagerChild.cpp index bfd09a6a9b91..d3eb3f7816dd 100644 --- a/dom/media/ipc/RemoteDecoderManagerChild.cpp +++ b/dom/media/ipc/RemoteDecoderManagerChild.cpp @@ -155,10 +155,6 @@ bool RemoteDecoderManagerChild::DeallocPRemoteDecoderChild( return true; } -RemoteDecoderManagerChild::RemoteDecoderManagerChild( - layers::VideoBridgeSource aSource) - : mSource(aSource) {} - void RemoteDecoderManagerChild::OpenForRDDProcess( Endpoint&& aEndpoint) { MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread()); @@ -174,8 +170,7 @@ void RemoteDecoderManagerChild::OpenForRDDProcess( } sRemoteDecoderManagerChildForRDDProcess = nullptr; if (aEndpoint.IsValid()) { - RefPtr manager = - new RemoteDecoderManagerChild(VideoBridgeSource::RddProcess); + RefPtr manager = new RemoteDecoderManagerChild(); if (aEndpoint.Bind(manager)) { sRemoteDecoderManagerChildForRDDProcess = manager; manager->InitIPDL(); @@ -189,8 +184,7 @@ void RemoteDecoderManagerChild::OpenForGPUProcess( // fail since this is as close to being recreated as we will ever be. sRemoteDecoderManagerChildForGPUProcess = nullptr; if (aEndpoint.IsValid()) { - RefPtr manager = - new RemoteDecoderManagerChild(VideoBridgeSource::GpuProcess); + RefPtr manager = new RemoteDecoderManagerChild(); if (aEndpoint.Bind(manager)) { sRemoteDecoderManagerChildForGPUProcess = manager; manager->InitIPDL(); diff --git a/dom/media/ipc/RemoteDecoderManagerChild.h b/dom/media/ipc/RemoteDecoderManagerChild.h index 0ebef5cbd625..61f37a008c75 100644 --- a/dom/media/ipc/RemoteDecoderManagerChild.h +++ b/dom/media/ipc/RemoteDecoderManagerChild.h @@ -6,7 +6,6 @@ #ifndef include_dom_media_ipc_RemoteDecoderManagerChild_h #define include_dom_media_ipc_RemoteDecoderManagerChild_h #include "mozilla/PRemoteDecoderManagerChild.h" -#include "mozilla/layers/VideoBridgeUtils.h" namespace mozilla { @@ -62,7 +61,6 @@ class RemoteDecoderManagerChild final : public PRemoteDecoderManagerChild, void RunWhenGPUProcessRecreated(already_AddRefed aTask); bool CanSend(); - layers::VideoBridgeSource GetSource() const { return mSource; } protected: void InitIPDL(); @@ -83,7 +81,7 @@ class RemoteDecoderManagerChild final : public PRemoteDecoderManagerChild, // Main thread only static void InitializeThread(); - explicit RemoteDecoderManagerChild(layers::VideoBridgeSource aSource); + RemoteDecoderManagerChild() = default; ~RemoteDecoderManagerChild() = default; static void OpenForRDDProcess( @@ -93,9 +91,6 @@ class RemoteDecoderManagerChild final : public PRemoteDecoderManagerChild, RefPtr mIPDLSelfRef; - // The associated source of this decoder manager - layers::VideoBridgeSource mSource; - // Should only ever be accessed on the manager thread. bool mCanSend = false; }; diff --git a/dom/media/ipc/RemoteDecoderManagerParent.cpp b/dom/media/ipc/RemoteDecoderManagerParent.cpp index 19ae2594846b..d2f9c17d7202 100644 --- a/dom/media/ipc/RemoteDecoderManagerParent.cpp +++ b/dom/media/ipc/RemoteDecoderManagerParent.cpp @@ -174,7 +174,7 @@ bool RemoteDecoderManagerParent::CreateForContent( return true; } -bool RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess( +bool RemoteDecoderManagerParent::CreateVideoBridgeToParentProcess( Endpoint&& aEndpoint) { // We never want to decode in the GPU process, but output // frames to the parent process. @@ -185,9 +185,9 @@ bool RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess( return false; } - RefPtr task = - NewRunnableFunction("gfx::VideoBridgeChild::Open", - &VideoBridgeChild::Open, std::move(aEndpoint)); + RefPtr task = NewRunnableFunction( + "gfx::VideoBridgeChild::Open", &VideoBridgeChild::OpenToParentProcess, + std::move(aEndpoint)); sRemoteDecoderManagerParentThread->Dispatch(task.forget(), NS_DISPATCH_NORMAL); return true; diff --git a/dom/media/ipc/RemoteDecoderManagerParent.h b/dom/media/ipc/RemoteDecoderManagerParent.h index 11fd4be1ad3b..ec9042ba5efc 100644 --- a/dom/media/ipc/RemoteDecoderManagerParent.h +++ b/dom/media/ipc/RemoteDecoderManagerParent.h @@ -21,7 +21,7 @@ class RemoteDecoderManagerParent final : public PRemoteDecoderManagerParent { static bool CreateForContent( Endpoint&& aEndpoint); - static bool CreateVideoBridgeToOtherProcess( + static bool CreateVideoBridgeToParentProcess( Endpoint&& aEndpoint); // Can be called from any thread diff --git a/dom/media/ipc/RemoteVideoDecoder.cpp b/dom/media/ipc/RemoteVideoDecoder.cpp index ab64ead3b7fb..a8523cbfae04 100644 --- a/dom/media/ipc/RemoteVideoDecoder.cpp +++ b/dom/media/ipc/RemoteVideoDecoder.cpp @@ -37,8 +37,9 @@ class KnowsCompositorVideo : public layers::KnowsCompositor { NS_INLINE_DECL_THREADSAFE_REFCOUNTING(KnowsCompositorVideo, override) layers::TextureForwarder* GetTextureForwarder() override { - auto* vbc = VideoBridgeChild::GetSingleton(); - return (vbc && vbc->CanSend()) ? vbc : nullptr; + return mTextureFactoryIdentifier.mParentProcessType == GeckoProcessType_GPU + ? VideoBridgeChild::GetSingletonToGPUProcess() + : VideoBridgeChild::GetSingletonToParentProcess(); } layers::LayersIPCActor* GetLayersIPCActor() override { return GetTextureForwarder(); @@ -46,7 +47,10 @@ class KnowsCompositorVideo : public layers::KnowsCompositor { static already_AddRefed TryCreateForIdentifier( const layers::TextureFactoryIdentifier& aIdentifier) { - VideoBridgeChild* child = VideoBridgeChild::GetSingleton(); + VideoBridgeChild* child = + (aIdentifier.mParentProcessType == GeckoProcessType_GPU) + ? VideoBridgeChild::GetSingletonToGPUProcess() + : VideoBridgeChild::GetSingletonToParentProcess(); if (!child) { return nullptr; } @@ -310,14 +314,13 @@ MediaResult RemoteVideoDecoderParent::ProcessDecodedData( DecodedOutputIPDL& aDecodedData) { MOZ_ASSERT(OnManagerThread()); - nsTArray array; - // If the video decoder bridge has shut down, stop. if (mKnowsCompositor && !mKnowsCompositor->GetTextureForwarder()) { - aDecodedData = std::move(array); return NS_OK; } + nsTArray array; + for (const auto& data : aData) { MOZ_ASSERT(data->mType == MediaData::Type::VIDEO_DATA, "Can only decode videos using RemoteDecoderParent!"); diff --git a/gfx/ipc/GPUParent.cpp b/gfx/ipc/GPUParent.cpp index c7a040cecced..1e759d469357 100644 --- a/gfx/ipc/GPUParent.cpp +++ b/gfx/ipc/GPUParent.cpp @@ -38,7 +38,6 @@ #include "mozilla/layers/LayerTreeOwnerTracker.h" #include "mozilla/layers/UiCompositorControllerParent.h" #include "mozilla/layers/MemoryReportingMLGPU.h" -#include "mozilla/layers/VideoBridgeParent.h" #include "mozilla/webrender/RenderThread.h" #include "mozilla/webrender/WebRenderAPI.h" #include "mozilla/HangDetails.h" @@ -316,12 +315,6 @@ mozilla::ipc::IPCResult GPUParent::RecvInitImageBridge( return IPC_OK(); } -mozilla::ipc::IPCResult GPUParent::RecvInitVideoBridge( - Endpoint&& aEndpoint) { - VideoBridgeParent::Open(std::move(aEndpoint), VideoBridgeSource::RddProcess); - return IPC_OK(); -} - mozilla::ipc::IPCResult GPUParent::RecvInitVRManager( Endpoint&& aEndpoint) { VRManagerParent::CreateForGPUProcess(std::move(aEndpoint)); diff --git a/gfx/ipc/GPUParent.h b/gfx/ipc/GPUParent.h index c2e29d86b58b..e8baa45d94a4 100644 --- a/gfx/ipc/GPUParent.h +++ b/gfx/ipc/GPUParent.h @@ -46,8 +46,6 @@ class GPUParent final : public PGPUParent { Endpoint&& aVsyncEndpoint); mozilla::ipc::IPCResult RecvInitImageBridge( Endpoint&& aEndpoint); - mozilla::ipc::IPCResult RecvInitVideoBridge( - Endpoint&& aEndpoint); mozilla::ipc::IPCResult RecvInitVRManager( Endpoint&& aEndpoint); mozilla::ipc::IPCResult RecvInitVR(Endpoint&& aVRGPUChild); diff --git a/gfx/ipc/GPUProcessManager.cpp b/gfx/ipc/GPUProcessManager.cpp index c3a86b801d9b..e457a64092b1 100644 --- a/gfx/ipc/GPUProcessManager.cpp +++ b/gfx/ipc/GPUProcessManager.cpp @@ -968,12 +968,6 @@ void GPUProcessManager::CreateContentRemoteDecoderManager( *aOutEndpoint = std::move(childPipe); } -void GPUProcessManager::InitVideoBridge(ipc::Endpoint&& aVideoBridge) { - if (EnsureGPUReady()) { - mGPUChild->SendInitVideoBridge(std::move(aVideoBridge)); - } -} - void GPUProcessManager::MapLayerTreeId(LayersId aLayersId, base::ProcessId aOwningId) { LayerTreeOwnerTracker::Get()->Map(aLayersId, aOwningId); diff --git a/gfx/ipc/GPUProcessManager.h b/gfx/ipc/GPUProcessManager.h index 5e06e70b9d50..493bdb0f67a9 100644 --- a/gfx/ipc/GPUProcessManager.h +++ b/gfx/ipc/GPUProcessManager.h @@ -33,7 +33,6 @@ class CompositorUpdateObserver; class PCompositorBridgeChild; class PCompositorManagerChild; class PImageBridgeChild; -class PVideoBridgeParent; class RemoteCompositorSession; class InProcessCompositorSession; class UiCompositorControllerChild; @@ -72,7 +71,6 @@ class GPUProcessManager final : public GPUProcessHost::Listener { typedef layers::PCompositorBridgeChild PCompositorBridgeChild; typedef layers::PCompositorManagerChild PCompositorManagerChild; typedef layers::PImageBridgeChild PImageBridgeChild; - typedef layers::PVideoBridgeParent PVideoBridgeParent; typedef layers::RemoteCompositorSession RemoteCompositorSession; typedef layers::InProcessCompositorSession InProcessCompositorSession; typedef layers::UiCompositorControllerChild UiCompositorControllerChild; @@ -106,9 +104,6 @@ class GPUProcessManager final : public GPUProcessHost::Listener { mozilla::ipc::Endpoint* aOutVideoManager, nsTArray* aNamespaces); - // Initialize GPU process with consuming end of PVideoBridge. - void InitVideoBridge(mozilla::ipc::Endpoint&& aVideoBridge); - // Maps the layer tree and process together so that aOwningPID is allowed // to access aLayersId across process. void MapLayerTreeId(LayersId aLayersId, base::ProcessId aOwningId); diff --git a/gfx/ipc/GfxMessageUtils.h b/gfx/ipc/GfxMessageUtils.h index 41c965a296db..a4cad43e31cc 100644 --- a/gfx/ipc/GfxMessageUtils.h +++ b/gfx/ipc/GfxMessageUtils.h @@ -25,7 +25,6 @@ #include "nsRect.h" #include "nsRegion.h" #include "mozilla/Array.h" -#include "mozilla/layers/VideoBridgeUtils.h" #include diff --git a/gfx/ipc/PGPU.ipdl b/gfx/ipc/PGPU.ipdl index 688ae7015e58..7a09fee98624 100644 --- a/gfx/ipc/PGPU.ipdl +++ b/gfx/ipc/PGPU.ipdl @@ -13,7 +13,6 @@ include protocol PImageBridge; include protocol PProfiler; include protocol PVRGPU; include protocol PVRManager; -include protocol PVideoBridge; include protocol PVsyncBridge; include protocol PUiCompositorController; include protocol PRemoteDecoderManager; @@ -62,7 +61,6 @@ parent: async InitCompositorManager(Endpoint endpoint); async InitVsyncBridge(Endpoint endpoint); async InitImageBridge(Endpoint endpoint); - async InitVideoBridge(Endpoint endpoint); async InitVRManager(Endpoint endpoint); async InitUiCompositorController(LayersId rootLayerTreeId, Endpoint endpoint); async InitProfiler(Endpoint endpoint); diff --git a/gfx/layers/client/GPUVideoTextureClient.cpp b/gfx/layers/client/GPUVideoTextureClient.cpp index f7b8b3308545..6c7f9e07f446 100644 --- a/gfx/layers/client/GPUVideoTextureClient.cpp +++ b/gfx/layers/client/GPUVideoTextureClient.cpp @@ -16,12 +16,9 @@ using namespace gfx; GPUVideoTextureData::GPUVideoTextureData(RemoteDecoderManagerChild* aManager, const SurfaceDescriptorGPUVideo& aSD, const gfx::IntSize& aSize) - : mManager(aManager), - mSD(aSD), mSize(aSize) { - mSD.source() = Some(mManager->GetSource()); -} + : mManager(aManager), mSD(aSD), mSize(aSize) {} - GPUVideoTextureData::~GPUVideoTextureData() {} +GPUVideoTextureData::~GPUVideoTextureData() {} bool GPUVideoTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) { aOutDescriptor = mSD; diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index 3d8003ef31b6..82c70241546f 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -1491,7 +1491,7 @@ void TextureClient::GPUVideoDesc(SurfaceDescriptorGPUVideo* const aOutDesc) { MOZ_RELEASE_ASSERT(mData); mData->GetSubDescriptor(&subDesc); - *aOutDesc = SurfaceDescriptorGPUVideo(handle, std::move(subDesc), Nothing()); + *aOutDesc = SurfaceDescriptorGPUVideo(handle, std::move(subDesc)); } class MemoryTextureReadLock : public NonBlockingTextureReadLock { diff --git a/gfx/layers/composite/GPUVideoTextureHost.cpp b/gfx/layers/composite/GPUVideoTextureHost.cpp index e296aaec8dd1..0ec3141ee2a6 100644 --- a/gfx/layers/composite/GPUVideoTextureHost.cpp +++ b/gfx/layers/composite/GPUVideoTextureHost.cpp @@ -37,7 +37,7 @@ TextureHost* GPUVideoTextureHost::EnsureWrappedTextureHost() { // one from RDD). We'll need to flag which one to use to lookup our // descriptor, or just try both. mWrappedTextureHost = - VideoBridgeParent::GetSingleton(mDescriptor.source())->LookupTexture(mDescriptor.handle()); + VideoBridgeParent::GetSingleton()->LookupTexture(mDescriptor.handle()); return mWrappedTextureHost; } diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh index e9f57ba0f33c..8b2a21d418f8 100644 --- a/gfx/layers/ipc/LayersSurfaces.ipdlh +++ b/gfx/layers/ipc/LayersSurfaces.ipdlh @@ -16,7 +16,6 @@ using mozilla::gfx::IntRect from "mozilla/gfx/Rect.h"; using mozilla::gfx::IntSize from "mozilla/gfx/Point.h"; using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h"; using gfxImageFormat from "gfxTypes.h"; -using mozilla::layers::MaybeVideoBridgeSource from "mozilla/layers/VideoBridgeUtils.h"; namespace mozilla { namespace layers { @@ -102,7 +101,6 @@ union GPUVideoSubDescriptor { struct SurfaceDescriptorGPUVideo { uint64_t handle; GPUVideoSubDescriptor subdesc; - MaybeVideoBridgeSource source; }; struct RGBDescriptor { diff --git a/gfx/layers/ipc/VideoBridgeChild.cpp b/gfx/layers/ipc/VideoBridgeChild.cpp index 1d4f4355e99e..384145435448 100644 --- a/gfx/layers/ipc/VideoBridgeChild.cpp +++ b/gfx/layers/ipc/VideoBridgeChild.cpp @@ -7,12 +7,12 @@ #include "VideoBridgeChild.h" #include "VideoBridgeParent.h" #include "CompositorThread.h" -#include "mozilla/dom/ContentChild.h" namespace mozilla { namespace layers { -StaticRefPtr sVideoBridge; +StaticRefPtr sVideoBridgeToParentProcess; +StaticRefPtr sVideoBridgeToGPUProcess; /* static */ void VideoBridgeChild::StartupForGPUProcess() { @@ -23,25 +23,42 @@ void VideoBridgeChild::StartupForGPUProcess() { base::GetCurrentProcId(), &parentPipe, &childPipe); - VideoBridgeChild::Open(std::move(childPipe)); - VideoBridgeParent::Open(std::move(parentPipe), VideoBridgeSource::GpuProcess); + VideoBridgeChild::OpenToGPUProcess(std::move(childPipe)); + + CompositorThreadHolder::Loop()->PostTask( + NewRunnableFunction("gfx::VideoBridgeParent::Open", + &VideoBridgeParent::Open, std::move(parentPipe))); } -void VideoBridgeChild::Open(Endpoint&& aEndpoint) { - MOZ_ASSERT(!sVideoBridge || !sVideoBridge->CanSend()); - sVideoBridge = new VideoBridgeChild(); +void VideoBridgeChild::OpenToParentProcess( + Endpoint&& aEndpoint) { + sVideoBridgeToParentProcess = new VideoBridgeChild(); - if (!aEndpoint.Bind(sVideoBridge)) { + if (!aEndpoint.Bind(sVideoBridgeToParentProcess)) { // We can't recover from this. - MOZ_CRASH("Failed to bind VideoBridgeChild to endpoint"); + MOZ_CRASH("Failed to bind RemoteDecoderManagerParent to endpoint"); + } +} + +void VideoBridgeChild::OpenToGPUProcess( + Endpoint&& aEndpoint) { + sVideoBridgeToGPUProcess = new VideoBridgeChild(); + + if (!aEndpoint.Bind(sVideoBridgeToGPUProcess)) { + // We can't recover from this. + MOZ_CRASH("Failed to bind RemoteDecoderManagerParent to endpoint"); } } /* static */ void VideoBridgeChild::Shutdown() { - if (sVideoBridge) { - sVideoBridge->Close(); - sVideoBridge = nullptr; + if (sVideoBridgeToParentProcess) { + sVideoBridgeToParentProcess->Close(); + sVideoBridgeToParentProcess = nullptr; + } + if (sVideoBridgeToGPUProcess) { + sVideoBridgeToGPUProcess->Close(); + sVideoBridgeToGPUProcess = nullptr; } } @@ -52,7 +69,13 @@ VideoBridgeChild::VideoBridgeChild() VideoBridgeChild::~VideoBridgeChild() {} -VideoBridgeChild* VideoBridgeChild::GetSingleton() { return sVideoBridge; } +VideoBridgeChild* VideoBridgeChild::GetSingletonToParentProcess() { + return sVideoBridgeToParentProcess; +} + +VideoBridgeChild* VideoBridgeChild::GetSingletonToGPUProcess() { + return sVideoBridgeToGPUProcess; +} bool VideoBridgeChild::AllocUnsafeShmem( size_t aSize, ipc::SharedMemory::SharedMemoryType aType, @@ -103,9 +126,5 @@ bool VideoBridgeChild::IsSameProcess() const { return OtherPid() == base::GetCurrentProcId(); } -void VideoBridgeChild::HandleFatalError(const char* aMsg) const { - dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aMsg, OtherPid()); -} - } // namespace layers } // namespace mozilla diff --git a/gfx/layers/ipc/VideoBridgeChild.h b/gfx/layers/ipc/VideoBridgeChild.h index 577c799706a6..cf9c12a87cf1 100644 --- a/gfx/layers/ipc/VideoBridgeChild.h +++ b/gfx/layers/ipc/VideoBridgeChild.h @@ -8,7 +8,6 @@ #define MOZILLA_GFX_VIDEOBRIDGECHILD_H #include "mozilla/layers/PVideoBridgeChild.h" -#include "mozilla/layers/VideoBridgeUtils.h" #include "ISurfaceAllocator.h" #include "TextureForwarder.h" @@ -23,7 +22,8 @@ class VideoBridgeChild final : public PVideoBridgeChild, static void StartupForGPUProcess(); static void Shutdown(); - static VideoBridgeChild* GetSingleton(); + static VideoBridgeChild* GetSingletonToParentProcess(); + static VideoBridgeChild* GetSingletonToGPUProcess(); // PVideoBridgeChild PTextureChild* AllocPTextureChild(const SurfaceDescriptor& aSharedData, @@ -65,10 +65,8 @@ class VideoBridgeChild final : public PVideoBridgeChild, bool CanSend() { return mCanSend; } - static void Open(Endpoint&& aEndpoint); - - protected: - void HandleFatalError(const char* aMsg) const override; + static void OpenToParentProcess(Endpoint&& aEndpoint); + static void OpenToGPUProcess(Endpoint&& aEndpoint); private: VideoBridgeChild(); diff --git a/gfx/layers/ipc/VideoBridgeParent.cpp b/gfx/layers/ipc/VideoBridgeParent.cpp index 7ef7e53bb4db..f72bfb0877f0 100644 --- a/gfx/layers/ipc/VideoBridgeParent.cpp +++ b/gfx/layers/ipc/VideoBridgeParent.cpp @@ -7,7 +7,6 @@ #include "VideoBridgeParent.h" #include "CompositorThread.h" #include "mozilla/layers/TextureHost.h" -#include "mozilla/layers/VideoBridgeUtils.h" namespace mozilla { namespace layers { @@ -15,66 +14,27 @@ namespace layers { using namespace mozilla::ipc; using namespace mozilla::gfx; -static VideoBridgeParent* sVideoBridgeFromRddProcess; -static VideoBridgeParent* sVideoBridgeFromGpuProcess; +static VideoBridgeParent* sVideoBridgeSingleton; -VideoBridgeParent::VideoBridgeParent(VideoBridgeSource aSource) - : mCompositorThreadHolder(CompositorThreadHolder::GetSingleton()), - mClosed(false) { +VideoBridgeParent::VideoBridgeParent() : mClosed(false) { mSelfRef = this; - switch (aSource) { - default: - MOZ_CRASH("Unhandled case"); - case VideoBridgeSource::RddProcess: - sVideoBridgeFromRddProcess = this; - break; - case VideoBridgeSource::GpuProcess: - sVideoBridgeFromGpuProcess = this; - break; - } + sVideoBridgeSingleton = this; + mCompositorThreadRef = CompositorThreadHolder::GetSingleton(); } -VideoBridgeParent::~VideoBridgeParent() { - if (sVideoBridgeFromRddProcess == this) { - sVideoBridgeFromRddProcess = nullptr; - } - if (sVideoBridgeFromGpuProcess == this) { - sVideoBridgeFromGpuProcess = nullptr; - } -} +VideoBridgeParent::~VideoBridgeParent() { sVideoBridgeSingleton = nullptr; } -/* static */ -void VideoBridgeParent::Open(Endpoint&& aEndpoint, - VideoBridgeSource aSource) { - RefPtr parent = new VideoBridgeParent(aSource); - - CompositorThreadHolder::Loop()->PostTask( - NewRunnableMethod&&>( - "gfx::layers::VideoBridgeParent::Bind", parent, - &VideoBridgeParent::Bind, std::move(aEndpoint))); -} - -void VideoBridgeParent::Bind(Endpoint&& aEndpoint) { - if (!aEndpoint.Bind(this)) { +void VideoBridgeParent::Open(Endpoint&& aEndpoint) { + RefPtr parent = new VideoBridgeParent(); + if (!aEndpoint.Bind(parent)) { // We can't recover from this. - MOZ_CRASH("Failed to bind VideoBridgeParent to endpoint"); + MOZ_CRASH("Failed to bind RemoteDecoderManagerParent to endpoint"); } } /* static */ -VideoBridgeParent* VideoBridgeParent::GetSingleton( - Maybe& aSource) { - MOZ_ASSERT(aSource.isSome()); - switch (aSource.value()) { - default: - MOZ_CRASH("Unhandled case"); - case VideoBridgeSource::RddProcess: - MOZ_ASSERT(sVideoBridgeFromRddProcess); - return sVideoBridgeFromRddProcess; - case VideoBridgeSource::GpuProcess: - MOZ_ASSERT(sVideoBridgeFromGpuProcess); - return sVideoBridgeFromGpuProcess; - } +VideoBridgeParent* VideoBridgeParent::GetSingleton() { + return sVideoBridgeSingleton; } TextureHost* VideoBridgeParent::LookupTexture(uint64_t aSerial) { @@ -87,7 +47,7 @@ void VideoBridgeParent::ActorDestroy(ActorDestroyReason aWhy) { } void VideoBridgeParent::ActorDealloc() { - mCompositorThreadHolder = nullptr; + mCompositorThreadRef = nullptr; mSelfRef = nullptr; } diff --git a/gfx/layers/ipc/VideoBridgeParent.h b/gfx/layers/ipc/VideoBridgeParent.h index 297c31d392ba..7e382958580b 100644 --- a/gfx/layers/ipc/VideoBridgeParent.h +++ b/gfx/layers/ipc/VideoBridgeParent.h @@ -13,7 +13,6 @@ namespace mozilla { namespace layers { -enum class VideoBridgeSource : uint8_t; class CompositorThreadHolder; class VideoBridgeParent final : public PVideoBridgeParent, @@ -22,11 +21,7 @@ class VideoBridgeParent final : public PVideoBridgeParent, public: ~VideoBridgeParent(); - static VideoBridgeParent* GetSingleton(Maybe& aSource); - - static void Open(Endpoint&& aEndpoint, - VideoBridgeSource aSource); - + static VideoBridgeParent* GetSingleton(); TextureHost* LookupTexture(uint64_t aSerial); // PVideoBridgeParent @@ -59,16 +54,17 @@ class VideoBridgeParent final : public PVideoBridgeParent, void DeallocShmem(ipc::Shmem& aShmem) override; + static void Open(Endpoint&& aEndpoint); + private: - explicit VideoBridgeParent(VideoBridgeSource aSource); - void Bind(Endpoint&& aEndpoint); + VideoBridgeParent(); void ActorDealloc() override; // This keeps us alive until ActorDestroy(), at which point we do a // deferred destruction of ourselves. RefPtr mSelfRef; - RefPtr mCompositorThreadHolder; + RefPtr mCompositorThreadRef; std::map mTextureMap; diff --git a/gfx/layers/ipc/VideoBridgeUtils.h b/gfx/layers/ipc/VideoBridgeUtils.h deleted file mode 100644 index 75c9c7974d35..000000000000 --- a/gfx/layers/ipc/VideoBridgeUtils.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef IPC_VideoBridgeUtils_h -#define IPC_VideoBridgeUtils_h - -#include "ipc/IPCMessageUtils.h" - -namespace mozilla { -namespace layers { - -enum class VideoBridgeSource : uint8_t { - RddProcess, - GpuProcess, - _Count, -}; - -typedef Maybe MaybeVideoBridgeSource; - -} // namespace layers -} // namespace mozilla - -namespace IPC { - -template <> -struct ParamTraits - : public ContiguousEnumSerializer< - mozilla::layers::VideoBridgeSource, - mozilla::layers::VideoBridgeSource::RddProcess, - mozilla::layers::VideoBridgeSource::_Count> {}; - -} // namespace IPC - -#endif // IPC_VideoBridgeUtils_h diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 05249c086ee5..de7c79f92946 100755 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -215,7 +215,6 @@ EXPORTS.mozilla.layers += [ 'ipc/UiCompositorControllerParent.h', 'ipc/VideoBridgeChild.h', 'ipc/VideoBridgeParent.h', - 'ipc/VideoBridgeUtils.h', 'LayerAttributes.h', 'LayerMetricsWrapper.h', 'LayersHelpers.h',