rsDispatch.cpp revision 48d2eae90f08dc33754a9d280337249690a954d6
1/* 2 * Copyright (C) 2011-2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16#define LOG_TAG "libDispatch" 17#include <android/log.h> 18 19#include "rsDispatch.h" 20#include <dlfcn.h> 21 22#define LOG_API(...) 23 24bool loadSymbols(void* handle, dispatchTable& dispatchTab) { 25 26 dispatchTab.AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"); 27 if (dispatchTab.AllocationGetType == NULL) { 28 LOG_API("Couldn't initialize dispatchTab.AllocationGetType"); 29 return false; 30 } 31 dispatchTab.TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"); 32 if (dispatchTab.TypeGetNativeData == NULL) { 33 LOG_API("Couldn't initialize dispatchTab.TypeGetNativeData"); 34 return false; 35 } 36 dispatchTab.ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"); 37 if (dispatchTab.ElementGetNativeData == NULL) { 38 LOG_API("Couldn't initialize dispatchTab.ElementGetNativeData"); 39 return false; 40 } 41 dispatchTab.ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements"); 42 if (dispatchTab.ElementGetSubElements == NULL) { 43 LOG_API("Couldn't initialize dispatchTab.ElementGetSubElements"); 44 return false; 45 } 46 dispatchTab.DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate"); 47 if (dispatchTab.DeviceCreate == NULL) { 48 LOG_API("Couldn't initialize dispatchTab.DeviceCreate"); 49 return false; 50 } 51 dispatchTab.DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy"); 52 if (dispatchTab.DeviceDestroy == NULL) { 53 LOG_API("Couldn't initialize dispatchTab.DeviceDestroy"); 54 return false; 55 } 56 dispatchTab.DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig"); 57 if (dispatchTab.DeviceSetConfig == NULL) { 58 LOG_API("Couldn't initialize dispatchTab.DeviceSetConfig"); 59 return false; 60 } 61 dispatchTab.ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");; 62 if (dispatchTab.ContextCreate == NULL) { 63 LOG_API("Couldn't initialize dispatchTab.ContextCreate"); 64 return false; 65 } 66 dispatchTab.GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");; 67 if (dispatchTab.GetName == NULL) { 68 LOG_API("Couldn't initialize dispatchTab.GetName"); 69 return false; 70 } 71 dispatchTab.ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"); 72 if (dispatchTab.ContextDestroy == NULL) { 73 LOG_API("Couldn't initialize dispatchTab.ContextDestroy"); 74 return false; 75 } 76 dispatchTab.ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"); 77 if (dispatchTab.ContextGetMessage == NULL) { 78 LOG_API("Couldn't initialize dispatchTab.ContextGetMessage"); 79 return false; 80 } 81 dispatchTab.ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"); 82 if (dispatchTab.ContextPeekMessage == NULL) { 83 LOG_API("Couldn't initialize dispatchTab.ContextPeekMessage"); 84 return false; 85 } 86 dispatchTab.ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"); 87 if (dispatchTab.ContextSendMessage == NULL) { 88 LOG_API("Couldn't initialize dispatchTab.ContextSendMessage"); 89 return false; 90 } 91 dispatchTab.ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"); 92 if (dispatchTab.ContextInitToClient == NULL) { 93 LOG_API("Couldn't initialize dispatchTab.ContextInitToClient"); 94 return false; 95 } 96 dispatchTab.ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient"); 97 if (dispatchTab.ContextDeinitToClient == NULL) { 98 LOG_API("Couldn't initialize dispatchTab.ContextDeinitToClient"); 99 return false; 100 } 101 dispatchTab.TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"); 102 if (dispatchTab.TypeCreate == NULL) { 103 LOG_API("Couldn't initialize dispatchTab.TypeCreate"); 104 return false; 105 } 106 dispatchTab.AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped"); 107 if (dispatchTab.AllocationCreateTyped == NULL) { 108 LOG_API("Couldn't initialize dispatchTab.AllocationCreateTyped"); 109 return false; 110 } 111 dispatchTab.AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap"); 112 if (dispatchTab.AllocationCreateFromBitmap == NULL) { 113 LOG_API("Couldn't initialize dispatchTab.AllocationCreateFromBitmap"); 114 return false; 115 } 116 dispatchTab.AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap"); 117 if (dispatchTab.AllocationCubeCreateFromBitmap == NULL) { 118 LOG_API("Couldn't initialize dispatchTab.AllocationCubeCreateFromBitmap"); 119 return false; 120 } 121 dispatchTab.AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"); 122 if (dispatchTab.AllocationGetSurface == NULL) { 123 LOG_API("Couldn't initialize dispatchTab.AllocationGetSurface"); 124 return false; 125 } 126 dispatchTab.AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"); 127 if (dispatchTab.AllocationSetSurface == NULL) { 128 LOG_API("Couldn't initialize dispatchTab.AllocationSetSurface"); 129 return false; 130 } 131 dispatchTab.ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"); 132 if (dispatchTab.ContextFinish == NULL) { 133 LOG_API("Couldn't initialize dispatchTab.ContextFinish"); 134 return false; 135 } 136 dispatchTab.ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"); 137 if (dispatchTab.ContextDump == NULL) { 138 LOG_API("Couldn't initialize dispatchTab.ContextDump"); 139 return false; 140 } 141 dispatchTab.ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"); 142 if (dispatchTab.ContextSetPriority == NULL) { 143 LOG_API("Couldn't initialize dispatchTab.ContextSetPriority"); 144 return false; 145 } 146 dispatchTab.AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"); 147 if (dispatchTab.AssignName == NULL) { 148 LOG_API("Couldn't initialize dispatchTab.AssignName"); 149 return false; 150 } 151 dispatchTab.ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"); 152 if (dispatchTab.ObjDestroy == NULL) { 153 LOG_API("Couldn't initialize dispatchTab.ObjDestroy"); 154 return false; 155 } 156 dispatchTab.ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"); 157 if (dispatchTab.ElementCreate == NULL) { 158 LOG_API("Couldn't initialize dispatchTab.ElementCreate"); 159 return false; 160 } 161 dispatchTab.ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"); 162 if (dispatchTab.ElementCreate2 == NULL) { 163 LOG_API("Couldn't initialize dispatchTab.ElementCreate2"); 164 return false; 165 } 166 dispatchTab.AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap"); 167 if (dispatchTab.AllocationCopyToBitmap == NULL) { 168 LOG_API("Couldn't initialize dispatchTab.AllocationCopyToBitmap"); 169 return false; 170 } 171 dispatchTab.Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"); 172 if (dispatchTab.Allocation1DData == NULL) { 173 LOG_API("Couldn't initialize dispatchTab.Allocation1DData"); 174 return false; 175 } 176 dispatchTab.Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData"); 177 if (dispatchTab.Allocation1DElementData == NULL) { 178 LOG_API("Couldn't initialize dispatchTab.Allocation1DElementData"); 179 return false; 180 } 181 dispatchTab.Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"); 182 if (dispatchTab.Allocation2DData == NULL) { 183 LOG_API("Couldn't initialize dispatchTab.Allocation2DData"); 184 return false; 185 } 186 dispatchTab.Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"); 187 if (dispatchTab.Allocation3DData == NULL) { 188 LOG_API("Couldn't initialize dispatchTab.Allocation3DData"); 189 return false; 190 } 191 dispatchTab.AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps"); 192 if (dispatchTab.AllocationGenerateMipmaps == NULL) { 193 LOG_API("Couldn't initialize dispatchTab.AllocationGenerateMipmaps"); 194 return false; 195 } 196 dispatchTab.AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"); 197 if (dispatchTab.AllocationRead == NULL) { 198 LOG_API("Couldn't initialize dispatchTab.AllocationRead"); 199 return false; 200 } 201 dispatchTab.Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"); 202 if (dispatchTab.Allocation1DRead == NULL) { 203 LOG_API("Couldn't initialize dispatchTab.Allocation1DRead"); 204 return false; 205 } 206 dispatchTab.Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"); 207 if (dispatchTab.Allocation2DRead == NULL) { 208 LOG_API("Couldn't initialize dispatchTab.Allocation2DRead"); 209 return false; 210 } 211 dispatchTab.AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"); 212 if (dispatchTab.AllocationSyncAll == NULL) { 213 LOG_API("Couldn't initialize dispatchTab.AllocationSyncAll"); 214 return false; 215 } 216 dispatchTab.AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"); 217 if (dispatchTab.AllocationResize1D == NULL) { 218 LOG_API("Couldn't initialize dispatchTab.AllocationResize1D"); 219 return false; 220 } 221 dispatchTab.AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange"); 222 if (dispatchTab.AllocationCopy2DRange == NULL) { 223 LOG_API("Couldn't initialize dispatchTab.AllocationCopy2DRange"); 224 return false; 225 } 226 dispatchTab.AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange"); 227 if (dispatchTab.AllocationCopy3DRange == NULL) { 228 LOG_API("Couldn't initialize dispatchTab.AllocationCopy3DRange"); 229 return false; 230 } 231 dispatchTab.SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"); 232 if (dispatchTab.SamplerCreate == NULL) { 233 LOG_API("Couldn't initialize dispatchTab.SamplerCreate"); 234 return false; 235 } 236 dispatchTab.ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"); 237 if (dispatchTab.ScriptBindAllocation == NULL) { 238 LOG_API("Couldn't initialize dispatchTab.ScriptBindAllocation"); 239 return false; 240 } 241 dispatchTab.ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"); 242 if (dispatchTab.ScriptSetTimeZone == NULL) { 243 LOG_API("Couldn't initialize dispatchTab.ScriptSetTimeZone"); 244 return false; 245 } 246 dispatchTab.ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"); 247 if (dispatchTab.ScriptInvoke == NULL) { 248 LOG_API("Couldn't initialize dispatchTab.ScriptInvoke"); 249 return false; 250 } 251 dispatchTab.ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"); 252 if (dispatchTab.ScriptInvokeV == NULL) { 253 LOG_API("Couldn't initialize dispatchTab.ScriptInvokeV"); 254 return false; 255 } 256 dispatchTab.ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach"); 257 if (dispatchTab.ScriptForEach == NULL) { 258 LOG_API("Couldn't initialize dispatchTab.ScriptForEach"); 259 return false; 260 } 261 dispatchTab.ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"); 262 if (dispatchTab.ScriptSetVarI == NULL) { 263 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarI"); 264 return false; 265 } 266 dispatchTab.ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"); 267 if (dispatchTab.ScriptSetVarObj == NULL) { 268 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarObj"); 269 return false; 270 } 271 dispatchTab.ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"); 272 if (dispatchTab.ScriptSetVarJ == NULL) { 273 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarJ"); 274 return false; 275 } 276 dispatchTab.ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"); 277 if (dispatchTab.ScriptSetVarF == NULL) { 278 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarF"); 279 return false; 280 } 281 dispatchTab.ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"); 282 if (dispatchTab.ScriptSetVarD == NULL) { 283 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarD"); 284 return false; 285 } 286 dispatchTab.ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"); 287 if (dispatchTab.ScriptSetVarV == NULL) { 288 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarV"); 289 return false; 290 } 291 dispatchTab.ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"); 292 if (dispatchTab.ScriptGetVarV == NULL) { 293 LOG_API("Couldn't initialize dispatchTab.ScriptGetVarV"); 294 return false; 295 } 296 dispatchTab.ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"); 297 if (dispatchTab.ScriptSetVarVE == NULL) { 298 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarVE"); 299 return false; 300 } 301 dispatchTab.ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"); 302 if (dispatchTab.ScriptCCreate == NULL) { 303 LOG_API("Couldn't initialize dispatchTab.ScriptCCreate"); 304 return false; 305 } 306 dispatchTab.ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate"); 307 if (dispatchTab.ScriptIntrinsicCreate == NULL) { 308 LOG_API("Couldn't initialize dispatchTab.ScriptIntrinsicCreate"); 309 return false; 310 } 311 dispatchTab.ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"); 312 if (dispatchTab.ScriptKernelIDCreate == NULL) { 313 LOG_API("Couldn't initialize dispatchTab.ScriptKernelIDCreate"); 314 return false; 315 } 316 dispatchTab.ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"); 317 if (dispatchTab.ScriptFieldIDCreate == NULL) { 318 LOG_API("Couldn't initialize dispatchTab.ScriptFieldIDCreate"); 319 return false; 320 } 321 dispatchTab.ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"); 322 if (dispatchTab.ScriptGroupCreate == NULL) { 323 LOG_API("Couldn't initialize dispatchTab.ScriptGroupCreate"); 324 return false; 325 } 326 dispatchTab.ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"); 327 if (dispatchTab.ScriptGroupSetOutput == NULL) { 328 LOG_API("Couldn't initialize dispatchTab.ScriptGroupSetOutput"); 329 return false; 330 } 331 dispatchTab.ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"); 332 if (dispatchTab.ScriptGroupSetInput == NULL) { 333 LOG_API("Couldn't initialize dispatchTab.ScriptGroupSetInput"); 334 return false; 335 } 336 dispatchTab.ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"); 337 if (dispatchTab.ScriptGroupExecute == NULL) { 338 LOG_API("Couldn't initialize dispatchTab.ScriptGroupExecute"); 339 return false; 340 } 341 dispatchTab.AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"); 342 if (dispatchTab.AllocationIoSend == NULL) { 343 LOG_API("Couldn't initialize dispatchTab.AllocationIoSend"); 344 return false; 345 } 346 dispatchTab.AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"); 347 if (dispatchTab.AllocationIoReceive == NULL) { 348 LOG_API("Couldn't initialize dispatchTab.AllocationIoReceive"); 349 return false; 350 } 351 dispatchTab.AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer"); 352 if (dispatchTab.AllocationGetPointer == NULL) { 353 LOG_API("Couldn't initialize dispatchTab.AllocationGetPointer"); 354 return false; 355 } 356 357 return true; 358} 359 360