Bug 1455974 - Ensure the metrics sharing IPC messages are sent from the compositor thread. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 23 Apr 2018 14:24:36 -0400
changeset 786633 cea986983c9859c681ce79e6bbc40ab6eb0e551c
parent 786632 cd675f40c1d9a8df75975de593c6b62fed9a849a
child 786634 594ddff2e3c32cc2676d9aad20ff8c219ccccb93
push id107548
push userkgupta@mozilla.com
push dateMon, 23 Apr 2018 18:24:55 +0000
reviewersbotond
bugs1455974
milestone61.0a1
Bug 1455974 - Ensure the metrics sharing IPC messages are sent from the compositor thread. r?botond With WR+async scene building, the updater thread is no longer the compositor thread, but we can only send the IPC messages from the compositor thread. So we need to bounce those calls over to the right thread. MozReview-Commit-ID: 6M9bSLYLi5n
gfx/layers/ipc/CompositorBridgeParent.cpp
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -173,39 +173,72 @@ CompositorBridgeParentBase::AllocUnsafeS
 }
 
 void
 CompositorBridgeParentBase::DeallocShmem(ipc::Shmem& aShmem)
 {
   PCompositorBridgeParent::DeallocShmem(aShmem);
 }
 
+static inline MessageLoop*
+CompositorLoop()
+{
+  return CompositorThreadHolder::Loop();
+}
+
 base::ProcessId
 CompositorBridgeParentBase::RemotePid()
 {
   return OtherPid();
 }
 
 bool
 CompositorBridgeParentBase::StartSharingMetrics(ipc::SharedMemoryBasic::Handle aHandle,
                                                 CrossProcessMutexHandle aMutexHandle,
                                                 LayersId aLayersId,
                                                 uint32_t aApzcId)
 {
+  if (!CompositorThreadHolder::IsInCompositorThread()) {
+    MOZ_ASSERT(CompositorLoop());
+    CompositorLoop()->PostTask(
+      NewRunnableMethod<ipc::SharedMemoryBasic::Handle,
+                        CrossProcessMutexHandle,
+                        LayersId,
+                        uint32_t>(
+        "layers::CompositorBridgeParent::StartSharingMetrics",
+        this,
+        &CompositorBridgeParentBase::StartSharingMetrics,
+        aHandle, aMutexHandle, aLayersId, aApzcId));
+    return true;
+  }
+
+  MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   if (!mCanSend) {
     return false;
   }
   return PCompositorBridgeParent::SendSharedCompositorFrameMetrics(
     aHandle, aMutexHandle, aLayersId, aApzcId);
 }
 
 bool
 CompositorBridgeParentBase::StopSharingMetrics(FrameMetrics::ViewID aScrollId,
                                                uint32_t aApzcId)
 {
+  if (!CompositorThreadHolder::IsInCompositorThread()) {
+    MOZ_ASSERT(CompositorLoop());
+    CompositorLoop()->PostTask(
+      NewRunnableMethod<FrameMetrics::ViewID, uint32_t>(
+        "layers::CompositorBridgeParent::StopSharingMetrics",
+        this,
+        &CompositorBridgeParentBase::StopSharingMetrics,
+        aScrollId, aApzcId));
+    return true;
+  }
+
+  MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   if (!mCanSend) {
     return false;
   }
   return PCompositorBridgeParent::SendReleaseSharedCompositorFrameMetrics(
     aScrollId, aApzcId);
 }
 
 CompositorBridgeParent::LayerTreeState::LayerTreeState()
@@ -308,22 +341,16 @@ CalculateCompositionFrameRate()
       return defaultFrameRate;
     }
     return layoutFrameRatePref;
   }
   return compositionFrameRatePref;
 }
 #endif
 
-static inline MessageLoop*
-CompositorLoop()
-{
-  return CompositorThreadHolder::Loop();
-}
-
 CompositorBridgeParent::CompositorBridgeParent(CompositorManagerParent* aManager,
                                                CSSToLayoutDeviceScale aScale,
                                                const TimeDuration& aVsyncRate,
                                                const CompositorOptions& aOptions,
                                                bool aUseExternalSurfaceSize,
                                                const gfx::IntSize& aSurfaceSize)
   : CompositorBridgeParentBase(aManager)
   , mWidget(nullptr)