blob: 6d4e2750b8ea28b60ceb250d430f7cc8389b197c [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,
Yang Nifef0cd42015-11-11 15:08:16 -080027 const int64_t* 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,
Yang Nifef0cd42015-11-11 15:08:16 -080037 const int64_t* 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 Nifef0cd42015-11-11 15:08:16 -080046 // Set the value of an argument or a global.
47 // The special value -1 for the size indicates the value is an Allocation.
48 void setArg(const uint32_t index, const void* value, const int size);
49 void setGlobal(const ScriptFieldID* fieldID, const int64_t value,
Yang Nibd0af2d2015-03-23 17:14:58 -070050 const int size);
Yang Ni1ffd86b2015-01-07 09:16:40 -080051
Yang Nieb9aa672015-01-27 14:32:25 -080052 Context* mContext;
Yang Ni1ffd86b2015-01-07 09:16:40 -080053
Yang Ni062c2872015-02-20 15:20:00 -080054 // KernelId or InvokeID
55 const ObjectBaseRef<IDBase> mFunctionID;
56 // Flag indicating if this closure is for a kernel (true) or invocable
57 // function (false)
58 const bool mIsKernel;
Yang Ni1ffd86b2015-01-07 09:16:40 -080059
Yang Nieb9aa672015-01-27 14:32:25 -080060 // Values referrenced in arguments and globals cannot be futures. They must be
61 // either a known value or unbound value.
62 // For now, all arguments should be Allocations.
Yang Niff2bb542015-02-02 14:33:47 -080063 const void** mArgs;
64 size_t mNumArg;
Yang Ni1ffd86b2015-01-07 09:16:40 -080065
Yang Niff2bb542015-02-02 14:33:47 -080066 // A global could be allocation or any primitive data type.
Yang Nifef0cd42015-11-11 15:08:16 -080067 Map<const ScriptFieldID*, Pair<int64_t, int>> mGlobals;
Yang Ni1ffd86b2015-01-07 09:16:40 -080068
Yang Nieb9aa672015-01-27 14:32:25 -080069 Allocation* mReturnValue;
Yang Ni1ffd86b2015-01-07 09:16:40 -080070
Yang Nieb9aa672015-01-27 14:32:25 -080071 // All the other closures which this closure depends on for one of its
72 // arguments, and the fields which it depends on.
Yang Nibd0af2d2015-03-23 17:14:58 -070073 Map<const Closure*, Map<int, ObjectBaseRef<ScriptFieldID>>*> mArgDeps;
Yang Nieb9aa672015-01-27 14:32:25 -080074
75 // All the other closures that this closure depends on for one of its fields,
76 // and the fields that it depends on.
Yang Nibd0af2d2015-03-23 17:14:58 -070077 Map<const Closure*, Map<const ScriptFieldID*,
78 ObjectBaseRef<ScriptFieldID>>*> mGlobalDeps;
Yang Nieb9aa672015-01-27 14:32:25 -080079
Yang Ni99bd4a42015-05-11 19:40:38 -070080 uint8_t* mParams;
Yang Nieb9aa672015-01-27 14:32:25 -080081 const size_t mParamLength;
Yang Ni1ffd86b2015-01-07 09:16:40 -080082};
83
84} // namespace renderscript
85} // namespace android
86
87#endif // ANDROID_RENDERSCRIPT_CLOSURE_H_