blob: 406602e4b03816de79bb9fe853f764caf63e2e1a [file] [log] [blame]
Miao Wangb78b2f42017-01-20 10:30:38 -08001#include "Context.h"
2#include "Device.h"
3
4namespace android {
5namespace hardware {
6namespace renderscript {
7namespace V1_0 {
8namespace implementation {
9
10
11static dispatchTable loadHAL();
12dispatchTable Device::mDispatchHal = loadHAL();
13
14Device::Device() {
15}
16
17dispatchTable& Device::getHal() {
18 return mDispatchHal;
19}
20
21
22// Methods from ::android::hardware::renderscript::V1_0::IDevice follow.
23
24Return<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
31IDevice* HIDL_FETCH_IDevice(const char* /* name */) {
32 return new Device();
33}
34
35// Helper function
36dispatchTable 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 Wangfdd83452017-05-16 15:36:54 -070045 .SetNativeLibDir = (SetNativeLibDirFnPtr) nullptr,
Miao Wangb78b2f42017-01-20 10:30:38 -080046
47 .Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"),
Miao Wangfdd83452017-05-16 15:36:54 -070048 .Allocation1DElementData = (Allocation1DElementDataFnPtr) nullptr,
Miao Wangb78b2f42017-01-20 10:30:38 -080049 .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"),
Miao Wangfdd83452017-05-16 15:36:54 -070054 .AllocationAdapterCreate =
55 (AllocationAdapterCreateFnPtr)dlsym(handle, "rsAllocationAdapterCreate"),
56 .AllocationAdapterOffset =
57 (AllocationAdapterOffsetFnPtr)dlsym(handle, "rsAllocationAdapterOffset"),
58 .AllocationCopy2DRange =
59 (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange"),
60 .AllocationCopy3DRange =
61 (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange"),
62 .AllocationCopyToBitmap =
63 (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap"),
64 .AllocationCreateFromBitmap =
65 (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap"),
66 .AllocationCreateStrided =
67 (AllocationCreateStridedFnPtr)dlsym(handle, "rsAllocationCreateStrided"),
68 .AllocationCreateTyped =
69 (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped"),
70 .AllocationCubeCreateFromBitmap =
71 (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap"),
72 .AllocationElementData =
73 (AllocationElementDataFnPtr)dlsym(handle, "rsAllocationElementData"),
74 .AllocationElementRead =
75 (AllocationElementReadFnPtr)dlsym(handle, "rsAllocationElementRead"),
76 .AllocationGenerateMipmaps =
77 (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps"),
Miao Wangb78b2f42017-01-20 10:30:38 -080078 .AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer"),
79 .AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"),
80 .AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"),
81 .AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"),
82 .AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"),
83 .AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"),
84 .AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"),
85 .AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"),
Miao Wangfdd83452017-05-16 15:36:54 -070086 .AllocationSetupBufferQueue =
87 (AllocationSetupBufferQueueFnPtr)dlsym(handle, "rsAllocationSetupBufferQueue"),
88 .AllocationShareBufferQueue =
89 (AllocationShareBufferQueueFnPtr)dlsym(handle, "rsAllocationShareBufferQueue"),
Miao Wangb78b2f42017-01-20 10:30:38 -080090 .AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"),
91 .AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"),
92 .ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"),
93 .ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"),
94 .ClosureSetGlobal = (ClosureSetGlobalFnPtr)dlsym(handle, "rsClosureSetGlobal"),
Miao Wangfdd83452017-05-16 15:36:54 -070095 .ContextCreateVendor = (ContextCreateVendorFnPtr)dlsym(handle, "rsContextCreateVendor"),
96 .ContextDeinitToClient =
97 (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient"),
Miao Wangb78b2f42017-01-20 10:30:38 -080098 .ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"),
99 .ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"),
100 .ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"),
101 .ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"),
102 .ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"),
103 .ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"),
104 .ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"),
105 .ContextSetCacheDir = (ContextSetCacheDirFnPtr)dlsym(handle, "rsContextSetCacheDir"),
106 .ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"),
Miao Wangfdd83452017-05-16 15:36:54 -0700107 .DeviceCreate = (DeviceCreateFnPtr) nullptr,
108 .DeviceDestroy = (DeviceDestroyFnPtr) nullptr,
109 .DeviceSetConfig = (DeviceSetConfigFnPtr) nullptr,
Miao Wangb78b2f42017-01-20 10:30:38 -0800110 .ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"),
111 .ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"),
112 .ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"),
Miao Wangfdd83452017-05-16 15:36:54 -0700113 .ElementGetSubElements =
114 (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements"),
Miao Wangb78b2f42017-01-20 10:30:38 -0800115 .GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName"),
116 .InvokeClosureCreate = (InvokeClosureCreateFnPtr)dlsym(handle, "rsInvokeClosureCreate"),
117 .ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"),
118 .SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"),
119 .ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"),
120 .ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"),
121 .ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"),
Miao Wangfdd83452017-05-16 15:36:54 -0700122 .ScriptForEach = (ScriptForEachFnPtr) nullptr,
Miao Wangb78b2f42017-01-20 10:30:38 -0800123 .ScriptForEachMulti = (ScriptForEachMultiFnPtr)dlsym(handle, "rsScriptForEachMulti"),
124 .ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"),
125 .ScriptGroup2Create = (ScriptGroup2CreateFnPtr)dlsym(handle, "rsScriptGroup2Create"),
126 .ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"),
127 .ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"),
128 .ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"),
129 .ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"),
Miao Wangfdd83452017-05-16 15:36:54 -0700130 .ScriptIntrinsicCreate =
131 (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate"),
Miao Wangb78b2f42017-01-20 10:30:38 -0800132 .ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"),
133 .ScriptInvokeIDCreate = (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"),
134 .ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"),
135 .ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"),
136 .ScriptReduce = (ScriptReduceFnPtr)dlsym(handle, "rsScriptReduce"),
137 .ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"),
138 .ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"),
139 .ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"),
140 .ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"),
141 .ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"),
142 .ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"),
143 .ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"),
144 .ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"),
145 .TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"),
146 .TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"),
147 };
148
149 return dispatchHal;
150}
151
152} // namespace implementation
153} // namespace V1_0
154} // namespace renderscript
155} // namespace hardware
156} // namespace android