blob: b14c2aaeeaa9dd60f4d161efc4e6061ea296c680 [file] [log] [blame]
Yang Ni1ffd86b2015-01-07 09:16:40 -08001#ifndef ANDROID_RENDERSCRIPT_CLOSURE_H_
2#define ANDROID_RENDERSCRIPT_CLOSURE_H_
3
Yang Ni1ffd86b2015-01-07 09:16:40 -08004#include "rsDefines.h"
Yang Niff2bb542015-02-02 14:33:47 -08005#include "rsMap.h"
Yang Ni1ffd86b2015-01-07 09:16:40 -08006#include "rsObjectBase.h"
7
8namespace android {
9namespace renderscript {
10
Yang Ni1ffd86b2015-01-07 09:16:40 -080011class Allocation;
12class Context;
Yang Nieb9aa672015-01-27 14:32:25 -080013class ObjectBase;
Yang Ni1ffd86b2015-01-07 09:16:40 -080014class ScriptFieldID;
Yang Nieb9aa672015-01-27 14:32:25 -080015class ScriptInvokeID;
Yang Ni1ffd86b2015-01-07 09:16:40 -080016class ScriptKernelID;
17class Type;
18
19class Closure : public ObjectBase {
20 public:
Yang Nieb9aa672015-01-27 14:32:25 -080021 Closure(Context* context,
22 const ScriptKernelID* kernelID,
23 Allocation* returnValue,
24 const int numValues,
25 const ScriptFieldID** fieldIDs,
26 const void** values, // Allocations or primitive (numeric) types
27 const size_t* sizes, // size for data type. -1 indicates an allocation.
28 const Closure** depClosures,
29 const ScriptFieldID** depFieldIDs);
30 Closure(Context* context,
31 const ScriptInvokeID* invokeID,
32 const void* params,
33 const size_t paramLength,
34 const size_t numValues,
35 const ScriptFieldID** fieldIDs,
36 const void** values, // Allocations or primitive (numeric) types
37 const size_t* sizes); // size for data type. -1 indicates an allocation.
Yang Ni1ffd86b2015-01-07 09:16:40 -080038
Yang Nieb9aa672015-01-27 14:32:25 -080039 virtual ~Closure();
Yang Ni1ffd86b2015-01-07 09:16:40 -080040
Yang Nieb9aa672015-01-27 14:32:25 -080041 virtual void serialize(Context *rsc, OStream *stream) const {}
Yang Ni1ffd86b2015-01-07 09:16:40 -080042
Yang Nieb9aa672015-01-27 14:32:25 -080043 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_CLOSURE; }
Yang Ni1ffd86b2015-01-07 09:16:40 -080044
Yang Nieb9aa672015-01-27 14:32:25 -080045 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);
Yang Ni1ffd86b2015-01-07 09:16:40 -080048
Yang Nieb9aa672015-01-27 14:32:25 -080049 Context* mContext;
Yang Ni1ffd86b2015-01-07 09:16:40 -080050
Yang Nieb9aa672015-01-27 14:32:25 -080051 // If mKernelID is not null, this is a closure for a kernel. Otherwise, it is
52 // a closure for an invoke function, whose id is the next field. At least one
53 // of these fields has to be non-null.
54 const ObjectBaseRef<ScriptKernelID> mKernelID;
55 // TODO(yangni): ObjectBaseRef<ScriptInvokeID>
56 const ScriptInvokeID* mInvokeID;
Yang Ni1ffd86b2015-01-07 09:16:40 -080057
Yang Nieb9aa672015-01-27 14:32:25 -080058 // Values referrenced in arguments and globals cannot be futures. They must be
59 // either a known value or unbound value.
60 // For now, all arguments should be Allocations.
Yang Niff2bb542015-02-02 14:33:47 -080061 const void** mArgs;
62 size_t mNumArg;
Yang Ni1ffd86b2015-01-07 09:16:40 -080063
Yang Niff2bb542015-02-02 14:33:47 -080064 // A global could be allocation or any primitive data type.
65 Map<const ScriptFieldID*, Pair<const void*, size_t>> mGlobals;
Yang Ni1ffd86b2015-01-07 09:16:40 -080066
Yang Nieb9aa672015-01-27 14:32:25 -080067 Allocation* mReturnValue;
Yang Ni1ffd86b2015-01-07 09:16:40 -080068
Yang Nieb9aa672015-01-27 14:32:25 -080069 // All the other closures that this closure depends on
Yang Niff2bb542015-02-02 14:33:47 -080070 // set<const Closure*> mDependences;
Yang Ni1ffd86b2015-01-07 09:16:40 -080071
Yang Nieb9aa672015-01-27 14:32:25 -080072 // All the other closures which this closure depends on for one of its
73 // arguments, and the fields which it depends on.
Yang Niff2bb542015-02-02 14:33:47 -080074 Map<const Closure*, Map<int, const ObjectBaseRef<ScriptFieldID>*>*> mArgDeps;
Yang Nieb9aa672015-01-27 14:32:25 -080075
76 // All the other closures that this closure depends on for one of its fields,
77 // and the fields that it depends on.
Yang Niff2bb542015-02-02 14:33:47 -080078 Map<const Closure*, Map<const ObjectBaseRef<ScriptFieldID>*,
Yang Nieb9aa672015-01-27 14:32:25 -080079 const ObjectBaseRef<ScriptFieldID>*>*> mGlobalDeps;
80
81 const void* mParams;
82 const size_t mParamLength;
Yang Ni1ffd86b2015-01-07 09:16:40 -080083};
84
85} // namespace renderscript
86} // namespace android
87
88#endif // ANDROID_RENDERSCRIPT_CLOSURE_H_