summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMiao Wang <miaowang@google.com>2014-11-17 21:27:09 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-11-17 21:27:10 +0000
commitf9fe049f16c70f3ecaa0be1ce91b244b825fed67 (patch)
tree293c76f45ac4688a1ff5a7b7a4ad646305dd0789 /cpp
parent6895086d12ae86c07f3f952ba1783c97ac008ed9 (diff)
parent48d2eae90f08dc33754a9d280337249690a954d6 (diff)
downloadrs-f9fe049f16c70f3ecaa0be1ce91b244b825fed67.tar.gz
Merge "Create a separate static lib that provides a dispatch table to both fw/support/v8/renderscript/jni and libRScpp to reduce code duplication."
Diffstat (limited to 'cpp')
-rw-r--r--cpp/Android.mk28
-rw-r--r--cpp/RenderScript.cpp339
-rw-r--r--cpp/rsDispatch.cpp359
-rw-r--r--cpp/rsDispatch.h1
4 files changed, 385 insertions, 342 deletions
diff --git a/cpp/Android.mk b/cpp/Android.mk
index e461f1ea..f8ae64d0 100644
--- a/cpp/Android.mk
+++ b/cpp/Android.mk
@@ -1,3 +1,22 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ rsDispatch.cpp
+
+LOCAL_C_INCLUDES += \
+ frameworks/rs
+
+LOCAL_CFLAGS += -Wno-unused-parameter
+
+LOCAL_MODULE:= libRSDispatch
+LOCAL_MODULE_TAGS := optional
+LOCAL_LDFLAGS += -ldl
+
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+
rs_cpp_SRC_FILES := \
RenderScript.cpp \
BaseObj.cpp \
@@ -9,10 +28,7 @@ rs_cpp_SRC_FILES := \
ScriptIntrinsics.cpp \
Sampler.cpp
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
include frameworks/compile/slang/rs_version.mk
local_cflags_for_rs_cpp += $(RS_VERSION_DEFINE)
local_cflags_for_rs_cpp += -Wno-unused-parameter -std=c++11
@@ -31,6 +47,9 @@ LOCAL_SHARED_LIBRARIES := \
liblog \
libdl \
+LOCAL_STATIC_LIBRARIES := \
+ libRSDispatch
+
LOCAL_MODULE:= libRScpp
LOCAL_MODULE_TAGS := optional
@@ -62,7 +81,8 @@ LOCAL_SRC_FILES += ../rsCompatibilityLib.cpp
LOCAL_WHOLE_STATIC_LIBRARIES := \
libutils \
- libstlport_static
+ libstlport_static \
+ libRSDispatch
LOCAL_MODULE:= libRScpp_static
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp
index 44747414..de22dea6 100644
--- a/cpp/RenderScript.cpp
+++ b/cpp/RenderScript.cpp
@@ -21,7 +21,6 @@
#include "RenderScript.h"
#include "rsCppStructs.h"
#include "rsCppInternal.h"
-#include "rsDispatch.h"
#include <dlfcn.h>
#include <unistd.h>
@@ -79,342 +78,6 @@ bool RS::init(std::string name, uint32_t flags) {
return RS::init(name, RS_VERSION, flags);
}
-static bool loadSymbols(void* handle) {
-
- RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType");
- if (RS::dispatch->AllocationGetType == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationGetType");
- return false;
- }
- RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData");
- if (RS::dispatch->TypeGetNativeData == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->TypeGetNativeData");
- return false;
- }
- RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData");
- if (RS::dispatch->ElementGetNativeData == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ElementGetNativeData");
- return false;
- }
- RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements");
- if (RS::dispatch->ElementGetSubElements == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ElementGetSubElements");
- return false;
- }
- RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate");
- if (RS::dispatch->DeviceCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->DeviceCreate");
- return false;
- }
- RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy");
- if (RS::dispatch->DeviceDestroy == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->DeviceDestroy");
- return false;
- }
- RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig");
- if (RS::dispatch->DeviceSetConfig == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->DeviceSetConfig");
- return false;
- }
- RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");;
- if (RS::dispatch->ContextCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextCreate");
- return false;
- }
- RS::dispatch->GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");;
- if (RS::dispatch->GetName == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->GetName");
- return false;
- }
- RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy");
- if (RS::dispatch->ContextDestroy == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextDestroy");
- return false;
- }
- RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage");
- if (RS::dispatch->ContextGetMessage == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextGetMessage");
- return false;
- }
- RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage");
- if (RS::dispatch->ContextPeekMessage == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextPeekMessage");
- return false;
- }
- RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage");
- if (RS::dispatch->ContextSendMessage == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextSendMessage");
- return false;
- }
- RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient");
- if (RS::dispatch->ContextInitToClient == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextInitToClient");
- return false;
- }
- RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient");
- if (RS::dispatch->ContextDeinitToClient == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextDeinitToClient");
- return false;
- }
- RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate");
- if (RS::dispatch->TypeCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->TypeCreate");
- return false;
- }
- RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped");
- if (RS::dispatch->AllocationCreateTyped == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationCreateTyped");
- return false;
- }
- RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap");
- if (RS::dispatch->AllocationCreateFromBitmap == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationCreateFromBitmap");
- return false;
- }
- RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap");
- if (RS::dispatch->AllocationCubeCreateFromBitmap == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationCubeCreateFromBitmap");
- return false;
- }
- RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface");
- if (RS::dispatch->AllocationGetSurface == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationGetSurface");
- return false;
- }
- RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface");
- if (RS::dispatch->AllocationSetSurface == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationSetSurface");
- return false;
- }
- RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish");
- if (RS::dispatch->ContextFinish == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextFinish");
- return false;
- }
- RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump");
- if (RS::dispatch->ContextDump == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextDump");
- return false;
- }
- RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority");
- if (RS::dispatch->ContextSetPriority == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ContextSetPriority");
- return false;
- }
- RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName");
- if (RS::dispatch->AssignName == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AssignName");
- return false;
- }
- RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy");
- if (RS::dispatch->ObjDestroy == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ObjDestroy");
- return false;
- }
- RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate");
- if (RS::dispatch->ElementCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ElementCreate");
- return false;
- }
- RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2");
- if (RS::dispatch->ElementCreate2 == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ElementCreate2");
- return false;
- }
- RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap");
- if (RS::dispatch->AllocationCopyToBitmap == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationCopyToBitmap");
- return false;
- }
- RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData");
- if (RS::dispatch->Allocation1DData == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->Allocation1DData");
- return false;
- }
- RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData");
- if (RS::dispatch->Allocation1DElementData == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->Allocation1DElementData");
- return false;
- }
- RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData");
- if (RS::dispatch->Allocation2DData == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->Allocation2DData");
- return false;
- }
- RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData");
- if (RS::dispatch->Allocation3DData == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->Allocation3DData");
- return false;
- }
- RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps");
- if (RS::dispatch->AllocationGenerateMipmaps == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationGenerateMipmaps");
- return false;
- }
- RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead");
- if (RS::dispatch->AllocationRead == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationRead");
- return false;
- }
- RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead");
- if (RS::dispatch->Allocation1DRead == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->Allocation1DRead");
- return false;
- }
- RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead");
- if (RS::dispatch->Allocation2DRead == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->Allocation2DRead");
- return false;
- }
- RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll");
- if (RS::dispatch->AllocationSyncAll == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationSyncAll");
- return false;
- }
- RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D");
- if (RS::dispatch->AllocationResize1D == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationResize1D");
- return false;
- }
- RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange");
- if (RS::dispatch->AllocationCopy2DRange == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationCopy2DRange");
- return false;
- }
- RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange");
- if (RS::dispatch->AllocationCopy3DRange == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationCopy3DRange");
- return false;
- }
- RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate");
- if (RS::dispatch->SamplerCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->SamplerCreate");
- return false;
- }
- RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation");
- if (RS::dispatch->ScriptBindAllocation == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptBindAllocation");
- return false;
- }
- RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone");
- if (RS::dispatch->ScriptSetTimeZone == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetTimeZone");
- return false;
- }
- RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke");
- if (RS::dispatch->ScriptInvoke == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptInvoke");
- return false;
- }
- RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV");
- if (RS::dispatch->ScriptInvokeV == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptInvokeV");
- return false;
- }
- RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach");
- if (RS::dispatch->ScriptForEach == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptForEach");
- return false;
- }
- RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI");
- if (RS::dispatch->ScriptSetVarI == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarI");
- return false;
- }
- RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj");
- if (RS::dispatch->ScriptSetVarObj == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarObj");
- return false;
- }
- RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ");
- if (RS::dispatch->ScriptSetVarJ == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarJ");
- return false;
- }
- RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF");
- if (RS::dispatch->ScriptSetVarF == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarF");
- return false;
- }
- RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD");
- if (RS::dispatch->ScriptSetVarD == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarD");
- return false;
- }
- RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV");
- if (RS::dispatch->ScriptSetVarV == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarV");
- return false;
- }
- RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV");
- if (RS::dispatch->ScriptGetVarV == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptGetVarV");
- return false;
- }
- RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE");
- if (RS::dispatch->ScriptSetVarVE == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarVE");
- return false;
- }
- RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate");
- if (RS::dispatch->ScriptCCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptCCreate");
- return false;
- }
- RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate");
- if (RS::dispatch->ScriptIntrinsicCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptIntrinsicCreate");
- return false;
- }
- RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate");
- if (RS::dispatch->ScriptKernelIDCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptKernelIDCreate");
- return false;
- }
- RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate");
- if (RS::dispatch->ScriptFieldIDCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptFieldIDCreate");
- return false;
- }
- RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate");
- if (RS::dispatch->ScriptGroupCreate == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptGroupCreate");
- return false;
- }
- RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput");
- if (RS::dispatch->ScriptGroupSetOutput == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetOutput");
- return false;
- }
- RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput");
- if (RS::dispatch->ScriptGroupSetInput == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetInput");
- return false;
- }
- RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute");
- if (RS::dispatch->ScriptGroupExecute == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->ScriptGroupExecute");
- return false;
- }
- RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend");
- if (RS::dispatch->AllocationIoSend == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationIoSend");
- return false;
- }
- RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive");
- if (RS::dispatch->AllocationIoReceive == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationIoReceive");
- return false;
- }
- RS::dispatch->AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer");
- if (RS::dispatch->AllocationGetPointer == nullptr) {
- ALOGV("Couldn't initialize RS::dispatch->AllocationGetPointer");
- //return false;
- }
-
- return true;
-}
-
// this will only open API 19+ libRS
// because that's when we changed libRS to extern "C" entry points
static bool loadSO(const char* filename) {
@@ -424,7 +87,7 @@ static bool loadSO(const char* filename) {
return false;
}
- if (loadSymbols(handle) == false) {
+ if (loadSymbols(handle, *RS::dispatch) == false) {
ALOGV("%s init failed!", filename);
return false;
}
diff --git a/cpp/rsDispatch.cpp b/cpp/rsDispatch.cpp
new file mode 100644
index 00000000..e0116884
--- /dev/null
+++ b/cpp/rsDispatch.cpp
@@ -0,0 +1,359 @@
+/*
+ * Copyright (C) 2011-2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define LOG_TAG "libDispatch"
+#include <android/log.h>
+
+#include "rsDispatch.h"
+#include <dlfcn.h>
+
+#define LOG_API(...)
+
+bool loadSymbols(void* handle, dispatchTable& dispatchTab) {
+
+ dispatchTab.AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType");
+ if (dispatchTab.AllocationGetType == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationGetType");
+ return false;
+ }
+ dispatchTab.TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData");
+ if (dispatchTab.TypeGetNativeData == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.TypeGetNativeData");
+ return false;
+ }
+ dispatchTab.ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData");
+ if (dispatchTab.ElementGetNativeData == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ElementGetNativeData");
+ return false;
+ }
+ dispatchTab.ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements");
+ if (dispatchTab.ElementGetSubElements == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ElementGetSubElements");
+ return false;
+ }
+ dispatchTab.DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate");
+ if (dispatchTab.DeviceCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.DeviceCreate");
+ return false;
+ }
+ dispatchTab.DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy");
+ if (dispatchTab.DeviceDestroy == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.DeviceDestroy");
+ return false;
+ }
+ dispatchTab.DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig");
+ if (dispatchTab.DeviceSetConfig == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.DeviceSetConfig");
+ return false;
+ }
+ dispatchTab.ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");;
+ if (dispatchTab.ContextCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextCreate");
+ return false;
+ }
+ dispatchTab.GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");;
+ if (dispatchTab.GetName == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.GetName");
+ return false;
+ }
+ dispatchTab.ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy");
+ if (dispatchTab.ContextDestroy == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextDestroy");
+ return false;
+ }
+ dispatchTab.ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage");
+ if (dispatchTab.ContextGetMessage == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextGetMessage");
+ return false;
+ }
+ dispatchTab.ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage");
+ if (dispatchTab.ContextPeekMessage == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextPeekMessage");
+ return false;
+ }
+ dispatchTab.ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage");
+ if (dispatchTab.ContextSendMessage == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextSendMessage");
+ return false;
+ }
+ dispatchTab.ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient");
+ if (dispatchTab.ContextInitToClient == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextInitToClient");
+ return false;
+ }
+ dispatchTab.ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient");
+ if (dispatchTab.ContextDeinitToClient == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextDeinitToClient");
+ return false;
+ }
+ dispatchTab.TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate");
+ if (dispatchTab.TypeCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.TypeCreate");
+ return false;
+ }
+ dispatchTab.AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped");
+ if (dispatchTab.AllocationCreateTyped == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationCreateTyped");
+ return false;
+ }
+ dispatchTab.AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap");
+ if (dispatchTab.AllocationCreateFromBitmap == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationCreateFromBitmap");
+ return false;
+ }
+ dispatchTab.AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap");
+ if (dispatchTab.AllocationCubeCreateFromBitmap == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationCubeCreateFromBitmap");
+ return false;
+ }
+ dispatchTab.AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface");
+ if (dispatchTab.AllocationGetSurface == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationGetSurface");
+ return false;
+ }
+ dispatchTab.AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface");
+ if (dispatchTab.AllocationSetSurface == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationSetSurface");
+ return false;
+ }
+ dispatchTab.ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish");
+ if (dispatchTab.ContextFinish == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextFinish");
+ return false;
+ }
+ dispatchTab.ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump");
+ if (dispatchTab.ContextDump == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextDump");
+ return false;
+ }
+ dispatchTab.ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority");
+ if (dispatchTab.ContextSetPriority == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ContextSetPriority");
+ return false;
+ }
+ dispatchTab.AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName");
+ if (dispatchTab.AssignName == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AssignName");
+ return false;
+ }
+ dispatchTab.ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy");
+ if (dispatchTab.ObjDestroy == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ObjDestroy");
+ return false;
+ }
+ dispatchTab.ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate");
+ if (dispatchTab.ElementCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ElementCreate");
+ return false;
+ }
+ dispatchTab.ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2");
+ if (dispatchTab.ElementCreate2 == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ElementCreate2");
+ return false;
+ }
+ dispatchTab.AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap");
+ if (dispatchTab.AllocationCopyToBitmap == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationCopyToBitmap");
+ return false;
+ }
+ dispatchTab.Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData");
+ if (dispatchTab.Allocation1DData == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.Allocation1DData");
+ return false;
+ }
+ dispatchTab.Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData");
+ if (dispatchTab.Allocation1DElementData == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.Allocation1DElementData");
+ return false;
+ }
+ dispatchTab.Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData");
+ if (dispatchTab.Allocation2DData == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.Allocation2DData");
+ return false;
+ }
+ dispatchTab.Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData");
+ if (dispatchTab.Allocation3DData == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.Allocation3DData");
+ return false;
+ }
+ dispatchTab.AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps");
+ if (dispatchTab.AllocationGenerateMipmaps == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationGenerateMipmaps");
+ return false;
+ }
+ dispatchTab.AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead");
+ if (dispatchTab.AllocationRead == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationRead");
+ return false;
+ }
+ dispatchTab.Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead");
+ if (dispatchTab.Allocation1DRead == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.Allocation1DRead");
+ return false;
+ }
+ dispatchTab.Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead");
+ if (dispatchTab.Allocation2DRead == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.Allocation2DRead");
+ return false;
+ }
+ dispatchTab.AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll");
+ if (dispatchTab.AllocationSyncAll == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationSyncAll");
+ return false;
+ }
+ dispatchTab.AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D");
+ if (dispatchTab.AllocationResize1D == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationResize1D");
+ return false;
+ }
+ dispatchTab.AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange");
+ if (dispatchTab.AllocationCopy2DRange == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationCopy2DRange");
+ return false;
+ }
+ dispatchTab.AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange");
+ if (dispatchTab.AllocationCopy3DRange == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationCopy3DRange");
+ return false;
+ }
+ dispatchTab.SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate");
+ if (dispatchTab.SamplerCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.SamplerCreate");
+ return false;
+ }
+ dispatchTab.ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation");
+ if (dispatchTab.ScriptBindAllocation == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptBindAllocation");
+ return false;
+ }
+ dispatchTab.ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone");
+ if (dispatchTab.ScriptSetTimeZone == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetTimeZone");
+ return false;
+ }
+ dispatchTab.ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke");
+ if (dispatchTab.ScriptInvoke == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptInvoke");
+ return false;
+ }
+ dispatchTab.ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV");
+ if (dispatchTab.ScriptInvokeV == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptInvokeV");
+ return false;
+ }
+ dispatchTab.ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach");
+ if (dispatchTab.ScriptForEach == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptForEach");
+ return false;
+ }
+ dispatchTab.ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI");
+ if (dispatchTab.ScriptSetVarI == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetVarI");
+ return false;
+ }
+ dispatchTab.ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj");
+ if (dispatchTab.ScriptSetVarObj == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetVarObj");
+ return false;
+ }
+ dispatchTab.ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ");
+ if (dispatchTab.ScriptSetVarJ == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetVarJ");
+ return false;
+ }
+ dispatchTab.ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF");
+ if (dispatchTab.ScriptSetVarF == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetVarF");
+ return false;
+ }
+ dispatchTab.ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD");
+ if (dispatchTab.ScriptSetVarD == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetVarD");
+ return false;
+ }
+ dispatchTab.ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV");
+ if (dispatchTab.ScriptSetVarV == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetVarV");
+ return false;
+ }
+ dispatchTab.ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV");
+ if (dispatchTab.ScriptGetVarV == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptGetVarV");
+ return false;
+ }
+ dispatchTab.ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE");
+ if (dispatchTab.ScriptSetVarVE == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptSetVarVE");
+ return false;
+ }
+ dispatchTab.ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate");
+ if (dispatchTab.ScriptCCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptCCreate");
+ return false;
+ }
+ dispatchTab.ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate");
+ if (dispatchTab.ScriptIntrinsicCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptIntrinsicCreate");
+ return false;
+ }
+ dispatchTab.ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate");
+ if (dispatchTab.ScriptKernelIDCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptKernelIDCreate");
+ return false;
+ }
+ dispatchTab.ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate");
+ if (dispatchTab.ScriptFieldIDCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptFieldIDCreate");
+ return false;
+ }
+ dispatchTab.ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate");
+ if (dispatchTab.ScriptGroupCreate == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptGroupCreate");
+ return false;
+ }
+ dispatchTab.ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput");
+ if (dispatchTab.ScriptGroupSetOutput == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptGroupSetOutput");
+ return false;
+ }
+ dispatchTab.ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput");
+ if (dispatchTab.ScriptGroupSetInput == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptGroupSetInput");
+ return false;
+ }
+ dispatchTab.ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute");
+ if (dispatchTab.ScriptGroupExecute == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.ScriptGroupExecute");
+ return false;
+ }
+ dispatchTab.AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend");
+ if (dispatchTab.AllocationIoSend == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationIoSend");
+ return false;
+ }
+ dispatchTab.AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive");
+ if (dispatchTab.AllocationIoReceive == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationIoReceive");
+ return false;
+ }
+ dispatchTab.AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer");
+ if (dispatchTab.AllocationGetPointer == NULL) {
+ LOG_API("Couldn't initialize dispatchTab.AllocationGetPointer");
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/cpp/rsDispatch.h b/cpp/rsDispatch.h
index 394a6b15..659591b0 100644
--- a/cpp/rsDispatch.h
+++ b/cpp/rsDispatch.h
@@ -160,4 +160,5 @@ struct dispatchTable {
AllocationGetPointerFnPtr AllocationGetPointer;
};
+bool loadSymbols(void* handle, dispatchTable& dispatchTab);
#endif