Bug 1314543 - Make EnsureGPUReady() returns bool to make sure GPU process is readay. r=dvander
authorvincentliu <vliu@mozilla.com>
Thu, 30 Mar 2017 09:23:24 +0800
changeset 350455 50907f304e247c56192bdd4af58159b4cdab46b8
parent 350454 e54a3d60d9fd5f48154f1013f8f63ecea1ebf06f
child 350456 b572053885859b78071bd6fd32e8e4dd2767dc70
push id31574
push usercbook@mozilla.com
push dateThu, 30 Mar 2017 11:48:04 +0000
treeherdermozilla-central@03d602fd723a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1314543
milestone55.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 1314543 - Make EnsureGPUReady() returns bool to make sure GPU process is readay. r=dvander
gfx/ipc/GPUChild.cpp
gfx/ipc/GPUChild.h
gfx/ipc/GPUProcessManager.cpp
gfx/ipc/GPUProcessManager.h
--- a/gfx/ipc/GPUChild.cpp
+++ b/gfx/ipc/GPUChild.cpp
@@ -75,29 +75,32 @@ GPUChild::Init()
 }
 
 void
 GPUChild::OnVarChanged(const GfxVarUpdate& aVar)
 {
   SendUpdateVar(aVar);
 }
 
-void
+bool
 GPUChild::EnsureGPUReady()
 {
   if (mGPUReady) {
-    return;
+    return true;
   }
 
   GPUDeviceData data;
-  SendGetDeviceStatus(&data);
+  if (!SendGetDeviceStatus(&data)) {
+    return false;
+  }
 
   gfxPlatform::GetPlatform()->ImportGPUDeviceData(data);
   Telemetry::AccumulateTimeDelta(Telemetry::GPU_PROCESS_LAUNCH_TIME_MS_2, mHost->GetLaunchTime());
   mGPUReady = true;
+  return true;
 }
 
 mozilla::ipc::IPCResult
 GPUChild::RecvInitComplete(const GPUDeviceData& aData)
 {
   // We synchronously requested GPU parameters before this arrived.
   if (mGPUReady) {
     return IPC_OK();
--- a/gfx/ipc/GPUChild.h
+++ b/gfx/ipc/GPUChild.h
@@ -36,17 +36,17 @@ class GPUChild final
   typedef mozilla::dom::MemoryReportRequestHost MemoryReportRequestHost;
 
 public:
   explicit GPUChild(GPUProcessHost* aHost);
   ~GPUChild();
 
   void Init();
 
-  void EnsureGPUReady();
+  bool EnsureGPUReady();
 
   // gfxVarReceiver overrides.
   void OnVarChanged(const GfxVarUpdate& aVar) override;
 
   // PGPUChild overrides.
   mozilla::ipc::IPCResult RecvInitComplete(const GPUDeviceData& aData) override;
   mozilla::ipc::IPCResult RecvReportCheckerboard(const uint32_t& aSeverity, const nsCString& aLog) override;
   mozilla::ipc::IPCResult RecvInitCrashReporter(Shmem&& shmem, const NativeThreadId& aThreadId) override;
--- a/gfx/ipc/GPUProcessManager.cpp
+++ b/gfx/ipc/GPUProcessManager.cpp
@@ -158,43 +158,43 @@ GPUProcessManager::DisableGPUProcess(con
   gfxCriticalNote << aMessage;
 
   gfxPlatform::NotifyGPUProcessDisabled();
 
   DestroyProcess();
   ShutdownVsyncIOThread();
 }
 
-void
+bool
 GPUProcessManager::EnsureGPUReady()
 {
   if (mProcess && !mProcess->IsConnected()) {
     if (!mProcess->WaitForLaunch()) {
       // If this fails, we should have fired OnProcessLaunchComplete and
       // removed the process.
       MOZ_ASSERT(!mProcess && !mGPUChild);
-      return;
+      return false;
     }
   }
 
-  if (mGPUChild) {
-    mGPUChild->EnsureGPUReady();
+  if (mGPUChild && mGPUChild->EnsureGPUReady()) {
+    return true;
   }
+
+  return false;
 }
 
 void
 GPUProcessManager::EnsureImageBridgeChild()
 {
   if (ImageBridgeChild::GetSingleton()) {
     return;
   }
 
-  EnsureGPUReady();
-
-  if (!mGPUChild) {
+  if (!EnsureGPUReady()) {
     ImageBridgeChild::InitSameProcess();
     return;
   }
 
   ipc::Endpoint<PImageBridgeParent> parentPipe;
   ipc::Endpoint<PImageBridgeChild> childPipe;
   nsresult rv = PImageBridge::CreateEndpoints(
     mGPUChild->OtherPid(),
@@ -212,19 +212,17 @@ GPUProcessManager::EnsureImageBridgeChil
 
 void
 GPUProcessManager::EnsureVRManager()
 {
   if (VRManagerChild::IsCreated()) {
     return;
   }
 
-  EnsureGPUReady();
-
-  if (!mGPUChild) {
+  if (!EnsureGPUReady()) {
     VRManagerChild::InitSameProcess();
     return;
   }
 
   ipc::Endpoint<PVRManagerParent> parentPipe;
   ipc::Endpoint<PVRManagerChild> childPipe;
   nsresult rv = PVRManager::CreateEndpoints(
     mGPUChild->OtherPid(),
@@ -243,25 +241,23 @@ GPUProcessManager::EnsureVRManager()
 #if defined(MOZ_WIDGET_ANDROID)
 void
 GPUProcessManager::EnsureUiCompositorController()
 {
   if (UiCompositorControllerChild::IsInitialized()) {
     return;
   }
 
-  EnsureGPUReady();
-
   RefPtr<nsThread> uiThread;
 
   uiThread = GetAndroidUiThread();
 
   MOZ_ASSERT(uiThread);
 
-  if (!mGPUChild) {
+  if (!EnsureGPUReady()) {
     UiCompositorControllerChild::InitSameProcess(uiThread);
     return;
   }
 
   ipc::Endpoint<PUiCompositorControllerParent> parentPipe;
   ipc::Endpoint<PUiCompositorControllerChild> childPipe;
   nsresult rv = PUiCompositorController::CreateEndpoints(
     mGPUChild->OtherPid(),
@@ -541,24 +537,23 @@ GPUProcessManager::CreateTopLevelComposi
                                             LayerManager* aLayerManager,
                                             CSSToLayoutDeviceScale aScale,
                                             const CompositorOptions& aOptions,
                                             bool aUseExternalSurfaceSize,
                                             const gfx::IntSize& aSurfaceSize)
 {
   uint64_t layerTreeId = AllocateLayerTreeId();
 
-  EnsureGPUReady();
   EnsureImageBridgeChild();
   EnsureVRManager();
 #if defined(MOZ_WIDGET_ANDROID)
   EnsureUiCompositorController();
 #endif // defined(MOZ_WIDGET_ANDROID)
 
-  if (mGPUChild) {
+  if (EnsureGPUReady()) {
     RefPtr<CompositorSession> session = CreateRemoteSession(
       aWidget,
       aLayerManager,
       layerTreeId,
       aScale,
       aOptions,
       aUseExternalSurfaceSize,
       aSurfaceSize);
@@ -677,36 +672,34 @@ GPUProcessManager::CreateContentBridges(
   CreateContentVideoDecoderManager(aOtherProcess, aOutVideoManager);
   return true;
 }
 
 bool
 GPUProcessManager::CreateContentCompositorBridge(base::ProcessId aOtherProcess,
                                                  ipc::Endpoint<PCompositorBridgeChild>* aOutEndpoint)
 {
-  EnsureGPUReady();
-
   ipc::Endpoint<PCompositorBridgeParent> parentPipe;
   ipc::Endpoint<PCompositorBridgeChild> childPipe;
 
-  base::ProcessId gpuPid = mGPUChild
+  base::ProcessId gpuPid = EnsureGPUReady()
                            ? mGPUChild->OtherPid()
                            : base::GetCurrentProcId();
 
   nsresult rv = PCompositorBridge::CreateEndpoints(
     gpuPid,
     aOtherProcess,
     &parentPipe,
     &childPipe);
   if (NS_FAILED(rv)) {
     gfxCriticalNote << "Could not create content compositor bridge: " << hexa(int(rv));
     return false;
   }
 
-  if (mGPUChild) {
+  if (EnsureGPUReady()) {
     mGPUChild->SendNewContentCompositorBridge(Move(parentPipe));
   } else {
     if (!CompositorBridgeParent::CreateForContent(Move(parentPipe))) {
       return false;
     }
   }
 
   *aOutEndpoint = Move(childPipe);
@@ -730,17 +723,17 @@ GPUProcessManager::CreateContentImageBri
     aOtherProcess,
     &parentPipe,
     &childPipe);
   if (NS_FAILED(rv)) {
     gfxCriticalNote << "Could not create content compositor bridge: " << hexa(int(rv));
     return false;
   }
 
-  if (mGPUChild) {
+  if (EnsureGPUReady()) {
     mGPUChild->SendNewContentImageBridge(Move(parentPipe));
   } else {
     if (!ImageBridgeParent::CreateForContent(Move(parentPipe))) {
       return false;
     }
   }
 
   *aOutEndpoint = Move(childPipe);
@@ -773,33 +766,33 @@ GPUProcessManager::CreateContentVRManage
     aOtherProcess,
     &parentPipe,
     &childPipe);
   if (NS_FAILED(rv)) {
     gfxCriticalNote << "Could not create content compositor bridge: " << hexa(int(rv));
     return false;
   }
 
-  if (mGPUChild) {
+  if (EnsureGPUReady()) {
     mGPUChild->SendNewContentVRManager(Move(parentPipe));
   } else {
     if (!VRManagerParent::CreateForContent(Move(parentPipe))) {
       return false;
     }
   }
 
   *aOutEndpoint = Move(childPipe);
   return true;
 }
 
 void
 GPUProcessManager::CreateContentVideoDecoderManager(base::ProcessId aOtherProcess,
                                                     ipc::Endpoint<dom::PVideoDecoderManagerChild>* aOutEndpoint)
 {
-  if (!mGPUChild || !MediaPrefs::PDMUseGPUDecoder()) {
+  if (!EnsureGPUReady() || !MediaPrefs::PDMUseGPUDecoder()) {
     return;
   }
 
   ipc::Endpoint<dom::PVideoDecoderManagerParent> parentPipe;
   ipc::Endpoint<dom::PVideoDecoderManagerChild> childPipe;
 
   nsresult rv = dom::PVideoDecoderManager::CreateEndpoints(
     mGPUChild->OtherPid(),
@@ -823,29 +816,29 @@ GPUProcessManager::GetAPZCTreeManagerFor
   return CompositorBridgeParent::GetAPZCTreeManager(aLayersId);
 }
 
 void
 GPUProcessManager::MapLayerTreeId(uint64_t aLayersId, base::ProcessId aOwningId)
 {
   LayerTreeOwnerTracker::Get()->Map(aLayersId, aOwningId);
 
-  if (mGPUChild) {
+  if (EnsureGPUReady()) {
     AutoTArray<LayerTreeIdMapping, 1> mappings;
     mappings.AppendElement(LayerTreeIdMapping(aLayersId, aOwningId));
     mGPUChild->SendAddLayerTreeIdMapping(mappings);
   }
 }
 
 void
 GPUProcessManager::UnmapLayerTreeId(uint64_t aLayersId, base::ProcessId aOwningId)
 {
   LayerTreeOwnerTracker::Get()->Unmap(aLayersId, aOwningId);
 
-  if (mGPUChild) {
+  if (EnsureGPUReady()) {
     mGPUChild->SendRemoveLayerTreeIdMapping(LayerTreeIdMapping(aLayersId, aOwningId));
     return;
   }
   CompositorBridgeParent::DeallocateLayerTreeId(aLayersId);
 }
 
 bool
 GPUProcessManager::IsLayerTreeIdMapped(uint64_t aLayersId, base::ProcessId aRequestingId)
@@ -899,17 +892,17 @@ void
 GPUProcessManager::RemoveListener(GPUProcessListener* aListener)
 {
   mListeners.RemoveElement(aListener);
 }
 
 bool
 GPUProcessManager::NotifyGpuObservers(const char* aTopic)
 {
-  if (!mGPUChild) {
+  if (!EnsureGPUReady()) {
     return false;
   }
   nsCString topic(aTopic);
   mGPUChild->SendNotifyGpuObservers(topic);
   return true;
 }
 
 class GPUMemoryReporter : public MemoryReportingProcess
@@ -957,16 +950,16 @@ private:
 
 protected:
   ~GPUMemoryReporter() = default;
 };
 
 RefPtr<MemoryReportingProcess>
 GPUProcessManager::GetProcessMemoryReporter()
 {
-  if (!mGPUChild) {
+  if (!EnsureGPUReady()) {
     return nullptr;
   }
   return new GPUMemoryReporter();
 }
 
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/ipc/GPUProcessManager.h
+++ b/gfx/ipc/GPUProcessManager.h
@@ -75,17 +75,17 @@ public:
   ~GPUProcessManager();
 
   // If not using a GPU process, launch a new GPU process asynchronously.
   void LaunchGPUProcess();
 
   // Ensure that GPU-bound methods can be used. If no GPU process is being
   // used, or one is launched and ready, this function returns immediately.
   // Otherwise it blocks until the GPU process has finished launching.
-  void EnsureGPUReady();
+  bool EnsureGPUReady();
 
   RefPtr<CompositorSession> CreateTopLevelCompositor(
     nsBaseWidget* aWidget,
     LayerManager* aLayerManager,
     CSSToLayoutDeviceScale aScale,
     const CompositorOptions& aOptions,
     bool aUseExternalSurfaceSize,
     const gfx::IntSize& aSurfaceSize);