android_renderscript_RenderScript.cpp revision 46ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43
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 <inttypes.h> 26 27#include <SkBitmap.h> 28 29#include <androidfw/Asset.h> 30#include <androidfw/AssetManager.h> 31#include <androidfw/ResourceTypes.h> 32 33#include "jni.h" 34#include "JNIHelp.h" 35#include "android_runtime/AndroidRuntime.h" 36#include "android_runtime/android_view_Surface.h" 37#include "android_runtime/android_util_AssetManager.h" 38 39#include <rs.h> 40#include <rsEnv.h> 41#include <gui/Surface.h> 42#include <gui/GLConsumer.h> 43#include <gui/Surface.h> 44#include <android_runtime/android_graphics_SurfaceTexture.h> 45 46//#define LOG_API ALOGE 47static constexpr bool kLogApi = false; 48 49using namespace android; 50 51template <typename... T> 52void UNUSED(T... t) {} 53 54#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \ 55 jint len = 0; \ 56 void *ptr = nullptr; \ 57 size_t typeBytes = 0; \ 58 jint relFlag = 0; \ 59 if (readonly) { \ 60 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \ 61 relFlag = JNI_ABORT; \ 62 } \ 63 switch(dataType) { \ 64 case RS_TYPE_FLOAT_32: \ 65 len = _env->GetArrayLength((jfloatArray)data); \ 66 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \ 67 typeBytes = 4; \ 68 fnc(__VA_ARGS__); \ 69 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \ 70 return; \ 71 case RS_TYPE_FLOAT_64: \ 72 len = _env->GetArrayLength((jdoubleArray)data); \ 73 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \ 74 typeBytes = 8; \ 75 fnc(__VA_ARGS__); \ 76 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \ 77 return; \ 78 case RS_TYPE_SIGNED_8: \ 79 case RS_TYPE_UNSIGNED_8: \ 80 len = _env->GetArrayLength((jbyteArray)data); \ 81 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \ 82 typeBytes = 1; \ 83 fnc(__VA_ARGS__); \ 84 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \ 85 return; \ 86 case RS_TYPE_SIGNED_16: \ 87 case RS_TYPE_UNSIGNED_16: \ 88 len = _env->GetArrayLength((jshortArray)data); \ 89 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \ 90 typeBytes = 2; \ 91 fnc(__VA_ARGS__); \ 92 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \ 93 return; \ 94 case RS_TYPE_SIGNED_32: \ 95 case RS_TYPE_UNSIGNED_32: \ 96 len = _env->GetArrayLength((jintArray)data); \ 97 ptr = _env->GetIntArrayElements((jintArray)data, flag); \ 98 typeBytes = 4; \ 99 fnc(__VA_ARGS__); \ 100 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \ 101 return; \ 102 case RS_TYPE_SIGNED_64: \ 103 case RS_TYPE_UNSIGNED_64: \ 104 len = _env->GetArrayLength((jlongArray)data); \ 105 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \ 106 typeBytes = 8; \ 107 fnc(__VA_ARGS__); \ 108 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \ 109 return; \ 110 default: \ 111 break; \ 112 } \ 113 UNUSED(len, ptr, typeBytes, relFlag); \ 114} 115 116 117class AutoJavaStringToUTF8 { 118public: 119 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { 120 fCStr = env->GetStringUTFChars(str, nullptr); 121 fLength = env->GetStringUTFLength(str); 122 } 123 ~AutoJavaStringToUTF8() { 124 fEnv->ReleaseStringUTFChars(fJStr, fCStr); 125 } 126 const char* c_str() const { return fCStr; } 127 jsize length() const { return fLength; } 128 129private: 130 JNIEnv* fEnv; 131 jstring fJStr; 132 const char* fCStr; 133 jsize fLength; 134}; 135 136class AutoJavaStringArrayToUTF8 { 137public: 138 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) 139 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { 140 mCStrings = nullptr; 141 mSizeArray = nullptr; 142 if (stringsLength > 0) { 143 mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); 144 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); 145 for (jsize ct = 0; ct < stringsLength; ct ++) { 146 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 147 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr); 148 mSizeArray[ct] = mEnv->GetStringUTFLength(s); 149 } 150 } 151 } 152 ~AutoJavaStringArrayToUTF8() { 153 for (jsize ct=0; ct < mStringsLength; ct++) { 154 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 155 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); 156 } 157 free(mCStrings); 158 free(mSizeArray); 159 } 160 const char **c_str() const { return mCStrings; } 161 size_t *c_str_len() const { return mSizeArray; } 162 jsize length() const { return mStringsLength; } 163 164private: 165 JNIEnv *mEnv; 166 jobjectArray mStrings; 167 const char **mCStrings; 168 size_t *mSizeArray; 169 jsize mStringsLength; 170}; 171 172// --------------------------------------------------------------------------- 173 174static jfieldID gContextId = 0; 175static jfieldID gNativeBitmapID = 0; 176 177static void _nInit(JNIEnv *_env, jclass _this) 178{ 179 gContextId = _env->GetFieldID(_this, "mContext", "J"); 180 181 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); 182 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J"); 183} 184 185// --------------------------------------------------------------------------- 186 187static void 188nContextFinish(JNIEnv *_env, jobject _this, jlong con) 189{ 190 if (kLogApi) { 191 ALOGD("nContextFinish, con(%p)", (RsContext)con); 192 } 193 rsContextFinish((RsContext)con); 194} 195 196static jlong 197nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID, 198 jlong returnValue, jlongArray fieldIDArray, 199 jlongArray valueArray, jintArray sizeArray, 200 jlongArray depClosureArray, jlongArray depFieldIDArray) { 201 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr); 202 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray); 203 RsScriptFieldID* fieldIDs = 204 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length); 205 for (int i = 0; i< fieldIDs_length; i++) { 206 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i]; 207 } 208 209 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr); 210 jsize values_length = _env->GetArrayLength(valueArray); 211 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length); 212 for (int i = 0; i < values_length; i++) { 213 values[i] = (uintptr_t)jValues[i]; 214 } 215 216 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr); 217 jsize sizes_length = _env->GetArrayLength(sizeArray); 218 219 jlong* jDepClosures = 220 _env->GetLongArrayElements(depClosureArray, nullptr); 221 jsize depClosures_length = _env->GetArrayLength(depClosureArray); 222 RsClosure* depClosures = 223 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length); 224 for (int i = 0; i < depClosures_length; i++) { 225 depClosures[i] = (RsClosure)jDepClosures[i]; 226 } 227 228 jlong* jDepFieldIDs = 229 _env->GetLongArrayElements(depFieldIDArray, nullptr); 230 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray); 231 RsScriptFieldID* depFieldIDs = 232 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length); 233 for (int i = 0; i < depClosures_length; i++) { 234 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i]; 235 } 236 237 return (jlong)(uintptr_t)rsClosureCreate( 238 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue, 239 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length, 240 (size_t*)sizes, (size_t)sizes_length, 241 depClosures, (size_t)depClosures_length, 242 depFieldIDs, (size_t)depFieldIDs_length); 243} 244 245static jlong 246nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID, 247 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray, 248 jintArray sizeArray) { 249 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr); 250 jsize jParamLength = _env->GetArrayLength(paramArray); 251 252 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr); 253 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray); 254 RsScriptFieldID* fieldIDs = 255 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length); 256 for (int i = 0; i< fieldIDs_length; i++) { 257 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i]; 258 } 259 260 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr); 261 jsize values_length = _env->GetArrayLength(valueArray); 262 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length); 263 for (int i = 0; i < values_length; i++) { 264 values[i] = (uintptr_t)jValues[i]; 265 } 266 267 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr); 268 jsize sizes_length = _env->GetArrayLength(sizeArray); 269 270 return (jlong)(uintptr_t)rsInvokeClosureCreate( 271 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength, 272 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length, 273 (size_t*)sizes, (size_t)sizes_length); 274} 275 276static void 277nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID, 278 jint index, jlong value, jint size) { 279 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index, 280 (uintptr_t)value, (size_t)size); 281} 282 283static void 284nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID, 285 jlong fieldID, jlong value, jint size) { 286 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID, 287 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size); 288} 289 290static long 291nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, 292 jstring cacheDir, jlongArray closureArray) { 293 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); 294 295 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr); 296 jsize numClosures = _env->GetArrayLength(closureArray); 297 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures); 298 for (int i = 0; i < numClosures; i++) { 299 closures[i] = (RsClosure)jClosures[i]; 300 } 301 302 return (jlong)(uintptr_t)rsScriptGroup2Create( 303 (RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length(), 304 closures, numClosures); 305} 306 307static void 308nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) { 309 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID); 310} 311 312static void 313nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str) 314{ 315 if (kLogApi) { 316 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj); 317 } 318 jint len = _env->GetArrayLength(str); 319 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 320 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len); 321 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 322} 323 324static jstring 325nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj) 326{ 327 if (kLogApi) { 328 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj); 329 } 330 const char *name = nullptr; 331 rsaGetName((RsContext)con, (void *)obj, &name); 332 if(name == nullptr || strlen(name) == 0) { 333 return nullptr; 334 } 335 return _env->NewStringUTF(name); 336} 337 338static void 339nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj) 340{ 341 if (kLogApi) { 342 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj); 343 } 344 rsObjDestroy((RsContext)con, (void *)obj); 345} 346 347// --------------------------------------------------------------------------- 348 349static jlong 350nDeviceCreate(JNIEnv *_env, jobject _this) 351{ 352 if (kLogApi) { 353 ALOGD("nDeviceCreate"); 354 } 355 return (jlong)(uintptr_t)rsDeviceCreate(); 356} 357 358static void 359nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev) 360{ 361 if (kLogApi) { 362 ALOGD("nDeviceDestroy"); 363 } 364 return rsDeviceDestroy((RsDevice)dev); 365} 366 367static void 368nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value) 369{ 370 if (kLogApi) { 371 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 372 } 373 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 374} 375 376static jlong 377nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType) 378{ 379 if (kLogApi) { 380 ALOGD("nContextCreate"); 381 } 382 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags); 383} 384 385static jlong 386nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, 387 jint colorMin, jint colorPref, 388 jint alphaMin, jint alphaPref, 389 jint depthMin, jint depthPref, 390 jint stencilMin, jint stencilPref, 391 jint samplesMin, jint samplesPref, jfloat samplesQ, 392 jint dpi) 393{ 394 RsSurfaceConfig sc; 395 sc.alphaMin = alphaMin; 396 sc.alphaPref = alphaPref; 397 sc.colorMin = colorMin; 398 sc.colorPref = colorPref; 399 sc.depthMin = depthMin; 400 sc.depthPref = depthPref; 401 sc.samplesMin = samplesMin; 402 sc.samplesPref = samplesPref; 403 sc.samplesQ = samplesQ; 404 405 if (kLogApi) { 406 ALOGD("nContextCreateGL"); 407 } 408 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi); 409} 410 411static void 412nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p) 413{ 414 if (kLogApi) { 415 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p); 416 } 417 rsContextSetPriority((RsContext)con, p); 418} 419 420 421 422static void 423nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd) 424{ 425 if (kLogApi) { 426 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, 427 width, height, (Surface *)wnd); 428 } 429 430 ANativeWindow * window = nullptr; 431 if (wnd == nullptr) { 432 433 } else { 434 window = android_view_Surface_getNativeWindow(_env, wnd).get(); 435 } 436 437 rsContextSetSurface((RsContext)con, width, height, window); 438} 439 440static void 441nContextDestroy(JNIEnv *_env, jobject _this, jlong con) 442{ 443 if (kLogApi) { 444 ALOGD("nContextDestroy, con(%p)", (RsContext)con); 445 } 446 rsContextDestroy((RsContext)con); 447} 448 449static void 450nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits) 451{ 452 if (kLogApi) { 453 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 454 } 455 rsContextDump((RsContext)con, bits); 456} 457 458static void 459nContextPause(JNIEnv *_env, jobject _this, jlong con) 460{ 461 if (kLogApi) { 462 ALOGD("nContextPause, con(%p)", (RsContext)con); 463 } 464 rsContextPause((RsContext)con); 465} 466 467static void 468nContextResume(JNIEnv *_env, jobject _this, jlong con) 469{ 470 if (kLogApi) { 471 ALOGD("nContextResume, con(%p)", (RsContext)con); 472 } 473 rsContextResume((RsContext)con); 474} 475 476 477static jstring 478nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con) 479{ 480 if (kLogApi) { 481 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con); 482 } 483 char buf[1024]; 484 485 size_t receiveLen; 486 uint32_t subID; 487 int id = rsContextGetMessage((RsContext)con, 488 buf, sizeof(buf), 489 &receiveLen, sizeof(receiveLen), 490 &subID, sizeof(subID)); 491 if (!id && receiveLen) { 492 ALOGV("message receive buffer too small. %zu", receiveLen); 493 } 494 return _env->NewStringUTF(buf); 495} 496 497static jint 498nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) 499{ 500 jint len = _env->GetArrayLength(data); 501 if (kLogApi) { 502 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len); 503 } 504 jint *ptr = _env->GetIntArrayElements(data, nullptr); 505 size_t receiveLen; 506 uint32_t subID; 507 int id = rsContextGetMessage((RsContext)con, 508 ptr, len * 4, 509 &receiveLen, sizeof(receiveLen), 510 &subID, sizeof(subID)); 511 if (!id && receiveLen) { 512 ALOGV("message receive buffer too small. %zu", receiveLen); 513 } 514 _env->ReleaseIntArrayElements(data, ptr, 0); 515 return (jint)id; 516} 517 518static jint 519nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData) 520{ 521 if (kLogApi) { 522 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con); 523 } 524 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr); 525 size_t receiveLen; 526 uint32_t subID; 527 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen), 528 &subID, sizeof(subID)); 529 auxDataPtr[0] = (jint)subID; 530 auxDataPtr[1] = (jint)receiveLen; 531 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); 532 return (jint)id; 533} 534 535static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con) 536{ 537 if (kLogApi) { 538 ALOGD("nContextInitToClient, con(%p)", (RsContext)con); 539 } 540 rsContextInitToClient((RsContext)con); 541} 542 543static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con) 544{ 545 if (kLogApi) { 546 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con); 547 } 548 rsContextDeinitToClient((RsContext)con); 549} 550 551static void 552nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data) 553{ 554 jint *ptr = nullptr; 555 jint len = 0; 556 if (data) { 557 len = _env->GetArrayLength(data); 558 ptr = _env->GetIntArrayElements(data, nullptr); 559 } 560 if (kLogApi) { 561 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); 562 } 563 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int)); 564 if (data) { 565 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 566 } 567} 568 569 570 571static jlong 572nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, 573 jint size) 574{ 575 if (kLogApi) { 576 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con, 577 type, kind, norm, size); 578 } 579 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, 580 norm, size); 581} 582 583static jlong 584nElementCreate2(JNIEnv *_env, jobject _this, jlong con, 585 jlongArray _ids, jobjectArray _names, jintArray _arraySizes) 586{ 587 int fieldCount = _env->GetArrayLength(_ids); 588 if (kLogApi) { 589 ALOGD("nElementCreate2, con(%p)", (RsContext)con); 590 } 591 592 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr); 593 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr); 594 595 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement)); 596 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t)); 597 598 for(int i = 0; i < fieldCount; i ++) { 599 ids[i] = (RsElement)jIds[i]; 600 arraySizes[i] = (uint32_t)jArraySizes[i]; 601 } 602 603 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); 604 605 const char **nameArray = names.c_str(); 606 size_t *sizeArray = names.c_str_len(); 607 608 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con, 609 (const RsElement *)ids, fieldCount, 610 nameArray, fieldCount * sizeof(size_t), sizeArray, 611 (const uint32_t *)arraySizes, fieldCount); 612 613 free(ids); 614 free(arraySizes); 615 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT); 616 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT); 617 618 return (jlong)(uintptr_t)id; 619} 620 621static void 622nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData) 623{ 624 int dataSize = _env->GetArrayLength(_elementData); 625 if (kLogApi) { 626 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con); 627 } 628 629 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements 630 assert(dataSize == 5); 631 632 uintptr_t elementData[5]; 633 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize); 634 635 for(jint i = 0; i < dataSize; i ++) { 636 const jint data = (jint)elementData[i]; 637 _env->SetIntArrayRegion(_elementData, i, 1, &data); 638 } 639} 640 641 642static void 643nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id, 644 jlongArray _IDs, 645 jobjectArray _names, 646 jintArray _arraySizes) 647{ 648 uint32_t dataSize = _env->GetArrayLength(_IDs); 649 if (kLogApi) { 650 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con); 651 } 652 653 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t)); 654 const char **names = (const char **)malloc(dataSize * sizeof(const char *)); 655 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t)); 656 657 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, 658 (uint32_t)dataSize); 659 660 for(uint32_t i = 0; i < dataSize; i++) { 661 const jlong id = (jlong)(uintptr_t)ids[i]; 662 const jint arraySize = (jint)arraySizes[i]; 663 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 664 _env->SetLongArrayRegion(_IDs, i, 1, &id); 665 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize); 666 } 667 668 free(ids); 669 free(names); 670 free(arraySizes); 671} 672 673// ----------------------------------- 674 675static jlong 676nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid, 677 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) 678{ 679 if (kLogApi) { 680 ALOGD("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", 681 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv); 682 } 683 684 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, 685 faces, yuv); 686} 687 688static void 689nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData) 690{ 691 // We are packing 6 items: mDimX; mDimY; mDimZ; 692 // mDimLOD; mDimFaces; mElement; into typeData 693 int elementCount = _env->GetArrayLength(_typeData); 694 695 assert(elementCount == 6); 696 if (kLogApi) { 697 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con); 698 } 699 700 uintptr_t typeData[6]; 701 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6); 702 703 for(jint i = 0; i < elementCount; i ++) { 704 const jlong data = (jlong)(uintptr_t)typeData[i]; 705 _env->SetLongArrayRegion(_typeData, i, 1, &data); 706 } 707} 708 709// ----------------------------------- 710 711static jlong 712nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, 713 jlong pointer) 714{ 715 if (kLogApi) { 716 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", 717 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer); 718 } 719 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type, 720 (RsAllocationMipmapControl)mips, 721 (uint32_t)usage, (uintptr_t)pointer); 722} 723 724static void 725nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits) 726{ 727 if (kLogApi) { 728 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, 729 bits); 730 } 731 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits); 732} 733 734static jobject 735nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a) 736{ 737 if (kLogApi) { 738 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); 739 } 740 741 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, 742 (RsAllocation)a); 743 sp<IGraphicBufferProducer> bp = v; 744 v->decStrong(nullptr); 745 746 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp); 747 return o; 748} 749 750static void 751nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur) 752{ 753 if (kLogApi) { 754 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con, 755 (RsAllocation)alloc, (Surface *)sur); 756 } 757 758 sp<Surface> s; 759 if (sur != 0) { 760 s = android_view_Surface_getSurface(_env, sur); 761 } 762 763 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, 764 static_cast<ANativeWindow *>(s.get())); 765} 766 767static void 768nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 769{ 770 if (kLogApi) { 771 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); 772 } 773 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc); 774} 775 776static void 777nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 778{ 779 if (kLogApi) { 780 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); 781 } 782 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc); 783} 784 785 786static void 787nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 788{ 789 if (kLogApi) { 790 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc); 791 } 792 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc); 793} 794 795static jlong 796nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, 797 jobject jbitmap, jint usage) 798{ 799 SkBitmap const * nativeBitmap = 800 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 801 const SkBitmap& bitmap(*nativeBitmap); 802 803 bitmap.lockPixels(); 804 const void* ptr = bitmap.getPixels(); 805 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con, 806 (RsType)type, (RsAllocationMipmapControl)mip, 807 ptr, bitmap.getSize(), usage); 808 bitmap.unlockPixels(); 809 return id; 810} 811 812static jlong 813nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, 814 jint mip, jobject jbitmap, jint usage) 815{ 816 SkBitmap const * nativeBitmap = 817 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 818 const SkBitmap& bitmap(*nativeBitmap); 819 820 bitmap.lockPixels(); 821 const void* ptr = bitmap.getPixels(); 822 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con, 823 (RsType)type, (RsAllocationMipmapControl)mip, 824 (uint32_t)usage, (uintptr_t)ptr); 825 bitmap.unlockPixels(); 826 return id; 827} 828 829static jlong 830nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, 831 jobject jbitmap, jint usage) 832{ 833 SkBitmap const * nativeBitmap = 834 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 835 const SkBitmap& bitmap(*nativeBitmap); 836 837 bitmap.lockPixels(); 838 const void* ptr = bitmap.getPixels(); 839 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con, 840 (RsType)type, (RsAllocationMipmapControl)mip, 841 ptr, bitmap.getSize(), usage); 842 bitmap.unlockPixels(); 843 return id; 844} 845 846static void 847nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) 848{ 849 SkBitmap const * nativeBitmap = 850 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 851 const SkBitmap& bitmap(*nativeBitmap); 852 int w = bitmap.width(); 853 int h = bitmap.height(); 854 855 bitmap.lockPixels(); 856 const void* ptr = bitmap.getPixels(); 857 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0, 858 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 859 w, h, ptr, bitmap.getSize(), 0); 860 bitmap.unlockPixels(); 861} 862 863static void 864nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) 865{ 866 SkBitmap const * nativeBitmap = 867 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 868 const SkBitmap& bitmap(*nativeBitmap); 869 870 bitmap.lockPixels(); 871 void* ptr = bitmap.getPixels(); 872 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize()); 873 bitmap.unlockPixels(); 874 bitmap.notifyPixelsChanged(); 875} 876 877// Copies from the Java object data into the Allocation pointed to by _alloc. 878static void 879nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, 880 jint count, jobject data, jint sizeBytes, jint dataType) 881{ 882 RsAllocation *alloc = (RsAllocation *)_alloc; 883 if (kLogApi) { 884 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), " 885 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, 886 dataType); 887 } 888 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count, 889 ptr, sizeBytes); 890} 891 892// Copies from the Java array data into the Allocation pointed to by alloc. 893static void 894// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes); 895nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, 896 jint compIdx, jbyteArray data, jint sizeBytes) 897{ 898 jint len = _env->GetArrayLength(data); 899 if (kLogApi) { 900 ALOGD("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), " 901 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, 902 sizeBytes); 903 } 904 jbyte *ptr = _env->GetByteArrayElements(data, nullptr); 905 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx); 906 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 907} 908 909// Copies from the Java object data into the Allocation pointed to by _alloc. 910static void 911nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, 912 jint w, jint h, jobject data, jint sizeBytes, jint dataType) 913{ 914 RsAllocation *alloc = (RsAllocation *)_alloc; 915 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; 916 if (kLogApi) { 917 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) " 918 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); 919 } 920 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); 921} 922 923// Copies from the Allocation pointed to by srcAlloc into the Allocation 924// pointed to by dstAlloc. 925static void 926nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con, 927 jlong dstAlloc, jint dstXoff, jint dstYoff, 928 jint dstMip, jint dstFace, 929 jint width, jint height, 930 jlong srcAlloc, jint srcXoff, jint srcYoff, 931 jint srcMip, jint srcFace) 932{ 933 if (kLogApi) { 934 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 935 " dstMip(%i), dstFace(%i), width(%i), height(%i)," 936 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", 937 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 938 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 939 } 940 941 rsAllocationCopy2DRange((RsContext)con, 942 (RsAllocation)dstAlloc, 943 dstXoff, dstYoff, 944 dstMip, dstFace, 945 width, height, 946 (RsAllocation)srcAlloc, 947 srcXoff, srcYoff, 948 srcMip, srcFace); 949} 950 951// Copies from the Java object data into the Allocation pointed to by _alloc. 952static void 953nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod, 954 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType) 955{ 956 RsAllocation *alloc = (RsAllocation *)_alloc; 957 if (kLogApi) { 958 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i)," 959 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, 960 lod, w, h, d, sizeBytes); 961 } 962 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 963} 964 965// Copies from the Allocation pointed to by srcAlloc into the Allocation 966// pointed to by dstAlloc. 967static void 968nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con, 969 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff, 970 jint dstMip, 971 jint width, jint height, jint depth, 972 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, 973 jint srcMip) 974{ 975 if (kLogApi) { 976 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 977 " dstMip(%i), width(%i), height(%i)," 978 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", 979 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, 980 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip); 981 } 982 983 rsAllocationCopy3DRange((RsContext)con, 984 (RsAllocation)dstAlloc, 985 dstXoff, dstYoff, dstZoff, dstMip, 986 width, height, depth, 987 (RsAllocation)srcAlloc, 988 srcXoff, srcYoff, srcZoff, srcMip); 989} 990 991 992// Copies from the Allocation pointed to by _alloc into the Java object data. 993static void 994nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType) 995{ 996 RsAllocation *alloc = (RsAllocation *)_alloc; 997 if (kLogApi) { 998 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); 999 } 1000 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes); 1001} 1002 1003// Copies from the Allocation pointed to by _alloc into the Java object data. 1004static void 1005nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, 1006 jint count, jobject data, int sizeBytes, int dataType) 1007{ 1008 RsAllocation *alloc = (RsAllocation *)_alloc; 1009 if (kLogApi) { 1010 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), " 1011 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType); 1012 } 1013 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); 1014} 1015 1016// Copies from the Allocation pointed to by _alloc into the Java object data. 1017static void 1018nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, 1019 jint w, jint h, jobject data, int sizeBytes, int dataType) 1020{ 1021 RsAllocation *alloc = (RsAllocation *)_alloc; 1022 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; 1023 if (kLogApi) { 1024 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) " 1025 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); 1026 } 1027 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, 1028 ptr, sizeBytes, 0); 1029} 1030 1031static jlong 1032nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a) 1033{ 1034 if (kLogApi) { 1035 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); 1036 } 1037 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a); 1038} 1039 1040static void 1041nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX) 1042{ 1043 if (kLogApi) { 1044 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, 1045 (RsAllocation)alloc, dimX); 1046 } 1047 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX); 1048} 1049 1050 1051static jlong 1052nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type) 1053{ 1054 if (kLogApi) { 1055 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)", 1056 (RsContext)con, (RsAllocation)basealloc, (RsElement)type); 1057 } 1058 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type, 1059 (RsAllocation)basealloc); 1060 1061} 1062 1063static void 1064nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc, 1065 jint x, jint y, jint z, jint face, jint lod, 1066 jint a1, jint a2, jint a3, jint a4) 1067{ 1068 uint32_t params[] = { 1069 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face, 1070 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4 1071 }; 1072 if (kLogApi) { 1073 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)", 1074 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4); 1075 } 1076 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc, 1077 params, sizeof(params)); 1078} 1079 1080 1081// ----------------------------------- 1082 1083static jlong 1084nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset) 1085{ 1086 Asset* asset = reinterpret_cast<Asset*>(native_asset); 1087 ALOGV("______nFileA3D %p", asset); 1088 1089 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength()); 1090 return id; 1091} 1092 1093static jlong 1094nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path) 1095{ 1096 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); 1097 if (mgr == nullptr) { 1098 return 0; 1099 } 1100 1101 AutoJavaStringToUTF8 str(_env, _path); 1102 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); 1103 if (asset == nullptr) { 1104 return 0; 1105 } 1106 1107 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset); 1108 return id; 1109} 1110 1111static jlong 1112nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName) 1113{ 1114 AutoJavaStringToUTF8 fileNameUTF(_env, fileName); 1115 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str()); 1116 1117 return id; 1118} 1119 1120static jint 1121nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D) 1122{ 1123 int32_t numEntries = 0; 1124 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D); 1125 return (jint)numEntries; 1126} 1127 1128static void 1129nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries) 1130{ 1131 ALOGV("______nFileA3D %p", (RsFile) fileA3D); 1132 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); 1133 1134 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); 1135 1136 for(jint i = 0; i < numEntries; i ++) { 1137 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); 1138 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); 1139 } 1140 1141 free(fileEntries); 1142} 1143 1144static jlong 1145nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index) 1146{ 1147 ALOGV("______nFileA3D %p", (RsFile) fileA3D); 1148 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D); 1149 return id; 1150} 1151 1152// ----------------------------------- 1153 1154static jlong 1155nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con, 1156 jstring fileName, jfloat fontSize, jint dpi) 1157{ 1158 AutoJavaStringToUTF8 fileNameUTF(_env, fileName); 1159 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con, 1160 fileNameUTF.c_str(), fileNameUTF.length(), 1161 fontSize, dpi); 1162 1163 return id; 1164} 1165 1166static jlong 1167nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, 1168 jstring name, jfloat fontSize, jint dpi, jlong native_asset) 1169{ 1170 Asset* asset = reinterpret_cast<Asset*>(native_asset); 1171 AutoJavaStringToUTF8 nameUTF(_env, name); 1172 1173 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con, 1174 nameUTF.c_str(), nameUTF.length(), 1175 fontSize, dpi, 1176 asset->getBuffer(false), asset->getLength()); 1177 return id; 1178} 1179 1180static jlong 1181nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path, 1182 jfloat fontSize, jint dpi) 1183{ 1184 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); 1185 if (mgr == nullptr) { 1186 return 0; 1187 } 1188 1189 AutoJavaStringToUTF8 str(_env, _path); 1190 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); 1191 if (asset == nullptr) { 1192 return 0; 1193 } 1194 1195 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con, 1196 str.c_str(), str.length(), 1197 fontSize, dpi, 1198 asset->getBuffer(false), asset->getLength()); 1199 delete asset; 1200 return id; 1201} 1202 1203// ----------------------------------- 1204 1205static void 1206nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot) 1207{ 1208 if (kLogApi) { 1209 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, 1210 (RsScript)script, (RsAllocation)alloc, slot); 1211 } 1212 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); 1213} 1214 1215static void 1216nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val) 1217{ 1218 if (kLogApi) { 1219 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, 1220 slot, val); 1221 } 1222 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val); 1223} 1224 1225static jint 1226nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 1227{ 1228 if (kLogApi) { 1229 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1230 } 1231 int value = 0; 1232 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 1233 return value; 1234} 1235 1236static void 1237nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) 1238{ 1239 if (kLogApi) { 1240 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script, 1241 slot, val); 1242 } 1243 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val); 1244} 1245 1246static void 1247nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) 1248{ 1249 if (kLogApi) { 1250 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script, 1251 slot, val); 1252 } 1253 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val); 1254} 1255 1256static jlong 1257nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 1258{ 1259 if (kLogApi) { 1260 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1261 } 1262 jlong value = 0; 1263 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 1264 return value; 1265} 1266 1267static void 1268nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val) 1269{ 1270 if (kLogApi) { 1271 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, 1272 slot, val); 1273 } 1274 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val); 1275} 1276 1277static jfloat 1278nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 1279{ 1280 if (kLogApi) { 1281 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1282 } 1283 jfloat value = 0; 1284 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 1285 return value; 1286} 1287 1288static void 1289nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val) 1290{ 1291 if (kLogApi) { 1292 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, 1293 slot, val); 1294 } 1295 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val); 1296} 1297 1298static jdouble 1299nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 1300{ 1301 if (kLogApi) { 1302 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1303 } 1304 jdouble value = 0; 1305 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 1306 return value; 1307} 1308 1309static void 1310nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 1311{ 1312 if (kLogApi) { 1313 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1314 } 1315 jint len = _env->GetArrayLength(data); 1316 jbyte *ptr = _env->GetByteArrayElements(data, nullptr); 1317 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len); 1318 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1319} 1320 1321static void 1322nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 1323{ 1324 if (kLogApi) { 1325 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1326 } 1327 jint len = _env->GetArrayLength(data); 1328 jbyte *ptr = _env->GetByteArrayElements(data, nullptr); 1329 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len); 1330 _env->ReleaseByteArrayElements(data, ptr, 0); 1331} 1332 1333static void 1334nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, 1335 jlong elem, jintArray dims) 1336{ 1337 if (kLogApi) { 1338 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1339 } 1340 jint len = _env->GetArrayLength(data); 1341 jbyte *ptr = _env->GetByteArrayElements(data, nullptr); 1342 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); 1343 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr); 1344 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem, 1345 (const uint32_t*) dimsPtr, dimsLen); 1346 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1347 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); 1348} 1349 1350 1351static void 1352nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone) 1353{ 1354 if (kLogApi) { 1355 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script); 1356 } 1357 1358 jint length = _env->GetArrayLength(timeZone); 1359 jbyte* timeZone_ptr; 1360 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 1361 1362 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length); 1363 1364 if (timeZone_ptr) { 1365 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 1366 } 1367} 1368 1369static void 1370nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot) 1371{ 1372 if (kLogApi) { 1373 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj); 1374 } 1375 rsScriptInvoke((RsContext)con, (RsScript)obj, slot); 1376} 1377 1378static void 1379nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 1380{ 1381 if (kLogApi) { 1382 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1383 } 1384 jint len = _env->GetArrayLength(data); 1385 jbyte *ptr = _env->GetByteArrayElements(data, nullptr); 1386 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len); 1387 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1388} 1389 1390static void 1391nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, 1392 jlongArray ains, jlong aout, jbyteArray params, 1393 jintArray limits) 1394{ 1395 if (kLogApi) { 1396 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1397 } 1398 1399 jint in_len = 0; 1400 jlong *in_ptr = nullptr; 1401 1402 RsAllocation *in_allocs = nullptr; 1403 1404 if (ains != nullptr) { 1405 in_len = _env->GetArrayLength(ains); 1406 in_ptr = _env->GetLongArrayElements(ains, nullptr); 1407 1408 if (sizeof(RsAllocation) == sizeof(jlong)) { 1409 in_allocs = (RsAllocation*)in_ptr; 1410 1411 } else { 1412 // Convert from 64-bit jlong types to the native pointer type. 1413 1414 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation)); 1415 1416 for (int index = in_len; --index >= 0;) { 1417 in_allocs[index] = (RsAllocation)in_ptr[index]; 1418 } 1419 } 1420 } 1421 1422 jint param_len = 0; 1423 jbyte *param_ptr = nullptr; 1424 1425 if (params != nullptr) { 1426 param_len = _env->GetArrayLength(params); 1427 param_ptr = _env->GetByteArrayElements(params, nullptr); 1428 } 1429 1430 RsScriptCall sc, *sca = nullptr; 1431 uint32_t sc_size = 0; 1432 1433 jint limit_len = 0; 1434 jint *limit_ptr = nullptr; 1435 1436 if (limits != nullptr) { 1437 limit_len = _env->GetArrayLength(limits); 1438 limit_ptr = _env->GetIntArrayElements(limits, nullptr); 1439 1440 assert(limit_len == 6); 1441 UNUSED(limit_len); // As the assert might not be compiled. 1442 1443 sc.xStart = limit_ptr[0]; 1444 sc.xEnd = limit_ptr[1]; 1445 sc.yStart = limit_ptr[2]; 1446 sc.yEnd = limit_ptr[3]; 1447 sc.zStart = limit_ptr[4]; 1448 sc.zEnd = limit_ptr[5]; 1449 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 1450 sc.arrayStart = 0; 1451 sc.arrayEnd = 0; 1452 sc.array2Start = 0; 1453 sc.array2End = 0; 1454 sc.array3Start = 0; 1455 sc.array3End = 0; 1456 sc.array4Start = 0; 1457 sc.array4End = 0; 1458 1459 sca = ≻ 1460 } 1461 1462 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, 1463 in_allocs, in_len, (RsAllocation)aout, 1464 param_ptr, param_len, sca, sc_size); 1465 1466 if (ains != nullptr) { 1467 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); 1468 } 1469 1470 if (params != nullptr) { 1471 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); 1472 } 1473 1474 if (limits != nullptr) { 1475 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); 1476 } 1477} 1478 1479// ----------------------------------- 1480 1481static jlong 1482nScriptCCreate(JNIEnv *_env, jobject _this, jlong con, 1483 jstring resName, jstring cacheDir, 1484 jbyteArray scriptRef, jint length) 1485{ 1486 if (kLogApi) { 1487 ALOGD("nScriptCCreate, con(%p)", (RsContext)con); 1488 } 1489 1490 AutoJavaStringToUTF8 resNameUTF(_env, resName); 1491 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); 1492 jlong ret = 0; 1493 jbyte* script_ptr = nullptr; 1494 jint _exception = 0; 1495 jint remaining; 1496 if (!scriptRef) { 1497 _exception = 1; 1498 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); 1499 goto exit; 1500 } 1501 if (length < 0) { 1502 _exception = 1; 1503 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); 1504 goto exit; 1505 } 1506 remaining = _env->GetArrayLength(scriptRef); 1507 if (remaining < length) { 1508 _exception = 1; 1509 //jniThrowException(_env, "java/lang/IllegalArgumentException", 1510 // "length > script.length - offset"); 1511 goto exit; 1512 } 1513 script_ptr = (jbyte *) 1514 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 1515 1516 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length); 1517 1518 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con, 1519 resNameUTF.c_str(), resNameUTF.length(), 1520 cacheDirUTF.c_str(), cacheDirUTF.length(), 1521 (const char *)script_ptr, length); 1522 1523exit: 1524 if (script_ptr) { 1525 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, 1526 _exception ? JNI_ABORT: 0); 1527 } 1528 1529 return (jlong)(uintptr_t)ret; 1530} 1531 1532static jlong 1533nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid) 1534{ 1535 if (kLogApi) { 1536 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, 1537 (void *)eid); 1538 } 1539 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid); 1540} 1541 1542static jlong 1543nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig) 1544{ 1545 if (kLogApi) { 1546 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, 1547 (void *)sid, slot, sig); 1548 } 1549 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig); 1550} 1551 1552static jlong 1553nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) 1554{ 1555 if (kLogApi) { 1556 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, 1557 (void *)sid, slot); 1558 } 1559 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot); 1560} 1561 1562static jlong 1563nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) 1564{ 1565 if (kLogApi) { 1566 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, 1567 slot); 1568 } 1569 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot); 1570} 1571 1572static jlong 1573nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src, 1574 jlongArray _dstk, jlongArray _dstf, jlongArray _types) 1575{ 1576 if (kLogApi) { 1577 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con); 1578 } 1579 1580 jint kernelsLen = _env->GetArrayLength(_kernels); 1581 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr); 1582 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen); 1583 for(int i = 0; i < kernelsLen; ++i) { 1584 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i]; 1585 } 1586 1587 jint srcLen = _env->GetArrayLength(_src); 1588 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr); 1589 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen); 1590 for(int i = 0; i < srcLen; ++i) { 1591 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i]; 1592 } 1593 1594 jint dstkLen = _env->GetArrayLength(_dstk); 1595 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr); 1596 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen); 1597 for(int i = 0; i < dstkLen; ++i) { 1598 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i]; 1599 } 1600 1601 jint dstfLen = _env->GetArrayLength(_dstf); 1602 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr); 1603 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen); 1604 for(int i = 0; i < dstfLen; ++i) { 1605 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i]; 1606 } 1607 1608 jint typesLen = _env->GetArrayLength(_types); 1609 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr); 1610 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen); 1611 for(int i = 0; i < typesLen; ++i) { 1612 typesPtr[i] = (RsType)jTypesPtr[i]; 1613 } 1614 1615 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con, 1616 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID), 1617 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID), 1618 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID), 1619 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID), 1620 (RsType *)typesPtr, typesLen * sizeof(RsType)); 1621 1622 free(kernelsPtr); 1623 free(srcPtr); 1624 free(dstkPtr); 1625 free(dstfPtr); 1626 free(typesPtr); 1627 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0); 1628 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0); 1629 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0); 1630 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0); 1631 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0); 1632 return id; 1633} 1634 1635static void 1636nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) 1637{ 1638 if (kLogApi) { 1639 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, 1640 (void *)gid, (void *)kid, (void *)alloc); 1641 } 1642 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 1643} 1644 1645static void 1646nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) 1647{ 1648 if (kLogApi) { 1649 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, 1650 (void *)gid, (void *)kid, (void *)alloc); 1651 } 1652 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 1653} 1654 1655static void 1656nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid) 1657{ 1658 if (kLogApi) { 1659 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid); 1660 } 1661 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid); 1662} 1663 1664// --------------------------------------------------------------------------- 1665 1666static jlong 1667nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con, 1668 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA, 1669 jboolean depthMask, jboolean ditherEnable, 1670 jint srcFunc, jint destFunc, 1671 jint depthFunc) 1672{ 1673 if (kLogApi) { 1674 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con); 1675 } 1676 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA, 1677 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc, 1678 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc); 1679} 1680 1681// --------------------------------------------------------------------------- 1682 1683static void 1684nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a) 1685{ 1686 if (kLogApi) { 1687 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, 1688 (RsProgramVertex)vpv, slot, (RsAllocation)a); 1689 } 1690 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a); 1691} 1692 1693static void 1694nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) 1695{ 1696 if (kLogApi) { 1697 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, 1698 (RsProgramFragment)vpf, slot, (RsAllocation)a); 1699 } 1700 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 1701} 1702 1703static void 1704nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) 1705{ 1706 if (kLogApi) { 1707 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, 1708 (RsProgramFragment)vpf, slot, (RsSampler)a); 1709 } 1710 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); 1711} 1712 1713// --------------------------------------------------------------------------- 1714 1715static jlong 1716nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, 1717 jobjectArray texNames, jlongArray params) 1718{ 1719 AutoJavaStringToUTF8 shaderUTF(_env, shader); 1720 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); 1721 jint paramLen = _env->GetArrayLength(params); 1722 1723 int texCount = _env->GetArrayLength(texNames); 1724 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); 1725 const char ** nameArray = names.c_str(); 1726 size_t* sizeArray = names.c_str_len(); 1727 1728 if (kLogApi) { 1729 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); 1730 } 1731 1732 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen); 1733 for(int i = 0; i < paramLen; ++i) { 1734 paramPtr[i] = (uintptr_t)jParamPtr[i]; 1735 } 1736 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(), 1737 nameArray, texCount, sizeArray, 1738 paramPtr, paramLen); 1739 1740 free(paramPtr); 1741 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT); 1742 return ret; 1743} 1744 1745 1746// --------------------------------------------------------------------------- 1747 1748static jlong 1749nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, 1750 jobjectArray texNames, jlongArray params) 1751{ 1752 AutoJavaStringToUTF8 shaderUTF(_env, shader); 1753 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); 1754 jint paramLen = _env->GetArrayLength(params); 1755 1756 if (kLogApi) { 1757 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); 1758 } 1759 1760 int texCount = _env->GetArrayLength(texNames); 1761 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); 1762 const char ** nameArray = names.c_str(); 1763 size_t* sizeArray = names.c_str_len(); 1764 1765 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen); 1766 for(int i = 0; i < paramLen; ++i) { 1767 paramPtr[i] = (uintptr_t)jParamPtr[i]; 1768 } 1769 1770 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(), 1771 nameArray, texCount, sizeArray, 1772 paramPtr, paramLen); 1773 1774 free(paramPtr); 1775 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT); 1776 return ret; 1777} 1778 1779// --------------------------------------------------------------------------- 1780 1781static jlong 1782nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull) 1783{ 1784 if (kLogApi) { 1785 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, 1786 pointSprite, cull); 1787 } 1788 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull); 1789} 1790 1791 1792// --------------------------------------------------------------------------- 1793 1794static void 1795nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script) 1796{ 1797 if (kLogApi) { 1798 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script); 1799 } 1800 rsContextBindRootScript((RsContext)con, (RsScript)script); 1801} 1802 1803static void 1804nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs) 1805{ 1806 if (kLogApi) { 1807 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs); 1808 } 1809 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs); 1810} 1811 1812static void 1813nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf) 1814{ 1815 if (kLogApi) { 1816 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, 1817 (RsProgramFragment)pf); 1818 } 1819 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf); 1820} 1821 1822static void 1823nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf) 1824{ 1825 if (kLogApi) { 1826 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf); 1827 } 1828 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf); 1829} 1830 1831static void 1832nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf) 1833{ 1834 if (kLogApi) { 1835 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf); 1836 } 1837 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf); 1838} 1839 1840 1841// --------------------------------------------------------------------------- 1842 1843static jlong 1844nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter, 1845 jint wrapS, jint wrapT, jint wrapR, jfloat aniso) 1846{ 1847 if (kLogApi) { 1848 ALOGD("nSamplerCreate, con(%p)", (RsContext)con); 1849 } 1850 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con, 1851 (RsSamplerValue)magFilter, 1852 (RsSamplerValue)minFilter, 1853 (RsSamplerValue)wrapS, 1854 (RsSamplerValue)wrapT, 1855 (RsSamplerValue)wrapR, 1856 aniso); 1857} 1858 1859// --------------------------------------------------------------------------- 1860 1861static jlong 1862nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) { 1863 if (kLogApi) { 1864 ALOGD("nPathCreate, con(%p)", (RsContext)con); 1865 } 1866 1867 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic, 1868 (RsAllocation)_vtx, 1869 (RsAllocation)_loop, q); 1870 return id; 1871} 1872 1873static jlong 1874nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim) 1875{ 1876 if (kLogApi) { 1877 ALOGD("nMeshCreate, con(%p)", (RsContext)con); 1878 } 1879 1880 jint vtxLen = _env->GetArrayLength(_vtx); 1881 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr); 1882 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen); 1883 for(int i = 0; i < vtxLen; ++i) { 1884 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i]; 1885 } 1886 1887 jint idxLen = _env->GetArrayLength(_idx); 1888 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr); 1889 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen); 1890 for(int i = 0; i < idxLen; ++i) { 1891 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i]; 1892 } 1893 1894 jint primLen = _env->GetArrayLength(_prim); 1895 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr); 1896 1897 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con, 1898 (RsAllocation *)vtxPtr, vtxLen, 1899 (RsAllocation *)idxPtr, idxLen, 1900 (uint32_t *)primPtr, primLen); 1901 1902 free(vtxPtr); 1903 free(idxPtr); 1904 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0); 1905 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0); 1906 _env->ReleaseIntArrayElements(_prim, primPtr, 0); 1907 return id; 1908} 1909 1910static jint 1911nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) 1912{ 1913 if (kLogApi) { 1914 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1915 } 1916 jint vtxCount = 0; 1917 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount); 1918 return vtxCount; 1919} 1920 1921static jint 1922nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) 1923{ 1924 if (kLogApi) { 1925 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1926 } 1927 jint idxCount = 0; 1928 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount); 1929 return idxCount; 1930} 1931 1932static void 1933nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs) 1934{ 1935 if (kLogApi) { 1936 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1937 } 1938 1939 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); 1940 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); 1941 1942 for(jint i = 0; i < numVtxIDs; i ++) { 1943 const jlong alloc = (jlong)(uintptr_t)allocs[i]; 1944 _env->SetLongArrayRegion(_ids, i, 1, &alloc); 1945 } 1946 1947 free(allocs); 1948} 1949 1950static void 1951nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices) 1952{ 1953 if (kLogApi) { 1954 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1955 } 1956 1957 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); 1958 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); 1959 1960 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); 1961 1962 for(jint i = 0; i < numIndices; i ++) { 1963 const jlong alloc = (jlong)(uintptr_t)allocs[i]; 1964 const jint prim = (jint)prims[i]; 1965 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc); 1966 _env->SetIntArrayRegion(_primitives, i, 1, &prim); 1967 } 1968 1969 free(allocs); 1970 free(prims); 1971} 1972 1973static jint 1974nSystemGetPointerSize(JNIEnv *_env, jobject _this) { 1975 return (jint)sizeof(void*); 1976} 1977 1978 1979// --------------------------------------------------------------------------- 1980 1981 1982static const char *classPathName = "android/renderscript/RenderScript"; 1983 1984static JNINativeMethod methods[] = { 1985{"_nInit", "()V", (void*)_nInit }, 1986 1987{"nDeviceCreate", "()J", (void*)nDeviceCreate }, 1988{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy }, 1989{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig }, 1990{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage }, 1991{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage }, 1992{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage }, 1993 1994{"nContextInitToClient", "(J)V", (void*)nContextInitToClient }, 1995{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient }, 1996 1997 1998// All methods below are thread protected in java. 1999{"rsnContextCreate", "(JIII)J", (void*)nContextCreate }, 2000{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL }, 2001{"rsnContextFinish", "(J)V", (void*)nContextFinish }, 2002{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority }, 2003{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface }, 2004{"rsnContextDestroy", "(J)V", (void*)nContextDestroy }, 2005{"rsnContextDump", "(JI)V", (void*)nContextDump }, 2006{"rsnContextPause", "(J)V", (void*)nContextPause }, 2007{"rsnContextResume", "(J)V", (void*)nContextResume }, 2008{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage }, 2009{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate }, 2010{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate }, 2011{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg }, 2012{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal }, 2013{"rsnAssignName", "(JJ[B)V", (void*)nAssignName }, 2014{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName }, 2015{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy }, 2016 2017{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile }, 2018{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream }, 2019{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset }, 2020{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries }, 2021{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, 2022{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex }, 2023 2024{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile }, 2025{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream }, 2026{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset }, 2027 2028{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate }, 2029{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 }, 2030{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData }, 2031{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, 2032 2033{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate }, 2034{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData }, 2035 2036{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped }, 2037{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap }, 2038{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation }, 2039{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap }, 2040 2041{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, 2042{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, 2043 2044{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll }, 2045{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface }, 2046{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface }, 2047{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend }, 2048{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive }, 2049{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D }, 2050{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D }, 2051{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D }, 2052{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc }, 2053{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D }, 2054{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc }, 2055{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead }, 2056{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D }, 2057{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D }, 2058{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType}, 2059{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D }, 2060{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps }, 2061 2062{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate }, 2063{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset }, 2064 2065{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation }, 2066{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, 2067{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, 2068{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, 2069 2070{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach }, 2071 2072{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, 2073{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI }, 2074{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, 2075{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ }, 2076{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF }, 2077{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF }, 2078{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD }, 2079{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD }, 2080{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV }, 2081{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV }, 2082{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE }, 2083{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj }, 2084 2085{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate }, 2086{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate }, 2087{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate }, 2088{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate }, 2089{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate }, 2090{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate }, 2091{"rsnScriptGroup2Create", "(JLjava/lang/String;[J)J", (void*)nScriptGroup2Create }, 2092{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput }, 2093{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput }, 2094{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute }, 2095{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute }, 2096 2097{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate }, 2098 2099{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants }, 2100{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture }, 2101{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler }, 2102 2103{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate }, 2104{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate }, 2105{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate }, 2106 2107{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript }, 2108{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore }, 2109{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment }, 2110{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex }, 2111{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster }, 2112 2113{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate }, 2114 2115{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate }, 2116{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate }, 2117 2118{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount }, 2119{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount }, 2120{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices }, 2121{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices }, 2122 2123{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize }, 2124}; 2125 2126static int registerFuncs(JNIEnv *_env) 2127{ 2128 return android::AndroidRuntime::registerNativeMethods( 2129 _env, classPathName, methods, NELEM(methods)); 2130} 2131 2132// --------------------------------------------------------------------------- 2133 2134jint JNI_OnLoad(JavaVM* vm, void* reserved) 2135{ 2136 JNIEnv* env = nullptr; 2137 jint result = -1; 2138 2139 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 2140 ALOGE("ERROR: GetEnv failed\n"); 2141 goto bail; 2142 } 2143 assert(env != nullptr); 2144 2145 if (registerFuncs(env) < 0) { 2146 ALOGE("ERROR: Renderscript native registration failed\n"); 2147 goto bail; 2148 } 2149 2150 /* success -- return valid version number */ 2151 result = JNI_VERSION_1_4; 2152 2153bail: 2154 return result; 2155} 2156