rsClosure.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef ANDROID_RENDERSCRIPT_CLOSURE_H_
  2. #define ANDROID_RENDERSCRIPT_CLOSURE_H_
  3. #include "rsDefines.h"
  4. #include "rsMap.h"
  5. #include "rsObjectBase.h"
  6. namespace android {
  7. namespace renderscript {
  8. class Allocation;
  9. class Context;
  10. class IDBase;
  11. class ObjectBase;
  12. class ScriptFieldID;
  13. class ScriptInvokeID;
  14. class ScriptKernelID;
  15. class Type;
  16. class Closure : public ObjectBase {
  17. public:
  18. Closure(Context* context,
  19. const ScriptKernelID* kernelID,
  20. Allocation* returnValue,
  21. const int numValues,
  22. const ScriptFieldID** fieldIDs,
  23. const int64_t* values, // Allocations or primitive (numeric) types
  24. const int* sizes, // size for data type. -1 indicates an allocation.
  25. const Closure** depClosures,
  26. const ScriptFieldID** depFieldIDs);
  27. Closure(Context* context,
  28. const ScriptInvokeID* invokeID,
  29. const void* params,
  30. const size_t paramLength,
  31. const size_t numValues,
  32. const ScriptFieldID** fieldIDs,
  33. const int64_t* values, // Allocations or primitive (numeric) types
  34. const int* sizes); // size for data type. -1 indicates an allocation.
  35. virtual ~Closure();
  36. virtual void serialize(Context *rsc, OStream *stream) const {}
  37. virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_CLOSURE; }
  38. // Set the value of an argument or a global.
  39. // The special value -1 for the size indicates the value is an Allocation.
  40. void setArg(const uint32_t index, const void* value, const int size);
  41. void setGlobal(const ScriptFieldID* fieldID, const int64_t value,
  42. const int size);
  43. Context* mContext;
  44. // KernelId or InvokeID
  45. const ObjectBaseRef<IDBase> mFunctionID;
  46. // Flag indicating if this closure is for a kernel (true) or invocable
  47. // function (false)
  48. const bool mIsKernel;
  49. // Values referrenced in arguments and globals cannot be futures. They must be
  50. // either a known value or unbound value.
  51. // For now, all arguments should be Allocations.
  52. const void** mArgs;
  53. size_t mNumArg;
  54. // A global could be allocation or any primitive data type.
  55. Map<const ScriptFieldID*, Pair<int64_t, int>> mGlobals;
  56. Allocation* mReturnValue;
  57. // All the other closures which this closure depends on for one of its
  58. // arguments, and the fields which it depends on.
  59. Map<const Closure*, Map<int, ObjectBaseRef<ScriptFieldID>>*> mArgDeps;
  60. // All the other closures that this closure depends on for one of its fields,
  61. // and the fields that it depends on.
  62. Map<const Closure*, Map<const ScriptFieldID*,
  63. ObjectBaseRef<ScriptFieldID>>*> mGlobalDeps;
  64. uint8_t* mParams;
  65. const size_t mParamLength;
  66. };
  67. } // namespace renderscript
  68. } // namespace android
  69. #endif // ANDROID_RENDERSCRIPT_CLOSURE_H_