Bug 1373177 - part4 : add assertion to make sure the function call order. draft
authorAlastor Wu <alwu@mozilla.com>
Fri, 30 Jun 2017 11:14:00 -0700
changeset 602756 45548ac1b5e554134a25d55865796ab5fbdbb741
parent 602754 5a8470e06dfd8b21fc0ac31425f5293042dcb4a6
child 635698 d0eb33bffd522b0060b30c66bfac584266d963a5
push id66536
push useralwu@mozilla.com
push dateFri, 30 Jun 2017 18:14:08 +0000
bugs1373177
milestone56.0a1
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
gfx/layers/opengl/TexturePoolOGL.cpp
--- 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