Skip recording dragging rect frames when not retaining, and optimize removal of modified rectangles
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 26 Sep 2017 16:28:38 +1300
changeset 685658 8960cfc33561a9c4f78dd2426676747c9826adef
parent 685657 fb5c244ddf0dbfc1da103676d1018839ade51f77
child 685659 6da944a3d704f7a8a7c6b4c56dbb0b338c1b219e
push id86010
push userbmo:ethlin@mozilla.com
push dateWed, 25 Oct 2017 00:44:42 +0000
milestone58.0a1
Skip recording dragging rect frames when not retaining, and optimize removal of modified rectangles
layout/painting/nsDisplayList.cpp
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -1869,21 +1869,25 @@ nsDisplayListBuilder::AdjustWindowDraggi
     LayoutDeviceRect devPixelBorderBox =
       LayoutDevicePixel::FromAppUnits(borderBox, aFrame->PresContext()->AppUnitsPerDevPixel());
     LayoutDeviceRect transformedDevPixelBorderBox =
       TransformBy(referenceFrameToRootReferenceFrame, devPixelBorderBox);
     transformedDevPixelBorderBox.Round();
     LayoutDeviceIntRect transformedDevPixelBorderBoxInt;
     if (transformedDevPixelBorderBox.ToIntRect(&transformedDevPixelBorderBoxInt)) {
       if (styleUI->mWindowDragging == StyleWindowDragging::Drag) {
-        mWindowDraggingFrames.emplace_back(aFrame);
+        if (IsRetainingDisplayList()) {
+          mWindowDraggingFrames.emplace_back(aFrame);
+        }
         mWindowDraggingRects.AppendElement(
           nsRegion::RectToBox(transformedDevPixelBorderBoxInt.ToUnknownRect()));
       } else {
-        mWindowNoDraggingFrames.emplace_back(aFrame);
+        if (IsRetainingDisplayList()) {
+          mWindowNoDraggingFrames.emplace_back(aFrame);
+        }
         mWindowNoDraggingRects.AppendElement(
           nsRegion::RectToBox(transformedDevPixelBorderBoxInt.ToUnknownRect()));
       }
     }
   }
 }
 
 LayoutDeviceIntRegion
@@ -1896,36 +1900,44 @@ nsDisplayListBuilder::GetWindowDraggingR
   result.Sub(dragRegion, noDragRegion);
   return result;
 }
 
 void
 nsDisplayListBuilder::RemoveModifiedWindowDraggingRegion()
 {
   uint32_t i = 0;
-  while (i < mWindowDraggingFrames.size()) {
+  uint32_t length = mWindowDraggingFrames.size();
+  while (i < length) {
     if (!mWindowDraggingFrames[i].IsAlive() ||
         mWindowDraggingFrames[i]->IsFrameModified()) {
-      mWindowDraggingFrames.erase(mWindowDraggingFrames.begin() + i);
-      mWindowDraggingRects.RemoveElementAt(i);
+      mWindowDraggingFrames[i] = mWindowDraggingFrames[length - 1];
+      mWindowDraggingRects[i] = mWindowDraggingRects[length - 1];
+      length--;
     } else {
       i++;
     }
   }
+  mWindowDraggingFrames.resize(length);
+  mWindowDraggingRects.SetLength(length);
   
   i = 0;
-  while (i < mWindowNoDraggingFrames.size()) {
+  length = mWindowNoDraggingFrames.size();
+  while (i < length) {
     if (!mWindowNoDraggingFrames[i].IsAlive() ||
         mWindowNoDraggingFrames[i]->IsFrameModified()) {
-      mWindowNoDraggingFrames.erase(mWindowDraggingFrames.begin() + i);
-      mWindowNoDraggingRects.RemoveElementAt(i);
+      mWindowNoDraggingFrames[i] = mWindowNoDraggingFrames[length - 1];
+      mWindowNoDraggingRects[i] = mWindowNoDraggingRects[length - 1];
+      length--;
     } else {
       i++;
     }
   }
+  mWindowNoDraggingFrames.resize(length);
+  mWindowNoDraggingRects.SetLength(length);
 }
 
 void
 nsDisplayListBuilder::ClearWindowDraggingRegion()
 {
   mWindowDraggingFrames.clear();
   mWindowDraggingRects.Clear();
   mWindowNoDraggingFrames.clear();