1 #include "Context.h" 2 #include "Device.h" 3 4 namespace android { 5 namespace hardware { 6 namespace renderscript { 7 namespace V1_0 { 8 namespace implementation { 9 10 11 Context::Context(uint32_t sdkVersion, ContextType ct, int32_t flags) { 12 RsDevice _dev = nullptr; 13 uint32_t _version = 0; 14 uint32_t _sdkVersion = sdkVersion; 15 RsContextType _ct = static_cast<RsContextType>(ct); 16 int32_t _flags = flags; 17 const char* driverName = nullptr; 18 19 #ifdef OVERRIDE_RS_DRIVER 20 #define XSTR(S) #S 21 #define STR(S) XSTR(S) 22 #define OVERRIDE_RS_DRIVER_STRING STR(OVERRIDE_RS_DRIVER) 23 static std::string driverString(OVERRIDE_RS_DRIVER_STRING); 24 driverName = driverString.c_str(); 25 #undef XSTR 26 #undef STR 27 #endif // OVERRIDE_RS_DRIVER 28 mContext = Device::getHal().ContextCreateVendor(_dev, _version, _sdkVersion, 29 _ct, _flags, driverName); 30 } 31 32 33 // Helper functions 34 template<typename ReturnType> 35 static ReturnType hidl_to_rs(OpaqueHandle src) { 36 return reinterpret_cast<ReturnType>(static_cast<uintptr_t>(src)); 37 } 38 39 template<typename ReturnType, typename SourceType> 40 static ReturnType hidl_to_rs(SourceType* src) { 41 return reinterpret_cast<ReturnType>(src); 42 } 43 44 template<typename RsType, typename HidlType, typename Operation> 45 static std::vector<RsType> hidl_to_rs(const hidl_vec<HidlType>& src, Operation operation) { 46 std::vector<RsType> dst(src.size()); 47 std::transform(src.begin(), src.end(), dst.begin(), operation); 48 return dst; 49 } 50 51 template<typename ReturnType, typename SourceType> 52 static ReturnType rs_to_hidl(SourceType* src) { 53 return static_cast<ReturnType>(reinterpret_cast<uintptr_t>(src)); 54 } 55 56 template<typename HidlType, typename RsType, typename Operation> 57 static hidl_vec<HidlType> rs_to_hidl(const std::vector<RsType>& src, Operation operation) { 58 std::vector<HidlType> dst(src.size()); 59 std::transform(src.begin(), src.end(), dst.begin(), operation); 60 return dst; 61 } 62 63 64 // Methods from ::android::hardware::renderscript::V1_0::IContext follow. 65 66 Return<Allocation> Context::allocationAdapterCreate(Type type, Allocation baseAlloc) { 67 RsType _type = hidl_to_rs<RsType>(type); 68 RsAllocation _baseAlloc = hidl_to_rs<RsAllocation>(baseAlloc); 69 RsAllocation _subAlloc = Device::getHal().AllocationAdapterCreate(mContext, _type, _baseAlloc); 70 return rs_to_hidl<Allocation>(_subAlloc); 71 } 72 73 Return<void> Context::allocationAdapterOffset(Allocation alloc, const hidl_vec<uint32_t>& offsets) { 74 RsAllocation _alloc = hidl_to_rs<RsAllocation>(alloc); 75 const hidl_vec<uint32_t>& _offsets = offsets; 76 Device::getHal().AllocationAdapterOffset(mContext, _alloc, _offsets.data(), _offsets.size() * sizeof(uint32_t)); 77 return Void(); 78 } 79 80 Return<Type> Context::allocationGetType(Allocation allocation) { 81 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 82 const void* _type = Device::getHal().AllocationGetType(mContext, _allocation); 83 return rs_to_hidl<Type>(_type); 84 } 85 86 Return<Allocation> Context::allocationCreateTyped(Type type, AllocationMipmapControl amips, int32_t usage, Ptr ptr) { 87 RsType _type = hidl_to_rs<RsType>(type); 88 RsAllocationMipmapControl _amips = static_cast<RsAllocationMipmapControl>(amips); 89 uint32_t _usage = usage; 90 uintptr_t _ptr = hidl_to_rs<uintptr_t>(ptr); 91 RsAllocation _allocation = Device::getHal().AllocationCreateTyped(mContext, _type, _amips, _usage, _ptr); 92 return rs_to_hidl<Allocation>(_allocation); 93 } 94 95 Return<Allocation> Context::allocationCreateFromBitmap(Type type, AllocationMipmapControl amips, const hidl_vec<uint8_t>& bitmap, int32_t usage) { 96 RsType _type = hidl_to_rs<RsType>(type); 97 RsAllocationMipmapControl _amips = static_cast<RsAllocationMipmapControl>(amips); 98 const hidl_vec<uint8_t>& _bitmap = bitmap; 99 uint32_t _usage = usage; 100 RsAllocation _allocation = Device::getHal().AllocationCreateFromBitmap(mContext, _type, _amips, _bitmap.data(), _bitmap.size(), _usage); 101 return rs_to_hidl<Allocation>(_allocation); 102 } 103 104 Return<Allocation> Context::allocationCubeCreateFromBitmap(Type type, AllocationMipmapControl amips, const hidl_vec<uint8_t>& bitmap, int32_t usage) { 105 RsType _type = hidl_to_rs<RsType>(type); 106 RsAllocationMipmapControl _amips = static_cast<RsAllocationMipmapControl>(amips); 107 const hidl_vec<uint8_t>& _bitmap = bitmap; 108 uint32_t _usage = usage; 109 RsAllocation _allocation = Device::getHal().AllocationCubeCreateFromBitmap(mContext, _type, _amips, _bitmap.data(), _bitmap.size(), _usage); 110 return rs_to_hidl<Allocation>(_allocation); 111 } 112 113 Return<NativeWindow> Context::allocationGetNativeWindow(Allocation allocation) { 114 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 115 RsNativeWindow _nativeWindow = Device::getHal().AllocationGetSurface(mContext, _allocation); 116 return rs_to_hidl<NativeWindow>(_nativeWindow); 117 } 118 119 Return<void> Context::allocationSetNativeWindow(Allocation allocation, NativeWindow nativewindow) { 120 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 121 RsNativeWindow _nativewindow = hidl_to_rs<RsNativeWindow>(nativewindow); 122 Device::getHal().AllocationSetSurface(mContext, _allocation, _nativewindow); 123 return Void(); 124 } 125 126 Return<void> Context::allocationSetupBufferQueue(Allocation alloc, uint32_t numBuffer) { 127 RsAllocation _alloc = hidl_to_rs<RsAllocation>(alloc); 128 uint32_t _numBuffer = numBuffer; 129 Device::getHal().AllocationSetupBufferQueue(mContext, _alloc, _numBuffer); 130 return Void(); 131 } 132 133 Return<void> Context::allocationShareBufferQueue(Allocation baseAlloc, Allocation subAlloc) { 134 RsAllocation _baseAlloc = hidl_to_rs<RsAllocation>(baseAlloc); 135 RsAllocation _subAlloc = hidl_to_rs<RsAllocation>(subAlloc); 136 Device::getHal().AllocationShareBufferQueue(mContext, _baseAlloc, _subAlloc); 137 return Void(); 138 } 139 140 Return<void> Context::allocationCopyToBitmap(Allocation allocation, Ptr data, Size sizeBytes) { 141 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 142 void* _data = hidl_to_rs<void*>(data); 143 size_t _sizeBytes = static_cast<size_t>(sizeBytes); 144 Device::getHal().AllocationCopyToBitmap(mContext, _allocation, _data, _sizeBytes); 145 return Void(); 146 } 147 148 Return<void> Context::allocation1DWrite(Allocation allocation, uint32_t offset, uint32_t lod, uint32_t count, const hidl_vec<uint8_t>& data) { 149 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 150 uint32_t _offset = offset; 151 uint32_t _lod = lod; 152 uint32_t _count = count; 153 const void* _dataPtr = hidl_to_rs<const void*>(data.data()); 154 size_t _sizeBytes = data.size(); 155 Device::getHal().Allocation1DData(mContext, _allocation, _offset, _lod, _count, _dataPtr, _sizeBytes); 156 return Void(); 157 } 158 159 Return<void> Context::allocationElementWrite(Allocation allocation, uint32_t x, uint32_t y, uint32_t z, uint32_t lod, const hidl_vec<uint8_t>& data, Size compIdx) { 160 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 161 uint32_t _x = x; 162 uint32_t _y = y; 163 uint32_t _z = z; 164 uint32_t _lod = lod; 165 const void* _dataPtr = hidl_to_rs<const void*>(data.data()); 166 size_t _sizeBytes = data.size(); 167 size_t _compIdx = static_cast<size_t>(compIdx); 168 Device::getHal().AllocationElementData(mContext, _allocation, _x, _y, _z, _lod, _dataPtr, _sizeBytes, _compIdx); 169 return Void(); 170 } 171 172 Return<void> Context::allocation2DWrite(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t lod, AllocationCubemapFace face, uint32_t w, uint32_t h, const hidl_vec<uint8_t>& data, Size stride) { 173 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 174 uint32_t _xoff = xoff; 175 uint32_t _yoff = yoff; 176 uint32_t _lod = lod; 177 RsAllocationCubemapFace _face = static_cast<RsAllocationCubemapFace>(face); 178 uint32_t _w = w; 179 uint32_t _h = h; 180 const void* _dataPtr = hidl_to_rs<const void*>(data.data()); 181 size_t _sizeBytes = data.size(); 182 size_t _stride = static_cast<size_t>(stride); 183 Device::getHal().Allocation2DData(mContext, _allocation, _xoff, _yoff, _lod, _face, _w, _h, _dataPtr, _sizeBytes, _stride); 184 return Void(); 185 } 186 187 Return<void> Context::allocation3DWrite(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, uint32_t w, uint32_t h, uint32_t d, const hidl_vec<uint8_t>& data, Size stride) { 188 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 189 uint32_t _xoff = xoff; 190 uint32_t _yoff = yoff; 191 uint32_t _zoff = zoff; 192 uint32_t _lod = lod; 193 uint32_t _w = w; 194 uint32_t _h = h; 195 uint32_t _d = d; 196 const void* _dataPtr = hidl_to_rs<const void*>(data.data()); 197 size_t _sizeBytes = data.size(); 198 size_t _stride = static_cast<size_t>(stride); 199 Device::getHal().Allocation3DData(mContext, _allocation, _xoff, _yoff, _zoff, _lod, _w, _h, _d, _dataPtr, _sizeBytes, _stride); 200 return Void(); 201 } 202 203 Return<void> Context::allocationGenerateMipmaps(Allocation allocation) { 204 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 205 Device::getHal().AllocationGenerateMipmaps(mContext, _allocation); 206 return Void(); 207 } 208 209 Return<void> Context::allocationRead(Allocation allocation, Ptr data, Size sizeBytes) { 210 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 211 void* _data = hidl_to_rs<void*>(data); 212 size_t _sizeBytes = static_cast<size_t>(sizeBytes); 213 Device::getHal().AllocationRead(mContext, _allocation, _data, _sizeBytes); 214 return Void(); 215 } 216 217 Return<void> Context::allocation1DRead(Allocation allocation, uint32_t xoff, uint32_t lod, uint32_t count, Ptr data, Size sizeBytes) { 218 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 219 uint32_t _xoff = xoff; 220 uint32_t _lod = lod; 221 uint32_t _count = count; 222 void* _data = hidl_to_rs<void*>(data); 223 size_t _sizeBytes = static_cast<size_t>(sizeBytes); 224 Device::getHal().Allocation1DRead(mContext, _allocation, _xoff, _lod, _count, _data, _sizeBytes); 225 return Void(); 226 } 227 228 Return<void> Context::allocationElementRead(Allocation allocation, uint32_t x, uint32_t y, uint32_t z, uint32_t lod, Ptr data, Size sizeBytes, Size compIdx) { 229 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 230 uint32_t _x = x; 231 uint32_t _y = y; 232 uint32_t _z = z; 233 uint32_t _lod = lod; 234 void* _data = hidl_to_rs<void*>(data); 235 size_t _sizeBytes = static_cast<size_t>(sizeBytes); 236 size_t _compIdx = static_cast<size_t>(compIdx); 237 Device::getHal().AllocationElementRead(mContext, _allocation, _x, _y, _z, _lod, _data, _sizeBytes, _compIdx); 238 return Void(); 239 } 240 241 Return<void> Context::allocation2DRead(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t lod, AllocationCubemapFace face, uint32_t w, uint32_t h, Ptr data, Size sizeBytes, Size stride) { 242 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 243 uint32_t _xoff = xoff; 244 uint32_t _yoff = yoff; 245 uint32_t _lod = lod; 246 RsAllocationCubemapFace _face = static_cast<RsAllocationCubemapFace>(face); 247 uint32_t _w = w; 248 uint32_t _h = h; 249 void* _data = hidl_to_rs<void*>(data); 250 size_t _sizeBytes = static_cast<size_t>(sizeBytes); 251 size_t _stride = static_cast<size_t>(stride); 252 Device::getHal().Allocation2DRead(mContext, _allocation, _xoff, _yoff, _lod, _face, _w, _h, _data, _sizeBytes, _stride); 253 return Void(); 254 } 255 256 Return<void> Context::allocation3DRead(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, uint32_t w, uint32_t h, uint32_t d, Ptr data, Size sizeBytes, Size stride) { 257 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 258 uint32_t _xoff = xoff; 259 uint32_t _yoff = yoff; 260 uint32_t _zoff = zoff; 261 uint32_t _lod = lod; 262 uint32_t _w = w; 263 uint32_t _h = h; 264 uint32_t _d = d; 265 void* _dataPtr = hidl_to_rs<void*>(data); 266 size_t _sizeBytes = static_cast<size_t>(sizeBytes); 267 size_t _stride = static_cast<size_t>(stride); 268 Device::getHal().Allocation3DRead(mContext, _allocation, _xoff, _yoff, _zoff, _lod, _w, _h, _d, _dataPtr, _sizeBytes, _stride); 269 return Void(); 270 } 271 272 Return<void> Context::allocationSyncAll(Allocation allocation, AllocationUsageType usageType) { 273 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 274 RsAllocationUsageType _usageType = static_cast<RsAllocationUsageType>(usageType); 275 Device::getHal().AllocationSyncAll(mContext, _allocation, _usageType); 276 return Void(); 277 } 278 279 Return<void> Context::allocationResize1D(Allocation allocation, uint32_t dimX) { 280 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 281 uint32_t _dimX = dimX; 282 Device::getHal().AllocationResize1D(mContext, _allocation, _dimX); 283 return Void(); 284 } 285 286 Return<void> Context::allocationCopy2DRange(Allocation dstAlloc, uint32_t dstXoff, uint32_t dstYoff, uint32_t dstMip, AllocationCubemapFace dstFace, uint32_t width, uint32_t height, Allocation srcAlloc, uint32_t srcXoff, uint32_t srcYoff, uint32_t srcMip, AllocationCubemapFace srcFace) { 287 RsAllocation _dstAlloc = hidl_to_rs<RsAllocation>(dstAlloc); 288 uint32_t _dstXoff = dstXoff; 289 uint32_t _dstYoff = dstYoff; 290 uint32_t _dstMip = dstMip; 291 RsAllocationCubemapFace _dstFace = static_cast<RsAllocationCubemapFace>(dstFace); 292 uint32_t _width = width; 293 uint32_t _height = height; 294 RsAllocation _srcAlloc = hidl_to_rs<RsAllocation>(srcAlloc); 295 uint32_t _srcXoff = srcXoff; 296 uint32_t _srcYoff = srcYoff; 297 uint32_t _srcMip = srcMip; 298 RsAllocationCubemapFace _srcFace = static_cast<RsAllocationCubemapFace>(srcFace); 299 Device::getHal().AllocationCopy2DRange(mContext, _dstAlloc, _dstXoff, _dstYoff, _dstMip, _dstFace, _width, _height, _srcAlloc, _srcXoff, _srcYoff, _srcMip, _srcFace); 300 return Void(); 301 } 302 303 Return<void> Context::allocationCopy3DRange(Allocation dstAlloc, uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, uint32_t dstMip, uint32_t width, uint32_t height, uint32_t depth, Allocation srcAlloc, uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, uint32_t srcMip) { 304 RsAllocation _dstAlloc = hidl_to_rs<RsAllocation>(dstAlloc); 305 uint32_t _dstXoff = dstXoff; 306 uint32_t _dstYoff = dstYoff; 307 uint32_t _dstZoff = dstZoff; 308 uint32_t _dstMip = dstMip; 309 uint32_t _width = width; 310 uint32_t _height = height; 311 uint32_t _depth = depth; 312 RsAllocation _srcAlloc = hidl_to_rs<RsAllocation>(srcAlloc); 313 uint32_t _srcXoff = srcXoff; 314 uint32_t _srcYoff = srcYoff; 315 uint32_t _srcZoff = srcZoff; 316 uint32_t _srcMip = srcMip; 317 Device::getHal().AllocationCopy3DRange(mContext, _dstAlloc, _dstXoff, _dstYoff, _dstZoff, _dstMip, _width, _height, _depth, _srcAlloc, _srcXoff, _srcYoff, _srcZoff, _srcMip); 318 return Void(); 319 } 320 321 Return<void> Context::allocationIoSend(Allocation allocation) { 322 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 323 Device::getHal().AllocationIoSend(mContext, _allocation); 324 return Void(); 325 } 326 327 Return<void> Context::allocationIoReceive(Allocation allocation) { 328 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 329 Device::getHal().AllocationIoReceive(mContext, _allocation); 330 return Void(); 331 } 332 333 Return<void> Context::allocationGetPointer(Allocation allocation, uint32_t lod, AllocationCubemapFace face, uint32_t z, allocationGetPointer_cb _hidl_cb) { 334 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 335 uint32_t _lod = lod; 336 RsAllocationCubemapFace _face = static_cast<RsAllocationCubemapFace>(face); 337 uint32_t _z = z; 338 uint32_t _array = 0; 339 size_t _stride = 0; 340 void* _dataPtr = Device::getHal().AllocationGetPointer(mContext, _allocation, _lod, _face, _z, _array, &_stride, sizeof(size_t)); 341 Ptr dataPtr = reinterpret_cast<Ptr>(_dataPtr); 342 Size stride = static_cast<Size>(_stride); 343 _hidl_cb(dataPtr, stride); 344 return Void(); 345 } 346 347 Return<void> Context::elementGetNativeMetadata(Element element, elementGetNativeMetadata_cb _hidl_cb) { 348 RsElement _element = hidl_to_rs<RsElement>(element); 349 std::vector<uint32_t> _elemData(5); 350 Device::getHal().ElementGetNativeData(mContext, _element, _elemData.data(), _elemData.size()); 351 hidl_vec<uint32_t> elemData = _elemData; 352 _hidl_cb(elemData); 353 return Void(); 354 } 355 356 Return<void> Context::elementGetSubElements(Element element, Size numSubElem, elementGetSubElements_cb _hidl_cb) { 357 RsElement _element = hidl_to_rs<RsElement>(element); 358 uint32_t _numSubElem = static_cast<uint32_t>(numSubElem); 359 std::vector<uintptr_t> _ids(_numSubElem); 360 std::vector<const char*> _names(_numSubElem); 361 std::vector<size_t> _arraySizes(_numSubElem); 362 Device::getHal().ElementGetSubElements(mContext, _element, _ids.data(), _names.data(), _arraySizes.data(), _numSubElem); 363 hidl_vec<Element> ids = rs_to_hidl<Element>(_ids, [](uintptr_t val) { return static_cast<Element>(val); }); 364 hidl_vec<hidl_string> names = rs_to_hidl<hidl_string>(_names, [](const char* val) { return val; }); 365 hidl_vec<Size> arraySizes = rs_to_hidl<Size>(_arraySizes, [](size_t val) { return static_cast<Size>(val); }); 366 _hidl_cb(ids, names, arraySizes); 367 return Void(); 368 } 369 370 Return<Element> Context::elementCreate(DataType dt, DataKind dk, bool norm, uint32_t size) { 371 RsDataType _dt = static_cast<RsDataType>(dt); 372 RsDataKind _dk = static_cast<RsDataKind>(dk); 373 bool _norm = norm; 374 uint32_t _size = size; 375 RsElement _element = Device::getHal().ElementCreate(mContext, _dt, _dk, _norm, _size); 376 return rs_to_hidl<Element>(_element); 377 } 378 379 Return<Element> Context::elementComplexCreate(const hidl_vec<Element>& eins, const hidl_vec<hidl_string>& names, const hidl_vec<Size>& arraySizes) { 380 std::vector<RsElement> _eins = hidl_to_rs<RsElement>(eins, [](Element val) { return hidl_to_rs<RsElement>(val); }); 381 std::vector<const char*> _namesPtr = hidl_to_rs<const char*>(names, [](const hidl_string& val) { return val.c_str(); }); 382 std::vector<size_t> _nameLengthsPtr = hidl_to_rs<size_t>(names, [](const hidl_string& val) { return val.size(); }); 383 std::vector<uint32_t> _arraySizes = hidl_to_rs<uint32_t>(arraySizes, [](Size val) { return static_cast<uint32_t>(val); }); 384 RsElement _element = Device::getHal().ElementCreate2(mContext, _eins.data(), _eins.size(), _namesPtr.data(), _namesPtr.size(), _nameLengthsPtr.data(), _arraySizes.data(), _arraySizes.size()); 385 return rs_to_hidl<Element>(_element); 386 } 387 388 Return<void> Context::typeGetNativeMetadata(Type type, typeGetNativeMetadata_cb _hidl_cb) { 389 RsType _type = hidl_to_rs<RsType>(type); 390 std::vector<uintptr_t> _metadata(6); 391 Device::getHal().TypeGetNativeData(mContext, _type, _metadata.data(), _metadata.size()); 392 hidl_vec<OpaqueHandle> metadata = rs_to_hidl<OpaqueHandle>(_metadata, [](uintptr_t val) { return static_cast<OpaqueHandle>(val); }); 393 _hidl_cb(metadata); 394 return Void(); 395 } 396 397 Return<Type> Context::typeCreate(Element element, uint32_t dimX, uint32_t dimY, uint32_t dimZ, bool mipmaps, bool faces, YuvFormat yuv) { 398 RsElement _element = hidl_to_rs<RsElement>(element); 399 uint32_t _dimX = dimX; 400 uint32_t _dimY = dimY; 401 uint32_t _dimZ = dimZ; 402 bool _mipmaps = mipmaps; 403 bool _faces = faces; 404 RsYuvFormat _yuv = static_cast<RsYuvFormat>(yuv); 405 RsType _type = Device::getHal().TypeCreate(mContext, _element, _dimX, _dimY, _dimZ, _mipmaps, _faces, _yuv); 406 return rs_to_hidl<Type>(_type); 407 } 408 409 Return<void> Context::contextDestroy() { 410 Device::getHal().ContextDestroy(mContext); 411 mContext = nullptr; 412 return Void(); 413 } 414 415 Return<void> Context::contextGetMessage(Ptr data, Size size, contextGetMessage_cb _hidl_cb) { 416 void* _data = hidl_to_rs<void*>(data); 417 size_t _size = static_cast<size_t>(size); 418 size_t _receiveLen = 0; 419 uint32_t _subID = 0; 420 RsMessageToClientType _messageType = Device::getHal().ContextGetMessage(mContext, _data, _size, &_receiveLen, sizeof(size_t), &_subID, sizeof(uint32_t)); 421 MessageToClientType messageType = static_cast<MessageToClientType>(_messageType); 422 Size receiveLen = static_cast<Size>(_receiveLen); 423 _hidl_cb(messageType, receiveLen); 424 return Void(); 425 } 426 427 Return<void> Context::contextPeekMessage(contextPeekMessage_cb _hidl_cb) { 428 size_t _receiveLen = 0; 429 uint32_t _subID = 0; 430 RsMessageToClientType _messageType = Device::getHal().ContextPeekMessage(mContext, &_receiveLen, sizeof(size_t), &_subID, sizeof(uint32_t)); 431 MessageToClientType messageType = static_cast<MessageToClientType>(_messageType); 432 Size receiveLen = static_cast<Size>(_receiveLen); 433 uint32_t subID = _subID; 434 _hidl_cb(messageType, receiveLen, subID); 435 return Void(); 436 } 437 438 Return<void> Context::contextSendMessage(uint32_t id, const hidl_vec<uint8_t>& data) { 439 uint32_t _id = id; 440 const uint8_t* _dataPtr = data.data(); 441 size_t _dataSize = data.size(); 442 Device::getHal().ContextSendMessage(mContext, _id, _dataPtr, _dataSize); 443 return Void(); 444 } 445 446 Return<void> Context::contextInitToClient() { 447 Device::getHal().ContextInitToClient(mContext); 448 return Void(); 449 } 450 451 Return<void> Context::contextDeinitToClient() { 452 Device::getHal().ContextDeinitToClient(mContext); 453 return Void(); 454 } 455 456 Return<void> Context::contextFinish() { 457 Device::getHal().ContextFinish(mContext); 458 return Void(); 459 } 460 461 Return<void> Context::contextLog() { 462 uint32_t _bits = 0; 463 Device::getHal().ContextDump(mContext, _bits); 464 return Void(); 465 } 466 467 Return<void> Context::contextSetPriority(ThreadPriorities priority) { 468 RsThreadPriorities _priority = static_cast<RsThreadPriorities>(priority); 469 Device::getHal().ContextSetPriority(mContext, _priority); 470 return Void(); 471 } 472 473 Return<void> Context::contextSetCacheDir(const hidl_string& cacheDir) { 474 Device::getHal().ContextSetCacheDir(mContext, cacheDir.c_str(), cacheDir.size()); 475 return Void(); 476 } 477 478 Return<void> Context::assignName(ObjectBase obj, const hidl_string& name) { 479 RsObjectBase _obj = hidl_to_rs<RsObjectBase>(obj); 480 const hidl_string& _name = name; 481 Device::getHal().AssignName(mContext, _obj, _name.c_str(), _name.size()); 482 return Void(); 483 } 484 485 Return<void> Context::getName(ObjectBase obj, getName_cb _hidl_cb) { 486 void* _obj = hidl_to_rs<void*>(obj); 487 const char* _name = nullptr; 488 Device::getHal().GetName(mContext, _obj, &_name); 489 hidl_string name = _name; 490 _hidl_cb(name); 491 return Void(); 492 } 493 494 Return<Closure> Context::closureCreate(ScriptKernelID kernelID, Allocation returnValue, const hidl_vec<ScriptFieldID>& fieldIDS, const hidl_vec<int64_t>& values, const hidl_vec<int32_t>& sizes, const hidl_vec<Closure>& depClosures, const hidl_vec<ScriptFieldID>& depFieldIDS) { 495 RsScriptKernelID _kernelID = hidl_to_rs<RsScriptKernelID>(kernelID); 496 RsAllocation _returnValue = hidl_to_rs<RsAllocation>(returnValue); 497 std::vector<RsScriptFieldID> _fieldIDS = hidl_to_rs<RsScriptFieldID>(fieldIDS, [](ScriptFieldID val) { return hidl_to_rs<RsScriptFieldID>(val); }); 498 int64_t* _valuesPtr = const_cast<int64_t*>(values.data()); 499 size_t _valuesLength = values.size(); 500 std::vector<int> _sizes = hidl_to_rs<int>(sizes, [](int32_t val) { return static_cast<int>(val); }); 501 std::vector<RsClosure> _depClosures = hidl_to_rs<RsClosure>(depClosures, [](Closure val) { return hidl_to_rs<RsClosure>(val); }); 502 std::vector<RsScriptFieldID> _depFieldIDS = hidl_to_rs<RsScriptFieldID>(depFieldIDS, [](ScriptFieldID val) { return hidl_to_rs<RsScriptFieldID>(val); }); 503 RsClosure _closure = Device::getHal().ClosureCreate(mContext, _kernelID, _returnValue, _fieldIDS.data(), _fieldIDS.size(), _valuesPtr, _valuesLength, _sizes.data(), _sizes.size(), _depClosures.data(), _depClosures.size(), _depFieldIDS.data(), _depFieldIDS.size()); 504 return rs_to_hidl<Closure>(_closure); 505 } 506 507 Return<Closure> Context::invokeClosureCreate(ScriptInvokeID invokeID, const hidl_vec<uint8_t>& params, const hidl_vec<ScriptFieldID>& fieldIDS, const hidl_vec<int64_t>& values, const hidl_vec<int32_t>& sizes) { 508 RsScriptInvokeID _invokeID = hidl_to_rs<RsScriptInvokeID>(invokeID); 509 const void* _paramsPtr = params.data(); 510 size_t _paramsSize = params.size(); 511 std::vector<RsScriptFieldID> _fieldIDS = hidl_to_rs<RsScriptFieldID>(fieldIDS, [](ScriptFieldID val) { return hidl_to_rs<RsScriptFieldID>(val); }); 512 const int64_t* _valuesPtr = values.data(); 513 size_t _valuesLength = values.size(); 514 std::vector<int> _sizes = hidl_to_rs<int>(sizes, [](int32_t val) { return static_cast<int>(val); }); 515 RsClosure _closure = Device::getHal().InvokeClosureCreate(mContext, _invokeID, _paramsPtr, _paramsSize, _fieldIDS.data(), _fieldIDS.size(), _valuesPtr, _valuesLength, _sizes.data(), _sizes.size()); 516 return rs_to_hidl<Closure>(_closure); 517 } 518 519 Return<void> Context::closureSetArg(Closure closure, uint32_t index, Ptr value, int32_t size) { 520 RsClosure _closure = hidl_to_rs<RsClosure>(closure); 521 uint32_t _index = index; 522 uintptr_t _value = hidl_to_rs<uintptr_t>(value); 523 int _size = static_cast<int>(size); 524 Device::getHal().ClosureSetArg(mContext, _closure, _index, _value, _size); 525 return Void(); 526 } 527 528 Return<void> Context::closureSetGlobal(Closure closure, ScriptFieldID fieldID, int64_t value, int32_t size) { 529 RsClosure _closure = hidl_to_rs<RsClosure>(closure); 530 RsScriptFieldID _fieldID = hidl_to_rs<RsScriptFieldID>(fieldID); 531 int64_t _value = value; 532 int _size = static_cast<int>(size); 533 Device::getHal().ClosureSetGlobal(mContext, _closure, _fieldID, _value, _size); 534 return Void(); 535 } 536 537 Return<ScriptKernelID> Context::scriptKernelIDCreate(Script script, int32_t slot, int32_t sig) { 538 RsScript _script = hidl_to_rs<RsScript>(script); 539 int _slot = static_cast<int>(slot); 540 int _sig = static_cast<int>(sig); 541 RsScriptKernelID _scriptKernelID = Device::getHal().ScriptKernelIDCreate(mContext, _script, _slot, _sig); 542 return rs_to_hidl<ScriptKernelID>(_scriptKernelID); 543 } 544 545 Return<ScriptInvokeID> Context::scriptInvokeIDCreate(Script script, int32_t slot) { 546 RsScript _script = hidl_to_rs<RsScript>(script); 547 int _slot = static_cast<int>(slot); 548 RsScriptInvokeID _scriptInvokeID = Device::getHal().ScriptInvokeIDCreate(mContext, _script, _slot); 549 return rs_to_hidl<ScriptInvokeID>(_scriptInvokeID); 550 } 551 552 Return<ScriptFieldID> Context::scriptFieldIDCreate(Script script, int32_t slot) { 553 RsScript _script = hidl_to_rs<RsScript>(script); 554 int _slot = static_cast<int>(slot); 555 RsScriptFieldID _scriptFieldID = Device::getHal().ScriptFieldIDCreate(mContext, _script, _slot); 556 return rs_to_hidl<ScriptFieldID>(_scriptFieldID); 557 } 558 559 Return<ScriptGroup> Context::scriptGroupCreate(const hidl_vec<ScriptKernelID>& kernels, const hidl_vec<ScriptKernelID>& srcK, const hidl_vec<ScriptKernelID>& dstK, const hidl_vec<ScriptFieldID>& dstF, const hidl_vec<Type>& types) { 560 std::vector<RsScriptKernelID> _kernels = hidl_to_rs<RsScriptKernelID>(kernels, [](ScriptFieldID val) { return hidl_to_rs<RsScriptKernelID>(val); }); 561 std::vector<RsScriptKernelID> _srcK = hidl_to_rs<RsScriptKernelID>(srcK, [](ScriptFieldID val) { return hidl_to_rs<RsScriptKernelID>(val); }); 562 std::vector<RsScriptKernelID> _dstK = hidl_to_rs<RsScriptKernelID>(dstK, [](ScriptFieldID val) { return hidl_to_rs<RsScriptKernelID>(val); }); 563 std::vector<RsScriptFieldID> _dstF = hidl_to_rs<RsScriptFieldID>(dstF, [](ScriptFieldID val) { return hidl_to_rs<RsScriptFieldID>(val); }); 564 std::vector<RsType> _types = hidl_to_rs<RsType>(types, [](Type val) { return hidl_to_rs<RsType>(val); }); 565 RsScriptGroup _scriptGroup = Device::getHal().ScriptGroupCreate(mContext, _kernels.data(), _kernels.size() * sizeof(RsScriptKernelID), _srcK.data(), _srcK.size() * sizeof(RsScriptKernelID), _dstK.data(), _dstK.size() * sizeof(RsScriptKernelID), _dstF.data(), _dstF.size() * sizeof(RsScriptFieldID), _types.data(), _types.size() * sizeof(RsType)); 566 return rs_to_hidl<ScriptGroup>(_scriptGroup); 567 } 568 569 Return<ScriptGroup2> Context::scriptGroup2Create(const hidl_string& name, const hidl_string& cacheDir, const hidl_vec<Closure>& closures) { 570 const hidl_string& _name = name; 571 const hidl_string& _cacheDir = cacheDir; 572 std::vector<RsClosure> _closures = hidl_to_rs<RsClosure>(closures, [](Closure val) { return hidl_to_rs<RsClosure>(val); }); 573 RsScriptGroup2 _scriptGroup2 = Device::getHal().ScriptGroup2Create(mContext, _name.c_str(), _name.size(), _cacheDir.c_str(), _cacheDir.size(), _closures.data(), _closures.size()); 574 return rs_to_hidl<ScriptGroup2>(_scriptGroup2); 575 } 576 577 Return<void> Context::scriptGroupSetOutput(ScriptGroup sg, ScriptKernelID kid, Allocation alloc) { 578 RsScriptGroup _sg = hidl_to_rs<RsScriptGroup>(sg); 579 RsScriptKernelID _kid = hidl_to_rs<RsScriptKernelID>(kid); 580 RsAllocation _alloc = hidl_to_rs<RsAllocation>(alloc); 581 Device::getHal().ScriptGroupSetOutput(mContext, _sg, _kid, _alloc); 582 return Void(); 583 } 584 585 Return<void> Context::scriptGroupSetInput(ScriptGroup sg, ScriptKernelID kid, Allocation alloc) { 586 RsScriptGroup _sg = hidl_to_rs<RsScriptGroup>(sg); 587 RsScriptKernelID _kid = hidl_to_rs<RsScriptKernelID>(kid); 588 RsAllocation _alloc = hidl_to_rs<RsAllocation>(alloc); 589 Device::getHal().ScriptGroupSetInput(mContext, _sg, _kid, _alloc); 590 return Void(); 591 } 592 593 Return<void> Context::scriptGroupExecute(ScriptGroup sg) { 594 RsScriptGroup _sg = hidl_to_rs<RsScriptGroup>(sg); 595 Device::getHal().ScriptGroupExecute(mContext, _sg); 596 return Void(); 597 } 598 599 Return<void> Context::objDestroy(ObjectBase obj) { 600 RsAsyncVoidPtr _obj = hidl_to_rs<RsAsyncVoidPtr>(obj); 601 Device::getHal().ObjDestroy(mContext, _obj); 602 return Void(); 603 } 604 605 Return<Sampler> Context::samplerCreate(SamplerValue magFilter, SamplerValue minFilter, SamplerValue wrapS, SamplerValue wrapT, SamplerValue wrapR, float aniso) { 606 RsSamplerValue _magFilter = static_cast<RsSamplerValue>(magFilter); 607 RsSamplerValue _minFilter = static_cast<RsSamplerValue>(minFilter); 608 RsSamplerValue _wrapS = static_cast<RsSamplerValue>(wrapS); 609 RsSamplerValue _wrapT = static_cast<RsSamplerValue>(wrapT); 610 RsSamplerValue _wrapR = static_cast<RsSamplerValue>(wrapR); 611 float _aniso = static_cast<float>(aniso); 612 RsSampler _sampler = Device::getHal().SamplerCreate(mContext, _magFilter, _minFilter, _wrapS, _wrapT, _wrapR, _aniso); 613 return rs_to_hidl<Sampler>(_sampler); 614 } 615 616 Return<void> Context::scriptBindAllocation(Script script, Allocation allocation, uint32_t slot) { 617 RsScript _script = hidl_to_rs<RsScript>(script); 618 RsAllocation _allocation = hidl_to_rs<RsAllocation>(allocation); 619 uint32_t _slot = slot; 620 Device::getHal().ScriptBindAllocation(mContext, _script, _allocation, _slot); 621 return Void(); 622 } 623 624 Return<void> Context::scriptSetTimeZone(Script script, const hidl_string& timeZone) { 625 RsScript _script = hidl_to_rs<RsScript>(script); 626 const hidl_string& _timeZone = timeZone; 627 Device::getHal().ScriptSetTimeZone(mContext, _script, _timeZone.c_str(), _timeZone.size()); 628 return Void(); 629 } 630 631 Return<void> Context::scriptInvoke(Script vs, uint32_t slot) { 632 RsScript _vs = hidl_to_rs<RsScript>(vs); 633 uint32_t _slot = slot; 634 Device::getHal().ScriptInvoke(mContext, _vs, _slot); 635 return Void(); 636 } 637 638 Return<void> Context::scriptInvokeV(Script vs, uint32_t slot, const hidl_vec<uint8_t>& data) { 639 RsScript _vs = hidl_to_rs<RsScript>(vs); 640 uint32_t _slot = slot; 641 const void* _dataPtr = hidl_to_rs<const void*>(data.data()); 642 size_t _len = data.size(); 643 Device::getHal().ScriptInvokeV(mContext, _vs, _slot, _dataPtr, _len); 644 return Void(); 645 } 646 647 Return<void> Context::scriptForEach(Script vs, uint32_t slot, const hidl_vec<Allocation>& vains, Allocation vaout, const hidl_vec<uint8_t>& params, Ptr sc) { 648 RsScript _vs = hidl_to_rs<RsScript>(vs); 649 uint32_t _slot = slot; 650 std::vector<RsAllocation> _vains = hidl_to_rs<RsAllocation>(vains, [](Allocation val) { return hidl_to_rs<RsAllocation>(val); }); 651 RsAllocation _vaout = hidl_to_rs<RsAllocation>(vaout); 652 const void* _paramsPtr = hidl_to_rs<const void*>(params.data()); 653 size_t _paramLen = params.size(); 654 const RsScriptCall* _sc = hidl_to_rs<const RsScriptCall*>(sc); 655 size_t _scLen = _sc != nullptr ? sizeof(ScriptCall) : 0; 656 Device::getHal().ScriptForEachMulti(mContext, _vs, _slot, _vains.data(), _vains.size(), _vaout, _paramsPtr, _paramLen, _sc, _scLen); 657 return Void(); 658 } 659 660 Return<void> Context::scriptReduce(Script vs, uint32_t slot, const hidl_vec<Allocation>& vains, Allocation vaout, Ptr sc) { 661 RsScript _vs = hidl_to_rs<RsScript>(vs); 662 uint32_t _slot = slot; 663 std::vector<RsAllocation> _vains = hidl_to_rs<RsAllocation>(vains, [](Allocation val) { return hidl_to_rs<RsAllocation>(val); }); 664 RsAllocation _vaout = hidl_to_rs<RsAllocation>(vaout); 665 const RsScriptCall* _sc = hidl_to_rs<const RsScriptCall*>(sc); 666 size_t _scLen = _sc != nullptr ? sizeof(ScriptCall) : 0; 667 Device::getHal().ScriptReduce(mContext, _vs, _slot, _vains.data(), _vains.size(), _vaout, _sc, _scLen); 668 return Void(); 669 } 670 671 Return<void> Context::scriptSetVarI(Script vs, uint32_t slot, int32_t value) { 672 RsScript _vs = hidl_to_rs<RsScript>(vs); 673 uint32_t _slot = slot; 674 int _value = static_cast<int>(value); 675 Device::getHal().ScriptSetVarI(mContext, _vs, _slot, _value); 676 return Void(); 677 } 678 679 Return<void> Context::scriptSetVarObj(Script vs, uint32_t slot, ObjectBase obj) { 680 RsScript _vs = hidl_to_rs<RsScript>(vs); 681 uint32_t _slot = slot; 682 RsObjectBase _obj = hidl_to_rs<RsObjectBase>(obj); 683 Device::getHal().ScriptSetVarObj(mContext, _vs, _slot, _obj); 684 return Void(); 685 } 686 687 Return<void> Context::scriptSetVarJ(Script vs, uint32_t slot, int64_t value) { 688 RsScript _vs = hidl_to_rs<RsScript>(vs); 689 uint32_t _slot = slot; 690 int64_t _value = static_cast<int64_t>(value); 691 Device::getHal().ScriptSetVarJ(mContext, _vs, _slot, _value); 692 return Void(); 693 } 694 695 Return<void> Context::scriptSetVarF(Script vs, uint32_t slot, float value) { 696 RsScript _vs = hidl_to_rs<RsScript>(vs); 697 uint32_t _slot = slot; 698 float _value = value; 699 Device::getHal().ScriptSetVarF(mContext, _vs, _slot, _value); 700 return Void(); 701 } 702 703 Return<void> Context::scriptSetVarD(Script vs, uint32_t slot, double value) { 704 RsScript _vs = hidl_to_rs<RsScript>(vs); 705 uint32_t _slot = slot; 706 double _value = value; 707 Device::getHal().ScriptSetVarD(mContext, _vs, _slot, _value); 708 return Void(); 709 } 710 711 Return<void> Context::scriptSetVarV(Script vs, uint32_t slot, const hidl_vec<uint8_t>& data) { 712 RsScript _vs = hidl_to_rs<RsScript>(vs); 713 uint32_t _slot = slot; 714 const void* _dataPtr = hidl_to_rs<const void*>(data.data()); 715 size_t _len = data.size(); 716 Device::getHal().ScriptSetVarV(mContext, _vs, _slot, _dataPtr, _len); 717 return Void(); 718 } 719 720 Return<void> Context::scriptGetVarV(Script vs, uint32_t slot, Size len, scriptGetVarV_cb _hidl_cb) { 721 RsScript _vs = hidl_to_rs<RsScript>(vs); 722 uint32_t _slot = slot; 723 size_t _len = static_cast<size_t>(len); 724 std::vector<uint8_t> _data(_len); 725 Device::getHal().ScriptGetVarV(mContext, _vs, _slot, _data.data(), _data.size()); 726 hidl_vec<uint8_t> data = _data; 727 _hidl_cb(data); 728 return Void(); 729 } 730 731 Return<void> Context::scriptSetVarVE(Script vs, uint32_t slot, const hidl_vec<uint8_t>& data, Element ve, const hidl_vec<uint32_t>& dims) { 732 RsScript _vs = hidl_to_rs<RsScript>(vs); 733 uint32_t _slot = slot; 734 const void* _dataPtr = hidl_to_rs<const void*>(data.data()); 735 size_t _len = data.size(); 736 RsElement _ve = hidl_to_rs<RsElement>(ve); 737 const uint32_t* _dimsPtr = dims.data(); 738 size_t _dimLen = dims.size() * sizeof(uint32_t); 739 Device::getHal().ScriptSetVarVE(mContext, _vs, _slot, _dataPtr, _len, _ve, _dimsPtr, _dimLen); 740 return Void(); 741 } 742 743 Return<Script> Context::scriptCCreate(const hidl_string& resName, const hidl_string& cacheDir, const hidl_vec<uint8_t>& text) { 744 const hidl_string& _resName = resName; 745 const hidl_string& _cacheDir = cacheDir; 746 const char* _textPtr = hidl_to_rs<const char*>(text.data()); 747 size_t _textSize = text.size(); 748 RsScript _script = Device::getHal().ScriptCCreate(mContext, _resName.c_str(), _resName.size(), _cacheDir.c_str(), _cacheDir.size(), _textPtr, _textSize); 749 return rs_to_hidl<Script>(_script); 750 } 751 752 Return<Script> Context::scriptIntrinsicCreate(ScriptIntrinsicID id, Element elem) { 753 RsScriptIntrinsicID _id = static_cast<RsScriptIntrinsicID>(id); 754 RsElement _elem = hidl_to_rs<RsElement>(elem); 755 RsScript _script = Device::getHal().ScriptIntrinsicCreate(mContext, _id, _elem); 756 return rs_to_hidl<Script>(_script); 757 } 758 759 760 // Methods from ::android::hidl::base::V1_0::IBase follow. 761 762 763 } // namespace implementation 764 } // namespace V1_0 765 } // namespace renderscript 766 } // namespace hardware 767 } // namespace android 768