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