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 | |
| 31 | class ANDROID_API RenderThread : public Thread, public Singleton<RenderThread> { |
| 32 | public: |
| 33 | // RenderThread takes complete ownership of tasks that are queued |
| 34 | // and will delete them after they are run |
| 35 | ANDROID_API void queue(RenderTask* task); |
| 36 | |
| 37 | protected: |
| 38 | virtual bool threadLoop(); |
| 39 | |
| 40 | private: |
| 41 | friend class Singleton<RenderThread>; |
| 42 | |
| 43 | RenderThread(); |
| 44 | virtual ~RenderThread(); |
| 45 | |
| 46 | RenderTask* nextTask(); |
| 47 | |
| 48 | sp<Looper> mLooper; |
| 49 | Mutex mLock; |
| 50 | |
| 51 | RenderTask* mQueueHead; |
| 52 | RenderTask* mQueueTail; |
| 53 | }; |
| 54 | |
| 55 | } /* namespace renderthread */ |
| 56 | } /* namespace uirenderer */ |
| 57 | } /* namespace android */ |
| 58 | #endif /* RENDERTHREAD_H_ */ |