diff options
| author | Tim Murray <timmurray@google.com> | 2013-07-23 16:25:41 -0700 |
|---|---|---|
| committer | Tim Murray <timmurray@google.com> | 2013-07-23 16:48:41 -0700 |
| commit | 0b8a2be7eb9322ec221383de325be8f30b36fe9a (patch) | |
| tree | 7fc784f97c5d66fbcbed2dcc083f23a0bdcab93c /cpp/RenderScript.cpp | |
| parent | a423096c0d49e5cfe13a400b4323a76f89c6885c (diff) | |
Load from libRS or libRSSupport.
Change-Id: I93678b42f9d56033a8563f09705cb88011c12828
Conflicts:
cpp/RenderScript.cpp
Diffstat (limited to 'cpp/RenderScript.cpp')
| -rw-r--r-- | cpp/RenderScript.cpp | 297 |
1 files changed, 152 insertions, 145 deletions
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp index 613d4aa5..b542ad62 100644 --- a/cpp/RenderScript.cpp +++ b/cpp/RenderScript.cpp @@ -67,343 +67,350 @@ bool RS::init(bool forceCpu, bool synchronous) { return RS::init(RS_VERSION, forceCpu, synchronous); } -bool RS::initDispatch(int targetApi) { +static bool loadSymbols(void* handle) { - pthread_mutex_lock(&gInitMutex); - if (gInitError) { - goto error; - } else if (gInitialized) { - return true; - } - // pick appropriate lib at some point - RS::librs = dlopen("libRS.so", RTLD_LAZY | RTLD_LOCAL); - if (RS::librs == 0) { - ALOGE("couldn't dlopen libRS, %s", dlerror()); - goto error; - } - ALOGE("libRS initialized successfully"); - - RS::dispatch = new dispatchTable; - - - RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(RS::librs, "rsaAllocationGetType"); + RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"); if (RS::dispatch->AllocationGetType == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationGetType"); - goto error; + return false; } - RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(RS::librs, "rsaTypeGetNativeData"); + RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"); if (RS::dispatch->TypeGetNativeData == NULL) { ALOGE("Couldn't initialize RS::dispatch->TypeGetNativeData"); - goto error; + return false; } - RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(RS::librs, "rsaElementGetNativeData"); + RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"); if (RS::dispatch->ElementGetNativeData == NULL) { ALOGE("Couldn't initialize RS::dispatch->ElementGetNativeData"); - goto error; + return false; } - RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(RS::librs, "rsaElementGetSubElements"); + RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements"); if (RS::dispatch->ElementGetSubElements == NULL) { ALOGE("Couldn't initialize RS::dispatch->ElementGetSubElements"); - goto error; + return false; } - RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(RS::librs, "rsDeviceCreate"); + RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate"); if (RS::dispatch->DeviceCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->DeviceCreate"); - goto error; + return false; } - RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(RS::librs, "rsDeviceDestroy"); + RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy"); if (RS::dispatch->DeviceDestroy == NULL) { ALOGE("Couldn't initialize RS::dispatch->DeviceDestroy"); - goto error; + return false; } - RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(RS::librs, "rsDeviceSetConfig"); + RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig"); if (RS::dispatch->DeviceSetConfig == NULL) { ALOGE("Couldn't initialize RS::dispatch->DeviceSetConfig"); - goto error; + return false; } - RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(RS::librs, "rsContextCreate");; + RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");; if (RS::dispatch->ContextCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextCreate"); - goto error; + return false; } - RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(RS::librs, "rsContextDestroy"); + RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"); if (RS::dispatch->ContextDestroy == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextDestroy"); - goto error; + return false; } - RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(RS::librs, "rsContextGetMessage"); + RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"); if (RS::dispatch->ContextGetMessage == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextGetMessage"); - goto error; + return false; } - RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(RS::librs, "rsContextPeekMessage"); + RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"); if (RS::dispatch->ContextPeekMessage == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextPeekMessage"); - goto error; + return false; } - RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(RS::librs, "rsContextSendMessage"); + RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"); if (RS::dispatch->ContextSendMessage == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextSendMessage"); - goto error; + return false; } - RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(RS::librs, "rsContextInitToClient"); + RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"); if (RS::dispatch->ContextInitToClient == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextInitToClient"); - goto error; + return false; } - RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(RS::librs, "rsContextDeinitToClient"); + RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient"); if (RS::dispatch->ContextDeinitToClient == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextDeinitToClient"); - goto error; + return false; } - RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(RS::librs, "rsTypeCreate"); + RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"); if (RS::dispatch->TypeCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->TypeCreate"); - goto error; + return false; } - RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(RS::librs, "rsAllocationCreateTyped"); + RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped"); if (RS::dispatch->AllocationCreateTyped == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationCreateTyped"); - goto error; + return false; } - RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(RS::librs, "rsAllocationCreateFromBitmap"); + RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap"); if (RS::dispatch->AllocationCreateFromBitmap == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationCreateFromBitmap"); - goto error; + return false; } - RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(RS::librs, "rsAllocationCubeCreateFromBitmap"); + RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap"); if (RS::dispatch->AllocationCubeCreateFromBitmap == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationCubeCreateFromBitmap"); - goto error; + return false; } - RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(RS::librs, "rsAllocationGetSurface"); + RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"); if (RS::dispatch->AllocationGetSurface == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationGetSurface"); - goto error; + return false; } - RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(RS::librs, "rsAllocationSetSurface"); + RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"); if (RS::dispatch->AllocationSetSurface == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationSetSurface"); - goto error; + return false; } - RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(RS::librs, "rsContextFinish"); + RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"); if (RS::dispatch->ContextFinish == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextFinish"); - goto error; + return false; } - RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(RS::librs, "rsContextDump"); + RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"); if (RS::dispatch->ContextDump == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextDump"); - goto error; + return false; } - RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(RS::librs, "rsContextSetPriority"); + RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"); if (RS::dispatch->ContextSetPriority == NULL) { ALOGE("Couldn't initialize RS::dispatch->ContextSetPriority"); - goto error; + return false; } - RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(RS::librs, "rsAssignName"); + RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"); if (RS::dispatch->AssignName == NULL) { ALOGE("Couldn't initialize RS::dispatch->AssignName"); - goto error; + return false; } - RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(RS::librs, "rsObjDestroy"); + RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"); if (RS::dispatch->ObjDestroy == NULL) { ALOGE("Couldn't initialize RS::dispatch->ObjDestroy"); - goto error; + return false; } - RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(RS::librs, "rsElementCreate"); + RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"); if (RS::dispatch->ElementCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->ElementCreate"); - goto error; + return false; } - RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(RS::librs, "rsElementCreate2"); + RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"); if (RS::dispatch->ElementCreate2 == NULL) { ALOGE("Couldn't initialize RS::dispatch->ElementCreate2"); - goto error; + return false; } - RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(RS::librs, "rsAllocationCopyToBitmap"); + RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap"); if (RS::dispatch->AllocationCopyToBitmap == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationCopyToBitmap"); - goto error; + return false; } - RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(RS::librs, "rsAllocation1DData"); + RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"); if (RS::dispatch->Allocation1DData == NULL) { ALOGE("Couldn't initialize RS::dispatch->Allocation1DData"); - goto error; + return false; } - RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(RS::librs, "rsAllocation1DElementData"); + RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData"); if (RS::dispatch->Allocation1DElementData == NULL) { ALOGE("Couldn't initialize RS::dispatch->Allocation1DElementData"); - goto error; + return false; } - RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(RS::librs, "rsAllocation2DData"); + RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"); if (RS::dispatch->Allocation2DData == NULL) { ALOGE("Couldn't initialize RS::dispatch->Allocation2DData"); - goto error; + return false; } - RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(RS::librs, "rsAllocation3DData"); + RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"); if (RS::dispatch->Allocation3DData == NULL) { ALOGE("Couldn't initialize RS::dispatch->Allocation3DData"); - goto error; + return false; } - RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(RS::librs, "rsAllocationGenerateMipmaps"); + RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps"); if (RS::dispatch->AllocationGenerateMipmaps == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationGenerateMipmaps"); - goto error; + return false; } - RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(RS::librs, "rsAllocationRead"); + RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"); if (RS::dispatch->AllocationRead == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationRead"); - goto error; + return false; } - RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(RS::librs, "rsAllocation1DRead"); + RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"); if (RS::dispatch->Allocation1DRead == NULL) { ALOGE("Couldn't initialize RS::dispatch->Allocation1DRead"); - goto error; + return false; } - RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(RS::librs, "rsAllocation2DRead"); + RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"); if (RS::dispatch->Allocation2DRead == NULL) { ALOGE("Couldn't initialize RS::dispatch->Allocation2DRead"); - goto error; + return false; } - RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(RS::librs, "rsAllocationSyncAll"); + RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"); if (RS::dispatch->AllocationSyncAll == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationSyncAll"); - goto error; + return false; } - RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(RS::librs, "rsAllocationResize1D"); + RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"); if (RS::dispatch->AllocationResize1D == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationResize1D"); - goto error; + return false; } - RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(RS::librs, "rsAllocationCopy2DRange"); + RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange"); if (RS::dispatch->AllocationCopy2DRange == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationCopy2DRange"); - goto error; + return false; } - RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(RS::librs, "rsAllocationCopy3DRange"); + RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange"); if (RS::dispatch->AllocationCopy3DRange == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationCopy3DRange"); - goto error; + return false; } - RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(RS::librs, "rsSamplerCreate"); + RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"); if (RS::dispatch->SamplerCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->SamplerCreate"); - goto error; + return false; } - RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(RS::librs, "rsScriptBindAllocation"); + RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"); if (RS::dispatch->ScriptBindAllocation == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptBindAllocation"); - goto error; + return false; } - RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(RS::librs, "rsScriptSetTimeZone"); + RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"); if (RS::dispatch->ScriptSetTimeZone == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetTimeZone"); - goto error; + return false; } - RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(RS::librs, "rsScriptInvoke"); + RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"); if (RS::dispatch->ScriptInvoke == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptInvoke"); - goto error; + return false; } - RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(RS::librs, "rsScriptInvokeV"); + RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"); if (RS::dispatch->ScriptInvokeV == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptInvokeV"); - goto error; + return false; } - RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(RS::librs, "rsScriptForEach"); + RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach"); if (RS::dispatch->ScriptForEach == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptForEach"); - goto error; + return false; } - RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(RS::librs, "rsScriptSetVarI"); + RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"); if (RS::dispatch->ScriptSetVarI == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarI"); - goto error; + return false; } - RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(RS::librs, "rsScriptSetVarObj"); + RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"); if (RS::dispatch->ScriptSetVarObj == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarObj"); - goto error; + return false; } - RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(RS::librs, "rsScriptSetVarJ"); + RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"); if (RS::dispatch->ScriptSetVarJ == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarJ"); - goto error; + return false; } - RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(RS::librs, "rsScriptSetVarF"); + RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"); if (RS::dispatch->ScriptSetVarF == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarF"); - goto error; + return false; } - RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(RS::librs, "rsScriptSetVarD"); + RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"); if (RS::dispatch->ScriptSetVarD == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarD"); - goto error; + return false; } - RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(RS::librs, "rsScriptSetVarV"); + RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"); if (RS::dispatch->ScriptSetVarV == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarV"); - goto error; + return false; } - RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(RS::librs, "rsScriptGetVarV"); + RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"); if (RS::dispatch->ScriptGetVarV == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptGetVarV"); - goto error; + return false; } - RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(RS::librs, "rsScriptSetVarVE"); + RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"); if (RS::dispatch->ScriptSetVarVE == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarVE"); - goto error; + return false; } - RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(RS::librs, "rsScriptCCreate"); + RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"); if (RS::dispatch->ScriptCCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptCCreate"); - goto error; + return false; } - RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(RS::librs, "rsScriptIntrinsicCreate"); + RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate"); if (RS::dispatch->ScriptIntrinsicCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptIntrinsicCreate"); - goto error; + return false; } - RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(RS::librs, "rsScriptKernelIDCreate"); + RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"); if (RS::dispatch->ScriptKernelIDCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptKernelIDCreate"); - goto error; + return false; } - RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(RS::librs, "rsScriptFieldIDCreate"); + RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"); if (RS::dispatch->ScriptFieldIDCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptFieldIDCreate"); - goto error; + return false; } - RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(RS::librs, "rsScriptGroupCreate"); + RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"); if (RS::dispatch->ScriptGroupCreate == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptGroupCreate"); - goto error; + return false; } - RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(RS::librs, "rsScriptGroupSetOutput"); + RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"); if (RS::dispatch->ScriptGroupSetOutput == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptGroupSetOutput"); - goto error; + return false; } - RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(RS::librs, "rsScriptGroupSetInput"); + RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"); if (RS::dispatch->ScriptGroupSetInput == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptGroupSetInput"); - goto error; + return false; } - RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(RS::librs, "rsScriptGroupExecute"); + RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"); if (RS::dispatch->ScriptGroupExecute == NULL) { ALOGE("Couldn't initialize RS::dispatch->ScriptGroupExecute"); - goto error; + return false; } - RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(RS::librs, "rsAllocationIoSend"); + RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"); if (RS::dispatch->AllocationIoSend == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationIoSend"); - goto error; + return false; } - RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(RS::librs, "rsAllocationIoReceive"); + RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"); if (RS::dispatch->AllocationIoReceive == NULL) { ALOGE("Couldn't initialize RS::dispatch->AllocationIoReceive"); + return false; + } + + return true; +} + +bool RS::initDispatch(int targetApi) { + + pthread_mutex_lock(&gInitMutex); + if (gInitError) { + goto error; + } else if (gInitialized) { + return true; + } + // pick appropriate lib at some point + RS::librs = dlopen("libRS.so", RTLD_LAZY | RTLD_LOCAL); + if (RS::librs == 0) { + ALOGE("couldn't dlopen libRS, %s", dlerror()); + goto error; + } + ALOGE("libRS initialized successfully"); + + RS::dispatch = new dispatchTable; + if (loadSymbols(RS::librs) == false) { goto error; } |
