blob: 9a211a238bbc63e28dc5d649f815bdb259dcc8e8 [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
20#define ATRACE_TAG ATRACE_TAG_VIEW
21
22#include <utils/RefBase.h>
23#include <utils/Trace.h>
24
25#include "Future.h"
26
27namespace android {
28namespace uirenderer {
29
30class TaskBase: public RefBase {
31public:
32 TaskBase() { }
33 virtual ~TaskBase() { }
34};
35
36template<typename T>
37class Task: public TaskBase {
38public:
39 Task(): mFuture(new Future<T>()) { }
40 virtual ~Task() { }
41
42 T getResult() const {
43 ATRACE_NAME("waitForTask");
44 return mFuture->get();
45 }
46
47 void setResult(T result) {
48 mFuture->produce(result);
49 }
50
51protected:
52 const sp<Future<T> >& future() const {
53 return mFuture;
54 }
55
56private:
57 sp<Future<T> > mFuture;
58};
59
60}; // namespace uirenderer
61}; // namespace android
62
63#endif // ANDROID_HWUI_TASK_H