diff options
Diffstat (limited to 'libs/hwui/renderthread/RenderTask.h')
-rw-r--r-- | libs/hwui/renderthread/RenderTask.h | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/libs/hwui/renderthread/RenderTask.h b/libs/hwui/renderthread/RenderTask.h index 865b1e6fced1..9fe7573f71b7 100644 --- a/libs/hwui/renderthread/RenderTask.h +++ b/libs/hwui/renderthread/RenderTask.h @@ -18,19 +18,79 @@ #define RENDERTASK_H_ #include <cutils/compiler.h> +#include <utils/Timers.h> namespace android { +class Mutex; +class Condition; namespace uirenderer { namespace renderthread { +#define METHOD_INVOKE_PAYLOAD_SIZE (8 * sizeof(void*)) + +/* + * Notes about memory management + * + * RenderThread will only invoke RenderTask::run(). It is the responsibility + * of the RenderTask to know if it needs to suicide at the end of run() or + * if some other lifecycle is being used. As such, it is not valid to reference + * anything on RenderTask after the first call to run(). + * + * For example SignalingRenderTask + * is expected to be stack allocated by the calling thread, so it does not + * suicide in run() but instead relies on the caller to destroy it. + * + * MethodInvokeRenderTask however is currently allocated with new, so it will + * suicide at the end of run(). TODO: Replace this with a small pool to avoid + * malloc/free churn of small objects? + */ + class ANDROID_API RenderTask { public: - ANDROID_API RenderTask(); - ANDROID_API virtual ~RenderTask(); + ANDROID_API RenderTask() : mNext(0), mRunAt(0) {} + ANDROID_API virtual ~RenderTask() {} ANDROID_API virtual void run() = 0; RenderTask* mNext; + nsecs_t mRunAt; +}; + +class SignalingRenderTask : public RenderTask { +public: + // Takes ownership of task, caller owns lock and signal + SignalingRenderTask(RenderTask* task, Mutex* lock, Condition* signal) + : mTask(task), mLock(lock), mSignal(signal) {} + virtual void run(); + +private: + RenderTask* mTask; + Mutex* mLock; + Condition* mSignal; +}; + +typedef void* (*RunnableMethod)(void* data); + +class MethodInvokeRenderTask : public RenderTask { +public: + MethodInvokeRenderTask(RunnableMethod method) + : mMethod(method), mReturnPtr(0) {} + + void* payload() { return mData; } + void setReturnPtr(void** retptr) { mReturnPtr = retptr; } + + virtual void run() { + void* retval = mMethod(mData); + if (mReturnPtr) { + *mReturnPtr = retval; + } + // Commit suicide + delete this; + } +private: + RunnableMethod mMethod; + char mData[METHOD_INVOKE_PAYLOAD_SIZE]; + void** mReturnPtr; }; } /* namespace renderthread */ |