| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 17 | #define LOG_TAG "libRS_jni" |
| 18 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | #include <stdio.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <unistd.h> |
| 23 | #include <math.h> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 24 | #include <utils/misc.h> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | #include <ui/Surface.h> |
| 27 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 28 | #include <core/SkBitmap.h> |
| 29 | |
| Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 30 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | #include "jni.h" |
| 32 | #include "JNIHelp.h" |
| 33 | #include "android_runtime/AndroidRuntime.h" |
| 34 | |
| Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 35 | #include <RenderScript.h> |
| 36 | #include <RenderScriptEnv.h> |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | |
| 38 | //#define LOG_API LOGE |
| 39 | #define LOG_API(...) |
| 40 | |
| 41 | using namespace android; |
| 42 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 43 | // --------------------------------------------------------------------------- |
| 44 | |
| 45 | static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) |
| 46 | { |
| 47 | jclass npeClazz = env->FindClass(exc); |
| 48 | env->ThrowNew(npeClazz, msg); |
| 49 | } |
| 50 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 51 | static jfieldID gContextId = 0; |
| 52 | static jfieldID gNativeBitmapID = 0; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 53 | |
| 54 | static void _nInit(JNIEnv *_env, jclass _this) |
| 55 | { |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 56 | gContextId = _env->GetFieldID(_this, "mContext", "I"); |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 57 | |
| 58 | jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); |
| 59 | gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
| 63 | // --------------------------------------------------------------------------- |
| 64 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 65 | static void |
| 66 | nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str) |
| 67 | { |
| 68 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 69 | LOG_API("nAssignName, con(%p), obj(%p)", con, obj); |
| 70 | |
| 71 | jint len = _env->GetArrayLength(str); |
| 72 | jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); |
| Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 73 | rsAssignName((void *)obj, (const char *)cptr, len); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 74 | _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); |
| 75 | } |
| 76 | |
| 77 | |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 78 | static jint |
| 79 | nFileOpen(JNIEnv *_env, jobject _this, jbyteArray str) |
| 80 | { |
| 81 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 82 | LOG_API("nFileOpen, con(%p)", con); |
| 83 | |
| 84 | jint len = _env->GetArrayLength(str); |
| 85 | jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); |
| 86 | jint ret = (jint)rsFileOpen((const char *)cptr, len); |
| 87 | _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); |
| 88 | return ret; |
| 89 | } |
| 90 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 91 | // --------------------------------------------------------------------------- |
| 92 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 93 | static jint |
| 94 | nDeviceCreate(JNIEnv *_env, jobject _this) |
| 95 | { |
| 96 | LOG_API("nDeviceCreate"); |
| 97 | return (jint)rsDeviceCreate(); |
| 98 | } |
| 99 | |
| 100 | static void |
| 101 | nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) |
| 102 | { |
| 103 | LOG_API("nDeviceDestroy"); |
| 104 | return rsDeviceDestroy((RsDevice)dev); |
| 105 | } |
| 106 | |
| 107 | static jint |
| 108 | nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver) |
| 109 | { |
| 110 | LOG_API("nContextCreate"); |
| 111 | |
| 112 | if (wnd == NULL) { |
| 113 | not_valid_surface: |
| 114 | doThrow(_env, "java/lang/IllegalArgumentException", |
| 115 | "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"); |
| 116 | return 0; |
| 117 | } |
| 118 | jclass surface_class = _env->FindClass("android/view/Surface"); |
| 119 | jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I"); |
| 120 | Surface * window = (Surface*)_env->GetIntField(wnd, surfaceFieldID); |
| 121 | if (window == NULL) |
| 122 | goto not_valid_surface; |
| 123 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 124 | return (jint)rsContextCreate((RsDevice)dev, window, ver); |
| 125 | } |
| 126 | |
| 127 | static void |
| 128 | nContextDestroy(JNIEnv *_env, jobject _this, jint con) |
| 129 | { |
| 130 | LOG_API("nContextDestroy, con(%p)", (RsContext)con); |
| 131 | return rsContextDestroy((RsContext)con); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | static void |
| 136 | nElementBegin(JNIEnv *_env, jobject _this) |
| 137 | { |
| 138 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 139 | LOG_API("nElementBegin, con(%p)", con); |
| 140 | rsElementBegin(); |
| 141 | } |
| 142 | |
| 143 | static void |
| 144 | nElementAddPredefined(JNIEnv *_env, jobject _this, jint predef) |
| 145 | { |
| 146 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 147 | LOG_API("nElementAddPredefined, con(%p), predef(%i)", con, predef); |
| 148 | rsElementAddPredefined((RsElementPredefined)predef); |
| 149 | } |
| 150 | |
| 151 | static void |
| 152 | nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jint norm, jint bits) |
| 153 | { |
| 154 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 155 | LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits); |
| 156 | rsElementAdd((RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits); |
| 157 | } |
| 158 | |
| 159 | static jint |
| 160 | nElementCreate(JNIEnv *_env, jobject _this) |
| 161 | { |
| 162 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 163 | LOG_API("nElementCreate, con(%p)", con); |
| 164 | return (jint)rsElementCreate(); |
| 165 | } |
| 166 | |
| 167 | static jint |
| 168 | nElementGetPredefined(JNIEnv *_env, jobject _this, jint predef) |
| 169 | { |
| 170 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 171 | LOG_API("nElementGetPredefined, con(%p) predef(%i)", con, predef); |
| 172 | return (jint)rsElementGetPredefined((RsElementPredefined)predef); |
| 173 | } |
| 174 | |
| 175 | static void |
| 176 | nElementDestroy(JNIEnv *_env, jobject _this, jint e) |
| 177 | { |
| 178 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 179 | LOG_API("nElementDestroy, con(%p) e(%p)", con, (RsElement)e); |
| 180 | rsElementDestroy((RsElement)e); |
| 181 | } |
| 182 | |
| 183 | // ----------------------------------- |
| 184 | |
| 185 | static void |
| 186 | nTypeBegin(JNIEnv *_env, jobject _this, jint eID) |
| 187 | { |
| 188 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 189 | LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID); |
| 190 | rsTypeBegin((RsElement)eID); |
| 191 | } |
| 192 | |
| 193 | static void |
| 194 | nTypeAdd(JNIEnv *_env, jobject _this, jint dim, jint val) |
| 195 | { |
| 196 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 197 | LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val); |
| 198 | rsTypeAdd((RsDimension)dim, val); |
| 199 | } |
| 200 | |
| 201 | static jint |
| 202 | nTypeCreate(JNIEnv *_env, jobject _this) |
| 203 | { |
| 204 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 205 | LOG_API("nTypeCreate, con(%p)", con); |
| 206 | return (jint)rsTypeCreate(); |
| 207 | } |
| 208 | |
| 209 | static void |
| 210 | nTypeDestroy(JNIEnv *_env, jobject _this, jint eID) |
| 211 | { |
| 212 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 213 | LOG_API("nTypeDestroy, con(%p), t(%p)", con, (RsType)eID); |
| 214 | rsTypeDestroy((RsType)eID); |
| 215 | } |
| 216 | |
| 217 | // ----------------------------------- |
| 218 | |
| 219 | static jint |
| 220 | nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e) |
| 221 | { |
| 222 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 223 | LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e); |
| 224 | return (jint) rsAllocationCreateTyped((RsElement)e); |
| 225 | } |
| 226 | |
| 227 | static jint |
| 228 | nAllocationCreatePredefSized(JNIEnv *_env, jobject _this, jint predef, jint count) |
| 229 | { |
| 230 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 231 | LOG_API("nAllocationCreatePredefSized, con(%p), predef(%i), count(%i)", con, predef, count); |
| 232 | return (jint) rsAllocationCreatePredefSized((RsElementPredefined)predef, count); |
| 233 | } |
| 234 | |
| 235 | static jint |
| 236 | nAllocationCreateSized(JNIEnv *_env, jobject _this, jint e, jint count) |
| 237 | { |
| 238 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 239 | LOG_API("nAllocationCreateSized, con(%p), e(%p), count(%i)", con, (RsElement)e, count); |
| 240 | return (jint) rsAllocationCreateSized((RsElement)e, count); |
| 241 | } |
| 242 | |
| 243 | static void |
| 244 | nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip) |
| 245 | { |
| 246 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 247 | LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip); |
| 248 | rsAllocationUploadToTexture((RsAllocation)a, mip); |
| 249 | } |
| 250 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 251 | static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg) |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 252 | { |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 253 | switch (cfg) { |
| 254 | case SkBitmap::kA8_Config: |
| 255 | return RS_ELEMENT_A_8; |
| 256 | case SkBitmap::kARGB_4444_Config: |
| 257 | return RS_ELEMENT_RGBA_4444; |
| 258 | case SkBitmap::kARGB_8888_Config: |
| 259 | return RS_ELEMENT_RGBA_8888; |
| 260 | case SkBitmap::kRGB_565_Config: |
| 261 | return RS_ELEMENT_RGB_565; |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 262 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 263 | default: |
| 264 | break; |
| 265 | } |
| 266 | // If we don't have a conversion mark it as a user type. |
| 267 | LOGE("Unsupported bitmap type"); |
| 268 | return RS_ELEMENT_USER_U8; |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 271 | static int |
| 272 | nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) |
| 273 | { |
| 274 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 275 | SkBitmap const * nativeBitmap = |
| 276 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 277 | const SkBitmap& bitmap(*nativeBitmap); |
| 278 | SkBitmap::Config config = bitmap.getConfig(); |
| 279 | |
| 280 | RsElementPredefined e = SkBitmapToPredefined(config); |
| 281 | |
| 282 | if (e != RS_ELEMENT_USER_U8) { |
| 283 | bitmap.lockPixels(); |
| 284 | const int w = bitmap.width(); |
| 285 | const int h = bitmap.height(); |
| 286 | const void* ptr = bitmap.getPixels(); |
| 287 | jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr); |
| 288 | bitmap.unlockPixels(); |
| 289 | return id; |
| 290 | } |
| 291 | return 0; |
| 292 | } |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 293 | |
| Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 294 | static int |
| 295 | nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) |
| 296 | { |
| 297 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 298 | SkBitmap const * nativeBitmap = |
| 299 | (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); |
| 300 | const SkBitmap& bitmap(*nativeBitmap); |
| 301 | SkBitmap::Config config = bitmap.getConfig(); |
| 302 | |
| 303 | RsElementPredefined e = SkBitmapToPredefined(config); |
| 304 | |
| 305 | if (e != RS_ELEMENT_USER_U8) { |
| 306 | bitmap.lockPixels(); |
| 307 | const int w = bitmap.width(); |
| 308 | const int h = bitmap.height(); |
| 309 | const void* ptr = bitmap.getPixels(); |
| 310 | jint id = (jint)rsAllocationCreateFromBitmapBoxed(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr); |
| 311 | bitmap.unlockPixels(); |
| 312 | return id; |
| 313 | } |
| 314 | return 0; |
| 315 | } |
| 316 | |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 317 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 318 | static void |
| 319 | nAllocationDestroy(JNIEnv *_env, jobject _this, jint a) |
| 320 | { |
| 321 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 322 | LOG_API("nAllocationDestroy, con(%p), a(%p)", con, (RsAllocation)a); |
| 323 | rsAllocationDestroy((RsAllocation)a); |
| 324 | } |
| 325 | |
| 326 | static void |
| 327 | nAllocationData_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data) |
| 328 | { |
| 329 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 330 | jint len = _env->GetArrayLength(data); |
| 331 | LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 332 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 333 | rsAllocationData((RsAllocation)alloc, ptr); |
| 334 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 335 | } |
| 336 | |
| 337 | static void |
| 338 | nAllocationData_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data) |
| 339 | { |
| 340 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 341 | jint len = _env->GetArrayLength(data); |
| 342 | LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 343 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 344 | rsAllocationData((RsAllocation)alloc, ptr); |
| 345 | _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); |
| 346 | } |
| 347 | |
| 348 | static void |
| 349 | nAllocationSubData1D_i(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jintArray data) |
| 350 | { |
| 351 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 352 | jint len = _env->GetArrayLength(data); |
| 353 | LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len); |
| 354 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 355 | rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr); |
| 356 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 357 | } |
| 358 | |
| 359 | static void |
| 360 | nAllocationSubData1D_f(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jfloatArray data) |
| 361 | { |
| 362 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 363 | jint len = _env->GetArrayLength(data); |
| 364 | LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len); |
| 365 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 366 | rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr); |
| 367 | _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); |
| 368 | } |
| 369 | |
| 370 | static void |
| 371 | nAllocationSubData2D_i(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data) |
| 372 | { |
| 373 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 374 | jint len = _env->GetArrayLength(data); |
| 375 | LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| 376 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 377 | rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr); |
| 378 | _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); |
| 379 | } |
| 380 | |
| 381 | static void |
| 382 | nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data) |
| 383 | { |
| 384 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 385 | jint len = _env->GetArrayLength(data); |
| 386 | LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); |
| 387 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 388 | rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr); |
| 389 | _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); |
| 390 | } |
| 391 | |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 392 | static void |
| 393 | nAllocationRead_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data) |
| 394 | { |
| 395 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 396 | jint len = _env->GetArrayLength(data); |
| 397 | LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 398 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 399 | rsAllocationData((RsAllocation)alloc, ptr); |
| 400 | _env->ReleaseIntArrayElements(data, ptr, JNI_COMMIT); |
| 401 | } |
| 402 | |
| 403 | static void |
| 404 | nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data) |
| 405 | { |
| 406 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 407 | jint len = _env->GetArrayLength(data); |
| 408 | LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); |
| 409 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 410 | rsAllocationData((RsAllocation)alloc, ptr); |
| 411 | _env->ReleaseFloatArrayElements(data, ptr, JNI_COMMIT); |
| 412 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 413 | |
| 414 | |
| 415 | // ----------------------------------- |
| 416 | |
| 417 | static void |
| 418 | nTriangleMeshDestroy(JNIEnv *_env, jobject _this, jint tm) |
| 419 | { |
| 420 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 421 | LOG_API("nTriangleMeshDestroy, con(%p), tm(%p)", con, (RsAllocation)tm); |
| 422 | rsTriangleMeshDestroy((RsTriangleMesh)tm); |
| 423 | } |
| 424 | |
| 425 | static void |
| 426 | nTriangleMeshBegin(JNIEnv *_env, jobject _this, jint v, jint i) |
| 427 | { |
| 428 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 429 | LOG_API("nTriangleMeshBegin, con(%p), vertex(%p), index(%p)", con, (RsElement)v, (RsElement)i); |
| 430 | rsTriangleMeshBegin((RsElement)v, (RsElement)i); |
| 431 | } |
| 432 | |
| 433 | static void |
| 434 | nTriangleMeshAddVertex_XY(JNIEnv *_env, jobject _this, jfloat x, jfloat y) |
| 435 | { |
| 436 | float v[] = {x, y}; |
| 437 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 438 | LOG_API("nTriangleMeshAddVertex_XY, con(%p), x(%f), y(%f)", con, x, y); |
| 439 | rsTriangleMeshAddVertex(v); |
| 440 | } |
| 441 | |
| 442 | static void |
| 443 | nTriangleMeshAddVertex_XYZ(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z) |
| 444 | { |
| 445 | float v[] = {x, y, z}; |
| 446 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 447 | LOG_API("nTriangleMeshAddVertex_XYZ, con(%p), x(%f), y(%f), z(%f)", con, x, y, z); |
| 448 | rsTriangleMeshAddVertex(v); |
| 449 | } |
| 450 | |
| 451 | static void |
| 452 | nTriangleMeshAddVertex_XY_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat s, jfloat t) |
| 453 | { |
| 454 | float v[] = {s, t, x, y}; |
| 455 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 456 | LOG_API("nTriangleMeshAddVertex_XY_ST, con(%p), x(%f), y(%f), s(%f), t(%f)", con, x, y, s, t); |
| 457 | rsTriangleMeshAddVertex(v); |
| 458 | } |
| 459 | |
| 460 | static void |
| 461 | nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t) |
| 462 | { |
| 463 | float v[] = {s, t, x, y, z}; |
| 464 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 465 | LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t); |
| 466 | rsTriangleMeshAddVertex(v); |
| 467 | } |
| 468 | |
| 469 | static void |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 470 | nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz) |
| 471 | { |
| 472 | float v[] = {nx, ny, nz, s, t, x, y, z}; |
| 473 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 474 | LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t); |
| 475 | rsTriangleMeshAddVertex(v); |
| 476 | } |
| 477 | |
| 478 | static void |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 479 | nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3) |
| 480 | { |
| 481 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 482 | LOG_API("nTriangleMeshAddTriangle, con(%p), i1(%i), i2(%i), i3(%i)", con, i1, i2, i3); |
| 483 | rsTriangleMeshAddTriangle(i1, i2, i3); |
| 484 | } |
| 485 | |
| 486 | static jint |
| 487 | nTriangleMeshCreate(JNIEnv *_env, jobject _this) |
| 488 | { |
| 489 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 490 | LOG_API("nTriangleMeshCreate, con(%p)", con); |
| 491 | return (jint) rsTriangleMeshCreate(); |
| 492 | } |
| 493 | |
| 494 | // ----------------------------------- |
| 495 | |
| 496 | static void |
| 497 | nAdapter1DDestroy(JNIEnv *_env, jobject _this, jint adapter) |
| 498 | { |
| 499 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 500 | LOG_API("nAdapter1DDestroy, con(%p), adapter(%p)", con, (RsAdapter1D)adapter); |
| 501 | rsAdapter1DDestroy((RsAdapter1D)adapter); |
| 502 | } |
| 503 | |
| 504 | static void |
| 505 | nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) |
| 506 | { |
| 507 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 508 | LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc); |
| 509 | rsAdapter1DBindAllocation((RsAdapter1D)adapter, (RsAllocation)alloc); |
| 510 | } |
| 511 | |
| 512 | static void |
| 513 | nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) |
| 514 | { |
| 515 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 516 | LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value); |
| 517 | rsAdapter1DSetConstraint((RsAdapter1D)adapter, (RsDimension)dim, value); |
| 518 | } |
| 519 | |
| 520 | static void |
| 521 | nAdapter1DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) |
| 522 | { |
| 523 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 524 | jint len = _env->GetArrayLength(data); |
| 525 | LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); |
| 526 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 527 | rsAdapter1DData((RsAdapter1D)adapter, ptr); |
| 528 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | nAdapter1DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jintArray data) |
| 533 | { |
| 534 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 535 | jint len = _env->GetArrayLength(data); |
| 536 | LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); |
| 537 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 538 | rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr); |
| 539 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 540 | } |
| 541 | |
| 542 | static void |
| 543 | nAdapter1DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) |
| 544 | { |
| 545 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 546 | jint len = _env->GetArrayLength(data); |
| 547 | LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); |
| 548 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 549 | rsAdapter1DData((RsAdapter1D)adapter, ptr); |
| 550 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 551 | } |
| 552 | |
| 553 | static void |
| 554 | nAdapter1DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jfloatArray data) |
| 555 | { |
| 556 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 557 | jint len = _env->GetArrayLength(data); |
| 558 | LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); |
| 559 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 560 | rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr); |
| 561 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 562 | } |
| 563 | |
| 564 | static jint |
| 565 | nAdapter1DCreate(JNIEnv *_env, jobject _this) |
| 566 | { |
| 567 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 568 | LOG_API("nAdapter1DCreate, con(%p)", con); |
| 569 | return (jint)rsAdapter1DCreate(); |
| 570 | } |
| 571 | |
| 572 | // ----------------------------------- |
| 573 | |
| 574 | static void |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 575 | nAdapter2DDestroy(JNIEnv *_env, jobject _this, jint adapter) |
| 576 | { |
| 577 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 578 | LOG_API("nAdapter2DDestroy, con(%p), adapter(%p)", con, (RsAdapter2D)adapter); |
| 579 | rsAdapter2DDestroy((RsAdapter2D)adapter); |
| 580 | } |
| 581 | |
| 582 | static void |
| 583 | nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) |
| 584 | { |
| 585 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 586 | LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc); |
| 587 | rsAdapter2DBindAllocation((RsAdapter2D)adapter, (RsAllocation)alloc); |
| 588 | } |
| 589 | |
| 590 | static void |
| 591 | nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) |
| 592 | { |
| 593 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 594 | LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value); |
| 595 | rsAdapter2DSetConstraint((RsAdapter2D)adapter, (RsDimension)dim, value); |
| 596 | } |
| 597 | |
| 598 | static void |
| 599 | nAdapter2DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) |
| 600 | { |
| 601 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 602 | jint len = _env->GetArrayLength(data); |
| 603 | LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); |
| 604 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 605 | rsAdapter2DData((RsAdapter2D)adapter, ptr); |
| 606 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 607 | } |
| 608 | |
| 609 | static void |
| 610 | nAdapter2DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) |
| 611 | { |
| 612 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 613 | jint len = _env->GetArrayLength(data); |
| 614 | LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); |
| 615 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 616 | rsAdapter2DData((RsAdapter2D)adapter, ptr); |
| 617 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 618 | } |
| 619 | |
| 620 | static void |
| 621 | nAdapter2DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data) |
| 622 | { |
| 623 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 624 | jint len = _env->GetArrayLength(data); |
| 625 | LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", |
| 626 | con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); |
| 627 | jint *ptr = _env->GetIntArrayElements(data, NULL); |
| 628 | rsAdapter2DSubData((RsAdapter2D)adapter, xoff, yoff, w, h, ptr); |
| 629 | _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 630 | } |
| 631 | |
| 632 | static void |
| 633 | nAdapter2DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data) |
| 634 | { |
| 635 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 636 | jint len = _env->GetArrayLength(data); |
| 637 | LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", |
| 638 | con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); |
| 639 | jfloat *ptr = _env->GetFloatArrayElements(data, NULL); |
| 640 | rsAdapter2DSubData((RsAdapter1D)adapter, xoff, yoff, w, h, ptr); |
| 641 | _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); |
| 642 | } |
| 643 | |
| 644 | static jint |
| 645 | nAdapter2DCreate(JNIEnv *_env, jobject _this) |
| 646 | { |
| 647 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 648 | LOG_API("nAdapter2DCreate, con(%p)", con); |
| 649 | return (jint)rsAdapter2DCreate(); |
| 650 | } |
| 651 | |
| 652 | // ----------------------------------- |
| 653 | |
| 654 | static void |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 655 | nScriptDestroy(JNIEnv *_env, jobject _this, jint script) |
| 656 | { |
| 657 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 658 | LOG_API("nScriptDestroy, con(%p), script(%p)", con, (RsScript)script); |
| 659 | rsScriptDestroy((RsScript)script); |
| 660 | } |
| 661 | |
| 662 | static void |
| 663 | nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint slot) |
| 664 | { |
| 665 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 666 | LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); |
| 667 | rsScriptBindAllocation((RsScript)script, (RsAllocation)alloc, slot); |
| 668 | } |
| 669 | |
| 670 | static void |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 671 | nScriptSetClearColor(JNIEnv *_env, jobject _this, jint script, jfloat r, jfloat g, jfloat b, jfloat a) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 672 | { |
| 673 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 674 | LOG_API("nScriptSetClearColor, con(%p), s(%p), r(%f), g(%f), b(%f), a(%f)", con, script, r, g, b, a); |
| 675 | rsScriptSetClearColor((RsScript)script, r, g, b, a); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | static void |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 679 | nScriptSetClearDepth(JNIEnv *_env, jobject _this, jint script, jfloat d) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 680 | { |
| 681 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 682 | LOG_API("nScriptCSetClearDepth, con(%p), s(%p), depth(%f)", con, script, d); |
| 683 | rsScriptSetClearDepth((RsScript)script, d); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static void |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 687 | nScriptSetClearStencil(JNIEnv *_env, jobject _this, jint script, jint stencil) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 688 | { |
| 689 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 690 | LOG_API("nScriptCSetClearStencil, con(%p), s(%p), stencil(%i)", con, script, stencil); |
| 691 | rsScriptSetClearStencil((RsScript)script, stencil); |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static void |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 695 | nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 696 | { |
| 697 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 698 | LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, script, timeZone); |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 699 | |
| 700 | jint length = _env->GetArrayLength(timeZone); |
| 701 | jbyte* timeZone_ptr; |
| 702 | timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); |
| 703 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 704 | rsScriptSetTimeZone((RsScript)script, (const char *)timeZone_ptr, length); |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 705 | |
| 706 | if (timeZone_ptr) { |
| 707 | _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); |
| 708 | } |
| 709 | } |
| 710 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 711 | // ----------------------------------- |
| 712 | |
| 713 | static void |
| 714 | nScriptCBegin(JNIEnv *_env, jobject _this) |
| 715 | { |
| 716 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 717 | LOG_API("nScriptCBegin, con(%p)", con); |
| 718 | rsScriptCBegin(); |
| 719 | } |
| 720 | |
| Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 721 | static void |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 722 | nScriptCAddType(JNIEnv *_env, jobject _this, jint type) |
| 723 | { |
| 724 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 725 | LOG_API("nScriptCAddType, con(%p), type(%p)", con, (RsType)type); |
| 726 | rsScriptCAddType((RsType)type); |
| 727 | } |
| 728 | |
| 729 | static void |
| 730 | nScriptCSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot) |
| 731 | { |
| 732 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 733 | LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot); |
| 734 | rsScriptCSetRoot(isRoot); |
| 735 | } |
| 736 | |
| 737 | static void |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 738 | nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef, |
| 739 | jint offset, jint length) |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 740 | { |
| 741 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 742 | LOG_API("!!! nScriptCSetScript, con(%p)", con); |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 743 | jint _exception = 0; |
| 744 | jint remaining; |
| 745 | jbyte* script_base = 0; |
| 746 | jbyte* script_ptr; |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 747 | if (!scriptRef) { |
| 748 | _exception = 1; |
| 749 | //_env->ThrowNew(IAEClass, "script == null"); |
| 750 | goto exit; |
| 751 | } |
| 752 | if (offset < 0) { |
| 753 | _exception = 1; |
| 754 | //_env->ThrowNew(IAEClass, "offset < 0"); |
| 755 | goto exit; |
| 756 | } |
| 757 | if (length < 0) { |
| 758 | _exception = 1; |
| 759 | //_env->ThrowNew(IAEClass, "length < 0"); |
| 760 | goto exit; |
| 761 | } |
| 762 | remaining = _env->GetArrayLength(scriptRef) - offset; |
| 763 | if (remaining < length) { |
| 764 | _exception = 1; |
| 765 | //_env->ThrowNew(IAEClass, "length > script.length - offset"); |
| 766 | goto exit; |
| 767 | } |
| 768 | script_base = (jbyte *) |
| 769 | _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); |
| 770 | script_ptr = script_base + offset; |
| 771 | |
| Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 772 | rsScriptCSetText((const char *)script_ptr, length); |
| 773 | |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 774 | exit: |
| 775 | if (script_base) { |
| 776 | _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, |
| 777 | _exception ? JNI_ABORT: 0); |
| 778 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static jint |
| 782 | nScriptCCreate(JNIEnv *_env, jobject _this) |
| 783 | { |
| 784 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 785 | LOG_API("nScriptCCreate, con(%p)", con); |
| 786 | return (jint)rsScriptCCreate(); |
| 787 | } |
| 788 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 789 | static void |
| 790 | nScriptCAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value) |
| 791 | { |
| 792 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 793 | const char* n = _env->GetStringUTFChars(name, NULL); |
| 794 | LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value); |
| 795 | rsScriptCSetDefineI32(n, value); |
| 796 | _env->ReleaseStringUTFChars(name, n); |
| 797 | } |
| 798 | |
| 799 | static void |
| 800 | nScriptCAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value) |
| 801 | { |
| 802 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 803 | const char* n = _env->GetStringUTFChars(name, NULL); |
| 804 | LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value); |
| 805 | rsScriptCSetDefineF(n, value); |
| 806 | _env->ReleaseStringUTFChars(name, n); |
| 807 | } |
| 808 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 809 | // --------------------------------------------------------------------------- |
| 810 | |
| 811 | static void |
| 812 | nProgramFragmentStoreBegin(JNIEnv *_env, jobject _this, jint in, jint out) |
| 813 | { |
| 814 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 815 | LOG_API("nProgramFragmentStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); |
| 816 | rsProgramFragmentStoreBegin((RsElement)in, (RsElement)out); |
| 817 | } |
| 818 | |
| 819 | static void |
| 820 | nProgramFragmentStoreDepthFunc(JNIEnv *_env, jobject _this, jint func) |
| 821 | { |
| 822 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 823 | LOG_API("nProgramFragmentStoreDepthFunc, con(%p), func(%i)", con, func); |
| 824 | rsProgramFragmentStoreDepthFunc((RsDepthFunc)func); |
| 825 | } |
| 826 | |
| 827 | static void |
| 828 | nProgramFragmentStoreDepthMask(JNIEnv *_env, jobject _this, jboolean enable) |
| 829 | { |
| 830 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 831 | LOG_API("nProgramFragmentStoreDepthMask, con(%p), enable(%i)", con, enable); |
| 832 | rsProgramFragmentStoreDepthMask(enable); |
| 833 | } |
| 834 | |
| 835 | static void |
| 836 | nProgramFragmentStoreColorMask(JNIEnv *_env, jobject _this, jboolean r, jboolean g, jboolean b, jboolean a) |
| 837 | { |
| 838 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 839 | LOG_API("nProgramFragmentStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); |
| 840 | rsProgramFragmentStoreColorMask(r, g, b, a); |
| 841 | } |
| 842 | |
| 843 | static void |
| 844 | nProgramFragmentStoreBlendFunc(JNIEnv *_env, jobject _this, int src, int dst) |
| 845 | { |
| 846 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 847 | LOG_API("nProgramFragmentStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); |
| 848 | rsProgramFragmentStoreBlendFunc((RsBlendSrcFunc)src, (RsBlendDstFunc)dst); |
| 849 | } |
| 850 | |
| 851 | static void |
| 852 | nProgramFragmentStoreDither(JNIEnv *_env, jobject _this, jboolean enable) |
| 853 | { |
| 854 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 855 | LOG_API("nProgramFragmentStoreDither, con(%p), enable(%i)", con, enable); |
| 856 | rsProgramFragmentStoreDither(enable); |
| 857 | } |
| 858 | |
| 859 | static jint |
| 860 | nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this) |
| 861 | { |
| 862 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 863 | LOG_API("nProgramFragmentStoreCreate, con(%p)", con); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 864 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 865 | return (jint)rsProgramFragmentStoreCreate(); |
| 866 | } |
| 867 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 868 | static void |
| 869 | nProgramFragmentStoreDestroy(JNIEnv *_env, jobject _this, jint pgm) |
| 870 | { |
| 871 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 872 | LOG_API("nProgramFragmentStoreDestroy, con(%p), pgm(%i)", con, pgm); |
| 873 | rsProgramFragmentStoreDestroy((RsProgramFragmentStore)pgm); |
| 874 | } |
| 875 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 876 | // --------------------------------------------------------------------------- |
| 877 | |
| 878 | static void |
| 879 | nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out) |
| 880 | { |
| 881 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 882 | LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); |
| 883 | rsProgramFragmentBegin((RsElement)in, (RsElement)out); |
| 884 | } |
| 885 | |
| 886 | static void |
| 887 | nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) |
| 888 | { |
| 889 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 890 | LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); |
| 891 | rsProgramFragmentBindTexture((RsProgramFragment)vpf, slot, (RsAllocation)a); |
| 892 | } |
| 893 | |
| 894 | static void |
| 895 | nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) |
| 896 | { |
| 897 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 898 | LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); |
| 899 | rsProgramFragmentBindSampler((RsProgramFragment)vpf, slot, (RsSampler)a); |
| 900 | } |
| 901 | |
| 902 | static void |
| 903 | nProgramFragmentSetType(JNIEnv *_env, jobject _this, jint slot, jint vt) |
| 904 | { |
| 905 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 906 | LOG_API("nProgramFragmentSetType, con(%p), slot(%i), vt(%p)", con, slot, (RsType)vt); |
| 907 | rsProgramFragmentSetType(slot, (RsType)vt); |
| 908 | } |
| 909 | |
| 910 | static void |
| 911 | nProgramFragmentSetEnvMode(JNIEnv *_env, jobject _this, jint slot, jint env) |
| 912 | { |
| 913 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 914 | LOG_API("nProgramFragmentSetEnvMode, con(%p), slot(%i), vt(%i)", con, slot, env); |
| 915 | rsProgramFragmentSetEnvMode(slot, (RsTexEnvMode)env); |
| 916 | } |
| 917 | |
| 918 | static void |
| 919 | nProgramFragmentSetTexEnable(JNIEnv *_env, jobject _this, jint slot, jboolean enable) |
| 920 | { |
| 921 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 922 | LOG_API("nProgramFragmentSetTexEnable, con(%p), slot(%i), enable(%i)", con, slot, enable); |
| 923 | rsProgramFragmentSetTexEnable(slot, enable); |
| 924 | } |
| 925 | |
| 926 | static jint |
| 927 | nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable) |
| 928 | { |
| 929 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 930 | LOG_API("nProgramFragmentCreate, con(%p)", con); |
| 931 | return (jint)rsProgramFragmentCreate(); |
| 932 | } |
| 933 | |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 934 | static void |
| 935 | nProgramFragmentDestroy(JNIEnv *_env, jobject _this, jint pgm) |
| 936 | { |
| 937 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 938 | LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm); |
| 939 | rsProgramFragmentDestroy((RsProgramFragment)pgm); |
| 940 | } |
| 941 | |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 942 | // --------------------------------------------------------------------------- |
| 943 | |
| 944 | static void |
| 945 | nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out) |
| 946 | { |
| 947 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 948 | LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); |
| 949 | rsProgramVertexBegin((RsElement)in, (RsElement)out); |
| 950 | } |
| 951 | |
| 952 | static void |
| Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 953 | nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint a) |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 954 | { |
| 955 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 956 | LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a); |
| Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 957 | rsProgramVertexBindAllocation((RsProgramFragment)vpv, (RsAllocation)a); |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | static void |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 961 | nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable) |
| 962 | { |
| 963 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 964 | LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable); |
| 965 | rsProgramVertexSetTextureMatrixEnable(enable); |
| 966 | } |
| 967 | |
| Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 968 | static void |
| 969 | nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light) |
| 970 | { |
| 971 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 972 | LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light); |
| 973 | rsProgramVertexAddLight((RsLight)light); |
| 974 | } |
| 975 | |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 976 | static jint |
| 977 | nProgramVertexCreate(JNIEnv *_env, jobject _this) |
| 978 | { |
| 979 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 980 | LOG_API("nProgramVertexCreate, con(%p)", con); |
| 981 | return (jint)rsProgramVertexCreate(); |
| 982 | } |
| 983 | |
| 984 | static void |
| 985 | nProgramVertexDestroy(JNIEnv *_env, jobject _this, jint pgm) |
| 986 | { |
| 987 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 988 | LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm); |
| 989 | rsProgramFragmentDestroy((RsProgramFragment)pgm); |
| 990 | } |
| 991 | |
| 992 | |
| 993 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 994 | |
| 995 | // --------------------------------------------------------------------------- |
| 996 | |
| 997 | static void |
| 998 | nContextBindRootScript(JNIEnv *_env, jobject _this, jint script) |
| 999 | { |
| 1000 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1001 | LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script); |
| 1002 | rsContextBindRootScript((RsScript)script); |
| 1003 | } |
| 1004 | |
| 1005 | static void |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1006 | nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs) |
| 1007 | { |
| 1008 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1009 | LOG_API("nContextBindProgramFragmentStore, con(%p), pfs(%p)", con, (RsProgramFragmentStore)pfs); |
| 1010 | rsContextBindProgramFragmentStore((RsProgramFragmentStore)pfs); |
| 1011 | } |
| 1012 | |
| 1013 | static void |
| 1014 | nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf) |
| 1015 | { |
| 1016 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1017 | LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf); |
| 1018 | rsContextBindProgramFragment((RsProgramFragment)pf); |
| 1019 | } |
| 1020 | |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1021 | static void |
| 1022 | nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf) |
| 1023 | { |
| 1024 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1025 | LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf); |
| 1026 | rsContextBindProgramVertex((RsProgramVertex)pf); |
| 1027 | } |
| 1028 | |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1029 | static void |
| 1030 | nContextAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value) |
| 1031 | { |
| 1032 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1033 | const char* n = _env->GetStringUTFChars(name, NULL); |
| 1034 | LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value); |
| 1035 | rsContextSetDefineI32(n, value); |
| 1036 | _env->ReleaseStringUTFChars(name, n); |
| 1037 | } |
| 1038 | |
| 1039 | static void |
| 1040 | nContextAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value) |
| 1041 | { |
| 1042 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1043 | const char* n = _env->GetStringUTFChars(name, NULL); |
| 1044 | LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value); |
| 1045 | rsContextSetDefineF(n, value); |
| 1046 | _env->ReleaseStringUTFChars(name, n); |
| 1047 | } |
| 1048 | |
| 1049 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1050 | // --------------------------------------------------------------------------- |
| 1051 | |
| 1052 | static void |
| 1053 | nSamplerDestroy(JNIEnv *_env, jobject _this, jint s) |
| 1054 | { |
| 1055 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1056 | LOG_API("nSamplerDestroy, con(%p), sampler(%p)", con, (RsSampler)s); |
| 1057 | rsSamplerDestroy((RsSampler)s); |
| 1058 | } |
| 1059 | |
| 1060 | static void |
| 1061 | nSamplerBegin(JNIEnv *_env, jobject _this) |
| 1062 | { |
| 1063 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1064 | LOG_API("nSamplerBegin, con(%p)", con); |
| 1065 | rsSamplerBegin(); |
| 1066 | } |
| 1067 | |
| 1068 | static void |
| 1069 | nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v) |
| 1070 | { |
| 1071 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1072 | LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v); |
| 1073 | rsSamplerSet((RsSamplerParam)p, (RsSamplerValue)v); |
| 1074 | } |
| 1075 | |
| 1076 | static jint |
| 1077 | nSamplerCreate(JNIEnv *_env, jobject _this) |
| 1078 | { |
| 1079 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1080 | LOG_API("nSamplerCreate, con(%p)", con); |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1081 | return (jint)rsSamplerCreate(); |
| 1082 | } |
| 1083 | |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1084 | // --------------------------------------------------------------------------- |
| 1085 | |
| 1086 | static void |
| 1087 | nLightBegin(JNIEnv *_env, jobject _this) |
| 1088 | { |
| 1089 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1090 | LOG_API("nLightBegin, con(%p)", con); |
| 1091 | rsLightBegin(); |
| 1092 | } |
| 1093 | |
| 1094 | static void |
| 1095 | nLightSetIsMono(JNIEnv *_env, jobject _this, jboolean isMono) |
| 1096 | { |
| 1097 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1098 | LOG_API("nLightSetIsMono, con(%p), isMono(%i)", con, isMono); |
| 1099 | rsLightSetMonochromatic(isMono); |
| 1100 | } |
| 1101 | |
| 1102 | static void |
| 1103 | nLightSetIsLocal(JNIEnv *_env, jobject _this, jboolean isLocal) |
| 1104 | { |
| 1105 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1106 | LOG_API("nLightSetIsLocal, con(%p), isLocal(%i)", con, isLocal); |
| 1107 | rsLightSetLocal(isLocal); |
| 1108 | } |
| 1109 | |
| 1110 | static jint |
| 1111 | nLightCreate(JNIEnv *_env, jobject _this) |
| 1112 | { |
| 1113 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1114 | LOG_API("nLightCreate, con(%p)", con); |
| 1115 | return (jint)rsLightCreate(); |
| 1116 | } |
| 1117 | |
| 1118 | static void |
| 1119 | nLightDestroy(JNIEnv *_env, jobject _this, jint light) |
| 1120 | { |
| 1121 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1122 | LOG_API("nLightDestroy, con(%p), light(%p)", con, (RsLight)light); |
| 1123 | rsLightDestroy((RsLight)light); |
| 1124 | } |
| 1125 | |
| 1126 | static void |
| 1127 | nLightSetColor(JNIEnv *_env, jobject _this, jint light, float r, float g, float b) |
| 1128 | { |
| 1129 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1130 | LOG_API("nLightSetColor, con(%p), light(%p), r(%f), g(%f), b(%f)", con, (RsLight)light, r, g, b); |
| 1131 | rsLightSetColor((RsLight)light, r, g, b); |
| 1132 | } |
| 1133 | |
| 1134 | static void |
| 1135 | nLightSetPosition(JNIEnv *_env, jobject _this, jint light, float x, float y, float z) |
| 1136 | { |
| 1137 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1138 | LOG_API("nLightSetPosition, con(%p), light(%p), x(%f), y(%f), z(%f)", con, (RsLight)light, x, y, z); |
| 1139 | rsLightSetPosition((RsLight)light, x, y, z); |
| 1140 | } |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1141 | |
| 1142 | // --------------------------------------------------------------------------- |
| 1143 | |
| Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1144 | static void |
| 1145 | nSimpleMeshDestroy(JNIEnv *_env, jobject _this, jint s) |
| 1146 | { |
| 1147 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1148 | LOG_API("nSimpleMeshDestroy, con(%p), SimpleMesh(%p)", con, (RsSimpleMesh)s); |
| 1149 | rsSimpleMeshDestroy((RsSimpleMesh)s); |
| 1150 | } |
| 1151 | |
| 1152 | static jint |
| 1153 | nSimpleMeshCreate(JNIEnv *_env, jobject _this, jint batchID, jint indexID, jintArray vtxIDs, jint primID) |
| 1154 | { |
| 1155 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1156 | jint len = _env->GetArrayLength(vtxIDs); |
| 1157 | LOG_API("nSimpleMeshCreate, con(%p), batchID(%i), indexID(%i), vtxIDs.len(%i), primID(%i)", |
| 1158 | con, batchID, indexID, len, primID); |
| 1159 | jint *ptr = _env->GetIntArrayElements(vtxIDs, NULL); |
| 1160 | int id = (int)rsSimpleMeshCreate((void *)batchID, (void *)indexID, (void **)ptr, len, primID); |
| 1161 | _env->ReleaseIntArrayElements(vtxIDs, ptr, 0/*JNI_ABORT*/); |
| 1162 | return id; |
| 1163 | } |
| 1164 | |
| 1165 | static void |
| 1166 | nSimpleMeshBindVertex(JNIEnv *_env, jobject _this, jint s, jint alloc, jint slot) |
| 1167 | { |
| 1168 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1169 | LOG_API("nSimpleMeshBindVertex, con(%p), SimpleMesh(%p), Alloc(%p), slot(%i)", con, (RsSimpleMesh)s, (RsAllocation)alloc, slot); |
| 1170 | rsSimpleMeshBindVertex((RsSimpleMesh)s, (RsAllocation)alloc, slot); |
| 1171 | } |
| 1172 | |
| 1173 | static void |
| 1174 | nSimpleMeshBindIndex(JNIEnv *_env, jobject _this, jint s, jint alloc) |
| 1175 | { |
| 1176 | RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); |
| 1177 | LOG_API("nSimpleMeshBindIndex, con(%p), SimpleMesh(%p), Alloc(%p)", con, (RsSimpleMesh)s, (RsAllocation)alloc); |
| 1178 | rsSimpleMeshBindIndex((RsSimpleMesh)s, (RsAllocation)alloc); |
| 1179 | } |
| 1180 | |
| 1181 | // --------------------------------------------------------------------------- |
| 1182 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1183 | |
| Jason Sams | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 1184 | static const char *classPathName = "android/renderscript/RenderScript"; |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1185 | |
| 1186 | static JNINativeMethod methods[] = { |
| 1187 | {"_nInit", "()V", (void*)_nInit }, |
| 1188 | {"nDeviceCreate", "()I", (void*)nDeviceCreate }, |
| 1189 | {"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, |
| 1190 | {"nContextCreate", "(ILandroid/view/Surface;I)I", (void*)nContextCreate }, |
| 1191 | {"nContextDestroy", "(I)V", (void*)nContextDestroy }, |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 1192 | {"nAssignName", "(I[B)V", (void*)nAssignName }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1193 | |
| Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 1194 | {"nFileOpen", "([B)I", (void*)nFileOpen }, |
| 1195 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1196 | {"nElementBegin", "()V", (void*)nElementBegin }, |
| 1197 | {"nElementAddPredefined", "(I)V", (void*)nElementAddPredefined }, |
| 1198 | {"nElementAdd", "(IIII)V", (void*)nElementAdd }, |
| 1199 | {"nElementCreate", "()I", (void*)nElementCreate }, |
| 1200 | {"nElementGetPredefined", "(I)I", (void*)nElementGetPredefined }, |
| 1201 | {"nElementDestroy", "(I)V", (void*)nElementDestroy }, |
| 1202 | |
| 1203 | {"nTypeBegin", "(I)V", (void*)nTypeBegin }, |
| 1204 | {"nTypeAdd", "(II)V", (void*)nTypeAdd }, |
| 1205 | {"nTypeCreate", "()I", (void*)nTypeCreate }, |
| 1206 | {"nTypeDestroy", "(I)V", (void*)nTypeDestroy }, |
| 1207 | |
| 1208 | {"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped }, |
| 1209 | {"nAllocationCreatePredefSized", "(II)I", (void*)nAllocationCreatePredefSized }, |
| 1210 | {"nAllocationCreateSized", "(II)I", (void*)nAllocationCreateSized }, |
| Jason Sams | ffe9f48 | 2009-06-01 17:45:53 -0700 | [diff] [blame] | 1211 | {"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, |
| Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1212 | {"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1213 | {"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture }, |
| 1214 | {"nAllocationDestroy", "(I)V", (void*)nAllocationDestroy }, |
| 1215 | {"nAllocationData", "(I[I)V", (void*)nAllocationData_i }, |
| 1216 | {"nAllocationData", "(I[F)V", (void*)nAllocationData_f }, |
| 1217 | {"nAllocationSubData1D", "(III[I)V", (void*)nAllocationSubData1D_i }, |
| 1218 | {"nAllocationSubData1D", "(III[F)V", (void*)nAllocationSubData1D_f }, |
| 1219 | {"nAllocationSubData2D", "(IIIII[I)V", (void*)nAllocationSubData2D_i }, |
| 1220 | {"nAllocationSubData2D", "(IIIII[F)V", (void*)nAllocationSubData2D_f }, |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1221 | {"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i }, |
| 1222 | {"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1223 | |
| 1224 | {"nTriangleMeshDestroy", "(I)V", (void*)nTriangleMeshDestroy }, |
| 1225 | {"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin }, |
| 1226 | {"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY }, |
| 1227 | {"nTriangleMeshAddVertex_XYZ", "(FFF)V", (void*)nTriangleMeshAddVertex_XYZ }, |
| 1228 | {"nTriangleMeshAddVertex_XY_ST", "(FFFF)V", (void*)nTriangleMeshAddVertex_XY_ST }, |
| 1229 | {"nTriangleMeshAddVertex_XYZ_ST", "(FFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST }, |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1230 | {"nTriangleMeshAddVertex_XYZ_ST_NORM", "(FFFFFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST_NORM }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1231 | {"nTriangleMeshAddTriangle", "(III)V", (void*)nTriangleMeshAddTriangle }, |
| 1232 | {"nTriangleMeshCreate", "()I", (void*)nTriangleMeshCreate }, |
| 1233 | |
| 1234 | {"nAdapter1DDestroy", "(I)V", (void*)nAdapter1DDestroy }, |
| 1235 | {"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation }, |
| 1236 | {"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint }, |
| 1237 | {"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1238 | {"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f }, |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1239 | {"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1240 | {"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f }, |
| 1241 | {"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate }, |
| 1242 | |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1243 | {"nAdapter2DDestroy", "(I)V", (void*)nAdapter2DDestroy }, |
| 1244 | {"nAdapter2DBindAllocation", "(II)V", (void*)nAdapter2DBindAllocation }, |
| 1245 | {"nAdapter2DSetConstraint", "(III)V", (void*)nAdapter2DSetConstraint }, |
| 1246 | {"nAdapter2DData", "(I[I)V", (void*)nAdapter2DData_i }, |
| 1247 | {"nAdapter2DData", "(I[F)V", (void*)nAdapter2DData_f }, |
| 1248 | {"nAdapter2DSubData", "(IIIII[I)V", (void*)nAdapter2DSubData_i }, |
| 1249 | {"nAdapter2DSubData", "(IIIII[F)V", (void*)nAdapter2DSubData_f }, |
| 1250 | {"nAdapter2DCreate", "()I", (void*)nAdapter2DCreate }, |
| 1251 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1252 | {"nScriptDestroy", "(I)V", (void*)nScriptDestroy }, |
| 1253 | {"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation }, |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 1254 | {"nScriptSetClearColor", "(IFFFF)V", (void*)nScriptSetClearColor }, |
| 1255 | {"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth }, |
| 1256 | {"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil }, |
| 1257 | {"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone }, |
| 1258 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1259 | {"nScriptCBegin", "()V", (void*)nScriptCBegin }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1260 | {"nScriptCAddType", "(I)V", (void*)nScriptCAddType }, |
| 1261 | {"nScriptCSetRoot", "(Z)V", (void*)nScriptCSetRoot }, |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1262 | {"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1263 | {"nScriptCCreate", "()I", (void*)nScriptCCreate }, |
| Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 1264 | {"nScriptCAddDefineI32", "(Ljava/lang/String;I)V", (void*)nScriptCAddDefineI32 }, |
| 1265 | {"nScriptCAddDefineF", "(Ljava/lang/String;F)V", (void*)nScriptCAddDefineF }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1266 | |
| 1267 | {"nProgramFragmentStoreBegin", "(II)V", (void*)nProgramFragmentStoreBegin }, |
| 1268 | {"nProgramFragmentStoreDepthFunc", "(I)V", (void*)nProgramFragmentStoreDepthFunc }, |
| 1269 | {"nProgramFragmentStoreDepthMask", "(Z)V", (void*)nProgramFragmentStoreDepthMask }, |
| 1270 | {"nProgramFragmentStoreColorMask", "(ZZZZ)V", (void*)nProgramFragmentStoreColorMask }, |
| 1271 | {"nProgramFragmentStoreBlendFunc", "(II)V", (void*)nProgramFragmentStoreBlendFunc }, |
| 1272 | {"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither }, |
| 1273 | {"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate }, |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 1274 | {"nProgramFragmentStoreDestroy", "(I)V", (void*)nProgramFragmentStoreDestroy }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1275 | |
| 1276 | {"nProgramFragmentBegin", "(II)V", (void*)nProgramFragmentBegin }, |
| 1277 | {"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture }, |
| 1278 | {"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler }, |
| 1279 | {"nProgramFragmentSetType", "(II)V", (void*)nProgramFragmentSetType }, |
| 1280 | {"nProgramFragmentSetEnvMode", "(II)V", (void*)nProgramFragmentSetEnvMode }, |
| 1281 | {"nProgramFragmentSetTexEnable", "(IZ)V", (void*)nProgramFragmentSetTexEnable }, |
| 1282 | {"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate }, |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 1283 | {"nProgramFragmentDestroy", "(I)V", (void*)nProgramFragmentDestroy }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1284 | |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1285 | {"nProgramVertexDestroy", "(I)V", (void*)nProgramVertexDestroy }, |
| Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 1286 | {"nProgramVertexBindAllocation", "(II)V", (void*)nProgramVertexBindAllocation }, |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1287 | {"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin }, |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1288 | {"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable }, |
| Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 1289 | {"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight }, |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 1290 | {"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate }, |
| 1291 | |
| Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 1292 | {"nLightBegin", "()V", (void*)nLightBegin }, |
| 1293 | {"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono }, |
| 1294 | {"nLightSetIsLocal", "(Z)V", (void*)nLightSetIsLocal }, |
| 1295 | {"nLightCreate", "()I", (void*)nLightCreate }, |
| 1296 | {"nLightDestroy", "(I)V", (void*)nLightDestroy }, |
| 1297 | {"nLightSetColor", "(IFFF)V", (void*)nLightSetColor }, |
| 1298 | {"nLightSetPosition", "(IFFF)V", (void*)nLightSetPosition }, |
| 1299 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1300 | {"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1301 | {"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore }, |
| 1302 | {"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment }, |
| Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 1303 | {"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex }, |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1304 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1305 | {"nSamplerDestroy", "(I)V", (void*)nSamplerDestroy }, |
| 1306 | {"nSamplerBegin", "()V", (void*)nSamplerBegin }, |
| 1307 | {"nSamplerSet", "(II)V", (void*)nSamplerSet }, |
| 1308 | {"nSamplerCreate", "()I", (void*)nSamplerCreate }, |
| 1309 | |
| Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1310 | {"nSimpleMeshDestroy", "(I)V", (void*)nSimpleMeshDestroy }, |
| 1311 | {"nSimpleMeshCreate", "(II[II)I", (void*)nSimpleMeshCreate }, |
| 1312 | {"nSimpleMeshBindVertex", "(III)V", (void*)nSimpleMeshBindVertex }, |
| 1313 | {"nSimpleMeshBindIndex", "(II)V", (void*)nSimpleMeshBindIndex }, |
| 1314 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1315 | }; |
| 1316 | |
| 1317 | static int registerFuncs(JNIEnv *_env) |
| 1318 | { |
| 1319 | return android::AndroidRuntime::registerNativeMethods( |
| 1320 | _env, classPathName, methods, NELEM(methods)); |
| 1321 | } |
| 1322 | |
| 1323 | // --------------------------------------------------------------------------- |
| 1324 | |
| 1325 | jint JNI_OnLoad(JavaVM* vm, void* reserved) |
| 1326 | { |
| 1327 | JNIEnv* env = NULL; |
| 1328 | jint result = -1; |
| 1329 | |
| Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1330 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
| 1331 | LOGE("ERROR: GetEnv failed\n"); |
| 1332 | goto bail; |
| 1333 | } |
| 1334 | assert(env != NULL); |
| 1335 | |
| 1336 | if (registerFuncs(env) < 0) { |
| 1337 | LOGE("ERROR: MediaPlayer native registration failed\n"); |
| 1338 | goto bail; |
| 1339 | } |
| 1340 | |
| 1341 | /* success -- return valid version number */ |
| 1342 | result = JNI_VERSION_1_4; |
| 1343 | |
| 1344 | bail: |
| 1345 | return result; |
| 1346 | } |