Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 2 | * Copyright (C) 2009-2012 The Android Open Source Project |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 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" |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 19 | #include "rsMatrix4x4.h" |
| 20 | #include "rsMatrix3x3.h" |
| 21 | #include "rsMatrix2x2.h" |
Alex Sakhartchouk | 4edf030 | 2012-03-09 10:47:27 -0800 | [diff] [blame] | 22 | #include "rsgApiStructs.h" |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 23 | |
Romain Guy | 98e10fd | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 24 | #include <time.h> |
I-Jui (Ray) Sung | 0ab0f90 | 2016-10-19 15:53:20 -0700 | [diff] [blame] | 25 | #include <sstream> |
Romain Guy | 98e10fd | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 26 | |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace renderscript { |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 30 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 31 | |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 32 | ////////////////////////////////////////////////////////////////////////////// |
| 33 | // Math routines |
| 34 | ////////////////////////////////////////////////////////////////////////////// |
| 35 | |
Stephen Hines | 196c111 | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 36 | #if 0 |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 37 | static float SC_sinf_fast(float x) { |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 38 | const float A = 1.0f / (2.0f * M_PI); |
| 39 | const float B = -16.0f; |
| 40 | const float C = 8.0f; |
Jason Sams | a57c0a7 | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 41 | |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 42 | // scale angle for easy argument reduction |
| 43 | x *= A; |
Jason Sams | a57c0a7 | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 44 | |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 45 | if (fabsf(x) >= 0.5f) { |
| 46 | // argument reduction |
| 47 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 48 | } |
Jason Sams | a57c0a7 | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 49 | |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 50 | const float y = B * x * fabsf(x) + C * x; |
| 51 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 52 | } |
| 53 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 54 | static float SC_cosf_fast(float x) { |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 55 | x += float(M_PI / 2); |
| 56 | |
| 57 | const float A = 1.0f / (2.0f * M_PI); |
| 58 | const float B = -16.0f; |
| 59 | const float C = 8.0f; |
Jason Sams | a57c0a7 | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 60 | |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 61 | // scale angle for easy argument reduction |
| 62 | x *= A; |
Jason Sams | a57c0a7 | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 63 | |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 64 | if (fabsf(x) >= 0.5f) { |
| 65 | // argument reduction |
| 66 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 67 | } |
Jason Sams | a57c0a7 | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 68 | |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 69 | const float y = B * x * fabsf(x) + C * x; |
| 70 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 71 | } |
Stephen Hines | 196c111 | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 72 | #endif |
Romain Guy | 2275d63 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 73 | |
Romain Guy | 98e10fd | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 74 | ////////////////////////////////////////////////////////////////////////////// |
| 75 | // Time routines |
| 76 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 77 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 78 | time_t rsrTime(Context *rsc, time_t *timer) { |
Stephen Hines | ca3f09c | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 79 | return time(timer); |
Romain Guy | 98e10fd | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 82 | tm* rsrLocalTime(Context *rsc, tm *local, time_t *timer) { |
Stephen Hines | ca3f09c | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 83 | if (!local) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 84 | return nullptr; |
Stephen Hines | ca3f09c | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 85 | } |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 86 | |
Stephen Hines | ca3f09c | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 87 | // The native localtime function is not thread-safe, so we |
| 88 | // have to apply locking for proper behavior in RenderScript. |
| 89 | pthread_mutex_lock(&rsc->gLibMutex); |
| 90 | tm *tmp = localtime(timer); |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 91 | memcpy(local, tmp, sizeof(int)*9); |
Stephen Hines | ca3f09c | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 92 | pthread_mutex_unlock(&rsc->gLibMutex); |
| 93 | return local; |
Romain Guy | 39dbc80 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 96 | int64_t rsrUptimeMillis(Context *rsc) { |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 97 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 98 | } |
| 99 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 100 | int64_t rsrUptimeNanos(Context *rsc) { |
Jason Sams | 7349547 | 2010-07-29 17:31:14 -0700 | [diff] [blame] | 101 | return systemTime(SYSTEM_TIME_MONOTONIC); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 104 | float rsrGetDt(Context *rsc, const Script *sc) { |
Jason Sams | ef5867a | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 105 | int64_t l = sc->mEnviroment.mLastDtTime; |
| 106 | sc->mEnviroment.mLastDtTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 107 | return ((float)(sc->mEnviroment.mLastDtTime - l)) / 1.0e9; |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 110 | ////////////////////////////////////////////////////////////////////////////// |
| 111 | // |
| 112 | ////////////////////////////////////////////////////////////////////////////// |
| 113 | |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 114 | static void SetObjectRef(const Context *rsc, const ObjectBase *dst, const ObjectBase *src) { |
| 115 | //ALOGE("setObjectRef %p,%p %p", rsc, dst, src); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 116 | if (src) { |
| 117 | CHECK_OBJ(src); |
| 118 | src->incSysRef(); |
Jason Sams | f24d7d0 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 119 | } |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 120 | if (dst) { |
| 121 | CHECK_OBJ(dst); |
| 122 | dst->decSysRef(); |
Jason Sams | f24d7d0 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 123 | } |
Jason Sams | c093685 | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 124 | } |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 125 | |
Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 126 | // Legacy, remove when drivers are updated |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 127 | void rsrClearObject(const Context *rsc, void *dst) { |
| 128 | ObjectBase **odst = (ObjectBase **)dst; |
Jason Sams | 0c77202 | 2015-04-14 17:27:39 -0700 | [diff] [blame] | 129 | if (ObjectBase::gDebugReferences) { |
| 130 | ALOGE("rsrClearObject %p,%p", odst, *odst); |
| 131 | } |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 132 | if (odst[0]) { |
| 133 | CHECK_OBJ(odst[0]); |
| 134 | odst[0]->decSysRef(); |
| 135 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 136 | *odst = nullptr; |
Jason Sams | c093685 | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 137 | } |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 138 | |
Yang Ni | 5e48002 | 2016-04-06 09:34:34 -0700 | [diff] [blame] | 139 | void rsrClearObject(rs_object_base *dst) { |
Jason Sams | 0c77202 | 2015-04-14 17:27:39 -0700 | [diff] [blame] | 140 | if (ObjectBase::gDebugReferences) { |
| 141 | ALOGE("rsrClearObject %p,%p", dst, dst->p); |
| 142 | } |
Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 143 | if (dst->p) { |
| 144 | CHECK_OBJ(dst->p); |
| 145 | dst->p->decSysRef(); |
| 146 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 147 | dst->p = nullptr; |
Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // Legacy, remove when drivers are updated |
Yang Ni | 3a17469 | 2016-04-11 15:29:20 -0700 | [diff] [blame] | 151 | void rsrClearObject(const Context *rsc, rs_object_base *dst) { |
| 152 | rsrClearObject(dst); |
| 153 | } |
| 154 | |
| 155 | // Legacy, remove when drivers are updated |
Jason Sams | 0c77202 | 2015-04-14 17:27:39 -0700 | [diff] [blame] | 156 | void rsrSetObject(const Context *rsc, void *dst, ObjectBase *src) { |
| 157 | if (src == nullptr) { |
| 158 | rsrClearObject(rsc, dst); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | ObjectBase **odst = (ObjectBase **)dst; |
| 163 | if (ObjectBase::gDebugReferences) { |
| 164 | ALOGE("rsrSetObject (base) %p,%p %p", dst, *odst, src); |
| 165 | } |
| 166 | SetObjectRef(rsc, odst[0], src); |
| 167 | src->callUpdateCacheObject(rsc, dst); |
| 168 | } |
| 169 | |
| 170 | void rsrSetObject(const Context *rsc, rs_object_base *dst, const ObjectBase *src) { |
| 171 | if (src == nullptr) { |
| 172 | rsrClearObject(rsc, dst); |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | ObjectBase **odst = (ObjectBase **)dst; |
| 177 | if (ObjectBase::gDebugReferences) { |
| 178 | ALOGE("rsrSetObject (base) %p,%p %p", dst, *odst, src); |
| 179 | } |
| 180 | SetObjectRef(rsc, odst[0], src); |
| 181 | src->callUpdateCacheObject(rsc, dst); |
| 182 | } |
| 183 | |
| 184 | // Legacy, remove when drivers are updated |
Tim Murray | 6a45ddb | 2014-08-06 11:49:02 -0700 | [diff] [blame] | 185 | bool rsrIsObject(const Context *, ObjectBase* src) { |
Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 186 | ObjectBase **osrc = (ObjectBase **)src; |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 187 | return osrc != nullptr; |
Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | bool rsrIsObject(const Context *rsc, rs_object_base o) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 191 | return o.p != nullptr; |
Jason Sams | c093685 | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Jason Sams | 7dce6bc | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 194 | |
Tim Murray | 6a45ddb | 2014-08-06 11:49:02 -0700 | [diff] [blame] | 195 | |
Stephen Hines | 276000a | 2013-12-03 09:33:32 -0800 | [diff] [blame] | 196 | uint32_t rsrToClient(Context *rsc, int cmdID, const void *data, int len) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 197 | //ALOGE("SC_toClient %i %i %i", cmdID, len); |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 198 | return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, false); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Stephen Hines | 276000a | 2013-12-03 09:33:32 -0800 | [diff] [blame] | 201 | uint32_t rsrToClientBlocking(Context *rsc, int cmdID, const void *data, int len) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 202 | //ALOGE("SC_toClientBlocking %i %i", cmdID, len); |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 203 | return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, true); |
Jason Sams | ef5867a | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Stephen Hines | 70537f5 | 2013-12-03 16:44:44 -0800 | [diff] [blame] | 206 | // Keep these two routines (using non-const void pointers) so that we can |
| 207 | // still use existing GPU drivers. |
| 208 | uint32_t rsrToClient(Context *rsc, int cmdID, void *data, int len) { |
| 209 | return rsrToClient(rsc, cmdID, (const void *)data, len); |
| 210 | } |
| 211 | |
| 212 | uint32_t rsrToClientBlocking(Context *rsc, int cmdID, void *data, int len) { |
| 213 | return rsrToClientBlocking(rsc, cmdID, (const void *)data, len); |
| 214 | } |
| 215 | |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 216 | void rsrAllocationIoSend(Context *rsc, Allocation *src) { |
| 217 | src->ioSend(rsc); |
| 218 | } |
| 219 | |
| 220 | void rsrAllocationIoReceive(Context *rsc, Allocation *src) { |
| 221 | src->ioReceive(rsc); |
| 222 | } |
Jason Sams | 3a27c95 | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 223 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 224 | void rsrForEach(Context *rsc, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 225 | Script *target, |
Yang Ni | 12398d8 | 2015-09-18 14:57:07 -0700 | [diff] [blame] | 226 | uint32_t slot, |
Yang Ni | dda5cb5 | 2015-10-27 15:23:17 -0700 | [diff] [blame] | 227 | uint32_t numInputs, |
| 228 | Allocation **in, Allocation *out, |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 229 | const void *usr, uint32_t usrBytes, |
Pirama Arumuga Nainar | 9479e5b | 2015-04-28 14:40:45 -0700 | [diff] [blame] | 230 | const RsScriptCall *call) { |
Yang Ni | dda5cb5 | 2015-10-27 15:23:17 -0700 | [diff] [blame] | 231 | target->runForEach(rsc, slot, (const Allocation**)in, numInputs, out, usr, usrBytes, call); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 234 | void rsrAllocationSyncAll(Context *rsc, Allocation *a, RsAllocationUsageType usage) { |
Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 235 | a->syncAll(rsc, usage); |
Jason Sams | 693080e | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 236 | } |
| 237 | |
I-Jui (Ray) Sung | 0ab0f90 | 2016-10-19 15:53:20 -0700 | [diff] [blame] | 238 | // Helper for validateCopyArgs() - initialize the error message; only called on |
| 239 | // infrequently executed paths |
| 240 | static void initializeErrorMsg(std::stringstream &ss, int expectDim, bool isSrc) { |
| 241 | ss << (expectDim == 1 ? "rsAllocationCopy1DRange" : "rsAllocationCopy2DRange") << ": "; |
| 242 | ss << (isSrc? "source" : "destination") << " "; |
| 243 | } |
| 244 | |
| 245 | // We are doing the check even in a non-debug context, which is permissible because in that case |
| 246 | // a failed bound check results in unspecified behavior. |
| 247 | static bool validateCopyArgs(Context *rsc, bool isSrc, uint32_t expectDim, |
| 248 | const Allocation *alloc, uint32_t xoff, uint32_t yoff, |
| 249 | uint32_t lod, uint32_t w, uint32_t h) { |
| 250 | std::stringstream ss; |
| 251 | |
| 252 | if (lod >= alloc->mHal.drvState.lodCount) { |
| 253 | initializeErrorMsg(ss, expectDim, isSrc); |
| 254 | ss << "Mip level out of range: "; |
| 255 | ss << lod << " >= " << alloc->mHal.drvState.lodCount; |
| 256 | rsc->setError(RS_ERROR_FATAL_DEBUG, ss.str().c_str()); |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | const uint32_t allocDimX = alloc->mHal.drvState.lod[lod].dimX; |
| 261 | |
| 262 | // Check both in case xoff + w overflows |
| 263 | if (xoff >= allocDimX || (xoff + w) > allocDimX) { |
| 264 | initializeErrorMsg(ss, expectDim, isSrc); |
| 265 | ss << "X range: "; |
| 266 | ss << "[" << xoff << ", " << xoff + w << ") outside "; |
| 267 | ss << "[0, " << allocDimX << ")"; |
| 268 | rsc->setError(RS_ERROR_FATAL_DEBUG, ss.str().c_str()); |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | const uint32_t allocDimY = alloc->mHal.drvState.lod[lod].dimY; |
| 273 | |
| 274 | if (expectDim > 1) { |
| 275 | if (allocDimY == 0) { // Copy2D was given an allocation of 1D |
| 276 | initializeErrorMsg(ss, expectDim, isSrc); |
| 277 | ss << "dimensionality invalid: expected 2D; given 1D rs_allocation"; |
| 278 | rsc->setError(RS_ERROR_FATAL_DEBUG, ss.str().c_str()); |
| 279 | return false; |
| 280 | } |
| 281 | // Check both in case yoff + h overflows |
| 282 | if (yoff >= allocDimY || (yoff + h) > allocDimY) { |
| 283 | initializeErrorMsg(ss, expectDim, isSrc); |
| 284 | ss << "Y range: "; |
| 285 | ss << "[" << yoff << ", " << yoff + h << ") outside "; |
| 286 | ss << "[0, " << allocDimY << ")"; |
| 287 | rsc->setError(RS_ERROR_FATAL_DEBUG, ss.str().c_str()); |
| 288 | return false; |
| 289 | } |
| 290 | } else { |
| 291 | if (allocDimY != 0) { // Copy1D was given an allocation of 2D |
| 292 | initializeErrorMsg(ss, expectDim, isSrc); |
| 293 | ss << "dimensionality invalid: expected 1D; given 2D rs_allocation"; |
| 294 | rsc->setError(RS_ERROR_FATAL_DEBUG, ss.str().c_str()); |
| 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | return true; |
| 300 | } |
| 301 | |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 302 | void rsrAllocationCopy1DRange(Context *rsc, Allocation *dstAlloc, |
| 303 | uint32_t dstOff, |
| 304 | uint32_t dstMip, |
| 305 | uint32_t count, |
| 306 | Allocation *srcAlloc, |
| 307 | uint32_t srcOff, uint32_t srcMip) { |
I-Jui (Ray) Sung | 0ab0f90 | 2016-10-19 15:53:20 -0700 | [diff] [blame] | 308 | if (!validateCopyArgs(rsc, false, 1, dstAlloc, dstOff, 0, dstMip, count, 1) || |
| 309 | !validateCopyArgs(rsc, true, 1, srcAlloc, srcOff, 0, srcMip, count, 1)) { |
| 310 | return; |
| 311 | } |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 312 | rsi_AllocationCopy2DRange(rsc, dstAlloc, dstOff, 0, |
| 313 | dstMip, 0, count, 1, |
| 314 | srcAlloc, srcOff, 0, srcMip, 0); |
| 315 | } |
| 316 | |
| 317 | void rsrAllocationCopy2DRange(Context *rsc, Allocation *dstAlloc, |
| 318 | uint32_t dstXoff, uint32_t dstYoff, |
| 319 | uint32_t dstMip, uint32_t dstFace, |
| 320 | uint32_t width, uint32_t height, |
| 321 | Allocation *srcAlloc, |
| 322 | uint32_t srcXoff, uint32_t srcYoff, |
| 323 | uint32_t srcMip, uint32_t srcFace) { |
I-Jui (Ray) Sung | 0ab0f90 | 2016-10-19 15:53:20 -0700 | [diff] [blame] | 324 | if (!validateCopyArgs(rsc, false, 2, dstAlloc, dstXoff, dstYoff, dstMip, width, height) || |
| 325 | !validateCopyArgs(rsc, true, 2, srcAlloc, srcXoff, srcYoff, srcMip, width, height)) { |
| 326 | return; |
| 327 | } |
| 328 | |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 329 | rsi_AllocationCopy2DRange(rsc, dstAlloc, dstXoff, dstYoff, |
| 330 | dstMip, dstFace, width, height, |
| 331 | srcAlloc, srcXoff, srcYoff, srcMip, srcFace); |
| 332 | } |
| 333 | |
Pirama Arumuga Nainar | 6b387c1 | 2015-10-12 14:06:57 -0700 | [diff] [blame] | 334 | RsElement rsrElementCreate(Context *rsc, RsDataType dt, RsDataKind dk, |
| 335 | bool norm, uint32_t vecSize) { |
Yang Ni | cc1b09f | 2016-03-08 20:59:21 +0000 | [diff] [blame] | 336 | return rsi_ElementCreate(rsc, dt, dk, norm, vecSize); |
Pirama Arumuga Nainar | 6b387c1 | 2015-10-12 14:06:57 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | RsType rsrTypeCreate(Context *rsc, const RsElement element, uint32_t dimX, |
| 340 | uint32_t dimY, uint32_t dimZ, bool mipmaps, bool faces, |
| 341 | uint32_t yuv) { |
Yang Ni | cc1b09f | 2016-03-08 20:59:21 +0000 | [diff] [blame] | 342 | return rsi_TypeCreate(rsc, element, dimX, dimY, dimZ, mipmaps, faces, yuv); |
Pirama Arumuga Nainar | 6b387c1 | 2015-10-12 14:06:57 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | RsAllocation rsrAllocationCreateTyped(Context *rsc, const RsType type, |
| 346 | RsAllocationMipmapControl mipmaps, |
| 347 | uint32_t usages, uintptr_t ptr) { |
Yang Ni | cc1b09f | 2016-03-08 20:59:21 +0000 | [diff] [blame] | 348 | return rsi_AllocationCreateTyped(rsc, type, mipmaps, usages, ptr); |
Pirama Arumuga Nainar | 6b387c1 | 2015-10-12 14:06:57 -0700 | [diff] [blame] | 349 | } |
Jason Sams | 693080e | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 350 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 351 | } // namespace renderscript |
| 352 | } // namespace android |