blob: e444aa0605e739479c728ae35b63bbb3f658de30 [file] [log] [blame]
John Reckcec24ae2013-11-05 13:27:50 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef RENDERTHREAD_H_
18#define RENDERTHREAD_H_
19
20#include "RenderTask.h"
21#include <cutils/compiler.h>
22#include <utils/Looper.h>
23#include <utils/Mutex.h>
24#include <utils/Singleton.h>
25#include <utils/Thread.h>
26
27namespace android {
28namespace uirenderer {
29namespace renderthread {
30
John Reck4f02bf42014-01-03 18:09:17 -080031class TaskQueue {
32public:
33 TaskQueue();
34
35 RenderTask* next();
36 void queue(RenderTask* task);
37 RenderTask* peek();
38 void remove(RenderTask* task);
39
40private:
41 RenderTask* mHead;
42 RenderTask* mTail;
43};
44
John Reckcec24ae2013-11-05 13:27:50 -080045class ANDROID_API RenderThread : public Thread, public Singleton<RenderThread> {
46public:
47 // RenderThread takes complete ownership of tasks that are queued
48 // and will delete them after they are run
49 ANDROID_API void queue(RenderTask* task);
John Reck4f02bf42014-01-03 18:09:17 -080050 void queueDelayed(RenderTask* task, int delayMs);
51 void remove(RenderTask* task);
John Reckcec24ae2013-11-05 13:27:50 -080052
53protected:
54 virtual bool threadLoop();
55
56private:
57 friend class Singleton<RenderThread>;
58
59 RenderThread();
60 virtual ~RenderThread();
61
John Reck4f02bf42014-01-03 18:09:17 -080062 // Returns the next task to be run. If this returns NULL nextWakeup is set
63 // to the time to requery for the nextTask to run. mNextWakeup is also
64 // set to this time
65 RenderTask* nextTask(nsecs_t* nextWakeup);
John Reckcec24ae2013-11-05 13:27:50 -080066
67 sp<Looper> mLooper;
68 Mutex mLock;
69
John Reck4f02bf42014-01-03 18:09:17 -080070 nsecs_t mNextWakeup;
71 TaskQueue mQueue;
John Reckcec24ae2013-11-05 13:27:50 -080072};
73
74} /* namespace renderthread */
75} /* namespace uirenderer */
76} /* namespace android */
77#endif /* RENDERTHREAD_H_ */