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
--- 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);