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 rsrBindTexture(Context *, Script *, ProgramFragment *, uint32_t slot, Allocation *); 33 void rsrBindConstant(Context *, Script *, ProgramFragment *, uint32_t slot, Allocation *); 34 void rsrBindConstant(Context *, Script *, ProgramVertex*, uint32_t slot, Allocation *); 35 void rsrBindSampler(Context *, Script *, ProgramFragment *, uint32_t slot, Sampler *); 36 void rsrBindProgramStore(Context *, Script *, ProgramStore *); 37 void rsrBindProgramFragment(Context *, Script *, ProgramFragment *); 38 void rsrBindProgramVertex(Context *, Script *, ProgramVertex *); 39 void rsrBindProgramRaster(Context *, Script *, ProgramRaster *); 40 void rsrBindFrameBufferObjectColorTarget(Context *, Script *, Allocation *, uint32_t slot); 41 void rsrBindFrameBufferObjectDepthTarget(Context *, Script *, Allocation *); 42 void rsrClearFrameBufferObjectColorTarget(Context *, Script *, uint32_t slot); 43 void rsrClearFrameBufferObjectDepthTarget(Context *, Script *); 44 void rsrClearFrameBufferObjectTargets(Context *, Script *); 45 46 ////////////////////////////////////////////////////////////////////////////// 47 // VP 48 ////////////////////////////////////////////////////////////////////////////// 49 50 void rsrVpLoadProjectionMatrix(Context *, Script *, const rsc_Matrix *m); 51 void rsrVpLoadModelMatrix(Context *, Script *, const rsc_Matrix *m); 52 void rsrVpLoadTextureMatrix(Context *, Script *, const rsc_Matrix *m); 53 void rsrPfConstantColor(Context *, Script *, ProgramFragment *, float r, float g, float b, float a); 54 void rsrVpGetProjectionMatrix(Context *, Script *, rsc_Matrix *m); 55 56 ////////////////////////////////////////////////////////////////////////////// 57 // Drawing 58 ////////////////////////////////////////////////////////////////////////////// 59 60 void rsrDrawPath(Context *, Script *, Path *); 61 void rsrDrawMesh(Context *, Script *, Mesh *); 62 void rsrDrawMeshPrimitive(Context *, Script *, Mesh *, uint32_t primIndex); 63 void rsrDrawMeshPrimitiveRange(Context *, Script *, Mesh *, 64 uint32_t primIndex, uint32_t start, uint32_t len); 65 void rsrMeshComputeBoundingBox(Context *, Script *, Mesh *, 66 float *minX, float *minY, float *minZ, 67 float *maxX, float *maxY, float *maxZ); 68 69 70 ////////////////////////////////////////////////////////////////////////////// 71 // 72 ////////////////////////////////////////////////////////////////////////////// 73 74 75 void rsrColor(Context *, Script *, float r, float g, float b, float a); 76 void rsrAllocationSyncAll(Context *, Script *, Allocation *); 77 78 void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc, 79 uint32_t dstOff, 80 uint32_t dstMip, 81 uint32_t count, 82 Allocation *srcAlloc, 83 uint32_t srcOff, uint32_t srcMip); 84 void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc, 85 uint32_t dstXoff, uint32_t dstYoff, 86 uint32_t dstMip, uint32_t dstFace, 87 uint32_t width, uint32_t height, 88 Allocation *srcAlloc, 89 uint32_t srcXoff, uint32_t srcYoff, 90 uint32_t srcMip, uint32_t srcFace); 91 92 void rsrPrepareClear(Context *, Script *); 93 uint32_t rsrGetWidth(Context *, Script *); 94 uint32_t rsrGetHeight(Context *, Script *); 95 void rsrDrawTextAlloc(Context *, Script *, Allocation *, int x, int y); 96 void rsrDrawText(Context *, Script *, const char *text, int x, int y); 97 void rsrSetMetrics(Context *, Script *, Font::Rect *metrics, 98 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom); 99 void rsrMeasureTextAlloc(Context *, Script *, Allocation *, 100 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom); 101 void rsrMeasureText(Context *, Script *, const char *text, 102 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom); 103 void rsrBindFont(Context *, Script *, Font *); 104 void rsrFontColor(Context *, Script *, float r, float g, float b, float a); 105 106 ////////////////////////////////////////////////////////////////////////////// 107 // Time routines 108 ////////////////////////////////////////////////////////////////////////////// 109 110 float rsrGetDt(Context *, Script *); 111 time_t rsrTime(Context *, Script *, time_t *timer); 112 tm* rsrLocalTime(Context *, Script *, tm *local, time_t *timer); 113 int64_t rsrUptimeMillis(Context *, Script *); 114 int64_t rsrUptimeNanos(Context *, Script *); 115 116 ////////////////////////////////////////////////////////////////////////////// 117 // Message routines 118 ////////////////////////////////////////////////////////////////////////////// 119 120 uint32_t rsrToClient(Context *, Script *, int cmdID, void *data, int len); 121 uint32_t rsrToClientBlocking(Context *, Script *, int cmdID, void *data, int len); 122 123 ////////////////////////////////////////////////////////////////////////////// 124 // 125 ////////////////////////////////////////////////////////////////////////////// 126 127 void rsrSetObject(const Context *, const Script *, ObjectBase **dst, ObjectBase * src); 128 void rsrClearObject(const Context *, const Script *, ObjectBase **dst); 129 bool rsrIsObject(const Context *, const Script *, const ObjectBase *src); 130 131 void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr, 132 size_t elementCount, size_t startOffset); 133 void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr, 134 size_t elementCount, size_t startOffset); 135 136 137 uint32_t rsrToClient(Context *, Script *, int cmdID, void *data, int len); 138 uint32_t rsrToClientBlocking(Context *, Script *, int cmdID, void *data, int len); 139 140 void rsrAllocationMarkDirty(Context *, Script *, RsAllocation a); 141 void rsrAllocationSyncAll(Context *, Script *, Allocation *a, RsAllocationUsageType source); 142 143 144 void rsrForEach(Context *, Script *, Script *target, 145 Allocation *in, 146 Allocation *out, 147 const void *usr, 148 uint32_t usrBytes, 149 const RsScriptCall *call); 150 151 152 ////////////////////////////////////////////////////////////////////////////// 153 // Heavy math functions 154 ////////////////////////////////////////////////////////////////////////////// 155 156 157 void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v); 158 float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col); 159 void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v); 160 float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col); 161 void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v); 162 float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col); 163 void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m); 164 void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m); 165 void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m); 166 void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v); 167 void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v); 168 void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v); 169 void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v); 170 void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v); 171 void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v); 172 void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v); 173 void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v); 174 void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z); 175 void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z); 176 void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z); 177 void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, 178 const rs_matrix4x4 *rhs); 179 void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs); 180 void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, 181 const rs_matrix3x3 *rhs); 182 void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs); 183 void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, 184 const rs_matrix2x2 *rhs); 185 void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs); 186 void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z); 187 void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z); 188 void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z); 189 void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, 190 float bottom, float top, float near, float far); 191 void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, 192 float bottom, float top, float near, float far); 193 void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far); 194 195 // Returns true if the matrix was successfully inversed 196 bool rsrMatrixInverse_4x4(rs_matrix4x4 *m); 197 // Returns true if the matrix was successfully inversed 198 bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m); 199 200 void rsrMatrixTranspose_4x4(rs_matrix4x4 *m); 201 void rsrMatrixTranspose_3x3(rs_matrix3x3 *m); 202 void rsrMatrixTranspose_2x2(rs_matrix2x2 *m); 203 204 } 205 } 206