Convert WeakFrame to nsIFrame* earlier
authorMiko Mynttinen <mikokm@gmail.com>
Tue, 17 Oct 2017 19:08:54 +0200
changeset 685679 902fb74ca4002ac2300c41203cb5d540df00ff33
parent 685678 a4758024dc354d2608accaae5543d636824c1f29
child 685680 912061a6ab946b861a6d85219a25e831f8782535
push id86010
push userbmo:ethlin@mozilla.com
push dateWed, 25 Oct 2017 00:44:42 +0000
milestone58.0a1
Convert WeakFrame to nsIFrame* earlier
layout/painting/RetainedDisplayListBuilder.cpp
layout/painting/RetainedDisplayListBuilder.h
--- a/layout/painting/RetainedDisplayListBuilder.cpp
+++ b/layout/painting/RetainedDisplayListBuilder.cpp
@@ -474,62 +474,68 @@ RetainedDisplayListBuilder::MergeDisplay
       old->Destroy(&mBuilder);
     }
   }
 
   aOutList->AppendToTop(&merged);
 }
 
 static void
-AddModifiedFramesFromRootFrame(std::vector<WeakFrame>& aFrames,
+AddModifiedFramesFromRootFrame(nsTArray<nsIFrame*>& aFrames,
                                nsIFrame* aRootFrame)
 {
   MOZ_ASSERT(aRootFrame);
 
   std::vector<WeakFrame>* frames =
     aRootFrame->GetProperty(nsIFrame::ModifiedFrameList());
 
-  if (frames) {
-    for (WeakFrame& frame : *frames) {
-      aFrames.push_back(Move(frame));
+  if (!frames) {
+    return;
+  }
+
+  for (WeakFrame& frame : *frames) {
+    nsIFrame* f = frame.GetFrame();
+
+    if (f) {
+      aFrames.AppendElement(f);
     }
+  }
 
-    frames->clear();
-  }
+  frames->clear();
 }
 
 static bool
 SubDocEnumCb(nsIDocument* aDocument, void* aData)
 {
   MOZ_ASSERT(aDocument);
   MOZ_ASSERT(aData);
 
-  std::vector<WeakFrame>* modifiedFrames =
-    static_cast<std::vector<WeakFrame>*>(aData);
+  nsTArray<nsIFrame*>* modifiedFrames =
+    static_cast<nsTArray<nsIFrame*>*>(aData);
 
   nsIPresShell* presShell = aDocument->GetShell();
   nsIFrame* rootFrame = presShell ? presShell->GetRootFrame() : nullptr;
 
   if (rootFrame) {
     AddModifiedFramesFromRootFrame(*modifiedFrames, rootFrame);
   }
 
   aDocument->EnumerateSubDocuments(SubDocEnumCb, aData);
   return true;
 }
 
-static std::vector<WeakFrame>
+static nsTArray<nsIFrame*>
 GetModifiedFrames(nsIFrame* aDisplayRootFrame)
 {
   MOZ_ASSERT(aDisplayRootFrame);
 
-  std::vector<WeakFrame> modifiedFrames;
+  nsTArray<nsIFrame*> modifiedFrames;
   AddModifiedFramesFromRootFrame(modifiedFrames, aDisplayRootFrame);
 
-  nsIDocument *rootdoc = aDisplayRootFrame->PresContext()->Document();
+  nsIDocument* rootdoc = aDisplayRootFrame->PresContext()->Document();
 
   if (rootdoc) {
     rootdoc->EnumerateSubDocuments(SubDocEnumCb, &modifiedFrames);
   }
 
   return modifiedFrames;
 }
 
@@ -563,26 +569,24 @@ GetModifiedFrames(nsIFrame* aDisplayRoot
  * @param aOutModifiedAGR The modified AGR for the root stacking context.
  * @param aOutFramesWithProps The list of frames to which we attached partial build
  * data so that it can be cleaned up.
  *
  * @return true if we succesfully computed a partial rebuild region, false if a full
  * build is required.
  */
 bool
-RetainedDisplayListBuilder::ComputeRebuildRegion(std::vector<WeakFrame>& aModifiedFrames,
+RetainedDisplayListBuilder::ComputeRebuildRegion(nsTArray<nsIFrame*>& aModifiedFrames,
                                                  nsRect* aOutDirty,
                                                  AnimatedGeometryRoot** aOutModifiedAGR,
                                                  nsTArray<nsIFrame*>* aOutFramesWithProps)
 {
   CRR_LOG("Computing rebuild regions for %d frames:\n", aModifiedFrames.size());
   for (nsIFrame* f : aModifiedFrames) {
-    if (!f) {
-      continue;
-    }
+    MOZ_ASSERT(f);
 
     if (f->HasOverrideDirtyRegion()) {
       aOutFramesWithProps->AppendElement(f);
     }
 
     // TODO: There is almost certainly a faster way of doing this, probably can be combined with the ancestor
     // walk for TransformFrameRectToAncestor.
     AnimatedGeometryRoot* agr = mBuilder.FindAnimatedGeometryRootFor(f)->GetAsyncAGR();
@@ -694,32 +698,28 @@ RetainedDisplayListBuilder::ComputeRebui
 
   return true;
 }
 
 /*
  * A simple early exit heuristic to avoid slow partial display list rebuilds.
  */
 static bool
-ShouldBuildPartial(const std::vector<WeakFrame>& aModifiedFrames,
+ShouldBuildPartial(nsTArray<nsIFrame*>& aModifiedFrames,
                    DisplayListStatistics& aStats)
 {
-  aStats.modifiedFrames = aModifiedFrames.size();
+  aStats.modifiedFrames = aModifiedFrames.Length();
 
-  if (aModifiedFrames.size() > gfxPrefs::LayoutRebuildFrameLimit()) {
+  if (aModifiedFrames.Length() > gfxPrefs::LayoutRebuildFrameLimit()) {
     return false;
   }
 
   bool shouldBuildPartial = true;
-  for (const WeakFrame& frame : aModifiedFrames) {
-    nsIFrame* f = frame.GetFrame();
-
-    if (!f) {
-      continue;
-    }
+  for (nsIFrame* f : aModifiedFrames) {
+    MOZ_ASSERT(f);
 
     aStats.frames.AppendElement(f);
 
     const LayoutFrameType type = f->Type();
 
     // If we have any modified frames of the following types, it is likely that
     // doing a partial rebuild of the display list will be slower than doing a
     // full rebuild.
@@ -741,17 +741,17 @@ RetainedDisplayListBuilder::AttemptParti
 {
   mBuilder.RemoveModifiedWindowDraggingRegion();
   if (mBuilder.ShouldSyncDecodeImages()) {
     MarkFramesWithItemsAndImagesModified(&mList);
   }
 
   mBuilder.EnterPresShell(mBuilder.RootReferenceFrame());
 
-  std::vector<WeakFrame> modifiedFrames =
+  nsTArray<nsIFrame*> modifiedFrames =
     GetModifiedFrames(mBuilder.RootReferenceFrame());
 
   const bool shouldBuildPartial = ShouldBuildPartial(modifiedFrames, aStats);
 
   if (mPreviousCaret != mBuilder.GetCaretFrame()) {
     if (mPreviousCaret) {
       mBuilder.MarkFrameModifiedDuringBuilding(mPreviousCaret);
     }
@@ -812,17 +812,16 @@ RetainedDisplayListBuilder::AttemptParti
 
   // TODO: Do we mark frames as modified during displaylist building? If
   // we do this isn't gonna work.
   for (nsIFrame* f : modifiedFrames) {
     if (f) {
       f->SetFrameIsModified(false);
     }
   }
-  modifiedFrames.clear();
 
   for (nsIFrame* f: framesWithProps) {
     f->SetHasOverrideDirtyRegion(false);
     f->DeleteProperty(nsDisplayListBuilder::DisplayListBuildingRect());
     f->DeleteProperty(nsDisplayListBuilder::DisplayListBuildingDisplayPortRect());
   }
 
   return merged;
--- a/layout/painting/RetainedDisplayListBuilder.h
+++ b/layout/painting/RetainedDisplayListBuilder.h
@@ -42,17 +42,17 @@ struct RetainedDisplayListBuilder {
 private:
   void PreProcessDisplayList(nsDisplayList* aList, AnimatedGeometryRoot* aAGR);
 
   void MergeDisplayLists(nsDisplayList* aNewList,
                          nsDisplayList* aOldList,
                          nsDisplayList* aOutList,
                          DisplayListStatistics& aStats);
 
-  bool ComputeRebuildRegion(std::vector<WeakFrame>& aModifiedFrames,
+  bool ComputeRebuildRegion(nsTArray<nsIFrame*>& aModifiedFrames,
                             nsRect* aOutDirty,
                             AnimatedGeometryRoot** aOutModifiedAGR,
                             nsTArray<nsIFrame*>* aOutFramesWithProps);
 
   void IncrementSubDocPresShellPaintCount(nsDisplayItem* aItem);
 
   nsDisplayListBuilder mBuilder;
   nsDisplayList mList;