rsDispatch.cpp revision 8a6a71757f64f02058a50778c75033546a79f2b5
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, int device_api) { 25 //fucntion to set the native lib path for 64bit compat lib. 26#ifdef __LP64__ 27 dispatchTab.SetNativeLibDir = (SetNativeLibDirFnPtr)dlsym(handle, "rsaContextSetNativeLibDir"); 28 if (dispatchTab.SetNativeLibDir == NULL) { 29 LOG_API("Couldn't initialize dispatchTab.SetNativeLibDir"); 30 return false; 31 } 32#endif 33 dispatchTab.AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"); 34 if (dispatchTab.AllocationGetType == NULL) { 35 LOG_API("Couldn't initialize dispatchTab.AllocationGetType"); 36 return false; 37 } 38 dispatchTab.TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"); 39 if (dispatchTab.TypeGetNativeData == NULL) { 40 LOG_API("Couldn't initialize dispatchTab.TypeGetNativeData"); 41 return false; 42 } 43 dispatchTab.ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"); 44 if (dispatchTab.ElementGetNativeData == NULL) { 45 LOG_API("Couldn't initialize dispatchTab.ElementGetNativeData"); 46 return false; 47 } 48 dispatchTab.ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements"); 49 if (dispatchTab.ElementGetSubElements == NULL) { 50 LOG_API("Couldn't initialize dispatchTab.ElementGetSubElements"); 51 return false; 52 } 53 dispatchTab.DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate"); 54 if (dispatchTab.DeviceCreate == NULL) { 55 LOG_API("Couldn't initialize dispatchTab.DeviceCreate"); 56 return false; 57 } 58 dispatchTab.DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy"); 59 if (dispatchTab.DeviceDestroy == NULL) { 60 LOG_API("Couldn't initialize dispatchTab.DeviceDestroy"); 61 return false; 62 } 63 dispatchTab.DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig"); 64 if (dispatchTab.DeviceSetConfig == NULL) { 65 LOG_API("Couldn't initialize dispatchTab.DeviceSetConfig"); 66 return false; 67 } 68 dispatchTab.ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");; 69 if (dispatchTab.ContextCreate == NULL) { 70 LOG_API("Couldn't initialize dispatchTab.ContextCreate"); 71 return false; 72 } 73 dispatchTab.GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");; 74 if (dispatchTab.GetName == NULL) { 75 LOG_API("Couldn't initialize dispatchTab.GetName"); 76 return false; 77 } 78 dispatchTab.ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"); 79 if (dispatchTab.ContextDestroy == NULL) { 80 LOG_API("Couldn't initialize dispatchTab.ContextDestroy"); 81 return false; 82 } 83 dispatchTab.ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"); 84 if (dispatchTab.ContextGetMessage == NULL) { 85 LOG_API("Couldn't initialize dispatchTab.ContextGetMessage"); 86 return false; 87 } 88 dispatchTab.ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"); 89 if (dispatchTab.ContextPeekMessage == NULL) { 90 LOG_API("Couldn't initialize dispatchTab.ContextPeekMessage"); 91 return false; 92 } 93 dispatchTab.ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"); 94 if (dispatchTab.ContextSendMessage == NULL) { 95 LOG_API("Couldn't initialize dispatchTab.ContextSendMessage"); 96 return false; 97 } 98 dispatchTab.ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"); 99 if (dispatchTab.ContextInitToClient == NULL) { 100 LOG_API("Couldn't initialize dispatchTab.ContextInitToClient"); 101 return false; 102 } 103 dispatchTab.ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient"); 104 if (dispatchTab.ContextDeinitToClient == NULL) { 105 LOG_API("Couldn't initialize dispatchTab.ContextDeinitToClient"); 106 return false; 107 } 108 dispatchTab.TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"); 109 if (dispatchTab.TypeCreate == NULL) { 110 LOG_API("Couldn't initialize dispatchTab.TypeCreate"); 111 return false; 112 } 113 dispatchTab.AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped"); 114 if (dispatchTab.AllocationCreateTyped == NULL) { 115 LOG_API("Couldn't initialize dispatchTab.AllocationCreateTyped"); 116 return false; 117 } 118 dispatchTab.AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap"); 119 if (dispatchTab.AllocationCreateFromBitmap == NULL) { 120 LOG_API("Couldn't initialize dispatchTab.AllocationCreateFromBitmap"); 121 return false; 122 } 123 dispatchTab.AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap"); 124 if (dispatchTab.AllocationCubeCreateFromBitmap == NULL) { 125 LOG_API("Couldn't initialize dispatchTab.AllocationCubeCreateFromBitmap"); 126 return false; 127 } 128 dispatchTab.AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"); 129 if (dispatchTab.AllocationGetSurface == NULL) { 130 LOG_API("Couldn't initialize dispatchTab.AllocationGetSurface"); 131 return false; 132 } 133 dispatchTab.AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"); 134 if (dispatchTab.AllocationSetSurface == NULL) { 135 LOG_API("Couldn't initialize dispatchTab.AllocationSetSurface"); 136 return false; 137 } 138 dispatchTab.ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"); 139 if (dispatchTab.ContextFinish == NULL) { 140 LOG_API("Couldn't initialize dispatchTab.ContextFinish"); 141 return false; 142 } 143 dispatchTab.ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"); 144 if (dispatchTab.ContextDump == NULL) { 145 LOG_API("Couldn't initialize dispatchTab.ContextDump"); 146 return false; 147 } 148 dispatchTab.ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"); 149 if (dispatchTab.ContextSetPriority == NULL) { 150 LOG_API("Couldn't initialize dispatchTab.ContextSetPriority"); 151 return false; 152 } 153 dispatchTab.AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"); 154 if (dispatchTab.AssignName == NULL) { 155 LOG_API("Couldn't initialize dispatchTab.AssignName"); 156 return false; 157 } 158 dispatchTab.ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"); 159 if (dispatchTab.ObjDestroy == NULL) { 160 LOG_API("Couldn't initialize dispatchTab.ObjDestroy"); 161 return false; 162 } 163 dispatchTab.ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"); 164 if (dispatchTab.ElementCreate == NULL) { 165 LOG_API("Couldn't initialize dispatchTab.ElementCreate"); 166 return false; 167 } 168 dispatchTab.ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"); 169 if (dispatchTab.ElementCreate2 == NULL) { 170 LOG_API("Couldn't initialize dispatchTab.ElementCreate2"); 171 return false; 172 } 173 dispatchTab.AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap"); 174 if (dispatchTab.AllocationCopyToBitmap == NULL) { 175 LOG_API("Couldn't initialize dispatchTab.AllocationCopyToBitmap"); 176 return false; 177 } 178 dispatchTab.Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"); 179 if (dispatchTab.Allocation1DData == NULL) { 180 LOG_API("Couldn't initialize dispatchTab.Allocation1DData"); 181 return false; 182 } 183 dispatchTab.Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData"); 184 if (dispatchTab.Allocation1DElementData == NULL) { 185 LOG_API("Couldn't initialize dispatchTab.Allocation1DElementData"); 186 return false; 187 } 188 dispatchTab.Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"); 189 if (dispatchTab.Allocation2DData == NULL) { 190 LOG_API("Couldn't initialize dispatchTab.Allocation2DData"); 191 return false; 192 } 193 dispatchTab.Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"); 194 if (dispatchTab.Allocation3DData == NULL) { 195 LOG_API("Couldn't initialize dispatchTab.Allocation3DData"); 196 return false; 197 } 198 dispatchTab.AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps"); 199 if (dispatchTab.AllocationGenerateMipmaps == NULL) { 200 LOG_API("Couldn't initialize dispatchTab.AllocationGenerateMipmaps"); 201 return false; 202 } 203 dispatchTab.AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"); 204 if (dispatchTab.AllocationRead == NULL) { 205 LOG_API("Couldn't initialize dispatchTab.AllocationRead"); 206 return false; 207 } 208 dispatchTab.Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"); 209 if (dispatchTab.Allocation1DRead == NULL) { 210 LOG_API("Couldn't initialize dispatchTab.Allocation1DRead"); 211 return false; 212 } 213 dispatchTab.Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"); 214 if (dispatchTab.Allocation2DRead == NULL) { 215 LOG_API("Couldn't initialize dispatchTab.Allocation2DRead"); 216 return false; 217 } 218 dispatchTab.AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"); 219 if (dispatchTab.AllocationSyncAll == NULL) { 220 LOG_API("Couldn't initialize dispatchTab.AllocationSyncAll"); 221 return false; 222 } 223 dispatchTab.AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"); 224 if (dispatchTab.AllocationResize1D == NULL) { 225 LOG_API("Couldn't initialize dispatchTab.AllocationResize1D"); 226 return false; 227 } 228 dispatchTab.AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange"); 229 if (dispatchTab.AllocationCopy2DRange == NULL) { 230 LOG_API("Couldn't initialize dispatchTab.AllocationCopy2DRange"); 231 return false; 232 } 233 dispatchTab.AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange"); 234 if (dispatchTab.AllocationCopy3DRange == NULL) { 235 LOG_API("Couldn't initialize dispatchTab.AllocationCopy3DRange"); 236 return false; 237 } 238 dispatchTab.SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"); 239 if (dispatchTab.SamplerCreate == NULL) { 240 LOG_API("Couldn't initialize dispatchTab.SamplerCreate"); 241 return false; 242 } 243 dispatchTab.ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"); 244 if (dispatchTab.ScriptBindAllocation == NULL) { 245 LOG_API("Couldn't initialize dispatchTab.ScriptBindAllocation"); 246 return false; 247 } 248 dispatchTab.ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"); 249 if (dispatchTab.ScriptSetTimeZone == NULL) { 250 LOG_API("Couldn't initialize dispatchTab.ScriptSetTimeZone"); 251 return false; 252 } 253 dispatchTab.ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"); 254 if (dispatchTab.ScriptInvoke == NULL) { 255 LOG_API("Couldn't initialize dispatchTab.ScriptInvoke"); 256 return false; 257 } 258 dispatchTab.ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"); 259 if (dispatchTab.ScriptInvokeV == NULL) { 260 LOG_API("Couldn't initialize dispatchTab.ScriptInvokeV"); 261 return false; 262 } 263 dispatchTab.ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach"); 264 if (dispatchTab.ScriptForEach == NULL) { 265 LOG_API("Couldn't initialize dispatchTab.ScriptForEach"); 266 return false; 267 } 268 dispatchTab.ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"); 269 if (dispatchTab.ScriptSetVarI == NULL) { 270 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarI"); 271 return false; 272 } 273 dispatchTab.ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"); 274 if (dispatchTab.ScriptSetVarObj == NULL) { 275 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarObj"); 276 return false; 277 } 278 dispatchTab.ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"); 279 if (dispatchTab.ScriptSetVarJ == NULL) { 280 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarJ"); 281 return false; 282 } 283 dispatchTab.ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"); 284 if (dispatchTab.ScriptSetVarF == NULL) { 285 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarF"); 286 return false; 287 } 288 dispatchTab.ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"); 289 if (dispatchTab.ScriptSetVarD == NULL) { 290 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarD"); 291 return false; 292 } 293 dispatchTab.ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"); 294 if (dispatchTab.ScriptSetVarV == NULL) { 295 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarV"); 296 return false; 297 } 298 dispatchTab.ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"); 299 if (dispatchTab.ScriptGetVarV == NULL) { 300 LOG_API("Couldn't initialize dispatchTab.ScriptGetVarV"); 301 return false; 302 } 303 dispatchTab.ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"); 304 if (dispatchTab.ScriptSetVarVE == NULL) { 305 LOG_API("Couldn't initialize dispatchTab.ScriptSetVarVE"); 306 return false; 307 } 308 dispatchTab.ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"); 309 if (dispatchTab.ScriptCCreate == NULL) { 310 LOG_API("Couldn't initialize dispatchTab.ScriptCCreate"); 311 return false; 312 } 313 dispatchTab.ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate"); 314 if (dispatchTab.ScriptIntrinsicCreate == NULL) { 315 LOG_API("Couldn't initialize dispatchTab.ScriptIntrinsicCreate"); 316 return false; 317 } 318 dispatchTab.ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"); 319 if (dispatchTab.ScriptKernelIDCreate == NULL) { 320 LOG_API("Couldn't initialize dispatchTab.ScriptKernelIDCreate"); 321 return false; 322 } 323 dispatchTab.ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"); 324 if (dispatchTab.ScriptFieldIDCreate == NULL) { 325 LOG_API("Couldn't initialize dispatchTab.ScriptFieldIDCreate"); 326 return false; 327 } 328 dispatchTab.ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"); 329 if (dispatchTab.ScriptGroupCreate == NULL) { 330 LOG_API("Couldn't initialize dispatchTab.ScriptGroupCreate"); 331 return false; 332 } 333 dispatchTab.ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"); 334 if (dispatchTab.ScriptGroupSetOutput == NULL) { 335 LOG_API("Couldn't initialize dispatchTab.ScriptGroupSetOutput"); 336 return false; 337 } 338 dispatchTab.ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"); 339 if (dispatchTab.ScriptGroupSetInput == NULL) { 340 LOG_API("Couldn't initialize dispatchTab.ScriptGroupSetInput"); 341 return false; 342 } 343 dispatchTab.ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"); 344 if (dispatchTab.ScriptGroupExecute == NULL) { 345 LOG_API("Couldn't initialize dispatchTab.ScriptGroupExecute"); 346 return false; 347 } 348 dispatchTab.AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"); 349 if (dispatchTab.AllocationIoSend == NULL) { 350 LOG_API("Couldn't initialize dispatchTab.AllocationIoSend"); 351 return false; 352 } 353 dispatchTab.AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"); 354 if (dispatchTab.AllocationIoReceive == NULL) { 355 LOG_API("Couldn't initialize dispatchTab.AllocationIoReceive"); 356 return false; 357 } 358 dispatchTab.AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer"); 359 if (dispatchTab.AllocationGetPointer == NULL) { 360 LOG_API("Couldn't initialize dispatchTab.AllocationGetPointer"); 361 return false; 362 } 363 364 // API_23 functions 365 if (device_api >= 23) { 366 //ScriptGroup V2 functions 367 dispatchTab.ScriptInvokeIDCreate = (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate"); 368 if (dispatchTab.ScriptInvokeIDCreate == NULL) { 369 LOG_API("Couldn't initialize dispatchTab.ScriptInvokeIDCreate"); 370 return false; 371 } 372 dispatchTab.ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate"); 373 if (dispatchTab.ClosureCreate == NULL) { 374 LOG_API("Couldn't initialize dispatchTab.ClosureCreate"); 375 return false; 376 } 377 dispatchTab.ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg"); 378 if (dispatchTab.ClosureSetArg == NULL) { 379 LOG_API("Couldn't initialize dispatchTab.ClosureSetArg"); 380 return false; 381 } 382 dispatchTab.ClosureSetGlobal = (ClosureSetGlobalFnPtr)dlsym(handle, "rsClosureSetGlobal"); 383 if (dispatchTab.ClosureSetGlobal == NULL) { 384 LOG_API("Couldn't initialize dispatchTab.ClosureSetGlobal"); 385 return false; 386 } 387 dispatchTab.ScriptGroup2Create = (ScriptGroup2CreateFnPtr)dlsym(handle, "rsScriptGroup2Create"); 388 if (dispatchTab.ScriptGroup2Create == NULL) { 389 LOG_API("Couldn't initialize dispatchTab.ScriptGroup2Create"); 390 return false; 391 } 392 } 393 394 return true; 395 396} 397 398 399bool loadIOSuppSyms(void* handleIO, ioSuppDT& ioDispatch){ 400 ioDispatch.sAllocationSetSurface = (sAllocationSetSurfaceFnPtr)dlsym(handleIO, "AllocationSetSurface"); 401 if (ioDispatch.sAllocationSetSurface == NULL) { 402 LOG_API("Couldn't initialize ioDispatch.sAllocationSetSurface"); 403 return false; 404 } 405 return true; 406} 407