blob: 4831a8b987b59c1e4a4ae9182e8328cfd2b4c700 [file] [log] [blame]
Miao Wang4772b602017-01-20 10:30:38 -08001#include "Context.h"
2#include "Device.h"
3
Jiyong Park0f709052017-08-16 23:30:42 +09004#include <android/dlext.h>
5#include <dlfcn.h>
6
Miao Wang4772b602017-01-20 10:30:38 -08007namespace android {
8namespace hardware {
9namespace renderscript {
10namespace V1_0 {
11namespace implementation {
12
13
14static dispatchTable loadHAL();
15dispatchTable Device::mDispatchHal = loadHAL();
16
17Device::Device() {
18}
19
20dispatchTable& Device::getHal() {
21 return mDispatchHal;
22}
23
24
25// Methods from ::android::hardware::renderscript::V1_0::IDevice follow.
26
27Return<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
34IDevice* HIDL_FETCH_IDevice(const char* /* name */) {
35 return new Device();
36}
37
38// Helper function
39dispatchTable 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 Park0f709052017-08-16 23:30:42 +090045 // 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 Wang4772b602017-01-20 10:30:38 -080064
65 dispatchTable dispatchHal = {
Miao Wang41d8a442017-05-16 15:36:54 -070066 .SetNativeLibDir = (SetNativeLibDirFnPtr) nullptr,
Miao Wang4772b602017-01-20 10:30:38 -080067
Miao Wang41d8a442017-05-16 15:36:54 -070068 .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 Wang4772b602017-01-20 10:30:38 -0800128 .AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"),
129 .ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"),
130 .ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"),
Miao Wang41d8a442017-05-16 15:36:54 -0700131 .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 Wang4772b602017-01-20 10:30:38 -0800139 .ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"),
140 .ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"),
Miao Wang41d8a442017-05-16 15:36:54 -0700141 .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 Wang4772b602017-01-20 10:30:38 -0800158 .ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700159 .ElementGetNativeData =
160 (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"),
161 .ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(
162 handle, "rsaElementGetSubElements"),
Miao Wang4772b602017-01-20 10:30:38 -0800163 .GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName"),
Miao Wang41d8a442017-05-16 15:36:54 -0700164 .InvokeClosureCreate =
165 (InvokeClosureCreateFnPtr)dlsym(handle, "rsInvokeClosureCreate"),
Miao Wang4772b602017-01-20 10:30:38 -0800166 .ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"),
167 .SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700168 .ScriptBindAllocation =
169 (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"),
Miao Wang4772b602017-01-20 10:30:38 -0800170 .ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700171 .ScriptFieldIDCreate =
172 (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"),
173 .ScriptForEach = (ScriptForEachFnPtr) nullptr,
174 .ScriptForEachMulti =
175 (ScriptForEachMultiFnPtr)dlsym(handle, "rsScriptForEachMulti"),
Miao Wang4772b602017-01-20 10:30:38 -0800176 .ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"),
Miao Wang41d8a442017-05-16 15:36:54 -0700177 .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 Wang4772b602017-01-20 10:30:38 -0800189 .ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"),
Miao Wang41d8a442017-05-16 15:36:54 -0700190 .ScriptInvokeIDCreate =
191 (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"),
Miao Wang4772b602017-01-20 10:30:38 -0800192 .ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"),
Miao Wang41d8a442017-05-16 15:36:54 -0700193 .ScriptKernelIDCreate =
194 (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"),
Miao Wang4772b602017-01-20 10:30:38 -0800195 .ScriptReduce = (ScriptReduceFnPtr)dlsym(handle, "rsScriptReduce"),
Miao Wang41d8a442017-05-16 15:36:54 -0700196 .ScriptSetTimeZone =
197 (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"),
Miao Wang4772b602017-01-20 10:30:38 -0800198 .ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"),
199 .ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"),
200 .ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"),
201 .ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"),
Miao Wang41d8a442017-05-16 15:36:54 -0700202 .ScriptSetVarObj =
203 (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"),
204 .ScriptSetVarVE =
205 (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"),
Miao Wang4772b602017-01-20 10:30:38 -0800206 .ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"),
207 .TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"),
Miao Wang41d8a442017-05-16 15:36:54 -0700208 .TypeGetNativeData =
209 (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"),
Miao Wang4772b602017-01-20 10:30:38 -0800210 };
211
212 return dispatchHal;
213}
214
215} // namespace implementation
216} // namespace V1_0
217} // namespace renderscript
218} // namespace hardware
219} // namespace android