1 /* 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 20 #include "utils/Timers.h" 21 22 #include <time.h> 23 24 namespace android { 25 namespace renderscript { 26 27 28 ////////////////////////////////////////////////////////////////////////////// 29 // Context 30 ////////////////////////////////////////////////////////////////////////////// 31 32 void rsrAllocationSyncAll(Context *, Script *, Allocation *); 33 34 void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc, 35 uint32_t dstOff, 36 uint32_t dstMip, 37 uint32_t count, 38 Allocation *srcAlloc, 39 uint32_t srcOff, uint32_t srcMip); 40 void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc, 41 uint32_t dstXoff, uint32_t dstYoff, 42 uint32_t dstMip, uint32_t dstFace, 43 uint32_t width, uint32_t height, 44 Allocation *srcAlloc, 45 uint32_t srcXoff, uint32_t srcYoff, 46 uint32_t srcMip, uint32_t srcFace); 47 48 ////////////////////////////////////////////////////////////////////////////// 49 // Time routines 50 ////////////////////////////////////////////////////////////////////////////// 51 52 float rsrGetDt(Context *, Script *); 53 time_t rsrTime(Context *, Script *, time_t *timer); 54 tm* rsrLocalTime(Context *, Script *, tm *local, time_t *timer); 55 int64_t rsrUptimeMillis(Context *, Script *); 56 int64_t rsrUptimeNanos(Context *, Script *); 57 58 ////////////////////////////////////////////////////////////////////////////// 59 // Message routines 60 ////////////////////////////////////////////////////////////////////////////// 61 62 uint32_t rsrToClient(Context *, Script *, int cmdID, void *data, int len); 63 uint32_t rsrToClientBlocking(Context *, Script *, int cmdID, void *data, int len); 64 65 ////////////////////////////////////////////////////////////////////////////// 66 // 67 ////////////////////////////////////////////////////////////////////////////// 68 69 void rsrSetObject(const Context *, const Script *, ObjectBase **dst, ObjectBase * src); 70 void rsrClearObject(const Context *, const Script *, ObjectBase **dst); 71 bool rsrIsObject(const Context *, const Script *, const ObjectBase *src); 72 73 void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr, 74 size_t elementCount, size_t startOffset); 75 void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr, 76 size_t elementCount, size_t startOffset); 77 78 79 uint32_t rsrToClient(Context *, Script *, int cmdID, void *data, int len); 80 uint32_t rsrToClientBlocking(Context *, Script *, int cmdID, void *data, int len); 81 82 void rsrAllocationMarkDirty(Context *, Script *, RsAllocation a); 83 void rsrAllocationSyncAll(Context *, Script *, Allocation *a, RsAllocationUsageType source); 84 85 86 void rsrForEach(Context *, Script *, Script *target, 87 Allocation *in, 88 Allocation *out, 89 const void *usr, 90 uint32_t usrBytes, 91 const RsScriptCall *call); 92 93 94 ////////////////////////////////////////////////////////////////////////////// 95 // Heavy math functions 96 ////////////////////////////////////////////////////////////////////////////// 97 98 99 void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v); 100 float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col); 101 void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v); 102 float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col); 103 void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v); 104 float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col); 105 void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m); 106 void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m); 107 void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m); 108 void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v); 109 void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v); 110 void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v); 111 void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v); 112 void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v); 113 void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v); 114 void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v); 115 void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v); 116 void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z); 117 void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z); 118 void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z); 119 void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, 120 const rs_matrix4x4 *rhs); 121 void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs); 122 void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, 123 const rs_matrix3x3 *rhs); 124 void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs); 125 void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, 126 const rs_matrix2x2 *rhs); 127 void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs); 128 void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z); 129 void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z); 130 void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z); 131 void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, 132 float bottom, float top, float near, float far); 133 void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, 134 float bottom, float top, float near, float far); 135 void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far); 136 137 // Returns true if the matrix was successfully inversed 138 bool rsrMatrixInverse_4x4(rs_matrix4x4 *m); 139 // Returns true if the matrix was successfully inversed 140 bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m); 141 142 void rsrMatrixTranspose_4x4(rs_matrix4x4 *m); 143 void rsrMatrixTranspose_3x3(rs_matrix3x3 *m); 144 void rsrMatrixTranspose_2x2(rs_matrix2x2 *m); 145 146 } 147 } 148