android_renderscript_RenderScript.cpp revision 099deb8fb1715e62bcb24513f8e9305ab4f7743a
1/* 2 * Copyright (C) 2011-2012 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 17#define LOG_TAG "libRS_jni" 18 19#include <stdlib.h> 20#include <stdio.h> 21#include <fcntl.h> 22#include <unistd.h> 23#include <math.h> 24#include <utils/misc.h> 25#include <android/bitmap.h> 26#include "jni.h" 27#include "JNIHelp.h" 28#include "android_runtime/AndroidRuntime.h" 29#include <rs.h> 30#include <rsEnv.h> 31 32#include <core/SkBitmap.h> 33#include <core/SkPixelRef.h> 34#include <core/SkStream.h> 35#include <core/SkTemplates.h> 36//#include <images/SkImageDecoder.h> 37 38//#define LOG_API ALOG 39#define LOG_API(...) 40 41using namespace android; 42 43class AutoJavaStringToUTF8 { 44public: 45 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { 46 fCStr = env->GetStringUTFChars(str, NULL); 47 fLength = env->GetStringUTFLength(str); 48 } 49 ~AutoJavaStringToUTF8() { 50 fEnv->ReleaseStringUTFChars(fJStr, fCStr); 51 } 52 const char* c_str() const { return fCStr; } 53 jsize length() const { return fLength; } 54 55private: 56 JNIEnv* fEnv; 57 jstring fJStr; 58 const char* fCStr; 59 jsize fLength; 60}; 61 62class AutoJavaStringArrayToUTF8 { 63public: 64 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) 65 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { 66 mCStrings = NULL; 67 mSizeArray = NULL; 68 if (stringsLength > 0) { 69 mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); 70 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); 71 for (jsize ct = 0; ct < stringsLength; ct ++) { 72 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 73 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL); 74 mSizeArray[ct] = mEnv->GetStringUTFLength(s); 75 } 76 } 77 } 78 ~AutoJavaStringArrayToUTF8() { 79 for (jsize ct=0; ct < mStringsLength; ct++) { 80 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 81 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); 82 } 83 free(mCStrings); 84 free(mSizeArray); 85 } 86 const char **c_str() const { return mCStrings; } 87 size_t *c_str_len() const { return mSizeArray; } 88 jsize length() const { return mStringsLength; } 89 90private: 91 JNIEnv *mEnv; 92 jobjectArray mStrings; 93 const char **mCStrings; 94 size_t *mSizeArray; 95 jsize mStringsLength; 96}; 97 98// --------------------------------------------------------------------------- 99 100static jfieldID gContextId = 0; 101static jfieldID gNativeBitmapID = 0; 102static jfieldID gTypeNativeCache = 0; 103 104static void _nInit(JNIEnv *_env, jclass _this) 105{ 106 gContextId = _env->GetFieldID(_this, "mContext", "I"); 107 108 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); 109 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); 110} 111 112// --------------------------------------------------------------------------- 113 114static void 115nContextFinish(JNIEnv *_env, jobject _this, RsContext con) 116{ 117 LOG_API("nContextFinish, con(%p)", con); 118 rsContextFinish(con); 119} 120 121static void 122nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj) 123{ 124 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); 125 rsObjDestroy(con, (void *)obj); 126} 127 128// --------------------------------------------------------------------------- 129 130static jint 131nDeviceCreate(JNIEnv *_env, jobject _this) 132{ 133 LOG_API("nDeviceCreate"); 134 return (jint)rsDeviceCreate(); 135} 136 137static void 138nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 139{ 140 LOG_API("nDeviceDestroy"); 141 return rsDeviceDestroy((RsDevice)dev); 142} 143 144static void 145nDeviceSetConfig(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 151static jint 152nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct) 153{ 154 LOG_API("nContextCreate"); 155 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, false, false); 156} 157 158 159static void 160nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p) 161{ 162 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p); 163 rsContextSetPriority(con, p); 164} 165 166 167 168static void 169nContextDestroy(JNIEnv *_env, jobject _this, RsContext con) 170{ 171 LOG_API("nContextDestroy, con(%p)", con); 172 rsContextDestroy(con); 173} 174 175static void 176nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits) 177{ 178 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 179 rsContextDump((RsContext)con, bits); 180} 181 182 183static jstring 184nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con) 185{ 186 LOG_API("nContextGetErrorMessage, con(%p)", con); 187 char buf[1024]; 188 189 size_t receiveLen; 190 uint32_t subID; 191 int id = rsContextGetMessage(con, 192 buf, sizeof(buf), 193 &receiveLen, sizeof(receiveLen), 194 &subID, sizeof(subID)); 195 if (!id && receiveLen) { 196 ALOGV("message receive buffer too small. %i", receiveLen); 197 } 198 return _env->NewStringUTF(buf); 199} 200 201static jint 202nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data) 203{ 204 jint len = _env->GetArrayLength(data); 205 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); 206 jint *ptr = _env->GetIntArrayElements(data, NULL); 207 size_t receiveLen; 208 uint32_t subID; 209 int id = rsContextGetMessage(con, 210 ptr, len * 4, 211 &receiveLen, sizeof(receiveLen), 212 &subID, sizeof(subID)); 213 if (!id && receiveLen) { 214 ALOGV("message receive buffer too small. %i", receiveLen); 215 } 216 _env->ReleaseIntArrayElements(data, ptr, 0); 217 return id; 218} 219 220static jint 221nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData) 222{ 223 LOG_API("nContextPeekMessage, con(%p)", con); 224 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); 225 size_t receiveLen; 226 uint32_t subID; 227 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen), 228 &subID, sizeof(subID)); 229 auxDataPtr[0] = (jint)subID; 230 auxDataPtr[1] = (jint)receiveLen; 231 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); 232 return id; 233} 234 235static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con) 236{ 237 LOG_API("nContextInitToClient, con(%p)", con); 238 rsContextInitToClient(con); 239} 240 241static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con) 242{ 243 LOG_API("nContextDeinitToClient, con(%p)", con); 244 rsContextDeinitToClient(con); 245} 246 247static void 248nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data) 249{ 250 jint *ptr = NULL; 251 jint len = 0; 252 if (data) { 253 len = _env->GetArrayLength(data); 254 jint *ptr = _env->GetIntArrayElements(data, NULL); 255 } 256 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len); 257 rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int)); 258 if (data) { 259 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 260 } 261} 262 263 264 265static jint 266nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size) 267{ 268 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size); 269 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size); 270} 271 272static jint 273nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, 274 jintArray _ids, jobjectArray _names, jintArray _arraySizes) 275{ 276 int fieldCount = _env->GetArrayLength(_ids); 277 LOG_API("nElementCreate2, con(%p)", con); 278 279 jint *ids = _env->GetIntArrayElements(_ids, NULL); 280 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL); 281 282 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); 283 284 const char **nameArray = names.c_str(); 285 size_t *sizeArray = names.c_str_len(); 286 287 jint id = (jint)rsElementCreate2(con, 288 (RsElement *)ids, fieldCount, 289 nameArray, fieldCount * sizeof(size_t), sizeArray, 290 (const uint32_t *)arraySizes, fieldCount); 291 292 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); 293 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT); 294 return (jint)id; 295} 296 297 298 299static void 300nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, 301 jintArray _IDs, 302 jobjectArray _names, 303 jintArray _arraySizes) 304{ 305 int dataSize = _env->GetArrayLength(_IDs); 306 LOG_API("nElementGetSubElements, con(%p)", con); 307 308 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 309 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); 310 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 311 312 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize); 313 314 for(jint i = 0; i < dataSize; i++) { 315 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 316 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); 317 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]); 318 } 319 320 free(ids); 321 free(names); 322 free(arraySizes); 323} 324 325// ----------------------------------- 326 327static int 328nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid, 329 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) 330{ 331 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", 332 con, eid, dimx, dimy, dimz, mips, faces, yuv); 333 334 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv); 335 return (jint)id; 336} 337 338// ----------------------------------- 339 340static jint 341nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer) 342{ 343 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer); 344 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer); 345} 346 347static void 348nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits) 349{ 350 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits); 351 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits); 352} 353 354static void 355nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc) 356{ 357 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc); 358 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc); 359} 360 361static size_t GetBitmapSize(JNIEnv *env, jobject jbitmap) { 362 AndroidBitmapInfo info; 363 memset(&info, 0, sizeof(info)); 364 AndroidBitmap_getInfo(env, jbitmap, &info); 365 size_t s = info.width * info.height; 366 switch (info.format) { 367 case ANDROID_BITMAP_FORMAT_RGBA_8888: s *= 4; break; 368 case ANDROID_BITMAP_FORMAT_RGB_565: s *= 2; break; 369 case ANDROID_BITMAP_FORMAT_RGBA_4444: s *= 2; break; 370 } 371 return s; 372} 373 374static int 375nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 376{ 377 SkBitmap const * nativeBitmap = 378 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 379 const SkBitmap& bitmap(*nativeBitmap); 380 381 bitmap.lockPixels(); 382 const void* ptr = bitmap.getPixels(); 383 jint id = (jint)rsAllocationCreateFromBitmap(con, 384 (RsType)type, (RsAllocationMipmapControl)mip, 385 ptr, bitmap.getSize(), usage); 386 bitmap.unlockPixels(); 387 return id; 388} 389 390static int 391nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 392{ 393 SkBitmap const * nativeBitmap = 394 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 395 const SkBitmap& bitmap(*nativeBitmap); 396 397 bitmap.lockPixels(); 398 const void* ptr = bitmap.getPixels(); 399 jint id = (jint)rsAllocationCreateTyped(con, 400 (RsType)type, (RsAllocationMipmapControl)mip, 401 (uint32_t)usage, (size_t)ptr); 402 bitmap.unlockPixels(); 403 return id; 404} 405 406static int 407nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 408{ 409 void *pixels = NULL; 410 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 411 412 jint id = 0; 413 if (pixels != NULL) { 414 id = (jint)rsAllocationCubeCreateFromBitmap(con, 415 (RsType)type, (RsAllocationMipmapControl)mip, 416 pixels, GetBitmapSize(_env, jbitmap), usage); 417 AndroidBitmap_unlockPixels(_env, jbitmap); 418 } 419 return id; 420} 421 422static void 423nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 424{ 425 AndroidBitmapInfo info; 426 memset(&info, 0, sizeof(info)); 427 AndroidBitmap_getInfo(_env, jbitmap, &info); 428 429 void *pixels = NULL; 430 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 431 432 if (pixels != NULL) { 433 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0, 434 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 435 info.width, info.height, pixels, GetBitmapSize(_env, jbitmap), 0); 436 AndroidBitmap_unlockPixels(_env, jbitmap); 437 } 438} 439 440static void 441nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 442{ 443 AndroidBitmapInfo info; 444 memset(&info, 0, sizeof(info)); 445 AndroidBitmap_getInfo(_env, jbitmap, &info); 446 447 void *pixels = NULL; 448 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 449 450 if (pixels != NULL) { 451 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, pixels, GetBitmapSize(_env, jbitmap)); 452 AndroidBitmap_unlockPixels(_env, jbitmap); 453 } 454 //bitmap.notifyPixelsChanged(); 455} 456 457 458static void 459nAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes) 460{ 461 jint len = _env->GetArrayLength(data); 462 LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 463 jint *ptr = _env->GetIntArrayElements(data, NULL); 464 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 465 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 466} 467 468static void 469nAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes) 470{ 471 jint len = _env->GetArrayLength(data); 472 LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 473 jshort *ptr = _env->GetShortArrayElements(data, NULL); 474 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 475 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 476} 477 478static void 479nAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes) 480{ 481 jint len = _env->GetArrayLength(data); 482 LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 483 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 484 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 485 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 486} 487 488static void 489nAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes) 490{ 491 jint len = _env->GetArrayLength(data); 492 LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 493 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 494 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 495 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 496} 497 498static void 499// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); 500nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes) 501{ 502 jint len = _env->GetArrayLength(data); 503 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); 504 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 505 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx); 506 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 507} 508 509static void 510nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 511 jint w, jint h, jshortArray data, int sizeBytes) 512{ 513 jint len = _env->GetArrayLength(data); 514 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); 515 jshort *ptr = _env->GetShortArrayElements(data, NULL); 516 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 517 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 518} 519 520static void 521nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 522 jint w, jint h, jbyteArray data, int sizeBytes) 523{ 524 jint len = _env->GetArrayLength(data); 525 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); 526 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 527 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 528 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 529} 530 531static void 532nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 533 jint w, jint h, jintArray data, int sizeBytes) 534{ 535 jint len = _env->GetArrayLength(data); 536 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); 537 jint *ptr = _env->GetIntArrayElements(data, NULL); 538 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 539 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 540} 541 542static void 543nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 544 jint w, jint h, jfloatArray data, int sizeBytes) 545{ 546 jint len = _env->GetArrayLength(data); 547 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); 548 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 549 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 550 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 551} 552 553static void 554nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con, 555 jint dstAlloc, jint dstXoff, jint dstYoff, 556 jint dstMip, jint dstFace, 557 jint width, jint height, 558 jint srcAlloc, jint srcXoff, jint srcYoff, 559 jint srcMip, jint srcFace) 560{ 561 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 562 " dstMip(%i), dstFace(%i), width(%i), height(%i)," 563 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", 564 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 565 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 566 567 rsAllocationCopy2DRange(con, 568 (RsAllocation)dstAlloc, 569 dstXoff, dstYoff, 570 dstMip, dstFace, 571 width, height, 572 (RsAllocation)srcAlloc, 573 srcXoff, srcYoff, 574 srcMip, srcFace); 575} 576 577static void 578nAllocationData3D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 579 jint w, jint h, jint d, jshortArray data, int sizeBytes) 580{ 581 jint len = _env->GetArrayLength(data); 582 LOG_API("nAllocation3DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 583 jshort *ptr = _env->GetShortArrayElements(data, NULL); 584 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 585 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 586} 587 588static void 589nAllocationData3D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 590 jint w, jint h, jint d, jbyteArray data, int sizeBytes) 591{ 592 jint len = _env->GetArrayLength(data); 593 LOG_API("nAllocation3DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 594 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 595 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 596 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 597} 598 599static void 600nAllocationData3D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 601 jint w, jint h, jint d, jintArray data, int sizeBytes) 602{ 603 jint len = _env->GetArrayLength(data); 604 LOG_API("nAllocation3DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 605 jint *ptr = _env->GetIntArrayElements(data, NULL); 606 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 607 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 608} 609 610static void 611nAllocationData3D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 612 jint w, jint h, jint d, jfloatArray data, int sizeBytes) 613{ 614 jint len = _env->GetArrayLength(data); 615 LOG_API("nAllocation3DData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 616 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 617 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 618 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 619} 620 621static void 622nAllocationData3D_alloc(JNIEnv *_env, jobject _this, RsContext con, 623 jint dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff, 624 jint dstMip, 625 jint width, jint height, jint depth, 626 jint srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, 627 jint srcMip) 628{ 629 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 630 " dstMip(%i), width(%i), height(%i)," 631 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", 632 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 633 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 634 635 rsAllocationCopy3DRange(con, 636 (RsAllocation)dstAlloc, 637 dstXoff, dstYoff, dstZoff, dstMip, 638 width, height, depth, 639 (RsAllocation)srcAlloc, 640 srcXoff, srcYoff, srcZoff, srcMip); 641} 642 643static void 644nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data) 645{ 646 jint len = _env->GetArrayLength(data); 647 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 648 jint *ptr = _env->GetIntArrayElements(data, NULL); 649 jsize length = _env->GetArrayLength(data); 650 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int)); 651 _env->ReleaseIntArrayElements(data, ptr, 0); 652} 653 654static void 655nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data) 656{ 657 jint len = _env->GetArrayLength(data); 658 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 659 jshort *ptr = _env->GetShortArrayElements(data, NULL); 660 jsize length = _env->GetArrayLength(data); 661 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short)); 662 _env->ReleaseShortArrayElements(data, ptr, 0); 663} 664 665static void 666nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data) 667{ 668 jint len = _env->GetArrayLength(data); 669 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 670 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 671 jsize length = _env->GetArrayLength(data); 672 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char)); 673 _env->ReleaseByteArrayElements(data, ptr, 0); 674} 675 676static void 677nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data) 678{ 679 jint len = _env->GetArrayLength(data); 680 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 681 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 682 jsize length = _env->GetArrayLength(data); 683 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float)); 684 _env->ReleaseFloatArrayElements(data, ptr, 0); 685} 686 687static jint 688nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a) 689{ 690 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a); 691 return (jint) rsaAllocationGetType(con, (RsAllocation)a); 692} 693 694static void 695nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX) 696{ 697 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX); 698 rsAllocationResize1D(con, (RsAllocation)alloc, dimX); 699} 700 701// ----------------------------------- 702 703static void 704nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot) 705{ 706 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); 707 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); 708} 709 710static void 711nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 712{ 713 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 714 rsScriptSetVarI(con, (RsScript)script, slot, val); 715} 716 717static void 718nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 719{ 720 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 721 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val); 722} 723 724static void 725nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val) 726{ 727 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val); 728 rsScriptSetVarJ(con, (RsScript)script, slot, val); 729} 730 731static void 732nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val) 733{ 734 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val); 735 rsScriptSetVarF(con, (RsScript)script, slot, val); 736} 737 738static void 739nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val) 740{ 741 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val); 742 rsScriptSetVarD(con, (RsScript)script, slot, val); 743} 744 745static void 746nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 747{ 748 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 749 jint len = _env->GetArrayLength(data); 750 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 751 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len); 752 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 753} 754 755static void 756nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims) 757{ 758 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 759 jint len = _env->GetArrayLength(data); 760 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 761 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); 762 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL); 763 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem, 764 (const size_t*) dimsPtr, dimsLen); 765 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 766 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); 767} 768 769 770static void 771nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone) 772{ 773 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone); 774 775 jint length = _env->GetArrayLength(timeZone); 776 jbyte* timeZone_ptr; 777 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 778 779 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); 780 781 if (timeZone_ptr) { 782 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 783 } 784} 785 786static void 787nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot) 788{ 789 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); 790 rsScriptInvoke(con, (RsScript)obj, slot); 791} 792 793static void 794nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 795{ 796 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 797 jint len = _env->GetArrayLength(data); 798 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 799 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len); 800 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 801} 802 803static void 804nScriptForEach(JNIEnv *_env, jobject _this, RsContext con, 805 jint script, jint slot, jint ain, jint aout) 806{ 807 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 808 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0); 809} 810static void 811nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con, 812 jint script, jint slot, jint ain, jint aout, jbyteArray params) 813{ 814 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 815 jint len = _env->GetArrayLength(params); 816 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 817 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0); 818 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 819} 820 821static void 822nScriptForEachClipped(JNIEnv *_env, jobject _this, RsContext con, 823 jint script, jint slot, jint ain, jint aout, 824 jint xstart, jint xend, 825 jint ystart, jint yend, jint zstart, jint zend) 826{ 827 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 828 RsScriptCall sc; 829 sc.xStart = xstart; 830 sc.xEnd = xend; 831 sc.yStart = ystart; 832 sc.yEnd = yend; 833 sc.zStart = zstart; 834 sc.zEnd = zend; 835 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 836 sc.arrayStart = 0; 837 sc.arrayEnd = 0; 838 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); 839} 840 841static void 842nScriptForEachClippedV(JNIEnv *_env, jobject _this, RsContext con, 843 jint script, jint slot, jint ain, jint aout, 844 jbyteArray params, jint xstart, jint xend, 845 jint ystart, jint yend, jint zstart, jint zend) 846{ 847 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 848 jint len = _env->GetArrayLength(params); 849 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 850 RsScriptCall sc; 851 sc.xStart = xstart; 852 sc.xEnd = xend; 853 sc.yStart = ystart; 854 sc.yEnd = yend; 855 sc.zStart = zstart; 856 sc.zEnd = zend; 857 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 858 sc.arrayStart = 0; 859 sc.arrayEnd = 0; 860 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc)); 861 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 862} 863 864// ----------------------------------- 865 866static jint 867nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, 868 jstring resName, jstring cacheDir, 869 jbyteArray scriptRef, jint length) 870{ 871 LOG_API("nScriptCCreate, con(%p)", con); 872 873 AutoJavaStringToUTF8 resNameUTF(_env, resName); 874 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); 875 jint ret = 0; 876 jbyte* script_ptr = NULL; 877 jint _exception = 0; 878 jint remaining; 879 if (!scriptRef) { 880 _exception = 1; 881 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); 882 goto exit; 883 } 884 if (length < 0) { 885 _exception = 1; 886 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); 887 goto exit; 888 } 889 remaining = _env->GetArrayLength(scriptRef); 890 if (remaining < length) { 891 _exception = 1; 892 //jniThrowException(_env, "java/lang/IllegalArgumentException", 893 // "length > script.length - offset"); 894 goto exit; 895 } 896 script_ptr = (jbyte *) 897 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 898 899 //rsScriptCSetText(con, (const char *)script_ptr, length); 900 901 ret = (jint)rsScriptCCreate(con, 902 resNameUTF.c_str(), resNameUTF.length(), 903 cacheDirUTF.c_str(), cacheDirUTF.length(), 904 (const char *)script_ptr, length); 905 906exit: 907 if (script_ptr) { 908 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, 909 _exception ? JNI_ABORT: 0); 910 } 911 912 return ret; 913} 914 915static jint 916nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid) 917{ 918 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid); 919 return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid); 920} 921 922static jint 923nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig) 924{ 925 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig); 926 return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig); 927} 928 929static jint 930nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot) 931{ 932 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot); 933 return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot); 934} 935 936static jint 937nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src, 938 jintArray _dstk, jintArray _dstf, jintArray _types) 939{ 940 LOG_API("nScriptGroupCreate, con(%p)", con); 941 942 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int); 943 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL); 944 jint srcLen = _env->GetArrayLength(_src) * sizeof(int); 945 jint *srcPtr = _env->GetIntArrayElements(_src, NULL); 946 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int); 947 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL); 948 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int); 949 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL); 950 jint typesLen = _env->GetArrayLength(_types) * sizeof(int); 951 jint *typesPtr = _env->GetIntArrayElements(_types, NULL); 952 953 int id = (int)rsScriptGroupCreate(con, 954 (RsScriptKernelID *)kernelsPtr, kernelsLen, 955 (RsScriptKernelID *)srcPtr, srcLen, 956 (RsScriptKernelID *)dstkPtr, dstkLen, 957 (RsScriptFieldID *)dstfPtr, dstfLen, 958 (RsType *)typesPtr, typesLen); 959 960 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0); 961 _env->ReleaseIntArrayElements(_src, srcPtr, 0); 962 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0); 963 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0); 964 _env->ReleaseIntArrayElements(_types, typesPtr, 0); 965 return id; 966} 967 968static void 969nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc) 970{ 971 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con, 972 (void *)gid, (void *)kid, (void *)alloc); 973 rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 974} 975 976static void 977nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc) 978{ 979 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con, 980 (void *)gid, (void *)kid, (void *)alloc); 981 rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 982} 983 984static void 985nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid) 986{ 987 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid); 988 rsScriptGroupExecute(con, (RsScriptGroup)gid); 989} 990 991// --------------------------------------------------------------------------- 992 993static jint 994nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter, 995 jint wrapS, jint wrapT, jint wrapR, jfloat aniso) 996{ 997 LOG_API("nSamplerCreate, con(%p)", con); 998 return (jint)rsSamplerCreate(con, 999 (RsSamplerValue)magFilter, 1000 (RsSamplerValue)minFilter, 1001 (RsSamplerValue)wrapS, 1002 (RsSamplerValue)wrapT, 1003 (RsSamplerValue)wrapR, 1004 aniso); 1005} 1006 1007// --------------------------------------------------------------------------- 1008 1009 1010static const char *classPathName = "android/support/v8/renderscript/RenderScript"; 1011 1012static JNINativeMethod methods[] = { 1013{"_nInit", "()V", (void*)_nInit }, 1014 1015{"nDeviceCreate", "()I", (void*)nDeviceCreate }, 1016{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, 1017{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, 1018{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage }, 1019{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage }, 1020{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage }, 1021 1022{"nContextInitToClient", "(I)V", (void*)nContextInitToClient }, 1023{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient }, 1024 1025 1026// All methods below are thread protected in java. 1027{"rsnContextCreate", "(IIII)I", (void*)nContextCreate }, 1028{"rsnContextFinish", "(I)V", (void*)nContextFinish }, 1029{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority }, 1030{"rsnContextDestroy", "(I)V", (void*)nContextDestroy }, 1031{"rsnContextDump", "(II)V", (void*)nContextDump }, 1032{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage }, 1033{"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, 1034 1035{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, 1036{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, 1037{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, 1038 1039{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate }, 1040 1041{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped }, 1042{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, 1043{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation }, 1044{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, 1045 1046{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, 1047{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, 1048 1049{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll }, 1050{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i }, 1051{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s }, 1052{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b }, 1053{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f }, 1054{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D }, 1055{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i }, 1056{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s }, 1057{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b }, 1058{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f }, 1059{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc }, 1060{"rsnAllocationData3D", "(IIIIIIIII[II)V", (void*)nAllocationData3D_i }, 1061{"rsnAllocationData3D", "(IIIIIIIII[SI)V", (void*)nAllocationData3D_s }, 1062{"rsnAllocationData3D", "(IIIIIIIII[BI)V", (void*)nAllocationData3D_b }, 1063{"rsnAllocationData3D", "(IIIIIIIII[FI)V", (void*)nAllocationData3D_f }, 1064{"rsnAllocationData3D", "(IIIIIIIIIIIIII)V", (void*)nAllocationData3D_alloc }, 1065{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i }, 1066{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s }, 1067{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b }, 1068{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f }, 1069{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType}, 1070{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D }, 1071{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps }, 1072 1073{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation }, 1074{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone }, 1075{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke }, 1076{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV }, 1077{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach }, 1078{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV }, 1079{"rsnScriptForEachClipped", "(IIIIIIIIIII)V", (void*)nScriptForEachClipped }, 1080{"rsnScriptForEachClipped", "(IIIII[BIIIIII)V", (void*)nScriptForEachClippedV }, 1081{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI }, 1082{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ }, 1083{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF }, 1084{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD }, 1085{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, 1086{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE }, 1087{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, 1088 1089{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate }, 1090{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate }, 1091{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate }, 1092{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate }, 1093{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate }, 1094{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput }, 1095{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput }, 1096{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute }, 1097 1098{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate }, 1099 1100}; 1101 1102static int registerFuncs(JNIEnv *_env) 1103{ 1104 return android::AndroidRuntime::registerNativeMethods( 1105 _env, classPathName, methods, NELEM(methods)); 1106} 1107 1108// --------------------------------------------------------------------------- 1109 1110jint JNI_OnLoad(JavaVM* vm, void* reserved) 1111{ 1112 JNIEnv* env = NULL; 1113 jint result = -1; 1114 1115 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1116 ALOGE("ERROR: GetEnv failed\n"); 1117 goto bail; 1118 } 1119 assert(env != NULL); 1120 1121 if (registerFuncs(env) < 0) { 1122 ALOGE("ERROR: MediaPlayer native registration failed\n"); 1123 goto bail; 1124 } 1125 1126 /* success -- return valid version number */ 1127 result = JNI_VERSION_1_4; 1128 1129bail: 1130 return result; 1131} 1132