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