Bug 1222308 - Assume frames that are very old will never be composited. r=nical, a=lizzard
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 06 Nov 2015 16:56:34 +1300
changeset 296705 8c199302644e
parent 296704 84b0b59ed1d2
child 296706 9fbc92fa9e4b
push id5297
push usercbook@mozilla.com
push date2015-11-12 11:11 +0000
treeherdermozilla-beta@8c199302644e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, lizzard
bugs1222308
milestone43.0
Bug 1222308 - Assume frames that are very old will never be composited. r=nical, a=lizzard This also makes NotifyCompositeInternal take O(N) time in the length of mFrameIDsNotYetComposited instead of O(N^2).
gfx/layers/ImageContainer.cpp
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -257,16 +257,24 @@ ImageContainer::SetCurrentImageInternal(
             img.mTimeStamp >= aImages[0].mTimeStamp) {
           break;
         }
         if (!img.mComposited && !img.mTimeStamp.IsNull() &&
             img.mFrameID != aImages[0].mFrameID) {
           mFrameIDsNotYetComposited.AppendElement(img.mFrameID);
         }
       }
+
+      // Remove really old frames, assuming they'll never be composited.
+      const uint32_t maxFrames = 100;
+      if (mFrameIDsNotYetComposited.Length() > maxFrames) {
+        uint32_t dropFrames = mFrameIDsNotYetComposited.Length() - maxFrames;
+        mDroppedImageCount += dropFrames;
+        mFrameIDsNotYetComposited.RemoveElementsAt(0, dropFrames);
+      }
     }
   }
 
   nsTArray<OwningImage> newImages;
 
   for (uint32_t i = 0; i < aImages.Length(); ++i) {
     NS_ASSERTION(aImages[i].mImage, "image can't be null");
     NS_ASSERTION(!aImages[i].mTimeStamp.IsNull() || aImages.Length() == 1,
@@ -392,26 +400,27 @@ ImageContainer::NotifyCompositeInternal(
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
   // An image composition notification is sent the first time a particular
   // image is composited by an ImageHost. Thus, every time we receive such
   // a notification, a new image has been painted.
   ++mPaintCount;
 
   if (aNotification.producerID() == mCurrentProducerID) {
-    while (!mFrameIDsNotYetComposited.IsEmpty()) {
-      if (mFrameIDsNotYetComposited[0] <= aNotification.frameID()) {
-        if (mFrameIDsNotYetComposited[0] < aNotification.frameID()) {
+    uint32_t i;
+    for (i = 0; i < mFrameIDsNotYetComposited.Length(); ++i) {
+      if (mFrameIDsNotYetComposited[i] <= aNotification.frameID()) {
+        if (mFrameIDsNotYetComposited[i] < aNotification.frameID()) {
           ++mDroppedImageCount;
         }
-        mFrameIDsNotYetComposited.RemoveElementAt(0);
       } else {
         break;
       }
     }
+    mFrameIDsNotYetComposited.RemoveElementsAt(0, i);
     for (auto& img : mCurrentImages) {
       if (img.mFrameID == aNotification.frameID()) {
         img.mComposited = true;
       }
     }
   }
 
   if (!aNotification.imageTimeStamp().IsNull()) {