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