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