| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 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 | |
| Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 26 | #include <surfaceflinger/Surface.h> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 28 | #include <core/SkBitmap.h> |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 29 | #include <core/SkPixelRef.h> |
| 30 | #include <core/SkStream.h> |
| 31 | #include <core/SkTemplates.h> |
| 32 | #include <images/SkImageDecoder.h> |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 33 | |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 34 | #include <utils/Asset.h> |
| 35 | #include <utils/ResourceTypes.h> |
| Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 36 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | #include "jni.h" |
| 38 | #include "JNIHelp.h" |
| 39 | #include "android_runtime/AndroidRuntime.h" |
| 40 | |
| Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 41 | #include <RenderScript.h> |
| 42 | #include <RenderScriptEnv.h> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 43 | |
| 44 | //#define LOG_API LOGE |
| 45 | #define LOG_API(...) |
| 46 | |
| 47 | using namespace android; |
| 48 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 49 | // --------------------------------------------------------------------------- |
| 50 | |
| 51 | static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) |
| 52 | { |
| 53 | jclass npeClazz = env->FindClass(exc); |
| 54 | env->ThrowNew(npeClazz, msg); |
| 55 | } |
| 56 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 57 | static jfieldID gContextId = 0; |
| 58 | static jfieldID gNativeBitmapID = 0; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 59 | static jfieldID gTypeNativeCache = 0; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 60 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 61 | static RsElement g_A_8 = NULL; |
| 62 | static RsElement g_RGBA_4444 = NULL; |
| 63 | static RsElement g_RGBA_8888 = NULL; |
| 64 | static RsElement g_RGB_565 = NULL; |
| 65 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | static void _nInit(JNIEnv *_env, jclass _this) |
| 67 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 68 | gContextId = _env->GetFieldID(_this, "mContext", "I"); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 69 | |
| 70 | jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); |
| 71 | gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 72 | |
| 73 | jclass typeClass = _env->FindClass("android/renderscript/Type"); |
| 74 | gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I"); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 77 | static void nInitElements(JNIEnv *_env, jobject _this, jint a8, jint rgba4444, jint rgba8888, jint rgb565) |
| 78 | { |
| 79 | g_A_8 = reinterpret_cast<RsElement>(a8); |
| 80 | g_RGBA_4444 = reinterpret_cast<RsElement>(rgba4444); |
| 81 | g_RGBA_8888 = reinterpret_cast<RsElement>(rgba8888); |
| 82 | g_RGB_565 = reinterpret_cast<RsElement>(rgb565); |
| 83 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 84 | |
| 85 | // --------------------------------------------------------------------------- |
| 86 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 87 | static void |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 88 | nContextFinish(JNIEnv *_env, jobject _this) |
| 89 | { |
| 90 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 91 | LOG_API("nContextFinish, con(%p)", con); |
| 92 | rsContextFinish(con); |
| 93 | } |
| 94 | |
| 95 | static void |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 96 | nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str) |
| 97 | { |
| 98 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 99 | LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 100 | |
| 101 | jint len = _env->GetArrayLength(str); |
| 102 | jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 103 | rsAssignName(con, (void *)obj, (const char *)cptr, len); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 104 | _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); |
| 105 | } |
| 106 | |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame^] | 107 | static jstring |
| 108 | nGetName(JNIEnv *_env, jobject _this, jint obj) |
| 109 | { |
| 110 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 111 | LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj); |
| 112 | |
| 113 | const char *name = NULL; |
| 114 | rsGetName(con, (void *)obj, &name); |
| 115 | return _env->NewStringUTF(name); |
| 116 | } |
| 117 | |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 118 | static void |
| 119 | nObjDestroy(JNIEnv *_env, jobject _this, jint obj) |
| 120 | { |
| 121 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 122 | LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); |
| 123 | rsObjDestroy(con, (void *)obj); |
| 124 | } |
| 125 | |
| Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 126 | static void |
| 127 | nObjDestroyOOB(JNIEnv *_env, jobject _this, jint obj) |
| 128 | { |
| 129 | // This function only differs from nObjDestroy in that it calls the |
| 130 | // special Out Of Band version of ObjDestroy which is thread safe. |
| 131 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 132 | LOG_API("nObjDestroyOOB, con(%p) obj(%p)", con, (void *)obj); |
| 133 | rsObjDestroyOOB(con, (void *)obj); |
| 134 | } |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 135 | |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 136 | static jint |
| 137 | nFileOpen(JNIEnv *_env, jobject _this, jbyteArray str) |
| 138 | { |
| 139 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 140 | LOG_API("nFileOpen, con(%p)", con); |
| 141 | |
| 142 | jint len = _env->GetArrayLength(str); |
| 143 | jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 144 | jint ret = (jint)rsFileOpen(con, (const char *)cptr, len); |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 145 | _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); |
| 146 | return ret; |
| 147 | } |
| 148 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 149 | // --------------------------------------------------------------------------- |
| 150 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 151 | static jint |
| 152 | nDeviceCreate(JNIEnv *_env, jobject _this) |
| 153 | { |
| 154 | LOG_API("nDeviceCreate"); |
| 155 | return (jint)rsDeviceCreate(); |
| 156 | } |
| 157 | |
| 158 | static void |
| 159 | nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) |
| 160 | { |
| 161 | LOG_API("nDeviceDestroy"); |
| 162 | return rsDeviceDestroy((RsDevice)dev); |
| 163 | } |
| 164 | |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 165 | static void |
| 166 | nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) |
| 167 | { |
| 168 | LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); |
| 169 | return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); |
| 170 | } |
| 171 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 172 | static jint |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 173 | nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 174 | { |
| 175 | LOG_API("nContextCreate"); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 176 | return (jint)rsContextCreate((RsDevice)dev, ver); |
| 177 | } |
| 178 | |
| 179 | static jint |
| 180 | nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jboolean useDepth) |
| 181 | { |
| 182 | LOG_API("nContextCreateGL"); |
| 183 | return (jint)rsContextCreateGL((RsDevice)dev, ver, useDepth); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static void |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 187 | nContextSetPriority(JNIEnv *_env, jobject _this, jint p) |
| 188 | { |
| 189 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 190 | LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p); |
| 191 | rsContextSetPriority(con, p); |
| 192 | } |
| 193 | |
| 194 | |
| 195 | |
| 196 | static void |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 197 | nContextSetSurface(JNIEnv *_env, jobject _this, jint width, jint height, jobject wnd) |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 198 | { |
| 199 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 200 | 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] | 201 | |
| 202 | Surface * window = NULL; |
| 203 | if (wnd == NULL) { |
| 204 | |
| 205 | } else { |
| 206 | jclass surface_class = _env->FindClass("android/view/Surface"); |
| Mathias Agopian | 8b13832 | 2010-04-12 16:22:15 -0700 | [diff] [blame] | 207 | jfieldID surfaceFieldID = _env->GetFieldID(surface_class, ANDROID_VIEW_SURFACE_JNI_ID, "I"); |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 208 | window = (Surface*)_env->GetIntField(wnd, surfaceFieldID); |
| 209 | } |
| 210 | |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 211 | rsContextSetSurface(con, width, height, window); |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 215 | nContextDestroy(JNIEnv *_env, jobject _this, jint con) |
| 216 | { |
| 217 | LOG_API("nContextDestroy, con(%p)", (RsContext)con); |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 218 | rsContextDestroy((RsContext)con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 221 | static void |
| 222 | nContextDump(JNIEnv *_env, jobject _this, jint bits) |
| 223 | { |
| 224 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 225 | LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); |
| 226 | rsContextDump((RsContext)con, bits); |
| 227 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 228 | |
| 229 | static void |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 230 | nContextPause(JNIEnv *_env, jobject _this) |
| 231 | { |
| 232 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 233 | LOG_API("nContextPause, con(%p)", con); |
| 234 | rsContextPause(con); |
| 235 | } |
| 236 | |
| 237 | static void |
| 238 | nContextResume(JNIEnv *_env, jobject _this) |
| 239 | { |
| 240 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 241 | LOG_API("nContextResume, con(%p)", con); |
| 242 | rsContextResume(con); |
| 243 | } |
| 244 | |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 245 | static jint |
| 246 | nContextGetMessage(JNIEnv *_env, jobject _this, jintArray data, jboolean wait) |
| 247 | { |
| 248 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 249 | jint len = _env->GetArrayLength(data); |
| 250 | LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); |
| 251 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 252 | size_t receiveLen; |
| 253 | int id = rsContextGetMessage(con, ptr, &receiveLen, len * 4, wait); |
| 254 | if (!id && receiveLen) { |
| 255 | LOGE("message receive buffer too small. %i", receiveLen); |
| 256 | } |
| 257 | _env->ReleaseIntArrayElements(data, ptr, 0); |
| 258 | return id; |
| 259 | } |
| 260 | |
| 261 | static void nContextInitToClient(JNIEnv *_env, jobject _this) |
| 262 | { |
| 263 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 264 | LOG_API("nContextInitToClient, con(%p)", con); |
| 265 | rsContextInitToClient(con); |
| 266 | } |
| 267 | |
| 268 | static void nContextDeinitToClient(JNIEnv *_env, jobject _this) |
| 269 | { |
| 270 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 271 | LOG_API("nContextDeinitToClient, con(%p)", con); |
| 272 | rsContextDeinitToClient(con); |
| 273 | } |
| 274 | |
| 275 | |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 276 | static jint |
| 277 | nElementCreate(JNIEnv *_env, jobject _this, jint type, jint kind, jboolean norm, jint size) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 278 | { |
| 279 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 280 | LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size); |
| 281 | return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static jint |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 285 | nElementCreate2(JNIEnv *_env, jobject _this, jintArray _ids, jobjectArray _names) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 286 | { |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 287 | int fieldCount = _env->GetArrayLength(_ids); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 288 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 289 | LOG_API("nElementCreate2, con(%p)", con); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 290 | |
| 291 | jint *ids = _env->GetIntArrayElements(_ids, NULL); |
| 292 | const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *)); |
| 293 | size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t)); |
| 294 | |
| 295 | for (int ct=0; ct < fieldCount; ct++) { |
| 296 | jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); |
| 297 | nameArray[ct] = _env->GetStringUTFChars(s, NULL); |
| 298 | sizeArray[ct] = _env->GetStringUTFLength(s); |
| 299 | } |
| 300 | jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray); |
| 301 | for (int ct=0; ct < fieldCount; ct++) { |
| 302 | jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); |
| 303 | _env->ReleaseStringUTFChars(s, nameArray[ct]); |
| 304 | } |
| 305 | _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); |
| 306 | free(nameArray); |
| 307 | free(sizeArray); |
| 308 | return (jint)id; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 311 | static void |
| 312 | nElementGetNativeData(JNIEnv *_env, jobject _this, jint id, jintArray _elementData) |
| 313 | { |
| 314 | int dataSize = _env->GetArrayLength(_elementData); |
| 315 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 316 | LOG_API("nElementGetNativeData, con(%p)", con); |
| 317 | |
| 318 | // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements |
| 319 | assert(dataSize == 5); |
| 320 | |
| 321 | uint32_t elementData[5]; |
| 322 | rsElementGetNativeData(con, (RsElement)id, elementData, dataSize); |
| 323 | |
| 324 | for(jint i = 0; i < dataSize; i ++) { |
| 325 | _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | |
| 330 | static void |
| 331 | nElementGetSubElements(JNIEnv *_env, jobject _this, jint id, jintArray _IDs, jobjectArray _names) |
| 332 | { |
| 333 | int dataSize = _env->GetArrayLength(_IDs); |
| 334 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 335 | LOG_API("nElementGetSubElements, con(%p)", con); |
| 336 | |
| 337 | uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); |
| 338 | const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); |
| 339 | |
| 340 | rsElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize); |
| 341 | |
| 342 | for(jint i = 0; i < dataSize; i ++) { |
| 343 | _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); |
| 344 | _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); |
| 345 | } |
| 346 | |
| 347 | free(ids); |
| 348 | free(names); |
| 349 | } |
| 350 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 351 | // ----------------------------------- |
| 352 | |
| 353 | static void |
| 354 | nTypeBegin(JNIEnv *_env, jobject _this, jint eID) |
| 355 | { |
| 356 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 357 | LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 358 | rsTypeBegin(con, (RsElement)eID); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static void |
| 362 | nTypeAdd(JNIEnv *_env, jobject _this, jint dim, jint val) |
| 363 | { |
| 364 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 365 | LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 366 | rsTypeAdd(con, (RsDimension)dim, val); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static jint |
| 370 | nTypeCreate(JNIEnv *_env, jobject _this) |
| 371 | { |
| 372 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 373 | LOG_API("nTypeCreate, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 374 | return (jint)rsTypeCreate(con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 377 | static void |
| 378 | nTypeGetNativeData(JNIEnv *_env, jobject _this, jint id, jintArray _typeData) |
| 379 | { |
| 380 | // We are packing 6 items: mDimX; mDimY; mDimZ; |
| 381 | // mDimLOD; mDimFaces; mElement; into typeData |
| 382 | int elementCount = _env->GetArrayLength(_typeData); |
| 383 | |
| 384 | assert(elementCount == 6); |
| 385 | |
| 386 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 387 | LOG_API("nTypeCreate, con(%p)", con); |
| 388 | |
| 389 | uint32_t typeData[6]; |
| 390 | rsTypeGetNativeData(con, (RsType)id, typeData, 6); |
| 391 | |
| 392 | for(jint i = 0; i < elementCount; i ++) { |
| 393 | _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]); |
| 394 | } |
| 395 | } |
| 396 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 397 | static void * SF_LoadInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 398 | { |
| 399 | ((int32_t *)buffer)[0] = _env->GetIntField(_obj, _field); |
| 400 | return ((uint8_t *)buffer) + 4; |
| 401 | } |
| 402 | |
| 403 | static void * SF_LoadShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 404 | { |
| 405 | ((int16_t *)buffer)[0] = _env->GetShortField(_obj, _field); |
| 406 | return ((uint8_t *)buffer) + 2; |
| 407 | } |
| 408 | |
| 409 | static void * SF_LoadByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 410 | { |
| 411 | ((int8_t *)buffer)[0] = _env->GetByteField(_obj, _field); |
| 412 | return ((uint8_t *)buffer) + 1; |
| 413 | } |
| 414 | |
| 415 | static void * SF_LoadFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 416 | { |
| 417 | ((float *)buffer)[0] = _env->GetFloatField(_obj, _field); |
| 418 | return ((uint8_t *)buffer) + 4; |
| 419 | } |
| 420 | |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 421 | static void * SF_SaveInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 422 | { |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 423 | _env->SetIntField(_obj, _field, ((int32_t *)buffer)[0]); |
| 424 | return ((uint8_t *)buffer) + 4; |
| 425 | } |
| 426 | |
| 427 | static void * SF_SaveShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 428 | { |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 429 | _env->SetShortField(_obj, _field, ((int16_t *)buffer)[0]); |
| 430 | return ((uint8_t *)buffer) + 2; |
| 431 | } |
| 432 | |
| 433 | static void * SF_SaveByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 434 | { |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 435 | _env->SetByteField(_obj, _field, ((int8_t *)buffer)[0]); |
| 436 | return ((uint8_t *)buffer) + 1; |
| 437 | } |
| 438 | |
| 439 | static void * SF_SaveFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) |
| 440 | { |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 441 | _env->SetFloatField(_obj, _field, ((float *)buffer)[0]); |
| 442 | return ((uint8_t *)buffer) + 4; |
| 443 | } |
| 444 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 445 | struct TypeFieldCache { |
| 446 | jfieldID field; |
| 447 | int bits; |
| 448 | void * (*ptr)(JNIEnv *, jobject, jfieldID, void *buffer); |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 449 | void * (*readPtr)(JNIEnv *, jobject, jfieldID, void *buffer); |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 450 | }; |
| 451 | |
| 452 | struct TypeCache { |
| 453 | int fieldCount; |
| 454 | int size; |
| 455 | TypeFieldCache fields[1]; |
| 456 | }; |
| 457 | |
| 458 | //{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy }, |
| 459 | static void |
| 460 | nTypeFinalDestroy(JNIEnv *_env, jobject _this, jobject _type) |
| 461 | { |
| 462 | TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); |
| 463 | free(tc); |
| 464 | } |
| 465 | |
| 466 | // native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs); |
| 467 | static void |
| 468 | nTypeSetupFields(JNIEnv *_env, jobject _this, jobject _type, jintArray _types, jintArray _bits, jobjectArray _IDs) |
| 469 | { |
| 470 | int fieldCount = _env->GetArrayLength(_types); |
| 471 | size_t structSize = sizeof(TypeCache) + (sizeof(TypeFieldCache) * (fieldCount-1)); |
| 472 | TypeCache *tc = (TypeCache *)malloc(structSize); |
| 473 | memset(tc, 0, structSize); |
| 474 | |
| 475 | TypeFieldCache *tfc = &tc->fields[0]; |
| 476 | tc->fieldCount = fieldCount; |
| 477 | _env->SetIntField(_type, gTypeNativeCache, (jint)tc); |
| 478 | |
| 479 | jint *fType = _env->GetIntArrayElements(_types, NULL); |
| 480 | jint *fBits = _env->GetIntArrayElements(_bits, NULL); |
| 481 | for (int ct=0; ct < fieldCount; ct++) { |
| 482 | jobject field = _env->GetObjectArrayElement(_IDs, ct); |
| 483 | tfc[ct].field = _env->FromReflectedField(field); |
| 484 | tfc[ct].bits = fBits[ct]; |
| 485 | |
| 486 | switch(fType[ct]) { |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 487 | case RS_TYPE_FLOAT_32: |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 488 | tfc[ct].ptr = SF_LoadFloat; |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 489 | tfc[ct].readPtr = SF_SaveFloat; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 490 | break; |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 491 | case RS_TYPE_UNSIGNED_32: |
| 492 | case RS_TYPE_SIGNED_32: |
| 493 | tfc[ct].ptr = SF_LoadInt; |
| 494 | tfc[ct].readPtr = SF_SaveInt; |
| 495 | break; |
| 496 | case RS_TYPE_UNSIGNED_16: |
| 497 | case RS_TYPE_SIGNED_16: |
| 498 | tfc[ct].ptr = SF_LoadShort; |
| 499 | tfc[ct].readPtr = SF_SaveShort; |
| 500 | break; |
| 501 | case RS_TYPE_UNSIGNED_8: |
| 502 | case RS_TYPE_SIGNED_8: |
| 503 | tfc[ct].ptr = SF_LoadByte; |
| 504 | tfc[ct].readPtr = SF_SaveByte; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 505 | break; |
| 506 | } |
| 507 | tc->size += 4; |
| 508 | } |
| 509 | |
| 510 | _env->ReleaseIntArrayElements(_types, fType, JNI_ABORT); |
| 511 | _env->ReleaseIntArrayElements(_bits, fBits, JNI_ABORT); |
| 512 | } |
| 513 | |
| 514 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 515 | // ----------------------------------- |
| 516 | |
| 517 | static jint |
| 518 | nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e) |
| 519 | { |
| 520 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 521 | LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 522 | return (jint) rsAllocationCreateTyped(con, (RsElement)e); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 525 | static void |
| Jason Sams | c2908e6 | 2010-02-23 17:44:28 -0800 | [diff] [blame] | 526 | nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jboolean genMip, jint mip) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 527 | { |
| 528 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | c2908e6 | 2010-02-23 17:44:28 -0800 | [diff] [blame] | 529 | LOG_API("nAllocationUploadToTexture, con(%p), a(%p), genMip(%i), mip(%i)", con, (RsAllocation)a, genMip, mip); |
| 530 | rsAllocationUploadToTexture(con, (RsAllocation)a, genMip, mip); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 533 | static void |
| 534 | nAllocationUploadToBufferObject(JNIEnv *_env, jobject _this, jint a) |
| 535 | { |
| 536 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 537 | LOG_API("nAllocationUploadToBufferObject, con(%p), a(%p)", con, (RsAllocation)a); |
| 538 | rsAllocationUploadToBufferObject(con, (RsAllocation)a); |
| 539 | } |
| 540 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 541 | static RsElement SkBitmapToPredefined(SkBitmap::Config cfg) |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 542 | { |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 543 | switch (cfg) { |
| 544 | case SkBitmap::kA8_Config: |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 545 | return g_A_8; |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 546 | case SkBitmap::kARGB_4444_Config: |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 547 | return g_RGBA_4444; |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 548 | case SkBitmap::kARGB_8888_Config: |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 549 | return g_RGBA_8888; |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 550 | case SkBitmap::kRGB_565_Config: |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 551 | return g_RGB_565; |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 552 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 553 | default: |
| 554 | break; |
| 555 | } |
| 556 | // If we don't have a conversion mark it as a user type. |
| 557 | LOGE("Unsupported bitmap type"); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 558 | return NULL; |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 561 | static int |
| 562 | nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) |
| 563 | { |
| 564 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 565 | SkBitmap const * nativeBitmap = |
| 566 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 567 | const SkBitmap& bitmap(*nativeBitmap); |
| 568 | SkBitmap::Config config = bitmap.getConfig(); |
| 569 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 570 | RsElement e = SkBitmapToPredefined(config); |
| 571 | if (e) { |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 572 | bitmap.lockPixels(); |
| 573 | const int w = bitmap.width(); |
| 574 | const int h = bitmap.height(); |
| 575 | const void* ptr = bitmap.getPixels(); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 576 | jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 577 | bitmap.unlockPixels(); |
| 578 | return id; |
| 579 | } |
| 580 | return 0; |
| 581 | } |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 582 | |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 583 | static void ReleaseBitmapCallback(void *bmp) |
| 584 | { |
| 585 | SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; |
| 586 | nativeBitmap->unlockPixels(); |
| 587 | } |
| 588 | |
| 589 | static int |
| 590 | nAllocationCreateBitmapRef(JNIEnv *_env, jobject _this, jint type, jobject jbitmap) |
| 591 | { |
| 592 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 593 | SkBitmap * nativeBitmap = |
| 594 | (SkBitmap *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 595 | |
| 596 | |
| 597 | nativeBitmap->lockPixels(); |
| 598 | void* ptr = nativeBitmap->getPixels(); |
| 599 | jint id = (jint)rsAllocationCreateBitmapRef(con, (RsType)type, ptr, nativeBitmap, ReleaseBitmapCallback); |
| 600 | return id; |
| 601 | } |
| 602 | |
| Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 603 | static int |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 604 | nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset) |
| 605 | { |
| 606 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 607 | |
| 608 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
| 609 | SkBitmap bitmap; |
| 610 | SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(), |
| 611 | &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode); |
| 612 | |
| 613 | SkBitmap::Config config = bitmap.getConfig(); |
| 614 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 615 | RsElement e = SkBitmapToPredefined(config); |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 616 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 617 | if (e) { |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 618 | bitmap.lockPixels(); |
| 619 | const int w = bitmap.width(); |
| 620 | const int h = bitmap.height(); |
| 621 | const void* ptr = bitmap.getPixels(); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 622 | jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr); |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 623 | bitmap.unlockPixels(); |
| 624 | return id; |
| 625 | } |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | static int |
| Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 630 | nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) |
| 631 | { |
| 632 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 633 | SkBitmap const * nativeBitmap = |
| 634 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 635 | const SkBitmap& bitmap(*nativeBitmap); |
| 636 | SkBitmap::Config config = bitmap.getConfig(); |
| 637 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 638 | RsElement e = SkBitmapToPredefined(config); |
| Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 639 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 640 | if (e) { |
| Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 641 | bitmap.lockPixels(); |
| 642 | const int w = bitmap.width(); |
| 643 | const int h = bitmap.height(); |
| 644 | const void* ptr = bitmap.getPixels(); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 645 | jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElement)dstFmt, e, genMips, ptr); |
| Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 646 | bitmap.unlockPixels(); |
| 647 | return id; |
| 648 | } |
| 649 | return 0; |
| 650 | } |
| 651 | |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 652 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 653 | static void |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 654 | nAllocationSubData1D_i(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jintArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 655 | { |
| 656 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 657 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 658 | LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 659 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 660 | rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 661 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 662 | } |
| 663 | |
| 664 | static void |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 665 | nAllocationSubData1D_s(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jshortArray data, int sizeBytes) |
| 666 | { |
| 667 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 668 | jint len = _env->GetArrayLength(data); |
| 669 | LOG_API("nAllocation1DSubData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); |
| 670 | jshort *ptr = _env->GetShortArrayElements(data, NULL); |
| 671 | rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); |
| 672 | _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); |
| 673 | } |
| 674 | |
| 675 | static void |
| 676 | nAllocationSubData1D_b(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jbyteArray data, int sizeBytes) |
| 677 | { |
| 678 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 679 | jint len = _env->GetArrayLength(data); |
| 680 | LOG_API("nAllocation1DSubData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); |
| 681 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| 682 | rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); |
| 683 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 684 | } |
| 685 | |
| 686 | static void |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 687 | nAllocationSubData1D_f(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jfloatArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 688 | { |
| 689 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 690 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 691 | LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 692 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 693 | rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 694 | _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); |
| 695 | } |
| 696 | |
| 697 | static void |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 698 | nAllocationSubData2D_i(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 699 | { |
| 700 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 701 | jint len = _env->GetArrayLength(data); |
| 702 | LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| 703 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 704 | rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 705 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 706 | } |
| 707 | |
| 708 | static void |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 709 | nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 710 | { |
| 711 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 712 | jint len = _env->GetArrayLength(data); |
| 713 | LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| 714 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 715 | rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 716 | _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); |
| 717 | } |
| 718 | |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 719 | static void |
| 720 | nAllocationRead_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data) |
| 721 | { |
| 722 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 723 | jint len = _env->GetArrayLength(data); |
| 724 | LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 725 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 726 | rsAllocationRead(con, (RsAllocation)alloc, ptr); |
| Joe Onorato | ae209ac | 2009-08-31 17:23:53 -0700 | [diff] [blame] | 727 | _env->ReleaseIntArrayElements(data, ptr, 0); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | static void |
| 731 | nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data) |
| 732 | { |
| 733 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 734 | jint len = _env->GetArrayLength(data); |
| Joe Onorato | a8f2ace | 2009-08-12 11:47:23 -0700 | [diff] [blame] | 735 | 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] | 736 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 737 | rsAllocationRead(con, (RsAllocation)alloc, ptr); |
| Joe Onorato | ae209ac | 2009-08-31 17:23:53 -0700 | [diff] [blame] | 738 | _env->ReleaseFloatArrayElements(data, ptr, 0); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 739 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 740 | |
| 741 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 742 | //{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject }, |
| 743 | static void |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 744 | nAllocationSubDataFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jint offset, jobject _o) |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 745 | { |
| 746 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 747 | LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc); |
| 748 | |
| 749 | const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); |
| 750 | |
| 751 | void * bufAlloc = malloc(tc->size); |
| 752 | void * buf = bufAlloc; |
| 753 | for (int ct=0; ct < tc->fieldCount; ct++) { |
| 754 | const TypeFieldCache *tfc = &tc->fields[ct]; |
| 755 | buf = tfc->ptr(_env, _o, tfc->field, buf); |
| 756 | } |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 757 | rsAllocation1DSubData(con, (RsAllocation)alloc, offset, 1, bufAlloc, tc->size); |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 758 | free(bufAlloc); |
| 759 | } |
| 760 | |
| 761 | static void |
| 762 | nAllocationSubReadFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jint offset, jobject _o) |
| 763 | { |
| 764 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 765 | LOG_API("nAllocationReadFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc); |
| 766 | |
| 767 | assert(offset == 0); |
| 768 | |
| 769 | const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); |
| 770 | |
| 771 | void * bufAlloc = malloc(tc->size); |
| 772 | void * buf = bufAlloc; |
| 773 | rsAllocationRead(con, (RsAllocation)alloc, bufAlloc); |
| 774 | |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 775 | for (int ct=0; ct < tc->fieldCount; ct++) { |
| 776 | const TypeFieldCache *tfc = &tc->fields[ct]; |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 777 | buf = tfc->readPtr(_env, _o, tfc->field, buf); |
| 778 | } |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 779 | free(bufAlloc); |
| 780 | } |
| 781 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 782 | static jint |
| 783 | nAllocationGetType(JNIEnv *_env, jobject _this, jint a) |
| 784 | { |
| 785 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 786 | LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a); |
| 787 | return (jint) rsAllocationGetType(con, (RsAllocation)a); |
| 788 | } |
| 789 | |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 790 | // ----------------------------------- |
| 791 | |
| 792 | static int |
| 793 | nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jint native_asset) |
| 794 | { |
| 795 | LOGV("______nFileA3D %u", (uint32_t) native_asset); |
| 796 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 797 | |
| 798 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
| 799 | |
| 800 | jint id = (jint)rsFileA3DCreateFromAssetStream(con, asset->getBuffer(false), asset->getLength()); |
| 801 | return id; |
| 802 | } |
| 803 | |
| 804 | static int |
| 805 | nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jint fileA3D) |
| 806 | { |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 807 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 808 | |
| 809 | int32_t numEntries = 0; |
| 810 | rsFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 811 | return numEntries; |
| 812 | } |
| 813 | |
| 814 | static void |
| 815 | nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries) |
| 816 | { |
| 817 | LOGV("______nFileA3D %u", (uint32_t) fileA3D); |
| 818 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 819 | |
| 820 | RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); |
| 821 | |
| 822 | rsFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); |
| 823 | |
| 824 | for(jint i = 0; i < numEntries; i ++) { |
| 825 | _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); |
| 826 | _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); |
| 827 | } |
| 828 | |
| 829 | free(fileEntries); |
| 830 | } |
| 831 | |
| 832 | static int |
| 833 | nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jint fileA3D, jint index) |
| 834 | { |
| 835 | LOGV("______nFileA3D %u", (uint32_t) fileA3D); |
| 836 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 837 | |
| 838 | jint id = (jint)rsFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D); |
| 839 | return id; |
| 840 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 841 | |
| 842 | // ----------------------------------- |
| 843 | |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 844 | static int |
| 845 | nFontCreateFromFile(JNIEnv *_env, jobject _this, jstring fileName, jint fontSize, jint dpi) |
| 846 | { |
| 847 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 848 | const char* fileNameUTF = _env->GetStringUTFChars(fileName, NULL); |
| 849 | |
| 850 | jint id = (jint)rsFontCreateFromFile(con, fileNameUTF, fontSize, dpi); |
| 851 | return id; |
| 852 | } |
| 853 | |
| 854 | |
| 855 | // ----------------------------------- |
| 856 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 857 | static void |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 858 | nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) |
| 859 | { |
| 860 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 861 | LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 862 | rsAdapter1DBindAllocation(con, (RsAdapter1D)adapter, (RsAllocation)alloc); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static void |
| 866 | nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) |
| 867 | { |
| 868 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 869 | LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 870 | rsAdapter1DSetConstraint(con, (RsAdapter1D)adapter, (RsDimension)dim, value); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static void |
| 874 | nAdapter1DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) |
| 875 | { |
| 876 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 877 | jint len = _env->GetArrayLength(data); |
| 878 | LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); |
| 879 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 880 | rsAdapter1DData(con, (RsAdapter1D)adapter, ptr); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 881 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 882 | } |
| 883 | |
| 884 | static void |
| 885 | nAdapter1DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jintArray data) |
| 886 | { |
| 887 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 888 | jint len = _env->GetArrayLength(data); |
| 889 | LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); |
| 890 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 891 | rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 892 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 893 | } |
| 894 | |
| 895 | static void |
| 896 | nAdapter1DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) |
| 897 | { |
| 898 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 899 | jint len = _env->GetArrayLength(data); |
| 900 | LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); |
| 901 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 902 | rsAdapter1DData(con, (RsAdapter1D)adapter, ptr); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 903 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 904 | } |
| 905 | |
| 906 | static void |
| 907 | nAdapter1DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jfloatArray data) |
| 908 | { |
| 909 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 910 | jint len = _env->GetArrayLength(data); |
| 911 | LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); |
| 912 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 913 | rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 914 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 915 | } |
| 916 | |
| 917 | static jint |
| 918 | nAdapter1DCreate(JNIEnv *_env, jobject _this) |
| 919 | { |
| 920 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 921 | LOG_API("nAdapter1DCreate, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 922 | return (jint)rsAdapter1DCreate(con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // ----------------------------------- |
| 926 | |
| 927 | static void |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 928 | nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) |
| 929 | { |
| 930 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 931 | LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 932 | rsAdapter2DBindAllocation(con, (RsAdapter2D)adapter, (RsAllocation)alloc); |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | static void |
| 936 | nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) |
| 937 | { |
| 938 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 939 | LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 940 | rsAdapter2DSetConstraint(con, (RsAdapter2D)adapter, (RsDimension)dim, value); |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | static void |
| 944 | nAdapter2DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) |
| 945 | { |
| 946 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 947 | jint len = _env->GetArrayLength(data); |
| 948 | LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); |
| 949 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 950 | rsAdapter2DData(con, (RsAdapter2D)adapter, ptr); |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 951 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 952 | } |
| 953 | |
| 954 | static void |
| 955 | nAdapter2DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) |
| 956 | { |
| 957 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 958 | jint len = _env->GetArrayLength(data); |
| 959 | LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); |
| 960 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 961 | rsAdapter2DData(con, (RsAdapter2D)adapter, ptr); |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 962 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 963 | } |
| 964 | |
| 965 | static void |
| 966 | nAdapter2DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data) |
| 967 | { |
| 968 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 969 | jint len = _env->GetArrayLength(data); |
| 970 | LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", |
| 971 | con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); |
| 972 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 973 | rsAdapter2DSubData(con, (RsAdapter2D)adapter, xoff, yoff, w, h, ptr); |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 974 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 975 | } |
| 976 | |
| 977 | static void |
| 978 | nAdapter2DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data) |
| 979 | { |
| 980 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 981 | jint len = _env->GetArrayLength(data); |
| 982 | LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", |
| 983 | con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); |
| 984 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 985 | rsAdapter2DSubData(con, (RsAdapter1D)adapter, xoff, yoff, w, h, ptr); |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 986 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 987 | } |
| 988 | |
| 989 | static jint |
| 990 | nAdapter2DCreate(JNIEnv *_env, jobject _this) |
| 991 | { |
| 992 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 993 | LOG_API("nAdapter2DCreate, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 994 | return (jint)rsAdapter2DCreate(con); |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | // ----------------------------------- |
| 998 | |
| 999 | static void |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1000 | nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint slot) |
| 1001 | { |
| 1002 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1003 | 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] | 1004 | rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | static void |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1008 | nScriptSetVarI(JNIEnv *_env, jobject _this, jint script, jint slot, jint val) |
| 1009 | { |
| 1010 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1011 | LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i), b(%f), a(%f)", con, (void *)script, slot, val); |
| 1012 | rsScriptSetVarI(con, (RsScript)script, slot, val); |
| 1013 | } |
| 1014 | |
| 1015 | static void |
| 1016 | nScriptSetVarF(JNIEnv *_env, jobject _this, jint script, jint slot, float val) |
| 1017 | { |
| 1018 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1019 | LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i), b(%f), a(%f)", con, (void *)script, slot, val); |
| 1020 | rsScriptSetVarF(con, (RsScript)script, slot, val); |
| 1021 | } |
| 1022 | |
| 1023 | static void |
| 1024 | nScriptSetVarV(JNIEnv *_env, jobject _this, jint script, jint slot, jbyteArray data) |
| 1025 | { |
| 1026 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1027 | LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); |
| 1028 | jint len = _env->GetArrayLength(data); |
| 1029 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| 1030 | rsScriptSetVarV(con, (RsScript)script, slot, ptr, len); |
| 1031 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1032 | } |
| 1033 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1034 | |
| 1035 | static void |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1036 | nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1037 | { |
| 1038 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 1039 | 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] | 1040 | |
| 1041 | jint length = _env->GetArrayLength(timeZone); |
| 1042 | jbyte* timeZone_ptr; |
| 1043 | timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); |
| 1044 | |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1045 | rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1046 | |
| 1047 | if (timeZone_ptr) { |
| 1048 | _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 1052 | static void |
| Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 1053 | nScriptInvoke(JNIEnv *_env, jobject _this, jint obj, jint slot) |
| 1054 | { |
| 1055 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1056 | LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); |
| 1057 | rsScriptInvoke(con, (RsScript)obj, slot); |
| 1058 | } |
| 1059 | |
| 1060 | static void |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1061 | nScriptInvokeV(JNIEnv *_env, jobject _this, jint script, jint slot, jbyteArray data) |
| 1062 | { |
| 1063 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1064 | LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); |
| 1065 | jint len = _env->GetArrayLength(data); |
| 1066 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| 1067 | rsScriptInvokeV(con, (RsScript)script, slot, ptr, len); |
| 1068 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 1069 | } |
| 1070 | |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 1071 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1072 | // ----------------------------------- |
| 1073 | |
| 1074 | static void |
| 1075 | nScriptCBegin(JNIEnv *_env, jobject _this) |
| 1076 | { |
| 1077 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1078 | LOG_API("nScriptCBegin, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1079 | rsScriptCBegin(con); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1082 | static void |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1083 | nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef, |
| 1084 | jint offset, jint length) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1085 | { |
| 1086 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1087 | LOG_API("!!! nScriptCSetScript, con(%p)", con); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1088 | jint _exception = 0; |
| 1089 | jint remaining; |
| 1090 | jbyte* script_base = 0; |
| 1091 | jbyte* script_ptr; |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1092 | if (!scriptRef) { |
| 1093 | _exception = 1; |
| 1094 | //_env->ThrowNew(IAEClass, "script == null"); |
| 1095 | goto exit; |
| 1096 | } |
| 1097 | if (offset < 0) { |
| 1098 | _exception = 1; |
| 1099 | //_env->ThrowNew(IAEClass, "offset < 0"); |
| 1100 | goto exit; |
| 1101 | } |
| 1102 | if (length < 0) { |
| 1103 | _exception = 1; |
| 1104 | //_env->ThrowNew(IAEClass, "length < 0"); |
| 1105 | goto exit; |
| 1106 | } |
| 1107 | remaining = _env->GetArrayLength(scriptRef) - offset; |
| 1108 | if (remaining < length) { |
| 1109 | _exception = 1; |
| 1110 | //_env->ThrowNew(IAEClass, "length > script.length - offset"); |
| 1111 | goto exit; |
| 1112 | } |
| 1113 | script_base = (jbyte *) |
| 1114 | _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); |
| 1115 | script_ptr = script_base + offset; |
| 1116 | |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1117 | rsScriptCSetText(con, (const char *)script_ptr, length); |
| Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 1118 | |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1119 | exit: |
| 1120 | if (script_base) { |
| 1121 | _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, |
| 1122 | _exception ? JNI_ABORT: 0); |
| 1123 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | static jint |
| 1127 | nScriptCCreate(JNIEnv *_env, jobject _this) |
| 1128 | { |
| 1129 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1130 | LOG_API("nScriptCCreate, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1131 | return (jint)rsScriptCCreate(con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | // --------------------------------------------------------------------------- |
| 1135 | |
| 1136 | static void |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1137 | nProgramStoreBegin(JNIEnv *_env, jobject _this, jint in, jint out) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1138 | { |
| 1139 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1140 | LOG_API("nProgramStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); |
| 1141 | rsProgramStoreBegin(con, (RsElement)in, (RsElement)out); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | static void |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1145 | nProgramStoreDepthFunc(JNIEnv *_env, jobject _this, jint func) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1146 | { |
| 1147 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1148 | LOG_API("nProgramStoreDepthFunc, con(%p), func(%i)", con, func); |
| 1149 | rsProgramStoreDepthFunc(con, (RsDepthFunc)func); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static void |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1153 | nProgramStoreDepthMask(JNIEnv *_env, jobject _this, jboolean enable) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1154 | { |
| 1155 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1156 | LOG_API("nProgramStoreDepthMask, con(%p), enable(%i)", con, enable); |
| 1157 | rsProgramStoreDepthMask(con, enable); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static void |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1161 | nProgramStoreColorMask(JNIEnv *_env, jobject _this, jboolean r, jboolean g, jboolean b, jboolean a) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1162 | { |
| 1163 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1164 | LOG_API("nProgramStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); |
| 1165 | rsProgramStoreColorMask(con, r, g, b, a); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | static void |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1169 | nProgramStoreBlendFunc(JNIEnv *_env, jobject _this, int src, int dst) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1170 | { |
| 1171 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1172 | LOG_API("nProgramStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); |
| 1173 | rsProgramStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | static void |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1177 | nProgramStoreDither(JNIEnv *_env, jobject _this, jboolean enable) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1178 | { |
| 1179 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1180 | LOG_API("nProgramStoreDither, con(%p), enable(%i)", con, enable); |
| 1181 | rsProgramStoreDither(con, enable); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static jint |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1185 | nProgramStoreCreate(JNIEnv *_env, jobject _this) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1186 | { |
| 1187 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1188 | LOG_API("nProgramStoreCreate, con(%p)", con); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 1189 | |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1190 | return (jint)rsProgramStoreCreate(con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1193 | // --------------------------------------------------------------------------- |
| 1194 | |
| 1195 | static void |
| 1196 | nProgramBindConstants(JNIEnv *_env, jobject _this, jint vpv, jint slot, jint a) |
| 1197 | { |
| 1198 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1199 | LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a); |
| 1200 | rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a); |
| 1201 | } |
| Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 1202 | |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1203 | static void |
| 1204 | nProgramBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) |
| 1205 | { |
| 1206 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1207 | LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| 1208 | rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| 1209 | } |
| 1210 | |
| 1211 | static void |
| 1212 | nProgramBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) |
| 1213 | { |
| 1214 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1215 | LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
| 1216 | rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
| 1217 | } |
| 1218 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1219 | // --------------------------------------------------------------------------- |
| 1220 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1221 | static jint |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1222 | nProgramFragmentCreate(JNIEnv *_env, jobject _this, jintArray params) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1223 | { |
| 1224 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1225 | jint *paramPtr = _env->GetIntArrayElements(params, NULL); |
| 1226 | jint paramLen = _env->GetArrayLength(params); |
| 1227 | |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1228 | LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen); |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1229 | |
| 1230 | jint ret = (jint)rsProgramFragmentCreate(con, (uint32_t *)paramPtr, paramLen); |
| 1231 | _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); |
| 1232 | return ret; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 1235 | static jint |
| 1236 | nProgramFragmentCreate2(JNIEnv *_env, jobject _this, jstring shader, jintArray params) |
| 1237 | { |
| 1238 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1239 | const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); |
| 1240 | jint shaderLen = _env->GetStringUTFLength(shader); |
| 1241 | jint *paramPtr = _env->GetIntArrayElements(params, NULL); |
| 1242 | jint paramLen = _env->GetArrayLength(params); |
| 1243 | |
| 1244 | LOG_API("nProgramFragmentCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); |
| 1245 | |
| 1246 | jint ret = (jint)rsProgramFragmentCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); |
| 1247 | _env->ReleaseStringUTFChars(shader, shaderUTF); |
| 1248 | _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); |
| 1249 | return ret; |
| 1250 | } |
| 1251 | |
| 1252 | |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1253 | // --------------------------------------------------------------------------- |
| 1254 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1255 | static jint |
| 1256 | nProgramVertexCreate(JNIEnv *_env, jobject _this, jboolean texMat) |
| Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 1257 | { |
| 1258 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1259 | LOG_API("nProgramVertexCreate, con(%p), texMat(%i)", con, texMat); |
| 1260 | return (jint)rsProgramVertexCreate(con, texMat); |
| Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1263 | static jint |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1264 | nProgramVertexCreate2(JNIEnv *_env, jobject _this, jstring shader, jintArray params) |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1265 | { |
| 1266 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1267 | const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); |
| 1268 | jint shaderLen = _env->GetStringUTFLength(shader); |
| 1269 | jint *paramPtr = _env->GetIntArrayElements(params, NULL); |
| 1270 | jint paramLen = _env->GetArrayLength(params); |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1271 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1272 | LOG_API("nProgramVertexCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); |
| 1273 | |
| 1274 | jint ret = (jint)rsProgramVertexCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); |
| 1275 | _env->ReleaseStringUTFChars(shader, shaderUTF); |
| 1276 | _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); |
| 1277 | return ret; |
| 1278 | } |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1279 | |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1280 | // --------------------------------------------------------------------------- |
| 1281 | |
| 1282 | static jint |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1283 | nProgramRasterCreate(JNIEnv *_env, jobject _this, jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite) |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1284 | { |
| 1285 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1286 | LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)", |
| 1287 | con, pointSmooth, lineSmooth, pointSprite); |
| 1288 | return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite); |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | static void |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1292 | nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, jint vpr, jfloat v) |
| 1293 | { |
| 1294 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1295 | LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1296 | rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v); |
| 1297 | } |
| 1298 | |
| 1299 | static void |
| 1300 | nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, jint vpr, jint v) |
| 1301 | { |
| 1302 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1303 | LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v); |
| 1304 | rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v); |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1307 | |
| 1308 | // --------------------------------------------------------------------------- |
| 1309 | |
| 1310 | static void |
| 1311 | nContextBindRootScript(JNIEnv *_env, jobject _this, jint script) |
| 1312 | { |
| 1313 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1314 | LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1315 | rsContextBindRootScript(con, (RsScript)script); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | static void |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1319 | nContextBindProgramStore(JNIEnv *_env, jobject _this, jint pfs) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1320 | { |
| 1321 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1322 | LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs); |
| 1323 | rsContextBindProgramStore(con, (RsProgramStore)pfs); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | static void |
| 1327 | nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf) |
| 1328 | { |
| 1329 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1330 | LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1331 | rsContextBindProgramFragment(con, (RsProgramFragment)pf); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1334 | static void |
| 1335 | nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf) |
| 1336 | { |
| 1337 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1338 | LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1339 | rsContextBindProgramVertex(con, (RsProgramVertex)pf); |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1342 | static void |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1343 | nContextBindProgramRaster(JNIEnv *_env, jobject _this, jint pf) |
| 1344 | { |
| 1345 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1346 | LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf); |
| 1347 | rsContextBindProgramRaster(con, (RsProgramRaster)pf); |
| 1348 | } |
| 1349 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1350 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1351 | // --------------------------------------------------------------------------- |
| 1352 | |
| 1353 | static void |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1354 | nSamplerBegin(JNIEnv *_env, jobject _this) |
| 1355 | { |
| 1356 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1357 | LOG_API("nSamplerBegin, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1358 | rsSamplerBegin(con); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | static void |
| 1362 | nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v) |
| 1363 | { |
| 1364 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1365 | LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1366 | rsSamplerSet(con, (RsSamplerParam)p, (RsSamplerValue)v); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | static jint |
| 1370 | nSamplerCreate(JNIEnv *_env, jobject _this) |
| 1371 | { |
| 1372 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1373 | LOG_API("nSamplerCreate, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1374 | return (jint)rsSamplerCreate(con); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1377 | // --------------------------------------------------------------------------- |
| 1378 | |
| 1379 | static void |
| 1380 | nLightBegin(JNIEnv *_env, jobject _this) |
| 1381 | { |
| 1382 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1383 | LOG_API("nLightBegin, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1384 | rsLightBegin(con); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | static void |
| 1388 | nLightSetIsMono(JNIEnv *_env, jobject _this, jboolean isMono) |
| 1389 | { |
| 1390 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1391 | LOG_API("nLightSetIsMono, con(%p), isMono(%i)", con, isMono); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1392 | rsLightSetMonochromatic(con, isMono); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static void |
| 1396 | nLightSetIsLocal(JNIEnv *_env, jobject _this, jboolean isLocal) |
| 1397 | { |
| 1398 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1399 | LOG_API("nLightSetIsLocal, con(%p), isLocal(%i)", con, isLocal); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1400 | rsLightSetLocal(con, isLocal); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | static jint |
| 1404 | nLightCreate(JNIEnv *_env, jobject _this) |
| 1405 | { |
| 1406 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1407 | LOG_API("nLightCreate, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1408 | return (jint)rsLightCreate(con); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | static void |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1412 | nLightSetColor(JNIEnv *_env, jobject _this, jint light, float r, float g, float b) |
| 1413 | { |
| 1414 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1415 | LOG_API("nLightSetColor, con(%p), light(%p), r(%f), g(%f), b(%f)", con, (RsLight)light, r, g, b); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1416 | rsLightSetColor(con, (RsLight)light, r, g, b); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | static void |
| 1420 | nLightSetPosition(JNIEnv *_env, jobject _this, jint light, float x, float y, float z) |
| 1421 | { |
| 1422 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1423 | LOG_API("nLightSetPosition, con(%p), light(%p), x(%f), y(%f), z(%f)", con, (RsLight)light, x, y, z); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1424 | rsLightSetPosition(con, (RsLight)light, x, y, z); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1425 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1426 | |
| 1427 | // --------------------------------------------------------------------------- |
| 1428 | |
| Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1429 | static jint |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1430 | nMeshCreate(JNIEnv *_env, jobject _this, jint vtxCount, jint idxCount) |
| 1431 | { |
| 1432 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1433 | LOG_API("nMeshCreate, con(%p), vtxCount(%i), idxCount(%i)", con, vtxCount, idxCount); |
| 1434 | int id = (int)rsMeshCreate(con, vtxCount, idxCount); |
| 1435 | return id; |
| 1436 | } |
| 1437 | |
| 1438 | static void |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1439 | nMeshBindVertex(JNIEnv *_env, jobject _this, jint mesh, jint alloc, jint slot) |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1440 | { |
| 1441 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1442 | LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)mesh, (RsAllocation)alloc, slot); |
| 1443 | rsMeshBindVertex(con, (RsMesh)mesh, (RsAllocation)alloc, slot); |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | static void |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1447 | nMeshBindIndex(JNIEnv *_env, jobject _this, jint mesh, jint alloc, jint primID, jint slot) |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1448 | { |
| 1449 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1450 | LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)mesh, (RsAllocation)alloc); |
| 1451 | rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot); |
| 1452 | } |
| 1453 | |
| 1454 | static jint |
| 1455 | nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jint mesh) |
| 1456 | { |
| 1457 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1458 | LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1459 | jint vtxCount = 0; |
| 1460 | rsMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount); |
| 1461 | return vtxCount; |
| 1462 | } |
| 1463 | |
| 1464 | static jint |
| 1465 | nMeshGetIndexCount(JNIEnv *_env, jobject _this, jint mesh) |
| 1466 | { |
| 1467 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1468 | LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1469 | jint idxCount = 0; |
| 1470 | rsMeshGetIndexCount(con, (RsMesh)mesh, &idxCount); |
| 1471 | return idxCount; |
| 1472 | } |
| 1473 | |
| 1474 | static void |
| 1475 | nMeshGetVertices(JNIEnv *_env, jobject _this, jint mesh, jintArray _ids, int numVtxIDs) |
| 1476 | { |
| 1477 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1478 | LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1479 | |
| 1480 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); |
| 1481 | rsMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); |
| 1482 | |
| 1483 | for(jint i = 0; i < numVtxIDs; i ++) { |
| 1484 | _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]); |
| 1485 | } |
| 1486 | |
| 1487 | free(allocs); |
| 1488 | } |
| 1489 | |
| 1490 | static void |
| 1491 | nMeshGetIndices(JNIEnv *_env, jobject _this, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices) |
| 1492 | { |
| 1493 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1494 | LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1495 | |
| 1496 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); |
| 1497 | uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); |
| 1498 | |
| 1499 | rsMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); |
| 1500 | |
| 1501 | for(jint i = 0; i < numIndices; i ++) { |
| 1502 | _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]); |
| 1503 | _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]); |
| 1504 | } |
| 1505 | |
| 1506 | free(allocs); |
| 1507 | free(prims); |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | // --------------------------------------------------------------------------- |
| 1511 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1512 | |
| Jason Sams | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 1513 | static const char *classPathName = "android/renderscript/RenderScript"; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1514 | |
| 1515 | static JNINativeMethod methods[] = { |
| 1516 | {"_nInit", "()V", (void*)_nInit }, |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 1517 | {"nInitElements", "(IIII)V", (void*)nInitElements }, |
| 1518 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1519 | {"nDeviceCreate", "()I", (void*)nDeviceCreate }, |
| 1520 | {"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1521 | {"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1522 | {"nContextCreate", "(II)I", (void*)nContextCreate }, |
| 1523 | {"nContextCreateGL", "(IIZ)I", (void*)nContextCreateGL }, |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 1524 | {"nContextFinish", "()V", (void*)nContextFinish }, |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 1525 | {"nContextSetPriority", "(I)V", (void*)nContextSetPriority }, |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 1526 | {"nContextSetSurface", "(IILandroid/view/Surface;)V", (void*)nContextSetSurface }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1527 | {"nContextDestroy", "(I)V", (void*)nContextDestroy }, |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 1528 | {"nContextDump", "(I)V", (void*)nContextDump }, |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 1529 | {"nContextPause", "()V", (void*)nContextPause }, |
| 1530 | {"nContextResume", "()V", (void*)nContextResume }, |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 1531 | {"nAssignName", "(I[B)V", (void*)nAssignName }, |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame^] | 1532 | {"nGetName", "(I)Ljava/lang/String;", (void*)nGetName }, |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 1533 | {"nObjDestroy", "(I)V", (void*)nObjDestroy }, |
| Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 1534 | {"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB }, |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1535 | {"nContextGetMessage", "([IZ)I", (void*)nContextGetMessage }, |
| 1536 | {"nContextInitToClient", "()V", (void*)nContextInitToClient }, |
| 1537 | {"nContextDeinitToClient", "()V", (void*)nContextDeinitToClient }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1538 | |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 1539 | {"nFileOpen", "([B)I", (void*)nFileOpen }, |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1540 | {"nFileA3DCreateFromAssetStream", "(I)I", (void*)nFileA3DCreateFromAssetStream }, |
| 1541 | {"nFileA3DGetNumIndexEntries", "(I)I", (void*)nFileA3DGetNumIndexEntries }, |
| 1542 | {"nFileA3DGetIndexEntries", "(II[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, |
| 1543 | {"nFileA3DGetEntryByIndex", "(II)I", (void*)nFileA3DGetEntryByIndex }, |
| 1544 | |
| 1545 | {"nFontCreateFromFile", "(Ljava/lang/String;II)I", (void*)nFontCreateFromFile }, |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 1546 | |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1547 | {"nElementCreate", "(IIZI)I", (void*)nElementCreate }, |
| 1548 | {"nElementCreate2", "([I[Ljava/lang/String;)I", (void*)nElementCreate2 }, |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1549 | {"nElementGetNativeData", "(I[I)V", (void*)nElementGetNativeData }, |
| 1550 | {"nElementGetSubElements", "(I[I[Ljava/lang/String;)V", (void*)nElementGetSubElements }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1551 | |
| 1552 | {"nTypeBegin", "(I)V", (void*)nTypeBegin }, |
| 1553 | {"nTypeAdd", "(II)V", (void*)nTypeAdd }, |
| 1554 | {"nTypeCreate", "()I", (void*)nTypeCreate }, |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 1555 | {"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy }, |
| 1556 | {"nTypeSetupFields", "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields }, |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1557 | {"nTypeGetNativeData", "(I[I)V", (void*)nTypeGetNativeData }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1558 | |
| 1559 | {"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped }, |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 1560 | {"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1561 | {"nAllocationCreateBitmapRef", "(ILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef }, |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 1562 | {"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed }, |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 1563 | {"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream }, |
| Jason Sams | c2908e6 | 2010-02-23 17:44:28 -0800 | [diff] [blame] | 1564 | {"nAllocationUploadToTexture", "(IZI)V", (void*)nAllocationUploadToTexture }, |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 1565 | {"nAllocationUploadToBufferObject","(I)V", (void*)nAllocationUploadToBufferObject }, |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 1566 | {"nAllocationSubData1D", "(III[II)V", (void*)nAllocationSubData1D_i }, |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 1567 | {"nAllocationSubData1D", "(III[SI)V", (void*)nAllocationSubData1D_s }, |
| 1568 | {"nAllocationSubData1D", "(III[BI)V", (void*)nAllocationSubData1D_b }, |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 1569 | {"nAllocationSubData1D", "(III[FI)V", (void*)nAllocationSubData1D_f }, |
| 1570 | {"nAllocationSubData2D", "(IIIII[II)V", (void*)nAllocationSubData2D_i }, |
| 1571 | {"nAllocationSubData2D", "(IIIII[FI)V", (void*)nAllocationSubData2D_f }, |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1572 | {"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i }, |
| 1573 | {"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f }, |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 1574 | {"nAllocationSubDataFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject }, |
| Jason Sams | 5f43fd2 | 2009-09-15 12:39:22 -0700 | [diff] [blame] | 1575 | {"nAllocationSubReadFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubReadFromObject }, |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 1576 | {"nAllocationGetType", "(I)I", (void*)nAllocationGetType}, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1577 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1578 | {"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation }, |
| 1579 | {"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint }, |
| 1580 | {"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1581 | {"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f }, |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1582 | {"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1583 | {"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f }, |
| 1584 | {"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate }, |
| 1585 | |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1586 | {"nAdapter2DBindAllocation", "(II)V", (void*)nAdapter2DBindAllocation }, |
| 1587 | {"nAdapter2DSetConstraint", "(III)V", (void*)nAdapter2DSetConstraint }, |
| 1588 | {"nAdapter2DData", "(I[I)V", (void*)nAdapter2DData_i }, |
| 1589 | {"nAdapter2DData", "(I[F)V", (void*)nAdapter2DData_f }, |
| 1590 | {"nAdapter2DSubData", "(IIIII[I)V", (void*)nAdapter2DSubData_i }, |
| 1591 | {"nAdapter2DSubData", "(IIIII[F)V", (void*)nAdapter2DSubData_f }, |
| 1592 | {"nAdapter2DCreate", "()I", (void*)nAdapter2DCreate }, |
| 1593 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1594 | {"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation }, |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1595 | {"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone }, |
| Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 1596 | {"nScriptInvoke", "(II)V", (void*)nScriptInvoke }, |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1597 | {"nScriptInvokeV", "(II[B)V", (void*)nScriptInvokeV }, |
| 1598 | {"nScriptSetVarI", "(III)V", (void*)nScriptSetVarI }, |
| 1599 | {"nScriptSetVarF", "(IIF)V", (void*)nScriptSetVarF }, |
| 1600 | {"nScriptSetVarV", "(II[B)V", (void*)nScriptSetVarV }, |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1601 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1602 | {"nScriptCBegin", "()V", (void*)nScriptCBegin }, |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1603 | {"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1604 | {"nScriptCCreate", "()I", (void*)nScriptCCreate }, |
| 1605 | |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1606 | {"nProgramStoreBegin", "(II)V", (void*)nProgramStoreBegin }, |
| 1607 | {"nProgramStoreDepthFunc", "(I)V", (void*)nProgramStoreDepthFunc }, |
| 1608 | {"nProgramStoreDepthMask", "(Z)V", (void*)nProgramStoreDepthMask }, |
| 1609 | {"nProgramStoreColorMask", "(ZZZZ)V", (void*)nProgramStoreColorMask }, |
| 1610 | {"nProgramStoreBlendFunc", "(II)V", (void*)nProgramStoreBlendFunc }, |
| 1611 | {"nProgramStoreDither", "(Z)V", (void*)nProgramStoreDither }, |
| 1612 | {"nProgramStoreCreate", "()I", (void*)nProgramStoreCreate }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1613 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1614 | {"nProgramBindConstants", "(III)V", (void*)nProgramBindConstants }, |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1615 | {"nProgramBindTexture", "(III)V", (void*)nProgramBindTexture }, |
| 1616 | {"nProgramBindSampler", "(III)V", (void*)nProgramBindSampler }, |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1617 | |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 1618 | {"nProgramFragmentCreate", "([I)I", (void*)nProgramFragmentCreate }, |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 1619 | {"nProgramFragmentCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate2 }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1620 | |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1621 | {"nProgramRasterCreate", "(ZZZ)I", (void*)nProgramRasterCreate }, |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1622 | {"nProgramRasterSetLineWidth", "(IF)V", (void*)nProgramRasterSetLineWidth }, |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1623 | {"nProgramRasterSetCullMode", "(II)V", (void*)nProgramRasterSetCullMode }, |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1624 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1625 | {"nProgramVertexCreate", "(Z)I", (void*)nProgramVertexCreate }, |
| 1626 | {"nProgramVertexCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramVertexCreate2 }, |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1627 | |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1628 | {"nLightBegin", "()V", (void*)nLightBegin }, |
| 1629 | {"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono }, |
| 1630 | {"nLightSetIsLocal", "(Z)V", (void*)nLightSetIsLocal }, |
| 1631 | {"nLightCreate", "()I", (void*)nLightCreate }, |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1632 | {"nLightSetColor", "(IFFF)V", (void*)nLightSetColor }, |
| 1633 | {"nLightSetPosition", "(IFFF)V", (void*)nLightSetPosition }, |
| 1634 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1635 | {"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript }, |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1636 | {"nContextBindProgramStore", "(I)V", (void*)nContextBindProgramStore }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1637 | {"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment }, |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1638 | {"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex }, |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1639 | {"nContextBindProgramRaster", "(I)V", (void*)nContextBindProgramRaster }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1640 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1641 | {"nSamplerBegin", "()V", (void*)nSamplerBegin }, |
| 1642 | {"nSamplerSet", "(II)V", (void*)nSamplerSet }, |
| 1643 | {"nSamplerCreate", "()I", (void*)nSamplerCreate }, |
| 1644 | |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1645 | {"nMeshCreate", "(II)I", (void*)nMeshCreate }, |
| 1646 | {"nMeshBindVertex", "(III)V", (void*)nMeshBindVertex }, |
| 1647 | {"nMeshBindIndex", "(IIII)V", (void*)nMeshBindIndex }, |
| 1648 | |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1649 | {"nMeshGetVertexBufferCount", "(I)I", (void*)nMeshGetVertexBufferCount }, |
| 1650 | {"nMeshGetIndexCount", "(I)I", (void*)nMeshGetIndexCount }, |
| 1651 | {"nMeshGetVertices", "(I[II)V", (void*)nMeshGetVertices }, |
| 1652 | {"nMeshGetIndices", "(I[I[II)V", (void*)nMeshGetIndices }, |
| 1653 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1654 | }; |
| 1655 | |
| 1656 | static int registerFuncs(JNIEnv *_env) |
| 1657 | { |
| 1658 | return android::AndroidRuntime::registerNativeMethods( |
| 1659 | _env, classPathName, methods, NELEM(methods)); |
| 1660 | } |
| 1661 | |
| 1662 | // --------------------------------------------------------------------------- |
| 1663 | |
| 1664 | jint JNI_OnLoad(JavaVM* vm, void* reserved) |
| 1665 | { |
| 1666 | JNIEnv* env = NULL; |
| 1667 | jint result = -1; |
| 1668 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1669 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
| 1670 | LOGE("ERROR: GetEnv failed\n"); |
| 1671 | goto bail; |
| 1672 | } |
| 1673 | assert(env != NULL); |
| 1674 | |
| 1675 | if (registerFuncs(env) < 0) { |
| 1676 | LOGE("ERROR: MediaPlayer native registration failed\n"); |
| 1677 | goto bail; |
| 1678 | } |
| 1679 | |
| 1680 | /* success -- return valid version number */ |
| 1681 | result = JNI_VERSION_1_4; |
| 1682 | |
| 1683 | bail: |
| 1684 | return result; |
| 1685 | } |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1686 | |