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