| 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 | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 17 | #define LOG_TAG "libRS_jni" |
| 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> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | |
| Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 26 | #include <SkBitmap.h> |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 27 | |
| Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 28 | #include <androidfw/Asset.h> |
| 29 | #include <androidfw/AssetManager.h> |
| 30 | #include <androidfw/ResourceTypes.h> |
| Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 31 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | #include "jni.h" |
| 33 | #include "JNIHelp.h" |
| 34 | #include "android_runtime/AndroidRuntime.h" |
| Jim Miller | ee95605 | 2010-08-19 18:56:00 -0700 | [diff] [blame] | 35 | #include "android_runtime/android_view_Surface.h" |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 36 | #include "android_runtime/android_util_AssetManager.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> |
| Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 42 | #include <gui/Surface.h> |
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 43 | #include <android_runtime/android_graphics_SurfaceTexture.h> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | |
| Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 45 | //#define LOG_API ALOGE |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | #define LOG_API(...) |
| 47 | |
| 48 | using namespace android; |
| 49 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 50 | #define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 51 | jint len = 0; \ |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 52 | void *ptr = nullptr; \ |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 53 | size_t typeBytes = 0; \ |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 54 | jint relFlag = 0; \ |
| 55 | if (readonly) { \ |
| 56 | /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \ |
| 57 | relFlag = JNI_ABORT; \ |
| 58 | } \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 59 | switch(dataType) { \ |
| 60 | case RS_TYPE_FLOAT_32: \ |
| 61 | len = _env->GetArrayLength((jfloatArray)data); \ |
| 62 | ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \ |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 63 | typeBytes = 4; \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 64 | fnc(__VA_ARGS__); \ |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 65 | _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 66 | return; \ |
| 67 | case RS_TYPE_FLOAT_64: \ |
| 68 | len = _env->GetArrayLength((jdoubleArray)data); \ |
| 69 | ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \ |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 70 | typeBytes = 8; \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 71 | fnc(__VA_ARGS__); \ |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 72 | _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 73 | return; \ |
| 74 | case RS_TYPE_SIGNED_8: \ |
| 75 | case RS_TYPE_UNSIGNED_8: \ |
| 76 | len = _env->GetArrayLength((jbyteArray)data); \ |
| 77 | ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \ |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 78 | typeBytes = 1; \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 79 | fnc(__VA_ARGS__); \ |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 80 | _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 81 | return; \ |
| 82 | case RS_TYPE_SIGNED_16: \ |
| 83 | case RS_TYPE_UNSIGNED_16: \ |
| 84 | len = _env->GetArrayLength((jshortArray)data); \ |
| 85 | ptr = _env->GetShortArrayElements((jshortArray)data, flag); \ |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 86 | typeBytes = 2; \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 87 | fnc(__VA_ARGS__); \ |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 88 | _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 89 | return; \ |
| 90 | case RS_TYPE_SIGNED_32: \ |
| 91 | case RS_TYPE_UNSIGNED_32: \ |
| 92 | len = _env->GetArrayLength((jintArray)data); \ |
| 93 | ptr = _env->GetIntArrayElements((jintArray)data, flag); \ |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 94 | typeBytes = 4; \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 95 | fnc(__VA_ARGS__); \ |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 96 | _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 97 | return; \ |
| 98 | case RS_TYPE_SIGNED_64: \ |
| 99 | case RS_TYPE_UNSIGNED_64: \ |
| 100 | len = _env->GetArrayLength((jlongArray)data); \ |
| 101 | ptr = _env->GetLongArrayElements((jlongArray)data, flag); \ |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 102 | typeBytes = 8; \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 103 | fnc(__VA_ARGS__); \ |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 104 | _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \ |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 105 | return; \ |
| 106 | default: \ |
| 107 | break; \ |
| 108 | } \ |
| 109 | } |
| 110 | |
| 111 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 112 | class AutoJavaStringToUTF8 { |
| 113 | public: |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 114 | AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 115 | fCStr = env->GetStringUTFChars(str, nullptr); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 116 | fLength = env->GetStringUTFLength(str); |
| 117 | } |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 118 | ~AutoJavaStringToUTF8() { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 119 | fEnv->ReleaseStringUTFChars(fJStr, fCStr); |
| 120 | } |
| 121 | const char* c_str() const { return fCStr; } |
| 122 | jsize length() const { return fLength; } |
| 123 | |
| 124 | private: |
| 125 | JNIEnv* fEnv; |
| 126 | jstring fJStr; |
| 127 | const char* fCStr; |
| 128 | jsize fLength; |
| 129 | }; |
| 130 | |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 131 | class AutoJavaStringArrayToUTF8 { |
| 132 | public: |
| 133 | AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) |
| 134 | : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 135 | mCStrings = nullptr; |
| 136 | mSizeArray = nullptr; |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 137 | if (stringsLength > 0) { |
| 138 | mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); |
| 139 | mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); |
| 140 | for (jsize ct = 0; ct < stringsLength; ct ++) { |
| 141 | jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 142 | mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr); |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 143 | mSizeArray[ct] = mEnv->GetStringUTFLength(s); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | ~AutoJavaStringArrayToUTF8() { |
| 148 | for (jsize ct=0; ct < mStringsLength; ct++) { |
| 149 | jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); |
| 150 | mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); |
| 151 | } |
| 152 | free(mCStrings); |
| 153 | free(mSizeArray); |
| 154 | } |
| 155 | const char **c_str() const { return mCStrings; } |
| 156 | size_t *c_str_len() const { return mSizeArray; } |
| 157 | jsize length() const { return mStringsLength; } |
| 158 | |
| 159 | private: |
| 160 | JNIEnv *mEnv; |
| 161 | jobjectArray mStrings; |
| 162 | const char **mCStrings; |
| 163 | size_t *mSizeArray; |
| 164 | jsize mStringsLength; |
| 165 | }; |
| 166 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 167 | // --------------------------------------------------------------------------- |
| 168 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 169 | static jfieldID gContextId = 0; |
| 170 | static jfieldID gNativeBitmapID = 0; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 171 | static jfieldID gTypeNativeCache = 0; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 172 | |
| 173 | static void _nInit(JNIEnv *_env, jclass _this) |
| 174 | { |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 175 | gContextId = _env->GetFieldID(_this, "mContext", "J"); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 176 | |
| 177 | jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 178 | gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J"); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 181 | // --------------------------------------------------------------------------- |
| 182 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 183 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 184 | nContextFinish(JNIEnv *_env, jobject _this, jlong con) |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 185 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 186 | LOG_API("nContextFinish, con(%p)", (RsContext)con); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 187 | rsContextFinish((RsContext)con); |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 191 | nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str) |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 192 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 193 | LOG_API("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 194 | jint len = _env->GetArrayLength(str); |
| 195 | jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 196 | rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 197 | _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); |
| 198 | } |
| 199 | |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 200 | static jstring |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 201 | nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj) |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 202 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 203 | LOG_API("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 204 | const char *name = nullptr; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 205 | rsaGetName((RsContext)con, (void *)obj, &name); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 206 | if(name == nullptr || strlen(name) == 0) { |
| 207 | return nullptr; |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 208 | } |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 209 | return _env->NewStringUTF(name); |
| 210 | } |
| 211 | |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 212 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 213 | nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj) |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 214 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 215 | LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 216 | rsObjDestroy((RsContext)con, (void *)obj); |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 219 | // --------------------------------------------------------------------------- |
| 220 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 221 | static jlong |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 222 | nDeviceCreate(JNIEnv *_env, jobject _this) |
| 223 | { |
| 224 | LOG_API("nDeviceCreate"); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 225 | return (jlong)(uintptr_t)rsDeviceCreate(); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static void |
| Tim Murray | 5eaf468 | 2014-01-10 11:25:52 -0800 | [diff] [blame] | 229 | nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 230 | { |
| 231 | LOG_API("nDeviceDestroy"); |
| 232 | return rsDeviceDestroy((RsDevice)dev); |
| 233 | } |
| 234 | |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 235 | static void |
| Tim Murray | 5eaf468 | 2014-01-10 11:25:52 -0800 | [diff] [blame] | 236 | nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value) |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 237 | { |
| 238 | LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); |
| 239 | return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); |
| 240 | } |
| 241 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 242 | static jlong |
| Tim Murray | 5eaf468 | 2014-01-10 11:25:52 -0800 | [diff] [blame] | 243 | nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 244 | { |
| 245 | LOG_API("nContextCreate"); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 246 | return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 249 | static jlong |
| Tim Murray | 5eaf468 | 2014-01-10 11:25:52 -0800 | [diff] [blame] | 250 | nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 251 | jint colorMin, jint colorPref, |
| 252 | jint alphaMin, jint alphaPref, |
| 253 | jint depthMin, jint depthPref, |
| 254 | jint stencilMin, jint stencilPref, |
| 255 | jint samplesMin, jint samplesPref, jfloat samplesQ, |
| 256 | jint dpi) |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 257 | { |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 258 | RsSurfaceConfig sc; |
| 259 | sc.alphaMin = alphaMin; |
| 260 | sc.alphaPref = alphaPref; |
| 261 | sc.colorMin = colorMin; |
| 262 | sc.colorPref = colorPref; |
| 263 | sc.depthMin = depthMin; |
| 264 | sc.depthPref = depthPref; |
| 265 | sc.samplesMin = samplesMin; |
| 266 | sc.samplesPref = samplesPref; |
| 267 | sc.samplesQ = samplesQ; |
| 268 | |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 269 | LOG_API("nContextCreateGL"); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 270 | return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 274 | nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p) |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 275 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 276 | LOG_API("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 277 | rsContextSetPriority((RsContext)con, p); |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
| 281 | |
| 282 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 283 | 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] | 284 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 285 | LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, width, height, (Surface *)wnd); |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 286 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 287 | ANativeWindow * window = nullptr; |
| 288 | if (wnd == nullptr) { |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 289 | |
| 290 | } else { |
| Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 291 | window = android_view_Surface_getNativeWindow(_env, wnd).get(); |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 294 | rsContextSetSurface((RsContext)con, width, height, window); |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 298 | nContextDestroy(JNIEnv *_env, jobject _this, jlong con) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 299 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 300 | LOG_API("nContextDestroy, con(%p)", (RsContext)con); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 301 | rsContextDestroy((RsContext)con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 304 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 305 | nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits) |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 306 | { |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 307 | LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); |
| 308 | rsContextDump((RsContext)con, bits); |
| 309 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 310 | |
| 311 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 312 | nContextPause(JNIEnv *_env, jobject _this, jlong con) |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 313 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 314 | LOG_API("nContextPause, con(%p)", (RsContext)con); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 315 | rsContextPause((RsContext)con); |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 319 | nContextResume(JNIEnv *_env, jobject _this, jlong con) |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 320 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 321 | LOG_API("nContextResume, con(%p)", (RsContext)con); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 322 | rsContextResume((RsContext)con); |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 325 | |
| 326 | static jstring |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 327 | nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con) |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 328 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 329 | LOG_API("nContextGetErrorMessage, con(%p)", (RsContext)con); |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 330 | char buf[1024]; |
| 331 | |
| 332 | size_t receiveLen; |
| 333 | uint32_t subID; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 334 | int id = rsContextGetMessage((RsContext)con, |
| Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 335 | buf, sizeof(buf), |
| 336 | &receiveLen, sizeof(receiveLen), |
| Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 337 | &subID, sizeof(subID)); |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 338 | if (!id && receiveLen) { |
| Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 339 | ALOGV("message receive buffer too small. %i", receiveLen); |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 340 | } |
| 341 | return _env->NewStringUTF(buf); |
| 342 | } |
| 343 | |
| Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 344 | static jint |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 345 | nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 346 | { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 347 | jint len = _env->GetArrayLength(data); |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 348 | LOG_API("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 349 | jint *ptr = _env->GetIntArrayElements(data, nullptr); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 350 | size_t receiveLen; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 351 | uint32_t subID; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 352 | int id = rsContextGetMessage((RsContext)con, |
| Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 353 | ptr, len * 4, |
| 354 | &receiveLen, sizeof(receiveLen), |
| Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 355 | &subID, sizeof(subID)); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 356 | if (!id && receiveLen) { |
| Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 357 | ALOGV("message receive buffer too small. %i", receiveLen); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 358 | } |
| 359 | _env->ReleaseIntArrayElements(data, ptr, 0); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 360 | return (jint)id; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static jint |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 364 | nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData) |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 365 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 366 | LOG_API("nContextPeekMessage, con(%p)", (RsContext)con); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 367 | jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr); |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 368 | size_t receiveLen; |
| 369 | uint32_t subID; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 370 | int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen), |
| Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 371 | &subID, sizeof(subID)); |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 372 | auxDataPtr[0] = (jint)subID; |
| 373 | auxDataPtr[1] = (jint)receiveLen; |
| 374 | _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 375 | return (jint)id; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 378 | static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con) |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 379 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 380 | LOG_API("nContextInitToClient, con(%p)", (RsContext)con); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 381 | rsContextInitToClient((RsContext)con); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 384 | static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con) |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 385 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 386 | LOG_API("nContextDeinitToClient, con(%p)", (RsContext)con); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 387 | rsContextDeinitToClient((RsContext)con); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 390 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 391 | nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data) |
| Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 392 | { |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 393 | jint *ptr = nullptr; |
| Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 394 | jint len = 0; |
| 395 | if (data) { |
| 396 | len = _env->GetArrayLength(data); |
| Stephen Hines | 4a043c1 | 2014-08-21 23:20:32 -0700 | [diff] [blame^] | 397 | ptr = _env->GetIntArrayElements(data, nullptr); |
| Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 398 | } |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 399 | LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 400 | rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int)); |
| Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 401 | if (data) { |
| 402 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 407 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 408 | static jlong |
| 409 | nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 410 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 411 | LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con, type, kind, norm, size); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 412 | return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, norm, size); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 415 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 416 | nElementCreate2(JNIEnv *_env, jobject _this, jlong con, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 417 | jlongArray _ids, jobjectArray _names, jintArray _arraySizes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 418 | { |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 419 | int fieldCount = _env->GetArrayLength(_ids); |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 420 | LOG_API("nElementCreate2, con(%p)", (RsContext)con); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 421 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 422 | jlong *jIds = _env->GetLongArrayElements(_ids, nullptr); |
| 423 | jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 424 | |
| 425 | RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement)); |
| 426 | uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t)); |
| 427 | |
| 428 | for(int i = 0; i < fieldCount; i ++) { |
| 429 | ids[i] = (RsElement)jIds[i]; |
| 430 | arraySizes[i] = (uint32_t)jArraySizes[i]; |
| 431 | } |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 432 | |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 433 | AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); |
| 434 | |
| 435 | const char **nameArray = names.c_str(); |
| 436 | size_t *sizeArray = names.c_str_len(); |
| 437 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 438 | jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 439 | (const RsElement *)ids, fieldCount, |
| Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 440 | nameArray, fieldCount * sizeof(size_t), sizeArray, |
| Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 441 | (const uint32_t *)arraySizes, fieldCount); |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 442 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 443 | free(ids); |
| 444 | free(arraySizes); |
| 445 | _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT); |
| 446 | _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT); |
| 447 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 448 | return (jlong)(uintptr_t)id; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 451 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 452 | nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData) |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 453 | { |
| 454 | int dataSize = _env->GetArrayLength(_elementData); |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 455 | LOG_API("nElementGetNativeData, con(%p)", (RsContext)con); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 456 | |
| 457 | // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements |
| 458 | assert(dataSize == 5); |
| 459 | |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 460 | uintptr_t elementData[5]; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 461 | rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 462 | |
| 463 | for(jint i = 0; i < dataSize; i ++) { |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 464 | const jint data = (jint)elementData[i]; |
| 465 | _env->SetIntArrayRegion(_elementData, i, 1, &data); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
| 469 | |
| 470 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 471 | nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 472 | jlongArray _IDs, |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 473 | jobjectArray _names, |
| 474 | jintArray _arraySizes) |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 475 | { |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 476 | uint32_t dataSize = _env->GetArrayLength(_IDs); |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 477 | LOG_API("nElementGetSubElements, con(%p)", (RsContext)con); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 478 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 479 | uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t)); |
| 480 | const char **names = (const char **)malloc(dataSize * sizeof(const char *)); |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 481 | uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t)); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 482 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 483 | rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 484 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 485 | for(uint32_t i = 0; i < dataSize; i++) { |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 486 | const jlong id = (jlong)(uintptr_t)ids[i]; |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 487 | const jint arraySize = (jint)arraySizes[i]; |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 488 | _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 489 | _env->SetLongArrayRegion(_IDs, i, 1, &id); |
| 490 | _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | free(ids); |
| 494 | free(names); |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 495 | free(arraySizes); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 498 | // ----------------------------------- |
| 499 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 500 | static jlong |
| 501 | nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid, |
| Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 502 | jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 503 | { |
| Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 504 | LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 505 | (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv); |
| Jason Sams | 3b9c52a | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 506 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 507 | return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 510 | static void |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 511 | nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData) |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 512 | { |
| 513 | // We are packing 6 items: mDimX; mDimY; mDimZ; |
| 514 | // mDimLOD; mDimFaces; mElement; into typeData |
| 515 | int elementCount = _env->GetArrayLength(_typeData); |
| 516 | |
| 517 | assert(elementCount == 6); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 518 | LOG_API("nTypeGetNativeData, con(%p)", (RsContext)con); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 519 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 520 | uintptr_t typeData[6]; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 521 | rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 522 | |
| 523 | for(jint i = 0; i < elementCount; i ++) { |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 524 | const jlong data = (jlong)(uintptr_t)typeData[i]; |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 525 | _env->SetLongArrayRegion(_typeData, i, 1, &data); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 529 | // ----------------------------------- |
| 530 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 531 | static jlong |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 532 | nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, jlong pointer) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 533 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 534 | LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", (RsContext)con, (RsElement)type, mips, usage, (void *)pointer); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 535 | return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uintptr_t)pointer); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 538 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 539 | nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits) |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 540 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 541 | LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, bits); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 542 | rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 545 | static jobject |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 546 | nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a) |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 547 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 548 | LOG_API("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 549 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 550 | IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a); |
| Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 551 | sp<IGraphicBufferProducer> bp = v; |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 552 | v->decStrong(nullptr); |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 553 | |
| Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 554 | jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp); |
| 555 | return o; |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 559 | nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur) |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 560 | { |
| Stephen Hines | 06883b7 | 2012-05-16 18:01:34 -0700 | [diff] [blame] | 561 | LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 562 | (RsContext)con, (RsAllocation)alloc, (Surface *)sur); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 563 | |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 564 | sp<Surface> s; |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 565 | if (sur != 0) { |
| Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 566 | s = android_view_Surface_getSurface(_env, sur); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 567 | } |
| 568 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 569 | rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, static_cast<ANativeWindow *>(s.get())); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 573 | nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc) |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 574 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 575 | LOG_API("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, alloc); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 576 | rsAllocationIoSend((RsContext)con, (RsAllocation)alloc); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 580 | nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc) |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 581 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 582 | LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, alloc); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 583 | rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | |
| 587 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 588 | nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc) |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 589 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 590 | LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 591 | rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc); |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 592 | } |
| 593 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 594 | static jlong |
| 595 | nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 596 | { |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 597 | SkBitmap const * nativeBitmap = |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 598 | (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 599 | const SkBitmap& bitmap(*nativeBitmap); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 600 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 601 | bitmap.lockPixels(); |
| 602 | const void* ptr = bitmap.getPixels(); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 603 | jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con, |
| Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 604 | (RsType)type, (RsAllocationMipmapControl)mip, |
| 605 | ptr, bitmap.getSize(), usage); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 606 | bitmap.unlockPixels(); |
| 607 | return id; |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 608 | } |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 609 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 610 | static jlong |
| 611 | nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) |
| Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 612 | { |
| 613 | SkBitmap const * nativeBitmap = |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 614 | (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); |
| Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 615 | const SkBitmap& bitmap(*nativeBitmap); |
| 616 | |
| 617 | bitmap.lockPixels(); |
| 618 | const void* ptr = bitmap.getPixels(); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 619 | jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con, |
| Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 620 | (RsType)type, (RsAllocationMipmapControl)mip, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 621 | (uint32_t)usage, (uintptr_t)ptr); |
| Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 622 | bitmap.unlockPixels(); |
| 623 | return id; |
| 624 | } |
| 625 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 626 | static jlong |
| 627 | nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 628 | { |
| 629 | SkBitmap const * nativeBitmap = |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 630 | (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 631 | const SkBitmap& bitmap(*nativeBitmap); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 632 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 633 | bitmap.lockPixels(); |
| 634 | const void* ptr = bitmap.getPixels(); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 635 | jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con, |
| Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 636 | (RsType)type, (RsAllocationMipmapControl)mip, |
| 637 | ptr, bitmap.getSize(), usage); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 638 | bitmap.unlockPixels(); |
| 639 | return id; |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 640 | } |
| 641 | |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 642 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 643 | nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 644 | { |
| 645 | SkBitmap const * nativeBitmap = |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 646 | (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 647 | const SkBitmap& bitmap(*nativeBitmap); |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 648 | int w = bitmap.width(); |
| 649 | int h = bitmap.height(); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 650 | |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 651 | bitmap.lockPixels(); |
| 652 | const void* ptr = bitmap.getPixels(); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 653 | rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 654 | 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
| Tim Murray | 38faea30 | 2012-11-27 14:55:08 -0800 | [diff] [blame] | 655 | w, h, ptr, bitmap.getSize(), 0); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 656 | bitmap.unlockPixels(); |
| 657 | } |
| 658 | |
| 659 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 660 | nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 661 | { |
| 662 | SkBitmap const * nativeBitmap = |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 663 | (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 664 | const SkBitmap& bitmap(*nativeBitmap); |
| 665 | |
| 666 | bitmap.lockPixels(); |
| 667 | void* ptr = bitmap.getPixels(); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 668 | rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize()); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 669 | bitmap.unlockPixels(); |
| Alex Sakhartchouk | 835b854 | 2011-07-20 14:33:10 -0700 | [diff] [blame] | 670 | bitmap.notifyPixelsChanged(); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 673 | static void ReleaseBitmapCallback(void *bmp) |
| 674 | { |
| 675 | SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; |
| 676 | nativeBitmap->unlockPixels(); |
| 677 | } |
| 678 | |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 679 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 680 | // 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] | 681 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 682 | nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 683 | jint count, jobject data, jint sizeBytes, jint dataType) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 684 | { |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 685 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 686 | LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)", |
| 687 | (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, dataType); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 688 | PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 691 | // Copies from the Java array data into the Allocation pointed to by alloc. |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 692 | static void |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 693 | // native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes); |
| 694 | nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, jint compIdx, jbyteArray data, jint sizeBytes) |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 695 | { |
| 696 | jint len = _env->GetArrayLength(data); |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 697 | LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 698 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 699 | rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx); |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 700 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 701 | } |
| 702 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 703 | // 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] | 704 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 705 | nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 706 | jint w, jint h, jobject data, jint sizeBytes, jint dataType) |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 707 | { |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 708 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| 709 | RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; |
| 710 | LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)", |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 711 | (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 712 | PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 715 | // Copies from the Allocation pointed to by srcAlloc into the Allocation |
| 716 | // pointed to by dstAlloc. |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 717 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 718 | nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 719 | jlong dstAlloc, jint dstXoff, jint dstYoff, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 720 | jint dstMip, jint dstFace, |
| 721 | jint width, jint height, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 722 | jlong srcAlloc, jint srcXoff, jint srcYoff, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 723 | jint srcMip, jint srcFace) |
| 724 | { |
| Jason Sams | 4c2e4c8 | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 725 | LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 726 | " dstMip(%i), dstFace(%i), width(%i), height(%i)," |
| 727 | " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 728 | (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 729 | width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); |
| 730 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 731 | rsAllocationCopy2DRange((RsContext)con, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 732 | (RsAllocation)dstAlloc, |
| 733 | dstXoff, dstYoff, |
| 734 | dstMip, dstFace, |
| 735 | width, height, |
| 736 | (RsAllocation)srcAlloc, |
| 737 | srcXoff, srcYoff, |
| 738 | srcMip, srcFace); |
| 739 | } |
| 740 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 741 | // 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] | 742 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 743 | nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod, |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 744 | jint w, jint h, jint d, jobject data, int sizeBytes, int dataType) |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 745 | { |
| Jason Sams | e729a94 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 746 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| 747 | LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)", |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 748 | (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 749 | PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true, (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] | 750 | } |
| 751 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 752 | // Copies from the Allocation pointed to by srcAlloc into the Allocation |
| 753 | // pointed to by dstAlloc. |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 754 | static void |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 755 | nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 756 | jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff, |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 757 | jint dstMip, |
| 758 | jint width, jint height, jint depth, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 759 | jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 760 | jint srcMip) |
| 761 | { |
| 762 | LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," |
| 763 | " dstMip(%i), width(%i), height(%i)," |
| 764 | " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 765 | (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, |
| 766 | width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip); |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 767 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 768 | rsAllocationCopy3DRange((RsContext)con, |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 769 | (RsAllocation)dstAlloc, |
| 770 | dstXoff, dstYoff, dstZoff, dstMip, |
| 771 | width, height, depth, |
| 772 | (RsAllocation)srcAlloc, |
| 773 | srcXoff, srcYoff, srcZoff, srcMip); |
| 774 | } |
| 775 | |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 776 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 777 | // 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] | 778 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 779 | nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType) |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 780 | { |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 781 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 782 | LOG_API("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 783 | PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 786 | // 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] | 787 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 788 | nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 789 | jint count, jobject data, int sizeBytes, int dataType) |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 790 | { |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 791 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 792 | LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)", |
| 793 | (RsContext)con, alloc, offset, count, sizeBytes, dataType); |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 794 | PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 795 | } |
| 796 | |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 797 | // 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] | 798 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 799 | nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 800 | jint w, jint h, jobject data, int sizeBytes, int dataType) |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 801 | { |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 802 | RsAllocation *alloc = (RsAllocation *)_alloc; |
| 803 | RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; |
| 804 | LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)", |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 805 | (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 806 | PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 807 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 808 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 809 | static jlong |
| 810 | nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a) |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 811 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 812 | LOG_API("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 813 | return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 816 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 817 | nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX) |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 818 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 819 | LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, (RsAllocation)alloc, dimX); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 820 | rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX); |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 823 | // ----------------------------------- |
| 824 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 825 | static jlong |
| 826 | nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset) |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 827 | { |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 828 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 829 | ALOGV("______nFileA3D %p", asset); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 830 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 831 | 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] | 832 | return id; |
| 833 | } |
| 834 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 835 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 836 | nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path) |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 837 | { |
| 838 | AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 839 | if (mgr == nullptr) { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | AutoJavaStringToUTF8 str(_env, _path); |
| 844 | Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 845 | if (asset == nullptr) { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 846 | return 0; |
| 847 | } |
| 848 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 849 | jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 850 | return id; |
| 851 | } |
| 852 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 853 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 854 | nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName) |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 855 | { |
| 856 | AutoJavaStringToUTF8 fileNameUTF(_env, fileName); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 857 | jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str()); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 858 | |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 859 | return id; |
| 860 | } |
| 861 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 862 | static jint |
| 863 | nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D) |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 864 | { |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 865 | int32_t numEntries = 0; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 866 | rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 867 | return (jint)numEntries; |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 871 | 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] | 872 | { |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 873 | ALOGV("______nFileA3D %p", (RsFile) fileA3D); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 874 | RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); |
| 875 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 876 | rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 877 | |
| 878 | for(jint i = 0; i < numEntries; i ++) { |
| 879 | _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); |
| 880 | _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); |
| 881 | } |
| 882 | |
| 883 | free(fileEntries); |
| 884 | } |
| 885 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 886 | static jlong |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 887 | nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index) |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 888 | { |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 889 | ALOGV("______nFileA3D %p", (RsFile) fileA3D); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 890 | 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] | 891 | return id; |
| 892 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 893 | |
| 894 | // ----------------------------------- |
| 895 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 896 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 897 | nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con, |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 898 | jstring fileName, jfloat fontSize, jint dpi) |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 899 | { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 900 | AutoJavaStringToUTF8 fileNameUTF(_env, fileName); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 901 | jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con, |
| Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 902 | fileNameUTF.c_str(), fileNameUTF.length(), |
| 903 | fontSize, dpi); |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 904 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 905 | return id; |
| 906 | } |
| 907 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 908 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 909 | nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 910 | jstring name, jfloat fontSize, jint dpi, jlong native_asset) |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 911 | { |
| 912 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
| 913 | AutoJavaStringToUTF8 nameUTF(_env, name); |
| 914 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 915 | jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con, |
| Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 916 | nameUTF.c_str(), nameUTF.length(), |
| 917 | fontSize, dpi, |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 918 | asset->getBuffer(false), asset->getLength()); |
| 919 | return id; |
| 920 | } |
| 921 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 922 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 923 | nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path, |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 924 | jfloat fontSize, jint dpi) |
| 925 | { |
| 926 | AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 927 | if (mgr == nullptr) { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | AutoJavaStringToUTF8 str(_env, _path); |
| 932 | Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 933 | if (asset == nullptr) { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 934 | return 0; |
| 935 | } |
| 936 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 937 | jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con, |
| Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 938 | str.c_str(), str.length(), |
| 939 | fontSize, dpi, |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 940 | asset->getBuffer(false), asset->getLength()); |
| 941 | delete asset; |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 942 | return id; |
| 943 | } |
| 944 | |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 945 | // ----------------------------------- |
| 946 | |
| 947 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 948 | 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] | 949 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 950 | LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 951 | rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 955 | 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] | 956 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 957 | LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 958 | rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 961 | static jint |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 962 | nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 963 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 964 | LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 965 | int value = 0; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 966 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 967 | return value; |
| 968 | } |
| 969 | |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 970 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 971 | 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] | 972 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 973 | LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 974 | rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val); |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 978 | 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] | 979 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 980 | LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, (void *)script, slot, val); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 981 | rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val); |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 984 | static jlong |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 985 | nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 986 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 987 | LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 988 | jlong value = 0; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 989 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 990 | return value; |
| 991 | } |
| 992 | |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 993 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 994 | 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] | 995 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 996 | LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, slot, val); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 997 | rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1000 | static jfloat |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1001 | nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1002 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1003 | LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1004 | jfloat value = 0; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1005 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1006 | return value; |
| 1007 | } |
| 1008 | |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1009 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1010 | 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] | 1011 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1012 | LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, slot, val); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1013 | rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val); |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1016 | static jdouble |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1017 | nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1018 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1019 | LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1020 | jdouble value = 0; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1021 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1022 | return value; |
| 1023 | } |
| 1024 | |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 1025 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1026 | 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] | 1027 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1028 | LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1029 | jint len = _env->GetArrayLength(data); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1030 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1031 | rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1032 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1033 | } |
| 1034 | |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1035 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1036 | 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] | 1037 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1038 | LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1039 | jint len = _env->GetArrayLength(data); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1040 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1041 | rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len); |
| Stephen Hines | 414fa2c | 2014-04-17 01:02:42 -0700 | [diff] [blame] | 1042 | _env->ReleaseByteArrayElements(data, ptr, 0); |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1046 | nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jlong elem, jintArray dims) |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1047 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1048 | LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1049 | jint len = _env->GetArrayLength(data); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1050 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1051 | jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1052 | jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1053 | rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem, |
| Stephen Hines | bc5d3ee | 2014-06-25 00:03:39 -0700 | [diff] [blame] | 1054 | (const uint32_t*) dimsPtr, dimsLen); |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 1055 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1056 | _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); |
| 1057 | } |
| 1058 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1059 | |
| 1060 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1061 | nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1062 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1063 | LOG_API("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script); |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1064 | |
| 1065 | jint length = _env->GetArrayLength(timeZone); |
| 1066 | jbyte* timeZone_ptr; |
| 1067 | timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); |
| 1068 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1069 | rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length); |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1070 | |
| 1071 | if (timeZone_ptr) { |
| 1072 | _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 1076 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1077 | nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot) |
| Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 1078 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1079 | LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1080 | rsScriptInvoke((RsContext)con, (RsScript)obj, slot); |
| Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1084 | 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] | 1085 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1086 | LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1087 | jint len = _env->GetArrayLength(data); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1088 | jbyte *ptr = _env->GetByteArrayElements(data, nullptr); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1089 | rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1090 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1091 | } |
| 1092 | |
| Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 1093 | static void |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1094 | nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, |
| 1095 | jlongArray ains, jlong aout, jbyteArray params, |
| 1096 | jintArray limits) |
| Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 1097 | { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1098 | LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, |
| 1099 | (void *)script, slot); |
| Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 1100 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1101 | jint in_len = 0; |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1102 | jlong *in_ptr = nullptr; |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1103 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1104 | RsAllocation *in_allocs = nullptr; |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1105 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1106 | if (ains != nullptr) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1107 | in_len = _env->GetArrayLength(ains); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1108 | in_ptr = _env->GetLongArrayElements(ains, nullptr); |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1109 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1110 | if (sizeof(RsAllocation) == sizeof(jlong)) { |
| 1111 | in_allocs = (RsAllocation*)in_ptr; |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1112 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1113 | } else { |
| 1114 | // Convert from 64-bit jlong types to the native pointer type. |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1115 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1116 | in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation)); |
| 1117 | |
| 1118 | for (int index = in_len; --index >= 0;) { |
| 1119 | in_allocs[index] = (RsAllocation)in_ptr[index]; |
| 1120 | } |
| 1121 | } |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1124 | jint param_len = 0; |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1125 | jbyte *param_ptr = nullptr; |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1126 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1127 | if (params != nullptr) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1128 | param_len = _env->GetArrayLength(params); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1129 | param_ptr = _env->GetByteArrayElements(params, nullptr); |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1132 | RsScriptCall sc, *sca = nullptr; |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1133 | uint32_t sc_size = 0; |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1134 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1135 | jint limit_len = 0; |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1136 | jint *limit_ptr = nullptr; |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1137 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1138 | if (limits != nullptr) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1139 | limit_len = _env->GetArrayLength(limits); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1140 | limit_ptr = _env->GetIntArrayElements(limits, nullptr); |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1141 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1142 | assert(limit_len == 6); |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1143 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1144 | sc.xStart = limit_ptr[0]; |
| 1145 | sc.xEnd = limit_ptr[1]; |
| 1146 | sc.yStart = limit_ptr[2]; |
| 1147 | sc.yEnd = limit_ptr[3]; |
| 1148 | sc.zStart = limit_ptr[4]; |
| 1149 | sc.zEnd = limit_ptr[5]; |
| 1150 | sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1151 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1152 | sca = ≻ |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1155 | rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, |
| 1156 | in_allocs, in_len, (RsAllocation)aout, |
| 1157 | param_ptr, param_len, sca, sc_size); |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1158 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1159 | if (ains != nullptr) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1160 | _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1163 | if (params != nullptr) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1164 | _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); |
| 1165 | } |
| 1166 | |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1167 | if (limits != nullptr) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1168 | _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); |
| 1169 | } |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1172 | // ----------------------------------- |
| 1173 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1174 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1175 | nScriptCCreate(JNIEnv *_env, jobject _this, jlong con, |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1176 | jstring resName, jstring cacheDir, |
| 1177 | jbyteArray scriptRef, jint length) |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1178 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1179 | LOG_API("nScriptCCreate, con(%p)", (RsContext)con); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1180 | |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1181 | AutoJavaStringToUTF8 resNameUTF(_env, resName); |
| 1182 | AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1183 | jlong ret = 0; |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1184 | jbyte* script_ptr = nullptr; |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1185 | jint _exception = 0; |
| 1186 | jint remaining; |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1187 | if (!scriptRef) { |
| 1188 | _exception = 1; |
| Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 1189 | //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1190 | goto exit; |
| 1191 | } |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1192 | if (length < 0) { |
| 1193 | _exception = 1; |
| Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 1194 | //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1195 | goto exit; |
| 1196 | } |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1197 | remaining = _env->GetArrayLength(scriptRef); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1198 | if (remaining < length) { |
| 1199 | _exception = 1; |
| Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 1200 | //jniThrowException(_env, "java/lang/IllegalArgumentException", |
| 1201 | // "length > script.length - offset"); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1202 | goto exit; |
| 1203 | } |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1204 | script_ptr = (jbyte *) |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1205 | _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1206 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1207 | //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length); |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1208 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1209 | ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con, |
| Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 1210 | resNameUTF.c_str(), resNameUTF.length(), |
| 1211 | cacheDirUTF.c_str(), cacheDirUTF.length(), |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1212 | (const char *)script_ptr, length); |
| Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 1213 | |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1214 | exit: |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1215 | if (script_ptr) { |
| 1216 | _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1217 | _exception ? JNI_ABORT: 0); |
| 1218 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1219 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1220 | return (jlong)(uintptr_t)ret; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1223 | static jlong |
| 1224 | nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid) |
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 1225 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1226 | LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1227 | return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid); |
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1230 | static jlong |
| 1231 | 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] | 1232 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1233 | LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, (void *)sid, slot, sig); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1234 | return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig); |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1237 | static jlong |
| 1238 | nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1239 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1240 | LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1241 | return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot); |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1244 | static jlong |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1245 | nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src, |
| 1246 | jlongArray _dstk, jlongArray _dstf, jlongArray _types) |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1247 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1248 | LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con); |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1249 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1250 | jint kernelsLen = _env->GetArrayLength(_kernels); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1251 | jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1252 | RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen); |
| 1253 | for(int i = 0; i < kernelsLen; ++i) { |
| 1254 | kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i]; |
| 1255 | } |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1256 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1257 | jint srcLen = _env->GetArrayLength(_src); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1258 | jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1259 | RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen); |
| 1260 | for(int i = 0; i < srcLen; ++i) { |
| 1261 | srcPtr[i] = (RsScriptKernelID)jSrcPtr[i]; |
| 1262 | } |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1263 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1264 | jint dstkLen = _env->GetArrayLength(_dstk); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1265 | jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1266 | RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen); |
| 1267 | for(int i = 0; i < dstkLen; ++i) { |
| 1268 | dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i]; |
| 1269 | } |
| 1270 | |
| 1271 | jint dstfLen = _env->GetArrayLength(_dstf); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1272 | jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1273 | RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen); |
| 1274 | for(int i = 0; i < dstfLen; ++i) { |
| 1275 | dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i]; |
| 1276 | } |
| 1277 | |
| 1278 | jint typesLen = _env->GetArrayLength(_types); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1279 | jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1280 | RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen); |
| 1281 | for(int i = 0; i < typesLen; ++i) { |
| 1282 | typesPtr[i] = (RsType)jTypesPtr[i]; |
| 1283 | } |
| 1284 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1285 | jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1286 | (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID), |
| 1287 | (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID), |
| 1288 | (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID), |
| 1289 | (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID), |
| 1290 | (RsType *)typesPtr, typesLen * sizeof(RsType)); |
| 1291 | |
| 1292 | free(kernelsPtr); |
| 1293 | free(srcPtr); |
| 1294 | free(dstkPtr); |
| 1295 | free(dstfPtr); |
| 1296 | free(typesPtr); |
| 1297 | _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0); |
| 1298 | _env->ReleaseLongArrayElements(_src, jSrcPtr, 0); |
| 1299 | _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0); |
| 1300 | _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0); |
| 1301 | _env->ReleaseLongArrayElements(_types, jTypesPtr, 0); |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1302 | return id; |
| 1303 | } |
| 1304 | |
| 1305 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1306 | 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] | 1307 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1308 | LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1309 | (void *)gid, (void *)kid, (void *)alloc); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1310 | rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1314 | 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] | 1315 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1316 | LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1317 | (void *)gid, (void *)kid, (void *)alloc); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1318 | rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1322 | nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid) |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1323 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1324 | LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1325 | rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid); |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1328 | // --------------------------------------------------------------------------- |
| 1329 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1330 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1331 | nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con, |
| Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 1332 | jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA, |
| 1333 | jboolean depthMask, jboolean ditherEnable, |
| 1334 | jint srcFunc, jint destFunc, |
| 1335 | jint depthFunc) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1336 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1337 | LOG_API("nProgramStoreCreate, con(%p)", (RsContext)con); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1338 | return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA, |
| Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 1339 | depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc, |
| 1340 | (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1343 | // --------------------------------------------------------------------------- |
| 1344 | |
| 1345 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1346 | 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] | 1347 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1348 | LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, (RsProgramVertex)vpv, slot, (RsAllocation)a); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1349 | rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1350 | } |
| Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 1351 | |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1352 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1353 | 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] | 1354 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1355 | LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1356 | rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | static void |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1360 | 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] | 1361 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1362 | LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1363 | rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1366 | // --------------------------------------------------------------------------- |
| 1367 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1368 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1369 | nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1370 | jobjectArray texNames, jlongArray params) |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 1371 | { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1372 | AutoJavaStringToUTF8 shaderUTF(_env, shader); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1373 | jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 1374 | jint paramLen = _env->GetArrayLength(params); |
| 1375 | |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 1376 | int texCount = _env->GetArrayLength(texNames); |
| 1377 | AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); |
| 1378 | const char ** nameArray = names.c_str(); |
| 1379 | size_t* sizeArray = names.c_str_len(); |
| 1380 | |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1381 | LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 1382 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1383 | uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen); |
| 1384 | for(int i = 0; i < paramLen; ++i) { |
| 1385 | paramPtr[i] = (uintptr_t)jParamPtr[i]; |
| 1386 | } |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1387 | 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] | 1388 | nameArray, texCount, sizeArray, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1389 | paramPtr, paramLen); |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 1390 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1391 | free(paramPtr); |
| 1392 | _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 1393 | return ret; |
| 1394 | } |
| 1395 | |
| 1396 | |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1397 | // --------------------------------------------------------------------------- |
| 1398 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1399 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1400 | nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1401 | jobjectArray texNames, jlongArray params) |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1402 | { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1403 | AutoJavaStringToUTF8 shaderUTF(_env, shader); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1404 | jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1405 | jint paramLen = _env->GetArrayLength(params); |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1406 | |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1407 | LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1408 | |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 1409 | int texCount = _env->GetArrayLength(texNames); |
| 1410 | AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); |
| 1411 | const char ** nameArray = names.c_str(); |
| 1412 | size_t* sizeArray = names.c_str_len(); |
| 1413 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1414 | uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen); |
| 1415 | for(int i = 0; i < paramLen; ++i) { |
| 1416 | paramPtr[i] = (uintptr_t)jParamPtr[i]; |
| 1417 | } |
| 1418 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1419 | 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] | 1420 | nameArray, texCount, sizeArray, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1421 | paramPtr, paramLen); |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 1422 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1423 | free(paramPtr); |
| 1424 | _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1425 | return ret; |
| 1426 | } |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1427 | |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1428 | // --------------------------------------------------------------------------- |
| 1429 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1430 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1431 | nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull) |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1432 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1433 | LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, pointSprite, cull); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1434 | return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull); |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1437 | |
| 1438 | // --------------------------------------------------------------------------- |
| 1439 | |
| 1440 | static void |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1441 | nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1442 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1443 | LOG_API("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1444 | rsContextBindRootScript((RsContext)con, (RsScript)script); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | static void |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1448 | nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1449 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1450 | LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1451 | rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | static void |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1455 | nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1456 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1457 | LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, (RsProgramFragment)pf); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1458 | rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1461 | static void |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1462 | nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf) |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1463 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1464 | LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1465 | rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf); |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1468 | static void |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1469 | nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf) |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1470 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1471 | LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1472 | rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf); |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1475 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1476 | // --------------------------------------------------------------------------- |
| 1477 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1478 | static jlong |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1479 | nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter, |
| Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 1480 | jint wrapS, jint wrapT, jint wrapR, jfloat aniso) |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1481 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1482 | LOG_API("nSamplerCreate, con(%p)", (RsContext)con); |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1483 | return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con, |
| Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 1484 | (RsSamplerValue)magFilter, |
| 1485 | (RsSamplerValue)minFilter, |
| 1486 | (RsSamplerValue)wrapS, |
| 1487 | (RsSamplerValue)wrapT, |
| 1488 | (RsSamplerValue)wrapR, |
| 1489 | aniso); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1492 | // --------------------------------------------------------------------------- |
| 1493 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1494 | static jlong |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1495 | nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1496 | LOG_API("nPathCreate, con(%p)", (RsContext)con); |
| Jason Sams | f15ed01 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 1497 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1498 | jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1499 | (RsAllocation)_vtx, |
| 1500 | (RsAllocation)_loop, q); |
| Jason Sams | f15ed01 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 1501 | return id; |
| 1502 | } |
| 1503 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1504 | static jlong |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1505 | 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] | 1506 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1507 | LOG_API("nMeshCreate, con(%p)", (RsContext)con); |
| Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 1508 | |
| 1509 | jint vtxLen = _env->GetArrayLength(_vtx); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1510 | jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1511 | RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen); |
| 1512 | for(int i = 0; i < vtxLen; ++i) { |
| 1513 | vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i]; |
| 1514 | } |
| 1515 | |
| Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 1516 | jint idxLen = _env->GetArrayLength(_idx); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1517 | jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr); |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1518 | RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen); |
| 1519 | for(int i = 0; i < idxLen; ++i) { |
| 1520 | idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i]; |
| 1521 | } |
| 1522 | |
| Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 1523 | jint primLen = _env->GetArrayLength(_prim); |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1524 | jint *primPtr = _env->GetIntArrayElements(_prim, nullptr); |
| Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 1525 | |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1526 | jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con, |
| Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 1527 | (RsAllocation *)vtxPtr, vtxLen, |
| 1528 | (RsAllocation *)idxPtr, idxLen, |
| 1529 | (uint32_t *)primPtr, primLen); |
| 1530 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1531 | free(vtxPtr); |
| 1532 | free(idxPtr); |
| 1533 | _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0); |
| 1534 | _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0); |
| Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 1535 | _env->ReleaseIntArrayElements(_prim, primPtr, 0); |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1536 | return id; |
| 1537 | } |
| 1538 | |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1539 | static jint |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1540 | nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1541 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1542 | LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1543 | jint vtxCount = 0; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1544 | rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1545 | return vtxCount; |
| 1546 | } |
| 1547 | |
| 1548 | static jint |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1549 | nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1550 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1551 | LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1552 | jint idxCount = 0; |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1553 | rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1554 | return idxCount; |
| 1555 | } |
| 1556 | |
| 1557 | static void |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1558 | 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] | 1559 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1560 | LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1561 | |
| 1562 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1563 | rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1564 | |
| 1565 | for(jint i = 0; i < numVtxIDs; i ++) { |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1566 | const jlong alloc = (jlong)(uintptr_t)allocs[i]; |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1567 | _env->SetLongArrayRegion(_ids, i, 1, &alloc); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | free(allocs); |
| 1571 | } |
| 1572 | |
| 1573 | static void |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1574 | 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] | 1575 | { |
| Tim Murray | 71a01b8 | 2014-01-07 15:36:19 -0800 | [diff] [blame] | 1576 | LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1577 | |
| 1578 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); |
| 1579 | uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); |
| 1580 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1581 | rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1582 | |
| 1583 | for(jint i = 0; i < numIndices; i ++) { |
| Tim Murray | 3aa89c1 | 2014-08-18 17:51:22 -0700 | [diff] [blame] | 1584 | const jlong alloc = (jlong)(uintptr_t)allocs[i]; |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1585 | const jint prim = (jint)prims[i]; |
| 1586 | _env->SetLongArrayRegion(_idxIds, i, 1, &alloc); |
| 1587 | _env->SetIntArrayRegion(_primitives, i, 1, &prim); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | free(allocs); |
| 1591 | free(prims); |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
| Tim Murray | 56f9e6f | 2014-05-16 11:47:26 -0700 | [diff] [blame] | 1594 | static jint |
| 1595 | nSystemGetPointerSize(JNIEnv *_env, jobject _this) { |
| 1596 | return (jint)sizeof(void*); |
| 1597 | } |
| 1598 | |
| 1599 | |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1600 | // --------------------------------------------------------------------------- |
| 1601 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1602 | |
| Jason Sams | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 1603 | static const char *classPathName = "android/renderscript/RenderScript"; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1604 | |
| 1605 | static JNINativeMethod methods[] = { |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1606 | {"_nInit", "()V", (void*)_nInit }, |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 1607 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1608 | {"nDeviceCreate", "()J", (void*)nDeviceCreate }, |
| 1609 | {"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy }, |
| 1610 | {"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig }, |
| 1611 | {"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage }, |
| 1612 | {"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage }, |
| 1613 | {"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage }, |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1614 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1615 | {"nContextInitToClient", "(J)V", (void*)nContextInitToClient }, |
| 1616 | {"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1617 | |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1618 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1619 | // All methods below are thread protected in java. |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1620 | {"rsnContextCreate", "(JIII)J", (void*)nContextCreate }, |
| 1621 | {"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL }, |
| 1622 | {"rsnContextFinish", "(J)V", (void*)nContextFinish }, |
| 1623 | {"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority }, |
| 1624 | {"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface }, |
| 1625 | {"rsnContextDestroy", "(J)V", (void*)nContextDestroy }, |
| 1626 | {"rsnContextDump", "(JI)V", (void*)nContextDump }, |
| 1627 | {"rsnContextPause", "(J)V", (void*)nContextPause }, |
| 1628 | {"rsnContextResume", "(J)V", (void*)nContextResume }, |
| 1629 | {"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage }, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1630 | {"rsnAssignName", "(JJ[B)V", (void*)nAssignName }, |
| 1631 | {"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName }, |
| 1632 | {"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy }, |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 1633 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1634 | {"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile }, |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1635 | {"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream }, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1636 | {"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset }, |
| 1637 | {"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries }, |
| 1638 | {"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1639 | {"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1640 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1641 | {"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile }, |
| 1642 | {"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream }, |
| 1643 | {"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1644 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1645 | {"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate }, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1646 | {"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 }, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1647 | {"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData }, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1648 | {"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1649 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1650 | {"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate }, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1651 | {"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1652 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1653 | {"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped }, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1654 | {"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap }, |
| 1655 | {"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation }, |
| 1656 | {"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap }, |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1657 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1658 | {"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, |
| 1659 | {"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1660 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1661 | {"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll }, |
| 1662 | {"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface }, |
| 1663 | {"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface }, |
| 1664 | {"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend }, |
| 1665 | {"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive }, |
| 1666 | {"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D }, |
| 1667 | {"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D }, |
| 1668 | {"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D }, |
| 1669 | {"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc }, |
| 1670 | {"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D }, |
| 1671 | {"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc }, |
| 1672 | {"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead }, |
| 1673 | {"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D }, |
| 1674 | {"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D }, |
| 1675 | {"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType}, |
| 1676 | {"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D }, |
| 1677 | {"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps }, |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1678 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1679 | {"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation }, |
| 1680 | {"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, |
| 1681 | {"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, |
| 1682 | {"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 1683 | |
| 1684 | {"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach }, |
| 1685 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1686 | {"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, |
| 1687 | {"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI }, |
| 1688 | {"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, |
| 1689 | {"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ }, |
| 1690 | {"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF }, |
| 1691 | {"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF }, |
| 1692 | {"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD }, |
| 1693 | {"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD }, |
| 1694 | {"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV }, |
| 1695 | {"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV }, |
| 1696 | {"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE }, |
| 1697 | {"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1698 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1699 | {"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate }, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1700 | {"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate }, |
| 1701 | {"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate }, |
| 1702 | {"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate }, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1703 | {"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate }, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1704 | {"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput }, |
| 1705 | {"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput }, |
| 1706 | {"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute }, |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1707 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1708 | {"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1709 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1710 | {"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants }, |
| 1711 | {"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture }, |
| 1712 | {"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler }, |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1713 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1714 | {"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate }, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1715 | {"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate }, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1716 | {"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1717 | |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 1718 | {"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript }, |
| 1719 | {"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore }, |
| 1720 | {"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment }, |
| 1721 | {"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex }, |
| 1722 | {"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster }, |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1723 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1724 | {"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate }, |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1725 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1726 | {"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate }, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1727 | {"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1728 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1729 | {"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount }, |
| 1730 | {"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount }, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 1731 | {"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices }, |
| 1732 | {"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices }, |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1733 | |
| Tim Murray | 56f9e6f | 2014-05-16 11:47:26 -0700 | [diff] [blame] | 1734 | {"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1735 | }; |
| 1736 | |
| 1737 | static int registerFuncs(JNIEnv *_env) |
| 1738 | { |
| 1739 | return android::AndroidRuntime::registerNativeMethods( |
| 1740 | _env, classPathName, methods, NELEM(methods)); |
| 1741 | } |
| 1742 | |
| 1743 | // --------------------------------------------------------------------------- |
| 1744 | |
| 1745 | jint JNI_OnLoad(JavaVM* vm, void* reserved) |
| 1746 | { |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1747 | JNIEnv* env = nullptr; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1748 | jint result = -1; |
| 1749 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1750 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
| Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1751 | ALOGE("ERROR: GetEnv failed\n"); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1752 | goto bail; |
| 1753 | } |
| Chris Wailes | 488230c3 | 2014-08-14 11:22:40 -0700 | [diff] [blame] | 1754 | assert(env != nullptr); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1755 | |
| 1756 | if (registerFuncs(env) < 0) { |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 1757 | ALOGE("ERROR: Renderscript native registration failed\n"); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1758 | goto bail; |
| 1759 | } |
| 1760 | |
| 1761 | /* success -- return valid version number */ |
| 1762 | result = JNI_VERSION_1_4; |
| 1763 | |
| 1764 | bail: |
| 1765 | return result; |
| 1766 | } |