blob: 44747414b58d9a53e22be29ff00743bd37b7ac16 [file] [log] [blame]
Jason Sams221a4b12012-02-22 15:22:41 -08001/*
Tim Murraya4230962013-07-17 16:50:10 -07002 * Copyright (C) 2013 The Android Open Source Project
Jason Sams221a4b12012-02-22 15:22:41 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Sams221a4b12012-02-22 15:22:41 -080017#include <malloc.h>
18#include <string.h>
Tim Murray84bf2b82012-10-31 16:03:16 -070019#include <pthread.h>
Jason Sams221a4b12012-02-22 15:22:41 -080020
21#include "RenderScript.h"
Tim Murray89daad62013-07-29 14:30:02 -070022#include "rsCppStructs.h"
Tim Murrayeeaf7142013-09-09 15:03:50 -070023#include "rsCppInternal.h"
Jason Sams66f0a162014-11-11 13:46:38 -080024#include "rsDispatch.h"
Jason Sams221a4b12012-02-22 15:22:41 -080025
Tim Murraya4230962013-07-17 16:50:10 -070026#include <dlfcn.h>
Tim Murray0f98d502014-01-15 14:35:31 -080027#include <unistd.h>
Tim Murraya4230962013-07-17 16:50:10 -070028
Tim Murray0f98d502014-01-15 14:35:31 -080029#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) && defined(HAVE_ANDROID_OS)
Tim Murray4a92d122013-07-22 10:56:18 -070030#include <cutils/properties.h>
Tim Murray0f98d502014-01-15 14:35:31 -080031#else
32#include "rsCompatibilityLib.h"
Tim Murray4a92d122013-07-22 10:56:18 -070033#endif
34
Tim Murray0f98d502014-01-15 14:35:31 -080035
Jason Sams69cccdf2012-04-02 19:11:49 -070036using namespace android;
Tim Murray9eb7f4b2012-11-16 14:02:18 -080037using namespace RSC;
Jason Sams69cccdf2012-04-02 19:11:49 -070038
Tim Murray84bf2b82012-10-31 16:03:16 -070039bool RS::gInitialized = false;
Tim Murray4a92d122013-07-22 10:56:18 -070040bool RS::usingNative = false;
Tim Murray84bf2b82012-10-31 16:03:16 -070041pthread_mutex_t RS::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
Chris Wailes44bef6f2014-08-12 13:51:10 -070042dispatchTable* RS::dispatch = nullptr;
Tim Murraya4230962013-07-17 16:50:10 -070043static int gInitError = 0;
Jason Sams221a4b12012-02-22 15:22:41 -080044
Tim Murray84bf2b82012-10-31 16:03:16 -070045RS::RS() {
Chris Wailes44bef6f2014-08-12 13:51:10 -070046 mDev = nullptr;
47 mContext = nullptr;
48 mErrorFunc = nullptr;
49 mMessageFunc = nullptr;
Jason Sams221a4b12012-02-22 15:22:41 -080050 mMessageRun = false;
Tim Murraya4230962013-07-17 16:50:10 -070051 mInit = false;
Tim Murray21fa7a02013-08-15 16:25:03 -070052 mCurrentError = RS_SUCCESS;
Jason Sams221a4b12012-02-22 15:22:41 -080053
54 memset(&mElements, 0, sizeof(mElements));
Tim Murray729b6fe2013-07-23 16:20:42 -070055 memset(&mSamplers, 0, sizeof(mSamplers));
Jason Sams221a4b12012-02-22 15:22:41 -080056}
57
Tim Murray84bf2b82012-10-31 16:03:16 -070058RS::~RS() {
Tim Murraya4230962013-07-17 16:50:10 -070059 if (mInit == true) {
60 mMessageRun = false;
Jason Sams221a4b12012-02-22 15:22:41 -080061
Xiaofei Wanfea96e82014-03-31 16:43:15 +080062 if (mContext) {
63 RS::dispatch->ContextDeinitToClient(mContext);
Jason Sams221a4b12012-02-22 15:22:41 -080064
Chris Wailes44bef6f2014-08-12 13:51:10 -070065 void *res = nullptr;
Xiaofei Wanfea96e82014-03-31 16:43:15 +080066 int status = pthread_join(mMessageThreadId, &res);
Jason Sams221a4b12012-02-22 15:22:41 -080067
Xiaofei Wanfea96e82014-03-31 16:43:15 +080068 RS::dispatch->ContextDestroy(mContext);
Chris Wailes44bef6f2014-08-12 13:51:10 -070069 mContext = nullptr;
Xiaofei Wanfea96e82014-03-31 16:43:15 +080070 }
71 if (mDev) {
72 RS::dispatch->DeviceDestroy(mDev);
Chris Wailes44bef6f2014-08-12 13:51:10 -070073 mDev = nullptr;
Xiaofei Wanfea96e82014-03-31 16:43:15 +080074 }
Tim Murraya4230962013-07-17 16:50:10 -070075 }
Jason Sams221a4b12012-02-22 15:22:41 -080076}
77
Tim Murraycaf41262013-12-13 12:54:37 -080078bool RS::init(std::string name, uint32_t flags) {
79 return RS::init(name, RS_VERSION, flags);
Tim Murray84bf2b82012-10-31 16:03:16 -070080}
81
Tim Murray0b8a2be2013-07-23 16:25:41 -070082static bool loadSymbols(void* handle) {
83
84 RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType");
Chris Wailes44bef6f2014-08-12 13:51:10 -070085 if (RS::dispatch->AllocationGetType == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -080086 ALOGV("Couldn't initialize RS::dispatch->AllocationGetType");
Tim Murray0b8a2be2013-07-23 16:25:41 -070087 return false;
88 }
89 RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData");
Chris Wailes44bef6f2014-08-12 13:51:10 -070090 if (RS::dispatch->TypeGetNativeData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -080091 ALOGV("Couldn't initialize RS::dispatch->TypeGetNativeData");
Tim Murray0b8a2be2013-07-23 16:25:41 -070092 return false;
93 }
94 RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData");
Chris Wailes44bef6f2014-08-12 13:51:10 -070095 if (RS::dispatch->ElementGetNativeData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -080096 ALOGV("Couldn't initialize RS::dispatch->ElementGetNativeData");
Tim Murray0b8a2be2013-07-23 16:25:41 -070097 return false;
98 }
99 RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700100 if (RS::dispatch->ElementGetSubElements == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800101 ALOGV("Couldn't initialize RS::dispatch->ElementGetSubElements");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700102 return false;
103 }
104 RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700105 if (RS::dispatch->DeviceCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800106 ALOGV("Couldn't initialize RS::dispatch->DeviceCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700107 return false;
108 }
109 RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700110 if (RS::dispatch->DeviceDestroy == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800111 ALOGV("Couldn't initialize RS::dispatch->DeviceDestroy");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700112 return false;
113 }
114 RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700115 if (RS::dispatch->DeviceSetConfig == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800116 ALOGV("Couldn't initialize RS::dispatch->DeviceSetConfig");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700117 return false;
118 }
119 RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");;
Chris Wailes44bef6f2014-08-12 13:51:10 -0700120 if (RS::dispatch->ContextCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800121 ALOGV("Couldn't initialize RS::dispatch->ContextCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700122 return false;
123 }
Tim Murray4a92d122013-07-22 10:56:18 -0700124 RS::dispatch->GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");;
Chris Wailes44bef6f2014-08-12 13:51:10 -0700125 if (RS::dispatch->GetName == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800126 ALOGV("Couldn't initialize RS::dispatch->GetName");
Tim Murray4a92d122013-07-22 10:56:18 -0700127 return false;
128 }
Tim Murray0b8a2be2013-07-23 16:25:41 -0700129 RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700130 if (RS::dispatch->ContextDestroy == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800131 ALOGV("Couldn't initialize RS::dispatch->ContextDestroy");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700132 return false;
133 }
134 RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700135 if (RS::dispatch->ContextGetMessage == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800136 ALOGV("Couldn't initialize RS::dispatch->ContextGetMessage");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700137 return false;
138 }
139 RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700140 if (RS::dispatch->ContextPeekMessage == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800141 ALOGV("Couldn't initialize RS::dispatch->ContextPeekMessage");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700142 return false;
143 }
144 RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700145 if (RS::dispatch->ContextSendMessage == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800146 ALOGV("Couldn't initialize RS::dispatch->ContextSendMessage");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700147 return false;
148 }
149 RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700150 if (RS::dispatch->ContextInitToClient == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800151 ALOGV("Couldn't initialize RS::dispatch->ContextInitToClient");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700152 return false;
153 }
154 RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700155 if (RS::dispatch->ContextDeinitToClient == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800156 ALOGV("Couldn't initialize RS::dispatch->ContextDeinitToClient");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700157 return false;
158 }
159 RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700160 if (RS::dispatch->TypeCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800161 ALOGV("Couldn't initialize RS::dispatch->TypeCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700162 return false;
163 }
164 RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700165 if (RS::dispatch->AllocationCreateTyped == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800166 ALOGV("Couldn't initialize RS::dispatch->AllocationCreateTyped");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700167 return false;
168 }
169 RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700170 if (RS::dispatch->AllocationCreateFromBitmap == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800171 ALOGV("Couldn't initialize RS::dispatch->AllocationCreateFromBitmap");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700172 return false;
173 }
174 RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700175 if (RS::dispatch->AllocationCubeCreateFromBitmap == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800176 ALOGV("Couldn't initialize RS::dispatch->AllocationCubeCreateFromBitmap");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700177 return false;
178 }
179 RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700180 if (RS::dispatch->AllocationGetSurface == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800181 ALOGV("Couldn't initialize RS::dispatch->AllocationGetSurface");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700182 return false;
183 }
184 RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700185 if (RS::dispatch->AllocationSetSurface == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800186 ALOGV("Couldn't initialize RS::dispatch->AllocationSetSurface");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700187 return false;
188 }
189 RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700190 if (RS::dispatch->ContextFinish == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800191 ALOGV("Couldn't initialize RS::dispatch->ContextFinish");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700192 return false;
193 }
194 RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700195 if (RS::dispatch->ContextDump == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800196 ALOGV("Couldn't initialize RS::dispatch->ContextDump");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700197 return false;
198 }
199 RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700200 if (RS::dispatch->ContextSetPriority == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800201 ALOGV("Couldn't initialize RS::dispatch->ContextSetPriority");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700202 return false;
203 }
204 RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700205 if (RS::dispatch->AssignName == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800206 ALOGV("Couldn't initialize RS::dispatch->AssignName");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700207 return false;
208 }
209 RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700210 if (RS::dispatch->ObjDestroy == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800211 ALOGV("Couldn't initialize RS::dispatch->ObjDestroy");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700212 return false;
213 }
214 RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700215 if (RS::dispatch->ElementCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800216 ALOGV("Couldn't initialize RS::dispatch->ElementCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700217 return false;
218 }
219 RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700220 if (RS::dispatch->ElementCreate2 == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800221 ALOGV("Couldn't initialize RS::dispatch->ElementCreate2");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700222 return false;
223 }
224 RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700225 if (RS::dispatch->AllocationCopyToBitmap == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800226 ALOGV("Couldn't initialize RS::dispatch->AllocationCopyToBitmap");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700227 return false;
228 }
229 RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700230 if (RS::dispatch->Allocation1DData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800231 ALOGV("Couldn't initialize RS::dispatch->Allocation1DData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700232 return false;
233 }
234 RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700235 if (RS::dispatch->Allocation1DElementData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800236 ALOGV("Couldn't initialize RS::dispatch->Allocation1DElementData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700237 return false;
238 }
239 RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700240 if (RS::dispatch->Allocation2DData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800241 ALOGV("Couldn't initialize RS::dispatch->Allocation2DData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700242 return false;
243 }
244 RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700245 if (RS::dispatch->Allocation3DData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800246 ALOGV("Couldn't initialize RS::dispatch->Allocation3DData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700247 return false;
248 }
249 RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700250 if (RS::dispatch->AllocationGenerateMipmaps == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800251 ALOGV("Couldn't initialize RS::dispatch->AllocationGenerateMipmaps");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700252 return false;
253 }
254 RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700255 if (RS::dispatch->AllocationRead == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800256 ALOGV("Couldn't initialize RS::dispatch->AllocationRead");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700257 return false;
258 }
259 RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700260 if (RS::dispatch->Allocation1DRead == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800261 ALOGV("Couldn't initialize RS::dispatch->Allocation1DRead");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700262 return false;
263 }
264 RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700265 if (RS::dispatch->Allocation2DRead == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800266 ALOGV("Couldn't initialize RS::dispatch->Allocation2DRead");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700267 return false;
268 }
269 RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700270 if (RS::dispatch->AllocationSyncAll == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800271 ALOGV("Couldn't initialize RS::dispatch->AllocationSyncAll");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700272 return false;
273 }
274 RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700275 if (RS::dispatch->AllocationResize1D == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800276 ALOGV("Couldn't initialize RS::dispatch->AllocationResize1D");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700277 return false;
278 }
279 RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700280 if (RS::dispatch->AllocationCopy2DRange == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800281 ALOGV("Couldn't initialize RS::dispatch->AllocationCopy2DRange");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700282 return false;
283 }
284 RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700285 if (RS::dispatch->AllocationCopy3DRange == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800286 ALOGV("Couldn't initialize RS::dispatch->AllocationCopy3DRange");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700287 return false;
288 }
289 RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700290 if (RS::dispatch->SamplerCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800291 ALOGV("Couldn't initialize RS::dispatch->SamplerCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700292 return false;
293 }
294 RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700295 if (RS::dispatch->ScriptBindAllocation == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800296 ALOGV("Couldn't initialize RS::dispatch->ScriptBindAllocation");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700297 return false;
298 }
299 RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700300 if (RS::dispatch->ScriptSetTimeZone == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800301 ALOGV("Couldn't initialize RS::dispatch->ScriptSetTimeZone");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700302 return false;
303 }
304 RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700305 if (RS::dispatch->ScriptInvoke == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800306 ALOGV("Couldn't initialize RS::dispatch->ScriptInvoke");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700307 return false;
308 }
309 RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700310 if (RS::dispatch->ScriptInvokeV == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800311 ALOGV("Couldn't initialize RS::dispatch->ScriptInvokeV");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700312 return false;
313 }
314 RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700315 if (RS::dispatch->ScriptForEach == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800316 ALOGV("Couldn't initialize RS::dispatch->ScriptForEach");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700317 return false;
318 }
319 RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700320 if (RS::dispatch->ScriptSetVarI == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800321 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarI");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700322 return false;
323 }
324 RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700325 if (RS::dispatch->ScriptSetVarObj == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800326 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarObj");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700327 return false;
328 }
329 RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700330 if (RS::dispatch->ScriptSetVarJ == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800331 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarJ");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700332 return false;
333 }
334 RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700335 if (RS::dispatch->ScriptSetVarF == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800336 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarF");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700337 return false;
338 }
339 RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700340 if (RS::dispatch->ScriptSetVarD == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800341 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarD");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700342 return false;
343 }
344 RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700345 if (RS::dispatch->ScriptSetVarV == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800346 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarV");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700347 return false;
348 }
349 RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700350 if (RS::dispatch->ScriptGetVarV == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800351 ALOGV("Couldn't initialize RS::dispatch->ScriptGetVarV");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700352 return false;
353 }
354 RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700355 if (RS::dispatch->ScriptSetVarVE == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800356 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarVE");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700357 return false;
358 }
359 RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700360 if (RS::dispatch->ScriptCCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800361 ALOGV("Couldn't initialize RS::dispatch->ScriptCCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700362 return false;
363 }
364 RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700365 if (RS::dispatch->ScriptIntrinsicCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800366 ALOGV("Couldn't initialize RS::dispatch->ScriptIntrinsicCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700367 return false;
368 }
369 RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700370 if (RS::dispatch->ScriptKernelIDCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800371 ALOGV("Couldn't initialize RS::dispatch->ScriptKernelIDCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700372 return false;
373 }
374 RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700375 if (RS::dispatch->ScriptFieldIDCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800376 ALOGV("Couldn't initialize RS::dispatch->ScriptFieldIDCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700377 return false;
378 }
379 RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700380 if (RS::dispatch->ScriptGroupCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800381 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700382 return false;
383 }
384 RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700385 if (RS::dispatch->ScriptGroupSetOutput == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800386 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetOutput");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700387 return false;
388 }
389 RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700390 if (RS::dispatch->ScriptGroupSetInput == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800391 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetInput");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700392 return false;
393 }
394 RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700395 if (RS::dispatch->ScriptGroupExecute == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800396 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupExecute");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700397 return false;
398 }
399 RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700400 if (RS::dispatch->AllocationIoSend == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800401 ALOGV("Couldn't initialize RS::dispatch->AllocationIoSend");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700402 return false;
403 }
404 RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700405 if (RS::dispatch->AllocationIoReceive == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800406 ALOGV("Couldn't initialize RS::dispatch->AllocationIoReceive");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700407 return false;
408 }
Jason Samsb8a94e22014-02-24 17:52:32 -0800409 RS::dispatch->AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700410 if (RS::dispatch->AllocationGetPointer == nullptr) {
Jason Samsb8a94e22014-02-24 17:52:32 -0800411 ALOGV("Couldn't initialize RS::dispatch->AllocationGetPointer");
412 //return false;
413 }
Tim Murray0b8a2be2013-07-23 16:25:41 -0700414
415 return true;
416}
417
Tim Murray75e877d2013-09-11 14:45:20 -0700418// this will only open API 19+ libRS
419// because that's when we changed libRS to extern "C" entry points
Tim Murray4a92d122013-07-22 10:56:18 -0700420static bool loadSO(const char* filename) {
421 void* handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
Chris Wailes44bef6f2014-08-12 13:51:10 -0700422 if (handle == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800423 ALOGV("couldn't dlopen %s, %s", filename, dlerror());
Tim Murray4a92d122013-07-22 10:56:18 -0700424 return false;
425 }
Tim Murraya4230962013-07-17 16:50:10 -0700426
Tim Murray4a92d122013-07-22 10:56:18 -0700427 if (loadSymbols(handle) == false) {
Tim Murray87c9d772013-12-03 12:42:00 -0800428 ALOGV("%s init failed!", filename);
Tim Murray4a92d122013-07-22 10:56:18 -0700429 return false;
430 }
Tim Murray84e3dea2013-09-09 16:12:51 -0700431 //ALOGE("Successfully loaded %s", filename);
Tim Murray4a92d122013-07-22 10:56:18 -0700432 return true;
433}
434
435static uint32_t getProp(const char *str) {
Tim Murraycbbac9f2014-09-10 15:42:29 -0700436#if !defined(__LP64__) && !defined(RS_SERVER) && defined(HAVE_ANDROID_OS)
Tim Murray4a92d122013-07-22 10:56:18 -0700437 char buf[256];
438 property_get(str, buf, "0");
439 return atoi(buf);
440#else
441 return 0;
442#endif
443}
444
445bool RS::initDispatch(int targetApi) {
Tim Murraya4230962013-07-17 16:50:10 -0700446 pthread_mutex_lock(&gInitMutex);
447 if (gInitError) {
448 goto error;
449 } else if (gInitialized) {
Tim Murray47666f52013-07-29 14:32:34 -0700450 pthread_mutex_unlock(&gInitMutex);
Tim Murraya4230962013-07-17 16:50:10 -0700451 return true;
452 }
Tim Murraya4230962013-07-17 16:50:10 -0700453
454 RS::dispatch = new dispatchTable;
Tim Murray4a92d122013-07-22 10:56:18 -0700455
456 // attempt to load libRS, load libRSSupport on failure
457 // if property is set, proceed directly to libRSSupport
458 if (getProp("debug.rs.forcecompat") == 0) {
459 usingNative = loadSO("libRS.so");
460 }
461 if (usingNative == false) {
462 if (loadSO("libRSSupport.so") == false) {
463 ALOGE("Failed to load libRS.so and libRSSupport.so");
464 goto error;
465 }
Tim Murraya4230962013-07-17 16:50:10 -0700466 }
467
468 gInitialized = true;
469
470 pthread_mutex_unlock(&gInitMutex);
471 return true;
472
473 error:
474 gInitError = 1;
475 pthread_mutex_unlock(&gInitMutex);
476 return false;
477}
478
Tim Murraycaf41262013-12-13 12:54:37 -0800479bool RS::init(std::string &name, int targetApi, uint32_t flags) {
480 if (mInit) {
481 return true;
482 }
483
Tim Murraya4230962013-07-17 16:50:10 -0700484 if (initDispatch(targetApi) == false) {
485 ALOGE("Couldn't initialize dispatch table");
486 return false;
487 }
488
Tim Murraycaf41262013-12-13 12:54:37 -0800489 mCacheDir = name;
Tim Murraycaf41262013-12-13 12:54:37 -0800490
Tim Murraya4230962013-07-17 16:50:10 -0700491 mDev = RS::dispatch->DeviceCreate();
Jason Sams221a4b12012-02-22 15:22:41 -0800492 if (mDev == 0) {
493 ALOGE("Device creation failed");
494 return false;
495 }
496
Jason Samsbfa5a8e2014-05-20 18:16:20 -0700497 if (flags & ~(RS_CONTEXT_SYNCHRONOUS | RS_CONTEXT_LOW_LATENCY |
498 RS_CONTEXT_LOW_POWER)) {
Tim Murray84e3dea2013-09-09 16:12:51 -0700499 ALOGE("Invalid flags passed");
500 return false;
501 }
502
503 mContext = RS::dispatch->ContextCreate(mDev, 0, targetApi, RS_CONTEXT_TYPE_NORMAL, flags);
Jason Sams221a4b12012-02-22 15:22:41 -0800504 if (mContext == 0) {
505 ALOGE("Context creation failed");
506 return false;
507 }
508
Jason Sams221a4b12012-02-22 15:22:41 -0800509 pid_t mNativeMessageThreadId;
510
Chris Wailes44bef6f2014-08-12 13:51:10 -0700511 int status = pthread_create(&mMessageThreadId, nullptr, threadProc, this);
Jason Sams221a4b12012-02-22 15:22:41 -0800512 if (status) {
Tim Murray84bf2b82012-10-31 16:03:16 -0700513 ALOGE("Failed to start RS message thread.");
Jason Sams221a4b12012-02-22 15:22:41 -0800514 return false;
515 }
516 // Wait for the message thread to be active.
517 while (!mMessageRun) {
518 usleep(1000);
519 }
520
Tim Murraya4230962013-07-17 16:50:10 -0700521 mInit = true;
522
Jason Sams221a4b12012-02-22 15:22:41 -0800523 return true;
524}
525
Tim Murray21fa7a02013-08-15 16:25:03 -0700526void RS::throwError(RSError error, const char *errMsg) {
527 if (mCurrentError == RS_SUCCESS) {
528 mCurrentError = error;
529 ALOGE("RS CPP error: %s", errMsg);
530 } else {
531 ALOGE("RS CPP error (masked by previous error): %s", errMsg);
532 }
Jason Samsb2e3dc52012-02-23 17:14:39 -0800533}
534
Tim Murray10913a52013-08-20 17:19:47 -0700535RSError RS::getError() {
536 return mCurrentError;
537}
538
Jason Samsb2e3dc52012-02-23 17:14:39 -0800539
Tim Murray84bf2b82012-10-31 16:03:16 -0700540void * RS::threadProc(void *vrsc) {
541 RS *rs = static_cast<RS *>(vrsc);
Jason Sams221a4b12012-02-22 15:22:41 -0800542 size_t rbuf_size = 256;
543 void * rbuf = malloc(rbuf_size);
544
Tim Murraya4230962013-07-17 16:50:10 -0700545 RS::dispatch->ContextInitToClient(rs->mContext);
Jason Sams221a4b12012-02-22 15:22:41 -0800546 rs->mMessageRun = true;
547
548 while (rs->mMessageRun) {
549 size_t receiveLen = 0;
550 uint32_t usrID = 0;
551 uint32_t subID = 0;
Tim Murraya4230962013-07-17 16:50:10 -0700552 RsMessageToClientType r = RS::dispatch->ContextPeekMessage(rs->mContext,
553 &receiveLen, sizeof(receiveLen),
554 &usrID, sizeof(usrID));
Jason Sams221a4b12012-02-22 15:22:41 -0800555
556 if (receiveLen >= rbuf_size) {
557 rbuf_size = receiveLen + 32;
558 rbuf = realloc(rbuf, rbuf_size);
559 }
560 if (!rbuf) {
Tim Murray84bf2b82012-10-31 16:03:16 -0700561 ALOGE("RS::message handler realloc error %zu", rbuf_size);
Jason Sams221a4b12012-02-22 15:22:41 -0800562 // No clean way to recover now?
563 }
Tim Murraya4230962013-07-17 16:50:10 -0700564 RS::dispatch->ContextGetMessage(rs->mContext, rbuf, rbuf_size, &receiveLen, sizeof(receiveLen),
Jason Sams221a4b12012-02-22 15:22:41 -0800565 &subID, sizeof(subID));
566
567 switch(r) {
568 case RS_MESSAGE_TO_CLIENT_ERROR:
569 ALOGE("RS Error %s", (const char *)rbuf);
Tim Murray21fa7a02013-08-15 16:25:03 -0700570 rs->throwError(RS_ERROR_RUNTIME_ERROR, "Error returned from runtime");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700571 if(rs->mMessageFunc != nullptr) {
Jason Sams221a4b12012-02-22 15:22:41 -0800572 rs->mErrorFunc(usrID, (const char *)rbuf);
573 }
574 break;
Stephen Hines76a1be42012-11-26 16:26:03 -0800575 case RS_MESSAGE_TO_CLIENT_NONE:
Jason Sams221a4b12012-02-22 15:22:41 -0800576 case RS_MESSAGE_TO_CLIENT_EXCEPTION:
Stephen Hines76a1be42012-11-26 16:26:03 -0800577 case RS_MESSAGE_TO_CLIENT_RESIZE:
Jason Sams221a4b12012-02-22 15:22:41 -0800578 // teardown. But we want to avoid starving other threads during
579 // teardown by yielding until the next line in the destructor can
Stephen Hines76a1be42012-11-26 16:26:03 -0800580 // execute to set mRun = false. Note that the FIFO sends an
581 // empty NONE message when it reaches its destructor.
Jason Sams221a4b12012-02-22 15:22:41 -0800582 usleep(1000);
583 break;
584 case RS_MESSAGE_TO_CLIENT_USER:
Chris Wailes44bef6f2014-08-12 13:51:10 -0700585 if(rs->mMessageFunc != nullptr) {
Jason Sams221a4b12012-02-22 15:22:41 -0800586 rs->mMessageFunc(usrID, rbuf, receiveLen);
587 } else {
588 ALOGE("Received a message from the script with no message handler installed.");
589 }
590 break;
591
592 default:
Tim Murray84bf2b82012-10-31 16:03:16 -0700593 ALOGE("RS unknown message type %i", r);
Jason Sams221a4b12012-02-22 15:22:41 -0800594 }
595 }
596
597 if (rbuf) {
598 free(rbuf);
599 }
Tim Murray87c9d772013-12-03 12:42:00 -0800600 ALOGV("RS Message thread exiting.");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700601 return nullptr;
Jason Sams221a4b12012-02-22 15:22:41 -0800602}
603
Tim Murray84bf2b82012-10-31 16:03:16 -0700604void RS::setErrorHandler(ErrorHandlerFunc_t func) {
Jason Sams221a4b12012-02-22 15:22:41 -0800605 mErrorFunc = func;
606}
607
Tim Murray84bf2b82012-10-31 16:03:16 -0700608void RS::setMessageHandler(MessageHandlerFunc_t func) {
Jason Sams221a4b12012-02-22 15:22:41 -0800609 mMessageFunc = func;
610}
Tim Murraybaca6c32012-11-14 16:51:46 -0800611
612void RS::finish() {
Tim Murraya4230962013-07-17 16:50:10 -0700613 RS::dispatch->ContextFinish(mContext);
Tim Murraybaca6c32012-11-14 16:51:46 -0800614}