android_renderscript_RenderScript.cpp revision 3d9b60c9ae71c4c09df0b4e59c825a5d631e1254
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 <android/bitmap.h> 25#include <android/log.h> 26 27#include <rsEnv.h> 28#include "rsDispatch.h" 29#include <dlfcn.h> 30 31//#define LOG_API ALOG 32#define LOG_API(...) 33 34#define NELEM(m) (sizeof(m) / sizeof((m)[0])) 35 36class AutoJavaStringToUTF8 { 37public: 38 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { 39 fCStr = env->GetStringUTFChars(str, NULL); 40 fLength = env->GetStringUTFLength(str); 41 } 42 ~AutoJavaStringToUTF8() { 43 fEnv->ReleaseStringUTFChars(fJStr, fCStr); 44 } 45 const char* c_str() const { return fCStr; } 46 jsize length() const { return fLength; } 47 48private: 49 JNIEnv* fEnv; 50 jstring fJStr; 51 const char* fCStr; 52 jsize fLength; 53}; 54 55class AutoJavaStringArrayToUTF8 { 56public: 57 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) 58 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { 59 mCStrings = NULL; 60 mSizeArray = NULL; 61 if (stringsLength > 0) { 62 mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); 63 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); 64 for (jsize ct = 0; ct < stringsLength; ct ++) { 65 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 66 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL); 67 mSizeArray[ct] = mEnv->GetStringUTFLength(s); 68 } 69 } 70 } 71 ~AutoJavaStringArrayToUTF8() { 72 for (jsize ct=0; ct < mStringsLength; ct++) { 73 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 74 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); 75 } 76 free(mCStrings); 77 free(mSizeArray); 78 } 79 const char **c_str() const { return mCStrings; } 80 size_t *c_str_len() const { return mSizeArray; } 81 jsize length() const { return mStringsLength; } 82 83private: 84 JNIEnv *mEnv; 85 jobjectArray mStrings; 86 const char **mCStrings; 87 size_t *mSizeArray; 88 jsize mStringsLength; 89}; 90 91 92// --------------------------------------------------------------------------- 93static dispatchTable dispatchTab; 94 95static jboolean nLoadSO(JNIEnv *_env, jobject _this, jboolean useNative) { 96 void* handle = NULL; 97 if (useNative) { 98 handle = dlopen("libRS.so", RTLD_LAZY | RTLD_LOCAL); 99 } else { 100 handle = dlopen("libRSSupport.so", RTLD_LAZY | RTLD_LOCAL); 101 } 102 if (handle == NULL) { 103 LOG_API("couldn't dlopen %s, %s", filename, dlerror()); 104 return false; 105 } 106 107 if (loadSymbols(handle, dispatchTab) == false) { 108 LOG_API("%s init failed!", filename); 109 return false; 110 } 111 LOG_API("Successfully loaded %s", filename); 112 return true; 113} 114 115static ioSuppDT ioDispatch; 116static jboolean nLoadIOSO(JNIEnv *_env, jobject _this) { 117 void* handleIO = NULL; 118 handleIO = dlopen("libRSSupportIO.so", RTLD_LAZY | RTLD_LOCAL); 119 if (handleIO == NULL) { 120 LOG_API("Couldn't load libRSSupportIO.so"); 121 return false; 122 } 123 if (loadIOSuppSyms(handleIO, ioDispatch) == false) { 124 LOG_API("libRSSupportIO init failed!"); 125 return false; 126 } 127 return true; 128} 129// --------------------------------------------------------------------------- 130 131static void 132nContextFinish(JNIEnv *_env, jobject _this, jlong con) 133{ 134 LOG_API("nContextFinish, con(%p)", (RsContext)con); 135 dispatchTab.ContextFinish((RsContext)con); 136} 137 138static jlong 139nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID, 140 jlong returnValue, jlongArray fieldIDArray, 141 jlongArray valueArray, jintArray sizeArray, 142 jlongArray depClosureArray, jlongArray depFieldIDArray) { 143 LOG_API("nClosureCreate: con(%p)", con); 144 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr); 145 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray); 146 RsScriptFieldID* fieldIDs = 147 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length); 148 for (int i = 0; i< fieldIDs_length; i++) { 149 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i]; 150 } 151 152 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr); 153 jsize values_length = _env->GetArrayLength(valueArray); 154 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length); 155 for (int i = 0; i < values_length; i++) { 156 values[i] = (uintptr_t)jValues[i]; 157 } 158 159 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr); 160 jsize sizes_length = _env->GetArrayLength(sizeArray); 161 162 jlong* jDepClosures = 163 _env->GetLongArrayElements(depClosureArray, nullptr); 164 jsize depClosures_length = _env->GetArrayLength(depClosureArray); 165 RsClosure* depClosures = 166 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length); 167 for (int i = 0; i < depClosures_length; i++) { 168 depClosures[i] = (RsClosure)jDepClosures[i]; 169 } 170 171 jlong* jDepFieldIDs = 172 _env->GetLongArrayElements(depFieldIDArray, nullptr); 173 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray); 174 RsScriptFieldID* depFieldIDs = 175 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length); 176 for (int i = 0; i < depClosures_length; i++) { 177 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i]; 178 } 179 180 return (jlong)(uintptr_t)dispatchTab.ClosureCreate( 181 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue, 182 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length, 183 (size_t*)sizes, (size_t)sizes_length, 184 depClosures, (size_t)depClosures_length, 185 depFieldIDs, (size_t)depFieldIDs_length); 186} 187 188static void 189nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID, 190 jint index, jlong value, jint size) { 191 dispatchTab.ClosureSetArg((RsContext)con, (RsClosure)closureID, 192 (uint32_t)index, (uintptr_t)value, (size_t)size); 193} 194 195static void 196nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID, 197 jlong fieldID, jlong value, jint size) { 198 dispatchTab.ClosureSetGlobal((RsContext)con, (RsClosure)closureID, 199 (RsScriptFieldID)fieldID, (uintptr_t)value, 200 (size_t)size); 201} 202 203static long 204nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, 205 jlongArray closureArray) { 206 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr); 207 jsize numClosures = _env->GetArrayLength(closureArray); 208 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures); 209 for (int i = 0; i < numClosures; i++) { 210 closures[i] = (RsClosure)jClosures[i]; 211 } 212 213 return (jlong)(uintptr_t)dispatchTab.ScriptGroup2Create((RsContext)con, 214 closures, 215 numClosures); 216} 217 218static void 219nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj) 220{ 221 LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj); 222 dispatchTab.ObjDestroy((RsContext)con, (void *)obj); 223} 224 225// --------------------------------------------------------------------------- 226 227static jlong 228nDeviceCreate(JNIEnv *_env, jobject _this) 229{ 230 LOG_API("nDeviceCreate"); 231 return (jlong)(uintptr_t)dispatchTab.DeviceCreate(); 232} 233 234static void 235nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev) 236{ 237 LOG_API("nDeviceDestroy"); 238 return dispatchTab.DeviceDestroy((RsDevice)dev); 239} 240 241static void 242nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value) 243{ 244 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 245 return dispatchTab.DeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 246} 247 248static jlong 249nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct) 250{ 251 LOG_API("nContextCreate"); 252 return (jlong)(uintptr_t)dispatchTab.ContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0); 253} 254 255 256static void 257nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p) 258{ 259 LOG_API("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p); 260 dispatchTab.ContextSetPriority((RsContext)con, p); 261} 262 263 264 265static void 266nContextDestroy(JNIEnv *_env, jobject _this, jlong con) 267{ 268 LOG_API("nContextDestroy, con(%p)", (RsContext)con); 269 dispatchTab.ContextDestroy((RsContext)con); 270} 271 272static void 273nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits) 274{ 275 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 276 dispatchTab.ContextDump((RsContext)con, bits); 277} 278 279 280static jstring 281nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con) 282{ 283 LOG_API("nContextGetErrorMessage, con(%p)", (RsContext)con); 284 char buf[1024]; 285 286 size_t receiveLen; 287 uint32_t subID; 288 int id = dispatchTab.ContextGetMessage((RsContext)con, 289 buf, sizeof(buf), 290 &receiveLen, sizeof(receiveLen), 291 &subID, sizeof(subID)); 292 if (!id && receiveLen) { 293 // __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, 294 // "message receive buffer too small. %zu", receiveLen); 295 } 296 return _env->NewStringUTF(buf); 297} 298 299static jint 300nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) 301{ 302 jint len = _env->GetArrayLength(data); 303 LOG_API("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len); 304 jint *ptr = _env->GetIntArrayElements(data, NULL); 305 size_t receiveLen; 306 uint32_t subID; 307 int id = dispatchTab.ContextGetMessage((RsContext)con, 308 ptr, len * 4, 309 &receiveLen, sizeof(receiveLen), 310 &subID, sizeof(subID)); 311 if (!id && receiveLen) { 312 // __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, 313 // "message receive buffer too small. %zu", receiveLen); 314 } 315 _env->ReleaseIntArrayElements(data, ptr, 0); 316 return (jint)id; 317} 318 319static jint 320nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData) 321{ 322 LOG_API("nContextPeekMessage, con(%p)", (RsContext)con); 323 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); 324 size_t receiveLen; 325 uint32_t subID; 326 int id = dispatchTab.ContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen), 327 &subID, sizeof(subID)); 328 auxDataPtr[0] = (jint)subID; 329 auxDataPtr[1] = (jint)receiveLen; 330 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); 331 return (jint)id; 332} 333 334static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con) 335{ 336 LOG_API("nContextInitToClient, con(%p)", (RsContext)con); 337 dispatchTab.ContextInitToClient((RsContext)con); 338} 339 340static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con) 341{ 342 LOG_API("nContextDeinitToClient, con(%p)", (RsContext)con); 343 dispatchTab.ContextDeinitToClient((RsContext)con); 344} 345 346static void 347nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data) 348{ 349 jint *ptr = NULL; 350 jint len = 0; 351 if (data) { 352 len = _env->GetArrayLength(data); 353 jint *ptr = _env->GetIntArrayElements(data, NULL); 354 } 355 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); 356 dispatchTab.ContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int)); 357 if (data) { 358 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 359 } 360} 361 362 363 364static jlong 365nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size) 366{ 367 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con, 368 type, kind, norm, size); 369 return (jlong)(uintptr_t)dispatchTab.ElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, 370 norm, size); 371} 372 373static jlong 374nElementCreate2(JNIEnv *_env, jobject _this, jlong con, 375 jlongArray _ids, jobjectArray _names, jintArray _arraySizes) 376{ 377 int fieldCount = _env->GetArrayLength(_ids); 378 LOG_API("nElementCreate2, con(%p)", (RsContext)con); 379 380 jlong *jIds = _env->GetLongArrayElements(_ids, NULL); 381 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, NULL); 382 383 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement)); 384 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t)); 385 386 for(int i = 0; i < fieldCount; i ++) { 387 ids[i] = (RsElement)jIds[i]; 388 arraySizes[i] = (uint32_t)jArraySizes[i]; 389 } 390 391 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); 392 393 const char **nameArray = names.c_str(); 394 size_t *sizeArray = names.c_str_len(); 395 396 jlong id = (jlong)(uintptr_t)dispatchTab.ElementCreate2((RsContext)con, 397 (RsElement *)ids, fieldCount, 398 nameArray, fieldCount * sizeof(size_t), sizeArray, 399 (const uint32_t *)arraySizes, fieldCount); 400 401 free(ids); 402 free(arraySizes); 403 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT); 404 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT); 405 return id; 406} 407 408 409 410 411static void 412nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id, 413 jlongArray _IDs, 414 jobjectArray _names, 415 jintArray _arraySizes) 416{ 417 uint32_t dataSize = _env->GetArrayLength(_IDs); 418 LOG_API("nElementGetSubElements, con(%p)", (RsContext)con); 419 420 uintptr_t *ids = (uintptr_t *)malloc(dataSize * sizeof(uintptr_t)); 421 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); 422 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 423 424 dispatchTab.ElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, 425 (uint32_t)dataSize); 426 427 for(uint32_t i = 0; i < dataSize; i++) { 428 const jlong id = (jlong)(uintptr_t)ids[i]; 429 const jint arraySize = (jint)arraySizes[i]; 430 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 431 _env->SetLongArrayRegion(_IDs, i, 1, &id); 432 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize); 433 } 434 435 free(ids); 436 free(names); 437 free(arraySizes); 438} 439 440// ----------------------------------- 441 442static jlong 443nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid, 444 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) 445{ 446 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", 447 (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv); 448 449 return (jlong)(uintptr_t)dispatchTab.TypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, 450 dimz, mips, faces, yuv); 451} 452 453// ----------------------------------- 454 455static jlong 456nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, 457 jlong pointer) 458{ 459 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", 460 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer); 461 return (jlong)(uintptr_t) dispatchTab.AllocationCreateTyped((RsContext)con, (RsType)type, 462 (RsAllocationMipmapControl)mips, 463 (uint32_t)usage, (uintptr_t)pointer); 464} 465 466static void 467nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits) 468{ 469 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, bits); 470 dispatchTab.AllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits); 471} 472 473static void 474nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur) 475{ 476 ioDispatch.sAllocationSetSurface(_env, _this, (RsContext)con, (RsAllocation)alloc, sur, dispatchTab); 477} 478 479static void 480nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 481{ 482 dispatchTab.AllocationIoSend((RsContext)con, (RsAllocation)alloc); 483} 484 485static void 486nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 487{ 488 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc); 489 dispatchTab.AllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc); 490} 491 492static size_t GetBitmapSize(JNIEnv *env, jobject jbitmap) { 493 AndroidBitmapInfo info; 494 memset(&info, 0, sizeof(info)); 495 AndroidBitmap_getInfo(env, jbitmap, &info); 496 size_t s = info.width * info.height; 497 switch (info.format) { 498 case ANDROID_BITMAP_FORMAT_RGBA_8888: s *= 4; break; 499 case ANDROID_BITMAP_FORMAT_RGB_565: s *= 2; break; 500 case ANDROID_BITMAP_FORMAT_RGBA_4444: s *= 2; break; 501 } 502 return s; 503} 504 505static jlong 506nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, 507 jobject jbitmap, jint usage) 508{ 509 jlong id = 0; 510 void *pixels = NULL; 511 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 512 513 if (pixels != NULL) { 514 id = (jlong)(uintptr_t)dispatchTab.AllocationCreateFromBitmap((RsContext)con, 515 (RsType)type, 516 (RsAllocationMipmapControl)mip, 517 pixels, 518 GetBitmapSize(_env, jbitmap), 519 usage); 520 AndroidBitmap_unlockPixels(_env, jbitmap); 521 } 522 return id; 523} 524 525static jlong 526nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, 527 jint mip, jobject jbitmap, jint usage) 528{ 529 jlong id = 0; 530 void *pixels = NULL; 531 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 532 533 if (pixels != NULL) { 534 id = (jlong)(uintptr_t)dispatchTab.AllocationCreateTyped((RsContext)con, 535 (RsType)type, 536 (RsAllocationMipmapControl)mip, 537 (uint32_t)usage, 538 (uintptr_t)pixels); 539 AndroidBitmap_unlockPixels(_env, jbitmap); 540 } 541 return id; 542} 543 544static jlong 545nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, 546 jint mip, jobject jbitmap, jint usage) 547{ 548 void *pixels = NULL; 549 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 550 551 jlong id = 0; 552 if (pixels != NULL) { 553 id = (jlong)(uintptr_t)dispatchTab.AllocationCubeCreateFromBitmap((RsContext)con, 554 (RsType)type, 555 (RsAllocationMipmapControl)mip, 556 pixels, 557 GetBitmapSize(_env, jbitmap), 558 usage); 559 AndroidBitmap_unlockPixels(_env, jbitmap); 560 } 561 return id; 562} 563 564static void 565nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) 566{ 567 AndroidBitmapInfo info; 568 memset(&info, 0, sizeof(info)); 569 AndroidBitmap_getInfo(_env, jbitmap, &info); 570 571 void *pixels = NULL; 572 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 573 574 if (pixels != NULL) { 575 dispatchTab.Allocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0, 0, 576 RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, info.width, 577 info.height, pixels, GetBitmapSize(_env, jbitmap), 0); 578 AndroidBitmap_unlockPixels(_env, jbitmap); 579 } 580} 581 582static void 583nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) 584{ 585 AndroidBitmapInfo info; 586 memset(&info, 0, sizeof(info)); 587 AndroidBitmap_getInfo(_env, jbitmap, &info); 588 589 void *pixels = NULL; 590 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 591 592 if (pixels != NULL) { 593 dispatchTab.AllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, pixels, 594 GetBitmapSize(_env, jbitmap)); 595 AndroidBitmap_unlockPixels(_env, jbitmap); 596 } 597 //bitmap.notifyPixelsChanged(); 598} 599 600 601static void 602nAllocationData1D_l(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, 603 jint lod, jint count, jlongArray data, int sizeBytes) 604{ 605 jint len = _env->GetArrayLength(data); 606 LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", 607 (RsContext)con, (RsAllocation)alloc, offset, count, len, sizeBytes); 608 jlong *ptr = _env->GetLongArrayElements(data, NULL); 609 dispatchTab.Allocation1DData((RsContext)con, (RsAllocation)alloc, offset, lod, count, 610 ptr, sizeBytes); 611 _env->ReleaseLongArrayElements(data, ptr, JNI_ABORT); 612} 613 614static void 615nAllocationData1D_i(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, 616 jint lod, jint count, jintArray data, int sizeBytes) 617{ 618 jint len = _env->GetArrayLength(data); 619 LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", 620 (RsContext)con, (RsAllocation)alloc, offset, count, len, sizeBytes); 621 jint *ptr = _env->GetIntArrayElements(data, NULL); 622 dispatchTab.Allocation1DData((RsContext)con, (RsAllocation)alloc, offset, lod, count, 623 ptr, sizeBytes); 624 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 625} 626 627static void 628nAllocationData1D_s(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, 629 jint lod, jint count, jshortArray data, int sizeBytes) 630{ 631 jint len = _env->GetArrayLength(data); 632 LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", 633 (RsContext)con, (RsAllocation)alloc, offset, count, len, sizeBytes); 634 jshort *ptr = _env->GetShortArrayElements(data, NULL); 635 dispatchTab.Allocation1DData((RsContext)con, (RsAllocation)alloc, offset, lod, count, 636 ptr, sizeBytes); 637 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 638} 639 640static void 641nAllocationData1D_b(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, 642 jint lod, jint count, jbyteArray data, int sizeBytes) 643{ 644 jint len = _env->GetArrayLength(data); 645 LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", 646 (RsContext)con, (RsAllocation)alloc, offset, count, len, sizeBytes); 647 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 648 dispatchTab.Allocation1DData((RsContext)con, (RsAllocation)alloc, offset, lod, count, 649 ptr, sizeBytes); 650 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 651} 652 653static void 654nAllocationData1D_f(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, 655 jint lod, jint count, jfloatArray data, int sizeBytes) 656{ 657 jint len = _env->GetArrayLength(data); 658 LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", 659 (RsContext)con, (RsAllocation)alloc, offset, count, len, sizeBytes); 660 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 661 dispatchTab.Allocation1DData((RsContext)con, (RsAllocation)alloc, offset, lod, count, 662 ptr, sizeBytes); 663 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 664} 665 666static void 667// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); 668nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, 669 jint lod, jint compIdx, jbyteArray data, int sizeBytes) 670{ 671 jint len = _env->GetArrayLength(data); 672 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", 673 (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); 674 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 675 dispatchTab.Allocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, 676 ptr, sizeBytes, compIdx); 677 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 678} 679 680static void 681nAllocationData2D_s(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint xoff, jint yoff, 682 jint lod, jint face, jint w, jint h, jshortArray data, int sizeBytes) 683{ 684 jint len = _env->GetArrayLength(data); 685 LOG_API("nAllocation2DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 686 (RsContext)con, (RsAllocation)alloc, xoff, yoff, w, h, len); 687 jshort *ptr = _env->GetShortArrayElements(data, NULL); 688 dispatchTab.Allocation2DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, lod, 689 (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 690 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 691} 692 693static void 694nAllocationData2D_b(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint xoff, jint yoff, 695 jint lod, jint face, jint w, jint h, jbyteArray data, int sizeBytes) 696{ 697 jint len = _env->GetArrayLength(data); 698 LOG_API("nAllocation2DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 699 (RsContext)con, (RsAllocation)alloc, xoff, yoff, w, h, len); 700 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 701 dispatchTab.Allocation2DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, lod, 702 (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 703 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 704} 705 706static void 707nAllocationData2D_l(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint xoff, jint yoff, 708 jint lod, jint face, jint w, jint h, jlongArray data, int sizeBytes) 709{ 710 jint len = _env->GetArrayLength(data); 711 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 712 (RsContext)con, (RsAllocation)alloc, xoff, yoff, w, h, len); 713 jlong *ptr = _env->GetLongArrayElements(data, NULL); 714 dispatchTab.Allocation2DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, lod, 715 (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 716 _env->ReleaseLongArrayElements(data, ptr, JNI_ABORT); 717} 718 719static void 720nAllocationData2D_i(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint xoff, jint yoff, 721 jint lod, jint face, jint w, jint h, jintArray data, int sizeBytes) 722{ 723 jint len = _env->GetArrayLength(data); 724 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 725 (RsContext)con, (RsAllocation)alloc, xoff, yoff, w, h, len); 726 jint *ptr = _env->GetIntArrayElements(data, NULL); 727 dispatchTab.Allocation2DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, lod, 728 (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 729 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 730} 731 732static void 733nAllocationData2D_f(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint xoff, jint yoff, 734 jint lod, jint face, jint w, jint h, jfloatArray data, int sizeBytes) 735{ 736 jint len = _env->GetArrayLength(data); 737 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 738 (RsContext)con, (RsAllocation)alloc, xoff, yoff, w, h, len); 739 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 740 dispatchTab.Allocation2DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, lod, 741 (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 742 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 743} 744 745static void 746nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con, 747 jlong dstAlloc, jint dstXoff, jint dstYoff, 748 jint dstMip, jint dstFace, 749 jint width, jint height, 750 jlong srcAlloc, jint srcXoff, jint srcYoff, 751 jint srcMip, jint srcFace) 752{ 753 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 754 " dstMip(%i), dstFace(%i), width(%i), height(%i)," 755 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", 756 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 757 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 758 759 dispatchTab.AllocationCopy2DRange((RsContext)con, 760 (RsAllocation)dstAlloc, 761 dstXoff, dstYoff, 762 dstMip, dstFace, 763 width, height, 764 (RsAllocation)srcAlloc, 765 srcXoff, srcYoff, 766 srcMip, srcFace); 767} 768 769static void 770nAllocationData3D_s(JNIEnv *_env, jobject _this, jlong con, jlong alloc, 771 jint xoff, jint yoff, jint zoff, 772 jint lod, jint w, jint h, jint d, jshortArray data, int sizeBytes) 773{ 774 jint len = _env->GetArrayLength(data); 775 LOG_API("nAllocation3DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 776 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 777 jshort *ptr = _env->GetShortArrayElements(data, NULL); 778 dispatchTab.Allocation3DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, 779 lod, w, h, d, ptr, sizeBytes, 0); 780 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 781} 782 783static void 784nAllocationData3D_b(JNIEnv *_env, jobject _this, jlong con, jlong alloc, 785 jint xoff, jint yoff, jint zoff, 786 jint lod, jint w, jint h, jint d, jbyteArray data, int sizeBytes) 787{ 788 jint len = _env->GetArrayLength(data); 789 LOG_API("nAllocation3DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 790 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 791 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 792 dispatchTab.Allocation3DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, 793 lod, w, h, d, ptr, sizeBytes, 0); 794 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 795} 796 797static void 798nAllocationData3D_l(JNIEnv *_env, jobject _this, jlong con, jlong alloc, 799 jint xoff, jint yoff, jint zoff, 800 jint lod, jint w, jint h, jint d, jlongArray data, int sizeBytes) 801{ 802 jint len = _env->GetArrayLength(data); 803 LOG_API("nAllocation3DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 804 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 805 jlong *ptr = _env->GetLongArrayElements(data, NULL); 806 dispatchTab.Allocation3DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, 807 lod, w, h, d, ptr, sizeBytes, 0); 808 _env->ReleaseLongArrayElements(data, ptr, JNI_ABORT); 809} 810 811static void 812nAllocationData3D_i(JNIEnv *_env, jobject _this, jlong con, jlong alloc, 813 jint xoff, jint yoff, jint zoff, 814 jint lod, jint w, jint h, jint d, jintArray data, int sizeBytes) 815{ 816 jint len = _env->GetArrayLength(data); 817 LOG_API("nAllocation3DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 818 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 819 jint *ptr = _env->GetIntArrayElements(data, NULL); 820 dispatchTab.Allocation3DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, 821 lod, w, h, d, ptr, sizeBytes, 0); 822 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 823} 824 825static void 826nAllocationData3D_f(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint xoff, jint yoff, 827 jint zoff, jint lod, jint w, jint h, jint d, jfloatArray data, int sizeBytes) 828{ 829 jint len = _env->GetArrayLength(data); 830 LOG_API("nAllocation3DData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 831 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 832 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 833 dispatchTab.Allocation3DData((RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, 834 lod, w, h, d, ptr, sizeBytes, 0); 835 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 836} 837 838static void 839nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con, 840 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff, 841 jint dstMip, 842 jint width, jint height, jint depth, 843 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, 844 jint srcMip) 845{ 846 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 847 " dstMip(%i), width(%i), height(%i)," 848 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", 849 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 850 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 851 852 dispatchTab.AllocationCopy3DRange((RsContext)con, 853 (RsAllocation)dstAlloc, 854 dstXoff, dstYoff, dstZoff, dstMip, 855 width, height, depth, 856 (RsAllocation)srcAlloc, 857 srcXoff, srcYoff, srcZoff, srcMip); 858} 859 860static void 861nAllocationRead_l(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jlongArray data) 862{ 863 jint len = _env->GetArrayLength(data); 864 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", (RsContext)con, 865 (RsAllocation)alloc, len); 866 jlong *ptr = _env->GetLongArrayElements(data, NULL); 867 jsize length = _env->GetArrayLength(data); 868 dispatchTab.AllocationRead((RsContext)con, (RsAllocation)alloc, ptr, length * sizeof(int)); 869 _env->ReleaseLongArrayElements(data, ptr, 0); 870} 871 872static void 873nAllocationRead_i(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jintArray data) 874{ 875 jint len = _env->GetArrayLength(data); 876 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", (RsContext)con, 877 (RsAllocation)alloc, len); 878 jint *ptr = _env->GetIntArrayElements(data, NULL); 879 jsize length = _env->GetArrayLength(data); 880 dispatchTab.AllocationRead((RsContext)con, (RsAllocation)alloc, ptr, length * sizeof(int)); 881 _env->ReleaseIntArrayElements(data, ptr, 0); 882} 883 884static void 885nAllocationRead_s(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jshortArray data) 886{ 887 jint len = _env->GetArrayLength(data); 888 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", (RsContext)con, 889 (RsAllocation)alloc, len); 890 jshort *ptr = _env->GetShortArrayElements(data, NULL); 891 jsize length = _env->GetArrayLength(data); 892 dispatchTab.AllocationRead((RsContext)con, (RsAllocation)alloc, ptr, length * sizeof(short)); 893 _env->ReleaseShortArrayElements(data, ptr, 0); 894} 895 896static void 897nAllocationRead_b(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jbyteArray data) 898{ 899 jint len = _env->GetArrayLength(data); 900 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", (RsContext)con, 901 (RsAllocation)alloc, len); 902 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 903 jsize length = _env->GetArrayLength(data); 904 dispatchTab.AllocationRead((RsContext)con, (RsAllocation)alloc, ptr, length * sizeof(char)); 905 _env->ReleaseByteArrayElements(data, ptr, 0); 906} 907 908static void 909nAllocationRead_f(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jfloatArray data) 910{ 911 jint len = _env->GetArrayLength(data); 912 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", (RsContext)con, 913 (RsAllocation)alloc, len); 914 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 915 jsize length = _env->GetArrayLength(data); 916 dispatchTab.AllocationRead((RsContext)con, (RsAllocation)alloc, ptr, length * sizeof(float)); 917 _env->ReleaseFloatArrayElements(data, ptr, 0); 918} 919 920static jlong 921nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a) 922{ 923 LOG_API("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); 924 return (jlong)(uintptr_t) dispatchTab.AllocationGetType((RsContext)con, (RsAllocation)a); 925} 926 927static void 928nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX) 929{ 930 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, 931 (RsAllocation)alloc, dimX); 932 dispatchTab.AllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX); 933} 934 935// ----------------------------------- 936 937static void 938nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot) 939{ 940 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", 941 (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); 942 dispatchTab.ScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); 943} 944 945static void 946nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val) 947{ 948 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, 949 (void *)script, slot, val); 950 dispatchTab.ScriptSetVarI((RsContext)con, (RsScript)script, slot, val); 951} 952 953static void 954nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) 955{ 956 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, 957 (void *)script, slot, val); 958 dispatchTab.ScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val); 959} 960 961static void 962nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) 963{ 964 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, 965 (void *)script, slot, val); 966 dispatchTab.ScriptSetVarJ((RsContext)con, (RsScript)script, slot, val); 967} 968 969static void 970nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val) 971{ 972 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, 973 (void *)script, slot, val); 974 dispatchTab.ScriptSetVarF((RsContext)con, (RsScript)script, slot, val); 975} 976 977static void 978nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val) 979{ 980 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, 981 (void *)script, slot, val); 982 dispatchTab.ScriptSetVarD((RsContext)con, (RsScript)script, slot, val); 983} 984 985static void 986nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 987{ 988 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 989 jint len = _env->GetArrayLength(data); 990 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 991 dispatchTab.ScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len); 992 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 993} 994 995static void 996nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, 997 jlong elem, jintArray dims) 998{ 999 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1000 jint len = _env->GetArrayLength(data); 1001 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 1002 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); 1003 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL); 1004 dispatchTab.ScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem, 1005 (const uint32_t *)dimsPtr, dimsLen); 1006 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1007 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); 1008} 1009 1010 1011static void 1012nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone) 1013{ 1014 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", (RsContext)con, 1015 (void *)script, (const char *)timeZone); 1016 1017 jint length = _env->GetArrayLength(timeZone); 1018 jbyte* timeZone_ptr; 1019 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 1020 1021 dispatchTab.ScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length); 1022 1023 if (timeZone_ptr) { 1024 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 1025 } 1026} 1027 1028static void 1029nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot) 1030{ 1031 LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj); 1032 dispatchTab.ScriptInvoke((RsContext)con, (RsScript)obj, slot); 1033} 1034 1035static void 1036nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 1037{ 1038 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1039 jint len = _env->GetArrayLength(data); 1040 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 1041 dispatchTab.ScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len); 1042 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1043} 1044 1045static void 1046nScriptForEach(JNIEnv *_env, jobject _this, jlong con, 1047 jlong script, jint slot, jlong ain, jlong aout) 1048{ 1049 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1050 dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot, 1051 (RsAllocation)ain, (RsAllocation)aout, 1052 NULL, 0, NULL, 0); 1053} 1054static void 1055nScriptForEachV(JNIEnv *_env, jobject _this, jlong con, 1056 jlong script, jint slot, jlong ain, jlong aout, jbyteArray params) 1057{ 1058 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1059 jint len = _env->GetArrayLength(params); 1060 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 1061 dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot, 1062 (RsAllocation)ain, (RsAllocation)aout, 1063 ptr, len, NULL, 0); 1064 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 1065} 1066 1067static void 1068nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con, 1069 jlong script, jint slot, jlong ain, jlong aout, 1070 jint xstart, jint xend, 1071 jint ystart, jint yend, jint zstart, jint zend) 1072{ 1073 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1074 RsScriptCall sc; 1075 sc.xStart = xstart; 1076 sc.xEnd = xend; 1077 sc.yStart = ystart; 1078 sc.yEnd = yend; 1079 sc.zStart = zstart; 1080 sc.zEnd = zend; 1081 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 1082 sc.arrayStart = 0; 1083 sc.arrayEnd = 0; 1084 dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot, 1085 (RsAllocation)ain, (RsAllocation)aout, 1086 NULL, 0, &sc, sizeof(sc)); 1087} 1088 1089static void 1090nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con, 1091 jlong script, jint slot, jlong ain, jlong aout, 1092 jbyteArray params, jint xstart, jint xend, 1093 jint ystart, jint yend, jint zstart, jint zend) 1094{ 1095 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1096 jint len = _env->GetArrayLength(params); 1097 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 1098 RsScriptCall sc; 1099 sc.xStart = xstart; 1100 sc.xEnd = xend; 1101 sc.yStart = ystart; 1102 sc.yEnd = yend; 1103 sc.zStart = zstart; 1104 sc.zEnd = zend; 1105 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 1106 sc.arrayStart = 0; 1107 sc.arrayEnd = 0; 1108 dispatchTab.ScriptForEach((RsContext)con, (RsScript)script, slot, 1109 (RsAllocation)ain, (RsAllocation)aout, 1110 ptr, len, &sc, sizeof(sc)); 1111 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 1112} 1113 1114// ----------------------------------- 1115 1116static jlong 1117nScriptCCreate(JNIEnv *_env, jobject _this, jlong con, 1118 jstring resName, jstring cacheDir, 1119 jbyteArray scriptRef, jint length) 1120{ 1121 LOG_API("nScriptCCreate, con(%p)", (RsContext)con); 1122 1123 AutoJavaStringToUTF8 resNameUTF(_env, resName); 1124 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); 1125 jlong ret = 0; 1126 jbyte* script_ptr = NULL; 1127 jint _exception = 0; 1128 jint remaining; 1129 if (!scriptRef) { 1130 _exception = 1; 1131 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); 1132 goto exit; 1133 } 1134 if (length < 0) { 1135 _exception = 1; 1136 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); 1137 goto exit; 1138 } 1139 remaining = _env->GetArrayLength(scriptRef); 1140 if (remaining < length) { 1141 _exception = 1; 1142 //jniThrowException(_env, "java/lang/IllegalArgumentException", 1143 // "length > script.length - offset"); 1144 goto exit; 1145 } 1146 script_ptr = (jbyte *) 1147 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 1148 1149 //rsScriptCSetText(con, (const char *)script_ptr, length); 1150 1151 ret = (jlong)(uintptr_t)dispatchTab.ScriptCCreate((RsContext)con, 1152 resNameUTF.c_str(), resNameUTF.length(), 1153 cacheDirUTF.c_str(), cacheDirUTF.length(), 1154 (const char *)script_ptr, length); 1155 1156exit: 1157 if (script_ptr) { 1158 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, 1159 _exception ? JNI_ABORT: 0); 1160 } 1161 1162 return (jlong)(uintptr_t)ret; 1163} 1164 1165static jlong 1166nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid) 1167{ 1168 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid); 1169 return (jlong)(uintptr_t)dispatchTab.ScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid); 1170} 1171 1172static jlong 1173nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig) 1174{ 1175 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, 1176 (void *)sid, slot, sig); 1177 return (jlong)(uintptr_t)dispatchTab.ScriptKernelIDCreate((RsContext)con, (RsScript)sid, 1178 slot, sig); 1179} 1180 1181static jlong 1182nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) 1183{ 1184 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot); 1185 return (jlong)(uintptr_t)dispatchTab.ScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot); 1186} 1187 1188static jlong 1189nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src, 1190 jlongArray _dstk, jlongArray _dstf, jlongArray _types) 1191{ 1192 LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con); 1193 1194 jint kernelsLen = _env->GetArrayLength(_kernels); 1195 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr); 1196 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen); 1197 for(int i = 0; i < kernelsLen; ++i) { 1198 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i]; 1199 } 1200 1201 jint srcLen = _env->GetArrayLength(_src); 1202 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr); 1203 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen); 1204 for(int i = 0; i < srcLen; ++i) { 1205 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i]; 1206 } 1207 1208 jint dstkLen = _env->GetArrayLength(_dstk); 1209 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr); 1210 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen); 1211 for(int i = 0; i < dstkLen; ++i) { 1212 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i]; 1213 } 1214 1215 jint dstfLen = _env->GetArrayLength(_dstf); 1216 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr); 1217 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen); 1218 for(int i = 0; i < dstfLen; ++i) { 1219 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i]; 1220 } 1221 1222 jint typesLen = _env->GetArrayLength(_types); 1223 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr); 1224 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen); 1225 for(int i = 0; i < typesLen; ++i) { 1226 typesPtr[i] = (RsType)jTypesPtr[i]; 1227 } 1228 1229 jlong id = (jlong)(uintptr_t) dispatchTab.ScriptGroupCreate((RsContext)con, 1230 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID), 1231 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID), 1232 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID), 1233 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID), 1234 (RsType *)typesPtr, typesLen * sizeof(RsType)); 1235 1236 free(kernelsPtr); 1237 free(srcPtr); 1238 free(dstkPtr); 1239 free(dstfPtr); 1240 free(typesPtr); 1241 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0); 1242 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0); 1243 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0); 1244 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0); 1245 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0); 1246 return id; 1247} 1248 1249static void 1250nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) 1251{ 1252 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, 1253 (void *)gid, (void *)kid, (void *)alloc); 1254 dispatchTab.ScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, 1255 (RsAllocation)alloc); 1256} 1257 1258static void 1259nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) 1260{ 1261 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, 1262 (void *)gid, (void *)kid, (void *)alloc); 1263 dispatchTab.ScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, 1264 (RsAllocation)alloc); 1265} 1266 1267static void 1268nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid) 1269{ 1270 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid); 1271 dispatchTab.ScriptGroupExecute((RsContext)con, (RsScriptGroup)gid); 1272} 1273 1274// --------------------------------------------------------------------------- 1275 1276static jlong 1277nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter, 1278 jint wrapS, jint wrapT, jint wrapR, jfloat aniso) 1279{ 1280 LOG_API("nSamplerCreate, con(%p)", (RsContext)con); 1281 return (jlong)(uintptr_t)dispatchTab.SamplerCreate((RsContext)con, 1282 (RsSamplerValue)magFilter, 1283 (RsSamplerValue)minFilter, 1284 (RsSamplerValue)wrapS, 1285 (RsSamplerValue)wrapT, 1286 (RsSamplerValue)wrapR, 1287 aniso); 1288} 1289 1290static jint 1291nSystemGetPointerSize(JNIEnv *_env, jobject _this) { 1292 return (jint)sizeof(void*); 1293} 1294 1295// --------------------------------------------------------------------------- 1296 1297 1298 1299static const char *classPathName = "android/support/v8/renderscript/RenderScript"; 1300 1301static JNINativeMethod methods[] = { 1302{"nLoadSO", "(Z)Z", (bool*)nLoadSO }, 1303{"nLoadIOSO", "()Z", (bool*)nLoadIOSO }, 1304{"nDeviceCreate", "()J", (void*)nDeviceCreate }, 1305{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy }, 1306{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig }, 1307{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage }, 1308{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage }, 1309{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage }, 1310{"nContextInitToClient", "(J)V", (void*)nContextInitToClient }, 1311{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient }, 1312 1313 1314// All methods below are thread protected in java. 1315{"rsnContextCreate", "(JIII)J", (void*)nContextCreate }, 1316{"rsnContextFinish", "(J)V", (void*)nContextFinish }, 1317{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority }, 1318{"rsnContextDestroy", "(J)V", (void*)nContextDestroy }, 1319{"rsnContextDump", "(JI)V", (void*)nContextDump }, 1320{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage }, 1321//{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate }, 1322//{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg }, 1323//{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal }, 1324{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy }, 1325 1326{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate }, 1327{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 }, 1328{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, 1329 1330{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate }, 1331 1332{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped }, 1333{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap }, 1334{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation }, 1335{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap }, 1336 1337{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, 1338{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, 1339 1340{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll }, 1341{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface }, 1342{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend }, 1343{"rsnAllocationData1D", "(JJIII[JI)V", (void*)nAllocationData1D_l }, 1344{"rsnAllocationData1D", "(JJIII[II)V", (void*)nAllocationData1D_i }, 1345{"rsnAllocationData1D", "(JJIII[SI)V", (void*)nAllocationData1D_s }, 1346{"rsnAllocationData1D", "(JJIII[BI)V", (void*)nAllocationData1D_b }, 1347{"rsnAllocationData1D", "(JJIII[FI)V", (void*)nAllocationData1D_f }, 1348{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D }, 1349{"rsnAllocationData2D", "(JJIIIIII[JI)V", (void*)nAllocationData2D_l }, 1350{"rsnAllocationData2D", "(JJIIIIII[II)V", (void*)nAllocationData2D_i }, 1351{"rsnAllocationData2D", "(JJIIIIII[SI)V", (void*)nAllocationData2D_s }, 1352{"rsnAllocationData2D", "(JJIIIIII[BI)V", (void*)nAllocationData2D_b }, 1353{"rsnAllocationData2D", "(JJIIIIII[FI)V", (void*)nAllocationData2D_f }, 1354{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc }, 1355{"rsnAllocationData3D", "(JJIIIIIII[JI)V", (void*)nAllocationData3D_l }, 1356{"rsnAllocationData3D", "(JJIIIIIII[II)V", (void*)nAllocationData3D_i }, 1357{"rsnAllocationData3D", "(JJIIIIIII[SI)V", (void*)nAllocationData3D_s }, 1358{"rsnAllocationData3D", "(JJIIIIIII[BI)V", (void*)nAllocationData3D_b }, 1359{"rsnAllocationData3D", "(JJIIIIIII[FI)V", (void*)nAllocationData3D_f }, 1360{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc }, 1361{"rsnAllocationRead", "(JJ[I)V", (void*)nAllocationRead_i }, 1362{"rsnAllocationRead", "(JJ[S)V", (void*)nAllocationRead_s }, 1363{"rsnAllocationRead", "(JJ[B)V", (void*)nAllocationRead_b }, 1364{"rsnAllocationRead", "(JJ[F)V", (void*)nAllocationRead_f }, 1365{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType}, 1366{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D }, 1367{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps }, 1368 1369{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation }, 1370{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, 1371{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, 1372{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, 1373{"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach }, 1374{"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV }, 1375{"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped }, 1376{"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV }, 1377{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, 1378{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, 1379{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF }, 1380{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD }, 1381{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV }, 1382{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE }, 1383{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj }, 1384 1385{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate }, 1386{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate }, 1387{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate }, 1388{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate }, 1389{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate }, 1390//{"rsnScriptGroup2Create", "(J[J)J", (void*)nScriptGroup2Create }, 1391{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput }, 1392{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput }, 1393{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute }, 1394 1395{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate }, 1396 1397{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize }, 1398}; 1399 1400// --------------------------------------------------------------------------- 1401 1402jint JNI_OnLoad(JavaVM* vm, void* reserved) 1403{ 1404 JNIEnv* env = NULL; 1405 jclass clazz = NULL; 1406 jint result = -1; 1407 1408 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1409 // __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, 1410 // "ERROR: GetEnv failed\n"); 1411 goto bail; 1412 } 1413 if (env == NULL) { 1414 // __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "ERROR: env == NULL"); 1415 goto bail; 1416 } 1417 1418 clazz = env->FindClass(classPathName); 1419 if (clazz == NULL) { 1420 goto bail; 1421 } 1422 1423 if (env->RegisterNatives(clazz, methods, NELEM(methods)) < 0) { 1424 // __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, 1425 // "ERROR: MediaPlayer native registration failed\n"); 1426 goto bail; 1427 } 1428 1429 /* success -- return valid version number */ 1430 result = JNI_VERSION_1_4; 1431 1432bail: 1433 return result; 1434} 1435