Bug 1452390 - Make WebRenderScrollData::HasMetadataFor work properly on the parent side. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 11 May 2018 21:18:21 -0400
changeset 794499 d8b7069bf6cad9449102739d276129d5ce3aa405
parent 794498 2083171b3ecbc178bc5eaebe629a28800635bd1b
child 794500 61f51684cc29e527504f1ec72824bf5b53fa1853
push id109697
push userbmo:sledru@mozilla.com
push dateSat, 12 May 2018 10:04:34 +0000
reviewersbotond
bugs1452390
milestone62.0a1
Bug 1452390 - Make WebRenderScrollData::HasMetadataFor work properly on the parent side. r=botond MozReview-Commit-ID: A2ScgCFVZ8J
gfx/layers/wr/WebRenderScrollData.cpp
gfx/layers/wr/WebRenderScrollData.h
--- a/gfx/layers/wr/WebRenderScrollData.cpp
+++ b/gfx/layers/wr/WebRenderScrollData.cpp
@@ -250,10 +250,21 @@ WebRenderScrollData::Dump() const
 {
   printf_stderr("WebRenderScrollData with %zu layers firstpaint: %d\n",
       mLayerScrollData.Length(), mIsFirstPaint);
   for (size_t i = 0; i < mLayerScrollData.Length(); i++) {
     mLayerScrollData.ElementAt(i).Dump(*this);
   }
 }
 
+bool
+WebRenderScrollData::RepopulateMap()
+{
+  MOZ_ASSERT(mScrollIdMap.empty());
+  for (size_t i = 0; i < mScrollMetadatas.Length(); i++) {
+    FrameMetrics::ViewID scrollId = mScrollMetadatas[i].GetMetrics().GetScrollId();
+    mScrollIdMap.emplace(scrollId, i);
+  }
+  return true;
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderScrollData.h
+++ b/gfx/layers/wr/WebRenderScrollData.h
@@ -155,25 +155,30 @@ public:
   void SetPaintSequenceNumber(uint32_t aPaintSequenceNumber);
   uint32_t GetPaintSequenceNumber() const;
 
   friend struct IPC::ParamTraits<WebRenderScrollData>;
 
   void Dump() const;
 
 private:
+  // This is called by the ParamTraits implementation to rebuild mScrollIdMap
+  // based on mScrollMetadatas
+  bool RepopulateMap();
+
+private:
   // Pointer back to the layer manager; if this is non-null, it will always be
   // valid, because the WebRenderLayerManager that created |this| will
   // outlive |this|.
   WebRenderLayerManager* MOZ_NON_OWNING_REF mManager;
 
   // Internal data structure used to maintain uniqueness of mScrollMetadatas.
-  // This is not serialized/deserialized over IPC because there's no need for it,
-  // as the parent side doesn't need this at all. Also because we don't have any
-  // IPC-friendly hashtable implementation lying around.
+  // This is not serialized/deserialized over IPC, but it is rebuilt on the
+  // parent side when mScrollMetadatas is deserialized. So it should always be
+  // valid on both the child and parent.
   // The key into this map is the scrollId of a ScrollMetadata, and the value is
   // an index into the mScrollMetadatas array.
   std::map<FrameMetrics::ViewID, size_t> mScrollIdMap;
 
   // A list of all the unique ScrollMetadata objects from the layer tree. Each
   // ScrollMetadata in this list must have a unique scroll id.
   nsTArray<ScrollMetadata> mScrollMetadatas;
 
@@ -265,15 +270,16 @@ struct ParamTraits<mozilla::layers::WebR
 
   static bool
   Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
     return ReadParam(aMsg, aIter, &aResult->mScrollMetadatas)
         && ReadParam(aMsg, aIter, &aResult->mLayerScrollData)
         && ReadParam(aMsg, aIter, &aResult->mFocusTarget)
         && ReadParam(aMsg, aIter, &aResult->mIsFirstPaint)
-        && ReadParam(aMsg, aIter, &aResult->mPaintSequenceNumber);
+        && ReadParam(aMsg, aIter, &aResult->mPaintSequenceNumber)
+        && aResult->RepopulateMap();
   }
 };
 
 } // namespace IPC
 
 #endif /* GFX_WEBRENDERSCROLLDATA_H */