Miao Wang | b78b2f4 | 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 = { |
| 45 | .SetNativeLibDir = (SetNativeLibDirFnPtr)nullptr, |
| 46 | |
| 47 | .Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"), |
| 48 | .Allocation1DElementData = (Allocation1DElementDataFnPtr)nullptr, |
| 49 | .Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"), |
| 50 | .Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"), |
| 51 | .Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"), |
| 52 | .Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"), |
| 53 | .Allocation3DRead = (Allocation3DReadFnPtr)dlsym(handle, "rsAllocation3DRead"), |
| 54 | .AllocationAdapterCreate = (AllocationAdapterCreateFnPtr)dlsym(handle, "rsAllocationAdapterCreate"), |
| 55 | .AllocationAdapterOffset = (AllocationAdapterOffsetFnPtr)dlsym(handle, "rsAllocationAdapterOffset"), |
| 56 | .AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange"), |
| 57 | .AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange"), |
| 58 | .AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap"), |
| 59 | .AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap"), |
| 60 | .AllocationCreateStrided = (AllocationCreateStridedFnPtr)dlsym(handle, "rsAllocationCreateStrided"), |
| 61 | .AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped"), |
| 62 | .AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap"), |
| 63 | .AllocationElementData = (AllocationElementDataFnPtr)dlsym(handle, "rsAllocationElementData"), |
| 64 | .AllocationElementRead = (AllocationElementReadFnPtr)dlsym(handle, "rsAllocationElementRead"), |
| 65 | .AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps"), |
| 66 | .AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer"), |
| 67 | .AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"), |
| 68 | .AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"), |
| 69 | .AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"), |
| 70 | .AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"), |
| 71 | .AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"), |
| 72 | .AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"), |
| 73 | .AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"), |
| 74 | .AllocationSetupBufferQueue = (AllocationSetupBufferQueueFnPtr)dlsym(handle, "rsAllocationSetupBufferQueue"), |
| 75 | .AllocationShareBufferQueue = (AllocationShareBufferQueueFnPtr)dlsym(handle, "rsAllocationShareBufferQueue"), |
| 76 | .AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"), |
| 77 | .AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"), |
| 78 | .ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"), |
| 79 | .ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"), |
| 80 | .ClosureSetGlobal = (ClosureSetGlobalFnPtr)dlsym(handle, "rsClosureSetGlobal"), |
| 81 | .ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate"), |
| 82 | .ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient"), |
| 83 | .ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"), |
| 84 | .ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"), |
| 85 | .ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"), |
| 86 | .ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"), |
| 87 | .ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"), |
| 88 | .ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"), |
| 89 | .ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"), |
| 90 | .ContextSetCacheDir = (ContextSetCacheDirFnPtr)dlsym(handle, "rsContextSetCacheDir"), |
| 91 | .ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"), |
| 92 | .DeviceCreate = (DeviceCreateFnPtr)nullptr, |
| 93 | .DeviceDestroy = (DeviceDestroyFnPtr)nullptr, |
| 94 | .DeviceSetConfig = (DeviceSetConfigFnPtr)nullptr, |
| 95 | .ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"), |
| 96 | .ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"), |
| 97 | .ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"), |
| 98 | .ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements"), |
| 99 | .GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName"), |
| 100 | .InvokeClosureCreate = (InvokeClosureCreateFnPtr)dlsym(handle, "rsInvokeClosureCreate"), |
| 101 | .ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"), |
| 102 | .SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"), |
| 103 | .ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"), |
| 104 | .ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"), |
| 105 | .ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"), |
| 106 | .ScriptForEach = (ScriptForEachFnPtr)nullptr, |
| 107 | .ScriptForEachMulti = (ScriptForEachMultiFnPtr)dlsym(handle, "rsScriptForEachMulti"), |
| 108 | .ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"), |
| 109 | .ScriptGroup2Create = (ScriptGroup2CreateFnPtr)dlsym(handle, "rsScriptGroup2Create"), |
| 110 | .ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"), |
| 111 | .ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"), |
| 112 | .ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"), |
| 113 | .ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"), |
| 114 | .ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate"), |
| 115 | .ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"), |
| 116 | .ScriptInvokeIDCreate = (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"), |
| 117 | .ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"), |
| 118 | .ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"), |
| 119 | .ScriptReduce = (ScriptReduceFnPtr)dlsym(handle, "rsScriptReduce"), |
| 120 | .ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"), |
| 121 | .ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"), |
| 122 | .ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"), |
| 123 | .ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"), |
| 124 | .ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"), |
| 125 | .ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"), |
| 126 | .ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"), |
| 127 | .ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"), |
| 128 | .TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"), |
| 129 | .TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"), |
| 130 | }; |
| 131 | |
| 132 | return dispatchHal; |
| 133 | } |
| 134 | |
| 135 | } // namespace implementation |
| 136 | } // namespace V1_0 |
| 137 | } // namespace renderscript |
| 138 | } // namespace hardware |
| 139 | } // namespace android |