blob: 3f3ff23167aad0437153f928e6bc3f26b3625d51 [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"
20
21#include "acc/acc.h"
Joe Onorato9c4e4ca2009-08-09 11:39:02 -070022#include "utils/Timers.h"
Jason Samse45ac6e2009-07-20 14:31:06 -070023
Romain Guy98e10fd2009-07-30 18:45:01 -070024#include <time.h>
Romain Guy98e10fd2009-07-30 18:45:01 -070025
Jason Samse45ac6e2009-07-20 14:31:06 -070026using namespace android;
27using namespace android::renderscript;
28
29#define GET_TLS() Context::ScriptTLSStruct * tls = \
30 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
31 Context * rsc = tls->mContext; \
32 ScriptC * sc = (ScriptC *) tls->mScript
33
Jason Samsbe36bf32010-05-11 14:03:58 -070034
Jason Samsbe36bf32010-05-11 14:03:58 -070035
36
37//////////////////////////////////////////////////////////////////////////////
38// Non-Updated code below
39//////////////////////////////////////////////////////////////////////////////
40
Jason Samsa57c0a72009-09-04 14:42:41 -070041typedef struct {
42 float x;
43 float y;
44 float z;
45} vec3_t;
46
47typedef struct {
48 float x;
49 float y;
50 float z;
51 float w;
52} vec4_t;
53
54typedef struct {
55 float x;
56 float y;
57} vec2_t;
Jason Samse45ac6e2009-07-20 14:31:06 -070058
Romain Guy06f7c932009-08-06 12:40:41 -070059
Jason Samsa57c0a72009-09-04 14:42:41 -070060//////////////////////////////////////////////////////////////////////////////
61// Vec3 routines
62//////////////////////////////////////////////////////////////////////////////
63
64static void SC_vec3Norm(vec3_t *v)
65{
66 float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
67 len = 1 / len;
68 v->x *= len;
69 v->y *= len;
70 v->z *= len;
71}
72
73static float SC_vec3Length(const vec3_t *v)
74{
75 return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
76}
77
78static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
79{
80 dest->x = lhs->x + rhs->x;
81 dest->y = lhs->y + rhs->y;
82 dest->z = lhs->z + rhs->z;
83}
84
85static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
86{
87 dest->x = lhs->x - rhs->x;
88 dest->y = lhs->y - rhs->y;
89 dest->z = lhs->z - rhs->z;
90}
91
92static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
93{
94 float x = lhs->y * rhs->z - lhs->z * rhs->y;
95 float y = lhs->z * rhs->x - lhs->x * rhs->z;
96 float z = lhs->x * rhs->y - lhs->y * rhs->x;
97 dest->x = x;
98 dest->y = y;
99 dest->z = z;
100}
101
102static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
103{
104 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
105}
106
107static void SC_vec3Scale(vec3_t *lhs, float scale)
108{
109 lhs->x *= scale;
110 lhs->y *= scale;
111 lhs->z *= scale;
112}
113
Romain Guyd6d4a5f2009-10-09 16:05:25 -0700114//////////////////////////////////////////////////////////////////////////////
115// Vec4 routines
116//////////////////////////////////////////////////////////////////////////////
117
118static void SC_vec4Norm(vec4_t *v)
119{
120 float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
121 len = 1 / len;
122 v->x *= len;
123 v->y *= len;
124 v->z *= len;
125 v->w *= len;
126}
127
128static float SC_vec4Length(const vec4_t *v)
129{
130 return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
131}
132
133static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
134{
135 dest->x = lhs->x + rhs->x;
136 dest->y = lhs->y + rhs->y;
137 dest->z = lhs->z + rhs->z;
138 dest->w = lhs->w + rhs->w;
139}
140
141static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
142{
143 dest->x = lhs->x - rhs->x;
144 dest->y = lhs->y - rhs->y;
145 dest->z = lhs->z - rhs->z;
146 dest->w = lhs->w - rhs->w;
147}
148
149static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
150{
151 return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
152}
153
154static void SC_vec4Scale(vec4_t *lhs, float scale)
155{
156 lhs->x *= scale;
157 lhs->y *= scale;
158 lhs->z *= scale;
159 lhs->w *= scale;
160}
Jason Samse45ac6e2009-07-20 14:31:06 -0700161
162//////////////////////////////////////////////////////////////////////////////
163// Math routines
164//////////////////////////////////////////////////////////////////////////////
165
Romain Guy2275d632009-08-18 11:39:17 -0700166static float SC_sinf_fast(float x)
167{
168 const float A = 1.0f / (2.0f * M_PI);
169 const float B = -16.0f;
170 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -0700171
Romain Guy2275d632009-08-18 11:39:17 -0700172 // scale angle for easy argument reduction
173 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -0700174
Romain Guy2275d632009-08-18 11:39:17 -0700175 if (fabsf(x) >= 0.5f) {
176 // argument reduction
177 x = x - ceilf(x + 0.5f) + 1.0f;
178 }
Jason Samsa57c0a72009-09-04 14:42:41 -0700179
Romain Guy2275d632009-08-18 11:39:17 -0700180 const float y = B * x * fabsf(x) + C * x;
181 return 0.2215f * (y * fabsf(y) - y) + y;
182}
183
184static float SC_cosf_fast(float x)
185{
186 x += float(M_PI / 2);
187
188 const float A = 1.0f / (2.0f * M_PI);
189 const float B = -16.0f;
190 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -0700191
Romain Guy2275d632009-08-18 11:39:17 -0700192 // scale angle for easy argument reduction
193 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -0700194
Romain Guy2275d632009-08-18 11:39:17 -0700195 if (fabsf(x) >= 0.5f) {
196 // argument reduction
197 x = x - ceilf(x + 0.5f) + 1.0f;
198 }
Jason Samsa57c0a72009-09-04 14:42:41 -0700199
Romain Guy2275d632009-08-18 11:39:17 -0700200 const float y = B * x * fabsf(x) + C * x;
201 return 0.2215f * (y * fabsf(y) - y) + y;
202}
203
Jason Sams22fa3712010-05-19 17:22:57 -0700204
Jason Samse45ac6e2009-07-20 14:31:06 -0700205static float SC_randf(float max)
206{
207 float r = (float)rand();
208 return r / RAND_MAX * max;
209}
210
Romain Guy39dbc802009-07-31 11:20:59 -0700211static float SC_randf2(float min, float max)
212{
213 float r = (float)rand();
214 return r / RAND_MAX * (max - min) + min;
215}
216
Jason Sams22fa3712010-05-19 17:22:57 -0700217static int SC_randi(int max)
218{
219 return (int)SC_randf(max);
220}
221
222static int SC_randi2(int min, int max)
223{
224 return (int)SC_randf2(min, max);
225}
226
Romain Guy27162ab2009-08-09 17:04:54 -0700227static int SC_clamp(int amount, int low, int high)
228{
229 return amount < low ? low : (amount > high ? high : amount);
230}
231
Jason Samsdac98f52009-09-18 14:24:24 -0700232static float SC_roundf(float v)
233{
234 return floorf(v + 0.4999999999);
235}
236
Romain Guy39dbc802009-07-31 11:20:59 -0700237static float SC_distf2(float x1, float y1, float x2, float y2)
238{
239 float x = x2 - x1;
240 float y = y2 - y1;
Jason Samse5ffb872009-08-09 17:01:55 -0700241 return sqrtf(x * x + y * y);
Romain Guy39dbc802009-07-31 11:20:59 -0700242}
243
244static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
245{
246 float x = x2 - x1;
247 float y = y2 - y1;
248 float z = z2 - z1;
Jason Samse5ffb872009-08-09 17:01:55 -0700249 return sqrtf(x * x + y * y + z * z);
Romain Guy39dbc802009-07-31 11:20:59 -0700250}
251
252static float SC_magf2(float a, float b)
253{
254 return sqrtf(a * a + b * b);
255}
256
257static float SC_magf3(float a, float b, float c)
258{
259 return sqrtf(a * a + b * b + c * c);
260}
261
Jason Samsbe36bf32010-05-11 14:03:58 -0700262static float SC_frac(float v)
263{
264 int i = (int)floor(v);
265 return fmin(v - i, 0x1.fffffep-1f);
266}
267
Romain Guy98e10fd2009-07-30 18:45:01 -0700268//////////////////////////////////////////////////////////////////////////////
269// Time routines
270//////////////////////////////////////////////////////////////////////////////
Jason Samse45ac6e2009-07-20 14:31:06 -0700271
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700272static int32_t SC_second()
Romain Guy98e10fd2009-07-30 18:45:01 -0700273{
274 GET_TLS();
275
276 time_t rawtime;
277 time(&rawtime);
278
Romain Guy519cdc92009-11-11 15:36:06 -0800279 struct tm *timeinfo;
280 timeinfo = localtime(&rawtime);
281 return timeinfo->tm_sec;
Romain Guy98e10fd2009-07-30 18:45:01 -0700282}
283
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700284static int32_t SC_minute()
Romain Guy98e10fd2009-07-30 18:45:01 -0700285{
286 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700287
Romain Guy98e10fd2009-07-30 18:45:01 -0700288 time_t rawtime;
289 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700290
Romain Guy519cdc92009-11-11 15:36:06 -0800291 struct tm *timeinfo;
292 timeinfo = localtime(&rawtime);
293 return timeinfo->tm_min;
Jason Samse5ffb872009-08-09 17:01:55 -0700294}
Romain Guy98e10fd2009-07-30 18:45:01 -0700295
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700296static int32_t SC_hour()
Romain Guy98e10fd2009-07-30 18:45:01 -0700297{
298 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700299
Romain Guy98e10fd2009-07-30 18:45:01 -0700300 time_t rawtime;
301 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700302
Romain Guy519cdc92009-11-11 15:36:06 -0800303 struct tm *timeinfo;
304 timeinfo = localtime(&rawtime);
305 return timeinfo->tm_hour;
Romain Guy39dbc802009-07-31 11:20:59 -0700306}
307
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700308static int32_t SC_day()
Romain Guy39dbc802009-07-31 11:20:59 -0700309{
310 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700311
Romain Guy39dbc802009-07-31 11:20:59 -0700312 time_t rawtime;
313 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700314
Romain Guy519cdc92009-11-11 15:36:06 -0800315 struct tm *timeinfo;
316 timeinfo = localtime(&rawtime);
317 return timeinfo->tm_mday;
Jason Samse5ffb872009-08-09 17:01:55 -0700318}
Jason Samse45ac6e2009-07-20 14:31:06 -0700319
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700320static int32_t SC_month()
Romain Guy39dbc802009-07-31 11:20:59 -0700321{
322 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700323
Romain Guy39dbc802009-07-31 11:20:59 -0700324 time_t rawtime;
325 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700326
Romain Guy519cdc92009-11-11 15:36:06 -0800327 struct tm *timeinfo;
328 timeinfo = localtime(&rawtime);
329 return timeinfo->tm_mon;
Jason Samse5ffb872009-08-09 17:01:55 -0700330}
Romain Guy39dbc802009-07-31 11:20:59 -0700331
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700332static int32_t SC_year()
Romain Guy39dbc802009-07-31 11:20:59 -0700333{
334 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700335
Romain Guy39dbc802009-07-31 11:20:59 -0700336 time_t rawtime;
337 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700338
Romain Guy519cdc92009-11-11 15:36:06 -0800339 struct tm *timeinfo;
340 timeinfo = localtime(&rawtime);
341 return timeinfo->tm_year;
Romain Guy39dbc802009-07-31 11:20:59 -0700342}
343
Jason Sams22fa3712010-05-19 17:22:57 -0700344static int64_t SC_uptimeMillis2()
345{
346 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
347}
348
349static int64_t SC_startTimeMillis2()
350{
351 GET_TLS();
352 return sc->mEnviroment.mStartTimeMillis;
353}
354
355static int64_t SC_elapsedTimeMillis2()
356{
357 GET_TLS();
358 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
359 - sc->mEnviroment.mStartTimeMillis;
360}
361
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700362static int32_t SC_uptimeMillis()
363{
364 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
365}
366
367static int32_t SC_startTimeMillis()
368{
369 GET_TLS();
370 return sc->mEnviroment.mStartTimeMillis;
371}
372
373static int32_t SC_elapsedTimeMillis()
374{
375 GET_TLS();
376 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
377 - sc->mEnviroment.mStartTimeMillis;
378}
379
Jason Samse45ac6e2009-07-20 14:31:06 -0700380//////////////////////////////////////////////////////////////////////////////
381// Matrix routines
382//////////////////////////////////////////////////////////////////////////////
383
384
385static void SC_matrixLoadIdentity(rsc_Matrix *mat)
386{
387 Matrix *m = reinterpret_cast<Matrix *>(mat);
388 m->loadIdentity();
389}
390
391static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
392{
393 Matrix *m = reinterpret_cast<Matrix *>(mat);
394 m->load(f);
395}
396
397static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
398{
399 Matrix *m = reinterpret_cast<Matrix *>(mat);
400 m->load(reinterpret_cast<const Matrix *>(newmat));
401}
402
403static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
404{
405 Matrix *m = reinterpret_cast<Matrix *>(mat);
406 m->loadRotate(rot, x, y, z);
407}
408
409static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
410{
411 Matrix *m = reinterpret_cast<Matrix *>(mat);
412 m->loadScale(x, y, z);
413}
414
415static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
416{
417 Matrix *m = reinterpret_cast<Matrix *>(mat);
418 m->loadTranslate(x, y, z);
419}
420
421static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
422{
423 Matrix *m = reinterpret_cast<Matrix *>(mat);
424 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
425 reinterpret_cast<const Matrix *>(rhs));
426}
427
428static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
429{
430 Matrix *m = reinterpret_cast<Matrix *>(mat);
431 m->multiply(reinterpret_cast<const Matrix *>(rhs));
432}
433
434static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
435{
436 Matrix *m = reinterpret_cast<Matrix *>(mat);
437 m->rotate(rot, x, y, z);
438}
439
440static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
441{
442 Matrix *m = reinterpret_cast<Matrix *>(mat);
443 m->scale(x, y, z);
444}
445
446static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
447{
448 Matrix *m = reinterpret_cast<Matrix *>(mat);
449 m->translate(x, y, z);
450}
451
452
Jason Samse45ac6e2009-07-20 14:31:06 -0700453//////////////////////////////////////////////////////////////////////////////
454//
455//////////////////////////////////////////////////////////////////////////////
456
Jason Samsbe36bf32010-05-11 14:03:58 -0700457static uint32_t SC_allocGetDimX(RsAllocation va)
458{
459 GET_TLS();
460 const Allocation *a = static_cast<const Allocation *>(va);
461 //LOGE("SC_allocGetDimX a=%p", a);
462 //LOGE(" type=%p", a->getType());
463 return a->getType()->getDimX();
464}
465
466static uint32_t SC_allocGetDimY(RsAllocation va)
467{
468 GET_TLS();
469 const Allocation *a = static_cast<const Allocation *>(va);
470 return a->getType()->getDimY();
471}
472
473static uint32_t SC_allocGetDimZ(RsAllocation va)
474{
475 GET_TLS();
476 const Allocation *a = static_cast<const Allocation *>(va);
477 return a->getType()->getDimZ();
478}
479
480static uint32_t SC_allocGetDimLOD(RsAllocation va)
481{
482 GET_TLS();
483 const Allocation *a = static_cast<const Allocation *>(va);
484 return a->getType()->getDimLOD();
485}
486
487static uint32_t SC_allocGetDimFaces(RsAllocation va)
488{
489 GET_TLS();
490 const Allocation *a = static_cast<const Allocation *>(va);
491 return a->getType()->getDimFaces();
492}
493
494
Jason Samse45ac6e2009-07-20 14:31:06 -0700495
Jason Sams22fa3712010-05-19 17:22:57 -0700496static void SC_debugF(const char *s, float f) {
497 LOGE("%s %f, 0x%08x", s, f, *((int *) (&f)));
Jason Samsc9d43db2009-07-28 12:02:16 -0700498}
Jason Sams22fa3712010-05-19 17:22:57 -0700499static void SC_debugFv2(const char *s, rsvF_2 fv) {
500 float *f = (float *)&fv;
501 LOGE("%s {%f, %f}", s, f[0], f[1]);
Romain Guy370ed152009-08-20 17:08:33 -0700502}
Jason Sams22fa3712010-05-19 17:22:57 -0700503static void SC_debugFv3(const char *s, rsvF_4 fv) {
504 float *f = (float *)&fv;
505 LOGE("%s {%f, %f, %f}", s, f[0], f[1], f[2]);
Jason Samsc9d43db2009-07-28 12:02:16 -0700506}
Jason Sams22fa3712010-05-19 17:22:57 -0700507static void SC_debugFv4(const char *s, rsvF_4 fv) {
508 float *f = (float *)&fv;
509 LOGE("%s {%f, %f, %f, %f}", s, f[0], f[1], f[2], f[3]);
510}
511static void SC_debugI32(const char *s, int32_t i) {
512 LOGE("%s %i 0x%x", s, i, i);
Romain Guy370ed152009-08-20 17:08:33 -0700513}
514
Jason Samsbe36bf32010-05-11 14:03:58 -0700515static uchar4 SC_convertColorTo8888_f3(float r, float g, float b) {
516 uchar4 t;
517 t.f[0] = (uint8_t)(r * 255.f);
518 t.f[1] = (uint8_t)(g * 255.f);
519 t.f[2] = (uint8_t)(b * 255.f);
520 t.f[3] = 0xff;
521 return t;
Jason Sams90b36a82009-08-17 13:56:09 -0700522}
523
Jason Samsbe36bf32010-05-11 14:03:58 -0700524static uchar4 SC_convertColorTo8888_f4(float r, float g, float b, float a) {
525 uchar4 t;
526 t.f[0] = (uint8_t)(r * 255.f);
527 t.f[1] = (uint8_t)(g * 255.f);
528 t.f[2] = (uint8_t)(b * 255.f);
529 t.f[3] = (uint8_t)(a * 255.f);
530 return t;
Jason Sams90b36a82009-08-17 13:56:09 -0700531}
532
Jason Sams8c401ef2009-10-06 13:58:47 -0700533static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
534{
535 GET_TLS();
Jason Samsbe36bf32010-05-11 14:03:58 -0700536 //LOGE("SC_toClient %i %i %i", cmdID, len, waitForSpace);
Jason Sams8c401ef2009-10-06 13:58:47 -0700537 return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
538}
539
Jason Sams3a27c952009-10-07 18:14:01 -0700540static void SC_scriptCall(int scriptID)
541{
542 GET_TLS();
Jason Samsc61346b2010-05-28 18:23:22 -0700543 rsc->runScript((Script *)scriptID);
Jason Sams3a27c952009-10-07 18:14:01 -0700544}
545
Jason Samsbe36bf32010-05-11 14:03:58 -0700546int SC_divsi3(int a, int b)
547{
548 return a / b;
549}
Jason Sams3a27c952009-10-07 18:14:01 -0700550
Jason Samsce92d4b2010-05-17 14:55:34 -0700551int SC_getAllocation(const void *ptr)
552{
553 GET_TLS();
554 const Allocation *alloc = sc->ptrToAllocation(ptr);
555 return (int)alloc;
556}
557
558
Jason Samsc61346b2010-05-28 18:23:22 -0700559void SC_ForEachii(RsScript vs, RsAllocation vin)
560{
561 GET_TLS();
562 Script *s = static_cast<Script *>(vs);
563 Allocation *ain = static_cast<Allocation *>(vin);
564 s->runForEach(rsc, ain, NULL);
565}
566
567void SC_ForEachiii(RsScript vs, RsAllocation vin, RsAllocation vout)
568{
569 GET_TLS();
570 Script *s = static_cast<Script *>(vs);
571 Allocation *ain = static_cast<Allocation *>(vin);
572 Allocation *aout = static_cast<Allocation *>(vout);
573 s->runForEach(rsc, ain, aout);
574}
575
576void SC_ForEachiiii(RsScript vs, RsAllocation vin, int xStart, int xEnd)
577{
578 GET_TLS();
579 Script *s = static_cast<Script *>(vs);
580 Allocation *ain = static_cast<Allocation *>(vin);
581 s->runForEach(rsc, ain, NULL, xStart, xEnd);
582}
583
584void SC_ForEachiiiii(RsScript vs, RsAllocation vin, RsAllocation vout, int xStart, int xEnd)
585{
586 GET_TLS();
587 Script *s = static_cast<Script *>(vs);
588 Allocation *ain = static_cast<Allocation *>(vin);
589 Allocation *aout = static_cast<Allocation *>(vout);
590 s->runForEach(rsc, ain, aout, xStart, xEnd);
591}
592
593void SC_ForEachiiiiii(RsScript vs, RsAllocation vin, int xStart, int yStart, int xEnd, int yEnd)
594{
595 GET_TLS();
596 Script *s = static_cast<Script *>(vs);
597 Allocation *ain = static_cast<Allocation *>(vin);
598 s->runForEach(rsc, ain, NULL, xStart, yStart, xEnd, yEnd);
599}
600
601void SC_ForEachiiiiiii(RsScript vs, RsAllocation vin, RsAllocation vout, int xStart, int yStart, int xEnd, int yEnd)
602{
603 GET_TLS();
604 Script *s = static_cast<Script *>(vs);
605 Allocation *ain = static_cast<Allocation *>(vin);
606 Allocation *aout = static_cast<Allocation *>(vout);
607 s->runForEach(rsc, ain, aout, xStart, yStart, xEnd, yEnd);
608}
609
610
Jason Samse45ac6e2009-07-20 14:31:06 -0700611//////////////////////////////////////////////////////////////////////////////
612// Class implementation
613//////////////////////////////////////////////////////////////////////////////
614
Jason Samsbe36bf32010-05-11 14:03:58 -0700615// llvm name mangling ref
616// <builtin-type> ::= v # void
617// ::= b # bool
618// ::= c # char
619// ::= a # signed char
620// ::= h # unsigned char
621// ::= s # short
622// ::= t # unsigned short
623// ::= i # int
624// ::= j # unsigned int
625// ::= l # long
626// ::= m # unsigned long
627// ::= x # long long, __int64
628// ::= y # unsigned long long, __int64
629// ::= f # float
630// ::= d # double
Jason Samse45ac6e2009-07-20 14:31:06 -0700631
Jason Samsaeb094b2010-05-18 13:35:45 -0700632static ScriptCState::SymbolTable_t gSyms[] = {
Jason Samsbe36bf32010-05-11 14:03:58 -0700633 { "__divsi3", (void *)&SC_divsi3 },
634
Jason Sams22fa3712010-05-19 17:22:57 -0700635 // allocation
636 { "rsAllocationGetDimX", (void *)&SC_allocGetDimX },
637 { "rsAllocationGetDimY", (void *)&SC_allocGetDimY },
638 { "rsAllocationGetDimZ", (void *)&SC_allocGetDimZ },
639 { "rsAllocationGetDimLOD", (void *)&SC_allocGetDimLOD },
640 { "rsAllocationGetDimFaces", (void *)&SC_allocGetDimFaces },
641 { "rsGetAllocation", (void *)&SC_getAllocation },
642
643 // color
644 { "_Z17rsPackColorTo8888fff", (void *)&SC_convertColorTo8888_f3 },
645 { "_Z17rsPackColorTo8888ffff", (void *)&SC_convertColorTo8888_f4 },
646 //extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3);
647 //extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4);
648 //extern float4 rsUnpackColor8888(uchar4);
649 //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b);
650 //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3);
651 //extern float4 rsUnpackColor565(uchar4);
652
653 // Debug
654 { "_Z7rsDebugPKcf", (void *)&SC_debugF },
655 { "_Z7rsDebugPKcDv2_f", (void *)&SC_debugFv2 },
656 { "_Z7rsDebugPKcDv3_f", (void *)&SC_debugFv3 },
657 { "_Z7rsDebugPKcDv4_f", (void *)&SC_debugFv4 },
658 { "_Z7rsDebugPKci", (void *)&SC_debugI32 },
659 //extern void __attribute__((overloadable))rsDebug(const char *, const void *);
660
661
662 // RS Math
663 { "_Z6rsRandi", (void *)&SC_randi },
664 { "_Z6rsRandii", (void *)&SC_randi2 },
665 { "_Z6rsRandf", (void *)&SC_randf },
666 { "_Z6rsRandff", (void *)&SC_randf2 },
667 { "_Z6rsFracf", (void *)&SC_frac },
668
669 // time
670 { "rsSecond", (void *)&SC_second },
671 { "rsMinute", (void *)&SC_minute },
672 { "rsHour", (void *)&SC_hour },
673 { "rsDay", (void *)&SC_day },
674 { "rsMonth", (void *)&SC_month },
675 { "rsYear", (void *)&SC_year },
676 { "rsUptimeMillis", (void*)&SC_uptimeMillis2 },
677 { "rsStartTimeMillis", (void*)&SC_startTimeMillis2 },
678 { "rsElapsedTimeMillis", (void*)&SC_elapsedTimeMillis2 },
679
680 { "rsSendToClient", (void *)&SC_toClient },
681
682 // matrix
683 { "rsMatrixLoadIdentity", (void *)&SC_matrixLoadIdentity },
684 { "rsMatrixLoadFloat", (void *)&SC_matrixLoadFloat },
685 { "rsMatrixLoadMat", (void *)&SC_matrixLoadMat },
686 { "rsMatrixLoadRotate", (void *)&SC_matrixLoadRotate },
687 { "rsMatrixLoadScale", (void *)&SC_matrixLoadScale },
688 { "rsMatrixLoadTranslate", (void *)&SC_matrixLoadTranslate },
689 { "rsMatrixLoadMultiply", (void *)&SC_matrixLoadMultiply },
690 { "rsMatrixMultiply", (void *)&SC_matrixMultiply },
691 { "rsMatrixRotate", (void *)&SC_matrixRotate },
692 { "rsMatrixScale", (void *)&SC_matrixScale },
693 { "rsMatrixTranslate", (void *)&SC_matrixTranslate },
694
Jason Samsc61346b2010-05-28 18:23:22 -0700695 { "_Z9rsForEachii", (void *)&SC_ForEachii },
696 { "_Z9rsForEachiii", (void *)&SC_ForEachiii },
697 { "_Z9rsForEachiiii", (void *)&SC_ForEachiiii },
698 { "_Z9rsForEachiiiii", (void *)&SC_ForEachiiiii },
699 { "_Z9rsForEachiiiiii", (void *)&SC_ForEachiiiiii },
700 { "_Z9rsForEachiiiiiii", (void *)&SC_ForEachiiiiiii },
Jason Sams22fa3712010-05-19 17:22:57 -0700701
702////////////////////////////////////////////////////////////////////
703
Jason Samsbe36bf32010-05-11 14:03:58 -0700704 //{ "sinf_fast", (void *)&SC_sinf_fast },
705 //{ "cosf_fast", (void *)&SC_cosf_fast },
Jason Sams22fa3712010-05-19 17:22:57 -0700706 //{ "clamp", (void *)&SC_clamp },
707 //{ "distf2", (void *)&SC_distf2 },
708 //{ "distf3", (void *)&SC_distf3 },
709 //{ "magf2", (void *)&SC_magf2 },
710 //{ "magf3", (void *)&SC_magf3 },
711 //{ "mapf", (void *)&SC_mapf },
Jason Samse45ac6e2009-07-20 14:31:06 -0700712
Jason Samsbe36bf32010-05-11 14:03:58 -0700713 { "scriptCall", (void *)&SC_scriptCall },
Jason Samsce92d4b2010-05-17 14:55:34 -0700714
Jason Samsc9d43db2009-07-28 12:02:16 -0700715
Jason Samsbe36bf32010-05-11 14:03:58 -0700716 { NULL, NULL }
Jason Samse45ac6e2009-07-20 14:31:06 -0700717};
718
719const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
720{
721 ScriptCState::SymbolTable_t *syms = gSyms;
722
723 while (syms->mPtr) {
724 if (!strcmp(syms->mName, sym)) {
725 return syms;
726 }
727 syms++;
728 }
729 return NULL;
730}
731