Bug 1122722 - Clean up asserts for compositor threads. r=nical, a=abillings
authorMilan Sreckovic <milan@mozilla.com>
Fri, 30 Jan 2015 10:47:20 -0500
changeset 243604 1ec36b2a9775
parent 243603 26d78b7b0bfa
child 243605 03be92be95c2
push id4411
push userryanvm@gmail.com
push date2015-01-30 20:02 +0000
treeherdermozilla-beta@03be92be95c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, abillings
bugs1122722
milestone36.0
Bug 1122722 - Clean up asserts for compositor threads. r=nical, a=abillings
gfx/layers/Compositor.cpp
gfx/layers/ipc/CompositorParent.cpp
--- a/gfx/layers/Compositor.cpp
+++ b/gfx/layers/Compositor.cpp
@@ -16,40 +16,43 @@ class Matrix4x4;
 }
 
 namespace layers {
 
 /* static */ LayersBackend Compositor::sBackend = LayersBackend::LAYERS_NONE;
 /* static */ LayersBackend
 Compositor::GetBackend()
 {
-  AssertOnCompositorThread();
+  if (sBackend != LayersBackend::LAYERS_NONE) {
+    AssertOnCompositorThread();
+  }
   return sBackend;
 }
 
 /* static */ void
 Compositor::SetBackend(LayersBackend backend)
 {
-  if (sBackend != LayersBackend::LAYERS_NONE && sBackend != backend) {
+  if (sBackend != backend &&
+      sBackend != LayersBackend::LAYERS_NONE &&
+      backend != LayersBackend::LAYERS_NONE) {
     // Assert this once we figure out bug 972891.
-    //MOZ_CRASH("Trying to use more than one OMTC compositor.");
 
 #ifdef XP_MACOSX
-    printf("ERROR: Changing compositor from %u to %u.\n",
-           unsigned(sBackend), unsigned(backend));
+    gfxWarning() << "Changing compositor from " << unsigned(sBackend) << " to " << unsigned(backend);
 #endif
   }
+
   sBackend = backend;
 }
 
 /* static */ void
 Compositor::AssertOnCompositorThread()
 {
-  MOZ_ASSERT(CompositorParent::CompositorLoop() ==
-             MessageLoop::current(),
+  MOZ_ASSERT(!CompositorParent::CompositorLoop() ||
+             CompositorParent::CompositorLoop() == MessageLoop::current(),
              "Can only call this from the compositor thread!");
 }
 
 bool
 Compositor::ShouldDrawDiagnostics(DiagnosticFlags aFlags)
 {
   if ((aFlags & DiagnosticFlags::TILE) && !(mDiagnosticTypes & DiagnosticTypes::TILE_BORDERS)) {
     return false;
--- a/gfx/layers/ipc/CompositorParent.cpp
+++ b/gfx/layers/ipc/CompositorParent.cpp
@@ -251,16 +251,17 @@ CompositorVsyncObserver::NotifyVsync(Tim
   MOZ_ASSERT(!CompositorParent::IsInCompositorThread());
   MOZ_ASSERT(!NS_IsMainThread());
 
   MonitorAutoLock lock(mCurrentCompositeTaskMonitor);
   if (mCurrentCompositeTask == nullptr) {
     mCurrentCompositeTask = NewRunnableMethod(this,
                                               &CompositorVsyncObserver::Composite,
                                               aVsyncTimestamp);
+    MOZ_ASSERT(CompositorParent::CompositorLoop());
     CompositorParent::CompositorLoop()->PostTask(FROM_HERE, mCurrentCompositeTask);
   }
   return true;
 }
 
 void
 CompositorVsyncObserver::CancelCurrentCompositeTask()
 {
@@ -378,16 +379,17 @@ CompositorParent::CompositorParent(nsIWi
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(CompositorThread(),
              "The compositor thread must be Initialized before instanciating a CompositorParent.");
   MOZ_COUNT_CTOR(CompositorParent);
   mCompositorID = 0;
   // FIXME: This holds on the the fact that right now the only thing that
   // can destroy this instance is initialized on the compositor thread after
   // this task has been processed.
+  MOZ_ASSERT(CompositorLoop());
   CompositorLoop()->PostTask(FROM_HERE, NewRunnableFunction(&AddCompositor,
                                                           this, &mCompositorID));
 
   CompositorLoop()->PostTask(FROM_HERE, NewRunnableFunction(SetThreadPriority));
 
   mRootLayerTreeID = AllocateLayerTreeId();
 
   { // scope lock
@@ -604,16 +606,17 @@ CompositorParent::ActorDestroy(ActorDest
   }
 }
 
 
 void
 CompositorParent::ScheduleRenderOnCompositorThread()
 {
   CancelableTask *renderTask = NewRunnableMethod(this, &CompositorParent::ScheduleComposition);
+  MOZ_ASSERT(CompositorLoop());
   CompositorLoop()->PostTask(FROM_HERE, renderTask);
 }
 
 void
 CompositorParent::PauseComposition()
 {
   MOZ_ASSERT(IsInCompositorThread(),
              "PauseComposition() can only be called on the compositor thread");
@@ -700,29 +703,31 @@ CompositorParent::ResumeCompositionAndRe
  */
 void
 CompositorParent::SchedulePauseOnCompositorThread()
 {
   MonitorAutoLock lock(mPauseCompositionMonitor);
 
   CancelableTask *pauseTask = NewRunnableMethod(this,
                                                 &CompositorParent::PauseComposition);
+  MOZ_ASSERT(CompositorLoop());
   CompositorLoop()->PostTask(FROM_HERE, pauseTask);
 
   // Wait until the pause has actually been processed by the compositor thread
   lock.Wait();
 }
 
 bool
 CompositorParent::ScheduleResumeOnCompositorThread(int width, int height)
 {
   MonitorAutoLock lock(mResumeCompositionMonitor);
 
   CancelableTask *resumeTask =
     NewRunnableMethod(this, &CompositorParent::ResumeCompositionAndResize, width, height);
+  MOZ_ASSERT(CompositorLoop());
   CompositorLoop()->PostTask(FROM_HERE, resumeTask);
 
   // Wait until the resume has actually been processed by the compositor thread
   lock.Wait();
 
   return !mPaused;
 }
 
@@ -1281,16 +1286,17 @@ EraseLayerState(uint64_t aId)
 
 /*static*/ void
 CompositorParent::DeallocateLayerTreeId(uint64_t aId)
 {
   MOZ_ASSERT(NS_IsMainThread());
   // Here main thread notifies compositor to remove an element from
   // sIndirectLayerTrees. This removed element might be queried soon.
   // Checking the elements of sIndirectLayerTrees exist or not before using.
+  MOZ_ASSERT(CompositorLoop());
   CompositorLoop()->PostTask(FROM_HERE,
                              NewRunnableFunction(&EraseLayerState, aId));
 }
 
 static void
 UpdateControllerForLayersId(uint64_t aLayersId,
                             GeckoContentController* aController)
 {