RenderThread animator support
Change-Id: Icf29098edfdaf7ed550bbe9d49e9eaefb4167084
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index e444aa0..b93dfd6 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -18,6 +18,10 @@
#define RENDERTHREAD_H_
#include "RenderTask.h"
+
+#include <memory>
+#include <set>
+
#include <cutils/compiler.h>
#include <utils/Looper.h>
#include <utils/Mutex.h>
@@ -25,9 +29,13 @@
#include <utils/Thread.h>
namespace android {
+class DisplayEventReceiver;
+
namespace uirenderer {
namespace renderthread {
+class DispatchFrameCallbacks;
+
class TaskQueue {
public:
TaskQueue();
@@ -42,6 +50,15 @@
RenderTask* mTail;
};
+// Mimics android.view.Choreographer.FrameCallback
+class IFrameCallback {
+public:
+ virtual void doFrame(nsecs_t frameTimeNanos) = 0;
+
+protected:
+ ~IFrameCallback() {}
+};
+
class ANDROID_API RenderThread : public Thread, public Singleton<RenderThread> {
public:
// RenderThread takes complete ownership of tasks that are queued
@@ -50,15 +67,25 @@
void queueDelayed(RenderTask* task, int delayMs);
void remove(RenderTask* task);
+ // Mimics android.view.Choreographer
+ void postFrameCallback(IFrameCallback* callback);
+ void removeFrameCallback(IFrameCallback* callback);
+
protected:
virtual bool threadLoop();
private:
friend class Singleton<RenderThread>;
+ friend class DispatchFrameCallbacks;
RenderThread();
virtual ~RenderThread();
+ void initializeDisplayEventReceiver();
+ static int displayEventReceiverCallback(int fd, int events, void* data);
+ void drainDisplayEventQueue();
+ void dispatchFrameCallbacks();
+
// Returns the next task to be run. If this returns NULL nextWakeup is set
// to the time to requery for the nextTask to run. mNextWakeup is also
// set to this time
@@ -69,6 +96,13 @@
nsecs_t mNextWakeup;
TaskQueue mQueue;
+
+ DisplayEventReceiver* mDisplayEventReceiver;
+ bool mVsyncRequested;
+ std::set<IFrameCallback*> mFrameCallbacks;
+ bool mFrameCallbackTaskPending;
+ DispatchFrameCallbacks* mFrameCallbackTask;
+ nsecs_t mFrameTime;
};
} /* namespace renderthread */