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