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