Bug 1373177 - part1 : automatically refill the pool if the textures number is lower than specific threshold. r=bechen,jolin,snorp

The pool would be refilled when the compositor starts rendering the frame.
However, if we consume lots of textures but doesn't render any frame, then the
pool would always empty and no one can get new texture id.

One case is that when we release decoders too early before rendering the first
frame, the pool won't be refilled, and it causes all media threads are blocked.

Now we would refill the pool if the textures number is lower than the specific
threshold.

MozReview-Commit-ID: CYBLYi9hFD9

--HG--
extra : rebase_source : 309338a4cf2283ed93afcc4af2cc1cf5e925661d
This commit is contained in:
Alastor Wu 2017-06-30 11:12:49 -07:00
parent 1265f14b35
commit eaf35bf952
2 changed files with 28 additions and 1 deletions

View File

@ -7,14 +7,17 @@
#include "GLContext.h" // for GLContext
#include "mozilla/Monitor.h" // for Monitor, MonitorAutoLock
#include "mozilla/mozalloc.h" // for operator delete, etc
#include "mozilla/layers/CompositorThread.h"
#include "nsDebug.h" // for NS_ASSERTION, NS_ERROR, etc
#include "nsDeque.h" // for nsDeque
#include "nsThreadUtils.h"
#ifdef MOZ_WIDGET_ANDROID
#include "GeneratedJNINatives.h"
#endif
#define TEXTURE_POOL_SIZE 10
static const unsigned int TEXTURE_POOL_SIZE = 10;
static const unsigned int TEXTURE_REFILL_THRESHOLD = TEXTURE_POOL_SIZE / 2;
namespace mozilla {
namespace gl {
@ -24,6 +27,8 @@ static GLContext* sActiveContext = nullptr;
static Monitor* sMonitor = nullptr;
static nsDeque* sTextures = nullptr;
static bool sHasPendingFillTask = false;
#ifdef MOZ_WIDGET_ANDROID
class GeckoSurfaceTextureSupport final
@ -37,6 +42,22 @@ public:
#endif // MOZ_WIDGET_ANDROID
void TexturePoolOGL::MaybeFillTextures()
{
if (sTextures->GetSize() < TEXTURE_REFILL_THRESHOLD &&
!sHasPendingFillTask) {
sHasPendingFillTask = true;
MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop();
MOZ_ASSERT(loop);
loop->PostTask(
NS_NewRunnableFunction(
"TexturePoolOGL::MaybeFillTextures",
[] () {
TexturePoolOGL::Fill(sActiveContext);
}));
}
}
GLuint TexturePoolOGL::AcquireTexture()
{
NS_ASSERTION(sMonitor, "not initialized");
@ -72,6 +93,8 @@ GLuint TexturePoolOGL::AcquireTexture()
delete popped;
NS_ASSERTION(texture, "Failed to retrieve texture from pool");
MaybeFillTextures();
}
return texture;
@ -97,6 +120,7 @@ void TexturePoolOGL::Fill(GLContext* aContext)
NS_ASSERTION(sMonitor, "not initialized");
MonitorAutoLock lock(*sMonitor);
sHasPendingFillTask = false;
if (sActiveContext != aContext) {
Clear();

View File

@ -32,6 +32,9 @@ public:
// Clears all internal data structures in preparation for shutdown
static void Shutdown();
private:
// These methods are used to refill textures to avoid pool becomes dry
static void MaybeFillTextures();
};
} // namespace gl