Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [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 ANDROID_HWUI_TASK_H |
| 18 | #define ANDROID_HWUI_TASK_H |
| 19 | |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 20 | #include <utils/RefBase.h> |
| 21 | #include <utils/Trace.h> |
| 22 | |
| 23 | #include "Future.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 28 | class TaskBase : public RefBase { |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 29 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 30 | TaskBase() {} |
| 31 | virtual ~TaskBase() {} |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 34 | template <typename T> |
| 35 | class Task : public TaskBase { |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 36 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 37 | Task() : mFuture(new Future<T>()) {} |
| 38 | virtual ~Task() {} |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 39 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 40 | T getResult() const { return mFuture->get(); } |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 41 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 42 | void setResult(T result) { mFuture->produce(result); } |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 43 | |
| 44 | protected: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 45 | const sp<Future<T> >& future() const { return mFuture; } |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | sp<Future<T> > mFuture; |
| 49 | }; |
| 50 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 51 | }; // namespace uirenderer |
| 52 | }; // namespace android |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 53 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 54 | #endif // ANDROID_HWUI_TASK_H |