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