Bug 1561179 - P5: Remove separate VideoBridgeChild Singletons. r=mattwoodrow
authorDan Glastonbury <dan.glastonbury@gmail.com>
Mon, 04 Nov 2019 03:41:59 +0000
changeset 500316 fa6bf31d950b963ed648c77969e5bbf17aa8b360
parent 500315 e4d3547739db667cecbcb571c5f9a0cbb6a484a8
child 500317 7a1c07e301a931e9d8409a81ded6c17a2979254c
push id36761
push userdvarga@mozilla.com
push dateMon, 04 Nov 2019 09:41:18 +0000
treeherdermozilla-central@5647ec4ba6f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1561179
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1561179 - P5: Remove separate VideoBridgeChild Singletons. r=mattwoodrow Combine sVideoBridgeToParentProcess and sVideoBridgeToGPUProcess into one sVideoBridge. Each producing process, GPU or RDD, is only ever started with one VideoBridgeChild endpoint. This is enough to get RemoteVideoDecoders in RDD process to start using GPU memory to send video to compositor over PVideoBridge. Differential Revision: https://phabricator.services.mozilla.com/D50402
dom/media/ipc/RemoteDecoderManagerParent.cpp
dom/media/ipc/RemoteVideoDecoder.cpp
gfx/layers/ipc/VideoBridgeChild.cpp
gfx/layers/ipc/VideoBridgeChild.h
--- a/dom/media/ipc/RemoteDecoderManagerParent.cpp
+++ b/dom/media/ipc/RemoteDecoderManagerParent.cpp
@@ -181,17 +181,17 @@ bool RemoteDecoderManagerParent::CreateV
   MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_RDD);
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!StartupThreads()) {
     return false;
   }
 
   RefPtr<Runnable> task = NewRunnableFunction(
-      "gfx::VideoBridgeChild::Open", &VideoBridgeChild::OpenToParentProcess,
+      "gfx::VideoBridgeChild::Open", &VideoBridgeChild::Open,
       std::move(aEndpoint));
   sRemoteDecoderManagerParentThread->Dispatch(task.forget(),
                                               NS_DISPATCH_NORMAL);
   return true;
 }
 
 RemoteDecoderManagerParent::RemoteDecoderManagerParent(
     RemoteDecoderManagerThreadHolder* aHolder)
--- a/dom/media/ipc/RemoteVideoDecoder.cpp
+++ b/dom/media/ipc/RemoteVideoDecoder.cpp
@@ -32,30 +32,25 @@ using namespace layers;  // for PlanarYC
 using namespace ipc;
 using namespace gfx;
 
 class KnowsCompositorVideo : public layers::KnowsCompositor {
  public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(KnowsCompositorVideo, override)
 
   layers::TextureForwarder* GetTextureForwarder() override {
-    return mTextureFactoryIdentifier.mParentProcessType == GeckoProcessType_GPU
-               ? VideoBridgeChild::GetSingletonToGPUProcess()
-               : VideoBridgeChild::GetSingletonToParentProcess();
+    return VideoBridgeChild::GetSingleton();
   }
   layers::LayersIPCActor* GetLayersIPCActor() override {
     return GetTextureForwarder();
   }
 
   static already_AddRefed<KnowsCompositorVideo> TryCreateForIdentifier(
       const layers::TextureFactoryIdentifier& aIdentifier) {
-    VideoBridgeChild* child =
-        (aIdentifier.mParentProcessType == GeckoProcessType_GPU)
-            ? VideoBridgeChild::GetSingletonToGPUProcess()
-            : VideoBridgeChild::GetSingletonToParentProcess();
+    VideoBridgeChild* child = VideoBridgeChild::GetSingleton();
     if (!child) {
       return nullptr;
     }
 
     // The RDD process will never use hardware decoding since it's
     // sandboxed, so don't bother trying to create a sync object.
     TextureFactoryIdentifier ident = aIdentifier;
     if (XRE_IsRDDProcess()) {
--- a/gfx/layers/ipc/VideoBridgeChild.cpp
+++ b/gfx/layers/ipc/VideoBridgeChild.cpp
@@ -6,78 +6,59 @@
 
 #include "VideoBridgeChild.h"
 #include "VideoBridgeParent.h"
 #include "CompositorThread.h"
 
 namespace mozilla {
 namespace layers {
 
-StaticRefPtr<VideoBridgeChild> sVideoBridgeToParentProcess;
-StaticRefPtr<VideoBridgeChild> sVideoBridgeToGPUProcess;
+StaticRefPtr<VideoBridgeChild> sVideoBridge;
 
 /* static */
 void VideoBridgeChild::StartupForGPUProcess() {
   ipc::Endpoint<PVideoBridgeParent> parentPipe;
   ipc::Endpoint<PVideoBridgeChild> childPipe;
 
   PVideoBridge::CreateEndpoints(base::GetCurrentProcId(),
                                 base::GetCurrentProcId(), &parentPipe,
                                 &childPipe);
 
-  VideoBridgeChild::OpenToGPUProcess(std::move(childPipe));
+  VideoBridgeChild::Open(std::move(childPipe));
   VideoBridgeParent::Open(std::move(parentPipe), VideoBridgeSource::GpuProcess);
 }
 
-void VideoBridgeChild::OpenToParentProcess(
-    Endpoint<PVideoBridgeChild>&& aEndpoint) {
-  sVideoBridgeToParentProcess = new VideoBridgeChild();
+void VideoBridgeChild::Open(Endpoint<PVideoBridgeChild>&& aEndpoint) {
+  // TODO(djg): This is for testing and probably incorrect. What happens when
+  // the IPC fails and is rebound?
+  MOZ_ASSERT(!sVideoBridge);
+  sVideoBridge = new VideoBridgeChild();
 
-  if (!aEndpoint.Bind(sVideoBridgeToParentProcess)) {
-    // We can't recover from this.
-    MOZ_CRASH("Failed to bind VideoBridgeChild to endpoint");
-  }
-}
-
-void VideoBridgeChild::OpenToGPUProcess(
-    Endpoint<PVideoBridgeChild>&& aEndpoint) {
-  sVideoBridgeToGPUProcess = new VideoBridgeChild();
-
-  if (!aEndpoint.Bind(sVideoBridgeToGPUProcess)) {
+  if (!aEndpoint.Bind(sVideoBridge)) {
     // We can't recover from this.
     MOZ_CRASH("Failed to bind VideoBridgeChild to endpoint");
   }
 }
 
 /* static */
 void VideoBridgeChild::Shutdown() {
-  if (sVideoBridgeToParentProcess) {
-    sVideoBridgeToParentProcess->Close();
-    sVideoBridgeToParentProcess = nullptr;
-  }
-  if (sVideoBridgeToGPUProcess) {
-    sVideoBridgeToGPUProcess->Close();
-    sVideoBridgeToGPUProcess = nullptr;
+  if (sVideoBridge) {
+    sVideoBridge->Close();
+    sVideoBridge = nullptr;
   }
 }
 
 VideoBridgeChild::VideoBridgeChild()
     : mIPDLSelfRef(this),
       mMessageLoop(MessageLoop::current()),
       mCanSend(true) {}
 
 VideoBridgeChild::~VideoBridgeChild() {}
 
-VideoBridgeChild* VideoBridgeChild::GetSingletonToParentProcess() {
-  return sVideoBridgeToParentProcess;
-}
-
-VideoBridgeChild* VideoBridgeChild::GetSingletonToGPUProcess() {
-  return sVideoBridgeToGPUProcess;
-}
+VideoBridgeChild* VideoBridgeChild::GetSingleton() { return sVideoBridge; }
 
 bool VideoBridgeChild::AllocUnsafeShmem(
     size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
     ipc::Shmem* aShmem) {
   return PVideoBridgeChild::AllocUnsafeShmem(aSize, aType, aShmem);
 }
 
 bool VideoBridgeChild::AllocShmem(size_t aSize,
--- a/gfx/layers/ipc/VideoBridgeChild.h
+++ b/gfx/layers/ipc/VideoBridgeChild.h
@@ -18,18 +18,17 @@ namespace layers {
 class VideoBridgeChild final : public PVideoBridgeChild,
                                public TextureForwarder {
  public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoBridgeChild, override);
 
   static void StartupForGPUProcess();
   static void Shutdown();
 
-  static VideoBridgeChild* GetSingletonToParentProcess();
-  static VideoBridgeChild* GetSingletonToGPUProcess();
+  static VideoBridgeChild* GetSingleton();
 
   // PVideoBridgeChild
   PTextureChild* AllocPTextureChild(const SurfaceDescriptor& aSharedData,
                                     const ReadLockDescriptor& aReadLock,
                                     const LayersBackend& aLayersBackend,
                                     const TextureFlags& aFlags,
                                     const uint64_t& aSerial);
   bool DeallocPTextureChild(PTextureChild* actor);
@@ -61,18 +60,17 @@ class VideoBridgeChild final : public PV
     MOZ_ASSERT(false, "NO RECYCLING HERE");
   }
 
   // ISurfaceAllocator
   bool IsSameProcess() const override;
 
   bool CanSend() { return mCanSend; }
 
-  static void OpenToParentProcess(Endpoint<PVideoBridgeChild>&& aEndpoint);
-  static void OpenToGPUProcess(Endpoint<PVideoBridgeChild>&& aEndpoint);
+  static void Open(Endpoint<PVideoBridgeChild>&& aEndpoint);
 
  private:
   VideoBridgeChild();
   virtual ~VideoBridgeChild();
 
   RefPtr<VideoBridgeChild> mIPDLSelfRef;
   MessageLoop* mMessageLoop;
   bool mCanSend;