1221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams/* 2a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray * Copyright (C) 2013 The Android Open Source Project 3221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * 4221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 5221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * you may not use this file except in compliance with the License. 6221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * You may obtain a copy of the License at 7221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * 8221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * http://www.apache.org/licenses/LICENSE-2.0 9221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * 10221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * Unless required by applicable law or agreed to in writing, software 11221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * distributed under the License is distributed on an "AS IS" BASIS, 12221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * See the License for the specific language governing permissions and 14221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * limitations under the License. 15221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams */ 16221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 17221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#include <malloc.h> 18221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#include <string.h> 1984bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray#include <pthread.h> 20221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 21221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#include "RenderScript.h" 2289daad6bae798779e57f252e9da4fe4e62337124Tim Murray#include "rsCppStructs.h" 23eeaf7142d7e06efb3e0ddc7ef542884ab1d527dcTim Murray#include "rsCppInternal.h" 24221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 25a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray#include <dlfcn.h> 26a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 274a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray#if !defined(RS_SERVER) && defined(HAVE_ANDROID_OS) 284a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray#include <cutils/properties.h> 294a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray#endif 304a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray 3169cccdf0659a193d6a75420ec745421fb5c436e6Jason Samsusing namespace android; 329eb7f4b90120ebe4be74343856e86b46495f72dfTim Murrayusing namespace RSC; 3369cccdf0659a193d6a75420ec745421fb5c436e6Jason Sams 3484bf2b877024aaa154b66e0f2338d54bdabd855aTim Murraybool RS::gInitialized = false; 354a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murraybool RS::usingNative = false; 3684bf2b877024aaa154b66e0f2338d54bdabd855aTim Murraypthread_mutex_t RS::gInitMutex = PTHREAD_MUTEX_INITIALIZER; 37a423096c0d49e5cfe13a400b4323a76f89c6885cTim MurraydispatchTable* RS::dispatch = NULL; 38a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murraystatic int gInitError = 0; 39221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 4084bf2b877024aaa154b66e0f2338d54bdabd855aTim MurrayRS::RS() { 41221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams mDev = NULL; 42221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams mContext = NULL; 43221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams mErrorFunc = NULL; 44221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams mMessageFunc = NULL; 45221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams mMessageRun = false; 46a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray mInit = false; 4721fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray mCurrentError = RS_SUCCESS; 48221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 49221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams memset(&mElements, 0, sizeof(mElements)); 50729b6fe58aff47c4f666b22bbb7a6d6114ddefa9Tim Murray memset(&mSamplers, 0, sizeof(mSamplers)); 51221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams} 52221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 5384bf2b877024aaa154b66e0f2338d54bdabd855aTim MurrayRS::~RS() { 54a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (mInit == true) { 55a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray mMessageRun = false; 56221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 57a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray RS::dispatch->ContextDeinitToClient(mContext); 58221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 59a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray void *res = NULL; 60a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray int status = pthread_join(mMessageThreadId, &res); 61221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 62a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray RS::dispatch->ContextDestroy(mContext); 63a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray mContext = NULL; 64a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray RS::dispatch->DeviceDestroy(mDev); 65a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray mDev = NULL; 66a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 67221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams} 68221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 6984e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murraybool RS::init(uint32_t flags) { 7084e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray return RS::init(RS_VERSION, flags); 7184bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray} 7284bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray 730b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murraystatic bool loadSymbols(void* handle) { 74a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 750b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"); 76a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationGetType == NULL) { 77a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationGetType"); 780b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 79a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 800b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"); 81a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->TypeGetNativeData == NULL) { 82a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->TypeGetNativeData"); 830b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 84a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 850b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"); 86a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ElementGetNativeData == NULL) { 87a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ElementGetNativeData"); 880b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 89a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 900b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements"); 91a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ElementGetSubElements == NULL) { 92a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ElementGetSubElements"); 930b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 94a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 950b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate"); 96a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->DeviceCreate == NULL) { 97a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->DeviceCreate"); 980b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 99a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1000b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy"); 101a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->DeviceDestroy == NULL) { 102a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->DeviceDestroy"); 1030b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 104a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1050b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig"); 106a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->DeviceSetConfig == NULL) { 107a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->DeviceSetConfig"); 1080b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 109a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1100b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");; 111a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextCreate == NULL) { 112a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextCreate"); 1130b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 114a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1154a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray RS::dispatch->GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");; 1164a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray if (RS::dispatch->GetName == NULL) { 1174a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray ALOGE("Couldn't initialize RS::dispatch->GetName"); 1184a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray return false; 1194a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray } 1200b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"); 121a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextDestroy == NULL) { 122a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextDestroy"); 1230b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 124a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1250b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"); 126a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextGetMessage == NULL) { 127a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextGetMessage"); 1280b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 129a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1300b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"); 131a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextPeekMessage == NULL) { 132a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextPeekMessage"); 1330b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 134a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1350b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"); 136a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextSendMessage == NULL) { 137a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextSendMessage"); 1380b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 139a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1400b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"); 141a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextInitToClient == NULL) { 142a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextInitToClient"); 1430b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 144a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1450b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient"); 146a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextDeinitToClient == NULL) { 147a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextDeinitToClient"); 1480b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 149a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1500b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"); 151a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->TypeCreate == NULL) { 152a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->TypeCreate"); 1530b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 154a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1550b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped"); 156a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationCreateTyped == NULL) { 157a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationCreateTyped"); 1580b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 159a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1600b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap"); 161a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationCreateFromBitmap == NULL) { 162a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationCreateFromBitmap"); 1630b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 164a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1650b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap"); 166a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationCubeCreateFromBitmap == NULL) { 167a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationCubeCreateFromBitmap"); 1680b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 169a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1700b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"); 171a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationGetSurface == NULL) { 172a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationGetSurface"); 1730b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 174a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1750b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"); 176a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationSetSurface == NULL) { 177a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationSetSurface"); 1780b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 179a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1800b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"); 181a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextFinish == NULL) { 182a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextFinish"); 1830b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 184a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1850b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"); 186a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextDump == NULL) { 187a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextDump"); 1880b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 189a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1900b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"); 191a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ContextSetPriority == NULL) { 192a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ContextSetPriority"); 1930b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 194a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 1950b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"); 196a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AssignName == NULL) { 197a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AssignName"); 1980b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 199a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2000b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"); 201a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ObjDestroy == NULL) { 202a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ObjDestroy"); 2030b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 204a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2050b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"); 206a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ElementCreate == NULL) { 207a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ElementCreate"); 2080b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 209a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2100b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"); 211a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ElementCreate2 == NULL) { 212a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ElementCreate2"); 2130b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 214a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2150b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap"); 216a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationCopyToBitmap == NULL) { 217a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationCopyToBitmap"); 2180b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 219a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2200b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"); 221a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->Allocation1DData == NULL) { 222a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->Allocation1DData"); 2230b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 224a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2250b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData"); 226a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->Allocation1DElementData == NULL) { 227a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->Allocation1DElementData"); 2280b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 229a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2300b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"); 231a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->Allocation2DData == NULL) { 232a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->Allocation2DData"); 2330b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 234a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2350b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"); 236a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->Allocation3DData == NULL) { 237a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->Allocation3DData"); 2380b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 239a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2400b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps"); 241a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationGenerateMipmaps == NULL) { 242a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationGenerateMipmaps"); 2430b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 244a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2450b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"); 246a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationRead == NULL) { 247a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationRead"); 2480b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 249a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2500b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"); 251a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->Allocation1DRead == NULL) { 252a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->Allocation1DRead"); 2530b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 254a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2550b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"); 256a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->Allocation2DRead == NULL) { 257a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->Allocation2DRead"); 2580b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 259a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2600b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"); 261a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationSyncAll == NULL) { 262a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationSyncAll"); 2630b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 264a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2650b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"); 266a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationResize1D == NULL) { 267a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationResize1D"); 2680b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 269a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2700b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange"); 271a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationCopy2DRange == NULL) { 272a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationCopy2DRange"); 2730b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 274a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2750b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange"); 276a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationCopy3DRange == NULL) { 277a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationCopy3DRange"); 2780b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 279a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2800b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"); 281a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->SamplerCreate == NULL) { 282a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->SamplerCreate"); 2830b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 284a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2850b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"); 286a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptBindAllocation == NULL) { 287a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptBindAllocation"); 2880b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 289a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2900b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"); 291a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetTimeZone == NULL) { 292a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetTimeZone"); 2930b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 294a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 2950b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"); 296a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptInvoke == NULL) { 297a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptInvoke"); 2980b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 299a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3000b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"); 301a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptInvokeV == NULL) { 302a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptInvokeV"); 3030b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 304a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3050b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach"); 306a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptForEach == NULL) { 307a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptForEach"); 3080b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 309a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3100b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"); 311a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetVarI == NULL) { 312a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarI"); 3130b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 314a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3150b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"); 316a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetVarObj == NULL) { 317a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarObj"); 3180b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 319a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3200b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"); 321a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetVarJ == NULL) { 322a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarJ"); 3230b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 324a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3250b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"); 326a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetVarF == NULL) { 327a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarF"); 3280b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 329a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3300b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"); 331a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetVarD == NULL) { 332a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarD"); 3330b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 334a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3350b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"); 336a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetVarV == NULL) { 337a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarV"); 3380b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 339a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3400b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"); 341a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptGetVarV == NULL) { 342a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptGetVarV"); 3430b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 344a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3450b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"); 346a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptSetVarVE == NULL) { 347a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptSetVarVE"); 3480b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 349a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3500b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"); 351a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptCCreate == NULL) { 352a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptCCreate"); 3530b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 354a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3550b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate"); 356a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptIntrinsicCreate == NULL) { 357a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptIntrinsicCreate"); 3580b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 359a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3600b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"); 361a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptKernelIDCreate == NULL) { 362a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptKernelIDCreate"); 3630b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 364a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3650b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"); 366a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptFieldIDCreate == NULL) { 367a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptFieldIDCreate"); 3680b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 369a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3700b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"); 371a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptGroupCreate == NULL) { 372a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptGroupCreate"); 3730b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 374a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3750b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"); 376a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptGroupSetOutput == NULL) { 377a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptGroupSetOutput"); 3780b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 379a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3800b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"); 381a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptGroupSetInput == NULL) { 382a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptGroupSetInput"); 3830b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 384a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3850b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"); 386a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->ScriptGroupExecute == NULL) { 387a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->ScriptGroupExecute"); 3880b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 389a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3900b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"); 391a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationIoSend == NULL) { 392a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationIoSend"); 3930b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 394a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 3950b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"); 396a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (RS::dispatch->AllocationIoReceive == NULL) { 397a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize RS::dispatch->AllocationIoReceive"); 3980b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return false; 3990b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray } 4000b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray 4010b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return true; 4020b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray} 4030b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray 40475e877d157f9429eb6d8fb1b09c75c5472db161aTim Murray// this will only open API 19+ libRS 40575e877d157f9429eb6d8fb1b09c75c5472db161aTim Murray// because that's when we changed libRS to extern "C" entry points 4064a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murraystatic bool loadSO(const char* filename) { 4074a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray void* handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL); 4084a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray if (handle == NULL) { 4094a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray ALOGE("couldn't dlopen %s, %s", filename, dlerror()); 4104a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray return false; 4114a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray } 4120b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray 4134a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray if (loadSymbols(handle) == false) { 4144a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray ALOGE("%s init failed!", filename); 4154a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray return false; 4164a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray } 41784e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray //ALOGE("Successfully loaded %s", filename); 4184a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray return true; 4194a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray} 4204a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray 4214a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murraystatic uint32_t getProp(const char *str) { 4224a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray#if !defined(RS_SERVER) && defined(HAVE_ANDROID_OS) 4234a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray char buf[256]; 4244a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray property_get(str, buf, "0"); 4254a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray return atoi(buf); 4264a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray#else 4274a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray return 0; 4284a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray#endif 4294a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray} 4304a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray 4314a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murraybool RS::initDispatch(int targetApi) { 4320b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray pthread_mutex_lock(&gInitMutex); 4330b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray if (gInitError) { 4340b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray goto error; 4350b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray } else if (gInitialized) { 43647666f52468d8ce14498fac635125f24f79d3257Tim Murray pthread_mutex_unlock(&gInitMutex); 4370b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray return true; 4380b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray } 4390b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray 4400b8a2be7eb9322ec221383de325be8f30b36fe9aTim Murray RS::dispatch = new dispatchTable; 4414a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray 4424a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray // attempt to load libRS, load libRSSupport on failure 4434a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray // if property is set, proceed directly to libRSSupport 4444a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray if (getProp("debug.rs.forcecompat") == 0) { 4454a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray usingNative = loadSO("libRS.so"); 4464a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray } 4474a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray if (usingNative == false) { 4484a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray if (loadSO("libRSSupport.so") == false) { 4494a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray ALOGE("Failed to load libRS.so and libRSSupport.so"); 4504a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray goto error; 4514a92d1268983edaf329f73c8a5b8860cdbb11596Tim Murray } 452a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 453a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 454a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray gInitialized = true; 455a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 456a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray pthread_mutex_unlock(&gInitMutex); 457a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray return true; 458a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 459a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray error: 460a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray gInitError = 1; 461a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray pthread_mutex_unlock(&gInitMutex); 462a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray return false; 463a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray} 464a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 46584e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murraybool RS::init(int targetApi, uint32_t flags) { 466a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray if (initDispatch(targetApi) == false) { 467a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray ALOGE("Couldn't initialize dispatch table"); 468a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray return false; 469a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray } 470a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 471a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray mDev = RS::dispatch->DeviceCreate(); 472221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if (mDev == 0) { 473221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams ALOGE("Device creation failed"); 474221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams return false; 475221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 476221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 47784e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray if (flags >= RS_CONTEXT_MAX) { 47884e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray ALOGE("Invalid flags passed"); 47984e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray return false; 48084e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray } 48184e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray 48284e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray mContext = RS::dispatch->ContextCreate(mDev, 0, targetApi, RS_CONTEXT_TYPE_NORMAL, flags); 483221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if (mContext == 0) { 484221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams ALOGE("Context creation failed"); 485221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams return false; 486221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 487221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 488221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams pid_t mNativeMessageThreadId; 489221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 490221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams int status = pthread_create(&mMessageThreadId, NULL, threadProc, this); 491221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if (status) { 49284bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray ALOGE("Failed to start RS message thread."); 493221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams return false; 494221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 495221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams // Wait for the message thread to be active. 496221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams while (!mMessageRun) { 497221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams usleep(1000); 498221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 499221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 500a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray mInit = true; 501a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray 502221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams return true; 503221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams} 504221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 50521fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murrayvoid RS::throwError(RSError error, const char *errMsg) { 50621fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray if (mCurrentError == RS_SUCCESS) { 50721fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray mCurrentError = error; 50821fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray ALOGE("RS CPP error: %s", errMsg); 50921fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray } else { 51021fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray ALOGE("RS CPP error (masked by previous error): %s", errMsg); 51121fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray } 512b2e3dc51dcbbe52b5e72d9c6a16de7000de70edfJason Sams} 513b2e3dc51dcbbe52b5e72d9c6a16de7000de70edfJason Sams 51410913a5c37ba119bef335320d3e8be25212c05adTim MurrayRSError RS::getError() { 51510913a5c37ba119bef335320d3e8be25212c05adTim Murray return mCurrentError; 51610913a5c37ba119bef335320d3e8be25212c05adTim Murray} 51710913a5c37ba119bef335320d3e8be25212c05adTim Murray 518b2e3dc51dcbbe52b5e72d9c6a16de7000de70edfJason Sams 51984bf2b877024aaa154b66e0f2338d54bdabd855aTim Murrayvoid * RS::threadProc(void *vrsc) { 52084bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray RS *rs = static_cast<RS *>(vrsc); 521221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams size_t rbuf_size = 256; 522221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams void * rbuf = malloc(rbuf_size); 523221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 524a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray RS::dispatch->ContextInitToClient(rs->mContext); 525221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams rs->mMessageRun = true; 526221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 527221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams while (rs->mMessageRun) { 528221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams size_t receiveLen = 0; 529221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams uint32_t usrID = 0; 530221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams uint32_t subID = 0; 531a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray RsMessageToClientType r = RS::dispatch->ContextPeekMessage(rs->mContext, 532a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray &receiveLen, sizeof(receiveLen), 533a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray &usrID, sizeof(usrID)); 534221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 535221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if (receiveLen >= rbuf_size) { 536221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams rbuf_size = receiveLen + 32; 537221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams rbuf = realloc(rbuf, rbuf_size); 538221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 539221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if (!rbuf) { 54084bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray ALOGE("RS::message handler realloc error %zu", rbuf_size); 541221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams // No clean way to recover now? 542221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 543a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray RS::dispatch->ContextGetMessage(rs->mContext, rbuf, rbuf_size, &receiveLen, sizeof(receiveLen), 544221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams &subID, sizeof(subID)); 545221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 546221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams switch(r) { 547221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams case RS_MESSAGE_TO_CLIENT_ERROR: 548221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams ALOGE("RS Error %s", (const char *)rbuf); 54921fa7a0a23eddab88ff261017f6d7a2548b4d89aTim Murray rs->throwError(RS_ERROR_RUNTIME_ERROR, "Error returned from runtime"); 550221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if(rs->mMessageFunc != NULL) { 551221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams rs->mErrorFunc(usrID, (const char *)rbuf); 552221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 553221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams break; 55476a1be4a35267cf0814fb85fb9b1b5bf887e6ae7Stephen Hines case RS_MESSAGE_TO_CLIENT_NONE: 555221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams case RS_MESSAGE_TO_CLIENT_EXCEPTION: 55676a1be4a35267cf0814fb85fb9b1b5bf887e6ae7Stephen Hines case RS_MESSAGE_TO_CLIENT_RESIZE: 557221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams // teardown. But we want to avoid starving other threads during 558221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams // teardown by yielding until the next line in the destructor can 55976a1be4a35267cf0814fb85fb9b1b5bf887e6ae7Stephen Hines // execute to set mRun = false. Note that the FIFO sends an 56076a1be4a35267cf0814fb85fb9b1b5bf887e6ae7Stephen Hines // empty NONE message when it reaches its destructor. 561221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams usleep(1000); 562221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams break; 563221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams case RS_MESSAGE_TO_CLIENT_USER: 564221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if(rs->mMessageFunc != NULL) { 565221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams rs->mMessageFunc(usrID, rbuf, receiveLen); 566221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } else { 567221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams ALOGE("Received a message from the script with no message handler installed."); 568221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 569221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams break; 570221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 571221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams default: 57284bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray ALOGE("RS unknown message type %i", r); 573221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 574221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 575221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 576221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams if (rbuf) { 577221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams free(rbuf); 578221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams } 57984bf2b877024aaa154b66e0f2338d54bdabd855aTim Murray ALOGE("RS Message thread exiting."); 580221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams return NULL; 581221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams} 582221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 58384bf2b877024aaa154b66e0f2338d54bdabd855aTim Murrayvoid RS::setErrorHandler(ErrorHandlerFunc_t func) { 584221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams mErrorFunc = func; 585221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams} 586221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams 58784bf2b877024aaa154b66e0f2338d54bdabd855aTim Murrayvoid RS::setMessageHandler(MessageHandlerFunc_t func) { 588221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams mMessageFunc = func; 589221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams} 590baca6c3c3d79a324c7976ba873afdded0b6bcfb5Tim Murray 591baca6c3c3d79a324c7976ba873afdded0b6bcfb5Tim Murrayvoid RS::finish() { 592a423096c0d49e5cfe13a400b4323a76f89c6885cTim Murray RS::dispatch->ContextFinish(mContext); 593baca6c3c3d79a324c7976ba873afdded0b6bcfb5Tim Murray} 594