Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 4cbe25a | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 2 | * Copyright (C) 2011-2012 The Android Open Source Project |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -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 | |
Jason Sams | d1516df | 2015-05-05 18:00:34 -0700 | [diff] [blame] | 17 | #define LOG_TAG "RenderScript_jni" |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 18 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | #include <stdio.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <unistd.h> |
| 23 | #include <math.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 24 | #include <utils/misc.h> |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 25 | #include <inttypes.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 27 | #include <androidfw/Asset.h> |
| 28 | #include <androidfw/AssetManager.h> |
| 29 | #include <androidfw/ResourceTypes.h> |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 30 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | #include "jni.h" |
| 32 | #include "JNIHelp.h" |
| 33 | #include "android_runtime/AndroidRuntime.h" |
Jim Miller | ee95605 | 2010-08-19 18:56:00 -0700 | [diff] [blame] | 34 | #include "android_runtime/android_view_Surface.h" |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 35 | #include "android_runtime/android_util_AssetManager.h" |
John Reck | f4faeac | 2015-03-05 13:50:31 -0800 | [diff] [blame] | 36 | #include "android/graphics/GraphicsJNI.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | |
Jason Sams | 1d6983a | 2012-02-16 16:07:49 -0800 | [diff] [blame] | 38 | #include <rs.h> |
| 39 | #include <rsEnv.h> |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 40 | #include <gui/Surface.h> |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 41 | #include <gui/GLConsumer.h> |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 42 | #include <android_runtime/android_graphics_SurfaceTexture.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 43 | |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 44 | //#define LOG_API ALOGE |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 45 | static constexpr bool kLogApi = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | |
| 47 | using namespace android; |
| 48 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 49 | template <typename... T> |
| 50 | void UNUSED(T... t) {} |
| 51 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 52 | #define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 53 | jint len = 0; \ |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 54 | void *ptr = nullptr; \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 55 | void *srcPtr = nullptr; \ |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 56 | size_t typeBytes = 0; \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 57 | jint relFlag = 0; \ |
| 58 | if (readonly) { \ |
| 59 | /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 60 | /* readonly = true, also indicates we are copying to the allocation . */ \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 61 | relFlag = JNI_ABORT; \ |
| 62 | } \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 63 | switch(dataType) { \ |
| 64 | case RS_TYPE_FLOAT_32: \ |
| 65 | len = _env->GetArrayLength((jfloatArray)data); \ |
| 66 | ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \ |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 67 | if (ptr == nullptr) { \ |
| 68 | ALOGE("Failed to get Java array elements."); \ |
| 69 | return; \ |
| 70 | } \ |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 71 | typeBytes = 4; \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 72 | if (usePadding) { \ |
| 73 | srcPtr = ptr; \ |
| 74 | len = len / 3 * 4; \ |
| 75 | if (count == 0) { \ |
| 76 | count = len / 4; \ |
| 77 | } \ |
| 78 | ptr = malloc (len * typeBytes); \ |
| 79 | if (readonly) { \ |
| 80 | copyWithPadding(ptr, srcPtr, mSize, count); \ |
| 81 | fnc(__VA_ARGS__); \ |
| 82 | } else { \ |
| 83 | fnc(__VA_ARGS__); \ |
| 84 | copyWithUnPadding(srcPtr, ptr, mSize, count); \ |
| 85 | } \ |
| 86 | free(ptr); \ |
| 87 | ptr = srcPtr; \ |
| 88 | } else { \ |
| 89 | fnc(__VA_ARGS__); \ |
| 90 | } \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 91 | _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 92 | return; \ |
| 93 | case RS_TYPE_FLOAT_64: \ |
| 94 | len = _env->GetArrayLength((jdoubleArray)data); \ |
| 95 | ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \ |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 96 | if (ptr == nullptr) { \ |
| 97 | ALOGE("Failed to get Java array elements."); \ |
| 98 | return; \ |
| 99 | } \ |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 100 | typeBytes = 8; \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 101 | if (usePadding) { \ |
| 102 | srcPtr = ptr; \ |
| 103 | len = len / 3 * 4; \ |
| 104 | if (count == 0) { \ |
| 105 | count = len / 4; \ |
| 106 | } \ |
| 107 | ptr = malloc (len * typeBytes); \ |
| 108 | if (readonly) { \ |
| 109 | copyWithPadding(ptr, srcPtr, mSize, count); \ |
| 110 | fnc(__VA_ARGS__); \ |
| 111 | } else { \ |
| 112 | fnc(__VA_ARGS__); \ |
| 113 | copyWithUnPadding(srcPtr, ptr, mSize, count); \ |
| 114 | } \ |
| 115 | free(ptr); \ |
| 116 | ptr = srcPtr; \ |
| 117 | } else { \ |
| 118 | fnc(__VA_ARGS__); \ |
| 119 | } \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 120 | _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 121 | return; \ |
| 122 | case RS_TYPE_SIGNED_8: \ |
| 123 | case RS_TYPE_UNSIGNED_8: \ |
| 124 | len = _env->GetArrayLength((jbyteArray)data); \ |
| 125 | ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \ |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 126 | if (ptr == nullptr) { \ |
| 127 | ALOGE("Failed to get Java array elements."); \ |
| 128 | return; \ |
| 129 | } \ |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 130 | typeBytes = 1; \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 131 | if (usePadding) { \ |
| 132 | srcPtr = ptr; \ |
| 133 | len = len / 3 * 4; \ |
| 134 | if (count == 0) { \ |
| 135 | count = len / 4; \ |
| 136 | } \ |
| 137 | ptr = malloc (len * typeBytes); \ |
| 138 | if (readonly) { \ |
| 139 | copyWithPadding(ptr, srcPtr, mSize, count); \ |
| 140 | fnc(__VA_ARGS__); \ |
| 141 | } else { \ |
| 142 | fnc(__VA_ARGS__); \ |
| 143 | copyWithUnPadding(srcPtr, ptr, mSize, count); \ |
| 144 | } \ |
| 145 | free(ptr); \ |
| 146 | ptr = srcPtr; \ |
| 147 | } else { \ |
| 148 | fnc(__VA_ARGS__); \ |
| 149 | } \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 150 | _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 151 | return; \ |
| 152 | case RS_TYPE_SIGNED_16: \ |
| 153 | case RS_TYPE_UNSIGNED_16: \ |
Pirama Arumuga Nainar | 85e8c51 | 2016-03-01 20:37:19 -0800 | [diff] [blame] | 154 | case RS_TYPE_FLOAT_16: \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 155 | len = _env->GetArrayLength((jshortArray)data); \ |
| 156 | ptr = _env->GetShortArrayElements((jshortArray)data, flag); \ |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 157 | if (ptr == nullptr) { \ |
| 158 | ALOGE("Failed to get Java array elements."); \ |
| 159 | return; \ |
| 160 | } \ |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 161 | typeBytes = 2; \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 162 | if (usePadding) { \ |
| 163 | srcPtr = ptr; \ |
| 164 | len = len / 3 * 4; \ |
| 165 | if (count == 0) { \ |
| 166 | count = len / 4; \ |
| 167 | } \ |
| 168 | ptr = malloc (len * typeBytes); \ |
| 169 | if (readonly) { \ |
| 170 | copyWithPadding(ptr, srcPtr, mSize, count); \ |
| 171 | fnc(__VA_ARGS__); \ |
| 172 | } else { \ |
| 173 | fnc(__VA_ARGS__); \ |
| 174 | copyWithUnPadding(srcPtr, ptr, mSize, count); \ |
| 175 | } \ |
| 176 | free(ptr); \ |
| 177 | ptr = srcPtr; \ |
| 178 | } else { \ |
| 179 | fnc(__VA_ARGS__); \ |
| 180 | } \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 181 | _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 182 | return; \ |
| 183 | case RS_TYPE_SIGNED_32: \ |
| 184 | case RS_TYPE_UNSIGNED_32: \ |
| 185 | len = _env->GetArrayLength((jintArray)data); \ |
| 186 | ptr = _env->GetIntArrayElements((jintArray)data, flag); \ |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 187 | if (ptr == nullptr) { \ |
| 188 | ALOGE("Failed to get Java array elements."); \ |
| 189 | return; \ |
| 190 | } \ |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 191 | typeBytes = 4; \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 192 | if (usePadding) { \ |
| 193 | srcPtr = ptr; \ |
| 194 | len = len / 3 * 4; \ |
| 195 | if (count == 0) { \ |
| 196 | count = len / 4; \ |
| 197 | } \ |
| 198 | ptr = malloc (len * typeBytes); \ |
| 199 | if (readonly) { \ |
| 200 | copyWithPadding(ptr, srcPtr, mSize, count); \ |
| 201 | fnc(__VA_ARGS__); \ |
| 202 | } else { \ |
| 203 | fnc(__VA_ARGS__); \ |
| 204 | copyWithUnPadding(srcPtr, ptr, mSize, count); \ |
| 205 | } \ |
| 206 | free(ptr); \ |
| 207 | ptr = srcPtr; \ |
| 208 | } else { \ |
| 209 | fnc(__VA_ARGS__); \ |
| 210 | } \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 211 | _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 212 | return; \ |
| 213 | case RS_TYPE_SIGNED_64: \ |
| 214 | case RS_TYPE_UNSIGNED_64: \ |
| 215 | len = _env->GetArrayLength((jlongArray)data); \ |
| 216 | ptr = _env->GetLongArrayElements((jlongArray)data, flag); \ |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 217 | if (ptr == nullptr) { \ |
| 218 | ALOGE("Failed to get Java array elements."); \ |
| 219 | return; \ |
| 220 | } \ |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 221 | typeBytes = 8; \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 222 | if (usePadding) { \ |
| 223 | srcPtr = ptr; \ |
| 224 | len = len / 3 * 4; \ |
| 225 | if (count == 0) { \ |
| 226 | count = len / 4; \ |
| 227 | } \ |
| 228 | ptr = malloc (len * typeBytes); \ |
| 229 | if (readonly) { \ |
| 230 | copyWithPadding(ptr, srcPtr, mSize, count); \ |
| 231 | fnc(__VA_ARGS__); \ |
| 232 | } else { \ |
| 233 | fnc(__VA_ARGS__); \ |
| 234 | copyWithUnPadding(srcPtr, ptr, mSize, count); \ |
| 235 | } \ |
| 236 | free(ptr); \ |
| 237 | ptr = srcPtr; \ |
| 238 | } else { \ |
| 239 | fnc(__VA_ARGS__); \ |
| 240 | } \ |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 241 | _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 242 | return; \ |
| 243 | default: \ |
| 244 | break; \ |
| 245 | } \ |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 246 | UNUSED(len, ptr, srcPtr, typeBytes, relFlag); \ |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 250 | class AutoJavaStringToUTF8 { |
| 251 | public: |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 252 | AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 253 | fCStr = env->GetStringUTFChars(str, nullptr); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 254 | fLength = env->GetStringUTFLength(str); |
| 255 | } |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 256 | ~AutoJavaStringToUTF8() { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 257 | fEnv->ReleaseStringUTFChars(fJStr, fCStr); |
| 258 | } |
| 259 | const char* c_str() const { return fCStr; } |
| 260 | jsize length() const { return fLength; } |
| 261 | |
| 262 | private: |
| 263 | JNIEnv* fEnv; |
| 264 | jstring fJStr; |
| 265 | const char* fCStr; |
| 266 | jsize fLength; |
| 267 | }; |
| 268 | |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 269 | class AutoJavaStringArrayToUTF8 { |
| 270 | public: |
| 271 | AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) |
| 272 | : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 273 | mCStrings = nullptr; |
| 274 | mSizeArray = nullptr; |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 275 | if (stringsLength > 0) { |
| 276 | mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); |
| 277 | mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); |
| 278 | for (jsize ct = 0; ct < stringsLength; ct ++) { |
| 279 | jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 280 | mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr); |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 281 | mSizeArray[ct] = mEnv->GetStringUTFLength(s); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | ~AutoJavaStringArrayToUTF8() { |
| 286 | for (jsize ct=0; ct < mStringsLength; ct++) { |
| 287 | jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); |
| 288 | mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); |
| 289 | } |
| 290 | free(mCStrings); |
| 291 | free(mSizeArray); |
| 292 | } |
| 293 | const char **c_str() const { return mCStrings; } |
| 294 | size_t *c_str_len() const { return mSizeArray; } |
| 295 | jsize length() const { return mStringsLength; } |
| 296 | |
| 297 | private: |
| 298 | JNIEnv *mEnv; |
| 299 | jobjectArray mStrings; |
| 300 | const char **mCStrings; |
| 301 | size_t *mSizeArray; |
| 302 | jsize mStringsLength; |
| 303 | }; |
| 304 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 305 | // --------------------------------------------------------------------------- |
| 306 | |
Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 307 | static jfieldID gContextId = 0; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 308 | |
| 309 | static void _nInit(JNIEnv *_env, jclass _this) |
| 310 | { |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 311 | gContextId = _env->GetFieldID(_this, "mContext", "J"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 314 | // --------------------------------------------------------------------------- |
| 315 | |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 316 | static void copyWithPadding(void* ptr, void* srcPtr, int mSize, int count) { |
| 317 | int sizeBytesPad = mSize * 4; |
| 318 | int sizeBytes = mSize * 3; |
| 319 | uint8_t *dst = static_cast<uint8_t *>(ptr); |
| 320 | uint8_t *src = static_cast<uint8_t *>(srcPtr); |
| 321 | for (int i = 0; i < count; i++) { |
| 322 | memcpy(dst, src, sizeBytes); |
| 323 | dst += sizeBytesPad; |
| 324 | src += sizeBytes; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | static void copyWithUnPadding(void* ptr, void* srcPtr, int mSize, int count) { |
| 329 | int sizeBytesPad = mSize * 4; |
| 330 | int sizeBytes = mSize * 3; |
| 331 | uint8_t *dst = static_cast<uint8_t *>(ptr); |
| 332 | uint8_t *src = static_cast<uint8_t *>(srcPtr); |
| 333 | for (int i = 0; i < count; i++) { |
| 334 | memcpy(dst, src, sizeBytes); |
| 335 | dst += sizeBytes; |
| 336 | src += sizeBytesPad; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | |
| 341 | // --------------------------------------------------------------------------- |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 342 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 343 | nContextFinish(JNIEnv *_env, jobject _this, jlong con) |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 344 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 345 | if (kLogApi) { |
| 346 | ALOGD("nContextFinish, con(%p)", (RsContext)con); |
| 347 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 348 | rsContextFinish((RsContext)con); |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 351 | static jlong |
| 352 | nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID, |
| 353 | jlong returnValue, jlongArray fieldIDArray, |
| 354 | jlongArray valueArray, jintArray sizeArray, |
| 355 | jlongArray depClosureArray, jlongArray depFieldIDArray) { |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 356 | jlong ret = 0; |
| 357 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 358 | jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr); |
| 359 | jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 360 | if (jFieldIDs == nullptr) { |
| 361 | ALOGE("Failed to get Java array elements: fieldIDs."); |
| 362 | return ret; |
| 363 | } |
| 364 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 365 | jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr); |
| 366 | jsize values_length = _env->GetArrayLength(valueArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 367 | if (jValues == nullptr) { |
| 368 | ALOGE("Failed to get Java array elements: values."); |
| 369 | return ret; |
| 370 | } |
| 371 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 372 | jint* jSizes = _env->GetIntArrayElements(sizeArray, nullptr); |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 373 | jsize sizes_length = _env->GetArrayLength(sizeArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 374 | if (jSizes == nullptr) { |
| 375 | ALOGE("Failed to get Java array elements: sizes."); |
| 376 | return ret; |
| 377 | } |
| 378 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 379 | jlong* jDepClosures = |
| 380 | _env->GetLongArrayElements(depClosureArray, nullptr); |
| 381 | jsize depClosures_length = _env->GetArrayLength(depClosureArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 382 | if (jDepClosures == nullptr) { |
| 383 | ALOGE("Failed to get Java array elements: depClosures."); |
| 384 | return ret; |
| 385 | } |
| 386 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 387 | jlong* jDepFieldIDs = |
| 388 | _env->GetLongArrayElements(depFieldIDArray, nullptr); |
| 389 | jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 390 | if (jDepFieldIDs == nullptr) { |
| 391 | ALOGE("Failed to get Java array elements: depFieldIDs."); |
| 392 | return ret; |
| 393 | } |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 394 | |
| 395 | size_t numValues, numDependencies; |
| 396 | RsScriptFieldID* fieldIDs; |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 397 | RsClosure* depClosures; |
| 398 | RsScriptFieldID* depFieldIDs; |
| 399 | |
| 400 | if (fieldIDs_length != values_length || values_length != sizes_length) { |
| 401 | ALOGE("Unmatched field IDs, values, and sizes in closure creation."); |
| 402 | goto exit; |
| 403 | } |
| 404 | |
| 405 | numValues = (size_t)fieldIDs_length; |
| 406 | |
| 407 | if (depClosures_length != depFieldIDs_length) { |
| 408 | ALOGE("Unmatched closures and field IDs for dependencies in closure creation."); |
| 409 | goto exit; |
| 410 | } |
| 411 | |
| 412 | numDependencies = (size_t)depClosures_length; |
| 413 | |
| 414 | if (numDependencies > numValues) { |
| 415 | ALOGE("Unexpected number of dependencies in closure creation"); |
| 416 | goto exit; |
| 417 | } |
| 418 | |
Yang Ni | 7b2a46f | 2015-05-05 12:41:19 -0700 | [diff] [blame] | 419 | if (numValues > RS_CLOSURE_MAX_NUMBER_ARGS_AND_BINDINGS) { |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 420 | ALOGE("Too many arguments or globals in closure creation"); |
| 421 | goto exit; |
| 422 | } |
| 423 | |
| 424 | fieldIDs = (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * numValues); |
| 425 | if (fieldIDs == nullptr) { |
| 426 | goto exit; |
| 427 | } |
| 428 | |
| 429 | for (size_t i = 0; i < numValues; i++) { |
| 430 | fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i]; |
| 431 | } |
| 432 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 433 | depClosures = (RsClosure*)alloca(sizeof(RsClosure) * numDependencies); |
| 434 | if (depClosures == nullptr) { |
| 435 | goto exit; |
| 436 | } |
| 437 | |
| 438 | for (size_t i = 0; i < numDependencies; i++) { |
| 439 | depClosures[i] = (RsClosure)jDepClosures[i]; |
| 440 | } |
| 441 | |
| 442 | depFieldIDs = (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * numDependencies); |
| 443 | if (depFieldIDs == nullptr) { |
| 444 | goto exit; |
| 445 | } |
| 446 | |
| 447 | for (size_t i = 0; i < numDependencies; i++) { |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 448 | depFieldIDs[i] = (RsClosure)jDepFieldIDs[i]; |
| 449 | } |
| 450 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 451 | ret = (jlong)(uintptr_t)rsClosureCreate( |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 452 | (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue, |
Yang Ni | 263cc90 | 2015-11-10 13:27:04 -0800 | [diff] [blame] | 453 | fieldIDs, numValues, jValues, numValues, |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 454 | (int*)jSizes, numValues, |
| 455 | depClosures, numDependencies, |
| 456 | depFieldIDs, numDependencies); |
| 457 | |
| 458 | exit: |
| 459 | |
| 460 | _env->ReleaseLongArrayElements(depFieldIDArray, jDepFieldIDs, JNI_ABORT); |
| 461 | _env->ReleaseLongArrayElements(depClosureArray, jDepClosures, JNI_ABORT); |
| 462 | _env->ReleaseIntArrayElements (sizeArray, jSizes, JNI_ABORT); |
| 463 | _env->ReleaseLongArrayElements(valueArray, jValues, JNI_ABORT); |
| 464 | _env->ReleaseLongArrayElements(fieldIDArray, jFieldIDs, JNI_ABORT); |
| 465 | |
| 466 | return ret; |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 469 | static jlong |
| 470 | nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID, |
| 471 | jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray, |
| 472 | jintArray sizeArray) { |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 473 | jlong ret = 0; |
| 474 | |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 475 | jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr); |
| 476 | jsize jParamLength = _env->GetArrayLength(paramArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 477 | if (jParams == nullptr) { |
| 478 | ALOGE("Failed to get Java array elements: params."); |
| 479 | return ret; |
| 480 | } |
| 481 | |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 482 | jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr); |
| 483 | jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 484 | if (jFieldIDs == nullptr) { |
| 485 | ALOGE("Failed to get Java array elements: fieldIDs."); |
| 486 | return ret; |
| 487 | } |
| 488 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 489 | jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr); |
| 490 | jsize values_length = _env->GetArrayLength(valueArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 491 | if (jValues == nullptr) { |
| 492 | ALOGE("Failed to get Java array elements: values."); |
| 493 | return ret; |
| 494 | } |
| 495 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 496 | jint* jSizes = _env->GetIntArrayElements(sizeArray, nullptr); |
| 497 | jsize sizes_length = _env->GetArrayLength(sizeArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 498 | if (jSizes == nullptr) { |
| 499 | ALOGE("Failed to get Java array elements: sizes."); |
| 500 | return ret; |
| 501 | } |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 502 | |
| 503 | size_t numValues; |
| 504 | RsScriptFieldID* fieldIDs; |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 505 | |
| 506 | if (fieldIDs_length != values_length || values_length != sizes_length) { |
| 507 | ALOGE("Unmatched field IDs, values, and sizes in closure creation."); |
| 508 | goto exit; |
| 509 | } |
| 510 | |
| 511 | numValues = (size_t) fieldIDs_length; |
| 512 | |
Yang Ni | 7b2a46f | 2015-05-05 12:41:19 -0700 | [diff] [blame] | 513 | if (numValues > RS_CLOSURE_MAX_NUMBER_ARGS_AND_BINDINGS) { |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 514 | ALOGE("Too many arguments or globals in closure creation"); |
| 515 | goto exit; |
| 516 | } |
| 517 | |
| 518 | fieldIDs = (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * numValues); |
| 519 | if (fieldIDs == nullptr) { |
| 520 | goto exit; |
| 521 | } |
| 522 | |
| 523 | for (size_t i = 0; i< numValues; i++) { |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 524 | fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i]; |
| 525 | } |
| 526 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 527 | ret = (jlong)(uintptr_t)rsInvokeClosureCreate( |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 528 | (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength, |
Yang Ni | 263cc90 | 2015-11-10 13:27:04 -0800 | [diff] [blame] | 529 | fieldIDs, numValues, jValues, numValues, |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 530 | (int*)jSizes, numValues); |
| 531 | |
| 532 | exit: |
| 533 | |
| 534 | _env->ReleaseIntArrayElements (sizeArray, jSizes, JNI_ABORT); |
| 535 | _env->ReleaseLongArrayElements(valueArray, jValues, JNI_ABORT); |
| 536 | _env->ReleaseLongArrayElements(fieldIDArray, jFieldIDs, JNI_ABORT); |
| 537 | _env->ReleaseByteArrayElements(paramArray, jParams, JNI_ABORT); |
| 538 | |
| 539 | return ret; |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 542 | static void |
| 543 | nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID, |
| 544 | jint index, jlong value, jint size) { |
Yang Ni | 263cc90 | 2015-11-10 13:27:04 -0800 | [diff] [blame] | 545 | // Size is signed with -1 indicating the value is an Allocation |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 546 | rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index, |
Yang Ni | 263cc90 | 2015-11-10 13:27:04 -0800 | [diff] [blame] | 547 | (uintptr_t)value, size); |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void |
| 551 | nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID, |
| 552 | jlong fieldID, jlong value, jint size) { |
Yang Ni | 263cc90 | 2015-11-10 13:27:04 -0800 | [diff] [blame] | 553 | // Size is signed with -1 indicating the value is an Allocation |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 554 | rsClosureSetGlobal((RsContext)con, (RsClosure)closureID, |
Yang Ni | 263cc90 | 2015-11-10 13:27:04 -0800 | [diff] [blame] | 555 | (RsScriptFieldID)fieldID, (int64_t)value, size); |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static long |
Yang Ni | 35be56c | 2015-04-02 17:47:56 -0700 | [diff] [blame] | 559 | nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, jstring name, |
Yang Ni | ebf6340 | 2015-01-16 11:06:26 -0800 | [diff] [blame] | 560 | jstring cacheDir, jlongArray closureArray) { |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 561 | jlong ret = 0; |
| 562 | |
Yang Ni | 35be56c | 2015-04-02 17:47:56 -0700 | [diff] [blame] | 563 | AutoJavaStringToUTF8 nameUTF(_env, name); |
Yang Ni | ebf6340 | 2015-01-16 11:06:26 -0800 | [diff] [blame] | 564 | AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); |
| 565 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 566 | jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr); |
| 567 | jsize numClosures = _env->GetArrayLength(closureArray); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 568 | if (jClosures == nullptr) { |
| 569 | ALOGE("Failed to get Java array elements: closures."); |
| 570 | return ret; |
| 571 | } |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 572 | |
| 573 | RsClosure* closures; |
| 574 | |
Yang Ni | 7b2a46f | 2015-05-05 12:41:19 -0700 | [diff] [blame] | 575 | if (numClosures > (jsize) RS_SCRIPT_GROUP_MAX_NUMBER_CLOSURES) { |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 576 | ALOGE("Too many closures in script group"); |
| 577 | goto exit; |
| 578 | } |
| 579 | |
| 580 | closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures); |
| 581 | if (closures == nullptr) { |
| 582 | goto exit; |
| 583 | } |
| 584 | |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 585 | for (int i = 0; i < numClosures; i++) { |
| 586 | closures[i] = (RsClosure)jClosures[i]; |
| 587 | } |
| 588 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 589 | ret = (jlong)(uintptr_t)rsScriptGroup2Create( |
Yang Ni | 35be56c | 2015-04-02 17:47:56 -0700 | [diff] [blame] | 590 | (RsContext)con, nameUTF.c_str(), nameUTF.length(), |
| 591 | cacheDirUTF.c_str(), cacheDirUTF.length(), |
Yang Ni | ebf6340 | 2015-01-16 11:06:26 -0800 | [diff] [blame] | 592 | closures, numClosures); |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 593 | |
| 594 | exit: |
| 595 | |
| 596 | _env->ReleaseLongArrayElements(closureArray, jClosures, JNI_ABORT); |
| 597 | |
| 598 | return ret; |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static void |
| 602 | nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) { |
| 603 | rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID); |
| 604 | } |
| 605 | |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 606 | static void |
Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 607 | nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, |
| 608 | jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, |
| 609 | jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY, |
| 610 | jint KL, jint KU) { |
| 611 | RsBlasCall call; |
| 612 | memset(&call, 0, sizeof(call)); |
| 613 | call.func = (RsBlasFunction)func; |
| 614 | call.transA = (RsBlasTranspose)TransA; |
| 615 | call.transB = (RsBlasTranspose)TransB; |
| 616 | call.side = (RsBlasSide)Side; |
| 617 | call.uplo = (RsBlasUplo)Uplo; |
| 618 | call.diag = (RsBlasDiag)Diag; |
| 619 | call.M = M; |
| 620 | call.N = N; |
| 621 | call.K = K; |
| 622 | call.alpha.f = alpha; |
| 623 | call.beta.f = beta; |
| 624 | call.incX = incX; |
| 625 | call.incY = incY; |
| 626 | call.KL = KL; |
| 627 | call.KU = KU; |
| 628 | |
| 629 | RsAllocation in_allocs[3]; |
| 630 | in_allocs[0] = (RsAllocation)A; |
| 631 | in_allocs[1] = (RsAllocation)B; |
| 632 | in_allocs[2] = (RsAllocation)C; |
| 633 | |
| 634 | rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, |
| 635 | in_allocs, sizeof(in_allocs), nullptr, |
| 636 | &call, sizeof(call), nullptr, 0); |
| 637 | } |
| 638 | |
| 639 | static void |
| 640 | nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, |
| 641 | jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, |
| 642 | jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY, |
| 643 | jint KL, jint KU) { |
| 644 | RsBlasCall call; |
| 645 | memset(&call, 0, sizeof(call)); |
| 646 | call.func = (RsBlasFunction)func; |
| 647 | call.transA = (RsBlasTranspose)TransA; |
| 648 | call.transB = (RsBlasTranspose)TransB; |
| 649 | call.side = (RsBlasSide)Side; |
| 650 | call.uplo = (RsBlasUplo)Uplo; |
| 651 | call.diag = (RsBlasDiag)Diag; |
| 652 | call.M = M; |
| 653 | call.N = N; |
| 654 | call.K = K; |
| 655 | call.alpha.d = alpha; |
| 656 | call.beta.d = beta; |
| 657 | call.incX = incX; |
| 658 | call.incY = incY; |
| 659 | call.KL = KL; |
| 660 | call.KU = KU; |
| 661 | |
| 662 | RsAllocation in_allocs[3]; |
| 663 | in_allocs[0] = (RsAllocation)A; |
| 664 | in_allocs[1] = (RsAllocation)B; |
| 665 | in_allocs[2] = (RsAllocation)C; |
| 666 | |
| 667 | rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, |
Miao Wang | 0b34f2a | 2015-09-30 15:38:07 -0700 | [diff] [blame] | 668 | in_allocs, NELEM(in_allocs), nullptr, |
Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 669 | &call, sizeof(call), nullptr, 0); |
| 670 | } |
| 671 | |
| 672 | static void |
| 673 | nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, |
| 674 | jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, |
| 675 | jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX, |
| 676 | jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) { |
| 677 | RsBlasCall call; |
| 678 | memset(&call, 0, sizeof(call)); |
| 679 | call.func = (RsBlasFunction)func; |
| 680 | call.transA = (RsBlasTranspose)TransA; |
| 681 | call.transB = (RsBlasTranspose)TransB; |
| 682 | call.side = (RsBlasSide)Side; |
| 683 | call.uplo = (RsBlasUplo)Uplo; |
| 684 | call.diag = (RsBlasDiag)Diag; |
| 685 | call.M = M; |
| 686 | call.N = N; |
| 687 | call.K = K; |
| 688 | call.alpha.c.r = alphaX; |
| 689 | call.alpha.c.i = alphaY; |
| 690 | call.beta.c.r = betaX; |
Miao Wang | 82585b3 | 2015-04-30 13:44:49 -0700 | [diff] [blame] | 691 | call.beta.c.i = betaY; |
Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 692 | call.incX = incX; |
| 693 | call.incY = incY; |
| 694 | call.KL = KL; |
| 695 | call.KU = KU; |
| 696 | |
| 697 | RsAllocation in_allocs[3]; |
| 698 | in_allocs[0] = (RsAllocation)A; |
| 699 | in_allocs[1] = (RsAllocation)B; |
| 700 | in_allocs[2] = (RsAllocation)C; |
| 701 | |
| 702 | rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, |
Miao Wang | 0b34f2a | 2015-09-30 15:38:07 -0700 | [diff] [blame] | 703 | in_allocs, NELEM(in_allocs), nullptr, |
Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 704 | &call, sizeof(call), nullptr, 0); |
| 705 | } |
| 706 | |
| 707 | static void |
| 708 | nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, |
| 709 | jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, |
| 710 | jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX, |
| 711 | jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) { |
| 712 | RsBlasCall call; |
| 713 | memset(&call, 0, sizeof(call)); |
| 714 | call.func = (RsBlasFunction)func; |
| 715 | call.transA = (RsBlasTranspose)TransA; |
| 716 | call.transB = (RsBlasTranspose)TransB; |
| 717 | call.side = (RsBlasSide)Side; |
| 718 | call.uplo = (RsBlasUplo)Uplo; |
| 719 | call.diag = (RsBlasDiag)Diag; |
| 720 | call.M = M; |
| 721 | call.N = N; |
| 722 | call.K = K; |
| 723 | call.alpha.z.r = alphaX; |
| 724 | call.alpha.z.i = alphaY; |
| 725 | call.beta.z.r = betaX; |
Miao Wang | 82585b3 | 2015-04-30 13:44:49 -0700 | [diff] [blame] | 726 | call.beta.z.i = betaY; |
Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 727 | call.incX = incX; |
| 728 | call.incY = incY; |
| 729 | call.KL = KL; |
| 730 | call.KU = KU; |
| 731 | |
| 732 | RsAllocation in_allocs[3]; |
| 733 | in_allocs[0] = (RsAllocation)A; |
| 734 | in_allocs[1] = (RsAllocation)B; |
| 735 | in_allocs[2] = (RsAllocation)C; |
| 736 | |
| 737 | rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, |
Miao Wang | 0b34f2a | 2015-09-30 15:38:07 -0700 | [diff] [blame] | 738 | in_allocs, NELEM(in_allocs), nullptr, |
Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 739 | &call, sizeof(call), nullptr, 0); |
| 740 | } |
| 741 | |
| 742 | |
| 743 | static void |
Tim Murray | 9cb16a2 | 2015-04-01 11:07:16 -0700 | [diff] [blame] | 744 | nScriptIntrinsicBLAS_BNNM(JNIEnv *_env, jobject _this, jlong con, jlong id, jint M, jint N, jint K, |
| 745 | jlong A, jint a_offset, jlong B, jint b_offset, jlong C, jint c_offset, |
| 746 | jint c_mult_int) { |
| 747 | RsBlasCall call; |
| 748 | memset(&call, 0, sizeof(call)); |
| 749 | call.func = RsBlas_bnnm; |
| 750 | call.M = M; |
| 751 | call.N = N; |
| 752 | call.K = K; |
Miao Wang | 2514806 | 2015-06-29 17:43:03 -0700 | [diff] [blame] | 753 | call.a_offset = a_offset & 0xFF; |
| 754 | call.b_offset = b_offset & 0xFF; |
Tim Murray | 9cb16a2 | 2015-04-01 11:07:16 -0700 | [diff] [blame] | 755 | call.c_offset = c_offset; |
| 756 | call.c_mult_int = c_mult_int; |
| 757 | |
| 758 | RsAllocation in_allocs[3]; |
| 759 | in_allocs[0] = (RsAllocation)A; |
| 760 | in_allocs[1] = (RsAllocation)B; |
| 761 | in_allocs[2] = (RsAllocation)C; |
| 762 | |
| 763 | rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, |
Miao Wang | 0b34f2a | 2015-09-30 15:38:07 -0700 | [diff] [blame] | 764 | in_allocs, NELEM(in_allocs), nullptr, |
Tim Murray | 9cb16a2 | 2015-04-01 11:07:16 -0700 | [diff] [blame] | 765 | &call, sizeof(call), nullptr, 0); |
| 766 | } |
| 767 | |
| 768 | |
| 769 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 770 | nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str) |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 771 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 772 | if (kLogApi) { |
| 773 | ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj); |
| 774 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 775 | jint len = _env->GetArrayLength(str); |
| 776 | jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 777 | if (cptr == nullptr) { |
| 778 | ALOGE("Failed to get Java array elements"); |
| 779 | return; |
| 780 | } |
| 781 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 782 | rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 783 | _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); |
| 784 | } |
| 785 | |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 786 | static jstring |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 787 | nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj) |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 788 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 789 | if (kLogApi) { |
| 790 | ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj); |
| 791 | } |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 792 | const char *name = nullptr; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 793 | rsaGetName((RsContext)con, (void *)obj, &name); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 794 | if(name == nullptr || strlen(name) == 0) { |
| 795 | return nullptr; |
Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 796 | } |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 797 | return _env->NewStringUTF(name); |
| 798 | } |
| 799 | |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 800 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 801 | nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj) |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 802 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 803 | if (kLogApi) { |
| 804 | ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj); |
| 805 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 806 | rsObjDestroy((RsContext)con, (void *)obj); |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 809 | // --------------------------------------------------------------------------- |
| 810 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 811 | static jlong |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 812 | nDeviceCreate(JNIEnv *_env, jobject _this) |
| 813 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 814 | if (kLogApi) { |
| 815 | ALOGD("nDeviceCreate"); |
| 816 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 817 | return (jlong)(uintptr_t)rsDeviceCreate(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static void |
Tim Murray | 5eaf468 | 2014-01-10 11:25:52 -0800 | [diff] [blame] | 821 | nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 822 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 823 | if (kLogApi) { |
| 824 | ALOGD("nDeviceDestroy"); |
| 825 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 826 | return rsDeviceDestroy((RsDevice)dev); |
| 827 | } |
| 828 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 829 | static void |
Tim Murray | 5eaf468 | 2014-01-10 11:25:52 -0800 | [diff] [blame] | 830 | nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value) |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 831 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 832 | if (kLogApi) { |
| 833 | ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); |
| 834 | } |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 835 | return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); |
| 836 | } |
| 837 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 838 | static jlong |
Jason Sams | 81cd2b1 | 2014-12-02 12:36:43 -0800 | [diff] [blame] | 839 | nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 840 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 841 | if (kLogApi) { |
| 842 | ALOGD("nContextCreate"); |
| 843 | } |
Jason Sams | 81cd2b1 | 2014-12-02 12:36:43 -0800 | [diff] [blame] | 844 | return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 847 | static jlong |
Tim Murray | 5eaf468 | 2014-01-10 11:25:52 -0800 | [diff] [blame] | 848 | nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 849 | jint colorMin, jint colorPref, |
| 850 | jint alphaMin, jint alphaPref, |
| 851 | jint depthMin, jint depthPref, |
| 852 | jint stencilMin, jint stencilPref, |
| 853 | jint samplesMin, jint samplesPref, jfloat samplesQ, |
| 854 | jint dpi) |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 855 | { |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 856 | RsSurfaceConfig sc; |
| 857 | sc.alphaMin = alphaMin; |
| 858 | sc.alphaPref = alphaPref; |
| 859 | sc.colorMin = colorMin; |
| 860 | sc.colorPref = colorPref; |
| 861 | sc.depthMin = depthMin; |
| 862 | sc.depthPref = depthPref; |
| 863 | sc.samplesMin = samplesMin; |
| 864 | sc.samplesPref = samplesPref; |
| 865 | sc.samplesQ = samplesQ; |
| 866 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 867 | if (kLogApi) { |
| 868 | ALOGD("nContextCreateGL"); |
| 869 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 870 | return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 874 | nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p) |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 875 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 876 | if (kLogApi) { |
| 877 | ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p); |
| 878 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 879 | rsContextSetPriority((RsContext)con, p); |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 880 | } |
| 881 | |
Tim Murray | 47f3158 | 2015-04-07 15:43:24 -0700 | [diff] [blame] | 882 | static void |
| 883 | nContextSetCacheDir(JNIEnv *_env, jobject _this, jlong con, jstring cacheDir) |
| 884 | { |
| 885 | AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); |
| 886 | |
| 887 | if (kLogApi) { |
| 888 | ALOGD("ContextSetCacheDir, con(%p), cacheDir(%s)", (RsContext)con, cacheDirUTF.c_str()); |
| 889 | } |
| 890 | rsContextSetCacheDir((RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length()); |
| 891 | } |
| 892 | |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 893 | |
| 894 | |
| 895 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 896 | nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd) |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 897 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 898 | if (kLogApi) { |
| 899 | ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, |
| 900 | width, height, (Surface *)wnd); |
| 901 | } |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 902 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 903 | ANativeWindow * window = nullptr; |
| 904 | if (wnd == nullptr) { |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 905 | |
| 906 | } else { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 907 | window = android_view_Surface_getNativeWindow(_env, wnd).get(); |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 908 | } |
| 909 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 910 | rsContextSetSurface((RsContext)con, width, height, window); |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 914 | nContextDestroy(JNIEnv *_env, jobject _this, jlong con) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 915 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 916 | if (kLogApi) { |
| 917 | ALOGD("nContextDestroy, con(%p)", (RsContext)con); |
| 918 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 919 | rsContextDestroy((RsContext)con); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 922 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 923 | nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits) |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 924 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 925 | if (kLogApi) { |
| 926 | ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); |
| 927 | } |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 928 | rsContextDump((RsContext)con, bits); |
| 929 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 930 | |
| 931 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 932 | nContextPause(JNIEnv *_env, jobject _this, jlong con) |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 933 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 934 | if (kLogApi) { |
| 935 | ALOGD("nContextPause, con(%p)", (RsContext)con); |
| 936 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 937 | rsContextPause((RsContext)con); |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 941 | nContextResume(JNIEnv *_env, jobject _this, jlong con) |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 942 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 943 | if (kLogApi) { |
| 944 | ALOGD("nContextResume, con(%p)", (RsContext)con); |
| 945 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 946 | rsContextResume((RsContext)con); |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 949 | |
| 950 | static jstring |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 951 | nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con) |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 952 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 953 | if (kLogApi) { |
| 954 | ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con); |
| 955 | } |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 956 | char buf[1024]; |
| 957 | |
| 958 | size_t receiveLen; |
| 959 | uint32_t subID; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 960 | int id = rsContextGetMessage((RsContext)con, |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 961 | buf, sizeof(buf), |
| 962 | &receiveLen, sizeof(receiveLen), |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 963 | &subID, sizeof(subID)); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 964 | if (!id && receiveLen) { |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 965 | ALOGV("message receive buffer too small. %zu", receiveLen); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 966 | } |
| 967 | return _env->NewStringUTF(buf); |
| 968 | } |
| 969 | |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 970 | static jint |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 971 | nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 972 | { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 973 | jint len = _env->GetArrayLength(data); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 974 | if (kLogApi) { |
| 975 | ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len); |
| 976 | } |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 977 | jint *ptr = _env->GetIntArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 978 | if (ptr == nullptr) { |
| 979 | ALOGE("Failed to get Java array elements"); |
| 980 | return 0; |
| 981 | } |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 982 | size_t receiveLen; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 983 | uint32_t subID; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 984 | int id = rsContextGetMessage((RsContext)con, |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 985 | ptr, len * 4, |
| 986 | &receiveLen, sizeof(receiveLen), |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 987 | &subID, sizeof(subID)); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 988 | if (!id && receiveLen) { |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 989 | ALOGV("message receive buffer too small. %zu", receiveLen); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 990 | } |
| 991 | _env->ReleaseIntArrayElements(data, ptr, 0); |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 992 | return (jint)id; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | static jint |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 996 | nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData) |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 997 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 998 | if (kLogApi) { |
| 999 | ALOGD("nContextPeekMessage, con(%p)", (RsContext)con); |
| 1000 | } |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1001 | jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1002 | if (auxDataPtr == nullptr) { |
| 1003 | ALOGE("Failed to get Java array elements"); |
| 1004 | return 0; |
| 1005 | } |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1006 | size_t receiveLen; |
| 1007 | uint32_t subID; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1008 | int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen), |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 1009 | &subID, sizeof(subID)); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1010 | auxDataPtr[0] = (jint)subID; |
| 1011 | auxDataPtr[1] = (jint)receiveLen; |
| 1012 | _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1013 | return (jint)id; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1016 | static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con) |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1017 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1018 | if (kLogApi) { |
| 1019 | ALOGD("nContextInitToClient, con(%p)", (RsContext)con); |
| 1020 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1021 | rsContextInitToClient((RsContext)con); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1024 | static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con) |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1025 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1026 | if (kLogApi) { |
| 1027 | ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con); |
| 1028 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1029 | rsContextDeinitToClient((RsContext)con); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1032 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1033 | nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data) |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1034 | { |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1035 | jint *ptr = nullptr; |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1036 | jint len = 0; |
| 1037 | if (data) { |
| 1038 | len = _env->GetArrayLength(data); |
Stephen Hines | 4a043c1 | 2014-08-21 23:20:32 -0700 | [diff] [blame] | 1039 | ptr = _env->GetIntArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1040 | if (ptr == nullptr) { |
| 1041 | ALOGE("Failed to get Java array elements"); |
| 1042 | return; |
| 1043 | } |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1044 | } |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1045 | if (kLogApi) { |
| 1046 | ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); |
| 1047 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1048 | rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int)); |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1049 | if (data) { |
| 1050 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1055 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1056 | static jlong |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1057 | nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, |
| 1058 | jint size) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1059 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1060 | if (kLogApi) { |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 1061 | ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con, |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1062 | type, kind, norm, size); |
| 1063 | } |
| 1064 | return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, |
Yang Ni | 3f3965e | 2016-03-08 20:59:48 +0000 | [diff] [blame] | 1065 | norm, size); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1068 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1069 | nElementCreate2(JNIEnv *_env, jobject _this, jlong con, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1070 | jlongArray _ids, jobjectArray _names, jintArray _arraySizes) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1071 | { |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1072 | int fieldCount = _env->GetArrayLength(_ids); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1073 | if (kLogApi) { |
| 1074 | ALOGD("nElementCreate2, con(%p)", (RsContext)con); |
| 1075 | } |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1076 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1077 | jlong *jIds = _env->GetLongArrayElements(_ids, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1078 | if (jIds == nullptr) { |
| 1079 | ALOGE("Failed to get Java array elements: ids"); |
| 1080 | return 0; |
| 1081 | } |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1082 | jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1083 | if (jArraySizes == nullptr) { |
| 1084 | ALOGE("Failed to get Java array elements: arraySizes"); |
| 1085 | return 0; |
| 1086 | } |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1087 | |
| 1088 | RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement)); |
| 1089 | uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t)); |
| 1090 | |
| 1091 | for(int i = 0; i < fieldCount; i ++) { |
| 1092 | ids[i] = (RsElement)jIds[i]; |
| 1093 | arraySizes[i] = (uint32_t)jArraySizes[i]; |
| 1094 | } |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1095 | |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 1096 | AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); |
| 1097 | |
| 1098 | const char **nameArray = names.c_str(); |
| 1099 | size_t *sizeArray = names.c_str_len(); |
| 1100 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1101 | jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1102 | (const RsElement *)ids, fieldCount, |
Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 1103 | nameArray, fieldCount * sizeof(size_t), sizeArray, |
Yang Ni | 3f3965e | 2016-03-08 20:59:48 +0000 | [diff] [blame] | 1104 | (const uint32_t *)arraySizes, fieldCount); |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 1105 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1106 | free(ids); |
| 1107 | free(arraySizes); |
| 1108 | _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT); |
| 1109 | _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT); |
| 1110 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1111 | return (jlong)(uintptr_t)id; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1114 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1115 | nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData) |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1116 | { |
| 1117 | int dataSize = _env->GetArrayLength(_elementData); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1118 | if (kLogApi) { |
| 1119 | ALOGD("nElementGetNativeData, con(%p)", (RsContext)con); |
| 1120 | } |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1121 | |
| 1122 | // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements |
| 1123 | assert(dataSize == 5); |
| 1124 | |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1125 | uintptr_t elementData[5]; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1126 | rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1127 | |
| 1128 | for(jint i = 0; i < dataSize; i ++) { |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1129 | const jint data = (jint)elementData[i]; |
| 1130 | _env->SetIntArrayRegion(_elementData, i, 1, &data); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | |
| 1135 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1136 | nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1137 | jlongArray _IDs, |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 1138 | jobjectArray _names, |
| 1139 | jintArray _arraySizes) |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1140 | { |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1141 | uint32_t dataSize = _env->GetArrayLength(_IDs); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1142 | if (kLogApi) { |
| 1143 | ALOGD("nElementGetSubElements, con(%p)", (RsContext)con); |
| 1144 | } |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1145 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1146 | uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t)); |
| 1147 | const char **names = (const char **)malloc(dataSize * sizeof(const char *)); |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1148 | uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t)); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1149 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1150 | rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, |
| 1151 | (uint32_t)dataSize); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1152 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1153 | for(uint32_t i = 0; i < dataSize; i++) { |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1154 | const jlong id = (jlong)(uintptr_t)ids[i]; |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1155 | const jint arraySize = (jint)arraySizes[i]; |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1156 | _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1157 | _env->SetLongArrayRegion(_IDs, i, 1, &id); |
| 1158 | _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | free(ids); |
| 1162 | free(names); |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 1163 | free(arraySizes); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1166 | // ----------------------------------- |
| 1167 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1168 | static jlong |
| 1169 | nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid, |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 1170 | jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1171 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1172 | if (kLogApi) { |
| 1173 | ALOGD("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 1174 | (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1175 | } |
Jason Sams | 3b9c52a | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 1176 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1177 | return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, |
Yang Ni | 3f3965e | 2016-03-08 20:59:48 +0000 | [diff] [blame] | 1178 | faces, yuv); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1181 | static void |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1182 | nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData) |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1183 | { |
| 1184 | // We are packing 6 items: mDimX; mDimY; mDimZ; |
| 1185 | // mDimLOD; mDimFaces; mElement; into typeData |
| 1186 | int elementCount = _env->GetArrayLength(_typeData); |
| 1187 | |
| 1188 | assert(elementCount == 6); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1189 | if (kLogApi) { |
| 1190 | ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con); |
| 1191 | } |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1192 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1193 | uintptr_t typeData[6]; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1194 | rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1195 | |
| 1196 | for(jint i = 0; i < elementCount; i ++) { |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1197 | const jlong data = (jlong)(uintptr_t)typeData[i]; |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1198 | _env->SetLongArrayRegion(_typeData, i, 1, &data); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1202 | // ----------------------------------- |
| 1203 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1204 | static jlong |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1205 | nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, |
| 1206 | jlong pointer) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1207 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1208 | if (kLogApi) { |
| 1209 | ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", |
| 1210 | (RsContext)con, (RsElement)type, mips, usage, (void *)pointer); |
| 1211 | } |
| 1212 | return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type, |
| 1213 | (RsAllocationMipmapControl)mips, |
Yang Ni | 3f3965e | 2016-03-08 20:59:48 +0000 | [diff] [blame] | 1214 | (uint32_t)usage, (uintptr_t)pointer); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1217 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1218 | nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits) |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1219 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1220 | if (kLogApi) { |
| 1221 | ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, |
| 1222 | bits); |
| 1223 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1224 | rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
Miao Wang | 8c15092 | 2015-10-26 17:44:10 -0700 | [diff] [blame] | 1227 | static void |
| 1228 | nAllocationSetupBufferQueue(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint numAlloc) |
| 1229 | { |
| 1230 | if (kLogApi) { |
| 1231 | ALOGD("nAllocationSetupBufferQueue, con(%p), alloc(%p), numAlloc(%d)", (RsContext)con, |
| 1232 | (RsAllocation)alloc, numAlloc); |
| 1233 | } |
| 1234 | rsAllocationSetupBufferQueue((RsContext)con, (RsAllocation)alloc, (uint32_t)numAlloc); |
| 1235 | } |
| 1236 | |
| 1237 | static void |
| 1238 | nAllocationShareBufferQueue(JNIEnv *_env, jobject _this, jlong con, jlong alloc1, jlong alloc2) |
| 1239 | { |
| 1240 | if (kLogApi) { |
| 1241 | ALOGD("nAllocationShareBufferQueue, con(%p), alloc1(%p), alloc2(%p)", (RsContext)con, |
| 1242 | (RsAllocation)alloc1, (RsAllocation)alloc2); |
| 1243 | } |
| 1244 | |
| 1245 | rsAllocationShareBufferQueue((RsContext)con, (RsAllocation)alloc1, (RsAllocation)alloc2); |
| 1246 | } |
| 1247 | |
Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 1248 | static jobject |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1249 | nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a) |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 1250 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1251 | if (kLogApi) { |
| 1252 | ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); |
| 1253 | } |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 1254 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1255 | IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, |
| 1256 | (RsAllocation)a); |
Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 1257 | sp<IGraphicBufferProducer> bp = v; |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1258 | v->decStrong(nullptr); |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 1259 | |
Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 1260 | jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp); |
| 1261 | return o; |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1265 | nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur) |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1266 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1267 | if (kLogApi) { |
| 1268 | ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con, |
| 1269 | (RsAllocation)alloc, (Surface *)sur); |
| 1270 | } |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1271 | |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1272 | sp<Surface> s; |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1273 | if (sur != 0) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 1274 | s = android_view_Surface_getSurface(_env, sur); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1277 | rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, |
| 1278 | static_cast<ANativeWindow *>(s.get())); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1282 | nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc) |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1283 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1284 | if (kLogApi) { |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 1285 | ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1286 | } |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1287 | rsAllocationIoSend((RsContext)con, (RsAllocation)alloc); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1288 | } |
| 1289 | |
Miao Wang | 8c15092 | 2015-10-26 17:44:10 -0700 | [diff] [blame] | 1290 | static jlong |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1291 | nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc) |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1292 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1293 | if (kLogApi) { |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 1294 | ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1295 | } |
Miao Wang | 8c15092 | 2015-10-26 17:44:10 -0700 | [diff] [blame] | 1296 | return (jlong) rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1299 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1300 | nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc) |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1301 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1302 | if (kLogApi) { |
| 1303 | ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc); |
| 1304 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1305 | rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc); |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1308 | static jlong |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1309 | nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, |
| 1310 | jobject jbitmap, jint usage) |
Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 1311 | { |
John Reck | ed207b9 | 2015-04-10 13:52:57 -0700 | [diff] [blame] | 1312 | SkBitmap bitmap; |
| 1313 | GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); |
Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 1314 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1315 | bitmap.lockPixels(); |
| 1316 | const void* ptr = bitmap.getPixels(); |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1317 | jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con, |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 1318 | (RsType)type, (RsAllocationMipmapControl)mip, |
Yang Ni | 3f3965e | 2016-03-08 20:59:48 +0000 | [diff] [blame] | 1319 | ptr, bitmap.getSize(), usage); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1320 | bitmap.unlockPixels(); |
| 1321 | return id; |
Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 1322 | } |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 1323 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1324 | static jlong |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1325 | nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, |
| 1326 | jint mip, jobject jbitmap, jint usage) |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 1327 | { |
John Reck | ed207b9 | 2015-04-10 13:52:57 -0700 | [diff] [blame] | 1328 | SkBitmap bitmap; |
| 1329 | GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 1330 | |
| 1331 | bitmap.lockPixels(); |
| 1332 | const void* ptr = bitmap.getPixels(); |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1333 | jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con, |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 1334 | (RsType)type, (RsAllocationMipmapControl)mip, |
Yang Ni | 3f3965e | 2016-03-08 20:59:48 +0000 | [diff] [blame] | 1335 | (uint32_t)usage, (uintptr_t)ptr); |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 1336 | bitmap.unlockPixels(); |
| 1337 | return id; |
| 1338 | } |
| 1339 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1340 | static jlong |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1341 | nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, |
| 1342 | jobject jbitmap, jint usage) |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1343 | { |
John Reck | ed207b9 | 2015-04-10 13:52:57 -0700 | [diff] [blame] | 1344 | SkBitmap bitmap; |
| 1345 | GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1346 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1347 | bitmap.lockPixels(); |
| 1348 | const void* ptr = bitmap.getPixels(); |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1349 | jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con, |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 1350 | (RsType)type, (RsAllocationMipmapControl)mip, |
Yang Ni | 3f3965e | 2016-03-08 20:59:48 +0000 | [diff] [blame] | 1351 | ptr, bitmap.getSize(), usage); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1352 | bitmap.unlockPixels(); |
| 1353 | return id; |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1354 | } |
| 1355 | |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 1356 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1357 | nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 1358 | { |
John Reck | ed207b9 | 2015-04-10 13:52:57 -0700 | [diff] [blame] | 1359 | SkBitmap bitmap; |
| 1360 | GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1361 | int w = bitmap.width(); |
| 1362 | int h = bitmap.height(); |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 1363 | |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1364 | bitmap.lockPixels(); |
| 1365 | const void* ptr = bitmap.getPixels(); |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1366 | rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1367 | 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
Tim Murray | 38faea3 | 2012-11-27 14:55:08 -0800 | [diff] [blame] | 1368 | w, h, ptr, bitmap.getSize(), 0); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1369 | bitmap.unlockPixels(); |
| 1370 | } |
| 1371 | |
| 1372 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1373 | nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1374 | { |
John Reck | ed207b9 | 2015-04-10 13:52:57 -0700 | [diff] [blame] | 1375 | SkBitmap bitmap; |
| 1376 | GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1377 | |
| 1378 | bitmap.lockPixels(); |
| 1379 | void* ptr = bitmap.getPixels(); |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1380 | rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize()); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1381 | bitmap.unlockPixels(); |
Alex Sakhartchouk | 835b854 | 2011-07-20 14:33:10 -0700 | [diff] [blame] | 1382 | bitmap.notifyPixelsChanged(); |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1385 | // Copies from the Java object data into the Allocation pointed to by _alloc. |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1386 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1387 | nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1388 | jint count, jobject data, jint sizeBytes, jint dataType, jint mSize, |
| 1389 | jboolean usePadding) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1390 | { |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 1391 | RsAllocation *alloc = (RsAllocation *)_alloc; |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1392 | if (kLogApi) { |
| 1393 | ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), " |
| 1394 | "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, |
| 1395 | dataType); |
| 1396 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1397 | PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, |
| 1398 | (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | static void |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1402 | nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc, |
| 1403 | jint xoff, jint yoff, jint zoff, |
| 1404 | jint lod, jint compIdx, jbyteArray data, jint sizeBytes) |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 1405 | { |
| 1406 | jint len = _env->GetArrayLength(data); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1407 | if (kLogApi) { |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1408 | ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), " |
| 1409 | "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len, |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1410 | sizeBytes); |
| 1411 | } |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1412 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1413 | if (ptr == nullptr) { |
| 1414 | ALOGE("Failed to get Java array elements"); |
| 1415 | return; |
| 1416 | } |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1417 | rsAllocationElementData((RsContext)con, (RsAllocation)alloc, |
| 1418 | xoff, yoff, zoff, |
| 1419 | lod, ptr, sizeBytes, compIdx); |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 1420 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1421 | } |
| 1422 | |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1423 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1424 | // Copies from the Java object data into the Allocation pointed to by _alloc. |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 1425 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1426 | nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1427 | jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize, |
| 1428 | jboolean usePadding) |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1429 | { |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 1430 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| 1431 | RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1432 | if (kLogApi) { |
| 1433 | ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) " |
| 1434 | "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); |
| 1435 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1436 | int count = w * h; |
| 1437 | PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true, |
| 1438 | (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1441 | // Copies from the Allocation pointed to by srcAlloc into the Allocation |
| 1442 | // pointed to by dstAlloc. |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1443 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1444 | nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1445 | jlong dstAlloc, jint dstXoff, jint dstYoff, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1446 | jint dstMip, jint dstFace, |
| 1447 | jint width, jint height, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1448 | jlong srcAlloc, jint srcXoff, jint srcYoff, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1449 | jint srcMip, jint srcFace) |
| 1450 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1451 | if (kLogApi) { |
| 1452 | ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," |
| 1453 | " dstMip(%i), dstFace(%i), width(%i), height(%i)," |
| 1454 | " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", |
| 1455 | (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, |
| 1456 | width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); |
| 1457 | } |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1458 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1459 | rsAllocationCopy2DRange((RsContext)con, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1460 | (RsAllocation)dstAlloc, |
| 1461 | dstXoff, dstYoff, |
| 1462 | dstMip, dstFace, |
| 1463 | width, height, |
| 1464 | (RsAllocation)srcAlloc, |
| 1465 | srcXoff, srcYoff, |
| 1466 | srcMip, srcFace); |
| 1467 | } |
| 1468 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1469 | // Copies from the Java object data into the Allocation pointed to by _alloc. |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1470 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1471 | nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1472 | jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType, |
| 1473 | jint mSize, jboolean usePadding) |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1474 | { |
Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 1475 | RsAllocation *alloc = (RsAllocation *)_alloc; |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1476 | if (kLogApi) { |
| 1477 | ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i)," |
| 1478 | " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, |
| 1479 | lod, w, h, d, sizeBytes); |
| 1480 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1481 | int count = w * h * d; |
| 1482 | PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true, |
| 1483 | (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1486 | // Copies from the Allocation pointed to by srcAlloc into the Allocation |
| 1487 | // pointed to by dstAlloc. |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1488 | static void |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1489 | nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1490 | jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff, |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1491 | jint dstMip, |
| 1492 | jint width, jint height, jint depth, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1493 | jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1494 | jint srcMip) |
| 1495 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1496 | if (kLogApi) { |
| 1497 | ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," |
| 1498 | " dstMip(%i), width(%i), height(%i)," |
| 1499 | " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", |
| 1500 | (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, |
| 1501 | width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip); |
| 1502 | } |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1503 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1504 | rsAllocationCopy3DRange((RsContext)con, |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1505 | (RsAllocation)dstAlloc, |
| 1506 | dstXoff, dstYoff, dstZoff, dstMip, |
| 1507 | width, height, depth, |
| 1508 | (RsAllocation)srcAlloc, |
| 1509 | srcXoff, srcYoff, srcZoff, srcMip); |
| 1510 | } |
| 1511 | |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 1512 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1513 | // Copies from the Allocation pointed to by _alloc into the Java object data. |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1514 | static void |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1515 | nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType, |
| 1516 | jint mSize, jboolean usePadding) |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1517 | { |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 1518 | RsAllocation *alloc = (RsAllocation *)_alloc; |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1519 | if (kLogApi) { |
| 1520 | ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); |
| 1521 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1522 | int count = 0; |
| 1523 | PER_ARRAY_TYPE(0, rsAllocationRead, false, |
| 1524 | (RsContext)con, alloc, ptr, len * typeBytes); |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1527 | // Copies from the Allocation pointed to by _alloc into the Java object data. |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1528 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1529 | nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1530 | jint count, jobject data, jint sizeBytes, jint dataType, |
| 1531 | jint mSize, jboolean usePadding) |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1532 | { |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 1533 | RsAllocation *alloc = (RsAllocation *)_alloc; |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1534 | if (kLogApi) { |
| 1535 | ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), " |
| 1536 | "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType); |
| 1537 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1538 | PER_ARRAY_TYPE(0, rsAllocation1DRead, false, |
| 1539 | (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1540 | } |
| 1541 | |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1542 | // Copies from the Element in the Allocation pointed to by _alloc into the Java array data. |
| 1543 | static void |
Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 1544 | nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc, |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1545 | jint xoff, jint yoff, jint zoff, |
Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 1546 | jint lod, jint compIdx, jbyteArray data, jint sizeBytes) |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1547 | { |
Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 1548 | jint len = _env->GetArrayLength(data); |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1549 | if (kLogApi) { |
Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 1550 | ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), " |
| 1551 | "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len, |
| 1552 | sizeBytes); |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1553 | } |
Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 1554 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1555 | if (ptr == nullptr) { |
| 1556 | ALOGE("Failed to get Java array elements"); |
| 1557 | return; |
| 1558 | } |
Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 1559 | rsAllocationElementRead((RsContext)con, (RsAllocation)alloc, |
| 1560 | xoff, yoff, zoff, |
Jason Sams | a7e2509 | 2015-03-11 11:00:00 -0700 | [diff] [blame] | 1561 | lod, ptr, sizeBytes, compIdx); |
Miao Wang | bfa5e65 | 2015-05-04 15:29:25 -0700 | [diff] [blame] | 1562 | _env->ReleaseByteArrayElements(data, ptr, 0); |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1563 | } |
| 1564 | |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1565 | // Copies from the Allocation pointed to by _alloc into the Java object data. |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1566 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1567 | nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1568 | jint w, jint h, jobject data, jint sizeBytes, jint dataType, |
| 1569 | jint mSize, jboolean usePadding) |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1570 | { |
Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 1571 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| 1572 | RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1573 | if (kLogApi) { |
| 1574 | ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) " |
| 1575 | "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); |
| 1576 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1577 | int count = w * h; |
| 1578 | PER_ARRAY_TYPE(0, rsAllocation2DRead, false, |
| 1579 | (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1580 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1581 | |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1582 | // Copies from the Allocation pointed to by _alloc into the Java object data. |
| 1583 | static void |
| 1584 | nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1585 | jint w, jint h, jint d, jobject data, int sizeBytes, int dataType, |
| 1586 | jint mSize, jboolean usePadding) |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1587 | { |
| 1588 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| 1589 | if (kLogApi) { |
| 1590 | ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i)," |
| 1591 | " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, |
| 1592 | lod, w, h, d, sizeBytes); |
| 1593 | } |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 1594 | int count = w * h * d; |
| 1595 | PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false, |
| 1596 | (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 1597 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1598 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1599 | static jlong |
| 1600 | nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a) |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1601 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1602 | if (kLogApi) { |
| 1603 | ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); |
| 1604 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1605 | return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 1608 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1609 | nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX) |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 1610 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1611 | if (kLogApi) { |
| 1612 | ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, |
| 1613 | (RsAllocation)alloc, dimX); |
| 1614 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1615 | rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX); |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Jason Sams | 46ba27e3 | 2015-02-06 17:45:15 -0800 | [diff] [blame] | 1618 | |
| 1619 | static jlong |
| 1620 | nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type) |
| 1621 | { |
| 1622 | if (kLogApi) { |
| 1623 | ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)", |
| 1624 | (RsContext)con, (RsAllocation)basealloc, (RsElement)type); |
| 1625 | } |
| 1626 | return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type, |
| 1627 | (RsAllocation)basealloc); |
| 1628 | |
| 1629 | } |
| 1630 | |
| 1631 | static void |
| 1632 | nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc, |
| 1633 | jint x, jint y, jint z, jint face, jint lod, |
| 1634 | jint a1, jint a2, jint a3, jint a4) |
| 1635 | { |
| 1636 | uint32_t params[] = { |
| 1637 | (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face, |
| 1638 | (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4 |
| 1639 | }; |
| 1640 | if (kLogApi) { |
| 1641 | ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)", |
| 1642 | (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4); |
| 1643 | } |
| 1644 | rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc, |
| 1645 | params, sizeof(params)); |
| 1646 | } |
| 1647 | |
| 1648 | |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1649 | // ----------------------------------- |
| 1650 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1651 | static jlong |
| 1652 | nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset) |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1653 | { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1654 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1655 | ALOGV("______nFileA3D %p", asset); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1656 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1657 | jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength()); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1658 | return id; |
| 1659 | } |
| 1660 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1661 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1662 | nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path) |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1663 | { |
| 1664 | AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1665 | if (mgr == nullptr) { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1666 | return 0; |
| 1667 | } |
| 1668 | |
| 1669 | AutoJavaStringToUTF8 str(_env, _path); |
| 1670 | Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1671 | if (asset == nullptr) { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1672 | return 0; |
| 1673 | } |
| 1674 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1675 | jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1676 | return id; |
| 1677 | } |
| 1678 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1679 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1680 | nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName) |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1681 | { |
| 1682 | AutoJavaStringToUTF8 fileNameUTF(_env, fileName); |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1683 | jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str()); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1684 | |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1685 | return id; |
| 1686 | } |
| 1687 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1688 | static jint |
| 1689 | nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D) |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1690 | { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1691 | int32_t numEntries = 0; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1692 | rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D); |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1693 | return (jint)numEntries; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1697 | nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries) |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1698 | { |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1699 | ALOGV("______nFileA3D %p", (RsFile) fileA3D); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1700 | RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); |
| 1701 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1702 | rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1703 | |
| 1704 | for(jint i = 0; i < numEntries; i ++) { |
| 1705 | _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); |
| 1706 | _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); |
| 1707 | } |
| 1708 | |
| 1709 | free(fileEntries); |
| 1710 | } |
| 1711 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1712 | static jlong |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1713 | nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index) |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1714 | { |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1715 | ALOGV("______nFileA3D %p", (RsFile) fileA3D); |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1716 | jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1717 | return id; |
| 1718 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1719 | |
| 1720 | // ----------------------------------- |
| 1721 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1722 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1723 | nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con, |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1724 | jstring fileName, jfloat fontSize, jint dpi) |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1725 | { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1726 | AutoJavaStringToUTF8 fileNameUTF(_env, fileName); |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1727 | jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con, |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 1728 | fileNameUTF.c_str(), fileNameUTF.length(), |
| 1729 | fontSize, dpi); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1730 | |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1731 | return id; |
| 1732 | } |
| 1733 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1734 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1735 | nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1736 | jstring name, jfloat fontSize, jint dpi, jlong native_asset) |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1737 | { |
| 1738 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
| 1739 | AutoJavaStringToUTF8 nameUTF(_env, name); |
| 1740 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1741 | jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con, |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 1742 | nameUTF.c_str(), nameUTF.length(), |
| 1743 | fontSize, dpi, |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1744 | asset->getBuffer(false), asset->getLength()); |
| 1745 | return id; |
| 1746 | } |
| 1747 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1748 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1749 | nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path, |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1750 | jfloat fontSize, jint dpi) |
| 1751 | { |
| 1752 | AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1753 | if (mgr == nullptr) { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1754 | return 0; |
| 1755 | } |
| 1756 | |
| 1757 | AutoJavaStringToUTF8 str(_env, _path); |
| 1758 | Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1759 | if (asset == nullptr) { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1760 | return 0; |
| 1761 | } |
| 1762 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1763 | jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con, |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 1764 | str.c_str(), str.length(), |
| 1765 | fontSize, dpi, |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1766 | asset->getBuffer(false), asset->getLength()); |
| 1767 | delete asset; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1768 | return id; |
| 1769 | } |
| 1770 | |
Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1771 | // ----------------------------------- |
| 1772 | |
| 1773 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1774 | nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1775 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1776 | if (kLogApi) { |
| 1777 | ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, |
| 1778 | (RsScript)script, (RsAllocation)alloc, slot); |
| 1779 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1780 | rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1784 | nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val) |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1785 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1786 | if (kLogApi) { |
| 1787 | ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, |
| 1788 | slot, val); |
| 1789 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1790 | rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1793 | static jint |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1794 | nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1795 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1796 | if (kLogApi) { |
| 1797 | ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1798 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1799 | int value = 0; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1800 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1801 | return value; |
| 1802 | } |
| 1803 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1804 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1805 | nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 1806 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1807 | if (kLogApi) { |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 1808 | ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script, |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1809 | slot, val); |
| 1810 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1811 | rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val); |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1815 | nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 1816 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1817 | if (kLogApi) { |
Bernhard Rosenkränzer | 09993f7 | 2014-11-17 20:25:28 +0100 | [diff] [blame] | 1818 | ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script, |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1819 | slot, val); |
| 1820 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1821 | rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val); |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1824 | static jlong |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1825 | nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1826 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1827 | if (kLogApi) { |
| 1828 | ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1829 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1830 | jlong value = 0; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1831 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1832 | return value; |
| 1833 | } |
| 1834 | |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 1835 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1836 | nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val) |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1837 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1838 | if (kLogApi) { |
| 1839 | ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, |
| 1840 | slot, val); |
| 1841 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1842 | rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1845 | static jfloat |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1846 | nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1847 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1848 | if (kLogApi) { |
| 1849 | ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1850 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1851 | jfloat value = 0; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1852 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1853 | return value; |
| 1854 | } |
| 1855 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1856 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1857 | nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val) |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 1858 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1859 | if (kLogApi) { |
| 1860 | ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, |
| 1861 | slot, val); |
| 1862 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1863 | rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val); |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1866 | static jdouble |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1867 | nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1868 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1869 | if (kLogApi) { |
| 1870 | ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1871 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1872 | jdouble value = 0; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1873 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1874 | return value; |
| 1875 | } |
| 1876 | |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 1877 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1878 | nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1879 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1880 | if (kLogApi) { |
| 1881 | ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1882 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1883 | jint len = _env->GetArrayLength(data); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1884 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1885 | if (ptr == nullptr) { |
| 1886 | ALOGE("Failed to get Java array elements"); |
| 1887 | return; |
| 1888 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1889 | rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1890 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1891 | } |
| 1892 | |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1893 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1894 | nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1895 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1896 | if (kLogApi) { |
| 1897 | ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1898 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1899 | jint len = _env->GetArrayLength(data); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1900 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1901 | if (ptr == nullptr) { |
| 1902 | ALOGE("Failed to get Java array elements"); |
| 1903 | return; |
| 1904 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1905 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len); |
Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1906 | _env->ReleaseByteArrayElements(data, ptr, 0); |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | static void |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1910 | nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, |
| 1911 | jlong elem, jintArray dims) |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1912 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1913 | if (kLogApi) { |
| 1914 | ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1915 | } |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1916 | jint len = _env->GetArrayLength(data); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1917 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1918 | if (ptr == nullptr) { |
| 1919 | ALOGE("Failed to get Java array elements"); |
| 1920 | return; |
| 1921 | } |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1922 | jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1923 | jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1924 | if (dimsPtr == nullptr) { |
| 1925 | ALOGE("Failed to get Java array elements"); |
| 1926 | return; |
| 1927 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1928 | rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem, |
Stephen Hines | bc5d3ee | 2014-06-25 00:03:39 -0700 | [diff] [blame] | 1929 | (const uint32_t*) dimsPtr, dimsLen); |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1930 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1931 | _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); |
| 1932 | } |
| 1933 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1934 | |
| 1935 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1936 | nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1937 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1938 | if (kLogApi) { |
| 1939 | ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script); |
| 1940 | } |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1941 | |
| 1942 | jint length = _env->GetArrayLength(timeZone); |
| 1943 | jbyte* timeZone_ptr; |
| 1944 | timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1945 | if (timeZone_ptr == nullptr) { |
| 1946 | ALOGE("Failed to get Java array elements"); |
| 1947 | return; |
| 1948 | } |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1949 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1950 | rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length); |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1951 | |
| 1952 | if (timeZone_ptr) { |
| 1953 | _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); |
| 1954 | } |
| 1955 | } |
| 1956 | |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 1957 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1958 | nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot) |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 1959 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1960 | if (kLogApi) { |
| 1961 | ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj); |
| 1962 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1963 | rsScriptInvoke((RsContext)con, (RsScript)obj, slot); |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1967 | nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1968 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1969 | if (kLogApi) { |
| 1970 | ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| 1971 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1972 | jint len = _env->GetArrayLength(data); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1973 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 1974 | if (ptr == nullptr) { |
| 1975 | ALOGE("Failed to get Java array elements"); |
| 1976 | return; |
| 1977 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1978 | rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1979 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1980 | } |
| 1981 | |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 1982 | static void |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1983 | nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, |
| 1984 | jlongArray ains, jlong aout, jbyteArray params, |
| 1985 | jintArray limits) |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 1986 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1987 | if (kLogApi) { |
Chih-Hung Hsieh | 9eb9dd3 | 2015-05-06 14:42:04 -0700 | [diff] [blame] | 1988 | ALOGD("nScriptForEach, con(%p), s(%p), slot(%i) ains(%p) aout(%" PRId64 ")", (RsContext)con, (void *)script, slot, ains, aout); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 1989 | } |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 1990 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1991 | jint in_len = 0; |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1992 | jlong *in_ptr = nullptr; |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1993 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1994 | RsAllocation *in_allocs = nullptr; |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1995 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1996 | if (ains != nullptr) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1997 | in_len = _env->GetArrayLength(ains); |
Yang Ni | 7b2a46f | 2015-05-05 12:41:19 -0700 | [diff] [blame] | 1998 | if (in_len > (jint)RS_KERNEL_MAX_ARGUMENTS) { |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 1999 | ALOGE("Too many arguments in kernel launch."); |
| 2000 | // TODO (b/20758983): Report back to Java and throw an exception |
| 2001 | return; |
| 2002 | } |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2003 | |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 2004 | in_ptr = _env->GetLongArrayElements(ains, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2005 | if (in_ptr == nullptr) { |
| 2006 | ALOGE("Failed to get Java array elements"); |
| 2007 | return; |
| 2008 | } |
| 2009 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2010 | if (sizeof(RsAllocation) == sizeof(jlong)) { |
| 2011 | in_allocs = (RsAllocation*)in_ptr; |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2012 | } else { |
| 2013 | // Convert from 64-bit jlong types to the native pointer type. |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2014 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2015 | in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation)); |
Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 2016 | if (in_allocs == nullptr) { |
| 2017 | ALOGE("Failed launching kernel for lack of memory."); |
| 2018 | _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); |
| 2019 | return; |
| 2020 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2021 | |
| 2022 | for (int index = in_len; --index >= 0;) { |
| 2023 | in_allocs[index] = (RsAllocation)in_ptr[index]; |
| 2024 | } |
| 2025 | } |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2028 | jint param_len = 0; |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2029 | jbyte *param_ptr = nullptr; |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2030 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2031 | if (params != nullptr) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2032 | param_len = _env->GetArrayLength(params); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2033 | param_ptr = _env->GetByteArrayElements(params, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2034 | if (param_ptr == nullptr) { |
| 2035 | ALOGE("Failed to get Java array elements"); |
| 2036 | return; |
| 2037 | } |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2040 | RsScriptCall sc, *sca = nullptr; |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2041 | uint32_t sc_size = 0; |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2042 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2043 | jint limit_len = 0; |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2044 | jint *limit_ptr = nullptr; |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2045 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2046 | if (limits != nullptr) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2047 | limit_len = _env->GetArrayLength(limits); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2048 | limit_ptr = _env->GetIntArrayElements(limits, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2049 | if (limit_ptr == nullptr) { |
| 2050 | ALOGE("Failed to get Java array elements"); |
| 2051 | return; |
| 2052 | } |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2053 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2054 | assert(limit_len == 6); |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2055 | UNUSED(limit_len); // As the assert might not be compiled. |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2056 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2057 | sc.xStart = limit_ptr[0]; |
| 2058 | sc.xEnd = limit_ptr[1]; |
| 2059 | sc.yStart = limit_ptr[2]; |
| 2060 | sc.yEnd = limit_ptr[3]; |
| 2061 | sc.zStart = limit_ptr[4]; |
| 2062 | sc.zEnd = limit_ptr[5]; |
| 2063 | sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; |
Jason Sams | 14331ab | 2015-01-26 18:14:36 -0800 | [diff] [blame] | 2064 | sc.arrayStart = 0; |
| 2065 | sc.arrayEnd = 0; |
| 2066 | sc.array2Start = 0; |
| 2067 | sc.array2End = 0; |
| 2068 | sc.array3Start = 0; |
| 2069 | sc.array3End = 0; |
| 2070 | sc.array4Start = 0; |
| 2071 | sc.array4End = 0; |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2072 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2073 | sca = ≻ |
Yang Ni | 2b551f4 | 2016-03-15 16:00:02 -0700 | [diff] [blame] | 2074 | // sc_size is required, but unused, by the runtime and drivers. |
| 2075 | sc_size = sizeof(sc); |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2078 | rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, |
| 2079 | in_allocs, in_len, (RsAllocation)aout, |
| 2080 | param_ptr, param_len, sca, sc_size); |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2081 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2082 | if (ains != nullptr) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2083 | _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2086 | if (params != nullptr) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2087 | _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); |
| 2088 | } |
| 2089 | |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2090 | if (limits != nullptr) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2091 | _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); |
| 2092 | } |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Matt Wala | 36eb1f7 | 2015-07-20 15:35:27 -0700 | [diff] [blame] | 2095 | static void |
| 2096 | nScriptReduce(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, |
| 2097 | jlong ain, jlong aout, jintArray limits) |
| 2098 | { |
| 2099 | if (kLogApi) { |
| 2100 | ALOGD("nScriptReduce, con(%p), s(%p), slot(%i) ain(%" PRId64 ") aout(%" PRId64 ")", (RsContext)con, (void *)script, slot, ain, aout); |
| 2101 | } |
| 2102 | |
| 2103 | RsScriptCall sc, *sca = nullptr; |
| 2104 | uint32_t sc_size = 0; |
| 2105 | |
| 2106 | jint limit_len = 0; |
| 2107 | jint *limit_ptr = nullptr; |
| 2108 | |
| 2109 | // If the caller passed limits, reflect them in the RsScriptCall. |
| 2110 | if (limits != nullptr) { |
| 2111 | limit_len = _env->GetArrayLength(limits); |
| 2112 | limit_ptr = _env->GetIntArrayElements(limits, nullptr); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2113 | if (limit_ptr == nullptr) { |
| 2114 | ALOGE("Failed to get Java array elements"); |
| 2115 | return; |
| 2116 | } |
Matt Wala | 36eb1f7 | 2015-07-20 15:35:27 -0700 | [diff] [blame] | 2117 | |
| 2118 | // We expect to be passed an array [x1, x2] which specifies |
| 2119 | // the sub-range for a 1-dimensional reduction. |
| 2120 | assert(limit_len == 2); |
| 2121 | UNUSED(limit_len); // As the assert might not be compiled. |
| 2122 | |
| 2123 | sc.xStart = limit_ptr[0]; |
| 2124 | sc.xEnd = limit_ptr[1]; |
| 2125 | sc.yStart = 0; |
| 2126 | sc.yEnd = 0; |
| 2127 | sc.zStart = 0; |
| 2128 | sc.zEnd = 0; |
| 2129 | sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; |
| 2130 | sc.arrayStart = 0; |
| 2131 | sc.arrayEnd = 0; |
| 2132 | sc.array2Start = 0; |
| 2133 | sc.array2End = 0; |
| 2134 | sc.array3Start = 0; |
| 2135 | sc.array3End = 0; |
| 2136 | sc.array4Start = 0; |
| 2137 | sc.array4End = 0; |
| 2138 | |
| 2139 | sca = ≻ |
| 2140 | sc_size = sizeof(sc); |
| 2141 | } |
| 2142 | |
| 2143 | rsScriptReduce((RsContext)con, (RsScript)script, slot, |
| 2144 | (RsAllocation)ain, (RsAllocation)aout, |
| 2145 | sca, sc_size); |
| 2146 | |
| 2147 | if (limits != nullptr) { |
| 2148 | _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); |
| 2149 | } |
| 2150 | } |
| 2151 | |
David Gross | 26ef7a73 | 2016-01-12 12:19:15 -0800 | [diff] [blame] | 2152 | static void |
| 2153 | nScriptReduceNew(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, |
| 2154 | jlongArray ains, jlong aout, jintArray limits) |
| 2155 | { |
| 2156 | if (kLogApi) { |
| 2157 | ALOGD("nScriptReduceNew, con(%p), s(%p), slot(%i) ains(%p) aout(%" PRId64 ")", (RsContext)con, (void *)script, slot, ains, aout); |
| 2158 | } |
| 2159 | |
| 2160 | if (ains == nullptr) { |
| 2161 | ALOGE("At least one input required."); |
| 2162 | // TODO (b/20758983): Report back to Java and throw an exception |
| 2163 | return; |
| 2164 | } |
| 2165 | jint in_len = _env->GetArrayLength(ains); |
| 2166 | if (in_len > (jint)RS_KERNEL_MAX_ARGUMENTS) { |
| 2167 | ALOGE("Too many arguments in kernel launch."); |
| 2168 | // TODO (b/20758983): Report back to Java and throw an exception |
| 2169 | return; |
| 2170 | } |
| 2171 | |
| 2172 | jlong *in_ptr = _env->GetLongArrayElements(ains, nullptr); |
| 2173 | if (in_ptr == nullptr) { |
| 2174 | ALOGE("Failed to get Java array elements"); |
| 2175 | // TODO (b/20758983): Report back to Java and throw an exception |
| 2176 | return; |
| 2177 | } |
| 2178 | |
| 2179 | RsAllocation *in_allocs = nullptr; |
| 2180 | if (sizeof(RsAllocation) == sizeof(jlong)) { |
| 2181 | in_allocs = (RsAllocation*)in_ptr; |
| 2182 | } else { |
| 2183 | // Convert from 64-bit jlong types to the native pointer type. |
| 2184 | |
| 2185 | in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation)); |
| 2186 | if (in_allocs == nullptr) { |
| 2187 | ALOGE("Failed launching kernel for lack of memory."); |
| 2188 | // TODO (b/20758983): Report back to Java and throw an exception |
| 2189 | _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); |
| 2190 | return; |
| 2191 | } |
| 2192 | |
| 2193 | for (int index = in_len; --index >= 0;) { |
| 2194 | in_allocs[index] = (RsAllocation)in_ptr[index]; |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | RsScriptCall sc, *sca = nullptr; |
| 2199 | uint32_t sc_size = 0; |
| 2200 | |
| 2201 | jint limit_len = 0; |
| 2202 | jint *limit_ptr = nullptr; |
| 2203 | |
| 2204 | if (limits != nullptr) { |
| 2205 | limit_len = _env->GetArrayLength(limits); |
| 2206 | limit_ptr = _env->GetIntArrayElements(limits, nullptr); |
| 2207 | if (limit_ptr == nullptr) { |
| 2208 | ALOGE("Failed to get Java array elements"); |
| 2209 | // TODO (b/20758983): Report back to Java and throw an exception |
| 2210 | return; |
| 2211 | } |
| 2212 | |
| 2213 | assert(limit_len == 6); |
| 2214 | UNUSED(limit_len); // As the assert might not be compiled. |
| 2215 | |
| 2216 | sc.xStart = limit_ptr[0]; |
| 2217 | sc.xEnd = limit_ptr[1]; |
| 2218 | sc.yStart = limit_ptr[2]; |
| 2219 | sc.yEnd = limit_ptr[3]; |
| 2220 | sc.zStart = limit_ptr[4]; |
| 2221 | sc.zEnd = limit_ptr[5]; |
| 2222 | sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; |
| 2223 | sc.arrayStart = 0; |
| 2224 | sc.arrayEnd = 0; |
| 2225 | sc.array2Start = 0; |
| 2226 | sc.array2End = 0; |
| 2227 | sc.array3Start = 0; |
| 2228 | sc.array3End = 0; |
| 2229 | sc.array4Start = 0; |
| 2230 | sc.array4End = 0; |
| 2231 | |
| 2232 | sca = ≻ |
| 2233 | sc_size = sizeof(sc); |
| 2234 | } |
| 2235 | |
| 2236 | rsScriptReduceNew((RsContext)con, (RsScript)script, slot, |
| 2237 | in_allocs, in_len, (RsAllocation)aout, |
| 2238 | sca, sc_size); |
| 2239 | |
| 2240 | _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); |
| 2241 | |
| 2242 | if (limits != nullptr) { |
| 2243 | _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); |
| 2244 | } |
| 2245 | } |
| 2246 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 2247 | // ----------------------------------- |
| 2248 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2249 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2250 | nScriptCCreate(JNIEnv *_env, jobject _this, jlong con, |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 2251 | jstring resName, jstring cacheDir, |
| 2252 | jbyteArray scriptRef, jint length) |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 2253 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2254 | if (kLogApi) { |
| 2255 | ALOGD("nScriptCCreate, con(%p)", (RsContext)con); |
| 2256 | } |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 2257 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 2258 | AutoJavaStringToUTF8 resNameUTF(_env, resName); |
| 2259 | AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2260 | jlong ret = 0; |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2261 | jbyte* script_ptr = nullptr; |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2262 | jint _exception = 0; |
| 2263 | jint remaining; |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2264 | if (!scriptRef) { |
| 2265 | _exception = 1; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 2266 | //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2267 | goto exit; |
| 2268 | } |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2269 | if (length < 0) { |
| 2270 | _exception = 1; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 2271 | //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2272 | goto exit; |
| 2273 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 2274 | remaining = _env->GetArrayLength(scriptRef); |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2275 | if (remaining < length) { |
| 2276 | _exception = 1; |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 2277 | //jniThrowException(_env, "java/lang/IllegalArgumentException", |
| 2278 | // "length > script.length - offset"); |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2279 | goto exit; |
| 2280 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 2281 | script_ptr = (jbyte *) |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2282 | _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2283 | if (script_ptr == nullptr) { |
| 2284 | ALOGE("Failed to get Java array elements"); |
| 2285 | return ret; |
| 2286 | } |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2287 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2288 | //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 2289 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2290 | ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con, |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 2291 | resNameUTF.c_str(), resNameUTF.length(), |
| 2292 | cacheDirUTF.c_str(), cacheDirUTF.length(), |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 2293 | (const char *)script_ptr, length); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 2294 | |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2295 | exit: |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 2296 | if (script_ptr) { |
| 2297 | _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 2298 | _exception ? JNI_ABORT: 0); |
| 2299 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2300 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2301 | return (jlong)(uintptr_t)ret; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2304 | static jlong |
| 2305 | nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid) |
Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 2306 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2307 | if (kLogApi) { |
| 2308 | ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, |
| 2309 | (void *)eid); |
| 2310 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2311 | return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid); |
Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2314 | static jlong |
| 2315 | nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig) |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2316 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2317 | if (kLogApi) { |
| 2318 | ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, |
| 2319 | (void *)sid, slot, sig); |
| 2320 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2321 | return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2324 | static jlong |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 2325 | nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) |
| 2326 | { |
| 2327 | if (kLogApi) { |
Elliott Hughes | 7ff53fa | 2015-02-05 21:36:10 -0800 | [diff] [blame] | 2328 | ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 2329 | (void *)sid, slot); |
| 2330 | } |
| 2331 | return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot); |
| 2332 | } |
| 2333 | |
| 2334 | static jlong |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2335 | nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2336 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2337 | if (kLogApi) { |
| 2338 | ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, |
| 2339 | slot); |
| 2340 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2341 | return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2344 | static jlong |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2345 | nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src, |
| 2346 | jlongArray _dstk, jlongArray _dstf, jlongArray _types) |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2347 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2348 | if (kLogApi) { |
| 2349 | ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con); |
| 2350 | } |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2351 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2352 | jlong id = 0; |
| 2353 | |
| 2354 | RsScriptKernelID* kernelsPtr; |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2355 | jint kernelsLen = _env->GetArrayLength(_kernels); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2356 | jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr); |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2357 | |
| 2358 | RsScriptKernelID* srcPtr; |
| 2359 | jint srcLen = _env->GetArrayLength(_src); |
| 2360 | jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr); |
| 2361 | |
| 2362 | RsScriptKernelID* dstkPtr; |
| 2363 | jint dstkLen = _env->GetArrayLength(_dstk); |
| 2364 | jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr); |
| 2365 | |
| 2366 | RsScriptKernelID* dstfPtr; |
| 2367 | jint dstfLen = _env->GetArrayLength(_dstf); |
| 2368 | jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr); |
| 2369 | |
| 2370 | RsType* typesPtr; |
| 2371 | jint typesLen = _env->GetArrayLength(_types); |
| 2372 | jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr); |
| 2373 | |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2374 | if (jKernelsPtr == nullptr) { |
| 2375 | ALOGE("Failed to get Java array elements: kernels"); |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2376 | goto cleanup; |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2377 | } |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2378 | if (jSrcPtr == nullptr) { |
| 2379 | ALOGE("Failed to get Java array elements: src"); |
| 2380 | goto cleanup; |
| 2381 | } |
| 2382 | if (jDstkPtr == nullptr) { |
| 2383 | ALOGE("Failed to get Java array elements: dstk"); |
| 2384 | goto cleanup; |
| 2385 | } |
| 2386 | if (jDstfPtr == nullptr) { |
| 2387 | ALOGE("Failed to get Java array elements: dstf"); |
| 2388 | goto cleanup; |
| 2389 | } |
| 2390 | if (jTypesPtr == nullptr) { |
| 2391 | ALOGE("Failed to get Java array elements: types"); |
| 2392 | goto cleanup; |
| 2393 | } |
| 2394 | |
| 2395 | kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2396 | for(int i = 0; i < kernelsLen; ++i) { |
| 2397 | kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i]; |
| 2398 | } |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2399 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2400 | srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2401 | for(int i = 0; i < srcLen; ++i) { |
| 2402 | srcPtr[i] = (RsScriptKernelID)jSrcPtr[i]; |
| 2403 | } |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2404 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2405 | dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2406 | for(int i = 0; i < dstkLen; ++i) { |
| 2407 | dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i]; |
| 2408 | } |
| 2409 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2410 | dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2411 | for(int i = 0; i < dstfLen; ++i) { |
| 2412 | dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i]; |
| 2413 | } |
| 2414 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2415 | typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2416 | for(int i = 0; i < typesLen; ++i) { |
| 2417 | typesPtr[i] = (RsType)jTypesPtr[i]; |
| 2418 | } |
| 2419 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2420 | id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2421 | (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID), |
| 2422 | (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID), |
| 2423 | (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID), |
| 2424 | (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID), |
| 2425 | (RsType *)typesPtr, typesLen * sizeof(RsType)); |
| 2426 | |
| 2427 | free(kernelsPtr); |
| 2428 | free(srcPtr); |
| 2429 | free(dstkPtr); |
| 2430 | free(dstfPtr); |
| 2431 | free(typesPtr); |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2432 | |
| 2433 | cleanup: |
| 2434 | if (jKernelsPtr != nullptr) { |
| 2435 | _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0); |
| 2436 | } |
| 2437 | if (jSrcPtr != nullptr) { |
| 2438 | _env->ReleaseLongArrayElements(_src, jSrcPtr, 0); |
| 2439 | } |
| 2440 | if (jDstkPtr != nullptr) { |
| 2441 | _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0); |
| 2442 | } |
| 2443 | if (jDstfPtr != nullptr) { |
| 2444 | _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0); |
| 2445 | } |
| 2446 | if (jTypesPtr != nullptr) { |
| 2447 | _env->ReleaseLongArrayElements(_types, jTypesPtr, 0); |
| 2448 | } |
| 2449 | |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2450 | return id; |
| 2451 | } |
| 2452 | |
| 2453 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2454 | nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2455 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2456 | if (kLogApi) { |
| 2457 | ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, |
| 2458 | (void *)gid, (void *)kid, (void *)alloc); |
| 2459 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2460 | rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2464 | nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2465 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2466 | if (kLogApi) { |
| 2467 | ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, |
| 2468 | (void *)gid, (void *)kid, (void *)alloc); |
| 2469 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2470 | rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2474 | nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid) |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2475 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2476 | if (kLogApi) { |
| 2477 | ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid); |
| 2478 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2479 | rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2482 | // --------------------------------------------------------------------------- |
| 2483 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2484 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2485 | nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con, |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 2486 | jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA, |
| 2487 | jboolean depthMask, jboolean ditherEnable, |
| 2488 | jint srcFunc, jint destFunc, |
| 2489 | jint depthFunc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2490 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2491 | if (kLogApi) { |
| 2492 | ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con); |
| 2493 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2494 | return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA, |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 2495 | depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc, |
| 2496 | (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 2499 | // --------------------------------------------------------------------------- |
| 2500 | |
| 2501 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2502 | nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a) |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 2503 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2504 | if (kLogApi) { |
| 2505 | ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, |
| 2506 | (RsProgramVertex)vpv, slot, (RsAllocation)a); |
| 2507 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2508 | rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 2509 | } |
Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 2510 | |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 2511 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2512 | nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 2513 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2514 | if (kLogApi) { |
| 2515 | ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, |
| 2516 | (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| 2517 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2518 | rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | static void |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2522 | nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 2523 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2524 | if (kLogApi) { |
| 2525 | ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, |
| 2526 | (RsProgramFragment)vpf, slot, (RsSampler)a); |
| 2527 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2528 | rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 2529 | } |
| 2530 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2531 | // --------------------------------------------------------------------------- |
| 2532 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2533 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2534 | nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2535 | jobjectArray texNames, jlongArray params) |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 2536 | { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 2537 | AutoJavaStringToUTF8 shaderUTF(_env, shader); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2538 | jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 2539 | jint paramLen = _env->GetArrayLength(params); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2540 | if (jParamPtr == nullptr) { |
| 2541 | ALOGE("Failed to get Java array elements"); |
| 2542 | return 0; |
| 2543 | } |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 2544 | |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 2545 | int texCount = _env->GetArrayLength(texNames); |
| 2546 | AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); |
| 2547 | const char ** nameArray = names.c_str(); |
| 2548 | size_t* sizeArray = names.c_str_len(); |
| 2549 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2550 | if (kLogApi) { |
| 2551 | ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); |
| 2552 | } |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 2553 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2554 | uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen); |
| 2555 | for(int i = 0; i < paramLen; ++i) { |
| 2556 | paramPtr[i] = (uintptr_t)jParamPtr[i]; |
| 2557 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2558 | jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(), |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 2559 | nameArray, texCount, sizeArray, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2560 | paramPtr, paramLen); |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 2561 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2562 | free(paramPtr); |
| 2563 | _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT); |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 2564 | return ret; |
| 2565 | } |
| 2566 | |
| 2567 | |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 2568 | // --------------------------------------------------------------------------- |
| 2569 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2570 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2571 | nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2572 | jobjectArray texNames, jlongArray params) |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 2573 | { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 2574 | AutoJavaStringToUTF8 shaderUTF(_env, shader); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2575 | jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 2576 | jint paramLen = _env->GetArrayLength(params); |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2577 | if (jParamPtr == nullptr) { |
| 2578 | ALOGE("Failed to get Java array elements"); |
| 2579 | return 0; |
| 2580 | } |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 2581 | |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2582 | if (kLogApi) { |
| 2583 | ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); |
| 2584 | } |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 2585 | |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 2586 | int texCount = _env->GetArrayLength(texNames); |
| 2587 | AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); |
| 2588 | const char ** nameArray = names.c_str(); |
| 2589 | size_t* sizeArray = names.c_str_len(); |
| 2590 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2591 | uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen); |
| 2592 | for(int i = 0; i < paramLen; ++i) { |
| 2593 | paramPtr[i] = (uintptr_t)jParamPtr[i]; |
| 2594 | } |
| 2595 | |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2596 | jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(), |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 2597 | nameArray, texCount, sizeArray, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2598 | paramPtr, paramLen); |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 2599 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2600 | free(paramPtr); |
| 2601 | _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 2602 | return ret; |
| 2603 | } |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 2604 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 2605 | // --------------------------------------------------------------------------- |
| 2606 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2607 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2608 | nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull) |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 2609 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2610 | if (kLogApi) { |
| 2611 | ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, |
| 2612 | pointSprite, cull); |
| 2613 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2614 | return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2617 | |
| 2618 | // --------------------------------------------------------------------------- |
| 2619 | |
| 2620 | static void |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 2621 | nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2622 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2623 | if (kLogApi) { |
| 2624 | ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script); |
| 2625 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2626 | rsContextBindRootScript((RsContext)con, (RsScript)script); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | static void |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 2630 | nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2631 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2632 | if (kLogApi) { |
| 2633 | ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs); |
| 2634 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2635 | rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | static void |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 2639 | nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2640 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2641 | if (kLogApi) { |
| 2642 | ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, |
| 2643 | (RsProgramFragment)pf); |
| 2644 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2645 | rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 2648 | static void |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 2649 | nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf) |
Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 2650 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2651 | if (kLogApi) { |
| 2652 | ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf); |
| 2653 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2654 | rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf); |
Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 2657 | static void |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 2658 | nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf) |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 2659 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2660 | if (kLogApi) { |
| 2661 | ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf); |
| 2662 | } |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2663 | rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 2666 | |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 2667 | // --------------------------------------------------------------------------- |
| 2668 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2669 | static jlong |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2670 | nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter, |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 2671 | jint wrapS, jint wrapT, jint wrapR, jfloat aniso) |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 2672 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2673 | if (kLogApi) { |
| 2674 | ALOGD("nSamplerCreate, con(%p)", (RsContext)con); |
| 2675 | } |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2676 | return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con, |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 2677 | (RsSamplerValue)magFilter, |
| 2678 | (RsSamplerValue)minFilter, |
| 2679 | (RsSamplerValue)wrapS, |
| 2680 | (RsSamplerValue)wrapT, |
| 2681 | (RsSamplerValue)wrapR, |
| 2682 | aniso); |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 2683 | } |
| 2684 | |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 2685 | // --------------------------------------------------------------------------- |
| 2686 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2687 | static jlong |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2688 | nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim) |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 2689 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2690 | if (kLogApi) { |
| 2691 | ALOGD("nMeshCreate, con(%p)", (RsContext)con); |
| 2692 | } |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 2693 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2694 | jlong id = 0; |
| 2695 | |
| 2696 | RsAllocation* vtxPtr; |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 2697 | jint vtxLen = _env->GetArrayLength(_vtx); |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 2698 | jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr); |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2699 | |
| 2700 | RsAllocation* idxPtr; |
| 2701 | jint idxLen = _env->GetArrayLength(_idx); |
| 2702 | jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr); |
| 2703 | |
| 2704 | jint primLen = _env->GetArrayLength(_prim); |
| 2705 | jint *primPtr = _env->GetIntArrayElements(_prim, nullptr); |
| 2706 | |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2707 | if (jVtxPtr == nullptr) { |
| 2708 | ALOGE("Failed to get Java array elements: vtx"); |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2709 | goto cleanupMesh; |
Miao Wang | ba8766c | 2015-10-12 17:24:13 -0700 | [diff] [blame] | 2710 | } |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2711 | if (jIdxPtr == nullptr) { |
| 2712 | ALOGE("Failed to get Java array elements: idx"); |
| 2713 | goto cleanupMesh; |
| 2714 | } |
| 2715 | if (primPtr == nullptr) { |
| 2716 | ALOGE("Failed to get Java array elements: prim"); |
| 2717 | goto cleanupMesh; |
| 2718 | } |
| 2719 | |
| 2720 | vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2721 | for(int i = 0; i < vtxLen; ++i) { |
| 2722 | vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i]; |
| 2723 | } |
| 2724 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2725 | idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen); |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2726 | for(int i = 0; i < idxLen; ++i) { |
| 2727 | idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i]; |
| 2728 | } |
| 2729 | |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2730 | id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con, |
| 2731 | (RsAllocation *)vtxPtr, vtxLen, |
| 2732 | (RsAllocation *)idxPtr, idxLen, |
| 2733 | (uint32_t *)primPtr, primLen); |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 2734 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2735 | free(vtxPtr); |
| 2736 | free(idxPtr); |
Miao Wang | f94e77d | 2016-02-11 12:32:39 -0800 | [diff] [blame] | 2737 | |
| 2738 | cleanupMesh: |
| 2739 | if (jVtxPtr != nullptr) { |
| 2740 | _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0); |
| 2741 | } |
| 2742 | if (jIdxPtr != nullptr) { |
| 2743 | _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0); |
| 2744 | } |
| 2745 | if (primPtr != nullptr) { |
| 2746 | _env->ReleaseIntArrayElements(_prim, primPtr, 0); |
| 2747 | } |
| 2748 | |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 2749 | return id; |
| 2750 | } |
| 2751 | |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2752 | static jint |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2753 | nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2754 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2755 | if (kLogApi) { |
| 2756 | ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| 2757 | } |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2758 | jint vtxCount = 0; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2759 | rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2760 | return vtxCount; |
| 2761 | } |
| 2762 | |
| 2763 | static jint |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2764 | nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2765 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2766 | if (kLogApi) { |
| 2767 | ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| 2768 | } |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2769 | jint idxCount = 0; |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2770 | rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2771 | return idxCount; |
| 2772 | } |
| 2773 | |
| 2774 | static void |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2775 | nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs) |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2776 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2777 | if (kLogApi) { |
| 2778 | ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| 2779 | } |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2780 | |
| 2781 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2782 | rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2783 | |
| 2784 | for(jint i = 0; i < numVtxIDs; i ++) { |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2785 | const jlong alloc = (jlong)(uintptr_t)allocs[i]; |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2786 | _env->SetLongArrayRegion(_ids, i, 1, &alloc); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | free(allocs); |
| 2790 | } |
| 2791 | |
| 2792 | static void |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2793 | nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices) |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2794 | { |
Andreas Gampe | 6733392 | 2014-11-10 20:35:59 -0800 | [diff] [blame] | 2795 | if (kLogApi) { |
| 2796 | ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| 2797 | } |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2798 | |
| 2799 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); |
| 2800 | uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); |
| 2801 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2802 | rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2803 | |
| 2804 | for(jint i = 0; i < numIndices; i ++) { |
Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 2805 | const jlong alloc = (jlong)(uintptr_t)allocs[i]; |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2806 | const jint prim = (jint)prims[i]; |
| 2807 | _env->SetLongArrayRegion(_idxIds, i, 1, &alloc); |
| 2808 | _env->SetIntArrayRegion(_primitives, i, 1, &prim); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | free(allocs); |
| 2812 | free(prims); |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
Tim Murray | 56f9e6f | 2014-05-16 11:47:26 -0700 | [diff] [blame] | 2815 | static jint |
| 2816 | nSystemGetPointerSize(JNIEnv *_env, jobject _this) { |
| 2817 | return (jint)sizeof(void*); |
| 2818 | } |
| 2819 | |
Miao Wang | 0facf02 | 2015-11-25 11:21:13 -0800 | [diff] [blame] | 2820 | static jobject |
| 2821 | nAllocationGetByteBuffer(JNIEnv *_env, jobject _this, jlong con, jlong alloc, |
| 2822 | jlongArray strideArr, jint xBytesSize, |
| 2823 | jint dimY, jint dimZ) { |
| 2824 | if (kLogApi) { |
| 2825 | ALOGD("nAllocationGetByteBuffer, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); |
| 2826 | } |
Tim Murray | 56f9e6f | 2014-05-16 11:47:26 -0700 | [diff] [blame] | 2827 | |
Miao Wang | 0facf02 | 2015-11-25 11:21:13 -0800 | [diff] [blame] | 2828 | jlong *jStridePtr = _env->GetLongArrayElements(strideArr, nullptr); |
| 2829 | if (jStridePtr == nullptr) { |
| 2830 | ALOGE("Failed to get Java array elements: strideArr"); |
| 2831 | return 0; |
| 2832 | } |
| 2833 | |
| 2834 | size_t strideIn = xBytesSize; |
| 2835 | void* ptr = nullptr; |
| 2836 | if (alloc != 0) { |
| 2837 | ptr = rsAllocationGetPointer((RsContext)con, (RsAllocation)alloc, 0, |
| 2838 | RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 0, 0, |
| 2839 | &strideIn, sizeof(size_t)); |
| 2840 | } |
| 2841 | |
| 2842 | jobject byteBuffer = nullptr; |
| 2843 | if (ptr != nullptr) { |
| 2844 | size_t bufferSize = strideIn; |
| 2845 | jStridePtr[0] = strideIn; |
| 2846 | if (dimY > 0) { |
| 2847 | bufferSize *= dimY; |
| 2848 | } |
| 2849 | if (dimZ > 0) { |
| 2850 | bufferSize *= dimZ; |
| 2851 | } |
| 2852 | byteBuffer = _env->NewDirectByteBuffer(ptr, (jlong) bufferSize); |
| 2853 | } |
| 2854 | _env->ReleaseLongArrayElements(strideArr, jStridePtr, 0); |
| 2855 | return byteBuffer; |
| 2856 | } |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 2857 | // --------------------------------------------------------------------------- |
| 2858 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2859 | |
Jason Sams | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 2860 | static const char *classPathName = "android/renderscript/RenderScript"; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2861 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 2862 | static const JNINativeMethod methods[] = { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 2863 | {"_nInit", "()V", (void*)_nInit }, |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 2864 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2865 | {"nDeviceCreate", "()J", (void*)nDeviceCreate }, |
| 2866 | {"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy }, |
| 2867 | {"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig }, |
| 2868 | {"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage }, |
| 2869 | {"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage }, |
| 2870 | {"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage }, |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 2871 | |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2872 | {"nContextInitToClient", "(J)V", (void*)nContextInitToClient }, |
| 2873 | {"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2874 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 2875 | |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 2876 | // All methods below are thread protected in java. |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2877 | {"rsnContextCreate", "(JIII)J", (void*)nContextCreate }, |
| 2878 | {"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL }, |
| 2879 | {"rsnContextFinish", "(J)V", (void*)nContextFinish }, |
| 2880 | {"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority }, |
Tim Murray | 47f3158 | 2015-04-07 15:43:24 -0700 | [diff] [blame] | 2881 | {"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir }, |
Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 2882 | {"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface }, |
| 2883 | {"rsnContextDestroy", "(J)V", (void*)nContextDestroy }, |
| 2884 | {"rsnContextDump", "(JI)V", (void*)nContextDump }, |
| 2885 | {"rsnContextPause", "(J)V", (void*)nContextPause }, |
| 2886 | {"rsnContextResume", "(J)V", (void*)nContextResume }, |
| 2887 | {"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage }, |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 2888 | {"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate }, |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 2889 | {"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate }, |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 2890 | {"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg }, |
| 2891 | {"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2892 | {"rsnAssignName", "(JJ[B)V", (void*)nAssignName }, |
| 2893 | {"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName }, |
| 2894 | {"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy }, |
Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 2895 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2896 | {"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile }, |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2897 | {"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2898 | {"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset }, |
| 2899 | {"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries }, |
| 2900 | {"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2901 | {"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2902 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2903 | {"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile }, |
| 2904 | {"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream }, |
| 2905 | {"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2906 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2907 | {"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate }, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2908 | {"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2909 | {"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData }, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2910 | {"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2911 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2912 | {"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate }, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2913 | {"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2914 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2915 | {"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2916 | {"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap }, |
| 2917 | {"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation }, |
| 2918 | {"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap }, |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 2919 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2920 | {"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, |
| 2921 | {"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 2922 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2923 | {"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll }, |
Miao Wang | 8c15092 | 2015-10-26 17:44:10 -0700 | [diff] [blame] | 2924 | {"rsnAllocationSetupBufferQueue", "(JJI)V", (void*)nAllocationSetupBufferQueue }, |
| 2925 | {"rsnAllocationShareBufferQueue", "(JJJ)V", (void*)nAllocationShareBufferQueue }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2926 | {"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface }, |
| 2927 | {"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface }, |
| 2928 | {"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend }, |
Miao Wang | 8c15092 | 2015-10-26 17:44:10 -0700 | [diff] [blame] | 2929 | {"rsnAllocationIoReceive", "(JJ)J", (void*)nAllocationIoReceive }, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 2930 | {"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D }, |
Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 2931 | {"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData }, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 2932 | {"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2933 | {"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc }, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 2934 | {"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2935 | {"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc }, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 2936 | {"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead }, |
| 2937 | {"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D }, |
Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 2938 | {"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead }, |
Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 2939 | {"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D }, |
| 2940 | {"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2941 | {"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType}, |
| 2942 | {"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D }, |
| 2943 | {"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps }, |
Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 2944 | |
Jason Sams | 46ba27e3 | 2015-02-06 17:45:15 -0800 | [diff] [blame] | 2945 | {"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate }, |
| 2946 | {"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset }, |
| 2947 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2948 | {"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation }, |
| 2949 | {"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, |
| 2950 | {"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, |
| 2951 | {"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2952 | |
| 2953 | {"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach }, |
Matt Wala | 36eb1f7 | 2015-07-20 15:35:27 -0700 | [diff] [blame] | 2954 | {"rsnScriptReduce", "(JJIJJ[I)V", (void*)nScriptReduce }, |
David Gross | 26ef7a73 | 2016-01-12 12:19:15 -0800 | [diff] [blame] | 2955 | {"rsnScriptReduceNew", "(JJI[JJ[I)V", (void*)nScriptReduceNew }, |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 2956 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2957 | {"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, |
| 2958 | {"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI }, |
| 2959 | {"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, |
| 2960 | {"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ }, |
| 2961 | {"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF }, |
| 2962 | {"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF }, |
| 2963 | {"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD }, |
| 2964 | {"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD }, |
| 2965 | {"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV }, |
| 2966 | {"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV }, |
| 2967 | {"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE }, |
| 2968 | {"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2969 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2970 | {"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2971 | {"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate }, |
| 2972 | {"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate }, |
Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 2973 | {"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2974 | {"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate }, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2975 | {"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate }, |
Yang Ni | 35be56c | 2015-04-02 17:47:56 -0700 | [diff] [blame] | 2976 | {"rsnScriptGroup2Create", "(JLjava/lang/String;Ljava/lang/String;[J)J", (void*)nScriptGroup2Create }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2977 | {"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput }, |
| 2978 | {"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput }, |
| 2979 | {"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute }, |
Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 2980 | {"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute }, |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 2981 | |
Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 2982 | {"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single }, |
| 2983 | {"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double }, |
| 2984 | {"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex }, |
| 2985 | {"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z }, |
| 2986 | |
Tim Murray | 9cb16a2 | 2015-04-01 11:07:16 -0700 | [diff] [blame] | 2987 | {"rsnScriptIntrinsicBLAS_BNNM", "(JJIIIJIJIJII)V", (void*)nScriptIntrinsicBLAS_BNNM }, |
| 2988 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 2989 | {"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2990 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2991 | {"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants }, |
| 2992 | {"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture }, |
| 2993 | {"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler }, |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 2994 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2995 | {"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate }, |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 2996 | {"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate }, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 2997 | {"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 2998 | |
Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 2999 | {"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript }, |
| 3000 | {"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore }, |
| 3001 | {"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment }, |
| 3002 | {"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex }, |
| 3003 | {"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster }, |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 3004 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 3005 | {"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate }, |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 3006 | |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 3007 | {"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate }, |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 3008 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 3009 | {"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount }, |
| 3010 | {"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount }, |
Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 3011 | {"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices }, |
| 3012 | {"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices }, |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 3013 | |
Tim Murray | 56f9e6f | 2014-05-16 11:47:26 -0700 | [diff] [blame] | 3014 | {"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize }, |
Miao Wang | 0facf02 | 2015-11-25 11:21:13 -0800 | [diff] [blame] | 3015 | {"rsnAllocationGetByteBuffer", "(JJ[JIII)Ljava/nio/ByteBuffer;", (void*)nAllocationGetByteBuffer }, |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 3016 | }; |
| 3017 | |
| 3018 | static int registerFuncs(JNIEnv *_env) |
| 3019 | { |
| 3020 | return android::AndroidRuntime::registerNativeMethods( |
| 3021 | _env, classPathName, methods, NELEM(methods)); |
| 3022 | } |
| 3023 | |
| 3024 | // --------------------------------------------------------------------------- |
| 3025 | |
| 3026 | jint JNI_OnLoad(JavaVM* vm, void* reserved) |
| 3027 | { |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 3028 | JNIEnv* env = nullptr; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 3029 | jint result = -1; |
| 3030 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 3031 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 3032 | ALOGE("ERROR: GetEnv failed\n"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 3033 | goto bail; |
| 3034 | } |
Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 3035 | assert(env != nullptr); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 3036 | |
| 3037 | if (registerFuncs(env) < 0) { |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 3038 | ALOGE("ERROR: Renderscript native registration failed\n"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 3039 | goto bail; |
| 3040 | } |
| 3041 | |
| 3042 | /* success -- return valid version number */ |
| 3043 | result = JNI_VERSION_1_4; |
| 3044 | |
| 3045 | bail: |
| 3046 | return result; |
| 3047 | } |