rsHidlAdaptation.cpp 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. /*
  2. * Copyright (C) 2017 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. #define LOG_TAG "RenderScript HIDL Adaptation"
  17. #include "cpp/rsDispatch.h"
  18. #include "rsHidlAdaptation.h"
  19. #include "rsFallbackAdaptation.h"
  20. #include <cutils/properties.h>
  21. #include <log/log.h>
  22. using ::android::hardware::renderscript::V1_0::IDevice;
  23. using ::android::hardware::renderscript::V1_0::IContext;
  24. using ::android::hardware::renderscript::V1_0::Allocation;
  25. using ::android::hardware::renderscript::V1_0::AllocationCubemapFace;
  26. using ::android::hardware::renderscript::V1_0::AllocationMipmapControl;
  27. using ::android::hardware::renderscript::V1_0::AllocationUsageType;
  28. using ::android::hardware::renderscript::V1_0::Closure;
  29. using ::android::hardware::renderscript::V1_0::ContextType;
  30. using ::android::hardware::renderscript::V1_0::DataKind;
  31. using ::android::hardware::renderscript::V1_0::DataType;
  32. using ::android::hardware::renderscript::V1_0::ForEachStrategy;
  33. using ::android::hardware::renderscript::V1_0::MessageToClientType;
  34. using ::android::hardware::renderscript::V1_0::SamplerValue;
  35. using ::android::hardware::renderscript::V1_0::ScriptCall;
  36. using ::android::hardware::renderscript::V1_0::ScriptFieldID;
  37. using ::android::hardware::renderscript::V1_0::ScriptKernelID;
  38. using ::android::hardware::renderscript::V1_0::ScriptIntrinsicID;
  39. using ::android::hardware::renderscript::V1_0::ThreadPriorities;
  40. using ::android::hardware::renderscript::V1_0::Type;
  41. using ::android::hardware::renderscript::V1_0::YuvFormat;
  42. using ::android::hardware::renderscript::V1_0::Size;
  43. using ::android::hidl::base::V1_0::IBase;
  44. using ::android::hardware::hidl_array;
  45. using ::android::hardware::hidl_memory;
  46. using ::android::hardware::details::hidl_pointer;
  47. using ::android::hardware::hidl_string;
  48. using ::android::hardware::hidl_vec;
  49. using ::android::hardware::Return;
  50. using ::android::hardware::Void;
  51. using ::android::sp;
  52. dispatchTable RsHidlAdaptation::mEntryFuncs;
  53. sp<IDevice> RsHidlAdaptation::mHidl;
  54. std::set<sp<IContext> > RsHidlAdaptation::mContexts;
  55. std::mutex RsHidlAdaptation::mContextsMutex;
  56. static uint32_t getProp(const char *str) {
  57. char buf[PROPERTY_VALUE_MAX];
  58. property_get(str, buf, "0");
  59. return atoi(buf);
  60. }
  61. RsHidlAdaptation::RsHidlAdaptation()
  62. {
  63. InitializeHalDeviceContext();
  64. }
  65. RsHidlAdaptation& RsHidlAdaptation::GetInstance()
  66. {
  67. // This function-local-static guarantees the instance is a singleton. The
  68. // constructor of RsHidlAdaptation will only be called when GetInstance is
  69. // called for the first time.
  70. static RsHidlAdaptation instance;
  71. return instance;
  72. }
  73. const dispatchTable* RsHidlAdaptation::GetEntryFuncs()
  74. {
  75. return &mEntryFuncs;
  76. }
  77. void RsHidlAdaptation::LoadDispatchForHidl() {
  78. mEntryFuncs.Allocation1DData = Allocation1DData;
  79. mEntryFuncs.Allocation1DElementData = Allocation1DElementData;
  80. mEntryFuncs.Allocation1DRead = Allocation1DRead;
  81. mEntryFuncs.Allocation2DData = Allocation2DData;
  82. mEntryFuncs.Allocation2DRead = Allocation2DRead;
  83. mEntryFuncs.Allocation3DData = Allocation3DData;
  84. mEntryFuncs.Allocation3DRead = Allocation3DRead;
  85. mEntryFuncs.AllocationAdapterCreate = AllocationAdapterCreate;
  86. mEntryFuncs.AllocationAdapterOffset = AllocationAdapterOffset;
  87. mEntryFuncs.AllocationCopy2DRange = AllocationCopy2DRange;
  88. mEntryFuncs.AllocationCopy3DRange = AllocationCopy3DRange;
  89. mEntryFuncs.AllocationCopyToBitmap = AllocationCopyToBitmap;
  90. mEntryFuncs.AllocationCreateFromBitmap = AllocationCreateFromBitmap;
  91. mEntryFuncs.AllocationCreateTyped = AllocationCreateTyped;
  92. mEntryFuncs.AllocationCubeCreateFromBitmap = AllocationCubeCreateFromBitmap;
  93. mEntryFuncs.AllocationElementData = AllocationElementData;
  94. mEntryFuncs.AllocationElementRead = AllocationElementRead;
  95. mEntryFuncs.AllocationGenerateMipmaps = AllocationGenerateMipmaps;
  96. mEntryFuncs.AllocationGetPointer = AllocationGetPointer;
  97. mEntryFuncs.AllocationGetSurface = AllocationGetSurface;
  98. mEntryFuncs.AllocationGetType = AllocationGetType;
  99. mEntryFuncs.AllocationIoReceive = AllocationIoReceive;
  100. mEntryFuncs.AllocationIoSend = AllocationIoSend;
  101. mEntryFuncs.AllocationRead = AllocationRead;
  102. mEntryFuncs.AllocationResize1D = AllocationResize1D;
  103. mEntryFuncs.AllocationSetSurface = AllocationSetSurface;
  104. mEntryFuncs.AllocationSetupBufferQueue = AllocationSetupBufferQueue;
  105. mEntryFuncs.AllocationShareBufferQueue = AllocationShareBufferQueue;
  106. mEntryFuncs.AllocationSyncAll = AllocationSyncAll;
  107. mEntryFuncs.AssignName = AssignName;
  108. mEntryFuncs.ClosureCreate = ClosureCreate;
  109. mEntryFuncs.ClosureSetArg = ClosureSetArg;
  110. mEntryFuncs.ClosureSetGlobal = ClosureSetGlobal;
  111. mEntryFuncs.ContextCreate = ContextCreate;
  112. mEntryFuncs.ContextDeinitToClient = ContextDeinitToClient;
  113. mEntryFuncs.ContextDestroy = ContextDestroy;
  114. mEntryFuncs.ContextDump = ContextDump;
  115. mEntryFuncs.ContextFinish = ContextFinish;
  116. mEntryFuncs.ContextGetMessage = ContextGetMessage;
  117. mEntryFuncs.ContextInitToClient = ContextInitToClient;
  118. mEntryFuncs.ContextPeekMessage = ContextPeekMessage;
  119. mEntryFuncs.ContextSendMessage = ContextSendMessage;
  120. mEntryFuncs.ContextSetCacheDir = ContextSetCacheDir;
  121. mEntryFuncs.ContextSetPriority = ContextSetPriority;
  122. mEntryFuncs.ElementCreate = ElementCreate;
  123. mEntryFuncs.ElementCreate2 = ElementCreate2;
  124. mEntryFuncs.ElementGetNativeData = ElementGetNativeData;
  125. mEntryFuncs.ElementGetSubElements = ElementGetSubElements;
  126. mEntryFuncs.GetName = GetName;
  127. mEntryFuncs.InvokeClosureCreate = InvokeClosureCreate;
  128. mEntryFuncs.ObjDestroy = ObjDestroy;
  129. mEntryFuncs.SamplerCreate = SamplerCreate;
  130. mEntryFuncs.ScriptBindAllocation = ScriptBindAllocation;
  131. mEntryFuncs.ScriptCCreate = ScriptCCreate;
  132. mEntryFuncs.ScriptFieldIDCreate = ScriptFieldIDCreate;
  133. mEntryFuncs.ScriptForEach = ScriptForEach;
  134. mEntryFuncs.ScriptForEachMulti = ScriptForEachMulti;
  135. mEntryFuncs.ScriptGetVarV = ScriptGetVarV;
  136. mEntryFuncs.ScriptGroup2Create = ScriptGroup2Create;
  137. mEntryFuncs.ScriptGroupCreate = ScriptGroupCreate;
  138. mEntryFuncs.ScriptGroupExecute = ScriptGroupExecute;
  139. mEntryFuncs.ScriptGroupSetInput = ScriptGroupSetInput;
  140. mEntryFuncs.ScriptGroupSetOutput = ScriptGroupSetOutput;
  141. mEntryFuncs.ScriptIntrinsicCreate = ScriptIntrinsicCreate;
  142. mEntryFuncs.ScriptInvoke = ScriptInvoke;
  143. mEntryFuncs.ScriptInvokeIDCreate = ScriptInvokeIDCreate;
  144. mEntryFuncs.ScriptInvokeV = ScriptInvokeV;
  145. mEntryFuncs.ScriptKernelIDCreate = ScriptKernelIDCreate;
  146. mEntryFuncs.ScriptReduce = ScriptReduce;
  147. mEntryFuncs.ScriptSetTimeZone = ScriptSetTimeZone;
  148. mEntryFuncs.ScriptSetVarD = ScriptSetVarD;
  149. mEntryFuncs.ScriptSetVarF = ScriptSetVarF;
  150. mEntryFuncs.ScriptSetVarI = ScriptSetVarI;
  151. mEntryFuncs.ScriptSetVarJ = ScriptSetVarJ;
  152. mEntryFuncs.ScriptSetVarObj = ScriptSetVarObj;
  153. mEntryFuncs.ScriptSetVarV = ScriptSetVarV;
  154. mEntryFuncs.ScriptSetVarVE = ScriptSetVarVE;
  155. mEntryFuncs.TypeCreate = TypeCreate;
  156. mEntryFuncs.TypeGetNativeData = TypeGetNativeData;
  157. }
  158. void RsHidlAdaptation::InitializeHalDeviceContext()
  159. {
  160. ALOGD("IRenderScriptDevice::getService()");
  161. if (getProp("debug.rs.rsov") == 0 &&
  162. getProp("debug.rs.default-CPU-driver") == 0) {
  163. // get HIDL service and register callback
  164. mHidl = IDevice::getService();
  165. }
  166. ALOGD("IRenderScriptDevice::getService() returned %p", mHidl.get());
  167. if (mHidl == NULL) {
  168. ALOGD("Using Fallback Path.");
  169. RsFallbackAdaptation& fallbackInstance = RsFallbackAdaptation::GetInstance();
  170. mEntryFuncs = *(fallbackInstance.GetEntryFuncs());
  171. } else {
  172. ALOGD("HIDL successfully loaded.");
  173. LoadDispatchForHidl();
  174. }
  175. }
  176. IContext *RsHidlAdaptation::GetIContextHandle(RsContext context) {
  177. return (IContext *)context;
  178. }
  179. RsContext RsHidlAdaptation::ContextCreate(RsDevice vdev, uint32_t version, uint32_t sdkVersion, RsContextType ct, uint32_t flags)
  180. {
  181. // Get the handle to IContext interface object and save it to the map.
  182. sp<IContext> context = mHidl->contextCreate(sdkVersion, (ContextType)ct, flags);
  183. RsContext ret = (RsContext)(uintptr_t)context.get();
  184. std::unique_lock<std::mutex> lock(mContextsMutex);
  185. mContexts.insert(context);
  186. return ret;
  187. }
  188. void RsHidlAdaptation::ContextDestroy (RsContext context)
  189. {
  190. // Destroy the driver context and remove IContext handle from the map.
  191. GetIContextHandle(context)->contextDestroy();
  192. std::unique_lock<std::mutex> lock(mContextsMutex);
  193. mContexts.erase((IContext*)context);
  194. }
  195. const void* RsHidlAdaptation::AllocationGetType(RsContext context, RsAllocation allocation)
  196. {
  197. // TODO: Replace this idiom "(uint64_t)(uintptr_t)" with a rs_to_hal function?
  198. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  199. uint64_t typeRet = GetIContextHandle(context)->allocationGetType(_allocation);
  200. return (void *)typeRet;
  201. }
  202. void RsHidlAdaptation::TypeGetNativeData(RsContext context, RsType type, uintptr_t *typedata, uint32_t typeDataSize)
  203. {
  204. uint64_t _type = (uint64_t)(uintptr_t)type;
  205. GetIContextHandle(context)->typeGetNativeMetadata(_type,
  206. [typedata, typeDataSize] (const hidl_vec<uint64_t> &retTypeData){
  207. for (uint32_t i=0; i<typeDataSize; i++) {
  208. typedata[i] = (uintptr_t)retTypeData[i];
  209. }
  210. });
  211. }
  212. void RsHidlAdaptation::ElementGetNativeData(RsContext context, RsElement element, uint32_t *elemData, uint32_t elemDataSize)
  213. {
  214. uint64_t _element = (uint64_t)(uintptr_t)element;
  215. GetIContextHandle(context)->elementGetNativeMetadata(_element,
  216. [elemData, elemDataSize] (const hidl_vec<uint32_t> &retElemData){
  217. for (uint32_t i=0; i<elemDataSize; i++) {
  218. elemData[i] = retElemData[i];
  219. }
  220. });
  221. }
  222. void RsHidlAdaptation::ElementGetSubElements(RsContext context, RsElement element, uintptr_t *ids, const char **names, size_t *arraySizes, uint32_t dataSize)
  223. {
  224. uint64_t _element = (uint64_t)(uintptr_t)element;
  225. uint64_t _ids = (uint64_t)(uintptr_t)ids;
  226. uint64_t _names = (uint64_t)(uintptr_t)names;
  227. uint64_t _arraySizes = (uint64_t)(uintptr_t)arraySizes;
  228. GetIContextHandle(context)->elementGetSubElements(_element, dataSize,
  229. [ids, names, arraySizes, dataSize] (const hidl_vec<uint64_t> &retIds, const hidl_vec<hidl_string> &retNames, const hidl_vec<Size> &retArraySizes){
  230. for (uint32_t i=0; i<dataSize; i++) {
  231. ids[i] = static_cast<uintptr_t>(retIds[i]);
  232. names[i] = static_cast<const char *>(retNames[i].c_str());
  233. arraySizes[i] = static_cast<size_t>(retArraySizes[i]);
  234. }
  235. });
  236. }
  237. void RsHidlAdaptation::GetName(RsContext context, void * obj, const char **name) {
  238. uint64_t _obj = (uint64_t)(uintptr_t)obj;
  239. GetIContextHandle(context)->getName(_obj, [name](hidl_string ret_name) {*name = ret_name.c_str();});
  240. }
  241. RsClosure RsHidlAdaptation::ClosureCreate(RsContext context, RsScriptKernelID kernelID,
  242. RsAllocation returnValue,
  243. RsScriptFieldID* fieldIDs, size_t fieldIDs_length,
  244. int64_t* values, size_t values_length,
  245. int* sizes, size_t sizes_length,
  246. RsClosure* depClosures, size_t depClosures_length,
  247. RsScriptFieldID* depFieldIDs,
  248. size_t depFieldIDs_length)
  249. {
  250. uint64_t _kernelID = (uint64_t)(uintptr_t)kernelID;
  251. uint64_t _returnValue = (uint64_t)(uintptr_t)returnValue;
  252. std::vector<ScriptFieldID> _fieldIDs(fieldIDs_length);
  253. std::vector<int64_t> _values(values_length);
  254. std::vector<int32_t> _sizes(sizes_length);
  255. std::vector<Closure> _depClosures(depClosures_length);
  256. std::vector<ScriptFieldID> _depFieldIDs(depFieldIDs_length);
  257. // TODO: Replace this idiom with a rs_to_hal function?
  258. for (size_t i = 0; i < fieldIDs_length; i++) {
  259. _fieldIDs[i] = (ScriptFieldID)(uintptr_t)fieldIDs[i];
  260. }
  261. for (size_t i = 0; i < values_length; i++) {
  262. _values[i] = (int64_t)values[i];
  263. }
  264. for (size_t i = 0; i < sizes_length; i++) {
  265. _sizes[i] = (int32_t)sizes[i];
  266. }
  267. for (size_t i = 0; i < depClosures_length; i++) {
  268. _depClosures[i] = (Closure)(uintptr_t)depClosures[i];
  269. }
  270. for (size_t i = 0; i < depFieldIDs_length; i++) {
  271. _depFieldIDs[i] = (ScriptFieldID)(uintptr_t)depFieldIDs[i];
  272. }
  273. uint64_t closure = GetIContextHandle(context)->closureCreate(_kernelID, _returnValue,
  274. _fieldIDs, _values, _sizes,
  275. _depClosures, _depFieldIDs);
  276. return (RsClosure) closure;
  277. }
  278. RsClosure RsHidlAdaptation::InvokeClosureCreate(RsContext context, RsScriptInvokeID invokeID,
  279. const void* params, const size_t paramLength,
  280. const RsScriptFieldID* fieldIDs, const size_t fieldIDs_length,
  281. const int64_t* values, const size_t values_length,
  282. const int* sizes, const size_t sizes_length)
  283. {
  284. uint64_t _invokeID = (uint64_t)(uintptr_t)invokeID;
  285. hidl_vec<uint8_t> _params;
  286. _params.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(params)), paramLength);
  287. std::vector<ScriptFieldID> _fieldIDs(fieldIDs_length);
  288. std::vector<int64_t> _values(values_length);
  289. std::vector<int32_t> _sizes(sizes_length);
  290. for (size_t i = 0; i < fieldIDs_length; i++) {
  291. _fieldIDs[i] = (ScriptFieldID)(uintptr_t)fieldIDs[i];
  292. }
  293. for (size_t i = 0; i < values_length; i++) {
  294. _values[i] = (int64_t)values[i];
  295. }
  296. for (size_t i = 0; i < sizes_length; i++) {
  297. _sizes[i] = (int32_t)sizes[i];
  298. }
  299. uint64_t closure = GetIContextHandle(context)->invokeClosureCreate(_invokeID,
  300. _params, _fieldIDs,
  301. _values, _sizes);
  302. return (RsClosure) closure;
  303. }
  304. void RsHidlAdaptation::ClosureSetArg(RsContext context, RsClosure closure, uint32_t index,
  305. uintptr_t value, int size)
  306. {
  307. uint64_t _closure = (uint64_t)(uintptr_t)closure;
  308. void * _value = (void *)value;
  309. GetIContextHandle(context)->closureSetArg(_closure, index, _value, size);
  310. }
  311. void RsHidlAdaptation::ClosureSetGlobal(RsContext context, RsClosure closure,
  312. RsScriptFieldID fieldID, int64_t value,
  313. int size)
  314. {
  315. uint64_t _closure = (uint64_t)(uintptr_t)closure;
  316. uint64_t _fieldID = (uint64_t)(uintptr_t)fieldID;
  317. GetIContextHandle(context)->closureSetGlobal(_closure, _fieldID, value, size);
  318. }
  319. RsMessageToClientType RsHidlAdaptation::ContextGetMessage (RsContext context, void * data, size_t data_length,
  320. size_t * receiveLen, size_t receiveLen_length,
  321. uint32_t * subID, size_t subID_length)
  322. {
  323. RsMessageToClientType msgType;
  324. GetIContextHandle(context)->contextGetMessage(data, data_length,
  325. [&msgType, receiveLen](MessageToClientType retMessageType, uint64_t retReceiveLen) {
  326. msgType = (RsMessageToClientType) retMessageType;
  327. *receiveLen = retReceiveLen;
  328. });
  329. return msgType;
  330. }
  331. RsMessageToClientType RsHidlAdaptation::ContextPeekMessage (RsContext context,
  332. size_t * receiveLen, size_t receiveLen_length,
  333. uint32_t * subID, size_t subID_length)
  334. {
  335. RsMessageToClientType msgType;
  336. GetIContextHandle(context)->contextPeekMessage(
  337. [&msgType, receiveLen, subID](MessageToClientType retMessageType, uint64_t retReceiveLen, uint32_t retSubID) {
  338. msgType = (RsMessageToClientType) retMessageType;
  339. *receiveLen = retReceiveLen;
  340. *subID = retSubID;
  341. });
  342. return msgType;
  343. }
  344. void RsHidlAdaptation::ContextSendMessage (RsContext context, uint32_t id, const uint8_t *data, size_t len)
  345. {
  346. hidl_vec<uint8_t> _data;
  347. _data.setToExternal(const_cast<uint8_t *>(data), len);
  348. GetIContextHandle(context)->contextSendMessage(id, _data);
  349. }
  350. void RsHidlAdaptation::ContextInitToClient (RsContext context)
  351. {
  352. GetIContextHandle(context)->contextInitToClient();
  353. }
  354. void RsHidlAdaptation::ContextDeinitToClient (RsContext context)
  355. {
  356. GetIContextHandle(context)->contextDeinitToClient();
  357. }
  358. RsType RsHidlAdaptation::TypeCreate (RsContext context, RsElement element, uint32_t dimX,
  359. uint32_t dimY, uint32_t dimZ, bool mipmaps,
  360. bool faces, uint32_t yuv)
  361. {
  362. uint64_t _element = (uint64_t)(uintptr_t)element;
  363. uint64_t type = GetIContextHandle(context)->typeCreate(_element, dimX, dimY, dimZ, mipmaps, faces,
  364. (YuvFormat) yuv);
  365. return (RsType) type;
  366. }
  367. RsAllocation RsHidlAdaptation::AllocationCreateTyped (RsContext context, RsType type,
  368. RsAllocationMipmapControl mipmaps,
  369. uint32_t usages, uintptr_t ptr)
  370. {
  371. uint64_t _type = (uint64_t)(uintptr_t)type;
  372. void * _ptr = (void *)ptr;
  373. uint64_t allocation = GetIContextHandle(context)->allocationCreateTyped(_type,
  374. (AllocationMipmapControl)mipmaps, usages, _ptr);
  375. return (RsAllocation) allocation;
  376. }
  377. RsAllocation RsHidlAdaptation::AllocationCreateFromBitmap (RsContext context, RsType type,
  378. RsAllocationMipmapControl mipmaps,
  379. const void *data, size_t sizeBytes, uint32_t usages)
  380. {
  381. uint64_t _type = (uint64_t)(uintptr_t)type;
  382. hidl_vec<uint8_t> _bitmap;
  383. _bitmap.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), sizeBytes);
  384. uint64_t allocation = GetIContextHandle(context)->allocationCreateFromBitmap(_type,
  385. (AllocationMipmapControl)mipmaps, _bitmap, usages);
  386. return (RsAllocation) allocation;
  387. }
  388. RsAllocation RsHidlAdaptation::AllocationCubeCreateFromBitmap(RsContext context, RsType type,
  389. RsAllocationMipmapControl mipmaps,
  390. const void *data, size_t sizeBytes, uint32_t usages)
  391. {
  392. uint64_t _type = (uint64_t)(uintptr_t)type;
  393. hidl_vec<uint8_t> _bitmap;
  394. _bitmap.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), sizeBytes);
  395. uint64_t allocation = GetIContextHandle(context)->allocationCubeCreateFromBitmap(_type, (AllocationMipmapControl)mipmaps, _bitmap, usages);
  396. return (RsAllocation) allocation;
  397. }
  398. RsNativeWindow RsHidlAdaptation::AllocationGetSurface (RsContext context, RsAllocation allocation)
  399. {
  400. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  401. uint64_t window = GetIContextHandle(context)->allocationGetNativeWindow(_allocation);
  402. return (RsNativeWindow) window;
  403. }
  404. void RsHidlAdaptation::AllocationSetSurface (RsContext context, RsAllocation allocation, RsNativeWindow window)
  405. {
  406. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  407. uint64_t _window = (uint64_t)(uintptr_t)window;
  408. GetIContextHandle(context)->allocationSetNativeWindow(_allocation, _window);
  409. }
  410. void RsHidlAdaptation::ContextFinish (RsContext context)
  411. {
  412. GetIContextHandle(context)->contextFinish();
  413. }
  414. void RsHidlAdaptation::ContextDump (RsContext context, int32_t bits)
  415. {
  416. GetIContextHandle(context)->contextLog();
  417. }
  418. void RsHidlAdaptation::ContextSetPriority (RsContext context, int32_t priority)
  419. {
  420. GetIContextHandle(context)->contextSetPriority((ThreadPriorities)priority);
  421. }
  422. void RsHidlAdaptation::ContextSetCacheDir (RsContext context, const char *cacheDir, size_t cacheDir_length)
  423. {
  424. GetIContextHandle(context)->contextSetCacheDir(hidl_string(cacheDir));
  425. }
  426. void RsHidlAdaptation::AssignName (RsContext context, RsObjectBase obj, const char* name, size_t size)
  427. {
  428. uint64_t _obj = (uint64_t)(uintptr_t)obj;
  429. GetIContextHandle(context)->assignName(_obj, hidl_string(name));
  430. }
  431. void RsHidlAdaptation::ObjDestroy (RsContext context, RsAsyncVoidPtr obj)
  432. {
  433. uint64_t _obj = (uint64_t)(uintptr_t)obj;
  434. GetIContextHandle(context)->objDestroy(_obj);
  435. }
  436. RsElement RsHidlAdaptation::ElementCreate (RsContext context,
  437. RsDataType dt,
  438. RsDataKind dk,
  439. bool norm,
  440. uint32_t vecSize)
  441. {
  442. uint64_t element = GetIContextHandle(context)->elementCreate((DataType) dt,
  443. (DataKind) dk,
  444. norm,
  445. vecSize);
  446. return (RsElement) element;
  447. }
  448. RsElement RsHidlAdaptation::ElementCreate2 (RsContext context,
  449. const RsElement * ein,
  450. size_t ein_length,
  451. const char ** names,
  452. size_t nameLengths_length,
  453. const size_t * nameLengths,
  454. const uint32_t * arraySizes,
  455. size_t arraySizes_length)
  456. {
  457. std::vector<uint64_t> _ein(ein_length);
  458. std::vector<hidl_string> _names(nameLengths_length);
  459. std::vector<Size> _arraySizes(arraySizes_length);
  460. for (size_t i = 0; i < ein_length; i++) {
  461. _ein[i] = (uint64_t)((uintptr_t)ein[i]);
  462. }
  463. for (size_t i = 0; i < ein_length; i++) {
  464. _names[i] = hidl_string(names[i]);
  465. }
  466. for (size_t i = 0; i < arraySizes_length; i++) {
  467. _arraySizes[i] = (Size)arraySizes[i];
  468. }
  469. uint64_t element = GetIContextHandle(context)->elementComplexCreate(_ein, _names, _arraySizes);
  470. return (RsElement) element;
  471. }
  472. void RsHidlAdaptation::AllocationCopyToBitmap (RsContext context, RsAllocation allocation, void *data, size_t sizeBytes)
  473. {
  474. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  475. GetIContextHandle(context)->allocationCopyToBitmap(_allocation, data, sizeBytes);
  476. }
  477. void RsHidlAdaptation::Allocation1DData (RsContext context, RsAllocation allocation, uint32_t xoff, uint32_t lod,
  478. uint32_t count, const void *data, size_t sizeBytes)
  479. {
  480. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  481. hidl_vec<uint8_t> _data;
  482. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), sizeBytes);
  483. GetIContextHandle(context)->allocation1DWrite(_allocation, xoff, lod, count, _data);
  484. }
  485. void RsHidlAdaptation::Allocation1DElementData (RsContext context, RsAllocation allocation, uint32_t xoff,
  486. uint32_t lod, const void *data, size_t sizeBytes, size_t eoff)
  487. {
  488. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  489. hidl_vec<uint8_t> _data;
  490. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), sizeBytes);
  491. GetIContextHandle(context)->allocationElementWrite(_allocation, xoff, 0, 0, lod, _data, eoff);
  492. }
  493. void RsHidlAdaptation::AllocationElementData (RsContext context, RsAllocation allocation, uint32_t x, uint32_t y, uint32_t z,
  494. uint32_t lod, const void *data, size_t sizeBytes, size_t eoff)
  495. {
  496. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  497. hidl_vec<uint8_t> _data;
  498. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), sizeBytes);
  499. GetIContextHandle(context)->allocationElementWrite(_allocation, x, y, z, lod, _data, eoff);
  500. }
  501. void RsHidlAdaptation::Allocation2DData (RsContext context, RsAllocation allocation, uint32_t xoff, uint32_t yoff,
  502. uint32_t lod, RsAllocationCubemapFace face,
  503. uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride)
  504. {
  505. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  506. hidl_vec<uint8_t> _data;
  507. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), sizeBytes);
  508. GetIContextHandle(context)->allocation2DWrite(_allocation, xoff, yoff, lod, (AllocationCubemapFace)face, w, h, _data, stride);
  509. }
  510. void RsHidlAdaptation::Allocation3DData (RsContext context, RsAllocation allocation, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
  511. uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride)
  512. {
  513. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  514. hidl_vec<uint8_t> _data;
  515. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), sizeBytes);
  516. GetIContextHandle(context)->allocation3DWrite(_allocation, xoff, yoff, zoff, lod, w, h, d, _data, stride);
  517. }
  518. void RsHidlAdaptation::AllocationGenerateMipmaps (RsContext context, RsAllocation allocation)
  519. {
  520. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  521. GetIContextHandle(context)->allocationGenerateMipmaps(_allocation);
  522. }
  523. void RsHidlAdaptation::AllocationRead (RsContext context, RsAllocation allocation, void *data, size_t sizeBytes)
  524. {
  525. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  526. GetIContextHandle(context)->allocationRead(_allocation, data, sizeBytes);
  527. }
  528. void RsHidlAdaptation::Allocation1DRead (RsContext context, RsAllocation allocation, uint32_t xoff, uint32_t lod,
  529. uint32_t count, void *data, size_t sizeBytes)
  530. {
  531. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  532. GetIContextHandle(context)->allocation1DRead(_allocation, xoff, lod, count, data, sizeBytes);
  533. }
  534. void RsHidlAdaptation::AllocationElementRead (RsContext context, RsAllocation allocation, uint32_t x, uint32_t y, uint32_t z,
  535. uint32_t lod, void *data, size_t sizeBytes, size_t eoff)
  536. {
  537. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  538. GetIContextHandle(context)->allocationElementRead(_allocation, x, y, z, lod, data, sizeBytes, eoff);
  539. }
  540. void RsHidlAdaptation::Allocation2DRead (RsContext context, RsAllocation allocation, uint32_t xoff, uint32_t yoff,
  541. uint32_t lod, RsAllocationCubemapFace face,
  542. uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride)
  543. {
  544. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  545. GetIContextHandle(context)->allocation2DRead(_allocation, xoff, yoff, lod, (AllocationCubemapFace)face, w, h, data, sizeBytes, stride);
  546. }
  547. void RsHidlAdaptation::Allocation3DRead (RsContext context, RsAllocation allocation, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
  548. uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, size_t stride)
  549. {
  550. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  551. GetIContextHandle(context)->allocation3DRead(_allocation, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
  552. }
  553. void RsHidlAdaptation::AllocationSyncAll (RsContext context, RsAllocation allocation, RsAllocationUsageType usage)
  554. {
  555. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  556. GetIContextHandle(context)->allocationSyncAll(_allocation,
  557. (AllocationUsageType) usage);
  558. }
  559. void RsHidlAdaptation::AllocationResize1D (RsContext context, RsAllocation allocation, uint32_t dimX)
  560. {
  561. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  562. GetIContextHandle(context)->allocationResize1D(_allocation, dimX);
  563. }
  564. void RsHidlAdaptation::AllocationCopy2DRange (RsContext context,
  565. RsAllocation dstAlloc,
  566. uint32_t dstXoff, uint32_t dstYoff,
  567. uint32_t dstMip, uint32_t dstFace,
  568. uint32_t width, uint32_t height,
  569. RsAllocation srcAlloc,
  570. uint32_t srcXoff, uint32_t srcYoff,
  571. uint32_t srcMip, uint32_t srcFace)
  572. {
  573. uint64_t _dstAlloc = (uint64_t)(uintptr_t)dstAlloc;
  574. uint64_t _srcAlloc = (uint64_t)(uintptr_t)srcAlloc;
  575. GetIContextHandle(context)->allocationCopy2DRange(_dstAlloc, dstXoff, dstYoff, dstMip, (AllocationCubemapFace)dstFace, width, height,
  576. _srcAlloc, srcXoff, srcYoff, srcMip, (AllocationCubemapFace)srcFace);
  577. }
  578. void RsHidlAdaptation::AllocationCopy3DRange (RsContext context,
  579. RsAllocation dstAlloc,
  580. uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
  581. uint32_t dstMip,
  582. uint32_t width, uint32_t height, uint32_t depth,
  583. RsAllocation srcAlloc,
  584. uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
  585. uint32_t srcMip)
  586. {
  587. uint64_t _dstAlloc = (uint64_t)(uintptr_t)dstAlloc;
  588. uint64_t _srcAlloc = (uint64_t)(uintptr_t)srcAlloc;
  589. GetIContextHandle(context)->allocationCopy3DRange(_dstAlloc, dstXoff, dstYoff, dstZoff, dstMip, width, height, depth,
  590. _srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
  591. }
  592. RsSampler RsHidlAdaptation::SamplerCreate (RsContext context,
  593. RsSamplerValue magFilter,
  594. RsSamplerValue minFilter,
  595. RsSamplerValue wrapS,
  596. RsSamplerValue wrapT,
  597. RsSamplerValue wrapR,
  598. float aniso)
  599. {
  600. uint64_t sampler = GetIContextHandle(context)->samplerCreate((SamplerValue) magFilter,
  601. (SamplerValue)minFilter,
  602. (SamplerValue)wrapS,
  603. (SamplerValue)wrapT,
  604. (SamplerValue)wrapR,
  605. aniso);
  606. return (RsSampler) sampler;
  607. }
  608. void RsHidlAdaptation::ScriptBindAllocation (RsContext context, RsScript script, RsAllocation allocation, uint32_t slot)
  609. {
  610. uint64_t _script = (uint64_t)(uintptr_t)script;
  611. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  612. GetIContextHandle(context)->scriptBindAllocation(_script, _allocation, slot);
  613. }
  614. void RsHidlAdaptation::ScriptSetTimeZone (RsContext context, RsScript script, const char* timezone, size_t size)
  615. {
  616. uint64_t _script = (uint64_t)(uintptr_t)script;
  617. GetIContextHandle(context)->scriptSetTimeZone(_script, hidl_string(timezone));
  618. }
  619. void RsHidlAdaptation::ScriptInvoke (RsContext context, RsScript script, uint32_t slot)
  620. {
  621. uint64_t _script = (uint64_t)(uintptr_t)script;
  622. GetIContextHandle(context)->scriptInvoke(_script, slot);
  623. }
  624. void RsHidlAdaptation::ScriptInvokeV (RsContext context, RsScript script, uint32_t slot, const void *data, size_t len)
  625. {
  626. uint64_t _script = (uint64_t)(uintptr_t)script;
  627. hidl_vec<uint8_t> _data;
  628. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), len);
  629. GetIContextHandle(context)->scriptInvokeV(_script, slot, _data);
  630. }
  631. void RsHidlAdaptation::ScriptForEach (RsContext context, RsScript script, uint32_t slot,
  632. RsAllocation vain, RsAllocation vaout,
  633. const void *params, size_t paramLen,
  634. const RsScriptCall *sc, size_t scLen)
  635. {
  636. RsAllocation * vains = nullptr;
  637. size_t inLen = 0;
  638. if (vain) {
  639. vains = &vain;
  640. inLen = 1;
  641. }
  642. ScriptForEachMulti(context, script, slot, vains, inLen, vaout, params, paramLen, sc, scLen);
  643. }
  644. void RsHidlAdaptation::ScriptForEachMulti (RsContext context, RsScript script, uint32_t slot,
  645. RsAllocation *vains, size_t inLen,
  646. RsAllocation vaout, const void *params,
  647. size_t paramLen, const RsScriptCall *sc,
  648. size_t scLen)
  649. {
  650. uint64_t _script = (uint64_t)(uintptr_t)script;
  651. std::vector<Allocation> _vains(inLen);
  652. for (size_t i = 0; i < inLen; i++) {
  653. _vains[i] = (Allocation)(uintptr_t)vains[i];
  654. }
  655. uint64_t _vaout = (uint64_t)(uintptr_t)vaout;
  656. hidl_vec<uint8_t> _params;
  657. _params.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(params)), paramLen);
  658. ScriptCall * _scPtr = nullptr;
  659. ScriptCall _sc;
  660. if (sc) {
  661. _sc.strategy = static_cast<ForEachStrategy>(sc->strategy);
  662. _sc.xStart = sc->xStart;
  663. _sc.xEnd = sc->xEnd;
  664. _sc.yStart = sc->yStart;
  665. _sc.yEnd = sc->yEnd;
  666. _sc.zStart = sc->zStart;
  667. _sc.zEnd = sc->zEnd;
  668. _sc.arrayStart = sc->arrayStart;
  669. _sc.arrayEnd = sc->arrayEnd;
  670. _sc.array2Start = sc->array2Start;
  671. _sc.array2End = sc->arrayEnd;
  672. _sc.array3Start = sc->array3Start;
  673. _sc.array3End = sc->arrayEnd;
  674. _sc.array4Start = sc->array4Start;
  675. _sc.array4End = sc->arrayEnd;
  676. _scPtr = &_sc;
  677. }
  678. GetIContextHandle(context)->scriptForEach(_script, slot, _vains, _vaout, _params, _scPtr);
  679. }
  680. void RsHidlAdaptation::ScriptReduce (RsContext context, RsScript script, uint32_t slot,
  681. RsAllocation *vains, size_t inLen, RsAllocation vaout,
  682. const RsScriptCall *sc, size_t scLen)
  683. {
  684. uint64_t _script = (uint64_t)(uintptr_t)script;
  685. std::vector<Allocation> _vains(inLen);
  686. for (size_t i = 0; i < inLen; i++) {
  687. _vains[i] = (Allocation)(uintptr_t)vains[i];
  688. }
  689. uint64_t _vaout = (uint64_t)(uintptr_t)vaout;
  690. ScriptCall * _scPtr = nullptr;
  691. ScriptCall _sc;
  692. if (sc) {
  693. _sc.strategy = static_cast<ForEachStrategy>(sc->strategy);
  694. _sc.xStart = sc->xStart;
  695. _sc.xEnd = sc->xEnd;
  696. _sc.yStart = sc->yStart;
  697. _sc.yEnd = sc->yEnd;
  698. _sc.zStart = sc->zStart;
  699. _sc.zEnd = sc->zEnd;
  700. _sc.arrayStart = sc->arrayStart;
  701. _sc.arrayEnd = sc->arrayEnd;
  702. _sc.array2Start = sc->array2Start;
  703. _sc.array2End = sc->arrayEnd;
  704. _sc.array3Start = sc->array3Start;
  705. _sc.array3End = sc->arrayEnd;
  706. _sc.array4Start = sc->array4Start;
  707. _sc.array4End = sc->arrayEnd;
  708. _scPtr = &_sc;
  709. }
  710. GetIContextHandle(context)->scriptReduce(_script, slot, _vains, _vaout, _scPtr);
  711. }
  712. void RsHidlAdaptation::ScriptSetVarI (RsContext context, RsScript script, uint32_t slot, int value)
  713. {
  714. uint64_t _script = (uint64_t)(uintptr_t)script;
  715. GetIContextHandle(context)->scriptSetVarI(_script, slot, value);
  716. }
  717. void RsHidlAdaptation::ScriptSetVarObj (RsContext context, RsScript script, uint32_t slot, RsObjectBase obj)
  718. {
  719. uint64_t _script = (uint64_t)(uintptr_t)script;
  720. uint64_t _obj = (uint64_t)(uintptr_t)obj;
  721. GetIContextHandle(context)->scriptSetVarObj(_script, slot, _obj);
  722. }
  723. void RsHidlAdaptation::ScriptSetVarJ (RsContext context, RsScript script, uint32_t slot, int64_t value)
  724. {
  725. uint64_t _script = (uint64_t)(uintptr_t)script;
  726. GetIContextHandle(context)->scriptSetVarJ(_script, slot, value);
  727. }
  728. void RsHidlAdaptation::ScriptSetVarF (RsContext context, RsScript script, uint32_t slot, float value)
  729. {
  730. uint64_t _script = (uint64_t)(uintptr_t)script;
  731. GetIContextHandle(context)->scriptSetVarF(_script, slot, value);
  732. }
  733. void RsHidlAdaptation::ScriptSetVarD (RsContext context, RsScript script, uint32_t slot, double value)
  734. {
  735. uint64_t _script = (uint64_t)(uintptr_t)script;
  736. GetIContextHandle(context)->scriptSetVarD(_script, slot, value);
  737. }
  738. void RsHidlAdaptation::ScriptSetVarV (RsContext context, RsScript script, uint32_t slot, const void* data, size_t len)
  739. {
  740. uint64_t _script = (uint64_t)(uintptr_t)script;
  741. hidl_vec<uint8_t> _data;
  742. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), len);
  743. GetIContextHandle(context)->scriptSetVarV(_script, slot, _data);
  744. }
  745. void RsHidlAdaptation::ScriptGetVarV (RsContext context, RsScript script, uint32_t slot, void* data, size_t len)
  746. {
  747. uint64_t _script = (uint64_t)(uintptr_t)script;
  748. GetIContextHandle(context)->scriptGetVarV(_script, slot, len,
  749. [data, len] (const hidl_vec<uint8_t> &retData) {
  750. memcpy(data, retData.data(), len);
  751. });
  752. }
  753. void RsHidlAdaptation::ScriptSetVarVE (RsContext context, RsScript script, uint32_t slot,
  754. const void *data, size_t len, RsElement ve,
  755. const uint32_t *dims, size_t dimLen)
  756. {
  757. uint64_t _script = (uint64_t)(uintptr_t)script;
  758. hidl_vec<uint8_t> _data;
  759. _data.setToExternal(reinterpret_cast<uint8_t *>(const_cast<void *>(data)), len);
  760. uint64_t _ve = (uint64_t)(uintptr_t)ve;
  761. hidl_vec<uint32_t> _dims;
  762. _dims.setToExternal(const_cast<uint32_t *>(dims), dimLen / sizeof(uint32_t));
  763. GetIContextHandle(context)->scriptSetVarVE(_script, slot, _data, _ve, _dims);
  764. }
  765. RsScript RsHidlAdaptation::ScriptCCreate (RsContext context,
  766. const char *resName, size_t resName_length,
  767. const char *cacheDir, size_t cacheDir_length,
  768. const char *text, size_t text_length)
  769. {
  770. hidl_vec<uint8_t> _text;
  771. _text.setToExternal(reinterpret_cast<uint8_t *>(const_cast<char *>(text)), text_length);
  772. uint64_t scriptc = GetIContextHandle(context)->scriptCCreate(hidl_string(resName), hidl_string(cacheDir), _text);
  773. return (RsScript) scriptc;
  774. }
  775. RsScript RsHidlAdaptation::ScriptIntrinsicCreate (RsContext context, uint32_t id, RsElement element)
  776. {
  777. uint64_t _element = (uint64_t)(uintptr_t)element;
  778. uint64_t intrinsic = GetIContextHandle(context)->scriptIntrinsicCreate((ScriptIntrinsicID)id, _element);
  779. return (RsScript) intrinsic;
  780. }
  781. RsScriptKernelID RsHidlAdaptation::ScriptKernelIDCreate (RsContext context, RsScript script, int slot, int sig)
  782. {
  783. uint64_t _script = (uint64_t)(uintptr_t)script;
  784. uint64_t kernelID = GetIContextHandle(context)->scriptKernelIDCreate(_script, slot, sig);
  785. return (RsScriptKernelID) kernelID;
  786. }
  787. RsScriptInvokeID RsHidlAdaptation::ScriptInvokeIDCreate (RsContext context, RsScript script, int slot)
  788. {
  789. uint64_t _script = (uint64_t)(uintptr_t)script;
  790. uint64_t invokeID = GetIContextHandle(context)->scriptInvokeIDCreate(_script, slot);
  791. return (RsScriptInvokeID) invokeID;
  792. }
  793. RsScriptFieldID RsHidlAdaptation::ScriptFieldIDCreate (RsContext context, RsScript script, int slot)
  794. {
  795. uint64_t _script = (uint64_t)(uintptr_t)script;
  796. uint64_t fieldID = GetIContextHandle(context)->scriptFieldIDCreate(_script, slot);
  797. return (RsScriptFieldID) fieldID;
  798. }
  799. RsScriptGroup RsHidlAdaptation::ScriptGroupCreate (RsContext context, RsScriptKernelID * kernels, size_t kernelsSize,
  800. RsScriptKernelID * src, size_t srcSize,
  801. RsScriptKernelID * dstK, size_t dstKSize,
  802. RsScriptFieldID * dstF, size_t dstFSize,
  803. const RsType * type, size_t typeSize)
  804. {
  805. std::vector<ScriptKernelID> _kernels(kernelsSize / sizeof(RsScriptKernelID));
  806. std::vector<ScriptKernelID> _src(srcSize / sizeof(RsScriptKernelID));
  807. std::vector<ScriptKernelID> _dstK(dstKSize / sizeof(RsScriptKernelID));
  808. std::vector<ScriptFieldID> _dstF(dstFSize / sizeof(RsScriptFieldID));
  809. std::vector<Type> _type(typeSize / sizeof(RsType));
  810. for (size_t i = 0; i < _kernels.size(); i++) {
  811. _kernels[i] = (ScriptKernelID)(uintptr_t)kernels[i];
  812. }
  813. for (size_t i = 0; i < _src.size(); i++) {
  814. _src[i] = (ScriptKernelID)(uintptr_t)src[i];
  815. }
  816. for (size_t i = 0; i < _dstK.size(); i++) {
  817. _dstK[i] = (ScriptKernelID)(uintptr_t)dstK[i];
  818. }
  819. for (size_t i = 0; i < _dstF.size(); i++) {
  820. _dstF[i] = (ScriptFieldID)(uintptr_t)dstF[i];
  821. }
  822. for (size_t i = 0; i < _type.size(); i++) {
  823. _type[i] = (Type)(uintptr_t)type[i];
  824. }
  825. uint64_t scriptGroup = GetIContextHandle(context)->scriptGroupCreate(_kernels, _src, _dstK, _dstF, _type);
  826. return (RsScriptGroup) scriptGroup;
  827. }
  828. RsScriptGroup2 RsHidlAdaptation::ScriptGroup2Create(RsContext context, const char* name, size_t nameLength,
  829. const char* cacheDir, size_t cacheDirLength,
  830. RsClosure* closures, size_t numClosures)
  831. {
  832. std::vector<Closure> _closures(numClosures);
  833. for (size_t i = 0; i < numClosures; i++) {
  834. _closures[i] = (Closure)(uintptr_t)closures[i];
  835. }
  836. uint64_t scriptGroup2 = GetIContextHandle(context)->scriptGroup2Create(hidl_string(name), hidl_string(cacheDir), _closures);
  837. return (RsScriptGroup2) scriptGroup2;
  838. }
  839. void RsHidlAdaptation::ScriptGroupSetOutput (RsContext context, RsScriptGroup sg, RsScriptKernelID kid, RsAllocation alloc)
  840. {
  841. uint64_t _sg = (uint64_t)(uintptr_t)sg;
  842. uint64_t _kid = (uint64_t)(uintptr_t)kid;
  843. uint64_t _alloc = (uint64_t)(uintptr_t)alloc;
  844. GetIContextHandle(context)->scriptGroupSetOutput(_sg, _kid, _alloc);
  845. }
  846. void RsHidlAdaptation::ScriptGroupSetInput (RsContext context, RsScriptGroup sg, RsScriptKernelID kid, RsAllocation alloc)
  847. {
  848. uint64_t _sg = (uint64_t)(uintptr_t)sg;
  849. uint64_t _kid = (uint64_t)(uintptr_t)kid;
  850. uint64_t _alloc = (uint64_t)(uintptr_t)alloc;
  851. GetIContextHandle(context)->scriptGroupSetInput(_sg, _kid, _alloc);
  852. }
  853. void RsHidlAdaptation::ScriptGroupExecute (RsContext context, RsScriptGroup sg)
  854. {
  855. uint64_t _sg = (uint64_t)(uintptr_t)sg;
  856. GetIContextHandle(context)->scriptGroupExecute(_sg);
  857. }
  858. void RsHidlAdaptation::AllocationIoSend (RsContext context, RsAllocation allocation)
  859. {
  860. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  861. GetIContextHandle(context)->allocationIoSend(_allocation);
  862. }
  863. int64_t RsHidlAdaptation::AllocationIoReceive (RsContext context, RsAllocation allocation)
  864. {
  865. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  866. GetIContextHandle(context)->allocationIoReceive(_allocation);
  867. // Fix me.
  868. return 0;
  869. }
  870. void * RsHidlAdaptation::AllocationGetPointer (RsContext context, RsAllocation allocation,
  871. uint32_t lod, RsAllocationCubemapFace face,
  872. uint32_t z, uint32_t array, size_t *stride, size_t strideLen)
  873. {
  874. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  875. void* ptr;
  876. GetIContextHandle(context)->allocationGetPointer(_allocation, lod,
  877. (AllocationCubemapFace)face, z,
  878. [&ptr, stride] (void* retPtr, uint64_t retStride) {
  879. ptr = retPtr;
  880. if (retStride > 0) {
  881. *stride = retStride;
  882. }
  883. });
  884. return ptr;
  885. }
  886. void RsHidlAdaptation::AllocationSetupBufferQueue (RsContext context, RsAllocation allocation, uint32_t numAlloc)
  887. {
  888. uint64_t _allocation = (uint64_t)(uintptr_t)allocation;
  889. GetIContextHandle(context)->allocationSetupBufferQueue(_allocation, numAlloc);
  890. }
  891. void RsHidlAdaptation::AllocationShareBufferQueue(RsContext context, RsAllocation valloc1, RsAllocation valloc2)
  892. {
  893. uint64_t _valloc1 = (uint64_t)(uintptr_t)valloc1;
  894. uint64_t _valloc2 = (uint64_t)(uintptr_t)valloc2;
  895. GetIContextHandle(context)->allocationShareBufferQueue(_valloc1, _valloc2);
  896. }
  897. RsAllocation RsHidlAdaptation::AllocationAdapterCreate (RsContext context, RsType vtype, RsAllocation baseAlloc)
  898. {
  899. uint64_t _vtype = (uint64_t)(uintptr_t)vtype;
  900. uint64_t _baseAlloc = (uint64_t)(uintptr_t)baseAlloc;
  901. uint64_t allocationAdapter = GetIContextHandle(context)->allocationAdapterCreate(_vtype, _baseAlloc);
  902. return (RsAllocation) allocationAdapter;
  903. }
  904. void RsHidlAdaptation::AllocationAdapterOffset (RsContext context, RsAllocation alloc, const uint32_t * offsets, size_t offsets_length)
  905. {
  906. uint64_t _alloc = (uint64_t)(uintptr_t)alloc;
  907. hidl_vec<uint32_t> _offsets;
  908. _offsets.setToExternal(const_cast<uint32_t *>(offsets), offsets_length / sizeof(uint32_t));
  909. GetIContextHandle(context)->allocationAdapterOffset(_alloc, _offsets);
  910. }