blob: ad44821c1496775ee3123230239582cf0969865e [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 Ni062c2872015-02-20 15:20:00 -080013class IDBase;
Yang Nieb9aa672015-01-27 14:32:25 -080014class ObjectBase;
Yang Ni1ffd86b2015-01-07 09:16:40 -080015class ScriptFieldID;
Yang Nieb9aa672015-01-27 14:32:25 -080016class ScriptInvokeID;
Yang Ni1ffd86b2015-01-07 09:16:40 -080017class ScriptKernelID;
18class Type;
19
20class Closure : public ObjectBase {
21 public:
Yang Nieb9aa672015-01-27 14:32:25 -080022 Closure(Context* context,
23 const ScriptKernelID* kernelID,
24 Allocation* returnValue,
25 const int numValues,
26 const ScriptFieldID** fieldIDs,
27 const void** values, // Allocations or primitive (numeric) types
Yang Nibd0af2d2015-03-23 17:14:58 -070028 const int* sizes, // size for data type. -1 indicates an allocation.
Yang Nieb9aa672015-01-27 14:32:25 -080029 const Closure** depClosures,
30 const ScriptFieldID** depFieldIDs);
31 Closure(Context* context,
32 const ScriptInvokeID* invokeID,
33 const void* params,
34 const size_t paramLength,
35 const size_t numValues,
36 const ScriptFieldID** fieldIDs,
37 const void** values, // Allocations or primitive (numeric) types
Yang Nibd0af2d2015-03-23 17:14:58 -070038 const int* sizes); // size for data type. -1 indicates an allocation.
Yang Ni1ffd86b2015-01-07 09:16:40 -080039
Yang Nieb9aa672015-01-27 14:32:25 -080040 virtual ~Closure();
Yang Ni1ffd86b2015-01-07 09:16:40 -080041
Yang Nieb9aa672015-01-27 14:32:25 -080042 virtual void serialize(Context *rsc, OStream *stream) const {}
Yang Ni1ffd86b2015-01-07 09:16:40 -080043
Yang Nieb9aa672015-01-27 14:32:25 -080044 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_CLOSURE; }
Yang Ni1ffd86b2015-01-07 09:16:40 -080045
Yang Nieb9aa672015-01-27 14:32:25 -080046 void setArg(const uint32_t index, const void* value, const size_t size);
47 void setGlobal(const ScriptFieldID* fieldID, const void* value,
Yang Nibd0af2d2015-03-23 17:14:58 -070048 const int size);
Yang Ni1ffd86b2015-01-07 09:16:40 -080049
Yang Nieb9aa672015-01-27 14:32:25 -080050 Context* mContext;
Yang Ni1ffd86b2015-01-07 09:16:40 -080051
Yang Ni062c2872015-02-20 15:20:00 -080052 // KernelId or InvokeID
53 const ObjectBaseRef<IDBase> mFunctionID;
54 // Flag indicating if this closure is for a kernel (true) or invocable
55 // function (false)
56 const bool mIsKernel;
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.
Yang Nibd0af2d2015-03-23 17:14:58 -070065 Map<const ScriptFieldID*, Pair<const void*, int>> 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 which this closure depends on for one of its
70 // arguments, and the fields which it depends on.
Yang Nibd0af2d2015-03-23 17:14:58 -070071 Map<const Closure*, Map<int, ObjectBaseRef<ScriptFieldID>>*> mArgDeps;
Yang Nieb9aa672015-01-27 14:32:25 -080072
73 // All the other closures that this closure depends on for one of its fields,
74 // and the fields that it depends on.
Yang Nibd0af2d2015-03-23 17:14:58 -070075 Map<const Closure*, Map<const ScriptFieldID*,
76 ObjectBaseRef<ScriptFieldID>>*> mGlobalDeps;
Yang Nieb9aa672015-01-27 14:32:25 -080077
78 const void* mParams;
79 const size_t mParamLength;
Yang Ni1ffd86b2015-01-07 09:16:40 -080080};
81
82} // namespace renderscript
83} // namespace android
84
85#endif // ANDROID_RENDERSCRIPT_CLOSURE_H_