John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | namespace renderthread { |
| 30 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 31 | class TaskQueue { |
| 32 | public: |
| 33 | TaskQueue(); |
| 34 | |
| 35 | RenderTask* next(); |
| 36 | void queue(RenderTask* task); |
| 37 | RenderTask* peek(); |
| 38 | void remove(RenderTask* task); |
| 39 | |
| 40 | private: |
| 41 | RenderTask* mHead; |
| 42 | RenderTask* mTail; |
| 43 | }; |
| 44 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 45 | class ANDROID_API RenderThread : public Thread, public Singleton<RenderThread> { |
| 46 | public: |
| 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 Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 50 | void queueDelayed(RenderTask* task, int delayMs); |
| 51 | void remove(RenderTask* task); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 52 | |
| 53 | protected: |
| 54 | virtual bool threadLoop(); |
| 55 | |
| 56 | private: |
| 57 | friend class Singleton<RenderThread>; |
| 58 | |
| 59 | RenderThread(); |
| 60 | virtual ~RenderThread(); |
| 61 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 62 | // 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 Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 66 | |
| 67 | sp<Looper> mLooper; |
| 68 | Mutex mLock; |
| 69 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 70 | nsecs_t mNextWakeup; |
| 71 | TaskQueue mQueue; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } /* namespace renderthread */ |
| 75 | } /* namespace uirenderer */ |
| 76 | } /* namespace android */ |
| 77 | #endif /* RENDERTHREAD_H_ */ |