2017-01-20 19:30:38 +01:00
|
|
|
#include "Context.h"
|
|
|
|
#include "Device.h"
|
|
|
|
|
2017-08-16 16:30:42 +02:00
|
|
|
#include <android/dlext.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
2017-01-20 19:30:38 +01:00
|
|
|
namespace android {
|
|
|
|
namespace hardware {
|
|
|
|
namespace renderscript {
|
|
|
|
namespace V1_0 {
|
|
|
|
namespace implementation {
|
|
|
|
|
|
|
|
|
|
|
|
static dispatchTable loadHAL();
|
|
|
|
dispatchTable Device::mDispatchHal = loadHAL();
|
|
|
|
|
|
|
|
Device::Device() {
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatchTable& Device::getHal() {
|
|
|
|
return mDispatchHal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Methods from ::android::hardware::renderscript::V1_0::IDevice follow.
|
|
|
|
|
|
|
|
Return<sp<IContext>> Device::contextCreate(uint32_t sdkVersion, ContextType ct, int32_t flags) {
|
|
|
|
return new Context(sdkVersion, ct, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
|
|
|
|
|
|
|
IDevice* HIDL_FETCH_IDevice(const char* /* name */) {
|
|
|
|
return new Device();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function
|
|
|
|
dispatchTable loadHAL() {
|
|
|
|
|
|
|
|
static_assert(sizeof(void*) <= sizeof(uint64_t), "RenderScript HIDL Error: sizeof(void*) > sizeof(uint64_t)");
|
|
|
|
static_assert(sizeof(size_t) <= sizeof(uint64_t), "RenderScript HIDL Error: sizeof(size_t) > sizeof(uint64_t)");
|
|
|
|
|
|
|
|
const char* filename = "libRS_internal.so";
|
2017-08-16 16:30:42 +02:00
|
|
|
// Try to load libRS_internal.so from the "rs" namespace directly.
|
|
|
|
typedef struct android_namespace_t* (*GetExportedNamespaceFnPtr)(const char*);
|
2017-10-20 10:28:41 +02:00
|
|
|
GetExportedNamespaceFnPtr getExportedNamespace = reinterpret_cast<GetExportedNamespaceFnPtr>(
|
|
|
|
dlsym(RTLD_DEFAULT, "android_get_exported_namespace"));
|
2017-08-16 16:30:42 +02:00
|
|
|
void* handle = nullptr;
|
|
|
|
if (getExportedNamespace != nullptr) {
|
2017-10-20 10:28:41 +02:00
|
|
|
android_namespace_t* rsNamespace = getExportedNamespace("rs");
|
|
|
|
if (rsNamespace != nullptr) {
|
2017-08-16 16:30:42 +02:00
|
|
|
const android_dlextinfo dlextinfo = {
|
2017-10-20 10:28:41 +02:00
|
|
|
.flags = ANDROID_DLEXT_USE_NAMESPACE, .library_namespace = rsNamespace,
|
2017-08-16 16:30:42 +02:00
|
|
|
};
|
|
|
|
handle = android_dlopen_ext(filename, RTLD_LAZY | RTLD_LOCAL, &dlextinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (handle == nullptr) {
|
|
|
|
// if there is no "rs" namespace (in case when this HAL impl is loaded
|
|
|
|
// into a vendor process), then use the plain dlopen.
|
|
|
|
handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
|
|
|
|
}
|
2017-01-20 19:30:38 +01:00
|
|
|
|
|
|
|
dispatchTable dispatchHal = {
|
2017-05-17 00:36:54 +02:00
|
|
|
.SetNativeLibDir = (SetNativeLibDirFnPtr) nullptr,
|
|
|
|
|
|
|
|
.Allocation1DData =
|
|
|
|
(Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"),
|
|
|
|
.Allocation1DElementData = (Allocation1DElementDataFnPtr) nullptr,
|
|
|
|
.Allocation1DRead =
|
|
|
|
(Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"),
|
|
|
|
.Allocation2DData =
|
|
|
|
(Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"),
|
|
|
|
.Allocation2DRead =
|
|
|
|
(Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"),
|
|
|
|
.Allocation3DData =
|
|
|
|
(Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"),
|
|
|
|
.Allocation3DRead =
|
|
|
|
(Allocation3DReadFnPtr)dlsym(handle, "rsAllocation3DRead"),
|
|
|
|
.AllocationAdapterCreate = (AllocationAdapterCreateFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationAdapterCreate"),
|
|
|
|
.AllocationAdapterOffset = (AllocationAdapterOffsetFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationAdapterOffset"),
|
|
|
|
.AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationCopy2DRange"),
|
|
|
|
.AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationCopy3DRange"),
|
|
|
|
.AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationCopyToBitmap"),
|
|
|
|
.AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationCreateFromBitmap"),
|
|
|
|
.AllocationCreateStrided = (AllocationCreateStridedFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationCreateStrided"),
|
|
|
|
.AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationCreateTyped"),
|
|
|
|
.AllocationCubeCreateFromBitmap =
|
|
|
|
(AllocationCubeCreateFromBitmapFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationCubeCreateFromBitmap"),
|
|
|
|
.AllocationElementData = (AllocationElementDataFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationElementData"),
|
|
|
|
.AllocationElementRead = (AllocationElementReadFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationElementRead"),
|
|
|
|
.AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationGenerateMipmaps"),
|
|
|
|
.AllocationGetPointer =
|
|
|
|
(AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer"),
|
|
|
|
.AllocationGetSurface =
|
|
|
|
(AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"),
|
|
|
|
.AllocationGetType =
|
|
|
|
(AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"),
|
|
|
|
.AllocationIoReceive =
|
|
|
|
(AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"),
|
|
|
|
.AllocationIoSend =
|
|
|
|
(AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"),
|
|
|
|
.AllocationRead =
|
|
|
|
(AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"),
|
|
|
|
.AllocationResize1D =
|
|
|
|
(AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"),
|
|
|
|
.AllocationSetSurface =
|
|
|
|
(AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"),
|
|
|
|
.AllocationSetupBufferQueue = (AllocationSetupBufferQueueFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationSetupBufferQueue"),
|
|
|
|
.AllocationShareBufferQueue = (AllocationShareBufferQueueFnPtr)dlsym(
|
|
|
|
handle, "rsAllocationShareBufferQueue"),
|
|
|
|
.AllocationSyncAll =
|
|
|
|
(AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"),
|
|
|
|
.ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"),
|
|
|
|
.ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ClosureSetGlobal =
|
|
|
|
(ClosureSetGlobalFnPtr)dlsym(handle, "rsClosureSetGlobal"),
|
|
|
|
.ContextCreateVendor =
|
|
|
|
(ContextCreateVendorFnPtr)dlsym(handle, "rsContextCreateVendor"),
|
|
|
|
.ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(
|
|
|
|
handle, "rsContextDeinitToClient"),
|
|
|
|
.ContextDestroy =
|
|
|
|
(ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"),
|
|
|
|
.ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ContextGetMessage =
|
|
|
|
(ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"),
|
|
|
|
.ContextInitToClient =
|
|
|
|
(ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"),
|
|
|
|
.ContextPeekMessage =
|
|
|
|
(ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"),
|
|
|
|
.ContextSendMessage =
|
|
|
|
(ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"),
|
|
|
|
.ContextSetCacheDir =
|
|
|
|
(ContextSetCacheDirFnPtr)dlsym(handle, "rsContextSetCacheDir"),
|
|
|
|
.ContextSetPriority =
|
|
|
|
(ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"),
|
|
|
|
.DeviceCreate = (DeviceCreateFnPtr) nullptr,
|
|
|
|
.DeviceDestroy = (DeviceDestroyFnPtr) nullptr,
|
|
|
|
.DeviceSetConfig = (DeviceSetConfigFnPtr) nullptr,
|
|
|
|
.ElementCreate2 =
|
|
|
|
(ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ElementGetNativeData =
|
|
|
|
(ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"),
|
|
|
|
.ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(
|
|
|
|
handle, "rsaElementGetSubElements"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.InvokeClosureCreate =
|
|
|
|
(InvokeClosureCreateFnPtr)dlsym(handle, "rsInvokeClosureCreate"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"),
|
|
|
|
.SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ScriptBindAllocation =
|
|
|
|
(ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ScriptFieldIDCreate =
|
|
|
|
(ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"),
|
|
|
|
.ScriptForEach = (ScriptForEachFnPtr) nullptr,
|
|
|
|
.ScriptForEachMulti =
|
|
|
|
(ScriptForEachMultiFnPtr)dlsym(handle, "rsScriptForEachMulti"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ScriptGroup2Create =
|
|
|
|
(ScriptGroup2CreateFnPtr)dlsym(handle, "rsScriptGroup2Create"),
|
|
|
|
.ScriptGroupCreate =
|
|
|
|
(ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"),
|
|
|
|
.ScriptGroupExecute =
|
|
|
|
(ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"),
|
|
|
|
.ScriptGroupSetInput =
|
|
|
|
(ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"),
|
|
|
|
.ScriptGroupSetOutput =
|
|
|
|
(ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"),
|
|
|
|
.ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(
|
|
|
|
handle, "rsScriptIntrinsicCreate"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ScriptInvokeIDCreate =
|
|
|
|
(ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ScriptKernelIDCreate =
|
|
|
|
(ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ScriptReduce = (ScriptReduceFnPtr)dlsym(handle, "rsScriptReduce"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ScriptSetTimeZone =
|
|
|
|
(ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"),
|
|
|
|
.ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"),
|
|
|
|
.ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"),
|
|
|
|
.ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.ScriptSetVarObj =
|
|
|
|
(ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"),
|
|
|
|
.ScriptSetVarVE =
|
|
|
|
(ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"),
|
2017-01-20 19:30:38 +01:00
|
|
|
.ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"),
|
|
|
|
.TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"),
|
2017-05-17 00:36:54 +02:00
|
|
|
.TypeGetNativeData =
|
|
|
|
(TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"),
|
2017-01-20 19:30:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return dispatchHal;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace implementation
|
|
|
|
} // namespace V1_0
|
|
|
|
} // namespace renderscript
|
|
|
|
} // namespace hardware
|
|
|
|
} // namespace android
|