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