Bug 1314543 - Make EnsureGPUReady() returns bool to make sure GPU process is readay. r=dvander, a=lizzard
authorvincentliu <vliu@mozilla.com>
Thu, 30 Mar 2017 09:23:24 +0800
changeset 379439 41323426061e6cd60125b5f0728442faca1cbe60
parent 379438 bb73dbc2ab8387d157bba14dc2e931057503f3fd
child 379440 ad3b4d7ad2830000553da75c1887181d8add89ef
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander, lizzard
bugs1314543
milestone53.0
Bug 1314543 - Make EnsureGPUReady() returns bool to make sure GPU process is readay. r=dvander, a=lizzard
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
@@ -66,29 +66,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
@@ -24,17 +24,17 @@ class GPUChild final
     public gfxVarReceiver
 {
 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) override;
--- a/gfx/ipc/GPUProcessManager.cpp
+++ b/gfx/ipc/GPUProcessManager.cpp
@@ -152,43 +152,43 @@ GPUProcessManager::DisableGPUProcess(con
 
   gfxConfig::SetFailed(Feature::GPU_PROCESS, FeatureStatus::Failed, aMessage);
   gfxCriticalNote << aMessage;
 
   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(),
@@ -206,19 +206,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(),
@@ -237,25 +235,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(),
@@ -535,24 +531,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);
@@ -671,36 +666,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);
@@ -724,17 +717,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);
@@ -767,33 +760,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(),
@@ -817,29 +810,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)
@@ -893,17 +886,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;
 }
 
 } // namespace gfx
--- a/gfx/ipc/GPUProcessManager.h
+++ b/gfx/ipc/GPUProcessManager.h
@@ -74,17 +74,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);