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