From b1f63863e873a76b13aa415d57b8bf5073ef8b6d Mon Sep 17 00:00:00 2001 From: Sotaro Ikeda Date: Tue, 19 Jul 2016 05:38:35 -0700 Subject: [PATCH] Bug 1287627 - Handle flush TextureHost without composition r=nical --- gfx/layers/Compositor.cpp | 13 +++++++++++++ gfx/layers/Compositor.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/gfx/layers/Compositor.cpp b/gfx/layers/Compositor.cpp index d8690863c102..9c61be7ff116 100644 --- a/gfx/layers/Compositor.cpp +++ b/gfx/layers/Compositor.cpp @@ -55,6 +55,7 @@ void Compositor::EndFrame() { ReadUnlockTextures(); + mLastCompositionEndTime = TimeStamp::Now(); } void @@ -78,6 +79,18 @@ Compositor::NotifyNotUsedAfterComposition(TextureHost* aTextureHost) MOZ_ASSERT(!mIsDestroyed); mNotifyNotUsedAfterComposition.AppendElement(aTextureHost); + + // If Compositor holds many TextureHosts without compositing, + // the TextureHosts should be flushed to reduce memory consumption. + const int thresholdCount = 5; + const double thresholdSec = 2.0f; + if (mNotifyNotUsedAfterComposition.Length() > thresholdCount) { + TimeDuration duration = TimeStamp::Now() - mLastCompositionEndTime; + // Check if we could flush + if (duration.ToSeconds() > thresholdSec) { + FlushPendingNotifyNotUsed(); + } + } } void diff --git a/gfx/layers/Compositor.h b/gfx/layers/Compositor.h index 5bc3cfd08dad..c6e301f3f625 100644 --- a/gfx/layers/Compositor.h +++ b/gfx/layers/Compositor.h @@ -593,6 +593,11 @@ protected: */ nsTArray> mNotifyNotUsedAfterComposition; + /** + * Last Composition end time. + */ + TimeStamp mLastCompositionEndTime; + /** * Render time for the current composition. */