Bug 1329079 - Make the SurfaceReleaser runnable HIGH priority. r?smaug, r?jrmuizel draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 26 Jan 2017 13:17:40 +0100
changeset 466737 47019c794614e02ea6875187b28eb98fefb35da7
parent 466736 c43613039e822f8b91f8464a332dc50370f2be5d
child 543503 0123540bce4a386f0cbc9bcdec295e61e6600a6e
push id42982
push userbmo:pehrson@telenordigital.com
push dateThu, 26 Jan 2017 12:38:43 +0000
reviewerssmaug, jrmuizel
bugs1329079
milestone53.0a1
Bug 1329079 - Make the SurfaceReleaser runnable HIGH priority. r?smaug, r?jrmuizel This avoids ever-growing memory allocations caused by SourceSurfaces allocated in a high priority runnable (like vsync) and a busy main thread that cannot process the SurfaceReleasers fast enough. MozReview-Commit-ID: CkYOh7DTSSs
gfx/layers/ImageContainer.cpp
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -31,30 +31,43 @@
 #endif
 
 #ifdef XP_WIN
 #include "gfxWindowsPlatform.h"
 #include <d3d10_1.h>
 #endif
 
 /**
- * The XPCOM event that will do the actual release on the main thread.
+ * The XPCOM event that will do the actual release on the creation thread.
+ *
+ * This must be a high priority runnable or we risk producing (high prio)
+ * images faster than we can consume (normal prio) them. See Bug 1329079.
  */
-class SurfaceReleaser : public mozilla::Runnable {
+class SurfaceReleaser : public mozilla::Runnable,
+                        public nsIRunnablePriority {
 public:
   typedef mozilla::gfx::SourceSurface* RawRef;
 
   explicit SurfaceReleaser(RawRef aRef) : mRef(aRef) {}
+  NS_DECL_ISUPPORTS_INHERITED
   NS_IMETHOD Run() override {
     mRef->Release();
     return NS_OK;
   }
+  NS_IMETHOD GetPriority(uint32_t* aPriority) override {
+    *aPriority = nsIRunnablePriority::PRIORITY_HIGH;
+    return NS_OK;
+  }
   RawRef mRef;
+private:
+  ~SurfaceReleaser() = default;
 };
 
+NS_IMPL_ISUPPORTS_INHERITED(SurfaceReleaser, mozilla::Runnable, nsIRunnablePriority)
+
 void
 nsAutoRefTraits<nsMainThreadSourceSurfaceRef>::Release(RawRef aRawRef)
 {
   if (NS_IsMainThread()) {
     aRawRef->Release();
     return;
   }
   nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);