blob: 276a22f941fe71bab4549ee5254349c3e3be40c2 [file] [log] [blame]
Romain Guy5dc7fa72013-03-11 20:48:31 -07001/*
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 Guy5dc7fa72013-03-11 20:48:31 -070020#include <utils/RefBase.h>
21#include <utils/Trace.h>
22
23#include "Future.h"
24
25namespace android {
26namespace uirenderer {
27
John Reck1bcacfd2017-11-03 10:12:19 -070028class TaskBase : public RefBase {
Romain Guy5dc7fa72013-03-11 20:48:31 -070029public:
John Reck1bcacfd2017-11-03 10:12:19 -070030 TaskBase() {}
31 virtual ~TaskBase() {}
Romain Guy5dc7fa72013-03-11 20:48:31 -070032};
33
John Reck1bcacfd2017-11-03 10:12:19 -070034template <typename T>
35class Task : public TaskBase {
Romain Guy5dc7fa72013-03-11 20:48:31 -070036public:
John Reck1bcacfd2017-11-03 10:12:19 -070037 Task() : mFuture(new Future<T>()) {}
38 virtual ~Task() {}
Romain Guy5dc7fa72013-03-11 20:48:31 -070039
John Reck1bcacfd2017-11-03 10:12:19 -070040 T getResult() const { return mFuture->get(); }
Romain Guy5dc7fa72013-03-11 20:48:31 -070041
John Reck1bcacfd2017-11-03 10:12:19 -070042 void setResult(T result) { mFuture->produce(result); }
Romain Guy5dc7fa72013-03-11 20:48:31 -070043
44protected:
John Reck1bcacfd2017-11-03 10:12:19 -070045 const sp<Future<T> >& future() const { return mFuture; }
Romain Guy5dc7fa72013-03-11 20:48:31 -070046
47private:
48 sp<Future<T> > mFuture;
49};
50
John Reck1bcacfd2017-11-03 10:12:19 -070051}; // namespace uirenderer
52}; // namespace android
Romain Guy5dc7fa72013-03-11 20:48:31 -070053
John Reck1bcacfd2017-11-03 10:12:19 -070054#endif // ANDROID_HWUI_TASK_H