1 #include "Context.h"
2 #include "Device.h"
4 #include <android/dlext.h>
5 #include <dlfcn.h>
7 namespace android {
8 namespace hardware {
9 namespace renderscript {
10 namespace V1_0 {
11 namespace implementation {
14 static dispatchTable loadHAL();
15 dispatchTable Device::mDispatchHal = loadHAL();
17 Device::Device() {
18 }
20 dispatchTable& Device::getHal() {
21 return mDispatchHal;
22 }
25 // Methods from ::android::hardware::renderscript::V1_0::IDevice follow.
27 Return<sp<IContext>> Device::contextCreate(uint32_t sdkVersion, ContextType ct, int32_t flags) {
28 return new Context(sdkVersion, ct, flags);
29 }
32 // Methods from ::android::hidl::base::V1_0::IBase follow.
34 IDevice* HIDL_FETCH_IDevice(const char* /* name */) {
35 return new Device();
36 }
38 // Helper function
39 dispatchTable loadHAL() {
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)");
44 const char* filename = "libRS_internal.so";
45 // 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 }
65 dispatchTable dispatchHal = {
66 .SetNativeLibDir = (SetNativeLibDirFnPtr) nullptr,
68 .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"),
128 .AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"),
129 .ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"),
130 .ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"),
131 .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"),
139 .ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"),
140 .ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"),
141 .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"),
158 .ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"),
159 .ElementGetNativeData =
160 (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"),
161 .ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(
162 handle, "rsaElementGetSubElements"),
163 .GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName"),
164 .InvokeClosureCreate =
165 (InvokeClosureCreateFnPtr)dlsym(handle, "rsInvokeClosureCreate"),
166 .ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"),
167 .SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"),
168 .ScriptBindAllocation =
169 (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"),
170 .ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"),
171 .ScriptFieldIDCreate =
172 (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"),
173 .ScriptForEach = (ScriptForEachFnPtr) nullptr,
174 .ScriptForEachMulti =
175 (ScriptForEachMultiFnPtr)dlsym(handle, "rsScriptForEachMulti"),
176 .ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"),
177 .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"),
189 .ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"),
190 .ScriptInvokeIDCreate =
191 (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"),
192 .ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"),
193 .ScriptKernelIDCreate =
194 (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"),
195 .ScriptReduce = (ScriptReduceFnPtr)dlsym(handle, "rsScriptReduce"),
196 .ScriptSetTimeZone =
197 (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"),
198 .ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"),
199 .ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"),
200 .ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"),
201 .ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"),
202 .ScriptSetVarObj =
203 (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"),
204 .ScriptSetVarVE =
205 (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"),
206 .ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"),
207 .TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"),
208 .TypeGetNativeData =
209 (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"),
210 };
212 return dispatchHal;
213 }
215 } // namespace implementation
216 } // namespace V1_0
217 } // namespace renderscript
218 } // namespace hardware
219 } // namespace android