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