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 | |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 20 | #include <time.h> |
| 21 | |
| 22 | namespace android { |
| 23 | namespace renderscript { |
| 24 | |
| 25 | |
| 26 | ////////////////////////////////////////////////////////////////////////////// |
| 27 | // Context |
| 28 | ////////////////////////////////////////////////////////////////////////////// |
| 29 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 30 | void rsrAllocationSyncAll(Context *, Script *, Allocation *); |
| 31 | |
| 32 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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 *); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 46 | |
| 47 | ////////////////////////////////////////////////////////////////////////////// |
| 48 | // VP |
| 49 | ////////////////////////////////////////////////////////////////////////////// |
| 50 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 56 | |
| 57 | ////////////////////////////////////////////////////////////////////////////// |
| 58 | // Drawing |
| 59 | ////////////////////////////////////////////////////////////////////////////// |
| 60 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 61 | void rsrDrawPath(Context *, Path *); |
| 62 | void rsrDrawMesh(Context *, Mesh *); |
| 63 | void rsrDrawMeshPrimitive(Context *, Mesh *, uint32_t primIndex); |
| 64 | void rsrDrawMeshPrimitiveRange(Context *, Mesh *, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 65 | uint32_t primIndex, uint32_t start, uint32_t len); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 66 | void rsrMeshComputeBoundingBox(Context *, Mesh *, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 67 | float *minX, float *minY, float *minZ, |
| 68 | float *maxX, float *maxY, float *maxZ); |
| 69 | |
| 70 | |
| 71 | ////////////////////////////////////////////////////////////////////////////// |
| 72 | // |
| 73 | ////////////////////////////////////////////////////////////////////////////// |
| 74 | |
| 75 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 76 | void rsrColor(Context *, float r, float g, float b, float a); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 77 | #endif |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 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 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 93 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 100 | int32_t *left, int32_t *right, int32_t *top, int32_t *bottom); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 101 | void rsrMeasureTextAlloc(Context *, Allocation *, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 102 | int32_t *left, int32_t *right, int32_t *top, int32_t *bottom); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 103 | void rsrMeasureText(Context *, const char *text, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 104 | int32_t *left, int32_t *right, int32_t *top, int32_t *bottom); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 105 | void rsrBindFont(Context *, Font *); |
| 106 | void rsrFontColor(Context *, float r, float g, float b, float a); |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 107 | |
Stephen Hines | 7a01126 | 2013-11-27 14:21:57 -0800 | [diff] [blame] | 108 | #endif |
| 109 | |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 110 | void rsrAllocationIoSend(Context *, Allocation *); |
| 111 | void rsrAllocationIoReceive(Context *, Allocation *); |
| 112 | |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 113 | ////////////////////////////////////////////////////////////////////////////// |
| 114 | // Time routines |
| 115 | ////////////////////////////////////////////////////////////////////////////// |
| 116 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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 *); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 122 | |
| 123 | ////////////////////////////////////////////////////////////////////////////// |
| 124 | // Message routines |
| 125 | ////////////////////////////////////////////////////////////////////////////// |
| 126 | |
Stephen Hines | 70537f5 | 2013-12-03 16:44:44 -0800 | [diff] [blame] | 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 | |
Stephen Hines | 276000a | 2013-12-03 09:33:32 -0800 | [diff] [blame] | 131 | uint32_t rsrToClient(Context *, int cmdID, const void *data, int len); |
| 132 | uint32_t rsrToClientBlocking(Context *, int cmdID, const void *data, int len); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 133 | |
| 134 | ////////////////////////////////////////////////////////////////////////////// |
| 135 | // |
| 136 | ////////////////////////////////////////////////////////////////////////////// |
| 137 | |
Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 138 | void rsrSetObject(const Context *, rs_object_base *dst, const ObjectBase *src); |
Yang Ni | ade3137 | 2016-04-06 09:34:34 -0700 | [diff] [blame] | 139 | void rsrClearObject(rs_object_base *dst); |
Tim Murray | 6a45ddb | 2014-08-06 11:49:02 -0700 | [diff] [blame] | 140 | |
Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 141 | bool rsrIsObject(const Context *, rs_object_base src); |
Tim Murray | 6a45ddb | 2014-08-06 11:49:02 -0700 | [diff] [blame] | 142 | bool rsrIsObject(const Context *, ObjectBase* src); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 143 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 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 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 150 | void rsrAllocationSyncAll(Context *, Allocation *a, RsAllocationUsageType source); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 151 | |
| 152 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 153 | void rsrForEach(Context *, Script *target, |
Yang Ni | 12398d8 | 2015-09-18 14:57:07 -0700 | [diff] [blame] | 154 | uint32_t slot, |
Yang Ni | dda5cb5 | 2015-10-27 15:23:17 -0700 | [diff] [blame] | 155 | uint32_t numInputs, |
| 156 | Allocation **in, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 157 | Allocation *out, |
| 158 | const void *usr, |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 159 | uint32_t usrBytes, |
Pirama Arumuga Nainar | 9479e5b | 2015-04-28 14:40:45 -0700 | [diff] [blame] | 160 | const RsScriptCall *call); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 161 | |
Pirama Arumuga Nainar | 6b387c1 | 2015-10-12 14:06:57 -0700 | [diff] [blame] | 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); |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 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 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 225 | } // namespace renderscript |
| 226 | } // namespace android |