RenderScript.cpp revision 87c9d77a3be0dff4a4413bbb6f5b91014896e048
15a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller/* 25a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * Copyright (C) 2013 The Android Open Source Project 35a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * 45a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * Licensed under the Apache License, Version 2.0 (the "License"); 55a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * you may not use this file except in compliance with the License. 65a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * You may obtain a copy of the License at 75a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * 85a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * http://www.apache.org/licenses/LICENSE-2.0 95a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * 105a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * Unless required by applicable law or agreed to in writing, software 115a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * distributed under the License is distributed on an "AS IS" BASIS, 125a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * See the License for the specific language governing permissions and 145a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller * limitations under the License. 155a8daad469c22b9b48fdf3ac478991e4ddefdf1eJim Miller */ 165ecd81154fa039961f65bb4e36d18ac555b0d1d6Jim Miller 17838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller#include <malloc.h> 187751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller#include <string.h> 197751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller#include <pthread.h> 203a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani 21838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller#include "RenderScript.h" 223a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani#include "rsCppStructs.h" 23838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller#include "rsCppInternal.h" 247751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 257751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller#include <dlfcn.h> 267751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 27052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren#if !defined(RS_SERVER) && defined(HAVE_ANDROID_OS) 287751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller#include <cutils/properties.h> 29838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller#endif 30838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller 317751ff6cd079e59e3c1f2404198774cd371ea69fJim Millerusing namespace android; 327751ff6cd079e59e3c1f2404198774cd371ea69fJim Millerusing namespace RSC; 337751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 347751ff6cd079e59e3c1f2404198774cd371ea69fJim Millerbool RS::gInitialized = false; 355cf17879a31b7b78c09ec50b727f921840dcf783Jorim Jaggibool RS::usingNative = false; 367751ff6cd079e59e3c1f2404198774cd371ea69fJim Millerpthread_mutex_t RS::gInitMutex = PTHREAD_MUTEX_INITIALIZER; 373a3d212a51974ccec6100c1e117225291edc83ccAmith YamasanidispatchTable* RS::dispatch = NULL; 383a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasanistatic int gInitError = 0; 393a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani 403a3d212a51974ccec6100c1e117225291edc83ccAmith YamasaniRS::RS() { 413a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani mDev = NULL; 427751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mContext = NULL; 437751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mErrorFunc = NULL; 447751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mMessageFunc = NULL; 457751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mMessageRun = false; 467751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mInit = false; 477751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mCurrentError = RS_SUCCESS; 487751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 497751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller memset(&mElements, 0, sizeof(mElements)); 50336be7f7a499eec1acd90ab04d3e47d2789c8168Adrian Roos memset(&mSamplers, 0, sizeof(mSamplers)); 51336be7f7a499eec1acd90ab04d3e47d2789c8168Adrian Roos} 527751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 537751ff6cd079e59e3c1f2404198774cd371ea69fJim MillerRS::~RS() { 54ba7d94b8f3c41fd5b933b185e7463a56589e04d2Jim Miller if (mInit == true) { 55b690f0d5023fcf144f2701058d5a6f88d66cc97aJorim Jaggi mMessageRun = false; 56ba7d94b8f3c41fd5b933b185e7463a56589e04d2Jim Miller 5725b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi RS::dispatch->ContextDeinitToClient(mContext); 5825b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi 5925b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi void *res = NULL; 6025b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi int status = pthread_join(mMessageThreadId, &res); 6125b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi 6225b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi RS::dispatch->ContextDestroy(mContext); 6372b46d429cbab54af962c25ffe087c5f927f7340Andrew Lee mContext = NULL; 647751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->DeviceDestroy(mDev); 657751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mDev = NULL; 66838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller } 67838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller} 68838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller 69838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Millerbool RS::init(uint32_t flags) { 70838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller return RS::init(RS_VERSION, flags); 71fe0f24cc92b04e03cac3f807859721f1ce7ef54aEsteban Talavera} 72838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller 73838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Millerstatic bool loadSymbols(void* handle) { 74838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller 75838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType"); 767751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationGetType == NULL) { 777751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationGetType"); 78336be7f7a499eec1acd90ab04d3e47d2789c8168Adrian Roos return false; 797751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 807751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData"); 817751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->TypeGetNativeData == NULL) { 827751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->TypeGetNativeData"); 837751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 847751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 857751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData"); 867751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ElementGetNativeData == NULL) { 87f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->ElementGetNativeData"); 88f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi return false; 89f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi } 907751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements"); 917751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ElementGetSubElements == NULL) { 927751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ElementGetSubElements"); 937751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 94f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi } 95f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate"); 96f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi if (RS::dispatch->DeviceCreate == NULL) { 977751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->DeviceCreate"); 987751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 99c14f829506a5273e8022b461db2d61038b18ac4bJorim Jaggi } 100f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy"); 101f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi if (RS::dispatch->DeviceDestroy == NULL) { 102f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->DeviceDestroy"); 103c14f829506a5273e8022b461db2d61038b18ac4bJorim Jaggi return false; 104c14f829506a5273e8022b461db2d61038b18ac4bJorim Jaggi } 10576a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig"); 10676a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi if (RS::dispatch->DeviceSetConfig == NULL) { 10776a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->DeviceSetConfig"); 10876a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi return false; 10976a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi } 11076a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");; 11176a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi if (RS::dispatch->ContextCreate == NULL) { 11276a1623afc170a13923b68f3256057d8adeb7937Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->ContextCreate"); 1137751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1147751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1157751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");; 1167751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->GetName == NULL) { 1177751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->GetName"); 1187751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1197751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 120c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy"); 121c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi if (RS::dispatch->ContextDestroy == NULL) { 122c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->ContextDestroy"); 123c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi return false; 124c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi } 125c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage"); 126c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi if (RS::dispatch->ContextGetMessage == NULL) { 127c1dff8cee8cf334906c1572cc3c50fbff96d1839Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->ContextGetMessage"); 1287751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1297751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1307751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage"); 1317751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ContextPeekMessage == NULL) { 1327751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ContextPeekMessage"); 1337751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1347751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1357751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage"); 1367751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ContextSendMessage == NULL) { 1377751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ContextSendMessage"); 1387751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1397751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1407751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient"); 1417751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ContextInitToClient == NULL) { 1427751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ContextInitToClient"); 1437751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1446b88cdfba770efc5722338c240ccaada13d7b0d4Jorim Jaggi } 1457751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient"); 1467751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ContextDeinitToClient == NULL) { 1477751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ContextDeinitToClient"); 1487751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1497751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1507751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate"); 1516b88cdfba770efc5722338c240ccaada13d7b0d4Jorim Jaggi if (RS::dispatch->TypeCreate == NULL) { 1527751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->TypeCreate"); 1537751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1547751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1557751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped"); 1567751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationCreateTyped == NULL) { 1577751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationCreateTyped"); 1587751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1597751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1607751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap"); 1617751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationCreateFromBitmap == NULL) { 1627751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationCreateFromBitmap"); 1637751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1647751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1657751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap"); 1667751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationCubeCreateFromBitmap == NULL) { 1677751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationCubeCreateFromBitmap"); 1687751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1697751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1707751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface"); 1717751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationGetSurface == NULL) { 1727751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationGetSurface"); 1737751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1747751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1757751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface"); 1767751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationSetSurface == NULL) { 1777751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationSetSurface"); 1787751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1797751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1807751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish"); 1817751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ContextFinish == NULL) { 1827751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ContextFinish"); 1837751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1842397427cb1a0bad8a42e6a342dcf29b31e40a234Andres Morales } 1852397427cb1a0bad8a42e6a342dcf29b31e40a234Andres Morales RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump"); 1867751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ContextDump == NULL) { 1877751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ContextDump"); 1887751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1897751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1907751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority"); 1917751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ContextSetPriority == NULL) { 1927751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ContextSetPriority"); 1937751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1947751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 1957751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName"); 1967751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AssignName == NULL) { 1977751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AssignName"); 1987751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 1997751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 2007751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy"); 2017751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ObjDestroy == NULL) { 2027751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ObjDestroy"); 2037751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2047751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 2057751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate"); 2067751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ElementCreate == NULL) { 2077751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ElementCreate"); 208ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia return false; 209ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia } 2107751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2"); 2117751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ElementCreate2 == NULL) { 2127751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ElementCreate2"); 2137751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2147751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 2153a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap"); 2163a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->AllocationCopyToBitmap == NULL) { 2173a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->AllocationCopyToBitmap"); 2183a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani return false; 2193a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2203a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData"); 2213a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->Allocation1DData == NULL) { 2223a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->Allocation1DData"); 2233a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani return false; 2243a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2253a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData"); 2263a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->Allocation1DElementData == NULL) { 2273a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->Allocation1DElementData"); 2283a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani return false; 2293a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2303a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData"); 2317751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->Allocation2DData == NULL) { 2327751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->Allocation2DData"); 2337751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2343a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2353a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData"); 2363a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->Allocation3DData == NULL) { 2373a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->Allocation3DData"); 2383a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani return false; 2393a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2403a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps"); 2413a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->AllocationGenerateMipmaps == NULL) { 2423a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->AllocationGenerateMipmaps"); 2433a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani return false; 2443a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2453a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead"); 2463a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->AllocationRead == NULL) { 2473a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->AllocationRead"); 2483a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani return false; 2493a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2507751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead"); 2517751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->Allocation1DRead == NULL) { 2527751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->Allocation1DRead"); 253ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia return false; 2547751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 255ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead"); 2567751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->Allocation2DRead == NULL) { 2577751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->Allocation2DRead"); 2587751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2593a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2603a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll"); 261ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia if (RS::dispatch->AllocationSyncAll == NULL) { 2627751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationSyncAll"); 2637751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2647751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 2657751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D"); 2667751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationResize1D == NULL) { 267fe0f24cc92b04e03cac3f807859721f1ce7ef54aEsteban Talavera ALOGV("Couldn't initialize RS::dispatch->AllocationResize1D"); 268fe0f24cc92b04e03cac3f807859721f1ce7ef54aEsteban Talavera return false; 269fe0f24cc92b04e03cac3f807859721f1ce7ef54aEsteban Talavera } 2703a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange"); 271ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia if (RS::dispatch->AllocationCopy2DRange == NULL) { 2723a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->AllocationCopy2DRange"); 273ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia return false; 274cc791bc47c004967557c44abe1764f1f2f7aef8bXiaohui Chen } 275cc791bc47c004967557c44abe1764f1f2f7aef8bXiaohui Chen RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange"); 2763a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->AllocationCopy3DRange == NULL) { 2773a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->AllocationCopy3DRange"); 2783a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani return false; 2793a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani } 2803a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate"); 2817751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->SamplerCreate == NULL) { 2823a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani ALOGV("Couldn't initialize RS::dispatch->SamplerCreate"); 2837751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2847751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 2853a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation"); 2863a3d212a51974ccec6100c1e117225291edc83ccAmith Yamasani if (RS::dispatch->ScriptBindAllocation == NULL) { 2877751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptBindAllocation"); 2887751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 289ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia } 290ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone"); 2912397427cb1a0bad8a42e6a342dcf29b31e40a234Andres Morales if (RS::dispatch->ScriptSetTimeZone == NULL) { 2922397427cb1a0bad8a42e6a342dcf29b31e40a234Andres Morales ALOGV("Couldn't initialize RS::dispatch->ScriptSetTimeZone"); 2937751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2947751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 2957751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke"); 2967751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptInvoke == NULL) { 2977751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptInvoke"); 2987751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 2997751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3007751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV"); 3017751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptInvokeV == NULL) { 3027751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptInvokeV"); 3037751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3047751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3057751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach"); 3067751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptForEach == NULL) { 3077751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptForEach"); 308ba7d94b8f3c41fd5b933b185e7463a56589e04d2Jim Miller return false; 309ba7d94b8f3c41fd5b933b185e7463a56589e04d2Jim Miller } 310ba7d94b8f3c41fd5b933b185e7463a56589e04d2Jim Miller RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI"); 311ba7d94b8f3c41fd5b933b185e7463a56589e04d2Jim Miller if (RS::dispatch->ScriptSetVarI == NULL) { 3127751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarI"); 3137751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3147751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 31525b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj"); 316e8bae6288bf0f241f0cea70f2c5e8294f930d4d8Selim Cinek if (RS::dispatch->ScriptSetVarObj == NULL) { 317e8bae6288bf0f241f0cea70f2c5e8294f930d4d8Selim Cinek ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarObj"); 318336be7f7a499eec1acd90ab04d3e47d2789c8168Adrian Roos return false; 319336be7f7a499eec1acd90ab04d3e47d2789c8168Adrian Roos } 3207751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ"); 3217751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptSetVarJ == NULL) { 3227751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarJ"); 3237751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3247751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3257751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF"); 3267751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptSetVarF == NULL) { 3277751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarF"); 3287751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3297751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3307751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD"); 33125b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi if (RS::dispatch->ScriptSetVarD == NULL) { 3327751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarD"); 3337751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3347751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3357751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV"); 3367751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptSetVarV == NULL) { 3377751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarV"); 3387751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 339245273ec8dd33f10f2682f140057ea0e5b270ef8Selim Cinek } 340245273ec8dd33f10f2682f140057ea0e5b270ef8Selim Cinek RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV"); 341245273ec8dd33f10f2682f140057ea0e5b270ef8Selim Cinek if (RS::dispatch->ScriptGetVarV == NULL) { 3427751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptGetVarV"); 3437751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3447751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3457751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE"); 3467751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptSetVarVE == NULL) { 3477751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarVE"); 3487751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3497751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3507751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate"); 3517751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptCCreate == NULL) { 3527751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptCCreate"); 3537751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3547751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 35525b4d4b280c6aa07656328bd9dd90977781d00e1Jorim Jaggi RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate"); 3567751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptIntrinsicCreate == NULL) { 3577751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptIntrinsicCreate"); 3587751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3597751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3607751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate"); 3617751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptKernelIDCreate == NULL) { 3627751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptKernelIDCreate"); 3637751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3647751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3657751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate"); 3667751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptFieldIDCreate == NULL) { 3677751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptFieldIDCreate"); 3687751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3697751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3707751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate"); 3717751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptGroupCreate == NULL) { 3727751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptGroupCreate"); 3737751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3747751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3757751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput"); 3767751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptGroupSetOutput == NULL) { 3777751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetOutput"); 3787751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 379f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi } 380f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput"); 381f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi if (RS::dispatch->ScriptGroupSetInput == NULL) { 382f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetInput"); 3837751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3847751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3857751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute"); 3867751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->ScriptGroupExecute == NULL) { 3877751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->ScriptGroupExecute"); 3887751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3897751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3907751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend"); 3917751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (RS::dispatch->AllocationIoSend == NULL) { 3927751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("Couldn't initialize RS::dispatch->AllocationIoSend"); 3937751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3947751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 3957751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive"); 396f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi if (RS::dispatch->AllocationIoReceive == NULL) { 397f479792e05485a536c3fa68db9d8a71f34591b78Jorim Jaggi ALOGV("Couldn't initialize RS::dispatch->AllocationIoReceive"); 3987751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 3997751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4007751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 401052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren return true; 402052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren} 403052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren 404c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren// this will only open API 19+ libRS 405052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren// because that's when we changed libRS to extern "C" entry points 406052999f3c94df2659e6e3e7730a2810980f718f7Chris Wrenstatic bool loadSO(const char* filename) { 407052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren void* handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL); 408052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren if (handle == NULL) { 409052999f3c94df2659e6e3e7730a2810980f718f7Chris Wren ALOGV("couldn't dlopen %s, %s", filename, dlerror()); 4107751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 411b690f0d5023fcf144f2701058d5a6f88d66cc97aJorim Jaggi } 4127751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 413b690f0d5023fcf144f2701058d5a6f88d66cc97aJorim Jaggi if (loadSymbols(handle) == false) { 4147751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGV("%s init failed!", filename); 4157751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 4167751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4177751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller //ALOGE("Successfully loaded %s", filename); 4187751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return true; 4197751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller} 4207751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4217751ff6cd079e59e3c1f2404198774cd371ea69fJim Millerstatic uint32_t getProp(const char *str) { 4227751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller#if !defined(RS_SERVER) && defined(HAVE_ANDROID_OS) 4237751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller char buf[256]; 4247751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller property_get(str, buf, "0"); 425ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia return atoi(buf); 4267751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller#else 4277751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return 0; 4287751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller#endif 429ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia} 4307751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 431ce64cea38389a75def2f3d933a007515af288714Xiyuan Xiabool RS::initDispatch(int targetApi) { 4327751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller pthread_mutex_lock(&gInitMutex); 4337751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (gInitError) { 4347751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller goto error; 43572b46d429cbab54af962c25ffe087c5f927f7340Andrew Lee } else if (gInitialized) { 43672b46d429cbab54af962c25ffe087c5f927f7340Andrew Lee pthread_mutex_unlock(&gInitMutex); 43772b46d429cbab54af962c25ffe087c5f927f7340Andrew Lee return true; 4387751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4397751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4407751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller RS::dispatch = new dispatchTable; 4417751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4427751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller // attempt to load libRS, load libRSSupport on failure 4437751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller // if property is set, proceed directly to libRSSupport 4447751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (getProp("debug.rs.forcecompat") == 0) { 445b690f0d5023fcf144f2701058d5a6f88d66cc97aJorim Jaggi usingNative = loadSO("libRS.so"); 4467751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 447ce64cea38389a75def2f3d933a007515af288714Xiyuan Xia if (usingNative == false) { 4487751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (loadSO("libRSSupport.so") == false) { 4497751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGE("Failed to load libRS.so and libRSSupport.so"); 4507751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller goto error; 4517751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 45272b46d429cbab54af962c25ffe087c5f927f7340Andrew Lee } 45372b46d429cbab54af962c25ffe087c5f927f7340Andrew Lee 4547751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller gInitialized = true; 4557751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4567751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller pthread_mutex_unlock(&gInitMutex); 4577751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return true; 4587751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4597751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller error: 4607751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller gInitError = 1; 4617751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller pthread_mutex_unlock(&gInitMutex); 4627751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 4637751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller} 4647751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4657751ff6cd079e59e3c1f2404198774cd371ea69fJim Millerbool RS::init(int targetApi, uint32_t flags) { 4667751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (initDispatch(targetApi) == false) { 467eff74b48a8e137039473cf251bd5be3f34600522Evan Rosky ALOGE("Couldn't initialize dispatch table"); 4687751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 4697751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4707751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4717751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mDev = RS::dispatch->DeviceCreate(); 4727751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (mDev == 0) { 4737751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGE("Device creation failed"); 4747751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 4757751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4767751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4777751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (flags >= RS_CONTEXT_MAX) { 4787751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGE("Invalid flags passed"); 4797751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 4807751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4817751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4827751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mContext = RS::dispatch->ContextCreate(mDev, 0, targetApi, RS_CONTEXT_TYPE_NORMAL, flags); 48395e89caeb252a54807c76d60c7440766829e418cJorim Jaggi if (mContext == 0) { 48495e89caeb252a54807c76d60c7440766829e418cJorim Jaggi ALOGE("Context creation failed"); 48595e89caeb252a54807c76d60c7440766829e418cJorim Jaggi return false; 48695e89caeb252a54807c76d60c7440766829e418cJorim Jaggi } 4877751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4887751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller pid_t mNativeMessageThreadId; 4897751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 4907751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller int status = pthread_create(&mMessageThreadId, NULL, threadProc, this); 4917751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (status) { 4927751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGE("Failed to start RS message thread."); 4937751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return false; 4947751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4957751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller // Wait for the message thread to be active. 4967751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller while (!mMessageRun) { 4977751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller usleep(1000); 4987751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 4997751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 5007751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mInit = true; 5017751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 5027751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return true; 5037751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller} 5047751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 5057751ff6cd079e59e3c1f2404198774cd371ea69fJim Millervoid RS::throwError(RSError error, const char *errMsg) { 5067751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (mCurrentError == RS_SUCCESS) { 5077751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller mCurrentError = error; 5087751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGE("RS CPP error: %s", errMsg); 5097751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } else { 5107751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGE("RS CPP error (masked by previous error): %s", errMsg); 5117751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 5127751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller} 5137751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 5147751ff6cd079e59e3c1f2404198774cd371ea69fJim MillerRSError RS::getError() { 5157751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller return mCurrentError; 5167751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller} 5177751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 5187751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller 5197751ff6cd079e59e3c1f2404198774cd371ea69fJim Millervoid * RS::threadProc(void *vrsc) { 5203122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek RS *rs = static_cast<RS *>(vrsc); 5213122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek size_t rbuf_size = 256; 522569edb85125e6754de8f8e60f993afad42eed490Adrian Roos void * rbuf = malloc(rbuf_size); 523569edb85125e6754de8f8e60f993afad42eed490Adrian Roos 524569edb85125e6754de8f8e60f993afad42eed490Adrian Roos RS::dispatch->ContextInitToClient(rs->mContext); 5253122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek rs->mMessageRun = true; 5263122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek 5273122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek while (rs->mMessageRun) { 5283122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek size_t receiveLen = 0; 529cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek uint32_t usrID = 0; 530cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek uint32_t subID = 0; 531cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek RsMessageToClientType r = RS::dispatch->ContextPeekMessage(rs->mContext, 532cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek &receiveLen, sizeof(receiveLen), 533cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek &usrID, sizeof(usrID)); 534cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek 535cfafe4ea6ff1610c24d94a9a9ecc7df6b841518cSelim Cinek if (receiveLen >= rbuf_size) { 5363122fa85b2f18c0a89f5fe1ef0942c530a271843Selim Cinek rbuf_size = receiveLen + 32; 5377751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller rbuf = realloc(rbuf, rbuf_size); 5387751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller } 5397751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller if (!rbuf) { 5407751ff6cd079e59e3c1f2404198774cd371ea69fJim Miller ALOGE("RS::message handler realloc error %zu", rbuf_size); 541838906b165e4d3cb2c512b2db344aa50cb5d4751Jim Miller // No clean way to recover now? 542c0ae9e67ebe6f1298800feaed1b43e867139a904Chris Wren } 543 RS::dispatch->ContextGetMessage(rs->mContext, rbuf, rbuf_size, &receiveLen, sizeof(receiveLen), 544 &subID, sizeof(subID)); 545 546 switch(r) { 547 case RS_MESSAGE_TO_CLIENT_ERROR: 548 ALOGE("RS Error %s", (const char *)rbuf); 549 rs->throwError(RS_ERROR_RUNTIME_ERROR, "Error returned from runtime"); 550 if(rs->mMessageFunc != NULL) { 551 rs->mErrorFunc(usrID, (const char *)rbuf); 552 } 553 break; 554 case RS_MESSAGE_TO_CLIENT_NONE: 555 case RS_MESSAGE_TO_CLIENT_EXCEPTION: 556 case RS_MESSAGE_TO_CLIENT_RESIZE: 557 // teardown. But we want to avoid starving other threads during 558 // teardown by yielding until the next line in the destructor can 559 // execute to set mRun = false. Note that the FIFO sends an 560 // empty NONE message when it reaches its destructor. 561 usleep(1000); 562 break; 563 case RS_MESSAGE_TO_CLIENT_USER: 564 if(rs->mMessageFunc != NULL) { 565 rs->mMessageFunc(usrID, rbuf, receiveLen); 566 } else { 567 ALOGE("Received a message from the script with no message handler installed."); 568 } 569 break; 570 571 default: 572 ALOGE("RS unknown message type %i", r); 573 } 574 } 575 576 if (rbuf) { 577 free(rbuf); 578 } 579 ALOGV("RS Message thread exiting."); 580 return NULL; 581} 582 583void RS::setErrorHandler(ErrorHandlerFunc_t func) { 584 mErrorFunc = func; 585} 586 587void RS::setMessageHandler(MessageHandlerFunc_t func) { 588 mMessageFunc = func; 589} 590 591void RS::finish() { 592 RS::dispatch->ContextFinish(mContext); 593} 594