Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 1 | #include "Context.h" |
| 2 | #include "Device.h" |
| 3 | |
| 4 | namespace android { |
| 5 | namespace hardware { |
| 6 | namespace renderscript { |
| 7 | namespace V1_0 { |
| 8 | namespace implementation { |
| 9 | |
| 10 | |
| 11 | static dispatchTable loadHAL(); |
| 12 | dispatchTable Device::mDispatchHal = loadHAL(); |
| 13 | |
| 14 | Device::Device() { |
| 15 | } |
| 16 | |
| 17 | dispatchTable& Device::getHal() { |
| 18 | return mDispatchHal; |
| 19 | } |
| 20 | |
| 21 | |
| 22 | // Methods from ::android::hardware::renderscript::V1_0::IDevice follow. |
| 23 | |
| 24 | Return<sp<IContext>> Device::contextCreate(uint32_t sdkVersion, ContextType ct, int32_t flags) { |
| 25 | return new Context(sdkVersion, ct, flags); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
| 30 | |
| 31 | IDevice* HIDL_FETCH_IDevice(const char* /* name */) { |
| 32 | return new Device(); |
| 33 | } |
| 34 | |
| 35 | // Helper function |
| 36 | dispatchTable loadHAL() { |
| 37 | |
| 38 | static_assert(sizeof(void*) <= sizeof(uint64_t), "RenderScript HIDL Error: sizeof(void*) > sizeof(uint64_t)"); |
| 39 | static_assert(sizeof(size_t) <= sizeof(uint64_t), "RenderScript HIDL Error: sizeof(size_t) > sizeof(uint64_t)"); |
| 40 | |
| 41 | const char* filename = "libRS_internal.so"; |
| 42 | void* handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL); |
| 43 | |
| 44 | dispatchTable dispatchHal = { |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 45 | .SetNativeLibDir = (SetNativeLibDirFnPtr) nullptr, |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 46 | |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 47 | .Allocation1DData = |
| 48 | (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"), |
| 49 | .Allocation1DElementData = (Allocation1DElementDataFnPtr) nullptr, |
| 50 | .Allocation1DRead = |
| 51 | (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"), |
| 52 | .Allocation2DData = |
| 53 | (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"), |
| 54 | .Allocation2DRead = |
| 55 | (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"), |
| 56 | .Allocation3DData = |
| 57 | (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"), |
| 58 | .Allocation3DRead = |
| 59 | (Allocation3DReadFnPtr)dlsym(handle, "rsAllocation3DRead"), |
| 60 | .AllocationAdapterCreate = (AllocationAdapterCreateFnPtr)dlsym( |
| 61 | handle, "rsAllocationAdapterCreate"), |
| 62 | .AllocationAdapterOffset = (AllocationAdapterOffsetFnPtr)dlsym( |
| 63 | handle, "rsAllocationAdapterOffset"), |
| 64 | .AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym( |
| 65 | handle, "rsAllocationCopy2DRange"), |
| 66 | .AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym( |
| 67 | handle, "rsAllocationCopy3DRange"), |
| 68 | .AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym( |
| 69 | handle, "rsAllocationCopyToBitmap"), |
| 70 | .AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym( |
| 71 | handle, "rsAllocationCreateFromBitmap"), |
| 72 | .AllocationCreateStrided = (AllocationCreateStridedFnPtr)dlsym( |
| 73 | handle, "rsAllocationCreateStrided"), |
| 74 | .AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym( |
| 75 | handle, "rsAllocationCreateTyped"), |
| 76 | .AllocationCubeCreateFromBitmap = |
| 77 | (AllocationCubeCreateFromBitmapFnPtr)dlsym( |
| 78 | handle, "rsAllocationCubeCreateFromBitmap"), |
| 79 | .AllocationElementData = (AllocationElementDataFnPtr)dlsym( |
| 80 | handle, "rsAllocationElementData"), |
| 81 | .AllocationElementRead = (AllocationElementReadFnPtr)dlsym( |
| 82 | handle, "rsAllocationElementRead"), |
| 83 | .AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym( |
| 84 | handle, "rsAllocationGenerateMipmaps"), |
| 85 | .AllocationGetPointer = |
| 86 | (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer"), |
| 87 | .AllocationGetSurface = |
| 88 | (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"), |
| 89 | .AllocationGetType = |
| 90 | (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"), |
| 91 | .AllocationIoReceive = |
| 92 | (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"), |
| 93 | .AllocationIoSend = |
| 94 | (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"), |
| 95 | .AllocationRead = |
| 96 | (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"), |
| 97 | .AllocationResize1D = |
| 98 | (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"), |
| 99 | .AllocationSetSurface = |
| 100 | (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"), |
| 101 | .AllocationSetupBufferQueue = (AllocationSetupBufferQueueFnPtr)dlsym( |
| 102 | handle, "rsAllocationSetupBufferQueue"), |
| 103 | .AllocationShareBufferQueue = (AllocationShareBufferQueueFnPtr)dlsym( |
| 104 | handle, "rsAllocationShareBufferQueue"), |
| 105 | .AllocationSyncAll = |
| 106 | (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 107 | .AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"), |
| 108 | .ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"), |
| 109 | .ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 110 | .ClosureSetGlobal = |
| 111 | (ClosureSetGlobalFnPtr)dlsym(handle, "rsClosureSetGlobal"), |
| 112 | .ContextCreateVendor = |
| 113 | (ContextCreateVendorFnPtr)dlsym(handle, "rsContextCreateVendor"), |
| 114 | .ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym( |
| 115 | handle, "rsContextDeinitToClient"), |
| 116 | .ContextDestroy = |
| 117 | (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 118 | .ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"), |
| 119 | .ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 120 | .ContextGetMessage = |
| 121 | (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"), |
| 122 | .ContextInitToClient = |
| 123 | (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"), |
| 124 | .ContextPeekMessage = |
| 125 | (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"), |
| 126 | .ContextSendMessage = |
| 127 | (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"), |
| 128 | .ContextSetCacheDir = |
| 129 | (ContextSetCacheDirFnPtr)dlsym(handle, "rsContextSetCacheDir"), |
| 130 | .ContextSetPriority = |
| 131 | (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"), |
| 132 | .DeviceCreate = (DeviceCreateFnPtr) nullptr, |
| 133 | .DeviceDestroy = (DeviceDestroyFnPtr) nullptr, |
| 134 | .DeviceSetConfig = (DeviceSetConfigFnPtr) nullptr, |
| 135 | .ElementCreate2 = |
| 136 | (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 137 | .ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 138 | .ElementGetNativeData = |
| 139 | (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"), |
| 140 | .ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym( |
| 141 | handle, "rsaElementGetSubElements"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 142 | .GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 143 | .InvokeClosureCreate = |
| 144 | (InvokeClosureCreateFnPtr)dlsym(handle, "rsInvokeClosureCreate"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 145 | .ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"), |
| 146 | .SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 147 | .ScriptBindAllocation = |
| 148 | (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 149 | .ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 150 | .ScriptFieldIDCreate = |
| 151 | (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"), |
| 152 | .ScriptForEach = (ScriptForEachFnPtr) nullptr, |
| 153 | .ScriptForEachMulti = |
| 154 | (ScriptForEachMultiFnPtr)dlsym(handle, "rsScriptForEachMulti"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 155 | .ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 156 | .ScriptGroup2Create = |
| 157 | (ScriptGroup2CreateFnPtr)dlsym(handle, "rsScriptGroup2Create"), |
| 158 | .ScriptGroupCreate = |
| 159 | (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"), |
| 160 | .ScriptGroupExecute = |
| 161 | (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"), |
| 162 | .ScriptGroupSetInput = |
| 163 | (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"), |
| 164 | .ScriptGroupSetOutput = |
| 165 | (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"), |
| 166 | .ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym( |
| 167 | handle, "rsScriptIntrinsicCreate"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 168 | .ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 169 | .ScriptInvokeIDCreate = |
| 170 | (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 171 | .ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 172 | .ScriptKernelIDCreate = |
| 173 | (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 174 | .ScriptReduce = (ScriptReduceFnPtr)dlsym(handle, "rsScriptReduce"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 175 | .ScriptSetTimeZone = |
| 176 | (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 177 | .ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"), |
| 178 | .ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"), |
| 179 | .ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"), |
| 180 | .ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 181 | .ScriptSetVarObj = |
| 182 | (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"), |
| 183 | .ScriptSetVarVE = |
| 184 | (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 185 | .ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"), |
| 186 | .TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"), |
Miao Wang | 41d8a44 | 2017-05-16 15:36:54 -0700 | [diff] [blame] | 187 | .TypeGetNativeData = |
| 188 | (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"), |
Miao Wang | 4772b60 | 2017-01-20 10:30:38 -0800 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | return dispatchHal; |
| 192 | } |
| 193 | |
| 194 | } // namespace implementation |
| 195 | } // namespace V1_0 |
| 196 | } // namespace renderscript |
| 197 | } // namespace hardware |
| 198 | } // namespace android |