Bug 1373177 - part4 : add assertion to make sure the function call order.
The Init()/Shutdown() would be run on the main thread, AcquireTexture() would be
on media thread and Fill() would be on compostitor thread.
Add assertion to make sure the call order, since we don't want to call Fill()
or AcquireTexture() after shutdown.
MozReview-Commit-ID: 3Gydr7b4Raq
--- a/gfx/layers/opengl/TexturePoolOGL.cpp
+++ b/gfx/layers/opengl/TexturePoolOGL.cpp
@@ -26,16 +26,23 @@ static mozilla::LazyLogModule gTexturePo
namespace mozilla {
namespace gl {
static GLContext* sActiveContext = nullptr;
static Monitor* sMonitor = nullptr;
static nsDeque* sTextures = nullptr;
+enum class PoolState : uint8_t {
+ NOT_INITIALIZE,
+ INITIALIZED,
+ SHUTDOWN
+};
+static PoolState sPoolState = PoolState::NOT_INITIALIZE;
+
static bool sHasPendingFillTask = false;
#ifdef MOZ_WIDGET_ANDROID
class GeckoSurfaceTextureSupport final
: public java::GeckoSurfaceTexture::Natives<GeckoSurfaceTextureSupport>
{
public:
@@ -60,17 +67,18 @@ void TexturePoolOGL::MaybeFillTextures()
[] () {
TexturePoolOGL::Fill(sActiveContext);
}));
}
}
GLuint TexturePoolOGL::AcquireTexture()
{
- NS_ASSERTION(sMonitor, "not initialized");
+ MOZ_ASSERT(sPoolState != PoolState::NOT_INITIALIZE, "not initialized");
+ MOZ_ASSERT(sPoolState != PoolState::SHUTDOWN, "should not be called after shutdown");
MonitorAutoLock lock(*sMonitor);
if (!sActiveContext) {
// Wait for a context
sMonitor->Wait();
if (!sActiveContext)
@@ -117,18 +125,19 @@ static void Clear()
sActiveContext->fDeleteTextures(1, item);
}
delete item;
}
}
void TexturePoolOGL::Fill(GLContext* aContext)
{
- NS_ASSERTION(aContext, "NULL GLContext");
- NS_ASSERTION(sMonitor, "not initialized");
+ MOZ_ASSERT(aContext, "NULL GLContext");
+ MOZ_ASSERT(sPoolState != PoolState::NOT_INITIALIZE, "not initialized");
+ MOZ_ASSERT(sPoolState != PoolState::SHUTDOWN, "should not be called after shutdown");
MonitorAutoLock lock(*sMonitor);
sHasPendingFillTask = false;
if (sActiveContext != aContext) {
Clear();
sActiveContext = aContext;
}
@@ -152,26 +161,30 @@ void TexturePoolOGL::Fill(GLContext* aCo
GLContext* TexturePoolOGL::GetGLContext()
{
return sActiveContext;
}
void TexturePoolOGL::Init()
{
+ MOZ_ASSERT(sPoolState != PoolState::INITIALIZED);
sMonitor = new Monitor("TexturePoolOGL.sMonitor");
sTextures = new nsDeque();
#ifdef MOZ_WIDGET_ANDROID
if (jni::IsAvailable()) {
GeckoSurfaceTextureSupport::Init();
}
#endif
+ sPoolState = PoolState::INITIALIZED;
}
void TexturePoolOGL::Shutdown()
{
+ MOZ_ASSERT(sPoolState == PoolState::INITIALIZED);
+ sPoolState = PoolState::SHUTDOWN;
delete sMonitor;
delete sTextures;
}
} // namespace gl
} // namespace mozilla