Bug 1456561 - Reduce the number of WakeSceneBuilder messages. r?botond
Avoid sending a flood of WakeSceneBuilder messages when we get a series
of updater-thread tasks to run in quick succession.
MozReview-Commit-ID: 34MV9gZYKRa
--- a/gfx/layers/apz/src/APZUpdater.cpp
+++ b/gfx/layers/apz/src/APZUpdater.cpp
@@ -351,30 +351,45 @@ APZUpdater::RunOnUpdaterThread(LayersId
}
if (UsingWebRenderUpdaterThread()) {
// If the updater thread is a WebRender thread, and we're not on it
// right now, save the task in the queue. We will run tasks from the queue
// during the callback from the updater thread, which we trigger by the
// call to WakeSceneBuilder.
+ bool sendWakeMessage = true;
{ // scope lock
MutexAutoLock lock(mQueueLock);
+ for (const auto& queuedTask : mUpdaterQueue) {
+ if (queuedTask.mLayersId == aLayersId) {
+ // If there's already a task in the queue with this layers id, then
+ // we must have previously sent a WakeSceneBuilder message (when
+ // adding the first task with this layers id to the queue). Either
+ // that hasn't been fully processed yet, or the layers id is blocked
+ // waiting for an epoch - in either case there's no point in sending
+ // another WakeSceneBuilder message.
+ sendWakeMessage = false;
+ break;
+ }
+ }
mUpdaterQueue.push_back(QueuedTask { aLayersId, task });
}
- RefPtr<wr::WebRenderAPI> api = mApz->GetWebRenderAPI();
- if (api) {
- api->WakeSceneBuilder();
- } else {
- // Not sure if this can happen, but it might be possible. If it does,
- // the task is in the queue, but if we didn't get a WebRenderAPI it
- // might never run, or it might run later if we manage to get a
- // WebRenderAPI later. For now let's just emit a warning, this can
- // probably be upgraded to an assert later.
- NS_WARNING("Possibly dropping task posted to updater thread");
+ if (sendWakeMessage) {
+ RefPtr<wr::WebRenderAPI> api = mApz->GetWebRenderAPI();
+ if (api) {
+ api->WakeSceneBuilder();
+ } else {
+ // Not sure if this can happen, but it might be possible. If it does,
+ // the task is in the queue, but if we didn't get a WebRenderAPI it
+ // might never run, or it might run later if we manage to get a
+ // WebRenderAPI later. For now let's just emit a warning, this can
+ // probably be upgraded to an assert later.
+ NS_WARNING("Possibly dropping task posted to updater thread");
+ }
}
return;
}
if (MessageLoop* loop = CompositorThreadHolder::Loop()) {
loop->PostTask(task.forget());
} else {
// Could happen during startup