From a5b7b8916622d44661b6e7936c9b738655a06f3b Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 15 Nov 2016 10:22:01 -0800 Subject: [PATCH] Avoid starving RT anims Test: Manual, usleep(16000) in DrawFrameTask and tap on recents Merged-In: I88bb30a2503bc908ec45650c7d36b6fb3cc750d0 Change-Id: I88bb30a2503bc908ec45650c7d36b6fb3cc750d0 --- libs/hwui/renderthread/RenderThread.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 3c1c0bceba582..0d9ede063c79a 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -20,6 +20,7 @@ #include "CanvasContext.h" #include "EglManager.h" #include "RenderProxy.h" +#include "utils/FatVector.h" #include #include @@ -282,10 +283,18 @@ bool RenderThread::threadLoop() { "RenderThread Looper POLL_ERROR!"); nsecs_t nextWakeup; - // Process our queue, if we have anything - while (RenderTask* task = nextTask(&nextWakeup)) { - task->run(); - // task may have deleted itself, do not reference it again + { + FatVector workQueue; + // Process our queue, if we have anything. By first acquiring + // all the pending events then processing them we avoid vsync + // starvation if more tasks are queued while we are processing tasks. + while (RenderTask* task = nextTask(&nextWakeup)) { + workQueue.push_back(task); + } + for (auto task : workQueue) { + task->run(); + // task may have deleted itself, do not reference it again + } } if (nextWakeup == LLONG_MAX) { timeoutMillis = -1;