Bug 1388309 P1 - let VideoDecoderManagerChild keep the info of whether decoding video on GPU process or not;
MozReview-Commit-ID: 2eShIbv9iid
--- 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);