blob: 956773bdecc22e548d7a410ffc1337066b2c9b52 [file] [log] [blame]
Jason Samse45ac6e2009-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"
Romain Guyb7f1a6d2009-08-03 21:12:51 -070020#include "rsNoise.h"
Jason Samse45ac6e2009-07-20 14:31:06 -070021
22#include "acc/acc.h"
Joe Onorato9c4e4ca2009-08-09 11:39:02 -070023#include "utils/Timers.h"
Jason Samse45ac6e2009-07-20 14:31:06 -070024
Romain Guy98e10fd2009-07-30 18:45:01 -070025#include <time.h>
Romain Guy98e10fd2009-07-30 18:45:01 -070026
Jason Samse45ac6e2009-07-20 14:31:06 -070027using namespace android;
28using namespace android::renderscript;
29
30#define GET_TLS() Context::ScriptTLSStruct * tls = \
31 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
32 Context * rsc = tls->mContext; \
33 ScriptC * sc = (ScriptC *) tls->mScript
34
Jason Samsbe36bf32010-05-11 14:03:58 -070035
Jason Samsbe36bf32010-05-11 14:03:58 -070036
37
38//////////////////////////////////////////////////////////////////////////////
39// Non-Updated code below
40//////////////////////////////////////////////////////////////////////////////
41
Jason Samsa57c0a72009-09-04 14:42:41 -070042typedef struct {
43 float x;
44 float y;
45 float z;
46} vec3_t;
47
48typedef struct {
49 float x;
50 float y;
51 float z;
52 float w;
53} vec4_t;
54
55typedef struct {
56 float x;
57 float y;
58} vec2_t;
Jason Samse45ac6e2009-07-20 14:31:06 -070059
Romain Guy06f7c932009-08-06 12:40:41 -070060
Jason Samsa57c0a72009-09-04 14:42:41 -070061//////////////////////////////////////////////////////////////////////////////
62// Vec3 routines
63//////////////////////////////////////////////////////////////////////////////
64
65static void SC_vec3Norm(vec3_t *v)
66{
67 float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
68 len = 1 / len;
69 v->x *= len;
70 v->y *= len;
71 v->z *= len;
72}
73
74static float SC_vec3Length(const vec3_t *v)
75{
76 return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
77}
78
79static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
80{
81 dest->x = lhs->x + rhs->x;
82 dest->y = lhs->y + rhs->y;
83 dest->z = lhs->z + rhs->z;
84}
85
86static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
87{
88 dest->x = lhs->x - rhs->x;
89 dest->y = lhs->y - rhs->y;
90 dest->z = lhs->z - rhs->z;
91}
92
93static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
94{
95 float x = lhs->y * rhs->z - lhs->z * rhs->y;
96 float y = lhs->z * rhs->x - lhs->x * rhs->z;
97 float z = lhs->x * rhs->y - lhs->y * rhs->x;
98 dest->x = x;
99 dest->y = y;
100 dest->z = z;
101}
102
103static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
104{
105 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
106}
107
108static void SC_vec3Scale(vec3_t *lhs, float scale)
109{
110 lhs->x *= scale;
111 lhs->y *= scale;
112 lhs->z *= scale;
113}
114
Romain Guyd6d4a5f2009-10-09 16:05:25 -0700115//////////////////////////////////////////////////////////////////////////////
116// Vec4 routines
117//////////////////////////////////////////////////////////////////////////////
118
119static void SC_vec4Norm(vec4_t *v)
120{
121 float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
122 len = 1 / len;
123 v->x *= len;
124 v->y *= len;
125 v->z *= len;
126 v->w *= len;
127}
128
129static float SC_vec4Length(const vec4_t *v)
130{
131 return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
132}
133
134static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
135{
136 dest->x = lhs->x + rhs->x;
137 dest->y = lhs->y + rhs->y;
138 dest->z = lhs->z + rhs->z;
139 dest->w = lhs->w + rhs->w;
140}
141
142static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
143{
144 dest->x = lhs->x - rhs->x;
145 dest->y = lhs->y - rhs->y;
146 dest->z = lhs->z - rhs->z;
147 dest->w = lhs->w - rhs->w;
148}
149
150static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
151{
152 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
153}
154
155static void SC_vec4Scale(vec4_t *lhs, float scale)
156{
157 lhs->x *= scale;
158 lhs->y *= scale;
159 lhs->z *= scale;
160 lhs->w *= scale;
161}
Jason Samse45ac6e2009-07-20 14:31:06 -0700162
163//////////////////////////////////////////////////////////////////////////////
164// Math routines
165//////////////////////////////////////////////////////////////////////////////
166
Romain Guy2275d632009-08-18 11:39:17 -0700167static float SC_sinf_fast(float x)
168{
169 const float A = 1.0f / (2.0f * M_PI);
170 const float B = -16.0f;
171 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -0700172
Romain Guy2275d632009-08-18 11:39:17 -0700173 // scale angle for easy argument reduction
174 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -0700175
Romain Guy2275d632009-08-18 11:39:17 -0700176 if (fabsf(x) >= 0.5f) {
177 // argument reduction
178 x = x - ceilf(x + 0.5f) + 1.0f;
179 }
Jason Samsa57c0a72009-09-04 14:42:41 -0700180
Romain Guy2275d632009-08-18 11:39:17 -0700181 const float y = B * x * fabsf(x) + C * x;
182 return 0.2215f * (y * fabsf(y) - y) + y;
183}
184
185static float SC_cosf_fast(float x)
186{
187 x += float(M_PI / 2);
188
189 const float A = 1.0f / (2.0f * M_PI);
190 const float B = -16.0f;
191 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -0700192
Romain Guy2275d632009-08-18 11:39:17 -0700193 // scale angle for easy argument reduction
194 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -0700195
Romain Guy2275d632009-08-18 11:39:17 -0700196 if (fabsf(x) >= 0.5f) {
197 // argument reduction
198 x = x - ceilf(x + 0.5f) + 1.0f;
199 }
Jason Samsa57c0a72009-09-04 14:42:41 -0700200
Romain Guy2275d632009-08-18 11:39:17 -0700201 const float y = B * x * fabsf(x) + C * x;
202 return 0.2215f * (y * fabsf(y) - y) + y;
203}
204
Jason Sams22fa3712010-05-19 17:22:57 -0700205
Jason Samse45ac6e2009-07-20 14:31:06 -0700206static float SC_randf(float max)
207{
208 float r = (float)rand();
209 return r / RAND_MAX * max;
210}
211
Romain Guy39dbc802009-07-31 11:20:59 -0700212static float SC_randf2(float min, float max)
213{
214 float r = (float)rand();
215 return r / RAND_MAX * (max - min) + min;
216}
217
Jason Sams22fa3712010-05-19 17:22:57 -0700218static int SC_randi(int max)
219{
220 return (int)SC_randf(max);
221}
222
223static int SC_randi2(int min, int max)
224{
225 return (int)SC_randf2(min, max);
226}
227
Romain Guyd6d4a5f2009-10-09 16:05:25 -0700228static int SC_sign(int value)
229{
230 return (value > 0) - (value < 0);
231}
232
Romain Guy27162ab2009-08-09 17:04:54 -0700233static int SC_clamp(int amount, int low, int high)
234{
235 return amount < low ? low : (amount > high ? high : amount);
236}
237
Jason Samsdac98f52009-09-18 14:24:24 -0700238static float SC_roundf(float v)
239{
240 return floorf(v + 0.4999999999);
241}
242
Romain Guy39dbc802009-07-31 11:20:59 -0700243static float SC_distf2(float x1, float y1, float x2, float y2)
244{
245 float x = x2 - x1;
246 float y = y2 - y1;
Jason Samse5ffb872009-08-09 17:01:55 -0700247 return sqrtf(x * x + y * y);
Romain Guy39dbc802009-07-31 11:20:59 -0700248}
249
250static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
251{
252 float x = x2 - x1;
253 float y = y2 - y1;
254 float z = z2 - z1;
Jason Samse5ffb872009-08-09 17:01:55 -0700255 return sqrtf(x * x + y * y + z * z);
Romain Guy39dbc802009-07-31 11:20:59 -0700256}
257
258static float SC_magf2(float a, float b)
259{
260 return sqrtf(a * a + b * b);
261}
262
263static float SC_magf3(float a, float b, float c)
264{
265 return sqrtf(a * a + b * b + c * c);
266}
267
Jason Samsbe36bf32010-05-11 14:03:58 -0700268static float SC_frac(float v)
269{
270 int i = (int)floor(v);
271 return fmin(v - i, 0x1.fffffep-1f);
272}
273
Romain Guy98e10fd2009-07-30 18:45:01 -0700274//////////////////////////////////////////////////////////////////////////////
275// Time routines
276//////////////////////////////////////////////////////////////////////////////
Jason Samse45ac6e2009-07-20 14:31:06 -0700277
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700278static int32_t SC_second()
Romain Guy98e10fd2009-07-30 18:45:01 -0700279{
280 GET_TLS();
281
282 time_t rawtime;
283 time(&rawtime);
284
Romain Guy519cdc92009-11-11 15:36:06 -0800285 struct tm *timeinfo;
286 timeinfo = localtime(&rawtime);
287 return timeinfo->tm_sec;
Romain Guy98e10fd2009-07-30 18:45:01 -0700288}
289
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700290static int32_t SC_minute()
Romain Guy98e10fd2009-07-30 18:45:01 -0700291{
292 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700293
Romain Guy98e10fd2009-07-30 18:45:01 -0700294 time_t rawtime;
295 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700296
Romain Guy519cdc92009-11-11 15:36:06 -0800297 struct tm *timeinfo;
298 timeinfo = localtime(&rawtime);
299 return timeinfo->tm_min;
Jason Samse5ffb872009-08-09 17:01:55 -0700300}
Romain Guy98e10fd2009-07-30 18:45:01 -0700301
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700302static int32_t SC_hour()
Romain Guy98e10fd2009-07-30 18:45:01 -0700303{
304 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700305
Romain Guy98e10fd2009-07-30 18:45:01 -0700306 time_t rawtime;
307 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700308
Romain Guy519cdc92009-11-11 15:36:06 -0800309 struct tm *timeinfo;
310 timeinfo = localtime(&rawtime);
311 return timeinfo->tm_hour;
Romain Guy39dbc802009-07-31 11:20:59 -0700312}
313
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700314static int32_t SC_day()
Romain Guy39dbc802009-07-31 11:20:59 -0700315{
316 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700317
Romain Guy39dbc802009-07-31 11:20:59 -0700318 time_t rawtime;
319 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700320
Romain Guy519cdc92009-11-11 15:36:06 -0800321 struct tm *timeinfo;
322 timeinfo = localtime(&rawtime);
323 return timeinfo->tm_mday;
Jason Samse5ffb872009-08-09 17:01:55 -0700324}
Jason Samse45ac6e2009-07-20 14:31:06 -0700325
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700326static int32_t SC_month()
Romain Guy39dbc802009-07-31 11:20:59 -0700327{
328 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700329
Romain Guy39dbc802009-07-31 11:20:59 -0700330 time_t rawtime;
331 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700332
Romain Guy519cdc92009-11-11 15:36:06 -0800333 struct tm *timeinfo;
334 timeinfo = localtime(&rawtime);
335 return timeinfo->tm_mon;
Jason Samse5ffb872009-08-09 17:01:55 -0700336}
Romain Guy39dbc802009-07-31 11:20:59 -0700337
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700338static int32_t SC_year()
Romain Guy39dbc802009-07-31 11:20:59 -0700339{
340 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700341
Romain Guy39dbc802009-07-31 11:20:59 -0700342 time_t rawtime;
343 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700344
Romain Guy519cdc92009-11-11 15:36:06 -0800345 struct tm *timeinfo;
346 timeinfo = localtime(&rawtime);
347 return timeinfo->tm_year;
Romain Guy39dbc802009-07-31 11:20:59 -0700348}
349
Jason Sams22fa3712010-05-19 17:22:57 -0700350static int64_t SC_uptimeMillis2()
351{
352 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
353}
354
355static int64_t SC_startTimeMillis2()
356{
357 GET_TLS();
358 return sc->mEnviroment.mStartTimeMillis;
359}
360
361static int64_t SC_elapsedTimeMillis2()
362{
363 GET_TLS();
364 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
365 - sc->mEnviroment.mStartTimeMillis;
366}
367
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700368static int32_t SC_uptimeMillis()
369{
370 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
371}
372
373static int32_t SC_startTimeMillis()
374{
375 GET_TLS();
376 return sc->mEnviroment.mStartTimeMillis;
377}
378
379static int32_t SC_elapsedTimeMillis()
380{
381 GET_TLS();
382 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
383 - sc->mEnviroment.mStartTimeMillis;
384}
385
Jason Samse45ac6e2009-07-20 14:31:06 -0700386//////////////////////////////////////////////////////////////////////////////
387// Matrix routines
388//////////////////////////////////////////////////////////////////////////////
389
390
391static void SC_matrixLoadIdentity(rsc_Matrix *mat)
392{
393 Matrix *m = reinterpret_cast<Matrix *>(mat);
394 m->loadIdentity();
395}
396
397static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
398{
399 Matrix *m = reinterpret_cast<Matrix *>(mat);
400 m->load(f);
401}
402
403static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
404{
405 Matrix *m = reinterpret_cast<Matrix *>(mat);
406 m->load(reinterpret_cast<const Matrix *>(newmat));
407}
408
409static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
410{
411 Matrix *m = reinterpret_cast<Matrix *>(mat);
412 m->loadRotate(rot, x, y, z);
413}
414
415static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
416{
417 Matrix *m = reinterpret_cast<Matrix *>(mat);
418 m->loadScale(x, y, z);
419}
420
421static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
422{
423 Matrix *m = reinterpret_cast<Matrix *>(mat);
424 m->loadTranslate(x, y, z);
425}
426
427static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
428{
429 Matrix *m = reinterpret_cast<Matrix *>(mat);
430 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
431 reinterpret_cast<const Matrix *>(rhs));
432}
433
434static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
435{
436 Matrix *m = reinterpret_cast<Matrix *>(mat);
437 m->multiply(reinterpret_cast<const Matrix *>(rhs));
438}
439
440static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
441{
442 Matrix *m = reinterpret_cast<Matrix *>(mat);
443 m->rotate(rot, x, y, z);
444}
445
446static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
447{
448 Matrix *m = reinterpret_cast<Matrix *>(mat);
449 m->scale(x, y, z);
450}
451
452static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
453{
454 Matrix *m = reinterpret_cast<Matrix *>(mat);
455 m->translate(x, y, z);
456}
457
458
Jason Samse45ac6e2009-07-20 14:31:06 -0700459//////////////////////////////////////////////////////////////////////////////
460//
461//////////////////////////////////////////////////////////////////////////////
462
Jason Samsbe36bf32010-05-11 14:03:58 -0700463static uint32_t SC_allocGetDimX(RsAllocation va)
464{
465 GET_TLS();
466 const Allocation *a = static_cast<const Allocation *>(va);
467 //LOGE("SC_allocGetDimX a=%p", a);
468 //LOGE(" type=%p", a->getType());
469 return a->getType()->getDimX();
470}
471
472static uint32_t SC_allocGetDimY(RsAllocation va)
473{
474 GET_TLS();
475 const Allocation *a = static_cast<const Allocation *>(va);
476 return a->getType()->getDimY();
477}
478
479static uint32_t SC_allocGetDimZ(RsAllocation va)
480{
481 GET_TLS();
482 const Allocation *a = static_cast<const Allocation *>(va);
483 return a->getType()->getDimZ();
484}
485
486static uint32_t SC_allocGetDimLOD(RsAllocation va)
487{
488 GET_TLS();
489 const Allocation *a = static_cast<const Allocation *>(va);
490 return a->getType()->getDimLOD();
491}
492
493static uint32_t SC_allocGetDimFaces(RsAllocation va)
494{
495 GET_TLS();
496 const Allocation *a = static_cast<const Allocation *>(va);
497 return a->getType()->getDimFaces();
498}
499
500
Jason Samse45ac6e2009-07-20 14:31:06 -0700501
Jason Sams22fa3712010-05-19 17:22:57 -0700502static void SC_debugF(const char *s, float f) {
503 LOGE("%s %f, 0x%08x", s, f, *((int *) (&f)));
Jason Samsc9d43db2009-07-28 12:02:16 -0700504}
Jason Sams22fa3712010-05-19 17:22:57 -0700505static void SC_debugFv2(const char *s, rsvF_2 fv) {
506 float *f = (float *)&fv;
507 LOGE("%s {%f, %f}", s, f[0], f[1]);
Romain Guy370ed152009-08-20 17:08:33 -0700508}
Jason Sams22fa3712010-05-19 17:22:57 -0700509static void SC_debugFv3(const char *s, rsvF_4 fv) {
510 float *f = (float *)&fv;
511 LOGE("%s {%f, %f, %f}", s, f[0], f[1], f[2]);
Jason Samsc9d43db2009-07-28 12:02:16 -0700512}
Jason Sams22fa3712010-05-19 17:22:57 -0700513static void SC_debugFv4(const char *s, rsvF_4 fv) {
514 float *f = (float *)&fv;
515 LOGE("%s {%f, %f, %f, %f}", s, f[0], f[1], f[2], f[3]);
516}
517static void SC_debugI32(const char *s, int32_t i) {
518 LOGE("%s %i 0x%x", s, i, i);
Romain Guy370ed152009-08-20 17:08:33 -0700519}
520
Jason Samsbe36bf32010-05-11 14:03:58 -0700521static uchar4 SC_convertColorTo8888_f3(float r, float g, float b) {
522 uchar4 t;
523 t.f[0] = (uint8_t)(r * 255.f);
524 t.f[1] = (uint8_t)(g * 255.f);
525 t.f[2] = (uint8_t)(b * 255.f);
526 t.f[3] = 0xff;
527 return t;
Jason Sams90b36a82009-08-17 13:56:09 -0700528}
529
Jason Samsbe36bf32010-05-11 14:03:58 -0700530static uchar4 SC_convertColorTo8888_f4(float r, float g, float b, float a) {
531 uchar4 t;
532 t.f[0] = (uint8_t)(r * 255.f);
533 t.f[1] = (uint8_t)(g * 255.f);
534 t.f[2] = (uint8_t)(b * 255.f);
535 t.f[3] = (uint8_t)(a * 255.f);
536 return t;
Jason Sams90b36a82009-08-17 13:56:09 -0700537}
538
Jason Sams8c401ef2009-10-06 13:58:47 -0700539static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
540{
541 GET_TLS();
Jason Samsbe36bf32010-05-11 14:03:58 -0700542 //LOGE("SC_toClient %i %i %i", cmdID, len, waitForSpace);
Jason Sams8c401ef2009-10-06 13:58:47 -0700543 return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
544}
545
Jason Sams3a27c952009-10-07 18:14:01 -0700546static void SC_scriptCall(int scriptID)
547{
548 GET_TLS();
549 rsc->runScript((Script *)scriptID, 0);
550}
551
Jason Samsbe36bf32010-05-11 14:03:58 -0700552static void SC_debugP(int i, void *p)
553{
554 LOGE("debug P %i %p, %i", i, p, (int)p);
555}
556
557static void SC_debugPi(int i, int p)
558{
559 LOGE("debug Pi %i 0x%08x, %i", i, p, (int)p);
560}
561
562static void SC_debugPf(int i, float p)
563{
564 LOGE("debug Pf %i %f, 0x%08x", i, p, reinterpret_cast<uint32_t *>(&p)[0]);
565}
566
567int SC_divsi3(int a, int b)
568{
569 return a / b;
570}
Jason Sams3a27c952009-10-07 18:14:01 -0700571
Jason Samsce92d4b2010-05-17 14:55:34 -0700572int SC_getAllocation(const void *ptr)
573{
574 GET_TLS();
575 const Allocation *alloc = sc->ptrToAllocation(ptr);
576 return (int)alloc;
577}
578
579
Jason Samse45ac6e2009-07-20 14:31:06 -0700580//////////////////////////////////////////////////////////////////////////////
581// Class implementation
582//////////////////////////////////////////////////////////////////////////////
583
Jason Samsbe36bf32010-05-11 14:03:58 -0700584// llvm name mangling ref
585// <builtin-type> ::= v # void
586// ::= b # bool
587// ::= c # char
588// ::= a # signed char
589// ::= h # unsigned char
590// ::= s # short
591// ::= t # unsigned short
592// ::= i # int
593// ::= j # unsigned int
594// ::= l # long
595// ::= m # unsigned long
596// ::= x # long long, __int64
597// ::= y # unsigned long long, __int64
598// ::= f # float
599// ::= d # double
Jason Samse45ac6e2009-07-20 14:31:06 -0700600
Jason Samsaeb094b2010-05-18 13:35:45 -0700601static ScriptCState::SymbolTable_t gSyms[] = {
Jason Samsbe36bf32010-05-11 14:03:58 -0700602 { "__divsi3", (void *)&SC_divsi3 },
603
Jason Sams22fa3712010-05-19 17:22:57 -0700604 // allocation
605 { "rsAllocationGetDimX", (void *)&SC_allocGetDimX },
606 { "rsAllocationGetDimY", (void *)&SC_allocGetDimY },
607 { "rsAllocationGetDimZ", (void *)&SC_allocGetDimZ },
608 { "rsAllocationGetDimLOD", (void *)&SC_allocGetDimLOD },
609 { "rsAllocationGetDimFaces", (void *)&SC_allocGetDimFaces },
610 { "rsGetAllocation", (void *)&SC_getAllocation },
611
612 // color
613 { "_Z17rsPackColorTo8888fff", (void *)&SC_convertColorTo8888_f3 },
614 { "_Z17rsPackColorTo8888ffff", (void *)&SC_convertColorTo8888_f4 },
615 //extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3);
616 //extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4);
617 //extern float4 rsUnpackColor8888(uchar4);
618 //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b);
619 //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3);
620 //extern float4 rsUnpackColor565(uchar4);
621
622 // Debug
623 { "_Z7rsDebugPKcf", (void *)&SC_debugF },
624 { "_Z7rsDebugPKcDv2_f", (void *)&SC_debugFv2 },
625 { "_Z7rsDebugPKcDv3_f", (void *)&SC_debugFv3 },
626 { "_Z7rsDebugPKcDv4_f", (void *)&SC_debugFv4 },
627 { "_Z7rsDebugPKci", (void *)&SC_debugI32 },
628 //extern void __attribute__((overloadable))rsDebug(const char *, const void *);
629
630
631 // RS Math
632 { "_Z6rsRandi", (void *)&SC_randi },
633 { "_Z6rsRandii", (void *)&SC_randi2 },
634 { "_Z6rsRandf", (void *)&SC_randf },
635 { "_Z6rsRandff", (void *)&SC_randf2 },
636 { "_Z6rsFracf", (void *)&SC_frac },
637
638 // time
639 { "rsSecond", (void *)&SC_second },
640 { "rsMinute", (void *)&SC_minute },
641 { "rsHour", (void *)&SC_hour },
642 { "rsDay", (void *)&SC_day },
643 { "rsMonth", (void *)&SC_month },
644 { "rsYear", (void *)&SC_year },
645 { "rsUptimeMillis", (void*)&SC_uptimeMillis2 },
646 { "rsStartTimeMillis", (void*)&SC_startTimeMillis2 },
647 { "rsElapsedTimeMillis", (void*)&SC_elapsedTimeMillis2 },
648
649 { "rsSendToClient", (void *)&SC_toClient },
650
651 // matrix
652 { "rsMatrixLoadIdentity", (void *)&SC_matrixLoadIdentity },
653 { "rsMatrixLoadFloat", (void *)&SC_matrixLoadFloat },
654 { "rsMatrixLoadMat", (void *)&SC_matrixLoadMat },
655 { "rsMatrixLoadRotate", (void *)&SC_matrixLoadRotate },
656 { "rsMatrixLoadScale", (void *)&SC_matrixLoadScale },
657 { "rsMatrixLoadTranslate", (void *)&SC_matrixLoadTranslate },
658 { "rsMatrixLoadMultiply", (void *)&SC_matrixLoadMultiply },
659 { "rsMatrixMultiply", (void *)&SC_matrixMultiply },
660 { "rsMatrixRotate", (void *)&SC_matrixRotate },
661 { "rsMatrixScale", (void *)&SC_matrixScale },
662 { "rsMatrixTranslate", (void *)&SC_matrixTranslate },
663
664
665////////////////////////////////////////////////////////////////////
666
Jason Samsbe36bf32010-05-11 14:03:58 -0700667 { "modf", (void *)&fmod },
Jason Samsbe36bf32010-05-11 14:03:58 -0700668 //{ "sinf_fast", (void *)&SC_sinf_fast },
669 //{ "cosf_fast", (void *)&SC_cosf_fast },
Jason Sams22fa3712010-05-19 17:22:57 -0700670 //{ "sign", (void *)&SC_sign },
671 //{ "clamp", (void *)&SC_clamp },
672 //{ "distf2", (void *)&SC_distf2 },
673 //{ "distf3", (void *)&SC_distf3 },
674 //{ "magf2", (void *)&SC_magf2 },
675 //{ "magf3", (void *)&SC_magf3 },
676 //{ "mapf", (void *)&SC_mapf },
Jason Samsbe36bf32010-05-11 14:03:58 -0700677 { "noisef", (void *)&SC_noisef },
678 { "noisef2", (void *)&SC_noisef2 },
679 { "noisef3", (void *)&SC_noisef3 },
680 { "turbulencef2", (void *)&SC_turbulencef2 },
681 { "turbulencef3", (void *)&SC_turbulencef3 },
Jason Samse45ac6e2009-07-20 14:31:06 -0700682
Jason Samsbe36bf32010-05-11 14:03:58 -0700683 { "scriptCall", (void *)&SC_scriptCall },
Jason Samsce92d4b2010-05-17 14:55:34 -0700684
Jason Samsc9d43db2009-07-28 12:02:16 -0700685
Jason Samsbe36bf32010-05-11 14:03:58 -0700686 { NULL, NULL }
Jason Samse45ac6e2009-07-20 14:31:06 -0700687};
688
689const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
690{
691 ScriptCState::SymbolTable_t *syms = gSyms;
692
693 while (syms->mPtr) {
694 if (!strcmp(syms->mName, sym)) {
695 return syms;
696 }
697 syms++;
698 }
699 return NULL;
700}
701