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