Bug 1501442 - Part 1: Add CompositionPayload type and allow submitting it as part of a transaction. r=mstange
authorBas Schouten <bschouten@mozilla.com>
Thu, 13 Dec 2018 15:59:22 +0100
changeset 509994 4c1fade7ceeb6407592d43ad0276c4b8090c3e7a
parent 509964 3131c1c9f3c5ea1c0f9c163ac560a0296c7b8f8e
child 509995 76070b4feec3c735818b859e3bb577941f284c30
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1501442
milestone66.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 1501442 - Part 1: Add CompositionPayload type and allow submitting it as part of a transaction. r=mstange
gfx/layers/Layers.h
gfx/layers/LayersTypes.h
gfx/layers/client/ClientLayerManager.cpp
gfx/layers/composite/LayerManagerComposite.cpp
gfx/layers/ipc/LayersMessageUtils.h
gfx/layers/ipc/LayersMessages.ipdlh
gfx/layers/ipc/ShadowLayers.cpp
gfx/layers/ipc/ShadowLayers.h
gfx/layers/mlgpu/LayerManagerMLGPU.cpp
gfx/layers/wr/WebRenderLayerManager.cpp
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -726,16 +726,25 @@ class LayerManager : public FrameRecorde
   }
 
   virtual void SetTransactionIdAllocator(TransactionIdAllocator* aAllocator) {}
 
   virtual TransactionId GetLastTransactionId() { return TransactionId{0}; }
 
   virtual CompositorBridgeChild* GetCompositorBridgeChild() { return nullptr; }
 
+  void RegisterPayload(const CompositionPayload& aPayload) {
+    mPayload.AppendElement(aPayload);
+    MOZ_ASSERT(mPayload.Length() < 10000);
+  }
+  void RegisterPayload(const InfallibleTArray<CompositionPayload>& aPayload) {
+    mPayload.AppendElements(aPayload);
+    MOZ_ASSERT(mPayload.Length() < 10000);
+  }
+
  protected:
   RefPtr<Layer> mRoot;
   gfx::UserData mUserData;
   bool mDestroyed;
   bool mSnapEffectiveTransforms;
 
   nsIntRegion mRegionToClear;
 
@@ -752,16 +761,24 @@ class LayerManager : public FrameRecorde
 
   uint64_t mId;
   bool mInTransaction;
   // The time when painting most recently finished. This is recorded so that
   // we can time any play-pending animations from this point.
   TimeStamp mAnimationReadyTime;
   // The count of pixels that were painted in the current transaction.
   uint32_t mPaintedPixelCount;
+  // The payload associated with currently pending painting work, for
+  // client layer managers that typically means payload that is part of the
+  // 'upcoming transaction', for HostLayerManagers this typically means
+  // what has been included in received transactions to be presented on the
+  // next composite.
+  // IMPORTANT: Clients should take care to clear this or risk it slowly
+  // growing out of control.
+  InfallibleTArray<CompositionPayload> mPayload;
 
  public:
   /*
    * Methods to store/get/clear a "pending scroll info update" object on a
    * per-scrollid basis. This is used for empty transactions that push over
    * scroll position updates to the APZ code.
    */
   virtual bool SetPendingScrollUpdateForNextTransaction(
--- a/gfx/layers/LayersTypes.h
+++ b/gfx/layers/LayersTypes.h
@@ -8,16 +8,17 @@
 #define GFX_LAYERSTYPES_H
 
 #include <stdint.h>  // for uint32_t
 
 #include "Units.h"
 #include "mozilla/DefineEnum.h"  // for MOZ_DEFINE_ENUM
 #include "mozilla/gfx/Point.h"   // for IntPoint
 #include "mozilla/Maybe.h"
+#include "mozilla/TimeStamp.h"   // for TimeStamp
 #include "mozilla/TypedEnumBits.h"
 #include "nsRegion.h"
 #include "nsStyleConsts.h"
 
 #include <stdio.h>            // FILE
 #include "mozilla/Logging.h"  // for PR_LOG
 
 #ifndef MOZ_LAYERS_HAVE_LOG
@@ -405,14 +406,30 @@ class CompositableHandle {
   uint64_t mHandle;
 };
 
 // clang-format off
 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection, uint32_t, (
   eVertical,
   eHorizontal
 ));
+
+MOZ_DEFINE_ENUM_CLASS_WITH_BASE(CompositionPayloadType, uint8_t, (
+  eKeyPress,
+  eAPZScroll,
+  eAPZPinchZoom
+));
 // clang-format on
 
+struct CompositionPayload {
+  bool operator ==(const CompositionPayload& aOther) const {
+    return mType == aOther.mType && mTimeStamp == aOther.mTimeStamp;
+  }
+  /* The type of payload that is in this composition */
+  CompositionPayloadType mType;
+  /* When this payload was generated */
+  TimeStamp mTimeStamp;
+};
+
 }  // namespace layers
 }  // namespace mozilla
 
 #endif /* GFX_LAYERSTYPES_H */
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -691,19 +691,22 @@ void ClientLayerManager::ForwardTransact
 
   // forward this transaction's changeset to our LayerManagerComposite
   bool sent = false;
   bool ok = mForwarder->EndTransaction(
       mRegionToClear, mLatestTransactionId, aScheduleComposite,
       mPaintSequenceNumber, mIsRepeatTransaction,
       mTransactionIdAllocator->GetVsyncId(),
       mTransactionIdAllocator->GetVsyncStart(), refreshStart, mTransactionStart,
-      mURL, &sent);
+      mURL, &sent, mPayload);
+
   if (ok) {
     if (sent) {
+      // Our payload has now been dispatched.
+      mPayload.Clear();
       mNeedsComposite = false;
     }
   } else if (HasShadowManager()) {
     NS_WARNING("failed to forward Layers transaction");
   }
 
   if (!sent) {
     // Clear the transaction id so that it doesn't get returned
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -970,16 +970,18 @@ void LayerManagerComposite::Render(const
     mCompositor->EndFrame();
   }
 
   mCompositor->GetWidget()->PostRender(&widgetContext);
 
   mProfilerScreenshotGrabber.MaybeProcessQueue();
 
   RecordFrame();
+  // Our payload has now been presented.
+  mPayload.Clear();
 }
 
 #if defined(MOZ_WIDGET_ANDROID)
 class ScopedCompostitorSurfaceSize {
  public:
   ScopedCompostitorSurfaceSize(CompositorOGL* aCompositor,
                                const gfx::IntSize& aSize)
       : mCompositor(aCompositor),
--- a/gfx/layers/ipc/LayersMessageUtils.h
+++ b/gfx/layers/ipc/LayersMessageUtils.h
@@ -707,12 +707,35 @@ struct ParamTraits<mozilla::layers::Comp
 
 template <>
 struct ParamTraits<mozilla::layers::SimpleLayerAttributes>
     : public PlainOldDataSerializer<mozilla::layers::SimpleLayerAttributes> {};
 
 template <>
 struct ParamTraits<mozilla::layers::ScrollUpdateInfo>
     : public PlainOldDataSerializer<mozilla::layers::ScrollUpdateInfo> {};
+ 
+template <>
+struct ParamTraits<mozilla::layers::CompositionPayloadType>
+    : public ContiguousEnumSerializerInclusive<
+          mozilla::layers::CompositionPayloadType,
+          mozilla::layers::CompositionPayloadType::eKeyPress,
+          mozilla::layers::kHighestCompositionPayloadType> {};
+
+template <>
+struct ParamTraits<mozilla::layers::CompositionPayload>
+{
+  typedef mozilla::layers::CompositionPayload paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam) {
+    WriteParam(aMsg, aParam.mType);
+    WriteParam(aMsg, aParam.mTimeStamp);
+  }
+
+  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
+    return ReadParam(aMsg, aIter, &aResult->mType) &&
+           ReadParam(aMsg, aIter, &aResult->mTimeStamp);
+  }
+};
 
 } /* namespace IPC */
 
 #endif /* mozilla_layers_LayersMessageUtils */
--- a/gfx/layers/ipc/LayersMessages.ipdlh
+++ b/gfx/layers/ipc/LayersMessages.ipdlh
@@ -42,16 +42,17 @@ using mozilla::layers::EventRegions from
 using mozilla::layers::EventRegionsOverride from "mozilla/layers/LayersTypes.h";
 using mozilla::layers::DiagnosticTypes from "mozilla/layers/CompositorTypes.h";
 using mozilla::layers::FocusTarget from "mozilla/layers/FocusTarget.h";
 using struct mozilla::layers::ScrollMetadata from "FrameMetrics.h";
 using mozilla::layers::ScrollableLayerGuid::ViewID from "mozilla/layers/ScrollableLayerGuid.h";
 using mozilla::layers::LayersBackend from "mozilla/layers/LayersTypes.h";
 using mozilla::layers::LayerHandle from "mozilla/layers/LayersTypes.h";
 using mozilla::layers::CompositableHandle from "mozilla/layers/LayersTypes.h";
+using mozilla::layers::CompositionPayload from "mozilla/layers/LayersTypes.h";
 using mozilla::layers::SimpleLayerAttributes from "mozilla/layers/LayerAttributes.h";
 using mozilla::CrossProcessSemaphoreHandle from "mozilla/ipc/CrossProcessSemaphore.h";
 using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
 using mozilla::layers::LayersId from "mozilla/layers/LayersTypes.h";
 using mozilla::layers::TransactionId from "mozilla/layers/LayersTypes.h";
 using mozilla::VsyncId from "mozilla/VsyncDispatcher.h";
 
 namespace mozilla {
@@ -555,16 +556,20 @@ struct TransactionInfo
   uint32_t paintSequenceNumber;
   bool isRepeatTransaction;
   VsyncId vsyncId;
   TimeStamp vsyncStart;
   TimeStamp refreshStart;
   TimeStamp transactionStart;
   nsCString url;
   TimeStamp fwdTime;
+  /* This provides some timing information on any content that is meant to be
+   * presented during this transaction.
+   */
+  CompositionPayload[] payload;
 };
 
 union MaybeTransform {
   Matrix4x4;
   void_t;
 };
 
 union OMTAValue {
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -527,17 +527,17 @@ void ShadowLayerForwarder::SendPaintTime
 
 bool ShadowLayerForwarder::EndTransaction(
     const nsIntRegion& aRegionToClear, TransactionId aId,
     bool aScheduleComposite, uint32_t aPaintSequenceNumber,
     bool aIsRepeatTransaction, const mozilla::VsyncId& aVsyncId,
     const mozilla::TimeStamp& aVsyncStart,
     const mozilla::TimeStamp& aRefreshStart,
     const mozilla::TimeStamp& aTransactionStart, const nsCString& aURL,
-    bool* aSent) {
+    bool* aSent, const InfallibleTArray<CompositionPayload>& aPayload) {
   *aSent = false;
 
   TransactionInfo info;
 
   MOZ_ASSERT(IPCOpen(), "no manager to forward to");
   if (!IPCOpen()) {
     return false;
   }
@@ -675,16 +675,17 @@ bool ShadowLayerForwarder::EndTransactio
   info.vsyncId() = aVsyncId;
   info.vsyncStart() = aVsyncStart;
   info.refreshStart() = aRefreshStart;
   info.transactionStart() = aTransactionStart;
   info.url() = aURL;
 #if defined(ENABLE_FRAME_LATENCY_LOG)
   info.fwdTime() = TimeStamp::Now();
 #endif
+  info.payload() = aPayload;
 
   TargetConfig targetConfig(mTxn->mTargetBounds, mTxn->mTargetRotation,
                             mTxn->mTargetOrientation, aRegionToClear);
   info.targetConfig() = targetConfig;
 
   if (!GetTextureForwarder()->IsSameProcess()) {
     MOZ_LAYERS_LOG(("[LayersForwarder] syncing before send..."));
     PlatformSyncBeforeUpdate();
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -251,17 +251,19 @@ class ShadowLayerForwarder final : publi
    */
   bool EndTransaction(const nsIntRegion& aRegionToClear, TransactionId aId,
                       bool aScheduleComposite, uint32_t aPaintSequenceNumber,
                       bool aIsRepeatTransaction,
                       const mozilla::VsyncId& aVsyncId,
                       const mozilla::TimeStamp& aVsyncTime,
                       const mozilla::TimeStamp& aRefreshStart,
                       const mozilla::TimeStamp& aTransactionStart,
-                      const nsCString& aURL, bool* aSent);
+                      const nsCString& aURL, bool* aSent,
+                      const InfallibleTArray<CompositionPayload>& aPayload =
+                          InfallibleTArray<CompositionPayload>());
 
   /**
    * Set an actor through which layer updates will be pushed.
    */
   void SetShadowManager(PLayerTransactionChild* aShadowManager);
 
   /**
    * Layout calls here to cache current plugin widget configuration
--- a/gfx/layers/mlgpu/LayerManagerMLGPU.cpp
+++ b/gfx/layers/mlgpu/LayerManagerMLGPU.cpp
@@ -299,16 +299,18 @@ void LayerManagerMLGPU::Composite() {
   // extra invalidation.
   //
   // Note that the old Compositor performs occlusion culling directly on the
   // shadow visible region, and does this *before* cloning layer tree
   // properties. Advanced Layers keeps the occlusion region separate and
   // performs invalidation against the clean layer tree.
   mClonedLayerTreeProperties = nullptr;
   mClonedLayerTreeProperties = LayerProperties::CloneFrom(mRoot);
+
+  mPayload.Clear();
 }
 
 void LayerManagerMLGPU::RenderLayers() {
   AUTO_PROFILER_LABEL("LayerManagerMLGPU::RenderLayers", GRAPHICS);
 
   // Traverse the layer tree and assign each layer to a render target.
   FrameBuilder builder(this, mSwapChain);
   mCurrentFrame = &builder;
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -517,16 +517,19 @@ void WebRenderLayerManager::DidComposite
   MOZ_ASSERT(mWidget);
 
   // Notifying the observers may tick the refresh driver which can cause
   // a lot of different things to happen that may affect the lifetime of
   // this layer manager. So let's make sure this object stays alive until
   // the end of the method invocation.
   RefPtr<WebRenderLayerManager> selfRef = this;
 
+  // XXX - Currently we don't track this. Make sure it doesn't just grow though.
+  mPayload.Clear();
+
   // |aTransactionId| will be > 0 if the compositor is acknowledging a shadow
   // layers transaction.
   if (aTransactionId.IsValid()) {
     nsIWidgetListener* listener = mWidget->GetWidgetListener();
     if (listener) {
       listener->DidCompositeWindow(aTransactionId, aCompositeStart,
                                    aCompositeEnd);
     }