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