rsdRuntimeStubs.cpp revision 57dc11a5eb5a92d2bc7070ad3392b12047dd9adc
1/*
2 * Copyright (C) 2011 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 "rsMatrix4x4.h"
20#include "rsMatrix3x3.h"
21#include "rsMatrix2x2.h"
22#include "rsRuntime.h"
23
24#include "utils/Timers.h"
25#include "rsdCore.h"
26#include "rsdBcc.h"
27
28#include "rsdRuntime.h"
29#include "rsdPath.h"
30#include "rsdAllocation.h"
31
32#include <time.h>
33
34using namespace android;
35using namespace android::renderscript;
36
37#define GET_TLS()  ScriptTLSStruct * tls = \
38    (ScriptTLSStruct *)pthread_getspecific(rsdgThreadTLSKey); \
39    Context * rsc = tls->mContext; \
40    ScriptC * sc = (ScriptC *) tls->mScript
41
42
43
44//////////////////////////////////////////////////////////////////////////////
45// Allocation
46//////////////////////////////////////////////////////////////////////////////
47
48
49static void SC_AllocationSyncAll2(Allocation *a, RsAllocationUsageType source) {
50    GET_TLS();
51    rsrAllocationSyncAll(rsc, sc, a, source);
52}
53
54static void SC_AllocationSyncAll(Allocation *a) {
55    GET_TLS();
56    rsrAllocationSyncAll(rsc, sc, a, RS_ALLOCATION_USAGE_SCRIPT);
57}
58
59static void SC_AllocationCopy1DRange(Allocation *dstAlloc,
60                                     uint32_t dstOff,
61                                     uint32_t dstMip,
62                                     uint32_t count,
63                                     Allocation *srcAlloc,
64                                     uint32_t srcOff, uint32_t srcMip) {
65    GET_TLS();
66    rsrAllocationCopy1DRange(rsc, dstAlloc, dstOff, dstMip, count,
67                             srcAlloc, srcOff, srcMip);
68}
69
70static void SC_AllocationCopy2DRange(Allocation *dstAlloc,
71                                     uint32_t dstXoff, uint32_t dstYoff,
72                                     uint32_t dstMip, uint32_t dstFace,
73                                     uint32_t width, uint32_t height,
74                                     Allocation *srcAlloc,
75                                     uint32_t srcXoff, uint32_t srcYoff,
76                                     uint32_t srcMip, uint32_t srcFace) {
77    GET_TLS();
78    rsrAllocationCopy2DRange(rsc, dstAlloc,
79                             dstXoff, dstYoff, dstMip, dstFace,
80                             width, height,
81                             srcAlloc,
82                             srcXoff, srcYoff, srcMip, srcFace);
83}
84
85static void SC_AllocationIoSend(Allocation *alloc) {
86    GET_TLS();
87    rsdAllocationIoSend(rsc, alloc);
88}
89
90
91static void SC_AllocationIoReceive(Allocation *alloc) {
92    GET_TLS();
93    rsdAllocationIoReceive(rsc, alloc);
94}
95
96
97
98//////////////////////////////////////////////////////////////////////////////
99// Context
100//////////////////////////////////////////////////////////////////////////////
101
102static void SC_BindTexture(ProgramFragment *pf, uint32_t slot, Allocation *a) {
103    GET_TLS();
104    rsrBindTexture(rsc, sc, pf, slot, a);
105}
106
107static void SC_BindVertexConstant(ProgramVertex *pv, uint32_t slot, Allocation *a) {
108    GET_TLS();
109    rsrBindConstant(rsc, sc, pv, slot, a);
110}
111
112static void SC_BindFragmentConstant(ProgramFragment *pf, uint32_t slot, Allocation *a) {
113    GET_TLS();
114    rsrBindConstant(rsc, sc, pf, slot, a);
115}
116
117static void SC_BindSampler(ProgramFragment *pf, uint32_t slot, Sampler *s) {
118    GET_TLS();
119    rsrBindSampler(rsc, sc, pf, slot, s);
120}
121
122static void SC_BindProgramStore(ProgramStore *ps) {
123    GET_TLS();
124    rsrBindProgramStore(rsc, sc, ps);
125}
126
127static void SC_BindProgramFragment(ProgramFragment *pf) {
128    GET_TLS();
129    rsrBindProgramFragment(rsc, sc, pf);
130}
131
132static void SC_BindProgramVertex(ProgramVertex *pv) {
133    GET_TLS();
134    rsrBindProgramVertex(rsc, sc, pv);
135}
136
137static void SC_BindProgramRaster(ProgramRaster *pr) {
138    GET_TLS();
139    rsrBindProgramRaster(rsc, sc, pr);
140}
141
142static void SC_BindFrameBufferObjectColorTarget(Allocation *a, uint32_t slot) {
143    GET_TLS();
144    rsrBindFrameBufferObjectColorTarget(rsc, sc, a, slot);
145}
146
147static void SC_BindFrameBufferObjectDepthTarget(Allocation *a) {
148    GET_TLS();
149    rsrBindFrameBufferObjectDepthTarget(rsc, sc, a);
150}
151
152static void SC_ClearFrameBufferObjectColorTarget(uint32_t slot) {
153    GET_TLS();
154    rsrClearFrameBufferObjectColorTarget(rsc, sc, slot);
155}
156
157static void SC_ClearFrameBufferObjectDepthTarget(Context *, Script *) {
158    GET_TLS();
159    rsrClearFrameBufferObjectDepthTarget(rsc, sc);
160}
161
162static void SC_ClearFrameBufferObjectTargets(Context *, Script *) {
163    GET_TLS();
164    rsrClearFrameBufferObjectTargets(rsc, sc);
165}
166
167
168//////////////////////////////////////////////////////////////////////////////
169// VP
170//////////////////////////////////////////////////////////////////////////////
171
172static void SC_VpLoadProjectionMatrix(const rsc_Matrix *m) {
173    GET_TLS();
174    rsrVpLoadProjectionMatrix(rsc, sc, m);
175}
176
177static void SC_VpLoadModelMatrix(const rsc_Matrix *m) {
178    GET_TLS();
179    rsrVpLoadModelMatrix(rsc, sc, m);
180}
181
182static void SC_VpLoadTextureMatrix(const rsc_Matrix *m) {
183    GET_TLS();
184    rsrVpLoadTextureMatrix(rsc, sc, m);
185}
186
187static void SC_PfConstantColor(ProgramFragment *pf, float r, float g, float b, float a) {
188    GET_TLS();
189    rsrPfConstantColor(rsc, sc, pf, r, g, b, a);
190}
191
192static void SC_VpGetProjectionMatrix(rsc_Matrix *m) {
193    GET_TLS();
194    rsrVpGetProjectionMatrix(rsc, sc, m);
195}
196
197
198//////////////////////////////////////////////////////////////////////////////
199// Drawing
200//////////////////////////////////////////////////////////////////////////////
201
202static void SC_DrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
203                                 float x2, float y2, float z2, float u2, float v2,
204                                 float x3, float y3, float z3, float u3, float v3,
205                                 float x4, float y4, float z4, float u4, float v4) {
206    GET_TLS();
207    rsrDrawQuadTexCoords(rsc, sc,
208                         x1, y1, z1, u1, v1,
209                         x2, y2, z2, u2, v2,
210                         x3, y3, z3, u3, v3,
211                         x4, y4, z4, u4, v4);
212}
213
214static void SC_DrawQuad(float x1, float y1, float z1,
215                        float x2, float y2, float z2,
216                        float x3, float y3, float z3,
217                        float x4, float y4, float z4) {
218    GET_TLS();
219    rsrDrawQuad(rsc, sc, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4);
220}
221
222static void SC_DrawSpriteScreenspace(float x, float y, float z, float w, float h) {
223    GET_TLS();
224    rsrDrawSpriteScreenspace(rsc, sc, x, y, z, w, h);
225}
226
227static void SC_DrawRect(float x1, float y1, float x2, float y2, float z) {
228    GET_TLS();
229    rsrDrawRect(rsc, sc, x1, y1, x2, y2, z);
230}
231
232static void SC_DrawPath(Path *p) {
233    GET_TLS();
234    //rsrDrawPath(rsc, sc, p);
235    rsdPathDraw(rsc, p);
236}
237
238static void SC_DrawMesh(Mesh *m) {
239    GET_TLS();
240    rsrDrawMesh(rsc, sc, m);
241}
242
243static void SC_DrawMeshPrimitive(Mesh *m, uint32_t primIndex) {
244    GET_TLS();
245    rsrDrawMeshPrimitive(rsc, sc, m, primIndex);
246}
247
248static void SC_DrawMeshPrimitiveRange(Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len) {
249    GET_TLS();
250    rsrDrawMeshPrimitiveRange(rsc, sc, m, primIndex, start, len);
251}
252
253static void SC_MeshComputeBoundingBox(Mesh *m,
254                               float *minX, float *minY, float *minZ,
255                               float *maxX, float *maxY, float *maxZ) {
256    GET_TLS();
257    rsrMeshComputeBoundingBox(rsc, sc, m, minX, minY, minZ, maxX, maxY, maxZ);
258}
259
260
261
262//////////////////////////////////////////////////////////////////////////////
263//
264//////////////////////////////////////////////////////////////////////////////
265
266
267static void SC_Color(float r, float g, float b, float a) {
268    GET_TLS();
269    rsrColor(rsc, sc, r, g, b, a);
270}
271
272static void SC_Finish() {
273    GET_TLS();
274    rsdGLFinish(rsc);
275}
276
277static void SC_ClearColor(float r, float g, float b, float a) {
278    GET_TLS();
279    rsrPrepareClear(rsc, sc);
280    rsdGLClearColor(rsc, r, g, b, a);
281}
282
283static void SC_ClearDepth(float v) {
284    GET_TLS();
285    rsrPrepareClear(rsc, sc);
286    rsdGLClearDepth(rsc, v);
287}
288
289static uint32_t SC_GetWidth() {
290    GET_TLS();
291    return rsrGetWidth(rsc, sc);
292}
293
294static uint32_t SC_GetHeight() {
295    GET_TLS();
296    return rsrGetHeight(rsc, sc);
297}
298
299static void SC_DrawTextAlloc(Allocation *a, int x, int y) {
300    GET_TLS();
301    rsrDrawTextAlloc(rsc, sc, a, x, y);
302}
303
304static void SC_DrawText(const char *text, int x, int y) {
305    GET_TLS();
306    rsrDrawText(rsc, sc, text, x, y);
307}
308
309static void SC_MeasureTextAlloc(Allocation *a,
310                         int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) {
311    GET_TLS();
312    rsrMeasureTextAlloc(rsc, sc, a, left, right, top, bottom);
313}
314
315static void SC_MeasureText(const char *text,
316                    int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) {
317    GET_TLS();
318    rsrMeasureText(rsc, sc, text, left, right, top, bottom);
319}
320
321static void SC_BindFont(Font *f) {
322    GET_TLS();
323    rsrBindFont(rsc, sc, f);
324}
325
326static void SC_FontColor(float r, float g, float b, float a) {
327    GET_TLS();
328    rsrFontColor(rsc, sc, r, g, b, a);
329}
330
331
332
333//////////////////////////////////////////////////////////////////////////////
334//
335//////////////////////////////////////////////////////////////////////////////
336
337static void SC_SetObject(ObjectBase **dst, ObjectBase * src) {
338    GET_TLS();
339    rsrSetObject(rsc, sc, dst, src);
340}
341
342static void SC_ClearObject(ObjectBase **dst) {
343    GET_TLS();
344    rsrClearObject(rsc, sc, dst);
345}
346
347static bool SC_IsObject(const ObjectBase *src) {
348    GET_TLS();
349    return rsrIsObject(rsc, sc, src);
350}
351
352
353
354
355static const Allocation * SC_GetAllocation(const void *ptr) {
356    GET_TLS();
357    return rsdScriptGetAllocationForPointer(rsc, sc, ptr);
358}
359
360static void SC_ForEach_SAA(Script *target,
361                            Allocation *in,
362                            Allocation *out) {
363    GET_TLS();
364    rsrForEach(rsc, sc, target, in, out, NULL, 0, NULL);
365}
366
367static void SC_ForEach_SAAU(Script *target,
368                            Allocation *in,
369                            Allocation *out,
370                            const void *usr) {
371    GET_TLS();
372    rsrForEach(rsc, sc, target, in, out, usr, 0, NULL);
373}
374
375static void SC_ForEach_SAAUS(Script *target,
376                             Allocation *in,
377                             Allocation *out,
378                             const void *usr,
379                             const RsScriptCall *call) {
380    GET_TLS();
381    rsrForEach(rsc, sc, target, in, out, usr, 0, call);
382}
383
384static void SC_ForEach_SAAUL(Script *target,
385                             Allocation *in,
386                             Allocation *out,
387                             const void *usr,
388                             uint32_t usrLen) {
389    GET_TLS();
390    rsrForEach(rsc, sc, target, in, out, usr, usrLen, NULL);
391}
392
393static void SC_ForEach_SAAULS(Script *target,
394                              Allocation *in,
395                              Allocation *out,
396                              const void *usr,
397                              uint32_t usrLen,
398                              const RsScriptCall *call) {
399    GET_TLS();
400    rsrForEach(rsc, sc, target, in, out, usr, usrLen, call);
401}
402
403
404
405//////////////////////////////////////////////////////////////////////////////
406// Time routines
407//////////////////////////////////////////////////////////////////////////////
408
409static float SC_GetDt() {
410    GET_TLS();
411    return rsrGetDt(rsc, sc);
412}
413
414time_t SC_Time(time_t *timer) {
415    GET_TLS();
416    return rsrTime(rsc, sc, timer);
417}
418
419tm* SC_LocalTime(tm *local, time_t *timer) {
420    GET_TLS();
421    return rsrLocalTime(rsc, sc, local, timer);
422}
423
424int64_t SC_UptimeMillis() {
425    GET_TLS();
426    return rsrUptimeMillis(rsc, sc);
427}
428
429int64_t SC_UptimeNanos() {
430    GET_TLS();
431    return rsrUptimeNanos(rsc, sc);
432}
433
434//////////////////////////////////////////////////////////////////////////////
435// Message routines
436//////////////////////////////////////////////////////////////////////////////
437
438static uint32_t SC_ToClient2(int cmdID, void *data, int len) {
439    GET_TLS();
440    return rsrToClient(rsc, sc, cmdID, data, len);
441}
442
443static uint32_t SC_ToClient(int cmdID) {
444    GET_TLS();
445    return rsrToClient(rsc, sc, cmdID, NULL, 0);
446}
447
448static uint32_t SC_ToClientBlocking2(int cmdID, void *data, int len) {
449    GET_TLS();
450    return rsrToClientBlocking(rsc, sc, cmdID, data, len);
451}
452
453static uint32_t SC_ToClientBlocking(int cmdID) {
454    GET_TLS();
455    return rsrToClientBlocking(rsc, sc, cmdID, NULL, 0);
456}
457
458int SC_divsi3(int a, int b) {
459    return a / b;
460}
461
462int SC_modsi3(int a, int b) {
463    return a % b;
464}
465
466unsigned int SC_udivsi3(unsigned int a, unsigned int b) {
467    return a / b;
468}
469
470unsigned int SC_umodsi3(unsigned int a, unsigned int b) {
471    return a % b;
472}
473
474static void SC_debugF(const char *s, float f) {
475    ALOGD("%s %f, 0x%08x", s, f, *((int *) (&f)));
476}
477static void SC_debugFv2(const char *s, float f1, float f2) {
478    ALOGD("%s {%f, %f}", s, f1, f2);
479}
480static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
481    ALOGD("%s {%f, %f, %f}", s, f1, f2, f3);
482}
483static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
484    ALOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
485}
486static void SC_debugD(const char *s, double d) {
487    ALOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
488}
489static void SC_debugFM4v4(const char *s, const float *f) {
490    ALOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
491    ALOGD("%s  %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
492    ALOGD("%s  %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
493    ALOGD("%s  %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
494}
495static void SC_debugFM3v3(const char *s, const float *f) {
496    ALOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]);
497    ALOGD("%s  %f, %f, %f", s, f[1], f[4], f[7]);
498    ALOGD("%s  %f, %f, %f}",s, f[2], f[5], f[8]);
499}
500static void SC_debugFM2v2(const char *s, const float *f) {
501    ALOGD("%s {%f, %f", s, f[0], f[2]);
502    ALOGD("%s  %f, %f}",s, f[1], f[3]);
503}
504
505static void SC_debugI32(const char *s, int32_t i) {
506    ALOGD("%s %i  0x%x", s, i, i);
507}
508static void SC_debugU32(const char *s, uint32_t i) {
509    ALOGD("%s %u  0x%x", s, i, i);
510}
511static void SC_debugLL64(const char *s, long long ll) {
512    ALOGD("%s %lld  0x%llx", s, ll, ll);
513}
514static void SC_debugULL64(const char *s, unsigned long long ll) {
515    ALOGD("%s %llu  0x%llx", s, ll, ll);
516}
517
518static void SC_debugP(const char *s, const void *p) {
519    ALOGD("%s %p", s, p);
520}
521
522
523//////////////////////////////////////////////////////////////////////////////
524// Stub implementation
525//////////////////////////////////////////////////////////////////////////////
526
527// llvm name mangling ref
528//  <builtin-type> ::= v  # void
529//                 ::= b  # bool
530//                 ::= c  # char
531//                 ::= a  # signed char
532//                 ::= h  # unsigned char
533//                 ::= s  # short
534//                 ::= t  # unsigned short
535//                 ::= i  # int
536//                 ::= j  # unsigned int
537//                 ::= l  # long
538//                 ::= m  # unsigned long
539//                 ::= x  # long long, __int64
540//                 ::= y  # unsigned long long, __int64
541//                 ::= f  # float
542//                 ::= d  # double
543
544static RsdSymbolTable gSyms[] = {
545    { "memset", (void *)&memset, true },
546    { "memcpy", (void *)&memcpy, true },
547
548    // Refcounting
549    { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_SetObject, true },
550    { "_Z13rsClearObjectP10rs_element", (void *)&SC_ClearObject, true },
551    { "_Z10rsIsObject10rs_element", (void *)&SC_IsObject, true },
552
553    { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_SetObject, true },
554    { "_Z13rsClearObjectP7rs_type", (void *)&SC_ClearObject, true },
555    { "_Z10rsIsObject7rs_type", (void *)&SC_IsObject, true },
556
557    { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_SetObject, true },
558    { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_ClearObject, true },
559    { "_Z10rsIsObject13rs_allocation", (void *)&SC_IsObject, true },
560
561    { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_SetObject, true },
562    { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_ClearObject, true },
563    { "_Z10rsIsObject10rs_sampler", (void *)&SC_IsObject, true },
564
565    { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_SetObject, true },
566    { "_Z13rsClearObjectP9rs_script", (void *)&SC_ClearObject, true },
567    { "_Z10rsIsObject9rs_script", (void *)&SC_IsObject, true },
568
569    { "_Z11rsSetObjectP7rs_pathS_", (void *)&SC_SetObject, true },
570    { "_Z13rsClearObjectP7rs_path", (void *)&SC_ClearObject, true },
571    { "_Z10rsIsObject7rs_path", (void *)&SC_IsObject, true },
572
573    { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_SetObject, true },
574    { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_ClearObject, true },
575    { "_Z10rsIsObject7rs_mesh", (void *)&SC_IsObject, true },
576
577    { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_SetObject, true },
578    { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_ClearObject, true },
579    { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_IsObject, true },
580
581    { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_SetObject, true },
582    { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_ClearObject, true },
583    { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_IsObject, true },
584
585    { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_SetObject, true },
586    { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_ClearObject, true },
587    { "_Z10rsIsObject17rs_program_raster", (void *)&SC_IsObject, true },
588
589    { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_SetObject, true },
590    { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_ClearObject, true },
591    { "_Z10rsIsObject16rs_program_store", (void *)&SC_IsObject, true },
592
593    { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_SetObject, true },
594    { "_Z13rsClearObjectP7rs_font", (void *)&SC_ClearObject, true },
595    { "_Z10rsIsObject7rs_font", (void *)&SC_IsObject, true },
596
597    // Allocation ops
598    { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true },
599    { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false },
600    { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false },
601    { "_Z20rsgAllocationSyncAll13rs_allocation24rs_allocation_usage_type", (void *)&SC_AllocationSyncAll2, false },
602    { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true },
603    { "_Z18rsAllocationIoSend13rs_allocation", (void *)&SC_AllocationIoSend, false },
604    { "_Z21rsAllocationIoReceive13rs_allocation", (void *)&SC_AllocationIoReceive, false },
605    { "_Z23rsAllocationCopy1DRange13rs_allocationjjjS_jj", (void *)&SC_AllocationCopy1DRange, false },
606    { "_Z23rsAllocationCopy2DRange13rs_allocationjjj26rs_allocation_cubemap_facejjS_jjjS0_", (void *)&SC_AllocationCopy2DRange, false },
607
608    // Messaging
609
610    { "_Z14rsSendToClienti", (void *)&SC_ToClient, false },
611    { "_Z14rsSendToClientiPKvj", (void *)&SC_ToClient2, false },
612    { "_Z22rsSendToClientBlockingi", (void *)&SC_ToClientBlocking, false },
613    { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_ToClientBlocking2, false },
614
615    { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_BindProgramFragment, false },
616    { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_BindProgramStore, false },
617    { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_BindProgramVertex, false },
618    { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_BindProgramRaster, false },
619    { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_BindSampler, false },
620    { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_BindTexture, false },
621    { "_Z15rsgBindConstant19rs_program_fragmentj13rs_allocation", (void *)&SC_BindFragmentConstant, false },
622    { "_Z15rsgBindConstant17rs_program_vertexj13rs_allocation", (void *)&SC_BindVertexConstant, false },
623
624    { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadProjectionMatrix, false },
625    { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadModelMatrix, false },
626    { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadTextureMatrix, false },
627
628    { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_VpGetProjectionMatrix, false },
629
630    { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_PfConstantColor, false },
631
632    { "_Z11rsgGetWidthv", (void *)&SC_GetWidth, false },
633    { "_Z12rsgGetHeightv", (void *)&SC_GetHeight, false },
634
635
636    { "_Z11rsgDrawRectfffff", (void *)&SC_DrawRect, false },
637    { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_DrawQuad, false },
638    { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_DrawQuadTexCoords, false },
639    { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_DrawSpriteScreenspace, false },
640
641    { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_DrawMesh, false },
642    { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_DrawMeshPrimitive, false },
643    { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_DrawMeshPrimitiveRange, false },
644    { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_MeshComputeBoundingBox, false },
645
646    { "_Z11rsgDrawPath7rs_path", (void *)&SC_DrawPath, false },
647
648    { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false },
649    { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false },
650
651    { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false },
652    { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false },
653    { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false },
654    { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false },
655
656    { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false },
657    { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false },
658
659    { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_BindFrameBufferObjectColorTarget, false },
660    { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_BindFrameBufferObjectDepthTarget, false },
661    { "_Z19rsgClearColorTargetj", (void *)&SC_ClearFrameBufferObjectColorTarget, false },
662    { "_Z19rsgClearDepthTargetv", (void *)&SC_ClearFrameBufferObjectDepthTarget, false },
663    { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_ClearFrameBufferObjectTargets, false },
664
665    { "_Z9rsForEach9rs_script13rs_allocationS0_", (void *)&SC_ForEach_SAA, true },
666    { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach_SAAU, true },
667    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvPK16rs_script_call_t", (void *)&SC_ForEach_SAAUS, true },
668    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach_SAAUL, true },
669    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvjPK16rs_script_call_t", (void *)&SC_ForEach_SAAULS, true },
670
671    // time
672    { "_Z6rsTimePi", (void *)&SC_Time, true },
673    { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_LocalTime, true },
674    { "_Z14rsUptimeMillisv", (void*)&SC_UptimeMillis, true },
675    { "_Z13rsUptimeNanosv", (void*)&SC_UptimeNanos, true },
676    { "_Z7rsGetDtv", (void*)&SC_GetDt, false },
677
678    // misc
679    { "_Z5colorffff", (void *)&SC_Color, false },
680    { "_Z9rsgFinishv", (void *)&SC_Finish, false },
681
682    // Debug
683    { "_Z7rsDebugPKcf", (void *)&SC_debugF, true },
684    { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true },
685    { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true },
686    { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true },
687    { "_Z7rsDebugPKcd", (void *)&SC_debugD, true },
688    { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true },
689    { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true },
690    { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true },
691    { "_Z7rsDebugPKci", (void *)&SC_debugI32, true },
692    { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true },
693    // Both "long" and "unsigned long" need to be redirected to their
694    // 64-bit counterparts, since we have hacked Slang to use 64-bit
695    // for "long" on Arm (to be similar to Java).
696    { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true },
697    { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true },
698    { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true },
699    { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true },
700    { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true },
701
702    { NULL, NULL, false }
703};
704
705
706void* rsdLookupRuntimeStub(void* pContext, char const* name) {
707    ScriptC *s = (ScriptC *)pContext;
708    if (!strcmp(name, "__isThreadable")) {
709      return (void*) s->mHal.info.isThreadable;
710    } else if (!strcmp(name, "__clearThreadable")) {
711      s->mHal.info.isThreadable = false;
712      return NULL;
713    }
714
715    RsdSymbolTable *syms = gSyms;
716    const RsdSymbolTable *sym = rsdLookupSymbolMath(name);
717
718    if (!sym) {
719        while (syms->mPtr) {
720            if (!strcmp(syms->mName, name)) {
721                sym = syms;
722            }
723            syms++;
724        }
725    }
726
727    if (sym) {
728        s->mHal.info.isThreadable &= sym->threadable;
729        return sym->mPtr;
730    }
731    ALOGE("ScriptC sym lookup failed for %s", name);
732    return NULL;
733}
734
735
736