rsClosure.h revision 1ffd86b448d78366190c540f98f8b6d641cdb6cf
1#ifndef ANDROID_RENDERSCRIPT_CLOSURE_H_
2#define ANDROID_RENDERSCRIPT_CLOSURE_H_
3
4#include <map>
5#include <set>
6#include <vector>
7
8#include "rsDefines.h"
9#include "rsObjectBase.h"
10
11namespace android {
12namespace renderscript {
13
14using std::map;
15using std::pair;
16using std::set;
17using std::vector;
18
19class Allocation;
20class Context;
21class ScriptFieldID;
22class ScriptKernelID;
23class Type;
24
25class Closure : public ObjectBase {
26 public:
27  Closure(Context* context,
28          const ScriptKernelID* kernelID,
29          Allocation* returnValue,
30          const int numValues,
31          const ScriptFieldID** fieldIDs,
32          const void** values,  // Allocations or primitive (numeric) types
33          const size_t* sizes,   // size for data type. -1 indicates an allocation.
34          const Closure** depClosures,
35          const ScriptFieldID** depFieldIDs);
36
37  virtual ~Closure();
38
39  virtual void serialize(Context *rsc, OStream *stream) const {}
40
41  virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_CLOSURE; }
42
43  void eval();
44
45  void setArg(const uint32_t index, const void* value, const size_t size);
46  void setGlobal(const ScriptFieldID* fieldID, const void* value,
47                 const size_t size);
48
49  Context* mContext;
50  const ObjectBaseRef<ScriptKernelID> mKernelID;
51
52  // Values referrenced in arguments and globals cannot be futures. They must be
53  // either a known value or unbound value.
54  // For now, all arguments should be Allocations.
55  vector<const void*> mArgs;
56
57  // A global could be allocation or any primitive data type.
58  map<const ScriptFieldID*, pair<const void*, int>> mGlobals;
59
60  Allocation* mReturnValue;
61
62  // All the other closures that this closure depends on
63  set<const Closure*> mDependences;
64
65  // All the other closures which this closure depends on for one of its
66  // arguments, and the fields which it depends on.
67  map<const Closure*, map<int, const ObjectBaseRef<ScriptFieldID>*>*> mArgDeps;
68
69  // All the other closures that this closure depends on for one of its fields,
70  // and the fields that it depends on.
71  map<const Closure*, map<const ObjectBaseRef<ScriptFieldID>*,
72                          const ObjectBaseRef<ScriptFieldID>*>*> mGlobalDeps;
73};
74
75}  // namespace renderscript
76}  // namespace android
77
78#endif  // ANDROID_RENDERSCRIPT_CLOSURE_H_
79