| 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> |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 35 | #include <utils/AssetManager.h> |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 36 | #include <utils/ResourceTypes.h> |
| Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 37 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | #include "jni.h" |
| 39 | #include "JNIHelp.h" |
| 40 | #include "android_runtime/AndroidRuntime.h" |
| Jim Miller | ee95605 | 2010-08-19 18:56:00 -0700 | [diff] [blame] | 41 | #include "android_runtime/android_view_Surface.h" |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 42 | #include "android_runtime/android_util_AssetManager.h" |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 43 | |
| Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 44 | #include <RenderScript.h> |
| 45 | #include <RenderScriptEnv.h> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | |
| 47 | //#define LOG_API LOGE |
| 48 | #define LOG_API(...) |
| 49 | |
| 50 | using namespace android; |
| 51 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 52 | class AutoJavaStringToUTF8 { |
| 53 | public: |
| 54 | AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) |
| 55 | { |
| 56 | fCStr = env->GetStringUTFChars(str, NULL); |
| 57 | fLength = env->GetStringUTFLength(str); |
| 58 | } |
| 59 | ~AutoJavaStringToUTF8() |
| 60 | { |
| 61 | fEnv->ReleaseStringUTFChars(fJStr, fCStr); |
| 62 | } |
| 63 | const char* c_str() const { return fCStr; } |
| 64 | jsize length() const { return fLength; } |
| 65 | |
| 66 | private: |
| 67 | JNIEnv* fEnv; |
| 68 | jstring fJStr; |
| 69 | const char* fCStr; |
| 70 | jsize fLength; |
| 71 | }; |
| 72 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 73 | // --------------------------------------------------------------------------- |
| 74 | |
| 75 | static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) |
| 76 | { |
| 77 | jclass npeClazz = env->FindClass(exc); |
| 78 | env->ThrowNew(npeClazz, msg); |
| 79 | } |
| 80 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 81 | static jfieldID gContextId = 0; |
| 82 | static jfieldID gNativeBitmapID = 0; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 83 | static jfieldID gTypeNativeCache = 0; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 84 | |
| 85 | static void _nInit(JNIEnv *_env, jclass _this) |
| 86 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 87 | gContextId = _env->GetFieldID(_this, "mContext", "I"); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 88 | |
| 89 | jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); |
| 90 | gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 93 | // --------------------------------------------------------------------------- |
| 94 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 95 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 96 | nContextFinish(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 97 | { |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 98 | LOG_API("nContextFinish, con(%p)", con); |
| 99 | rsContextFinish(con); |
| 100 | } |
| 101 | |
| 102 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 103 | nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str) |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 104 | { |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 105 | LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 106 | jint len = _env->GetArrayLength(str); |
| 107 | jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 108 | rsAssignName(con, (void *)obj, (const char *)cptr, len); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 109 | _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); |
| 110 | } |
| 111 | |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 112 | static jstring |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 113 | nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj) |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 114 | { |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 115 | LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj); |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 116 | const char *name = NULL; |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 117 | rsaGetName(con, (void *)obj, &name); |
| 118 | if(name == NULL || strlen(name) == 0) { |
| 119 | return NULL; |
| 120 | } |
| Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 121 | return _env->NewStringUTF(name); |
| 122 | } |
| 123 | |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 124 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 125 | nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj) |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 126 | { |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 127 | LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); |
| Jason Sams | 9c25aee | 2010-10-14 17:57:30 -0700 | [diff] [blame] | 128 | rsObjDestroy(con, (void *)obj); |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 131 | // --------------------------------------------------------------------------- |
| 132 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 133 | static jint |
| 134 | nDeviceCreate(JNIEnv *_env, jobject _this) |
| 135 | { |
| 136 | LOG_API("nDeviceCreate"); |
| 137 | return (jint)rsDeviceCreate(); |
| 138 | } |
| 139 | |
| 140 | static void |
| 141 | nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) |
| 142 | { |
| 143 | LOG_API("nDeviceDestroy"); |
| 144 | return rsDeviceDestroy((RsDevice)dev); |
| 145 | } |
| 146 | |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 147 | static void |
| 148 | nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) |
| 149 | { |
| 150 | LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); |
| 151 | return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); |
| 152 | } |
| 153 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 154 | static jint |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 155 | nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 156 | { |
| 157 | LOG_API("nContextCreate"); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 158 | return (jint)rsContextCreate((RsDevice)dev, ver); |
| 159 | } |
| 160 | |
| 161 | static jint |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 162 | nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, |
| 163 | int colorMin, int colorPref, |
| 164 | int alphaMin, int alphaPref, |
| 165 | int depthMin, int depthPref, |
| 166 | int stencilMin, int stencilPref, |
| 167 | int samplesMin, int samplesPref, float samplesQ) |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 168 | { |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 169 | RsSurfaceConfig sc; |
| 170 | sc.alphaMin = alphaMin; |
| 171 | sc.alphaPref = alphaPref; |
| 172 | sc.colorMin = colorMin; |
| 173 | sc.colorPref = colorPref; |
| 174 | sc.depthMin = depthMin; |
| 175 | sc.depthPref = depthPref; |
| 176 | sc.samplesMin = samplesMin; |
| 177 | sc.samplesPref = samplesPref; |
| 178 | sc.samplesQ = samplesQ; |
| 179 | |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 180 | LOG_API("nContextCreateGL"); |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 181 | return (jint)rsContextCreateGL((RsDevice)dev, ver, sc); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 185 | nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p) |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 186 | { |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 187 | LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p); |
| 188 | rsContextSetPriority(con, p); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | |
| 193 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 194 | 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] | 195 | { |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 196 | 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] | 197 | |
| 198 | Surface * window = NULL; |
| 199 | if (wnd == NULL) { |
| 200 | |
| 201 | } else { |
| Jim Miller | ee95605 | 2010-08-19 18:56:00 -0700 | [diff] [blame] | 202 | window = (Surface*) android_Surface_getNativeWindow(_env, wnd).get(); |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 205 | rsContextSetSurface(con, width, height, window); |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 209 | nContextDestroy(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 210 | { |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 211 | LOG_API("nContextDestroy, con(%p)", con); |
| 212 | rsContextDestroy(con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 215 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 216 | nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits) |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 217 | { |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 218 | LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); |
| 219 | rsContextDump((RsContext)con, bits); |
| 220 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 221 | |
| 222 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 223 | nContextPause(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 224 | { |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 225 | LOG_API("nContextPause, con(%p)", con); |
| 226 | rsContextPause(con); |
| 227 | } |
| 228 | |
| 229 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 230 | nContextResume(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 231 | { |
| Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 232 | LOG_API("nContextResume, con(%p)", con); |
| 233 | rsContextResume(con); |
| 234 | } |
| 235 | |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 236 | |
| 237 | static jstring |
| 238 | nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con) |
| 239 | { |
| 240 | LOG_API("nContextGetErrorMessage, con(%p)", con); |
| 241 | char buf[1024]; |
| 242 | |
| 243 | size_t receiveLen; |
| 244 | uint32_t subID; |
| 245 | int id = rsContextGetMessage(con, buf, &receiveLen, &subID, sizeof(buf), true); |
| 246 | if (!id && receiveLen) { |
| 247 | LOGV("message receive buffer too small. %i", receiveLen); |
| 248 | } |
| 249 | return _env->NewStringUTF(buf); |
| 250 | } |
| 251 | |
| 252 | static void |
| 253 | nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data) |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 254 | { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 255 | jint len = _env->GetArrayLength(data); |
| 256 | LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); |
| 257 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 258 | size_t receiveLen; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 259 | uint32_t subID; |
| 260 | int id = rsContextGetMessage(con, ptr, &receiveLen, &subID, len * 4, true); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 261 | if (!id && receiveLen) { |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 262 | LOGV("message receive buffer too small. %i", receiveLen); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 263 | } |
| 264 | _env->ReleaseIntArrayElements(data, ptr, 0); |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static jint |
| 268 | nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData, jboolean wait) |
| 269 | { |
| 270 | LOG_API("nContextPeekMessage, con(%p)", con); |
| 271 | jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); |
| 272 | size_t receiveLen; |
| 273 | uint32_t subID; |
| 274 | int id = rsContextPeekMessage(con, &receiveLen, &subID, wait); |
| 275 | auxDataPtr[0] = (jint)subID; |
| 276 | auxDataPtr[1] = (jint)receiveLen; |
| 277 | _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 278 | return id; |
| 279 | } |
| 280 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 281 | static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 282 | { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 283 | LOG_API("nContextInitToClient, con(%p)", con); |
| 284 | rsContextInitToClient(con); |
| 285 | } |
| 286 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 287 | static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 288 | { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 289 | LOG_API("nContextDeinitToClient, con(%p)", con); |
| 290 | rsContextDeinitToClient(con); |
| 291 | } |
| 292 | |
| 293 | |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 294 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 295 | 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] | 296 | { |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 297 | LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size); |
| 298 | return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | static jint |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 302 | nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 303 | { |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 304 | int fieldCount = _env->GetArrayLength(_ids); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 305 | LOG_API("nElementCreate2, con(%p)", con); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 306 | |
| 307 | jint *ids = _env->GetIntArrayElements(_ids, NULL); |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 308 | jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 309 | const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *)); |
| 310 | size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t)); |
| 311 | |
| 312 | for (int ct=0; ct < fieldCount; ct++) { |
| 313 | jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); |
| 314 | nameArray[ct] = _env->GetStringUTFChars(s, NULL); |
| 315 | sizeArray[ct] = _env->GetStringUTFLength(s); |
| 316 | } |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 317 | jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray, (const uint32_t *)arraySizes); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 318 | for (int ct=0; ct < fieldCount; ct++) { |
| 319 | jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); |
| 320 | _env->ReleaseStringUTFChars(s, nameArray[ct]); |
| 321 | } |
| 322 | _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 323 | _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 324 | free(nameArray); |
| 325 | free(sizeArray); |
| 326 | return (jint)id; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 329 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 330 | nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData) |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 331 | { |
| 332 | int dataSize = _env->GetArrayLength(_elementData); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 333 | LOG_API("nElementGetNativeData, con(%p)", con); |
| 334 | |
| 335 | // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements |
| 336 | assert(dataSize == 5); |
| 337 | |
| 338 | uint32_t elementData[5]; |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 339 | rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 340 | |
| 341 | for(jint i = 0; i < dataSize; i ++) { |
| 342 | _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | |
| 347 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 348 | 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] | 349 | { |
| 350 | int dataSize = _env->GetArrayLength(_IDs); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 351 | LOG_API("nElementGetSubElements, con(%p)", con); |
| 352 | |
| 353 | uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); |
| 354 | const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); |
| 355 | |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 356 | rsaElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 357 | |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 358 | for(jint i = 0; i < dataSize; i++) { |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 359 | _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); |
| 360 | _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); |
| 361 | } |
| 362 | |
| 363 | free(ids); |
| 364 | free(names); |
| 365 | } |
| 366 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 367 | // ----------------------------------- |
| 368 | |
| Jason Sams | 3b9c52a | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 369 | static int |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 370 | nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid, |
| 371 | jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 372 | { |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 373 | LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)", |
| 374 | con, eid, dimx, dimy, dimz, mips, faces); |
| Jason Sams | 3b9c52a | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 375 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 376 | jint id = (jint)rsaTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces); |
| Jason Sams | 3b9c52a | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 377 | return (jint)id; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 380 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 381 | nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData) |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 382 | { |
| 383 | // We are packing 6 items: mDimX; mDimY; mDimZ; |
| 384 | // mDimLOD; mDimFaces; mElement; into typeData |
| 385 | int elementCount = _env->GetArrayLength(_typeData); |
| 386 | |
| 387 | assert(elementCount == 6); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 388 | LOG_API("nTypeCreate, con(%p)", con); |
| 389 | |
| 390 | uint32_t typeData[6]; |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 391 | rsaTypeGetNativeData(con, (RsType)id, typeData, 6); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 392 | |
| 393 | for(jint i = 0; i < elementCount; i ++) { |
| 394 | _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]); |
| 395 | } |
| 396 | } |
| 397 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 398 | // ----------------------------------- |
| 399 | |
| 400 | static jint |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 401 | nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 402 | { |
| Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 403 | LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage); |
| 404 | return (jint) rsaAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 407 | static void |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 408 | nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits) |
| 409 | { |
| 410 | LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits); |
| 411 | rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits); |
| 412 | } |
| 413 | |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 414 | static void |
| 415 | nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc) |
| 416 | { |
| 417 | LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc); |
| 418 | rsAllocationGenerateMipmaps(con, (RsAllocation)alloc); |
| 419 | } |
| 420 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 421 | static int |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 422 | nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 423 | { |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 424 | SkBitmap const * nativeBitmap = |
| 425 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 426 | const SkBitmap& bitmap(*nativeBitmap); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 427 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 428 | bitmap.lockPixels(); |
| 429 | const void* ptr = bitmap.getPixels(); |
| Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 430 | jint id = (jint)rsaAllocationCreateFromBitmap(con, (RsType)type, (RsAllocationMipmapControl)mip, ptr, usage); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 431 | bitmap.unlockPixels(); |
| 432 | return id; |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 433 | } |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 434 | |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 435 | static int |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 436 | nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 437 | { |
| 438 | SkBitmap const * nativeBitmap = |
| 439 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 440 | const SkBitmap& bitmap(*nativeBitmap); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 441 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 442 | bitmap.lockPixels(); |
| 443 | const void* ptr = bitmap.getPixels(); |
| Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 444 | jint id = (jint)rsaAllocationCubeCreateFromBitmap(con, (RsType)type, (RsAllocationMipmapControl)mip, ptr, usage); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 445 | bitmap.unlockPixels(); |
| 446 | return id; |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 449 | static void |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 450 | nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 451 | { |
| 452 | SkBitmap const * nativeBitmap = |
| 453 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 454 | const SkBitmap& bitmap(*nativeBitmap); |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 455 | int w = bitmap.width(); |
| 456 | int h = bitmap.height(); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 457 | |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 458 | bitmap.lockPixels(); |
| 459 | const void* ptr = bitmap.getPixels(); |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 460 | rsAllocation2DData(con, (RsAllocation)alloc, 0, 0, |
| 461 | 0, RS_ALLOCATION_CUBMAP_FACE_POSITVE_X, |
| 462 | w, h, ptr, bitmap.getSize()); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 463 | bitmap.unlockPixels(); |
| 464 | } |
| 465 | |
| 466 | static void |
| 467 | nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) |
| 468 | { |
| 469 | SkBitmap const * nativeBitmap = |
| 470 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 471 | const SkBitmap& bitmap(*nativeBitmap); |
| 472 | |
| 473 | bitmap.lockPixels(); |
| 474 | void* ptr = bitmap.getPixels(); |
| 475 | rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize()); |
| 476 | bitmap.unlockPixels(); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 479 | static void ReleaseBitmapCallback(void *bmp) |
| 480 | { |
| 481 | SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; |
| 482 | nativeBitmap->unlockPixels(); |
| 483 | } |
| 484 | |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 485 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 486 | static void |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 487 | nAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 488 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 489 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 490 | LOG_API("nAllocation1DData_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] | 491 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 492 | rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 493 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 494 | } |
| 495 | |
| 496 | static void |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 497 | nAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes) |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 498 | { |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 499 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 500 | LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 501 | jshort *ptr = _env->GetShortArrayElements(data, NULL); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 502 | rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 503 | _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); |
| 504 | } |
| 505 | |
| 506 | static void |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 507 | nAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes) |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 508 | { |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 509 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 510 | LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 511 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 512 | rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 513 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 514 | } |
| 515 | |
| 516 | static void |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 517 | nAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 518 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 519 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 520 | LOG_API("nAllocation1DData_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] | 521 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 522 | rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 523 | _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); |
| 524 | } |
| 525 | |
| 526 | static void |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 527 | // native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); |
| 528 | nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes) |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 529 | { |
| 530 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 531 | LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 532 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 533 | rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, compIdx, sizeBytes); |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 534 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 535 | } |
| 536 | |
| 537 | static void |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame^] | 538 | nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, |
| 539 | jint w, jint h, jshortArray data, int sizeBytes) |
| 540 | { |
| 541 | jint len = _env->GetArrayLength(data); |
| 542 | LOG_API("nAllocation2DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| 543 | jshort *ptr = _env->GetShortArrayElements(data, NULL); |
| 544 | rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); |
| 545 | _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); |
| 546 | } |
| 547 | |
| 548 | static void |
| 549 | nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, |
| 550 | jint w, jint h, jbyteArray data, int sizeBytes) |
| 551 | { |
| 552 | jint len = _env->GetArrayLength(data); |
| 553 | LOG_API("nAllocation2DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| 554 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| 555 | rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); |
| 556 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 557 | } |
| 558 | |
| 559 | static void |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 560 | nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, |
| 561 | jint w, jint h, jintArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 562 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 563 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 564 | LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 565 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 566 | rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 567 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 568 | } |
| 569 | |
| 570 | static void |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 571 | nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, |
| 572 | jint w, jint h, jfloatArray data, int sizeBytes) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 573 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 574 | jint len = _env->GetArrayLength(data); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 575 | LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 576 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 577 | rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 578 | _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); |
| 579 | } |
| 580 | |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 581 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 582 | nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data) |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 583 | { |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 584 | jint len = _env->GetArrayLength(data); |
| 585 | LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 586 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 587 | rsAllocationRead(con, (RsAllocation)alloc, ptr); |
| Joe Onorato | ae209ac | 2009-08-31 17:23:53 -0700 | [diff] [blame] | 588 | _env->ReleaseIntArrayElements(data, ptr, 0); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | static void |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame^] | 592 | nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data) |
| 593 | { |
| 594 | jint len = _env->GetArrayLength(data); |
| 595 | LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 596 | jshort *ptr = _env->GetShortArrayElements(data, NULL); |
| 597 | rsAllocationRead(con, (RsAllocation)alloc, ptr); |
| 598 | _env->ReleaseShortArrayElements(data, ptr, 0); |
| 599 | } |
| 600 | |
| 601 | static void |
| 602 | nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data) |
| 603 | { |
| 604 | jint len = _env->GetArrayLength(data); |
| 605 | LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 606 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| 607 | rsAllocationRead(con, (RsAllocation)alloc, ptr); |
| 608 | _env->ReleaseByteArrayElements(data, ptr, 0); |
| 609 | } |
| 610 | |
| 611 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 612 | nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data) |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 613 | { |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 614 | jint len = _env->GetArrayLength(data); |
| Joe Onorato | a8f2ace | 2009-08-12 11:47:23 -0700 | [diff] [blame] | 615 | 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] | 616 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 617 | rsAllocationRead(con, (RsAllocation)alloc, ptr); |
| Joe Onorato | ae209ac | 2009-08-31 17:23:53 -0700 | [diff] [blame] | 618 | _env->ReleaseFloatArrayElements(data, ptr, 0); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 619 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 620 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 621 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 622 | nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a) |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 623 | { |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 624 | LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a); |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 625 | return (jint) rsaAllocationGetType(con, (RsAllocation)a); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 628 | static void |
| 629 | nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX) |
| 630 | { |
| 631 | LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX); |
| 632 | rsAllocationResize1D(con, (RsAllocation)alloc, dimX); |
| 633 | } |
| 634 | |
| 635 | static void |
| 636 | nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY) |
| 637 | { |
| 638 | LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY); |
| 639 | rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY); |
| 640 | } |
| 641 | |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 642 | // ----------------------------------- |
| 643 | |
| 644 | static int |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 645 | nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset) |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 646 | { |
| 647 | LOGV("______nFileA3D %u", (uint32_t) native_asset); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 648 | |
| 649 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
| 650 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 651 | jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength()); |
| 652 | return id; |
| 653 | } |
| 654 | |
| 655 | static int |
| 656 | nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path) |
| 657 | { |
| 658 | AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); |
| 659 | if (mgr == NULL) { |
| 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | AutoJavaStringToUTF8 str(_env, _path); |
| 664 | Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); |
| 665 | if (asset == NULL) { |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | jint id = (jint)rsaFileA3DCreateFromAsset(con, asset); |
| 670 | return id; |
| 671 | } |
| 672 | |
| 673 | static int |
| 674 | nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName) |
| 675 | { |
| 676 | AutoJavaStringToUTF8 fileNameUTF(_env, fileName); |
| 677 | jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str()); |
| 678 | |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 679 | return id; |
| 680 | } |
| 681 | |
| 682 | static int |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 683 | nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D) |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 684 | { |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 685 | int32_t numEntries = 0; |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 686 | rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 687 | return numEntries; |
| 688 | } |
| 689 | |
| 690 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 691 | 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] | 692 | { |
| 693 | LOGV("______nFileA3D %u", (uint32_t) fileA3D); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 694 | RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); |
| 695 | |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 696 | rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 697 | |
| 698 | for(jint i = 0; i < numEntries; i ++) { |
| 699 | _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); |
| 700 | _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); |
| 701 | } |
| 702 | |
| 703 | free(fileEntries); |
| 704 | } |
| 705 | |
| 706 | static int |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 707 | nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index) |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 708 | { |
| 709 | LOGV("______nFileA3D %u", (uint32_t) fileA3D); |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 710 | jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D); |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 711 | return id; |
| 712 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 713 | |
| 714 | // ----------------------------------- |
| 715 | |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 716 | static int |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 717 | nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, |
| 718 | jstring fileName, jfloat fontSize, jint dpi) |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 719 | { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 720 | AutoJavaStringToUTF8 fileNameUTF(_env, fileName); |
| 721 | jint id = (jint)rsFontCreateFromFile(con, fileNameUTF.c_str(), fontSize, dpi); |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 722 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 723 | return id; |
| 724 | } |
| 725 | |
| 726 | static int |
| 727 | nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, |
| 728 | jstring name, jfloat fontSize, jint dpi, jint native_asset) |
| 729 | { |
| 730 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
| 731 | AutoJavaStringToUTF8 nameUTF(_env, name); |
| 732 | |
| 733 | jint id = (jint)rsFontCreateFromMemory(con, nameUTF.c_str(), fontSize, dpi, |
| 734 | asset->getBuffer(false), asset->getLength()); |
| 735 | return id; |
| 736 | } |
| 737 | |
| 738 | static int |
| 739 | nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path, |
| 740 | jfloat fontSize, jint dpi) |
| 741 | { |
| 742 | AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); |
| 743 | if (mgr == NULL) { |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | AutoJavaStringToUTF8 str(_env, _path); |
| 748 | Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); |
| 749 | if (asset == NULL) { |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | jint id = (jint)rsFontCreateFromMemory(con, str.c_str(), fontSize, dpi, |
| 754 | asset->getBuffer(false), asset->getLength()); |
| 755 | delete asset; |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 756 | return id; |
| 757 | } |
| 758 | |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 759 | // ----------------------------------- |
| 760 | |
| 761 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 762 | 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] | 763 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 764 | 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] | 765 | rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 769 | 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] | 770 | { |
| Jason Sams | cfc0436 | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 771 | LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 772 | rsScriptSetVarI(con, (RsScript)script, slot, val); |
| 773 | } |
| 774 | |
| 775 | static void |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 776 | nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) |
| 777 | { |
| 778 | LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); |
| 779 | rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val); |
| 780 | } |
| 781 | |
| 782 | static void |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 783 | nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val) |
| 784 | { |
| 785 | LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val); |
| 786 | rsScriptSetVarJ(con, (RsScript)script, slot, val); |
| 787 | } |
| 788 | |
| 789 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 790 | 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] | 791 | { |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 792 | LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 793 | rsScriptSetVarF(con, (RsScript)script, slot, val); |
| 794 | } |
| 795 | |
| 796 | static void |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 797 | nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val) |
| 798 | { |
| 799 | LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val); |
| 800 | rsScriptSetVarD(con, (RsScript)script, slot, val); |
| 801 | } |
| 802 | |
| 803 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 804 | 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] | 805 | { |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 806 | LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); |
| 807 | jint len = _env->GetArrayLength(data); |
| 808 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| 809 | rsScriptSetVarV(con, (RsScript)script, slot, ptr, len); |
| 810 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 811 | } |
| 812 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 813 | |
| 814 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 815 | nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 816 | { |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 817 | 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] | 818 | |
| 819 | jint length = _env->GetArrayLength(timeZone); |
| 820 | jbyte* timeZone_ptr; |
| 821 | timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); |
| 822 | |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 823 | rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 824 | |
| 825 | if (timeZone_ptr) { |
| 826 | _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); |
| 827 | } |
| 828 | } |
| 829 | |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 830 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 831 | nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot) |
| Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 832 | { |
| Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 833 | LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); |
| 834 | rsScriptInvoke(con, (RsScript)obj, slot); |
| 835 | } |
| 836 | |
| 837 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 838 | 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] | 839 | { |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 840 | LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); |
| 841 | jint len = _env->GetArrayLength(data); |
| 842 | jbyte *ptr = _env->GetByteArrayElements(data, NULL); |
| 843 | rsScriptInvokeV(con, (RsScript)script, slot, ptr, len); |
| 844 | _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); |
| 845 | } |
| 846 | |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 847 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 848 | // ----------------------------------- |
| 849 | |
| 850 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 851 | nScriptCBegin(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 852 | { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 853 | LOG_API("nScriptCBegin, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 854 | rsScriptCBegin(con); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 857 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 858 | nScriptCSetScript(JNIEnv *_env, jobject _this, RsContext con, jbyteArray scriptRef, |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 859 | jint offset, jint length) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 860 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 861 | LOG_API("!!! nScriptCSetScript, con(%p)", con); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 862 | jint _exception = 0; |
| 863 | jint remaining; |
| 864 | jbyte* script_base = 0; |
| 865 | jbyte* script_ptr; |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 866 | if (!scriptRef) { |
| 867 | _exception = 1; |
| 868 | //_env->ThrowNew(IAEClass, "script == null"); |
| 869 | goto exit; |
| 870 | } |
| 871 | if (offset < 0) { |
| 872 | _exception = 1; |
| 873 | //_env->ThrowNew(IAEClass, "offset < 0"); |
| 874 | goto exit; |
| 875 | } |
| 876 | if (length < 0) { |
| 877 | _exception = 1; |
| 878 | //_env->ThrowNew(IAEClass, "length < 0"); |
| 879 | goto exit; |
| 880 | } |
| 881 | remaining = _env->GetArrayLength(scriptRef) - offset; |
| 882 | if (remaining < length) { |
| 883 | _exception = 1; |
| 884 | //_env->ThrowNew(IAEClass, "length > script.length - offset"); |
| 885 | goto exit; |
| 886 | } |
| 887 | script_base = (jbyte *) |
| 888 | _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); |
| 889 | script_ptr = script_base + offset; |
| 890 | |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 891 | rsScriptCSetText(con, (const char *)script_ptr, length); |
| Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 892 | |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 893 | exit: |
| 894 | if (script_base) { |
| 895 | _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, |
| 896 | _exception ? JNI_ABORT: 0); |
| 897 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | static jint |
| Shih-wei Liao | eeca435 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 901 | nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring packageName, jstring resName, jstring cacheDir) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 902 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 903 | LOG_API("nScriptCCreate, con(%p)", con); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 904 | AutoJavaStringToUTF8 packageNameUTF(_env, packageName); |
| 905 | AutoJavaStringToUTF8 resNameUTF(_env, resName); |
| 906 | AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); |
| 907 | jint i = (jint)rsScriptCCreate(con, packageNameUTF.c_str(), resNameUTF.c_str(), cacheDirUTF.c_str()); |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 908 | return i; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | // --------------------------------------------------------------------------- |
| 912 | |
| 913 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 914 | nProgramStoreBegin(JNIEnv *_env, jobject _this, RsContext con, jint in, jint out) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 915 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 916 | LOG_API("nProgramStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); |
| 917 | rsProgramStoreBegin(con, (RsElement)in, (RsElement)out); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 921 | nProgramStoreDepthFunc(JNIEnv *_env, jobject _this, RsContext con, jint func) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 922 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 923 | LOG_API("nProgramStoreDepthFunc, con(%p), func(%i)", con, func); |
| 924 | rsProgramStoreDepthFunc(con, (RsDepthFunc)func); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 928 | nProgramStoreDepthMask(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 929 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 930 | LOG_API("nProgramStoreDepthMask, con(%p), enable(%i)", con, enable); |
| 931 | rsProgramStoreDepthMask(con, enable); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 935 | 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] | 936 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 937 | LOG_API("nProgramStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); |
| 938 | rsProgramStoreColorMask(con, r, g, b, a); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 942 | nProgramStoreBlendFunc(JNIEnv *_env, jobject _this, RsContext con, int src, int dst) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 943 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 944 | LOG_API("nProgramStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); |
| 945 | rsProgramStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 949 | nProgramStoreDither(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 950 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 951 | LOG_API("nProgramStoreDither, con(%p), enable(%i)", con, enable); |
| 952 | rsProgramStoreDither(con, enable); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 956 | nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 957 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 958 | LOG_API("nProgramStoreCreate, con(%p)", con); |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 959 | return (jint)rsProgramStoreCreate(con); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 962 | // --------------------------------------------------------------------------- |
| 963 | |
| 964 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 965 | 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] | 966 | { |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 967 | LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a); |
| 968 | rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a); |
| 969 | } |
| Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 970 | |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 971 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 972 | 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] | 973 | { |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 974 | LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| 975 | rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| 976 | } |
| 977 | |
| 978 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 979 | 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] | 980 | { |
| Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 981 | LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
| 982 | rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
| 983 | } |
| 984 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 985 | // --------------------------------------------------------------------------- |
| 986 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 987 | static jint |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 988 | nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 989 | { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 990 | AutoJavaStringToUTF8 shaderUTF(_env, shader); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 991 | jint *paramPtr = _env->GetIntArrayElements(params, NULL); |
| 992 | jint paramLen = _env->GetArrayLength(params); |
| 993 | |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 994 | LOG_API("nProgramFragmentCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 995 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 996 | jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); |
| Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 997 | _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); |
| 998 | return ret; |
| 999 | } |
| 1000 | |
| 1001 | |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1002 | // --------------------------------------------------------------------------- |
| 1003 | |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1004 | static jint |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1005 | nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1006 | { |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1007 | AutoJavaStringToUTF8 shaderUTF(_env, shader); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1008 | jint *paramPtr = _env->GetIntArrayElements(params, NULL); |
| 1009 | jint paramLen = _env->GetArrayLength(params); |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1010 | |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1011 | LOG_API("nProgramVertexCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1012 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1013 | jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1014 | _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); |
| 1015 | return ret; |
| 1016 | } |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1017 | |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1018 | // --------------------------------------------------------------------------- |
| 1019 | |
| 1020 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1021 | 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] | 1022 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1023 | LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)", |
| 1024 | con, pointSmooth, lineSmooth, pointSprite); |
| 1025 | return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite); |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1029 | nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jfloat v) |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1030 | { |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1031 | 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] | 1032 | rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v); |
| 1033 | } |
| 1034 | |
| 1035 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1036 | nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jint v) |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1037 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1038 | LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v); |
| 1039 | rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v); |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1042 | |
| 1043 | // --------------------------------------------------------------------------- |
| 1044 | |
| 1045 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1046 | nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1047 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1048 | LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1049 | rsContextBindRootScript(con, (RsScript)script); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1053 | nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1054 | { |
| Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 1055 | LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs); |
| 1056 | rsContextBindProgramStore(con, (RsProgramStore)pfs); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1060 | nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1061 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1062 | LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1063 | rsContextBindProgramFragment(con, (RsProgramFragment)pf); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1066 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1067 | nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf) |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1068 | { |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1069 | LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1070 | rsContextBindProgramVertex(con, (RsProgramVertex)pf); |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1073 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1074 | nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf) |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1075 | { |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1076 | LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf); |
| 1077 | rsContextBindProgramRaster(con, (RsProgramRaster)pf); |
| 1078 | } |
| 1079 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1080 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1081 | // --------------------------------------------------------------------------- |
| 1082 | |
| 1083 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1084 | nSamplerBegin(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1085 | { |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1086 | LOG_API("nSamplerBegin, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1087 | rsSamplerBegin(con); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1091 | nSamplerSet(JNIEnv *_env, jobject _this, RsContext con, jint p, jint v) |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1092 | { |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1093 | LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1094 | rsSamplerSet(con, (RsSamplerParam)p, (RsSamplerValue)v); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| Alex Sakhartchouk | f5b3510 | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 1097 | static void |
| 1098 | nSamplerSet2(JNIEnv *_env, jobject _this, RsContext con, jint p, jfloat v) |
| 1099 | { |
| 1100 | LOG_API("nSamplerSet2, con(%p), param(%i), value(%f)", con, p, v); |
| 1101 | rsSamplerSet2(con, (RsSamplerParam)p, v); |
| 1102 | } |
| 1103 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1104 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1105 | nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con) |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1106 | { |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1107 | LOG_API("nSamplerCreate, con(%p)", con); |
| Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 1108 | return (jint)rsSamplerCreate(con); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1111 | // --------------------------------------------------------------------------- |
| 1112 | |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1113 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1114 | nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jint vtxCount, jint idxCount) |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1115 | { |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1116 | LOG_API("nMeshCreate, con(%p), vtxCount(%i), idxCount(%i)", con, vtxCount, idxCount); |
| 1117 | int id = (int)rsMeshCreate(con, vtxCount, idxCount); |
| 1118 | return id; |
| 1119 | } |
| 1120 | |
| 1121 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1122 | 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] | 1123 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1124 | LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)mesh, (RsAllocation)alloc, slot); |
| 1125 | rsMeshBindVertex(con, (RsMesh)mesh, (RsAllocation)alloc, slot); |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1129 | 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] | 1130 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1131 | LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)mesh, (RsAllocation)alloc); |
| 1132 | rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot); |
| 1133 | } |
| 1134 | |
| Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 1135 | static void |
| 1136 | nMeshInitVertexAttribs(JNIEnv *_env, jobject _this, RsContext con, jint mesh) |
| 1137 | { |
| 1138 | LOG_API("nMeshInitVertexAttribs, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1139 | rsMeshInitVertexAttribs(con, (RsMesh)mesh); |
| 1140 | } |
| 1141 | |
| 1142 | |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1143 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1144 | nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh) |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1145 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1146 | LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1147 | jint vtxCount = 0; |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 1148 | rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1149 | return vtxCount; |
| 1150 | } |
| 1151 | |
| 1152 | static jint |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1153 | nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh) |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1154 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1155 | LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1156 | jint idxCount = 0; |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 1157 | rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1158 | return idxCount; |
| 1159 | } |
| 1160 | |
| 1161 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1162 | 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] | 1163 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1164 | LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1165 | |
| 1166 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 1167 | rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1168 | |
| 1169 | for(jint i = 0; i < numVtxIDs; i ++) { |
| 1170 | _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]); |
| 1171 | } |
| 1172 | |
| 1173 | free(allocs); |
| 1174 | } |
| 1175 | |
| 1176 | static void |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1177 | 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] | 1178 | { |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1179 | LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); |
| 1180 | |
| 1181 | RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); |
| 1182 | uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); |
| 1183 | |
| Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 1184 | rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1185 | |
| 1186 | for(jint i = 0; i < numIndices; i ++) { |
| 1187 | _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]); |
| 1188 | _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]); |
| 1189 | } |
| 1190 | |
| 1191 | free(allocs); |
| 1192 | free(prims); |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | // --------------------------------------------------------------------------- |
| 1196 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1197 | |
| Jason Sams | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 1198 | static const char *classPathName = "android/renderscript/RenderScript"; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1199 | |
| 1200 | static JNINativeMethod methods[] = { |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1201 | {"_nInit", "()V", (void*)_nInit }, |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 1202 | |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1203 | {"nDeviceCreate", "()I", (void*)nDeviceCreate }, |
| 1204 | {"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, |
| 1205 | {"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, |
| 1206 | {"nContextGetUserMessage", "(I[I)V", (void*)nContextGetUserMessage }, |
| 1207 | {"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage }, |
| 1208 | {"nContextPeekMessage", "(I[IZ)I", (void*)nContextPeekMessage }, |
| 1209 | |
| 1210 | {"nContextInitToClient", "(I)V", (void*)nContextInitToClient }, |
| 1211 | {"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1212 | |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1213 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1214 | // All methods below are thread protected in java. |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1215 | {"rsnContextCreate", "(II)I", (void*)nContextCreate }, |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 1216 | {"rsnContextCreateGL", "(IIIIIIIIIIIIF)I", (void*)nContextCreateGL }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1217 | {"rsnContextFinish", "(I)V", (void*)nContextFinish }, |
| 1218 | {"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority }, |
| 1219 | {"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface }, |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1220 | {"rsnContextDestroy", "(I)V", (void*)nContextDestroy }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1221 | {"rsnContextDump", "(II)V", (void*)nContextDump }, |
| 1222 | {"rsnContextPause", "(I)V", (void*)nContextPause }, |
| 1223 | {"rsnContextResume", "(I)V", (void*)nContextResume }, |
| 1224 | {"rsnAssignName", "(II[B)V", (void*)nAssignName }, |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1225 | {"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1226 | {"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 1227 | |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1228 | {"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1229 | {"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream }, |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1230 | {"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1231 | {"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries }, |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1232 | {"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1233 | {"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1234 | |
| Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 1235 | {"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile }, |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 1236 | {"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream }, |
| 1237 | {"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1238 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1239 | {"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 1240 | {"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1241 | {"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData }, |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1242 | {"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1243 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1244 | {"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate }, |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1245 | {"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1246 | |
| Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 1247 | {"rsnAllocationCreateTyped", "(IIII)I", (void*)nAllocationCreateTyped }, |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1248 | {"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, |
| 1249 | {"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1250 | |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1251 | {"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, |
| 1252 | {"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, |
| 1253 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1254 | {"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll }, |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1255 | {"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i }, |
| 1256 | {"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s }, |
| 1257 | {"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b }, |
| 1258 | {"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f }, |
| 1259 | {"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D }, |
| 1260 | {"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i }, |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame^] | 1261 | {"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s }, |
| 1262 | {"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b }, |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1263 | {"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1264 | {"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i }, |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame^] | 1265 | {"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s }, |
| 1266 | {"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1267 | {"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1268 | {"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType}, |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 1269 | {"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D }, |
| 1270 | {"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D }, |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1271 | {"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps }, |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1272 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1273 | {"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation }, |
| 1274 | {"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone }, |
| 1275 | {"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke }, |
| 1276 | {"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV }, |
| 1277 | {"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI }, |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 1278 | {"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1279 | {"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF }, |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 1280 | {"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1281 | {"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 1282 | {"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1283 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1284 | {"rsnScriptCBegin", "(I)V", (void*)nScriptCBegin }, |
| 1285 | {"rsnScriptCSetScript", "(I[BII)V", (void*)nScriptCSetScript }, |
| Shih-wei Liao | eeca435 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 1286 | {"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", (void*)nScriptCCreate }, |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 1287 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1288 | {"rsnProgramStoreBegin", "(III)V", (void*)nProgramStoreBegin }, |
| 1289 | {"rsnProgramStoreDepthFunc", "(II)V", (void*)nProgramStoreDepthFunc }, |
| 1290 | {"rsnProgramStoreDepthMask", "(IZ)V", (void*)nProgramStoreDepthMask }, |
| 1291 | {"rsnProgramStoreColorMask", "(IZZZZ)V", (void*)nProgramStoreColorMask }, |
| 1292 | {"rsnProgramStoreBlendFunc", "(III)V", (void*)nProgramStoreBlendFunc }, |
| 1293 | {"rsnProgramStoreDither", "(IZ)V", (void*)nProgramStoreDither }, |
| 1294 | {"rsnProgramStoreCreate", "(I)I", (void*)nProgramStoreCreate }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1295 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1296 | {"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants }, |
| 1297 | {"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture }, |
| 1298 | {"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler }, |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1299 | |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1300 | {"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate }, |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1301 | |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1302 | {"rsnProgramRasterCreate", "(IZZZ)I", (void*)nProgramRasterCreate }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1303 | {"rsnProgramRasterSetLineWidth", "(IIF)V", (void*)nProgramRasterSetLineWidth }, |
| 1304 | {"rsnProgramRasterSetCullMode", "(III)V", (void*)nProgramRasterSetCullMode }, |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1305 | |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1306 | {"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1307 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1308 | {"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript }, |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1309 | {"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1310 | {"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment }, |
| 1311 | {"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex }, |
| 1312 | {"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster }, |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1313 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1314 | {"rsnSamplerBegin", "(I)V", (void*)nSamplerBegin }, |
| 1315 | {"rsnSamplerSet", "(III)V", (void*)nSamplerSet }, |
| Alex Sakhartchouk | f5b3510 | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 1316 | {"rsnSamplerSet2", "(IIF)V", (void*)nSamplerSet2 }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1317 | {"rsnSamplerCreate", "(I)I", (void*)nSamplerCreate }, |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 1318 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1319 | {"rsnMeshCreate", "(III)I", (void*)nMeshCreate }, |
| 1320 | {"rsnMeshBindVertex", "(IIII)V", (void*)nMeshBindVertex }, |
| 1321 | {"rsnMeshBindIndex", "(IIIII)V", (void*)nMeshBindIndex }, |
| Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 1322 | {"rsnMeshInitVertexAttribs", "(II)V", (void*)nMeshInitVertexAttribs }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1323 | |
| 1324 | {"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount }, |
| 1325 | {"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount }, |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 1326 | {"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices }, |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1327 | {"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices }, |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 1328 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1329 | }; |
| 1330 | |
| 1331 | static int registerFuncs(JNIEnv *_env) |
| 1332 | { |
| 1333 | return android::AndroidRuntime::registerNativeMethods( |
| 1334 | _env, classPathName, methods, NELEM(methods)); |
| 1335 | } |
| 1336 | |
| 1337 | // --------------------------------------------------------------------------- |
| 1338 | |
| 1339 | jint JNI_OnLoad(JavaVM* vm, void* reserved) |
| 1340 | { |
| 1341 | JNIEnv* env = NULL; |
| 1342 | jint result = -1; |
| 1343 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1344 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
| 1345 | LOGE("ERROR: GetEnv failed\n"); |
| 1346 | goto bail; |
| 1347 | } |
| 1348 | assert(env != NULL); |
| 1349 | |
| 1350 | if (registerFuncs(env) < 0) { |
| 1351 | LOGE("ERROR: MediaPlayer native registration failed\n"); |
| 1352 | goto bail; |
| 1353 | } |
| 1354 | |
| 1355 | /* success -- return valid version number */ |
| 1356 | result = JNI_VERSION_1_4; |
| 1357 | |
| 1358 | bail: |
| 1359 | return result; |
| 1360 | } |