blob: 8a4789ab1f3f16d1a7ed0e264b3cfe3f6104bded [file] [log] [blame]
Jason Samsc97bb882009-07-20 14:31:06 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "rsContext.h"
18#include "rsScriptC.h"
19#include "rsMatrix.h"
20
Joe Onorato3370ec92009-08-09 11:39:02 -070021#include "utils/Timers.h"
Jason Samsc97bb882009-07-20 14:31:06 -070022
Romain Guy584a3752009-07-30 18:45:01 -070023#include <time.h>
Romain Guy584a3752009-07-30 18:45:01 -070024
Jason Samsc97bb882009-07-20 14:31:06 -070025using namespace android;
26using namespace android::renderscript;
27
28#define GET_TLS() Context::ScriptTLSStruct * tls = \
29 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
30 Context * rsc = tls->mContext; \
31 ScriptC * sc = (ScriptC *) tls->mScript
32
Jason Sams4d339932010-05-11 14:03:58 -070033
Jason Samsc97bb882009-07-20 14:31:06 -070034//////////////////////////////////////////////////////////////////////////////
35// Math routines
36//////////////////////////////////////////////////////////////////////////////
37
Stephen Hines1bf1f8d2011-03-01 17:34:59 -080038#if 0
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080039static float SC_sinf_fast(float x) {
Romain Guycac80a62009-08-18 11:39:17 -070040 const float A = 1.0f / (2.0f * M_PI);
41 const float B = -16.0f;
42 const float C = 8.0f;
Jason Samsea84a7c2009-09-04 14:42:41 -070043
Romain Guycac80a62009-08-18 11:39:17 -070044 // scale angle for easy argument reduction
45 x *= A;
Jason Samsea84a7c2009-09-04 14:42:41 -070046
Romain Guycac80a62009-08-18 11:39:17 -070047 if (fabsf(x) >= 0.5f) {
48 // argument reduction
49 x = x - ceilf(x + 0.5f) + 1.0f;
50 }
Jason Samsea84a7c2009-09-04 14:42:41 -070051
Romain Guycac80a62009-08-18 11:39:17 -070052 const float y = B * x * fabsf(x) + C * x;
53 return 0.2215f * (y * fabsf(y) - y) + y;
54}
55
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080056static float SC_cosf_fast(float x) {
Romain Guycac80a62009-08-18 11:39:17 -070057 x += float(M_PI / 2);
58
59 const float A = 1.0f / (2.0f * M_PI);
60 const float B = -16.0f;
61 const float C = 8.0f;
Jason Samsea84a7c2009-09-04 14:42:41 -070062
Romain Guycac80a62009-08-18 11:39:17 -070063 // scale angle for easy argument reduction
64 x *= A;
Jason Samsea84a7c2009-09-04 14:42:41 -070065
Romain Guycac80a62009-08-18 11:39:17 -070066 if (fabsf(x) >= 0.5f) {
67 // argument reduction
68 x = x - ceilf(x + 0.5f) + 1.0f;
69 }
Jason Samsea84a7c2009-09-04 14:42:41 -070070
Romain Guycac80a62009-08-18 11:39:17 -070071 const float y = B * x * fabsf(x) + C * x;
72 return 0.2215f * (y * fabsf(y) - y) + y;
73}
Stephen Hines1bf1f8d2011-03-01 17:34:59 -080074#endif
Romain Guycac80a62009-08-18 11:39:17 -070075
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080076static float SC_randf(float max) {
Jason Samsc97bb882009-07-20 14:31:06 -070077 float r = (float)rand();
Jason Sams5476b452010-12-08 16:14:36 -080078 r *= max;
Alex Sakhartchouk4658d772011-04-19 18:22:28 -070079 r /= RAND_MAX;
80 return r;
Jason Samsc97bb882009-07-20 14:31:06 -070081}
82
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080083static float SC_randf2(float min, float max) {
Romain Guy8839ca52009-07-31 11:20:59 -070084 float r = (float)rand();
Alex Sakhartchouk4658d772011-04-19 18:22:28 -070085 r /= RAND_MAX;
Jason Sams5476b452010-12-08 16:14:36 -080086 r = r * (max - min) + min;
Alex Sakhartchouk4658d772011-04-19 18:22:28 -070087 return r;
Romain Guy8839ca52009-07-31 11:20:59 -070088}
89
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080090static int SC_randi(int max) {
Jason Samsd79b2e92010-05-19 17:22:57 -070091 return (int)SC_randf(max);
92}
93
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080094static int SC_randi2(int min, int max) {
Jason Samsd79b2e92010-05-19 17:22:57 -070095 return (int)SC_randf2(min, max);
96}
97
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080098static float SC_frac(float v) {
Jason Sams4d339932010-05-11 14:03:58 -070099 int i = (int)floor(v);
100 return fmin(v - i, 0x1.fffffep-1f);
101}
102
Romain Guy584a3752009-07-30 18:45:01 -0700103//////////////////////////////////////////////////////////////////////////////
104// Time routines
105//////////////////////////////////////////////////////////////////////////////
Jason Samsc97bb882009-07-20 14:31:06 -0700106
Stephen Hines1ac9da62011-01-07 15:11:30 -0800107static time_t SC_time(time_t *timer) {
Romain Guy584a3752009-07-30 18:45:01 -0700108 GET_TLS();
Stephen Hines1ac9da62011-01-07 15:11:30 -0800109 return time(timer);
Romain Guy584a3752009-07-30 18:45:01 -0700110}
111
Stephen Hines1ac9da62011-01-07 15:11:30 -0800112static tm* SC_localtime(tm *local, time_t *timer) {
Romain Guy584a3752009-07-30 18:45:01 -0700113 GET_TLS();
Stephen Hines1ac9da62011-01-07 15:11:30 -0800114 if (!local) {
115 return NULL;
116 }
Jason Sams1bada8c2009-08-09 17:01:55 -0700117
Stephen Hines1ac9da62011-01-07 15:11:30 -0800118 // The native localtime function is not thread-safe, so we
119 // have to apply locking for proper behavior in RenderScript.
120 pthread_mutex_lock(&rsc->gLibMutex);
121 tm *tmp = localtime(timer);
122 memcpy(local, tmp, sizeof(*tmp));
123 pthread_mutex_unlock(&rsc->gLibMutex);
124 return local;
Romain Guy8839ca52009-07-31 11:20:59 -0700125}
126
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800127static int64_t SC_uptimeMillis() {
Jason Samsd79b2e92010-05-19 17:22:57 -0700128 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
129}
130
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800131static int64_t SC_uptimeNanos() {
Jason Samsf0690c42010-07-29 17:31:14 -0700132 return systemTime(SYSTEM_TIME_MONOTONIC);
Jason Samsd79b2e92010-05-19 17:22:57 -0700133}
134
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800135static float SC_getDt() {
Joe Onorato3370ec92009-08-09 11:39:02 -0700136 GET_TLS();
Jason Sams17966512010-07-28 11:17:53 -0700137 int64_t l = sc->mEnviroment.mLastDtTime;
138 sc->mEnviroment.mLastDtTime = systemTime(SYSTEM_TIME_MONOTONIC);
139 return ((float)(sc->mEnviroment.mLastDtTime - l)) / 1.0e9;
Jason Samsc97bb882009-07-20 14:31:06 -0700140}
141
Jason Samsc97bb882009-07-20 14:31:06 -0700142//////////////////////////////////////////////////////////////////////////////
143//
144//////////////////////////////////////////////////////////////////////////////
145
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800146static uint32_t SC_allocGetDimX(RsAllocation va) {
Jason Sams4d339932010-05-11 14:03:58 -0700147 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700148 CHECK_OBJ(a);
149 //LOGE("SC_allocGetDimX a=%p type=%p", a, a->getType());
Jason Sams4d339932010-05-11 14:03:58 -0700150 return a->getType()->getDimX();
151}
152
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800153static uint32_t SC_allocGetDimY(RsAllocation va) {
Jason Sams4d339932010-05-11 14:03:58 -0700154 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700155 CHECK_OBJ(a);
Jason Sams4d339932010-05-11 14:03:58 -0700156 return a->getType()->getDimY();
157}
158
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800159static uint32_t SC_allocGetDimZ(RsAllocation va) {
Jason Sams4d339932010-05-11 14:03:58 -0700160 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700161 CHECK_OBJ(a);
Jason Sams4d339932010-05-11 14:03:58 -0700162 return a->getType()->getDimZ();
163}
164
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800165static uint32_t SC_allocGetDimLOD(RsAllocation va) {
Jason Sams4d339932010-05-11 14:03:58 -0700166 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700167 CHECK_OBJ(a);
Jason Sams4d339932010-05-11 14:03:58 -0700168 return a->getType()->getDimLOD();
169}
170
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800171static uint32_t SC_allocGetDimFaces(RsAllocation va) {
Jason Sams4d339932010-05-11 14:03:58 -0700172 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700173 CHECK_OBJ(a);
Jason Sams4d339932010-05-11 14:03:58 -0700174 return a->getType()->getDimFaces();
175}
176
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800177static const void * SC_getElementAtX(RsAllocation va, uint32_t x) {
Jason Sams8e6c17f2010-07-19 15:38:19 -0700178 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700179 CHECK_OBJ(a);
Jason Sams8e6c17f2010-07-19 15:38:19 -0700180 const Type *t = a->getType();
Jason Samsf166d9b2010-09-30 18:15:52 -0700181 CHECK_OBJ(t);
Jason Sams8e6c17f2010-07-19 15:38:19 -0700182 const uint8_t *p = (const uint8_t *)a->getPtr();
183 return &p[t->getElementSizeBytes() * x];
184}
185
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800186static const void * SC_getElementAtXY(RsAllocation va, uint32_t x, uint32_t y) {
Jason Sams8e6c17f2010-07-19 15:38:19 -0700187 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700188 CHECK_OBJ(a);
Jason Sams8e6c17f2010-07-19 15:38:19 -0700189 const Type *t = a->getType();
Jason Samsf166d9b2010-09-30 18:15:52 -0700190 CHECK_OBJ(t);
Jason Sams8e6c17f2010-07-19 15:38:19 -0700191 const uint8_t *p = (const uint8_t *)a->getPtr();
192 return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
193}
194
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800195static const void * SC_getElementAtXYZ(RsAllocation va, uint32_t x, uint32_t y, uint32_t z) {
Jason Sams8e6c17f2010-07-19 15:38:19 -0700196 const Allocation *a = static_cast<const Allocation *>(va);
Jason Samsf166d9b2010-09-30 18:15:52 -0700197 CHECK_OBJ(a);
Jason Sams8e6c17f2010-07-19 15:38:19 -0700198 const Type *t = a->getType();
Jason Samsf166d9b2010-09-30 18:15:52 -0700199 CHECK_OBJ(t);
Jason Sams8e6c17f2010-07-19 15:38:19 -0700200 const uint8_t *p = (const uint8_t *)a->getPtr();
201 return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
202}
Jason Sams4d339932010-05-11 14:03:58 -0700203
Jason Sams02f62aa2010-08-16 12:41:48 -0700204static void SC_setObject(void **vdst, void * vsrc) {
Jason Sams4fd8bb42010-09-17 13:17:17 -0700205 //LOGE("SC_setObject %p,%p %p", vdst, *vdst, vsrc);
206 if (vsrc) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700207 CHECK_OBJ(vsrc);
Jason Sams4fd8bb42010-09-17 13:17:17 -0700208 static_cast<ObjectBase *>(vsrc)->incSysRef();
209 }
210 if (vdst[0]) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700211 CHECK_OBJ(vdst[0]);
Jason Sams4fd8bb42010-09-17 13:17:17 -0700212 static_cast<ObjectBase *>(vdst[0])->decSysRef();
213 }
Jason Sams02f62aa2010-08-16 12:41:48 -0700214 *vdst = vsrc;
Jason Sams4fd8bb42010-09-17 13:17:17 -0700215 //LOGE("SC_setObject *");
Jason Sams02f62aa2010-08-16 12:41:48 -0700216}
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800217
Jason Sams02f62aa2010-08-16 12:41:48 -0700218static void SC_clearObject(void **vdst) {
Jason Sams4fd8bb42010-09-17 13:17:17 -0700219 //LOGE("SC_clearObject %p,%p", vdst, *vdst);
220 if (vdst[0]) {
Jason Samsf166d9b2010-09-30 18:15:52 -0700221 CHECK_OBJ(vdst[0]);
Jason Sams4fd8bb42010-09-17 13:17:17 -0700222 static_cast<ObjectBase *>(vdst[0])->decSysRef();
223 }
Jason Sams02f62aa2010-08-16 12:41:48 -0700224 *vdst = NULL;
Jason Sams4fd8bb42010-09-17 13:17:17 -0700225 //LOGE("SC_clearObject *");
Jason Sams02f62aa2010-08-16 12:41:48 -0700226}
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800227
Jason Sams02f62aa2010-08-16 12:41:48 -0700228static bool SC_isObject(RsAllocation vsrc) {
229 return vsrc != NULL;
230}
231
Jason Samsd79b2e92010-05-19 17:22:57 -0700232static void SC_debugF(const char *s, float f) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800233 LOGD("%s %f, 0x%08x", s, f, *((int *) (&f)));
Jason Samsb0ec1b42009-07-28 12:02:16 -0700234}
Jason Samsd64188a2010-08-06 16:22:50 -0700235static void SC_debugFv2(const char *s, float f1, float f2) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800236 LOGD("%s {%f, %f}", s, f1, f2);
Romain Guyd22fff72009-08-20 17:08:33 -0700237}
Jason Samsd64188a2010-08-06 16:22:50 -0700238static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800239 LOGD("%s {%f, %f, %f}", s, f1, f2, f3);
Jason Samsb0ec1b42009-07-28 12:02:16 -0700240}
Jason Samsd64188a2010-08-06 16:22:50 -0700241static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800242 LOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
Jason Samsd79b2e92010-05-19 17:22:57 -0700243}
Stephen Hines65688962010-10-15 12:47:49 -0700244static void SC_debugD(const char *s, double d) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800245 LOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
Stephen Hines65688962010-10-15 12:47:49 -0700246}
Jason Samsd64188a2010-08-06 16:22:50 -0700247static void SC_debugFM4v4(const char *s, const float *f) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800248 LOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
249 LOGD("%s %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
250 LOGD("%s %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
251 LOGD("%s %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
Jason Samsd64188a2010-08-06 16:22:50 -0700252}
253static void SC_debugFM3v3(const char *s, const float *f) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800254 LOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]);
255 LOGD("%s %f, %f, %f", s, f[1], f[4], f[7]);
256 LOGD("%s %f, %f, %f}",s, f[2], f[5], f[8]);
Jason Samsd64188a2010-08-06 16:22:50 -0700257}
258static void SC_debugFM2v2(const char *s, const float *f) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800259 LOGD("%s {%f, %f", s, f[0], f[2]);
260 LOGD("%s %f, %f}",s, f[1], f[3]);
Jason Samsd64188a2010-08-06 16:22:50 -0700261}
262
Jason Samsd79b2e92010-05-19 17:22:57 -0700263static void SC_debugI32(const char *s, int32_t i) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800264 LOGD("%s %i 0x%x", s, i, i);
Romain Guyd22fff72009-08-20 17:08:33 -0700265}
Jason Sams17966512010-07-28 11:17:53 -0700266static void SC_debugU32(const char *s, uint32_t i) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800267 LOGD("%s %u 0x%x", s, i, i);
Stephen Hines65688962010-10-15 12:47:49 -0700268}
269static void SC_debugLL64(const char *s, long long ll) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800270 LOGD("%s %lld 0x%llx", s, ll, ll);
Stephen Hines65688962010-10-15 12:47:49 -0700271}
272static void SC_debugULL64(const char *s, unsigned long long ll) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800273 LOGD("%s %llu 0x%llx", s, ll, ll);
Jason Sams17966512010-07-28 11:17:53 -0700274}
Romain Guyd22fff72009-08-20 17:08:33 -0700275
Jason Sams8e6c17f2010-07-19 15:38:19 -0700276static void SC_debugP(const char *s, const void *p) {
Jason Samsbf2afed2011-01-18 18:22:19 -0800277 LOGD("%s %p", s, p);
Jason Sams8e6c17f2010-07-19 15:38:19 -0700278}
279
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800280static uint32_t SC_toClient2(int cmdID, void *data, int len) {
Jason Sams516c3192009-10-06 13:58:47 -0700281 GET_TLS();
Jason Sams17966512010-07-28 11:17:53 -0700282 //LOGE("SC_toClient %i %i %i", cmdID, len);
Jason Sams1c415172010-11-08 17:06:46 -0800283 return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, false);
Jason Sams516c3192009-10-06 13:58:47 -0700284}
285
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800286static uint32_t SC_toClient(int cmdID) {
Jason Samsbd2197f2009-10-07 18:14:01 -0700287 GET_TLS();
Jason Sams17966512010-07-28 11:17:53 -0700288 //LOGE("SC_toClient %i", cmdID);
Jason Sams1c415172010-11-08 17:06:46 -0800289 return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, false);
Jason Sams17966512010-07-28 11:17:53 -0700290}
291
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800292static uint32_t SC_toClientBlocking2(int cmdID, void *data, int len) {
Jason Sams17966512010-07-28 11:17:53 -0700293 GET_TLS();
294 //LOGE("SC_toClientBlocking %i %i", cmdID, len);
Jason Sams1c415172010-11-08 17:06:46 -0800295 return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, true);
Jason Sams17966512010-07-28 11:17:53 -0700296}
297
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800298static uint32_t SC_toClientBlocking(int cmdID) {
Jason Sams17966512010-07-28 11:17:53 -0700299 GET_TLS();
300 //LOGE("SC_toClientBlocking %i", cmdID);
Jason Sams1c415172010-11-08 17:06:46 -0800301 return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, true);
Jason Samsbd2197f2009-10-07 18:14:01 -0700302}
303
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800304int SC_divsi3(int a, int b) {
Jason Sams4d339932010-05-11 14:03:58 -0700305 return a / b;
306}
Jason Samsbd2197f2009-10-07 18:14:01 -0700307
Bryan Mawhinneyc0aaccc2010-11-11 14:33:12 +0000308int SC_modsi3(int a, int b) {
309 return a % b;
310}
311
Stephen Hines7e893e12011-01-24 12:03:51 -0800312unsigned int SC_udivsi3(unsigned int a, unsigned int b) {
313 return a / b;
314}
315
316unsigned int SC_umodsi3(unsigned int a, unsigned int b) {
317 return a % b;
318}
319
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800320int SC_getAllocation(const void *ptr) {
Jason Sams1de0b872010-05-17 14:55:34 -0700321 GET_TLS();
322 const Allocation *alloc = sc->ptrToAllocation(ptr);
323 return (int)alloc;
324}
325
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800326void SC_allocationMarkDirty(RsAllocation a) {
Alex Sakhartchouk8e954662010-09-01 16:34:48 -0700327 Allocation *alloc = static_cast<Allocation *>(a);
328 alloc->sendDirty();
329}
Jason Sams1de0b872010-05-17 14:55:34 -0700330
Jason Sams8f8a5722010-07-15 17:11:13 -0700331void SC_ForEach(RsScript vs,
332 RsAllocation vin,
333 RsAllocation vout,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800334 const void *usr) {
Jason Samsf17bccc2010-05-28 18:23:22 -0700335 GET_TLS();
Jason Sams8f8a5722010-07-15 17:11:13 -0700336 const Allocation *ain = static_cast<const Allocation *>(vin);
Jason Samsf17bccc2010-05-28 18:23:22 -0700337 Allocation *aout = static_cast<Allocation *>(vout);
Jason Sams8f8a5722010-07-15 17:11:13 -0700338 Script *s = static_cast<Script *>(vs);
339 s->runForEach(rsc, ain, aout, usr);
Jason Samsf17bccc2010-05-28 18:23:22 -0700340}
341
Jason Sams8f8a5722010-07-15 17:11:13 -0700342void SC_ForEach2(RsScript vs,
343 RsAllocation vin,
344 RsAllocation vout,
345 const void *usr,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800346 const RsScriptCall *call) {
Jason Samsf17bccc2010-05-28 18:23:22 -0700347 GET_TLS();
Jason Sams8f8a5722010-07-15 17:11:13 -0700348 const Allocation *ain = static_cast<const Allocation *>(vin);
Jason Samsf17bccc2010-05-28 18:23:22 -0700349 Allocation *aout = static_cast<Allocation *>(vout);
Jason Samsf17bccc2010-05-28 18:23:22 -0700350 Script *s = static_cast<Script *>(vs);
Jason Sams8f8a5722010-07-15 17:11:13 -0700351 s->runForEach(rsc, ain, aout, usr, call);
Jason Samsf17bccc2010-05-28 18:23:22 -0700352}
353
Jason Sams1afbf542011-01-25 21:33:44 -0800354
355//////////////////////////////////////////////////////////////////////////////
356// Heavy math functions
357//////////////////////////////////////////////////////////////////////////////
358
359typedef struct {
360 float m[16];
361} rs_matrix4x4;
362
363typedef struct {
364 float m[9];
365} rs_matrix3x3;
366
367typedef struct {
368 float m[4];
369} rs_matrix2x2;
370
371static inline void
372rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) {
373 m->m[row * 4 + col] = v;
374}
375
376static inline float
377rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) {
378 return m->m[row * 4 + col];
379}
380
381static inline void
382rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) {
383 m->m[row * 3 + col] = v;
384}
385
386static inline float
387rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) {
388 return m->m[row * 3 + col];
389}
390
391static inline void
392rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) {
393 m->m[row * 2 + col] = v;
394}
395
396static inline float
397rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) {
398 return m->m[row * 2 + col];
399}
400
401
402static void SC_MatrixLoadIdentity_4x4(rs_matrix4x4 *m) {
403 m->m[0] = 1.f;
404 m->m[1] = 0.f;
405 m->m[2] = 0.f;
406 m->m[3] = 0.f;
407 m->m[4] = 0.f;
408 m->m[5] = 1.f;
409 m->m[6] = 0.f;
410 m->m[7] = 0.f;
411 m->m[8] = 0.f;
412 m->m[9] = 0.f;
413 m->m[10] = 1.f;
414 m->m[11] = 0.f;
415 m->m[12] = 0.f;
416 m->m[13] = 0.f;
417 m->m[14] = 0.f;
418 m->m[15] = 1.f;
419}
420
421static void SC_MatrixLoadIdentity_3x3(rs_matrix3x3 *m) {
422 m->m[0] = 1.f;
423 m->m[1] = 0.f;
424 m->m[2] = 0.f;
425 m->m[3] = 0.f;
426 m->m[4] = 1.f;
427 m->m[5] = 0.f;
428 m->m[6] = 0.f;
429 m->m[7] = 0.f;
430 m->m[8] = 1.f;
431}
432
433static void SC_MatrixLoadIdentity_2x2(rs_matrix2x2 *m) {
434 m->m[0] = 1.f;
435 m->m[1] = 0.f;
436 m->m[2] = 0.f;
437 m->m[3] = 1.f;
438}
439
440static void SC_MatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v) {
441 m->m[0] = v[0];
442 m->m[1] = v[1];
443 m->m[2] = v[2];
444 m->m[3] = v[3];
445 m->m[4] = v[4];
446 m->m[5] = v[5];
447 m->m[6] = v[6];
448 m->m[7] = v[7];
449 m->m[8] = v[8];
450 m->m[9] = v[9];
451 m->m[10] = v[10];
452 m->m[11] = v[11];
453 m->m[12] = v[12];
454 m->m[13] = v[13];
455 m->m[14] = v[14];
456 m->m[15] = v[15];
457}
458
459static void SC_MatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v) {
460 m->m[0] = v[0];
461 m->m[1] = v[1];
462 m->m[2] = v[2];
463 m->m[3] = v[3];
464 m->m[4] = v[4];
465 m->m[5] = v[5];
466 m->m[6] = v[6];
467 m->m[7] = v[7];
468 m->m[8] = v[8];
469}
470
471static void SC_MatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v) {
472 m->m[0] = v[0];
473 m->m[1] = v[1];
474 m->m[2] = v[2];
475 m->m[3] = v[3];
476}
477
478static void SC_MatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v) {
479 m->m[0] = v->m[0];
480 m->m[1] = v->m[1];
481 m->m[2] = v->m[2];
482 m->m[3] = v->m[3];
483 m->m[4] = v->m[4];
484 m->m[5] = v->m[5];
485 m->m[6] = v->m[6];
486 m->m[7] = v->m[7];
487 m->m[8] = v->m[8];
488 m->m[9] = v->m[9];
489 m->m[10] = v->m[10];
490 m->m[11] = v->m[11];
491 m->m[12] = v->m[12];
492 m->m[13] = v->m[13];
493 m->m[14] = v->m[14];
494 m->m[15] = v->m[15];
495}
496
497static void SC_MatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v) {
498 m->m[0] = v->m[0];
499 m->m[1] = v->m[1];
500 m->m[2] = v->m[2];
501 m->m[3] = 0.f;
502 m->m[4] = v->m[3];
503 m->m[5] = v->m[4];
504 m->m[6] = v->m[5];
505 m->m[7] = 0.f;
506 m->m[8] = v->m[6];
507 m->m[9] = v->m[7];
508 m->m[10] = v->m[8];
509 m->m[11] = 0.f;
510 m->m[12] = 0.f;
511 m->m[13] = 0.f;
512 m->m[14] = 0.f;
513 m->m[15] = 1.f;
514}
515
516static void SC_MatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v) {
517 m->m[0] = v->m[0];
518 m->m[1] = v->m[1];
519 m->m[2] = 0.f;
520 m->m[3] = 0.f;
521 m->m[4] = v->m[2];
522 m->m[5] = v->m[3];
523 m->m[6] = 0.f;
524 m->m[7] = 0.f;
525 m->m[8] = 0.f;
526 m->m[9] = 0.f;
527 m->m[10] = 1.f;
528 m->m[11] = 0.f;
529 m->m[12] = 0.f;
530 m->m[13] = 0.f;
531 m->m[14] = 0.f;
532 m->m[15] = 1.f;
533}
534
535static void SC_MatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v) {
536 m->m[0] = v->m[0];
537 m->m[1] = v->m[1];
538 m->m[2] = v->m[2];
539 m->m[3] = v->m[3];
540 m->m[4] = v->m[4];
541 m->m[5] = v->m[5];
542 m->m[6] = v->m[6];
543 m->m[7] = v->m[7];
544 m->m[8] = v->m[8];
545}
546
547static void SC_MatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v) {
548 m->m[0] = v->m[0];
549 m->m[1] = v->m[1];
550 m->m[2] = v->m[2];
551 m->m[3] = v->m[3];
552}
553
554static void SC_MatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
555 float c, s;
556 m->m[3] = 0;
557 m->m[7] = 0;
558 m->m[11]= 0;
559 m->m[12]= 0;
560 m->m[13]= 0;
561 m->m[14]= 0;
562 m->m[15]= 1;
563 rot *= (float)(M_PI / 180.0f);
564 c = cos(rot);
565 s = sin(rot);
566
567 const float len = x*x + y*y + z*z;
568 if (len != 1) {
569 const float recipLen = 1.f / sqrt(len);
570 x *= recipLen;
571 y *= recipLen;
572 z *= recipLen;
573 }
574 const float nc = 1.0f - c;
575 const float xy = x * y;
576 const float yz = y * z;
577 const float zx = z * x;
578 const float xs = x * s;
579 const float ys = y * s;
580 const float zs = z * s;
581 m->m[ 0] = x*x*nc + c;
582 m->m[ 4] = xy*nc - zs;
583 m->m[ 8] = zx*nc + ys;
584 m->m[ 1] = xy*nc + zs;
585 m->m[ 5] = y*y*nc + c;
586 m->m[ 9] = yz*nc - xs;
587 m->m[ 2] = zx*nc - ys;
588 m->m[ 6] = yz*nc + xs;
589 m->m[10] = z*z*nc + c;
590}
591
592static void SC_MatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z) {
593 SC_MatrixLoadIdentity_4x4(m);
594 m->m[0] = x;
595 m->m[5] = y;
596 m->m[10] = z;
597}
598
599static void SC_MatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z) {
600 SC_MatrixLoadIdentity_4x4(m);
601 m->m[12] = x;
602 m->m[13] = y;
603 m->m[14] = z;
604}
605
606static void SC_MatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) {
607 for (int i=0 ; i<4 ; i++) {
608 float ri0 = 0;
609 float ri1 = 0;
610 float ri2 = 0;
611 float ri3 = 0;
612 for (int j=0 ; j<4 ; j++) {
613 const float rhs_ij = rsMatrixGet(rhs, i,j);
614 ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
615 ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
616 ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
617 ri3 += rsMatrixGet(lhs, j, 3) * rhs_ij;
618 }
619 rsMatrixSet(m, i, 0, ri0);
620 rsMatrixSet(m, i, 1, ri1);
621 rsMatrixSet(m, i, 2, ri2);
622 rsMatrixSet(m, i, 3, ri3);
623 }
624}
625
626static void SC_MatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs) {
627 rs_matrix4x4 mt;
628 SC_MatrixLoadMultiply_4x4_4x4_4x4(&mt, m, rhs);
629 SC_MatrixLoad_4x4_4x4(m, &mt);
630}
631
632static void SC_MatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) {
633 for (int i=0 ; i<3 ; i++) {
634 float ri0 = 0;
635 float ri1 = 0;
636 float ri2 = 0;
637 for (int j=0 ; j<3 ; j++) {
638 const float rhs_ij = rsMatrixGet(rhs, i,j);
639 ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
640 ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
641 ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
642 }
643 rsMatrixSet(m, i, 0, ri0);
644 rsMatrixSet(m, i, 1, ri1);
645 rsMatrixSet(m, i, 2, ri2);
646 }
647}
648
649static void SC_MatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs) {
650 rs_matrix3x3 mt;
651 SC_MatrixLoadMultiply_3x3_3x3_3x3(&mt, m, rhs);
652 SC_MatrixLoad_3x3_3x3(m, &mt);
653}
654
655static void SC_MatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
656 for (int i=0 ; i<2 ; i++) {
657 float ri0 = 0;
658 float ri1 = 0;
659 for (int j=0 ; j<2 ; j++) {
660 const float rhs_ij = rsMatrixGet(rhs, i,j);
661 ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
662 ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
663 }
664 rsMatrixSet(m, i, 0, ri0);
665 rsMatrixSet(m, i, 1, ri1);
666 }
667}
668
669static void SC_MatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs) {
670 rs_matrix2x2 mt;
671 SC_MatrixLoadMultiply_2x2_2x2_2x2(&mt, m, rhs);
672 SC_MatrixLoad_2x2_2x2(m, &mt);
673}
674
675static void SC_MatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
676 rs_matrix4x4 m1;
677 SC_MatrixLoadRotate(&m1, rot, x, y, z);
678 SC_MatrixMultiply_4x4_4x4(m, &m1);
679}
680
681static void SC_MatrixScale(rs_matrix4x4 *m, float x, float y, float z) {
682 rs_matrix4x4 m1;
683 SC_MatrixLoadScale(&m1, x, y, z);
684 SC_MatrixMultiply_4x4_4x4(m, &m1);
685}
686
687static void SC_MatrixTranslate(rs_matrix4x4 *m, float x, float y, float z) {
688 rs_matrix4x4 m1;
689 SC_MatrixLoadTranslate(&m1, x, y, z);
690 SC_MatrixMultiply_4x4_4x4(m, &m1);
691}
692
693static void SC_MatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
694 SC_MatrixLoadIdentity_4x4(m);
695 m->m[0] = 2.f / (right - left);
696 m->m[5] = 2.f / (top - bottom);
697 m->m[10]= -2.f / (far - near);
698 m->m[12]= -(right + left) / (right - left);
699 m->m[13]= -(top + bottom) / (top - bottom);
700 m->m[14]= -(far + near) / (far - near);
701}
702
703static void SC_MatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
704 SC_MatrixLoadIdentity_4x4(m);
705 m->m[0] = 2.f * near / (right - left);
706 m->m[5] = 2.f * near / (top - bottom);
707 m->m[8] = (right + left) / (right - left);
708 m->m[9] = (top + bottom) / (top - bottom);
709 m->m[10]= -(far + near) / (far - near);
710 m->m[11]= -1.f;
711 m->m[14]= -2.f * far * near / (far - near);
712 m->m[15]= 0.f;
713}
714
715static void SC_MatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far) {
716 float top = near * tan((float) (fovy * M_PI / 360.0f));
717 float bottom = -top;
718 float left = bottom * aspect;
719 float right = top * aspect;
720 SC_MatrixLoadFrustum(m, left, right, bottom, top, near, far);
721}
722
723
724// Returns true if the matrix was successfully inversed
725static bool SC_MatrixInverse_4x4(rs_matrix4x4 *m) {
726 rs_matrix4x4 result;
727
728 int i, j;
729 for (i = 0; i < 4; ++i) {
730 for (j = 0; j < 4; ++j) {
731 // computeCofactor for int i, int j
732 int c0 = (i+1) % 4;
733 int c1 = (i+2) % 4;
734 int c2 = (i+3) % 4;
735 int r0 = (j+1) % 4;
736 int r1 = (j+2) % 4;
737 int r2 = (j+3) % 4;
738
739 float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
740 - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
741 + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
742
743 float cofactor = (i+j) & 1 ? -minor : minor;
744
745 result.m[4*i + j] = cofactor;
746 }
747 }
748
749 // Dot product of 0th column of source and 0th row of result
750 float det = m->m[0]*result.m[0] + m->m[4]*result.m[1] +
751 m->m[8]*result.m[2] + m->m[12]*result.m[3];
752
753 if (fabs(det) < 1e-6) {
754 return false;
755 }
756
757 det = 1.0f / det;
758 for (i = 0; i < 16; ++i) {
759 m->m[i] = result.m[i] * det;
760 }
761
762 return true;
763}
764
765// Returns true if the matrix was successfully inversed
766static bool SC_MatrixInverseTranspose_4x4(rs_matrix4x4 *m) {
767 rs_matrix4x4 result;
768
769 int i, j;
770 for (i = 0; i < 4; ++i) {
771 for (j = 0; j < 4; ++j) {
772 // computeCofactor for int i, int j
773 int c0 = (i+1) % 4;
774 int c1 = (i+2) % 4;
775 int c2 = (i+3) % 4;
776 int r0 = (j+1) % 4;
777 int r1 = (j+2) % 4;
778 int r2 = (j+3) % 4;
779
780 float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
781 - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
782 + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
783
784 float cofactor = (i+j) & 1 ? -minor : minor;
785
786 result.m[4*j + i] = cofactor;
787 }
788 }
789
790 // Dot product of 0th column of source and 0th column of result
791 float det = m->m[0]*result.m[0] + m->m[4]*result.m[4] +
792 m->m[8]*result.m[8] + m->m[12]*result.m[12];
793
794 if (fabs(det) < 1e-6) {
795 return false;
796 }
797
798 det = 1.0f / det;
799 for (i = 0; i < 16; ++i) {
800 m->m[i] = result.m[i] * det;
801 }
802
803 return true;
804}
805
806static void SC_MatrixTranspose_4x4(rs_matrix4x4 *m) {
807 int i, j;
808 float temp;
809 for (i = 0; i < 3; ++i) {
810 for (j = i + 1; j < 4; ++j) {
811 temp = m->m[i*4 + j];
812 m->m[i*4 + j] = m->m[j*4 + i];
813 m->m[j*4 + i] = temp;
814 }
815 }
816}
817
818static void SC_MatrixTranspose_3x3(rs_matrix3x3 *m) {
819 int i, j;
820 float temp;
821 for (i = 0; i < 2; ++i) {
822 for (j = i + 1; j < 3; ++j) {
823 temp = m->m[i*3 + j];
824 m->m[i*3 + j] = m->m[j*4 + i];
825 m->m[j*3 + i] = temp;
826 }
827 }
828}
829
830static void SC_MatrixTranspose_2x2(rs_matrix2x2 *m) {
831 float temp = m->m[1];
832 m->m[1] = m->m[2];
833 m->m[2] = temp;
834}
835
836
Jason Samsc97bb882009-07-20 14:31:06 -0700837//////////////////////////////////////////////////////////////////////////////
838// Class implementation
839//////////////////////////////////////////////////////////////////////////////
840
Jason Sams4d339932010-05-11 14:03:58 -0700841// llvm name mangling ref
842// <builtin-type> ::= v # void
843// ::= b # bool
844// ::= c # char
845// ::= a # signed char
846// ::= h # unsigned char
847// ::= s # short
848// ::= t # unsigned short
849// ::= i # int
850// ::= j # unsigned int
851// ::= l # long
852// ::= m # unsigned long
853// ::= x # long long, __int64
854// ::= y # unsigned long long, __int64
855// ::= f # float
856// ::= d # double
Jason Samsc97bb882009-07-20 14:31:06 -0700857
Jason Sams536923d2010-05-18 13:35:45 -0700858static ScriptCState::SymbolTable_t gSyms[] = {
Jason Sams8f0adba2010-11-01 14:26:30 -0700859 { "__divsi3", (void *)&SC_divsi3, true },
Bryan Mawhinneyc0aaccc2010-11-11 14:33:12 +0000860 { "__modsi3", (void *)&SC_modsi3, true },
Stephen Hines7e893e12011-01-24 12:03:51 -0800861 { "__udivsi3", (void *)&SC_udivsi3, true },
862 { "__umodsi3", (void *)&SC_umodsi3, true },
Stephen Hines3f73da52011-02-04 14:39:57 -0800863 { "memset", (void *)&memset, true },
864 { "memcpy", (void *)&memcpy, true },
Jason Sams4d339932010-05-11 14:03:58 -0700865
Jason Samsd79b2e92010-05-19 17:22:57 -0700866 // allocation
Jason Sams8f0adba2010-11-01 14:26:30 -0700867 { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true },
868 { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true },
869 { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true },
870 { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true },
871 { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true },
872 { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true },
Jason Samsd79b2e92010-05-19 17:22:57 -0700873
Jason Sams8f0adba2010-11-01 14:26:30 -0700874 { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true },
875 { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true },
876 { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true },
Jason Sams8e6c17f2010-07-19 15:38:19 -0700877
Jason Sams8f0adba2010-11-01 14:26:30 -0700878 { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_setObject, true },
879 { "_Z13rsClearObjectP10rs_element", (void *)&SC_clearObject, true },
880 { "_Z10rsIsObject10rs_element", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700881
Jason Sams8f0adba2010-11-01 14:26:30 -0700882 { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_setObject, true },
883 { "_Z13rsClearObjectP7rs_type", (void *)&SC_clearObject, true },
884 { "_Z10rsIsObject7rs_type", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700885
Jason Sams8f0adba2010-11-01 14:26:30 -0700886 { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_setObject, true },
887 { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_clearObject, true },
888 { "_Z10rsIsObject13rs_allocation", (void *)&SC_isObject, true },
Jason Sams02f62aa2010-08-16 12:41:48 -0700889
Jason Sams8f0adba2010-11-01 14:26:30 -0700890 { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_setObject, true },
891 { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_clearObject, true },
892 { "_Z10rsIsObject10rs_sampler", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700893
Jason Sams8f0adba2010-11-01 14:26:30 -0700894 { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_setObject, true },
895 { "_Z13rsClearObjectP9rs_script", (void *)&SC_clearObject, true },
896 { "_Z10rsIsObject9rs_script", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700897
Jason Sams8f0adba2010-11-01 14:26:30 -0700898 { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_setObject, true },
899 { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_clearObject, true },
900 { "_Z10rsIsObject7rs_mesh", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700901
Jason Sams8f0adba2010-11-01 14:26:30 -0700902 { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_setObject, true },
903 { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_clearObject, true },
904 { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700905
Jason Sams8f0adba2010-11-01 14:26:30 -0700906 { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_setObject, true },
907 { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_clearObject, true },
908 { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700909
Jason Sams8f0adba2010-11-01 14:26:30 -0700910 { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_setObject, true },
911 { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_clearObject, true },
912 { "_Z10rsIsObject17rs_program_raster", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700913
Jason Sams8f0adba2010-11-01 14:26:30 -0700914 { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_setObject, true },
915 { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_clearObject, true },
916 { "_Z10rsIsObject16rs_program_store", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700917
Jason Sams8f0adba2010-11-01 14:26:30 -0700918 { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_setObject, true },
919 { "_Z13rsClearObjectP7rs_font", (void *)&SC_clearObject, true },
920 { "_Z10rsIsObject7rs_font", (void *)&SC_isObject, true },
Jason Sams4fd8bb42010-09-17 13:17:17 -0700921
922
Jason Sams8f0adba2010-11-01 14:26:30 -0700923 { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_allocationMarkDirty, true },
Alex Sakhartchouk8e954662010-09-01 16:34:48 -0700924
Jason Sams02f62aa2010-08-16 12:41:48 -0700925
Jason Samsd79b2e92010-05-19 17:22:57 -0700926 // Debug
Jason Sams8f0adba2010-11-01 14:26:30 -0700927 { "_Z7rsDebugPKcf", (void *)&SC_debugF, true },
928 { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true },
929 { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true },
930 { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true },
931 { "_Z7rsDebugPKcd", (void *)&SC_debugD, true },
932 { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true },
933 { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true },
934 { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true },
935 { "_Z7rsDebugPKci", (void *)&SC_debugI32, true },
936 { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true },
Stephen Hines65688962010-10-15 12:47:49 -0700937 // Both "long" and "unsigned long" need to be redirected to their
938 // 64-bit counterparts, since we have hacked Slang to use 64-bit
939 // for "long" on Arm (to be similar to Java).
Jason Sams8f0adba2010-11-01 14:26:30 -0700940 { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true },
941 { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true },
942 { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true },
943 { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true },
944 { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true },
Jason Samsd79b2e92010-05-19 17:22:57 -0700945
946 // RS Math
Jason Sams8f0adba2010-11-01 14:26:30 -0700947 { "_Z6rsRandi", (void *)&SC_randi, true },
948 { "_Z6rsRandii", (void *)&SC_randi2, true },
949 { "_Z6rsRandf", (void *)&SC_randf, true },
950 { "_Z6rsRandff", (void *)&SC_randf2, true },
951 { "_Z6rsFracf", (void *)&SC_frac, true },
Jason Samsd79b2e92010-05-19 17:22:57 -0700952
953 // time
Stephen Hines1ac9da62011-01-07 15:11:30 -0800954 { "_Z6rsTimePi", (void *)&SC_time, true },
955 { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_localtime, true },
Jason Sams8f0adba2010-11-01 14:26:30 -0700956 { "_Z14rsUptimeMillisv", (void*)&SC_uptimeMillis, true },
957 { "_Z13rsUptimeNanosv", (void*)&SC_uptimeNanos, true },
958 { "_Z7rsGetDtv", (void*)&SC_getDt, false },
Jason Samsd79b2e92010-05-19 17:22:57 -0700959
Jason Sams8f0adba2010-11-01 14:26:30 -0700960 { "_Z14rsSendToClienti", (void *)&SC_toClient, false },
961 { "_Z14rsSendToClientiPKvj", (void *)&SC_toClient2, false },
962 { "_Z22rsSendToClientBlockingi", (void *)&SC_toClientBlocking, false },
963 { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_toClientBlocking2, false },
Jason Samsd79b2e92010-05-19 17:22:57 -0700964
Jason Sams1afbf542011-01-25 21:33:44 -0800965 // matrix
Stephen Hines413bce42011-03-14 19:15:47 -0700966 { "_Z20rsMatrixLoadIdentityP12rs_matrix4x4", (void *)&SC_MatrixLoadIdentity_4x4, true },
967 { "_Z20rsMatrixLoadIdentityP12rs_matrix3x3", (void *)&SC_MatrixLoadIdentity_3x3, true },
968 { "_Z20rsMatrixLoadIdentityP12rs_matrix2x2", (void *)&SC_MatrixLoadIdentity_2x2, true },
Jason Sams1afbf542011-01-25 21:33:44 -0800969
Stephen Hines413bce42011-03-14 19:15:47 -0700970 { "_Z12rsMatrixLoadP12rs_matrix4x4PKf", (void *)&SC_MatrixLoad_4x4_f, true },
971 { "_Z12rsMatrixLoadP12rs_matrix3x3PKf", (void *)&SC_MatrixLoad_3x3_f, true },
972 { "_Z12rsMatrixLoadP12rs_matrix2x2PKf", (void *)&SC_MatrixLoad_2x2_f, true },
Jason Sams1afbf542011-01-25 21:33:44 -0800973
Stephen Hines413bce42011-03-14 19:15:47 -0700974 { "_Z12rsMatrixLoadP12rs_matrix4x4PKS_", (void *)&SC_MatrixLoad_4x4_4x4, true },
975 { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix3x3", (void *)&SC_MatrixLoad_4x4_3x3, true },
976 { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix2x2", (void *)&SC_MatrixLoad_4x4_2x2, true },
977 { "_Z12rsMatrixLoadP12rs_matrix3x3PKS_", (void *)&SC_MatrixLoad_3x3_3x3, true },
978 { "_Z12rsMatrixLoadP12rs_matrix2x2PKS_", (void *)&SC_MatrixLoad_2x2_2x2, true },
Jason Sams1afbf542011-01-25 21:33:44 -0800979
Stephen Hines413bce42011-03-14 19:15:47 -0700980 { "_Z18rsMatrixLoadRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadRotate, true },
981 { "_Z17rsMatrixLoadScaleP12rs_matrix4x4fff", (void *)&SC_MatrixLoadScale, true },
982 { "_Z21rsMatrixLoadTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixLoadTranslate, true },
983 { "_Z14rsMatrixRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixRotate, true },
984 { "_Z13rsMatrixScaleP12rs_matrix4x4fff", (void *)&SC_MatrixScale, true },
985 { "_Z17rsMatrixTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixTranslate, true },
Jason Sams1afbf542011-01-25 21:33:44 -0800986
Stephen Hines413bce42011-03-14 19:15:47 -0700987 { "_Z20rsMatrixLoadMultiplyP12rs_matrix4x4PKS_S2_", (void *)&SC_MatrixLoadMultiply_4x4_4x4_4x4, true },
988 { "_Z16rsMatrixMultiplyP12rs_matrix4x4PKS_", (void *)&SC_MatrixMultiply_4x4_4x4, true },
989 { "_Z20rsMatrixLoadMultiplyP12rs_matrix3x3PKS_S2_", (void *)&SC_MatrixLoadMultiply_3x3_3x3_3x3, true },
990 { "_Z16rsMatrixMultiplyP12rs_matrix3x3PKS_", (void *)&SC_MatrixMultiply_3x3_3x3, true },
991 { "_Z20rsMatrixLoadMultiplyP12rs_matrix2x2PKS_S2_", (void *)&SC_MatrixLoadMultiply_2x2_2x2_2x2, true },
992 { "_Z16rsMatrixMultiplyP12rs_matrix2x2PKS_", (void *)&SC_MatrixMultiply_2x2_2x2, true },
Jason Sams1afbf542011-01-25 21:33:44 -0800993
Stephen Hines413bce42011-03-14 19:15:47 -0700994 { "_Z17rsMatrixLoadOrthoP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadOrtho, true },
995 { "_Z19rsMatrixLoadFrustumP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadFrustum, true },
996 { "_Z23rsMatrixLoadPerspectiveP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadPerspective, true },
Jason Sams1afbf542011-01-25 21:33:44 -0800997
Stephen Hines413bce42011-03-14 19:15:47 -0700998 { "_Z15rsMatrixInverseP12rs_matrix4x4", (void *)&SC_MatrixInverse_4x4, true },
999 { "_Z24rsMatrixInverseTransposeP12rs_matrix4x4", (void *)&SC_MatrixInverseTranspose_4x4, true },
1000 { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_4x4, true },
1001 { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_3x3, true },
1002 { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_2x2, true },
Jason Sams1afbf542011-01-25 21:33:44 -08001003
Jason Sams8f0adba2010-11-01 14:26:30 -07001004 { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false },
1005 //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2, true },
Jason Samsd79b2e92010-05-19 17:22:57 -07001006
1007////////////////////////////////////////////////////////////////////
1008
Jason Sams8f0adba2010-11-01 14:26:30 -07001009 //{ "sinf_fast", (void *)&SC_sinf_fast, true },
1010 //{ "cosf_fast", (void *)&SC_cosf_fast, true },
Jason Samsc97bb882009-07-20 14:31:06 -07001011
Jason Sams8f0adba2010-11-01 14:26:30 -07001012 { NULL, NULL, false }
Jason Samsc97bb882009-07-20 14:31:06 -07001013};
1014
Alex Sakhartchouked9f2102010-11-09 17:00:54 -08001015const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) {
Jason Samsc97bb882009-07-20 14:31:06 -07001016 ScriptCState::SymbolTable_t *syms = gSyms;
1017
1018 while (syms->mPtr) {
1019 if (!strcmp(syms->mName, sym)) {
1020 return syms;
1021 }
1022 syms++;
1023 }
1024 return NULL;
1025}