Bug 1388309 P1 - let VideoDecoderManagerChild keep the info of whether decoding video on GPU process or not; draft
authorKaku Kuo <kaku@mozilla.com>
Mon, 14 Aug 2017 17:21:47 +0800
changeset 649679 91aa7886ad289d1c017961a9bfcb365f5fd17615
parent 645833 df9beb781895fcd0493c21e95ad313e0044515ec
child 649680 c34ad38e91882e455df2984dbd6e926c40c0b2b0
child 649681 82ed0fa0b761157dda591cdb767b527dc826fce9
push id75094
push userbmo:kaku@mozilla.com
push dateMon, 21 Aug 2017 05:25:07 +0000
bugs1388309
milestone57.0a1
Bug 1388309 P1 - let VideoDecoderManagerChild keep the info of whether decoding video on GPU process or not; MozReview-Commit-ID: 2eShIbv9iid
dom/media/ipc/VideoDecoderManagerChild.cpp
dom/media/ipc/VideoDecoderManagerChild.h
--- a/dom/media/ipc/VideoDecoderManagerChild.cpp
+++ b/dom/media/ipc/VideoDecoderManagerChild.cpp
@@ -24,16 +24,17 @@ using namespace gfx;
 
 // Only modified on the main-thread
 StaticRefPtr<nsIThread> sVideoDecoderChildThread;
 StaticRefPtr<AbstractThread> sVideoDecoderChildAbstractThread;
 
 // Only accessed from sVideoDecoderChildThread
 static StaticRefPtr<VideoDecoderManagerChild> sDecoderManager;
 static UniquePtr<nsTArray<RefPtr<Runnable>>> sRecreateTasks;
+static bool sDecodeVideoOnGPUProcess = false;
 
 /* static */ void
 VideoDecoderManagerChild::InitializeThread()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!sVideoDecoderChildThread) {
     RefPtr<nsIThread> childThread;
@@ -63,16 +64,17 @@ VideoDecoderManagerChild::Shutdown()
   if (sVideoDecoderChildThread) {
     sVideoDecoderChildThread->Dispatch(
       NS_NewRunnableFunction("dom::VideoDecoderManagerChild::Shutdown",
                              []() {
                                if (sDecoderManager &&
                                    sDecoderManager->CanSend()) {
                                  sDecoderManager->Close();
                                  sDecoderManager = nullptr;
+                                 sDecodeVideoOnGPUProcess = false;
                                }
                              }),
       NS_DISPATCH_NORMAL);
 
     sVideoDecoderChildAbstractThread = nullptr;
     sVideoDecoderChildThread->Shutdown();
     sVideoDecoderChildThread = nullptr;
 
@@ -97,16 +99,23 @@ VideoDecoderManagerChild::RunWhenRecreat
 
 /* static */ VideoDecoderManagerChild*
 VideoDecoderManagerChild::GetSingleton()
 {
   MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
   return sDecoderManager;
 }
 
+/* static */ bool
+VideoDecoderManagerChild::IsDecodeVideoOnGPUProcess()
+{
+  MOZ_ASSERT(NS_GetCurrentThread() == GetManagerThread());
+  return sDecodeVideoOnGPUProcess;
+}
+
 /* static */ nsIThread*
 VideoDecoderManagerChild::GetManagerThread()
 {
   return sVideoDecoderChildThread;
 }
 
 /* static */ AbstractThread*
 VideoDecoderManagerChild::GetManagerAbstractThread()
@@ -131,21 +140,27 @@ VideoDecoderManagerChild::DeallocPVideoD
 }
 
 void
 VideoDecoderManagerChild::Open(Endpoint<PVideoDecoderManagerChild>&& aEndpoint)
 {
   // Make sure we always dispatch everything in sRecreateTasks, even if we
   // fail since this is as close to being recreated as we will ever be.
   sDecoderManager = nullptr;
+  sDecodeVideoOnGPUProcess = false;
   if (aEndpoint.IsValid()) {
     RefPtr<VideoDecoderManagerChild> manager = new VideoDecoderManagerChild();
     if (aEndpoint.Bind(manager)) {
       sDecoderManager = manager;
       manager->InitIPDL();
+
+      // Only set this to true if the end points are valid and the binding succeeds.
+      // If the GPUProcessManager decides not to decode video on GPU process, it
+      // pass null end points through IPC calls.
+      sDecodeVideoOnGPUProcess = true;
     }
   }
   for (Runnable* task : *sRecreateTasks) {
     task->Run();
   }
   sRecreateTasks->Clear();
 }
 
--- a/dom/media/ipc/VideoDecoderManagerChild.h
+++ b/dom/media/ipc/VideoDecoderManagerChild.h
@@ -18,16 +18,17 @@ namespace dom {
 class VideoDecoderManagerChild final : public PVideoDecoderManagerChild
                                      , public mozilla::ipc::IShmemAllocator
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoDecoderManagerChild)
 
   // Can only be called from the manager thread
   static VideoDecoderManagerChild* GetSingleton();
+  static bool IsDecodeVideoOnGPUProcess();
 
   // Can be called from any thread.
   static nsIThread* GetManagerThread();
   static AbstractThread* GetManagerAbstractThread();
 
   // Can be called from any thread, dispatches the request to the IPDL thread internally
   // and will be ignored if the IPDL actor has been destroyed.
   already_AddRefed<gfx::SourceSurface> Readback(const SurfaceDescriptorGPUVideo& aSD);