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