Bug 1122722 - Clean up asserts for compositor threads. r=nical, a=abillings
authorMilan Sreckovic <milan@mozilla.com>
Fri, 30 Jan 2015 10:48:56 -0500
changeset 249492 af25a4300b47095d39970ab7eea1bacf7d9596e2
parent 249491 b2c29669f13a139c5eb99bfa91cf10bd27b7cf47
child 249493 e7c713e8e682454f8b96c03cc10ef8732f19724e
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, abillings
bugs1122722
milestone37.0a2
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
@@ -241,16 +241,17 @@ CompositorVsyncObserver::~CompositorVsyn
  * If a layer transaction comes after vsync, do we composite ASAP or wait until
  * next vsync?
  * How many skipped vsync events until we stop listening to vsync events?
  */
 void
 CompositorVsyncObserver::SetNeedsComposite(bool aNeedsComposite)
 {
   if (aNeedsComposite && !CompositorParent::IsInCompositorThread()) {
+    MOZ_ASSERT(CompositorParent::CompositorLoop());
     CompositorParent::CompositorLoop()->PostTask(FROM_HERE,
       NewRunnableMethod(this,
                         &CompositorVsyncObserver::SetNeedsComposite,
                         aNeedsComposite));
   }
 
   mNeedsComposite = aNeedsComposite;
   if (!mIsObservingVsync && mNeedsComposite) {
@@ -265,16 +266,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()
 {
@@ -385,16 +387,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
@@ -614,16 +617,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");
@@ -710,29 +714,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;
 }
 
@@ -1293,16 +1299,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)
 {