Bug 1293794 - Allow imgFrame volatile buffers to be freed on all platforms. r=jrmuizel
authorSeth Fowler <mark.seth.fowler@gmail.com>
Tue, 09 Aug 2016 14:47:26 -0700
changeset 353086 e1e30e96ea5a5aca494f90159ba86edb7683556d
parent 353085 b41fac93dc9087b4f7e6b71a2d3d80c7a6928f60
child 353087 4af6ac9ead4a07edb29d287bb1ca17773045695e
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1293794
milestone51.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 1293794 - Allow imgFrame volatile buffers to be freed on all platforms. r=jrmuizel
image/imgFrame.cpp
--- a/image/imgFrame.cpp
+++ b/image/imgFrame.cpp
@@ -438,28 +438,27 @@ imgFrame::Optimize()
 
   mOptSurface = gfxPlatform::GetPlatform()
     ->ScreenReferenceDrawTarget()->OptimizeSourceSurface(mImageSurface);
   if (mOptSurface == mImageSurface) {
     mOptSurface = nullptr;
   }
 
   if (mOptSurface) {
+    // There's no reason to keep our volatile buffer around at all if we have an
+    // optimized surface. Release our reference to it. This will leave
+    // |mVBufPtr| and |mImageSurface| as the only things keeping it alive, so
+    // it'll get freed below.
     mVBuf = nullptr;
-    mVBufPtr = nullptr;
-    mImageSurface = nullptr;
   }
 
-#ifdef MOZ_WIDGET_ANDROID
-  // On Android, free mImageSurface unconditionally if we're discardable. This
-  // allows the operating system to free our volatile buffer.
-  // XXX(seth): We'd eventually like to do this on all platforms, but right now
-  // converting raw memory to a SourceSurface is expensive on some backends.
+  // Release all strong references to our volatile buffer's memory. This will
+  // allow the operating system to free the memory if it needs to.
+  mVBufPtr = nullptr;
   mImageSurface = nullptr;
-#endif
 
   return NS_OK;
 }
 
 DrawableFrameRef
 imgFrame::DrawableRef()
 {
   return DrawableFrameRef(this);
@@ -784,24 +783,19 @@ imgFrame::UnlockImageData()
   if (mLockCount == 1 && !mPalettedImageData) {
     // We can't safely optimize off-main-thread, so create a runnable to do it.
     if (!NS_IsMainThread()) {
       nsCOMPtr<nsIRunnable> runnable = new UnlockImageDataRunnable(this);
       NS_DispatchToMainThread(runnable);
       return NS_OK;
     }
 
-    // Convert our data surface to a GPU surface if possible. We'll also try to
-    // release mImageSurface.
+    // Convert our data surface to a GPU surface if possible and release
+    // whatever memory we can.
     Optimize();
-
-    // Allow the OS to release our data surface. Note that mImageSurface also
-    // keeps our volatile buffer alive, so this doesn't actually work unless we
-    // released mImageSurface in Optimize().
-    mVBufPtr = nullptr;
   }
 
   mLockCount--;
 
   return NS_OK;
 }
 
 void