OSDN Git Service

Avoid starving RT anims
authorJohn Reck <jreck@google.com>
Tue, 15 Nov 2016 18:22:01 +0000 (10:22 -0800)
committerZhao Wei Liew <zhaoweiliew@gmail.com>
Tue, 24 Jan 2017 09:48:42 +0000 (09:48 +0000)
Test: Manual, usleep(16000) in DrawFrameTask and tap
on recents

Merged-In: I88bb30a2503bc908ec45650c7d36b6fb3cc750d0

Change-Id: I88bb30a2503bc908ec45650c7d36b6fb3cc750d0
(cherry picked from commit 02eeda148184a2c8e5e94239fd5f7a14ea0e20be)

libs/hwui/renderthread/RenderThread.cpp

index f4b4416..9dfd754 100644 (file)
@@ -20,6 +20,7 @@
 #include "CanvasContext.h"
 #include "EglManager.h"
 #include "RenderProxy.h"
+#include "utils/FatVector.h"
 
 #include <gui/DisplayEventReceiver.h>
 #include <gui/ISurfaceComposer.h>
@@ -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<RenderTask*, 10> 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;