• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011-2012 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 
23 #include "rsCpuCore.h"
24 #include "rsCpuScript.h"
25 
26 using android::renderscript::Matrix2x2;
27 using android::renderscript::Matrix3x3;
28 using android::renderscript::Matrix4x4;
29 
30 #define EXPORT_F32_FN_F32(func)                                 \
31     float __attribute__((overloadable)) SC_##func(float v) {    \
32         return func(v);                                         \
33     }
34 
35 #define EXPORT_F32_FN_F32_F32(func)                                     \
36     float __attribute__((overloadable)) SC_##func(float t, float v) {   \
37         return func(t, v);                                              \
38     }
39 
40 //////////////////////////////////////////////////////////////////////////////
41 // Float util
42 //////////////////////////////////////////////////////////////////////////////
43 
44 // Handle missing Gingerbread functions like tgammaf.
SC_tgammaf(float x)45 float SC_tgammaf(float x) {
46 #ifdef RS_COMPATIBILITY_LIB
47     return __builtin_tgamma(x);
48 #else
49     return tgammaf(x);
50 #endif
51 }
52 
SC_abs_i32(int32_t v)53 uint32_t SC_abs_i32(int32_t v) {return abs(v);}
54 
SC_MatrixLoadRotate(Matrix4x4 * m,float rot,float x,float y,float z)55 static void SC_MatrixLoadRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
56     m->loadRotate(rot, x, y, z);
57 }
SC_MatrixLoadScale(Matrix4x4 * m,float x,float y,float z)58 static void SC_MatrixLoadScale(Matrix4x4 *m, float x, float y, float z) {
59     m->loadScale(x, y, z);
60 }
SC_MatrixLoadTranslate(Matrix4x4 * m,float x,float y,float z)61 static void SC_MatrixLoadTranslate(Matrix4x4 *m, float x, float y, float z) {
62     m->loadTranslate(x, y, z);
63 }
SC_MatrixRotate(Matrix4x4 * m,float rot,float x,float y,float z)64 static void SC_MatrixRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
65     m->rotate(rot, x, y, z);
66 }
SC_MatrixScale(Matrix4x4 * m,float x,float y,float z)67 static void SC_MatrixScale(Matrix4x4 *m, float x, float y, float z) {
68     m->scale(x, y, z);
69 }
SC_MatrixTranslate(Matrix4x4 * m,float x,float y,float z)70 static void SC_MatrixTranslate(Matrix4x4 *m, float x, float y, float z) {
71     m->translate(x, y, z);
72 }
73 
SC_MatrixLoadOrtho(Matrix4x4 * m,float l,float r,float b,float t,float n,float f)74 static void SC_MatrixLoadOrtho(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
75     m->loadOrtho(l, r, b, t, n, f);
76 }
SC_MatrixLoadFrustum(Matrix4x4 * m,float l,float r,float b,float t,float n,float f)77 static void SC_MatrixLoadFrustum(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
78     m->loadFrustum(l, r, b, t, n, f);
79 }
SC_MatrixLoadPerspective(Matrix4x4 * m,float fovy,float aspect,float near,float far)80 static void SC_MatrixLoadPerspective(Matrix4x4 *m, float fovy, float aspect, float near, float far) {
81     m->loadPerspective(fovy, aspect, near, far);
82 }
83 
SC_MatrixInverse_4x4(Matrix4x4 * m)84 static bool SC_MatrixInverse_4x4(Matrix4x4 *m) {
85     return m->inverse();
86 }
SC_MatrixInverseTranspose_4x4(Matrix4x4 * m)87 static bool SC_MatrixInverseTranspose_4x4(Matrix4x4 *m) {
88     return m->inverseTranspose();
89 }
SC_MatrixTranspose_4x4(Matrix4x4 * m)90 static void SC_MatrixTranspose_4x4(Matrix4x4 *m) {
91     m->transpose();
92 }
SC_MatrixTranspose_3x3(Matrix3x3 * m)93 static void SC_MatrixTranspose_3x3(Matrix3x3 *m) {
94     m->transpose();
95 }
SC_MatrixTranspose_2x2(Matrix2x2 * m)96 static void SC_MatrixTranspose_2x2(Matrix2x2 *m) {
97     m->transpose();
98 }
99 
SC_randf2(float min,float max)100 float SC_randf2(float min, float max) {
101     float r = (float)rand();
102     r /= RAND_MAX;
103     r = r * (max - min) + min;
104     return r;
105 }
106 
107 EXPORT_F32_FN_F32(acosf)
EXPORT_F32_FN_F32(acoshf)108 EXPORT_F32_FN_F32(acoshf)
109 EXPORT_F32_FN_F32(asinf)
110 EXPORT_F32_FN_F32(asinhf)
111 EXPORT_F32_FN_F32(atanf)
112 EXPORT_F32_FN_F32_F32(atan2f)
113 EXPORT_F32_FN_F32(atanhf)
114 EXPORT_F32_FN_F32(cbrtf)
115 EXPORT_F32_FN_F32(ceilf)
116 EXPORT_F32_FN_F32_F32(copysignf)
117 EXPORT_F32_FN_F32(cosf)
118 EXPORT_F32_FN_F32(coshf)
119 EXPORT_F32_FN_F32(erfcf)
120 EXPORT_F32_FN_F32(erff)
121 EXPORT_F32_FN_F32(expf)
122 EXPORT_F32_FN_F32(exp2f)
123 EXPORT_F32_FN_F32(expm1f)
124 EXPORT_F32_FN_F32_F32(fdimf)
125 EXPORT_F32_FN_F32(floorf)
126 float SC_fmaf(float u, float t, float v) {return fmaf(u, t, v);}
127 EXPORT_F32_FN_F32_F32(fmaxf)
EXPORT_F32_FN_F32_F32(fminf)128 EXPORT_F32_FN_F32_F32(fminf)
129 EXPORT_F32_FN_F32_F32(fmodf)
130 float SC_frexpf(float v, int* ptr) {return frexpf(v, ptr);}
EXPORT_F32_FN_F32_F32(hypotf)131 EXPORT_F32_FN_F32_F32(hypotf)
132 int SC_ilogbf(float v) {return ilogbf(v); }
SC_ldexpf(float v,int i)133 float SC_ldexpf(float v, int i) {return ldexpf(v, i);}
EXPORT_F32_FN_F32(lgammaf)134 EXPORT_F32_FN_F32(lgammaf)
135 float SC_lgammaf_r(float v, int* ptr) {return lgammaf_r(v, ptr);}
136 EXPORT_F32_FN_F32(logf)
EXPORT_F32_FN_F32(log10f)137 EXPORT_F32_FN_F32(log10f)
138 EXPORT_F32_FN_F32(log1pf)
139 EXPORT_F32_FN_F32(logbf)
140 float SC_modff(float v, float* ptr) {return modff(v, ptr);}
141 EXPORT_F32_FN_F32_F32(nextafterf)
EXPORT_F32_FN_F32_F32(powf)142 EXPORT_F32_FN_F32_F32(powf)
143 EXPORT_F32_FN_F32_F32(remainderf)
144 float SC_remquof(float t, float v, int* ptr) {return remquof(t, v, ptr);}
145 EXPORT_F32_FN_F32(rintf)
EXPORT_F32_FN_F32(roundf)146 EXPORT_F32_FN_F32(roundf)
147 EXPORT_F32_FN_F32(sinf)
148 EXPORT_F32_FN_F32(sinhf)
149 EXPORT_F32_FN_F32(sqrtf)
150 EXPORT_F32_FN_F32(tanf)
151 EXPORT_F32_FN_F32(tanhf)
152 EXPORT_F32_FN_F32(truncf)
153 void __attribute__((overloadable)) rsMatrixLoadRotate(rs_matrix4x4 *m,
154         float rot, float x, float y, float z) {
155     SC_MatrixLoadRotate((Matrix4x4 *) m, rot, x, y, z);
156 }
rsMatrixLoadScale(rs_matrix4x4 * m,float x,float y,float z)157 void __attribute__((overloadable)) rsMatrixLoadScale(rs_matrix4x4 *m,
158         float x, float y, float z) {
159     SC_MatrixLoadScale((Matrix4x4 *) m, x, y, z);
160 }
rsMatrixLoadTranslate(rs_matrix4x4 * m,float x,float y,float z)161 void __attribute__((overloadable)) rsMatrixLoadTranslate(rs_matrix4x4 *m,
162         float x, float y, float z) {
163     SC_MatrixLoadTranslate((Matrix4x4 *) m, x, y, z);
164 }
rsMatrixRotate(rs_matrix4x4 * m,float rot,float x,float y,float z)165 void __attribute__((overloadable)) rsMatrixRotate(rs_matrix4x4 *m, float rot,
166         float x, float y, float z) {
167     SC_MatrixRotate((Matrix4x4 *) m, rot, x, y, z);
168 }
rsMatrixScale(rs_matrix4x4 * m,float x,float y,float z)169 void __attribute__((overloadable)) rsMatrixScale(rs_matrix4x4 *m, float x,
170         float y, float z) {
171     SC_MatrixScale((Matrix4x4 *) m, x, y, z);
172 }
rsMatrixTranslate(rs_matrix4x4 * m,float x,float y,float z)173 void __attribute__((overloadable)) rsMatrixTranslate(rs_matrix4x4 *m, float x,
174         float y, float z) {
175     SC_MatrixTranslate((Matrix4x4 *) m, x, y, z);
176 }
rsMatrixLoadOrtho(rs_matrix4x4 * m,float l,float r,float b,float t,float n,float f)177 void __attribute__((overloadable)) rsMatrixLoadOrtho(rs_matrix4x4 *m, float l,
178         float r, float b, float t, float n, float f) {
179     SC_MatrixLoadOrtho((Matrix4x4 *) m, l, r, b, t, n, f);
180 }
rsMatrixLoadFrustum(rs_matrix4x4 * m,float l,float r,float b,float t,float n,float f)181 void __attribute__((overloadable)) rsMatrixLoadFrustum(rs_matrix4x4 *m,
182         float l, float r, float b, float t, float n, float f) {
183     SC_MatrixLoadFrustum((Matrix4x4 *) m, l, r, b, t, n, f);
184 }
rsMatrixLoadPerspective(rs_matrix4x4 * m,float fovy,float aspect,float near,float far)185 void __attribute__((overloadable)) rsMatrixLoadPerspective(rs_matrix4x4 *m,
186         float fovy, float aspect, float near, float far) {
187     SC_MatrixLoadPerspective((Matrix4x4 *) m, fovy, aspect, near, far);
188 }
rsMatrixInverse(rs_matrix4x4 * m)189 bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m) {
190     return SC_MatrixInverse_4x4((Matrix4x4 *) m);
191 }
rsMatrixInverseTranspose(rs_matrix4x4 * m)192 bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m) {
193     return SC_MatrixInverseTranspose_4x4((Matrix4x4 *) m);
194 }
rsMatrixTranspose(rs_matrix4x4 * m)195 void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m) {
196     SC_MatrixTranspose_4x4((Matrix4x4 *) m);
197 }
rsMatrixTranspose(rs_matrix3x3 * m)198 void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m) {
199     SC_MatrixTranspose_3x3((Matrix3x3 *) m);
200 }
rsMatrixTranspose(rs_matrix2x2 * m)201 void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m) {
202     SC_MatrixTranspose_2x2((Matrix2x2 *) m);
203 }
204 
205 
206