blob: 3aae06097507a5df5acd4800aa1a7cf98779f3b2 [file] [log] [blame]
Miao Wang4772b602017-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 Wang41d8a442017-05-16 15:36:54 -070045 .SetNativeLibDir = (SetNativeLibDirFnPtr) nullptr,
Miao Wang4772b602017-01-20 10:30:38 -080046
Miao Wang41d8a442017-05-16 15:36:54 -070047 .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 Wang4772b602017-01-20 10:30:38 -0800107 .AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"),
108 .ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"),
109 .ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"),
Miao Wang41d8a442017-05-16 15:36:54 -0700110 .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 Wang4772b602017-01-20 10:30:38 -0800118 .ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"),
119 .ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"),
Miao Wang41d8a442017-05-16 15:36:54 -0700120 .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 Wang4772b602017-01-20 10:30:38 -0800137 .ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700138 .ElementGetNativeData =
139 (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"),
140 .ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(
141 handle, "rsaElementGetSubElements"),
Miao Wang4772b602017-01-20 10:30:38 -0800142 .GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName"),
Miao Wang41d8a442017-05-16 15:36:54 -0700143 .InvokeClosureCreate =
144 (InvokeClosureCreateFnPtr)dlsym(handle, "rsInvokeClosureCreate"),
Miao Wang4772b602017-01-20 10:30:38 -0800145 .ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"),
146 .SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700147 .ScriptBindAllocation =
148 (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"),
Miao Wang4772b602017-01-20 10:30:38 -0800149 .ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700150 .ScriptFieldIDCreate =
151 (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"),
152 .ScriptForEach = (ScriptForEachFnPtr) nullptr,
153 .ScriptForEachMulti =
154 (ScriptForEachMultiFnPtr)dlsym(handle, "rsScriptForEachMulti"),
Miao Wang4772b602017-01-20 10:30:38 -0800155 .ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"),
Miao Wang41d8a442017-05-16 15:36:54 -0700156 .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 Wang4772b602017-01-20 10:30:38 -0800168 .ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"),
Miao Wang41d8a442017-05-16 15:36:54 -0700169 .ScriptInvokeIDCreate =
170 (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"),
Miao Wang4772b602017-01-20 10:30:38 -0800171 .ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"),
Miao Wang41d8a442017-05-16 15:36:54 -0700172 .ScriptKernelIDCreate =
173 (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"),
Miao Wang4772b602017-01-20 10:30:38 -0800174 .ScriptReduce = (ScriptReduceFnPtr)dlsym(handle, "rsScriptReduce"),
Miao Wang41d8a442017-05-16 15:36:54 -0700175 .ScriptSetTimeZone =
176 (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"),
Miao Wang4772b602017-01-20 10:30:38 -0800177 .ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"),
178 .ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"),
179 .ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"),
180 .ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"),
Miao Wang41d8a442017-05-16 15:36:54 -0700181 .ScriptSetVarObj =
182 (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"),
183 .ScriptSetVarVE =
184 (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"),
Miao Wang4772b602017-01-20 10:30:38 -0800185 .ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"),
186 .TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700187 .TypeGetNativeData =
188 (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"),
Miao Wang4772b602017-01-20 10:30:38 -0800189 };
190
191 return dispatchHal;
192}
193
194} // namespace implementation
195} // namespace V1_0
196} // namespace renderscript
197} // namespace hardware
198} // namespace android