blob: 27cb3e831d9288736327b7559fbef868f09496bb [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 Sams221a4b12012-02-22 15:22:41 -080024
Tim Murraya4230962013-07-17 16:50:10 -070025#include <dlfcn.h>
Tim Murray0f98d502014-01-15 14:35:31 -080026#include <unistd.h>
Tim Murraya4230962013-07-17 16:50:10 -070027
Tim Murray0f98d502014-01-15 14:35:31 -080028#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) && defined(HAVE_ANDROID_OS)
Tim Murray4a92d122013-07-22 10:56:18 -070029#include <cutils/properties.h>
Tim Murray0f98d502014-01-15 14:35:31 -080030#else
31#include "rsCompatibilityLib.h"
Tim Murray4a92d122013-07-22 10:56:18 -070032#endif
33
Tim Murray0f98d502014-01-15 14:35:31 -080034
Jason Sams69cccdf2012-04-02 19:11:49 -070035using namespace android;
Tim Murray9eb7f4b2012-11-16 14:02:18 -080036using namespace RSC;
Jason Sams69cccdf2012-04-02 19:11:49 -070037
Tim Murray84bf2b82012-10-31 16:03:16 -070038bool RS::gInitialized = false;
Tim Murray4a92d122013-07-22 10:56:18 -070039bool RS::usingNative = false;
Tim Murray84bf2b82012-10-31 16:03:16 -070040pthread_mutex_t RS::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
Chris Wailes44bef6f2014-08-12 13:51:10 -070041dispatchTable* RS::dispatch = nullptr;
Tim Murraya4230962013-07-17 16:50:10 -070042static int gInitError = 0;
Jason Sams221a4b12012-02-22 15:22:41 -080043
Tim Murray84bf2b82012-10-31 16:03:16 -070044RS::RS() {
Chris Wailes44bef6f2014-08-12 13:51:10 -070045 mDev = nullptr;
46 mContext = nullptr;
47 mErrorFunc = nullptr;
48 mMessageFunc = nullptr;
Jason Sams221a4b12012-02-22 15:22:41 -080049 mMessageRun = false;
Tim Murraya4230962013-07-17 16:50:10 -070050 mInit = false;
Tim Murray21fa7a02013-08-15 16:25:03 -070051 mCurrentError = RS_SUCCESS;
Jason Sams221a4b12012-02-22 15:22:41 -080052
53 memset(&mElements, 0, sizeof(mElements));
Tim Murray729b6fe2013-07-23 16:20:42 -070054 memset(&mSamplers, 0, sizeof(mSamplers));
Jason Sams221a4b12012-02-22 15:22:41 -080055}
56
Tim Murray84bf2b82012-10-31 16:03:16 -070057RS::~RS() {
Tim Murraya4230962013-07-17 16:50:10 -070058 if (mInit == true) {
59 mMessageRun = false;
Jason Sams221a4b12012-02-22 15:22:41 -080060
Xiaofei Wanfea96e82014-03-31 16:43:15 +080061 if (mContext) {
62 RS::dispatch->ContextDeinitToClient(mContext);
Jason Sams221a4b12012-02-22 15:22:41 -080063
Chris Wailes44bef6f2014-08-12 13:51:10 -070064 void *res = nullptr;
Xiaofei Wanfea96e82014-03-31 16:43:15 +080065 int status = pthread_join(mMessageThreadId, &res);
Jason Sams221a4b12012-02-22 15:22:41 -080066
Xiaofei Wanfea96e82014-03-31 16:43:15 +080067 RS::dispatch->ContextDestroy(mContext);
Chris Wailes44bef6f2014-08-12 13:51:10 -070068 mContext = nullptr;
Xiaofei Wanfea96e82014-03-31 16:43:15 +080069 }
70 if (mDev) {
71 RS::dispatch->DeviceDestroy(mDev);
Chris Wailes44bef6f2014-08-12 13:51:10 -070072 mDev = nullptr;
Xiaofei Wanfea96e82014-03-31 16:43:15 +080073 }
Tim Murraya4230962013-07-17 16:50:10 -070074 }
Jason Sams221a4b12012-02-22 15:22:41 -080075}
76
Tim Murraycaf41262013-12-13 12:54:37 -080077bool RS::init(std::string name, uint32_t flags) {
78 return RS::init(name, RS_VERSION, flags);
Tim Murray84bf2b82012-10-31 16:03:16 -070079}
80
Tim Murray0b8a2be2013-07-23 16:25:41 -070081static bool loadSymbols(void* handle) {
82
83 RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType");
Chris Wailes44bef6f2014-08-12 13:51:10 -070084 if (RS::dispatch->AllocationGetType == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -080085 ALOGV("Couldn't initialize RS::dispatch->AllocationGetType");
Tim Murray0b8a2be2013-07-23 16:25:41 -070086 return false;
87 }
88 RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData");
Chris Wailes44bef6f2014-08-12 13:51:10 -070089 if (RS::dispatch->TypeGetNativeData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -080090 ALOGV("Couldn't initialize RS::dispatch->TypeGetNativeData");
Tim Murray0b8a2be2013-07-23 16:25:41 -070091 return false;
92 }
93 RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData");
Chris Wailes44bef6f2014-08-12 13:51:10 -070094 if (RS::dispatch->ElementGetNativeData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -080095 ALOGV("Couldn't initialize RS::dispatch->ElementGetNativeData");
Tim Murray0b8a2be2013-07-23 16:25:41 -070096 return false;
97 }
98 RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements");
Chris Wailes44bef6f2014-08-12 13:51:10 -070099 if (RS::dispatch->ElementGetSubElements == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800100 ALOGV("Couldn't initialize RS::dispatch->ElementGetSubElements");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700101 return false;
102 }
103 RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700104 if (RS::dispatch->DeviceCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800105 ALOGV("Couldn't initialize RS::dispatch->DeviceCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700106 return false;
107 }
108 RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700109 if (RS::dispatch->DeviceDestroy == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800110 ALOGV("Couldn't initialize RS::dispatch->DeviceDestroy");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700111 return false;
112 }
113 RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700114 if (RS::dispatch->DeviceSetConfig == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800115 ALOGV("Couldn't initialize RS::dispatch->DeviceSetConfig");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700116 return false;
117 }
118 RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");;
Chris Wailes44bef6f2014-08-12 13:51:10 -0700119 if (RS::dispatch->ContextCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800120 ALOGV("Couldn't initialize RS::dispatch->ContextCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700121 return false;
122 }
Tim Murray4a92d122013-07-22 10:56:18 -0700123 RS::dispatch->GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");;
Chris Wailes44bef6f2014-08-12 13:51:10 -0700124 if (RS::dispatch->GetName == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800125 ALOGV("Couldn't initialize RS::dispatch->GetName");
Tim Murray4a92d122013-07-22 10:56:18 -0700126 return false;
127 }
Tim Murray0b8a2be2013-07-23 16:25:41 -0700128 RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700129 if (RS::dispatch->ContextDestroy == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800130 ALOGV("Couldn't initialize RS::dispatch->ContextDestroy");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700131 return false;
132 }
133 RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700134 if (RS::dispatch->ContextGetMessage == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800135 ALOGV("Couldn't initialize RS::dispatch->ContextGetMessage");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700136 return false;
137 }
138 RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700139 if (RS::dispatch->ContextPeekMessage == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800140 ALOGV("Couldn't initialize RS::dispatch->ContextPeekMessage");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700141 return false;
142 }
143 RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700144 if (RS::dispatch->ContextSendMessage == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800145 ALOGV("Couldn't initialize RS::dispatch->ContextSendMessage");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700146 return false;
147 }
148 RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700149 if (RS::dispatch->ContextInitToClient == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800150 ALOGV("Couldn't initialize RS::dispatch->ContextInitToClient");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700151 return false;
152 }
153 RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700154 if (RS::dispatch->ContextDeinitToClient == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800155 ALOGV("Couldn't initialize RS::dispatch->ContextDeinitToClient");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700156 return false;
157 }
158 RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700159 if (RS::dispatch->TypeCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800160 ALOGV("Couldn't initialize RS::dispatch->TypeCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700161 return false;
162 }
163 RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700164 if (RS::dispatch->AllocationCreateTyped == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800165 ALOGV("Couldn't initialize RS::dispatch->AllocationCreateTyped");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700166 return false;
167 }
168 RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700169 if (RS::dispatch->AllocationCreateFromBitmap == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800170 ALOGV("Couldn't initialize RS::dispatch->AllocationCreateFromBitmap");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700171 return false;
172 }
173 RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700174 if (RS::dispatch->AllocationCubeCreateFromBitmap == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800175 ALOGV("Couldn't initialize RS::dispatch->AllocationCubeCreateFromBitmap");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700176 return false;
177 }
178 RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700179 if (RS::dispatch->AllocationGetSurface == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800180 ALOGV("Couldn't initialize RS::dispatch->AllocationGetSurface");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700181 return false;
182 }
183 RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700184 if (RS::dispatch->AllocationSetSurface == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800185 ALOGV("Couldn't initialize RS::dispatch->AllocationSetSurface");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700186 return false;
187 }
188 RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700189 if (RS::dispatch->ContextFinish == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800190 ALOGV("Couldn't initialize RS::dispatch->ContextFinish");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700191 return false;
192 }
193 RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700194 if (RS::dispatch->ContextDump == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800195 ALOGV("Couldn't initialize RS::dispatch->ContextDump");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700196 return false;
197 }
198 RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700199 if (RS::dispatch->ContextSetPriority == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800200 ALOGV("Couldn't initialize RS::dispatch->ContextSetPriority");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700201 return false;
202 }
203 RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700204 if (RS::dispatch->AssignName == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800205 ALOGV("Couldn't initialize RS::dispatch->AssignName");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700206 return false;
207 }
208 RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700209 if (RS::dispatch->ObjDestroy == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800210 ALOGV("Couldn't initialize RS::dispatch->ObjDestroy");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700211 return false;
212 }
213 RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700214 if (RS::dispatch->ElementCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800215 ALOGV("Couldn't initialize RS::dispatch->ElementCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700216 return false;
217 }
218 RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700219 if (RS::dispatch->ElementCreate2 == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800220 ALOGV("Couldn't initialize RS::dispatch->ElementCreate2");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700221 return false;
222 }
223 RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700224 if (RS::dispatch->AllocationCopyToBitmap == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800225 ALOGV("Couldn't initialize RS::dispatch->AllocationCopyToBitmap");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700226 return false;
227 }
228 RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700229 if (RS::dispatch->Allocation1DData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800230 ALOGV("Couldn't initialize RS::dispatch->Allocation1DData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700231 return false;
232 }
233 RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700234 if (RS::dispatch->Allocation1DElementData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800235 ALOGV("Couldn't initialize RS::dispatch->Allocation1DElementData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700236 return false;
237 }
238 RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700239 if (RS::dispatch->Allocation2DData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800240 ALOGV("Couldn't initialize RS::dispatch->Allocation2DData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700241 return false;
242 }
243 RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700244 if (RS::dispatch->Allocation3DData == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800245 ALOGV("Couldn't initialize RS::dispatch->Allocation3DData");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700246 return false;
247 }
248 RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700249 if (RS::dispatch->AllocationGenerateMipmaps == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800250 ALOGV("Couldn't initialize RS::dispatch->AllocationGenerateMipmaps");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700251 return false;
252 }
253 RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700254 if (RS::dispatch->AllocationRead == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800255 ALOGV("Couldn't initialize RS::dispatch->AllocationRead");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700256 return false;
257 }
258 RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700259 if (RS::dispatch->Allocation1DRead == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800260 ALOGV("Couldn't initialize RS::dispatch->Allocation1DRead");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700261 return false;
262 }
263 RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700264 if (RS::dispatch->Allocation2DRead == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800265 ALOGV("Couldn't initialize RS::dispatch->Allocation2DRead");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700266 return false;
267 }
268 RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700269 if (RS::dispatch->AllocationSyncAll == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800270 ALOGV("Couldn't initialize RS::dispatch->AllocationSyncAll");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700271 return false;
272 }
273 RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700274 if (RS::dispatch->AllocationResize1D == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800275 ALOGV("Couldn't initialize RS::dispatch->AllocationResize1D");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700276 return false;
277 }
278 RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700279 if (RS::dispatch->AllocationCopy2DRange == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800280 ALOGV("Couldn't initialize RS::dispatch->AllocationCopy2DRange");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700281 return false;
282 }
283 RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700284 if (RS::dispatch->AllocationCopy3DRange == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800285 ALOGV("Couldn't initialize RS::dispatch->AllocationCopy3DRange");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700286 return false;
287 }
288 RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700289 if (RS::dispatch->SamplerCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800290 ALOGV("Couldn't initialize RS::dispatch->SamplerCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700291 return false;
292 }
293 RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700294 if (RS::dispatch->ScriptBindAllocation == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800295 ALOGV("Couldn't initialize RS::dispatch->ScriptBindAllocation");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700296 return false;
297 }
298 RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700299 if (RS::dispatch->ScriptSetTimeZone == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800300 ALOGV("Couldn't initialize RS::dispatch->ScriptSetTimeZone");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700301 return false;
302 }
303 RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700304 if (RS::dispatch->ScriptInvoke == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800305 ALOGV("Couldn't initialize RS::dispatch->ScriptInvoke");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700306 return false;
307 }
308 RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700309 if (RS::dispatch->ScriptInvokeV == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800310 ALOGV("Couldn't initialize RS::dispatch->ScriptInvokeV");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700311 return false;
312 }
313 RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700314 if (RS::dispatch->ScriptForEach == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800315 ALOGV("Couldn't initialize RS::dispatch->ScriptForEach");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700316 return false;
317 }
318 RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700319 if (RS::dispatch->ScriptSetVarI == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800320 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarI");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700321 return false;
322 }
323 RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700324 if (RS::dispatch->ScriptSetVarObj == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800325 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarObj");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700326 return false;
327 }
328 RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700329 if (RS::dispatch->ScriptSetVarJ == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800330 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarJ");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700331 return false;
332 }
333 RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700334 if (RS::dispatch->ScriptSetVarF == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800335 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarF");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700336 return false;
337 }
338 RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700339 if (RS::dispatch->ScriptSetVarD == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800340 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarD");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700341 return false;
342 }
343 RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700344 if (RS::dispatch->ScriptSetVarV == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800345 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarV");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700346 return false;
347 }
348 RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700349 if (RS::dispatch->ScriptGetVarV == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800350 ALOGV("Couldn't initialize RS::dispatch->ScriptGetVarV");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700351 return false;
352 }
353 RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700354 if (RS::dispatch->ScriptSetVarVE == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800355 ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarVE");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700356 return false;
357 }
358 RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700359 if (RS::dispatch->ScriptCCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800360 ALOGV("Couldn't initialize RS::dispatch->ScriptCCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700361 return false;
362 }
363 RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700364 if (RS::dispatch->ScriptIntrinsicCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800365 ALOGV("Couldn't initialize RS::dispatch->ScriptIntrinsicCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700366 return false;
367 }
368 RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700369 if (RS::dispatch->ScriptKernelIDCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800370 ALOGV("Couldn't initialize RS::dispatch->ScriptKernelIDCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700371 return false;
372 }
373 RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700374 if (RS::dispatch->ScriptFieldIDCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800375 ALOGV("Couldn't initialize RS::dispatch->ScriptFieldIDCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700376 return false;
377 }
378 RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700379 if (RS::dispatch->ScriptGroupCreate == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800380 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupCreate");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700381 return false;
382 }
383 RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700384 if (RS::dispatch->ScriptGroupSetOutput == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800385 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetOutput");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700386 return false;
387 }
388 RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700389 if (RS::dispatch->ScriptGroupSetInput == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800390 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetInput");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700391 return false;
392 }
393 RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700394 if (RS::dispatch->ScriptGroupExecute == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800395 ALOGV("Couldn't initialize RS::dispatch->ScriptGroupExecute");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700396 return false;
397 }
398 RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700399 if (RS::dispatch->AllocationIoSend == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800400 ALOGV("Couldn't initialize RS::dispatch->AllocationIoSend");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700401 return false;
402 }
403 RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700404 if (RS::dispatch->AllocationIoReceive == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800405 ALOGV("Couldn't initialize RS::dispatch->AllocationIoReceive");
Tim Murray0b8a2be2013-07-23 16:25:41 -0700406 return false;
407 }
Jason Samsb8a94e22014-02-24 17:52:32 -0800408 RS::dispatch->AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700409 if (RS::dispatch->AllocationGetPointer == nullptr) {
Jason Samsb8a94e22014-02-24 17:52:32 -0800410 ALOGV("Couldn't initialize RS::dispatch->AllocationGetPointer");
411 //return false;
412 }
Tim Murray0b8a2be2013-07-23 16:25:41 -0700413
414 return true;
415}
416
Tim Murray75e877d2013-09-11 14:45:20 -0700417// this will only open API 19+ libRS
418// because that's when we changed libRS to extern "C" entry points
Tim Murray4a92d122013-07-22 10:56:18 -0700419static bool loadSO(const char* filename) {
420 void* handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
Chris Wailes44bef6f2014-08-12 13:51:10 -0700421 if (handle == nullptr) {
Tim Murray87c9d772013-12-03 12:42:00 -0800422 ALOGV("couldn't dlopen %s, %s", filename, dlerror());
Tim Murray4a92d122013-07-22 10:56:18 -0700423 return false;
424 }
Tim Murraya4230962013-07-17 16:50:10 -0700425
Tim Murray4a92d122013-07-22 10:56:18 -0700426 if (loadSymbols(handle) == false) {
Tim Murray87c9d772013-12-03 12:42:00 -0800427 ALOGV("%s init failed!", filename);
Tim Murray4a92d122013-07-22 10:56:18 -0700428 return false;
429 }
Tim Murray84e3dea2013-09-09 16:12:51 -0700430 //ALOGE("Successfully loaded %s", filename);
Tim Murray4a92d122013-07-22 10:56:18 -0700431 return true;
432}
433
434static uint32_t getProp(const char *str) {
435#if !defined(RS_SERVER) && defined(HAVE_ANDROID_OS)
436 char buf[256];
437 property_get(str, buf, "0");
438 return atoi(buf);
439#else
440 return 0;
441#endif
442}
443
444bool RS::initDispatch(int targetApi) {
Tim Murraya4230962013-07-17 16:50:10 -0700445 pthread_mutex_lock(&gInitMutex);
446 if (gInitError) {
447 goto error;
448 } else if (gInitialized) {
Tim Murray47666f52013-07-29 14:32:34 -0700449 pthread_mutex_unlock(&gInitMutex);
Tim Murraya4230962013-07-17 16:50:10 -0700450 return true;
451 }
Tim Murraya4230962013-07-17 16:50:10 -0700452
453 RS::dispatch = new dispatchTable;
Tim Murray4a92d122013-07-22 10:56:18 -0700454
455 // attempt to load libRS, load libRSSupport on failure
456 // if property is set, proceed directly to libRSSupport
457 if (getProp("debug.rs.forcecompat") == 0) {
458 usingNative = loadSO("libRS.so");
459 }
460 if (usingNative == false) {
461 if (loadSO("libRSSupport.so") == false) {
462 ALOGE("Failed to load libRS.so and libRSSupport.so");
463 goto error;
464 }
Tim Murraya4230962013-07-17 16:50:10 -0700465 }
466
467 gInitialized = true;
468
469 pthread_mutex_unlock(&gInitMutex);
470 return true;
471
472 error:
473 gInitError = 1;
474 pthread_mutex_unlock(&gInitMutex);
475 return false;
476}
477
Tim Murraycaf41262013-12-13 12:54:37 -0800478bool RS::init(std::string &name, int targetApi, uint32_t flags) {
479 if (mInit) {
480 return true;
481 }
482
Tim Murraya4230962013-07-17 16:50:10 -0700483 if (initDispatch(targetApi) == false) {
484 ALOGE("Couldn't initialize dispatch table");
485 return false;
486 }
487
Tim Murraycaf41262013-12-13 12:54:37 -0800488 mCacheDir = name;
Tim Murraycaf41262013-12-13 12:54:37 -0800489
Tim Murraya4230962013-07-17 16:50:10 -0700490 mDev = RS::dispatch->DeviceCreate();
Jason Sams221a4b12012-02-22 15:22:41 -0800491 if (mDev == 0) {
492 ALOGE("Device creation failed");
493 return false;
494 }
495
Jason Samsbfa5a8e2014-05-20 18:16:20 -0700496 if (flags & ~(RS_CONTEXT_SYNCHRONOUS | RS_CONTEXT_LOW_LATENCY |
497 RS_CONTEXT_LOW_POWER)) {
Tim Murray84e3dea2013-09-09 16:12:51 -0700498 ALOGE("Invalid flags passed");
499 return false;
500 }
501
502 mContext = RS::dispatch->ContextCreate(mDev, 0, targetApi, RS_CONTEXT_TYPE_NORMAL, flags);
Jason Sams221a4b12012-02-22 15:22:41 -0800503 if (mContext == 0) {
504 ALOGE("Context creation failed");
505 return false;
506 }
507
Jason Sams221a4b12012-02-22 15:22:41 -0800508 pid_t mNativeMessageThreadId;
509
Chris Wailes44bef6f2014-08-12 13:51:10 -0700510 int status = pthread_create(&mMessageThreadId, nullptr, threadProc, this);
Jason Sams221a4b12012-02-22 15:22:41 -0800511 if (status) {
Tim Murray84bf2b82012-10-31 16:03:16 -0700512 ALOGE("Failed to start RS message thread.");
Jason Sams221a4b12012-02-22 15:22:41 -0800513 return false;
514 }
515 // Wait for the message thread to be active.
516 while (!mMessageRun) {
517 usleep(1000);
518 }
519
Tim Murraya4230962013-07-17 16:50:10 -0700520 mInit = true;
521
Jason Sams221a4b12012-02-22 15:22:41 -0800522 return true;
523}
524
Tim Murray21fa7a02013-08-15 16:25:03 -0700525void RS::throwError(RSError error, const char *errMsg) {
526 if (mCurrentError == RS_SUCCESS) {
527 mCurrentError = error;
528 ALOGE("RS CPP error: %s", errMsg);
529 } else {
530 ALOGE("RS CPP error (masked by previous error): %s", errMsg);
531 }
Jason Samsb2e3dc52012-02-23 17:14:39 -0800532}
533
Tim Murray10913a52013-08-20 17:19:47 -0700534RSError RS::getError() {
535 return mCurrentError;
536}
537
Jason Samsb2e3dc52012-02-23 17:14:39 -0800538
Tim Murray84bf2b82012-10-31 16:03:16 -0700539void * RS::threadProc(void *vrsc) {
540 RS *rs = static_cast<RS *>(vrsc);
Jason Sams221a4b12012-02-22 15:22:41 -0800541 size_t rbuf_size = 256;
542 void * rbuf = malloc(rbuf_size);
543
Tim Murraya4230962013-07-17 16:50:10 -0700544 RS::dispatch->ContextInitToClient(rs->mContext);
Jason Sams221a4b12012-02-22 15:22:41 -0800545 rs->mMessageRun = true;
546
547 while (rs->mMessageRun) {
548 size_t receiveLen = 0;
549 uint32_t usrID = 0;
550 uint32_t subID = 0;
Tim Murraya4230962013-07-17 16:50:10 -0700551 RsMessageToClientType r = RS::dispatch->ContextPeekMessage(rs->mContext,
552 &receiveLen, sizeof(receiveLen),
553 &usrID, sizeof(usrID));
Jason Sams221a4b12012-02-22 15:22:41 -0800554
555 if (receiveLen >= rbuf_size) {
556 rbuf_size = receiveLen + 32;
557 rbuf = realloc(rbuf, rbuf_size);
558 }
559 if (!rbuf) {
Tim Murray84bf2b82012-10-31 16:03:16 -0700560 ALOGE("RS::message handler realloc error %zu", rbuf_size);
Jason Sams221a4b12012-02-22 15:22:41 -0800561 // No clean way to recover now?
562 }
Tim Murraya4230962013-07-17 16:50:10 -0700563 RS::dispatch->ContextGetMessage(rs->mContext, rbuf, rbuf_size, &receiveLen, sizeof(receiveLen),
Jason Sams221a4b12012-02-22 15:22:41 -0800564 &subID, sizeof(subID));
565
566 switch(r) {
567 case RS_MESSAGE_TO_CLIENT_ERROR:
568 ALOGE("RS Error %s", (const char *)rbuf);
Tim Murray21fa7a02013-08-15 16:25:03 -0700569 rs->throwError(RS_ERROR_RUNTIME_ERROR, "Error returned from runtime");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700570 if(rs->mMessageFunc != nullptr) {
Jason Sams221a4b12012-02-22 15:22:41 -0800571 rs->mErrorFunc(usrID, (const char *)rbuf);
572 }
573 break;
Stephen Hines76a1be42012-11-26 16:26:03 -0800574 case RS_MESSAGE_TO_CLIENT_NONE:
Jason Sams221a4b12012-02-22 15:22:41 -0800575 case RS_MESSAGE_TO_CLIENT_EXCEPTION:
Stephen Hines76a1be42012-11-26 16:26:03 -0800576 case RS_MESSAGE_TO_CLIENT_RESIZE:
Jason Sams221a4b12012-02-22 15:22:41 -0800577 // teardown. But we want to avoid starving other threads during
578 // teardown by yielding until the next line in the destructor can
Stephen Hines76a1be42012-11-26 16:26:03 -0800579 // execute to set mRun = false. Note that the FIFO sends an
580 // empty NONE message when it reaches its destructor.
Jason Sams221a4b12012-02-22 15:22:41 -0800581 usleep(1000);
582 break;
583 case RS_MESSAGE_TO_CLIENT_USER:
Chris Wailes44bef6f2014-08-12 13:51:10 -0700584 if(rs->mMessageFunc != nullptr) {
Jason Sams221a4b12012-02-22 15:22:41 -0800585 rs->mMessageFunc(usrID, rbuf, receiveLen);
586 } else {
587 ALOGE("Received a message from the script with no message handler installed.");
588 }
589 break;
590
591 default:
Tim Murray84bf2b82012-10-31 16:03:16 -0700592 ALOGE("RS unknown message type %i", r);
Jason Sams221a4b12012-02-22 15:22:41 -0800593 }
594 }
595
596 if (rbuf) {
597 free(rbuf);
598 }
Tim Murray87c9d772013-12-03 12:42:00 -0800599 ALOGV("RS Message thread exiting.");
Chris Wailes44bef6f2014-08-12 13:51:10 -0700600 return nullptr;
Jason Sams221a4b12012-02-22 15:22:41 -0800601}
602
Tim Murray84bf2b82012-10-31 16:03:16 -0700603void RS::setErrorHandler(ErrorHandlerFunc_t func) {
Jason Sams221a4b12012-02-22 15:22:41 -0800604 mErrorFunc = func;
605}
606
Tim Murray84bf2b82012-10-31 16:03:16 -0700607void RS::setMessageHandler(MessageHandlerFunc_t func) {
Jason Sams221a4b12012-02-22 15:22:41 -0800608 mMessageFunc = func;
609}
Tim Murraybaca6c32012-11-14 16:51:46 -0800610
611void RS::finish() {
Tim Murraya4230962013-07-17 16:50:10 -0700612 RS::dispatch->ContextFinish(mContext);
Tim Murraybaca6c32012-11-14 16:51:46 -0800613}