rsScript.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (C) 2009-2012 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_RS_SCRIPT_H
  17. #define ANDROID_RS_SCRIPT_H
  18. #include "rsAllocation.h"
  19. #include "rsMap.h"
  20. #include <utility>
  21. // ---------------------------------------------------------------------------
  22. namespace android {
  23. namespace renderscript {
  24. #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB)
  25. class ProgramVertex;
  26. class ProgramFragment;
  27. class ProgramRaster;
  28. class ProgramStore;
  29. #endif
  30. class IDBase : public ObjectBase {
  31. public:
  32. IDBase(Context *rsc, Script *s, int slot) :
  33. ObjectBase(rsc), mScript(s), mSlot(slot) {}
  34. virtual ~IDBase() {}
  35. virtual void serialize(Context *rsc, OStream *stream) const {}
  36. virtual RsA3DClassID getClassId() const = 0;
  37. Script *mScript;
  38. int mSlot;
  39. };
  40. class ScriptKernelID : public IDBase {
  41. public:
  42. ScriptKernelID(Context *rsc, Script *s, int slot, int sig);
  43. virtual ~ScriptKernelID() {}
  44. virtual RsA3DClassID getClassId() const;
  45. bool mHasKernelInput;
  46. bool mHasKernelOutput;
  47. };
  48. class ScriptInvokeID : public IDBase {
  49. public:
  50. ScriptInvokeID(Context *rsc, Script *s, int slot);
  51. virtual ~ScriptInvokeID() {}
  52. virtual RsA3DClassID getClassId() const;
  53. };
  54. class ScriptFieldID : public IDBase {
  55. public:
  56. ScriptFieldID(Context *rsc, Script *s, int slot);
  57. virtual ~ScriptFieldID() {}
  58. virtual RsA3DClassID getClassId() const;
  59. };
  60. class Script : public ObjectBase {
  61. public:
  62. struct Hal {
  63. void * drv;
  64. struct DriverInfo {
  65. int mVersionMajor;
  66. int mVersionMinor;
  67. size_t exportedVariableCount;
  68. size_t exportedForEachCount;
  69. size_t exportedReduceCount;
  70. size_t exportedFunctionCount;
  71. size_t exportedPragmaCount;
  72. char const **exportedPragmaKeyList;
  73. char const **exportedPragmaValueList;
  74. const Pair<const char *, uint32_t> *exportedForeachFuncList;
  75. int (* root)();
  76. };
  77. DriverInfo info;
  78. };
  79. Hal mHal;
  80. explicit Script(Context *);
  81. virtual ~Script();
  82. struct Enviroment_t {
  83. int64_t mStartTimeMillis;
  84. mutable int64_t mLastDtTime;
  85. #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB)
  86. ObjectBaseRef<ProgramVertex> mVertex;
  87. ObjectBaseRef<ProgramFragment> mFragment;
  88. ObjectBaseRef<ProgramRaster> mRaster;
  89. ObjectBaseRef<ProgramStore> mFragmentStore;
  90. #endif
  91. };
  92. Enviroment_t mEnviroment;
  93. void setSlot(uint32_t slot, Allocation *a);
  94. void setVar(uint32_t slot, const void *val, size_t len);
  95. void getVar(uint32_t slot, const void *val, size_t len);
  96. void setVar(uint32_t slot, const void *val, size_t len, Element *e,
  97. const uint32_t *dims, size_t dimLen);
  98. void setVarObj(uint32_t slot, ObjectBase *val);
  99. virtual bool freeChildren();
  100. virtual void runForEach(Context* rsc,
  101. uint32_t slot,
  102. const Allocation ** ains,
  103. size_t inLen,
  104. Allocation* aout,
  105. const void* usr,
  106. size_t usrBytes,
  107. const RsScriptCall *sc = nullptr) = 0;
  108. virtual void runReduce(Context *rsc, uint32_t slot,
  109. const Allocation **ains, size_t inLen,
  110. Allocation *aout, const RsScriptCall *sc) = 0;
  111. virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
  112. virtual void setupScript(Context *rsc) = 0;
  113. virtual uint32_t run(Context *) = 0;
  114. virtual bool isIntrinsic() const { return false; }
  115. bool hasObjectSlots() const {
  116. return mHasObjectSlots;
  117. }
  118. virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
  119. uint32_t getApiLevel() const {
  120. return mApiLevel;
  121. }
  122. protected:
  123. bool mInitialized;
  124. bool mHasObjectSlots;
  125. uint32_t mApiLevel;
  126. ObjectBaseRef<Allocation> *mSlots;
  127. ObjectBaseRef<const Type> *mTypes;
  128. };
  129. } // namespace renderscript
  130. } // namespace android
  131. #endif