Bug 1122722 - Clean up asserts for compositor threads. r=nical
authorMilan Sreckovic <milan@mozilla.com>
Tue, 27 Jan 2015 15:52:44 -0500
changeset 226575 cf5abbbc9f4956a3ba5fd1d171050c7fb66bb71c
parent 226574 7f03823a577ee8ceb412644903df352ae68f9124
child 226576 13be1a0293003267deb85c5ad84d70a82a9a8e3d
push id28200
push userkwierso@gmail.com
push dateThu, 29 Jan 2015 23:01:46 +0000
treeherdermozilla-central@4380ed39de3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1122722
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1122722 - Clean up asserts for compositor threads. r=nical
gfx/layers/Compositor.cpp
gfx/layers/ipc/CompositorParent.cpp
--- a/gfx/layers/Compositor.cpp
+++ b/gfx/layers/Compositor.cpp
@@ -17,40 +17,42 @@ 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 (!gIsGtest && sBackend != LayersBackend::LAYERS_NONE && sBackend != backend) {
+  if (!gIsGtest && 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
@@ -265,16 +265,17 @@ CompositorVsyncObserver::CancelCurrentSe
 void
 CompositorVsyncObserver::SetNeedsComposite(bool aNeedsComposite)
 {
   if (!CompositorParent::IsInCompositorThread()) {
     MonitorAutoLock lock(mSetNeedsCompositeMonitor);
     mSetNeedsCompositeTask = NewRunnableMethod(this,
                                               &CompositorVsyncObserver::SetNeedsComposite,
                                               aNeedsComposite);
+    MOZ_ASSERT(CompositorParent::CompositorLoop());
     CompositorParent::CompositorLoop()->PostTask(FROM_HERE, mSetNeedsCompositeTask);
     return;
   } else {
     MonitorAutoLock lock(mSetNeedsCompositeMonitor);
     mSetNeedsCompositeTask = nullptr;
   }
 
   mNeedsComposite = aNeedsComposite;
@@ -290,16 +291,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()
 {
@@ -410,16 +412,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
@@ -641,16 +644,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");
@@ -737,29 +741,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;
 }
 
@@ -1324,16 +1330,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)
 {