Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 1 | #ifndef ANDROID_RENDERSCRIPT_CLOSURE_H_ |
| 2 | #define ANDROID_RENDERSCRIPT_CLOSURE_H_ |
| 3 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 4 | #include "rsDefines.h" |
Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 5 | #include "rsMap.h" |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 6 | #include "rsObjectBase.h" |
| 7 | |
| 8 | namespace android { |
| 9 | namespace renderscript { |
| 10 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 11 | class Allocation; |
| 12 | class Context; |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 13 | class ObjectBase; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 14 | class ScriptFieldID; |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 15 | class ScriptInvokeID; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 16 | class ScriptKernelID; |
| 17 | class Type; |
| 18 | |
| 19 | class Closure : public ObjectBase { |
| 20 | public: |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 21 | 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 Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 38 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 39 | virtual ~Closure(); |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 40 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 41 | virtual void serialize(Context *rsc, OStream *stream) const {} |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 42 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 43 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_CLOSURE; } |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 44 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 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); |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 48 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 49 | Context* mContext; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 50 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 51 | // 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 Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 57 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 58 | // 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 Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 61 | const void** mArgs; |
| 62 | size_t mNumArg; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 63 | |
Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 64 | // A global could be allocation or any primitive data type. |
| 65 | Map<const ScriptFieldID*, Pair<const void*, size_t>> mGlobals; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 66 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 67 | Allocation* mReturnValue; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 68 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 69 | // All the other closures that this closure depends on |
Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 70 | // set<const Closure*> mDependences; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 71 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 72 | // All the other closures which this closure depends on for one of its |
| 73 | // arguments, and the fields which it depends on. |
Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 74 | Map<const Closure*, Map<int, const ObjectBaseRef<ScriptFieldID>*>*> mArgDeps; |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 75 | |
| 76 | // All the other closures that this closure depends on for one of its fields, |
| 77 | // and the fields that it depends on. |
Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 78 | Map<const Closure*, Map<const ObjectBaseRef<ScriptFieldID>*, |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 79 | const ObjectBaseRef<ScriptFieldID>*>*> mGlobalDeps; |
| 80 | |
| 81 | const void* mParams; |
| 82 | const size_t mParamLength; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } // namespace renderscript |
| 86 | } // namespace android |
| 87 | |
| 88 | #endif // ANDROID_RENDERSCRIPT_CLOSURE_H_ |