rsClosure.h revision eb9aa675754c49f613c6ad71d41472b30f38b007
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 ObjectBase; 22class ScriptFieldID; 23class ScriptInvokeID; 24class ScriptKernelID; 25class Type; 26 27class Closure : public ObjectBase { 28 public: 29 Closure(Context* context, 30 const ScriptKernelID* kernelID, 31 Allocation* returnValue, 32 const int numValues, 33 const ScriptFieldID** fieldIDs, 34 const void** values, // Allocations or primitive (numeric) types 35 const size_t* sizes, // size for data type. -1 indicates an allocation. 36 const Closure** depClosures, 37 const ScriptFieldID** depFieldIDs); 38 Closure(Context* context, 39 const ScriptInvokeID* invokeID, 40 const void* params, 41 const size_t paramLength, 42 const size_t numValues, 43 const ScriptFieldID** fieldIDs, 44 const void** values, // Allocations or primitive (numeric) types 45 const size_t* sizes); // size for data type. -1 indicates an allocation. 46 47 virtual ~Closure(); 48 49 virtual void serialize(Context *rsc, OStream *stream) const {} 50 51 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_CLOSURE; } 52 53 void eval(); 54 55 void setArg(const uint32_t index, const void* value, const size_t size); 56 void setGlobal(const ScriptFieldID* fieldID, const void* value, 57 const size_t size); 58 59 Context* mContext; 60 61 // If mKernelID is not null, this is a closure for a kernel. Otherwise, it is 62 // a closure for an invoke function, whose id is the next field. At least one 63 // of these fields has to be non-null. 64 const ObjectBaseRef<ScriptKernelID> mKernelID; 65 // TODO(yangni): ObjectBaseRef<ScriptInvokeID> 66 const ScriptInvokeID* mInvokeID; 67 68 // Values referrenced in arguments and globals cannot be futures. They must be 69 // either a known value or unbound value. 70 // For now, all arguments should be Allocations. 71 vector<const void*> mArgs; 72 73 // A global could be allocation or any other data type, including primitive 74 // data types. 75 map<const ScriptFieldID*, pair<const void*, int>> mGlobals; 76 77 Allocation* mReturnValue; 78 79 // All the other closures that this closure depends on 80 set<const Closure*> mDependences; 81 82 // All the other closures which this closure depends on for one of its 83 // arguments, and the fields which it depends on. 84 map<const Closure*, map<int, const ObjectBaseRef<ScriptFieldID>*>*> mArgDeps; 85 86 // All the other closures that this closure depends on for one of its fields, 87 // and the fields that it depends on. 88 map<const Closure*, map<const ObjectBaseRef<ScriptFieldID>*, 89 const ObjectBaseRef<ScriptFieldID>*>*> mGlobalDeps; 90 91 const void* mParams; 92 const size_t mParamLength; 93}; 94 95} // namespace renderscript 96} // namespace android 97 98#endif // ANDROID_RENDERSCRIPT_CLOSURE_H_ 99