Bug 1451469 - Run deferred tasks on the controller thread. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 16 Apr 2018 17:39:26 -0400
changeset 783273 ab7d1be48ad6e283b292b0c58ae8a102f51b4e76
parent 783272 cdc71fad9b309d491746fc5336958c0a58fb43da
child 783274 8f190a76cf6b9a79e26b8f5ddce681ba772b6ee7
push id106651
push userkgupta@mozilla.com
push dateMon, 16 Apr 2018 21:40:40 +0000
reviewersbotond
bugs1451469
milestone61.0a1
Bug 1451469 - Run deferred tasks on the controller thread. r?botond Deferred tasks currently run as part of the sampling process, in AdvanceAnimations. However, deferred tasks also sometimes need to acquire the APZ tree lock for stuff. Acquiring the tree lock is not going to be allowed on the render backend thread (which is the sampler thread when WR is enabled), so we need to bump these tasks to another thread. The controller thread is safe for this purpose. MozReview-Commit-ID: AP3bnGF5UjL
gfx/layers/apz/src/AsyncPanZoomController.cpp
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -3662,24 +3662,21 @@ bool AsyncPanZoomController::AdvanceAnim
     }
   }
 
   // Execute any deferred tasks queued up by mAnimation's Sample() (called by
   // UpdateAnimation()). This needs to be done after the monitor is released
   // since the tasks are allowed to call APZCTreeManager methods which can grab
   // the tree lock.
   for (uint32_t i = 0; i < deferredTasks.Length(); ++i) {
-    deferredTasks[i]->Run();
-    deferredTasks[i] = nullptr;
+    APZThreadUtils::RunOnControllerThread(deferredTasks[i].forget());
   }
 
-  // One of the deferred tasks may have started a new animation. In this case,
-  // we want to ask the compositor to schedule a new composite.
-  requestAnimationFrame |= (mAnimation != nullptr);
-
+  // If any of the deferred tasks starts a new animation, it will request a
+  // new composite directly, so we can just return requestAnimationFrame here.
   return requestAnimationFrame;
 }
 
 ParentLayerPoint
 AsyncPanZoomController::GetCurrentAsyncScrollOffset(AsyncTransformConsumer aMode) const
 {
   RecursiveMutexAutoLock lock(mRecursiveMutex);