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