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