android_renderscript_RenderScript.cpp revision e926dddb21392f6391dee56fa509d60cb6ee18c4
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 26#include <core/SkBitmap.h> 27#include <core/SkPixelRef.h> 28#include <core/SkStream.h> 29#include <core/SkTemplates.h> 30 31#include <androidfw/Asset.h> 32#include <androidfw/AssetManager.h> 33#include <androidfw/ResourceTypes.h> 34 35#include "jni.h" 36#include "JNIHelp.h" 37#include "android_runtime/AndroidRuntime.h" 38#include "android_runtime/android_view_Surface.h" 39#include "android_runtime/android_util_AssetManager.h" 40 41#include <rs.h> 42#include <rsEnv.h> 43#include <gui/Surface.h> 44#include <gui/GLConsumer.h> 45#include <gui/Surface.h> 46#include <android_runtime/android_graphics_SurfaceTexture.h> 47 48//#define LOG_API ALOGE 49#define LOG_API(...) 50 51using namespace android; 52 53#define PER_ARRAY_TYPE(flag, fnc, ...) { \ 54 jint len = 0; \ 55 void *ptr = NULL; \ 56 size_t typeBytes = 0; \ 57 switch(dataType) { \ 58 case RS_TYPE_FLOAT_32: \ 59 len = _env->GetArrayLength((jfloatArray)data); \ 60 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \ 61 typeBytes = 4; \ 62 fnc(__VA_ARGS__); \ 63 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, JNI_ABORT); \ 64 return; \ 65 case RS_TYPE_FLOAT_64: \ 66 len = _env->GetArrayLength((jdoubleArray)data); \ 67 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \ 68 typeBytes = 8; \ 69 fnc(__VA_ARGS__); \ 70 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, JNI_ABORT);\ 71 return; \ 72 case RS_TYPE_SIGNED_8: \ 73 case RS_TYPE_UNSIGNED_8: \ 74 len = _env->GetArrayLength((jbyteArray)data); \ 75 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \ 76 typeBytes = 1; \ 77 fnc(__VA_ARGS__); \ 78 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, JNI_ABORT); \ 79 return; \ 80 case RS_TYPE_SIGNED_16: \ 81 case RS_TYPE_UNSIGNED_16: \ 82 len = _env->GetArrayLength((jshortArray)data); \ 83 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \ 84 typeBytes = 2; \ 85 fnc(__VA_ARGS__); \ 86 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, JNI_ABORT); \ 87 return; \ 88 case RS_TYPE_SIGNED_32: \ 89 case RS_TYPE_UNSIGNED_32: \ 90 len = _env->GetArrayLength((jintArray)data); \ 91 ptr = _env->GetIntArrayElements((jintArray)data, flag); \ 92 typeBytes = 4; \ 93 fnc(__VA_ARGS__); \ 94 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, JNI_ABORT); \ 95 return; \ 96 case RS_TYPE_SIGNED_64: \ 97 case RS_TYPE_UNSIGNED_64: \ 98 len = _env->GetArrayLength((jlongArray)data); \ 99 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \ 100 typeBytes = 8; \ 101 fnc(__VA_ARGS__); \ 102 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, JNI_ABORT); \ 103 return; \ 104 default: \ 105 break; \ 106 } \ 107} 108 109 110class AutoJavaStringToUTF8 { 111public: 112 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { 113 fCStr = env->GetStringUTFChars(str, NULL); 114 fLength = env->GetStringUTFLength(str); 115 } 116 ~AutoJavaStringToUTF8() { 117 fEnv->ReleaseStringUTFChars(fJStr, fCStr); 118 } 119 const char* c_str() const { return fCStr; } 120 jsize length() const { return fLength; } 121 122private: 123 JNIEnv* fEnv; 124 jstring fJStr; 125 const char* fCStr; 126 jsize fLength; 127}; 128 129class AutoJavaStringArrayToUTF8 { 130public: 131 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) 132 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { 133 mCStrings = NULL; 134 mSizeArray = NULL; 135 if (stringsLength > 0) { 136 mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); 137 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); 138 for (jsize ct = 0; ct < stringsLength; ct ++) { 139 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 140 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL); 141 mSizeArray[ct] = mEnv->GetStringUTFLength(s); 142 } 143 } 144 } 145 ~AutoJavaStringArrayToUTF8() { 146 for (jsize ct=0; ct < mStringsLength; ct++) { 147 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 148 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); 149 } 150 free(mCStrings); 151 free(mSizeArray); 152 } 153 const char **c_str() const { return mCStrings; } 154 size_t *c_str_len() const { return mSizeArray; } 155 jsize length() const { return mStringsLength; } 156 157private: 158 JNIEnv *mEnv; 159 jobjectArray mStrings; 160 const char **mCStrings; 161 size_t *mSizeArray; 162 jsize mStringsLength; 163}; 164 165// --------------------------------------------------------------------------- 166 167static jfieldID gContextId = 0; 168static jfieldID gNativeBitmapID = 0; 169static jfieldID gTypeNativeCache = 0; 170 171static void _nInit(JNIEnv *_env, jclass _this) 172{ 173 gContextId = _env->GetFieldID(_this, "mContext", "J"); 174 175 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); 176 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J"); 177} 178 179// --------------------------------------------------------------------------- 180 181static void 182nContextFinish(JNIEnv *_env, jobject _this, jlong con) 183{ 184 LOG_API("nContextFinish, con(%p)", (RsContext)con); 185 rsContextFinish((RsContext)con); 186} 187 188static void 189nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str) 190{ 191 LOG_API("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj); 192 jint len = _env->GetArrayLength(str); 193 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 194 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len); 195 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 196} 197 198static jstring 199nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj) 200{ 201 LOG_API("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj); 202 const char *name = NULL; 203 rsaGetName((RsContext)con, (void *)obj, &name); 204 if(name == NULL || strlen(name) == 0) { 205 return NULL; 206 } 207 return _env->NewStringUTF(name); 208} 209 210static void 211nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj) 212{ 213 LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj); 214 rsObjDestroy((RsContext)con, (void *)obj); 215} 216 217// --------------------------------------------------------------------------- 218 219static jlong 220nDeviceCreate(JNIEnv *_env, jobject _this) 221{ 222 LOG_API("nDeviceCreate"); 223 return (jint)rsDeviceCreate(); 224} 225 226static void 227nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 228{ 229 LOG_API("nDeviceDestroy"); 230 return rsDeviceDestroy((RsDevice)dev); 231} 232 233static void 234nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) 235{ 236 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 237 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 238} 239 240static jlong 241nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct) 242{ 243 LOG_API("nContextCreate"); 244 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0); 245} 246 247static jlong 248nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, 249 int colorMin, int colorPref, 250 int alphaMin, int alphaPref, 251 int depthMin, int depthPref, 252 int stencilMin, int stencilPref, 253 int samplesMin, int samplesPref, float samplesQ, 254 int dpi) 255{ 256 RsSurfaceConfig sc; 257 sc.alphaMin = alphaMin; 258 sc.alphaPref = alphaPref; 259 sc.colorMin = colorMin; 260 sc.colorPref = colorPref; 261 sc.depthMin = depthMin; 262 sc.depthPref = depthPref; 263 sc.samplesMin = samplesMin; 264 sc.samplesPref = samplesPref; 265 sc.samplesQ = samplesQ; 266 267 LOG_API("nContextCreateGL"); 268 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi); 269} 270 271static void 272nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p) 273{ 274 LOG_API("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p); 275 rsContextSetPriority((RsContext)con, p); 276} 277 278 279 280static void 281nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd) 282{ 283 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, width, height, (Surface *)wnd); 284 285 ANativeWindow * window = NULL; 286 if (wnd == NULL) { 287 288 } else { 289 window = android_view_Surface_getNativeWindow(_env, wnd).get(); 290 } 291 292 rsContextSetSurface((RsContext)con, width, height, window); 293} 294 295static void 296nContextDestroy(JNIEnv *_env, jobject _this, jlong con) 297{ 298 LOG_API("nContextDestroy, con(%p)", (RsContext)con); 299 rsContextDestroy((RsContext)con); 300} 301 302static void 303nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits) 304{ 305 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 306 rsContextDump((RsContext)con, bits); 307} 308 309static void 310nContextPause(JNIEnv *_env, jobject _this, jlong con) 311{ 312 LOG_API("nContextPause, con(%p)", (RsContext)con); 313 rsContextPause((RsContext)con); 314} 315 316static void 317nContextResume(JNIEnv *_env, jobject _this, jlong con) 318{ 319 LOG_API("nContextResume, con(%p)", (RsContext)con); 320 rsContextResume((RsContext)con); 321} 322 323 324static jstring 325nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con) 326{ 327 LOG_API("nContextGetErrorMessage, con(%p)", (RsContext)con); 328 char buf[1024]; 329 330 size_t receiveLen; 331 uint32_t subID; 332 int id = rsContextGetMessage((RsContext)con, 333 buf, sizeof(buf), 334 &receiveLen, sizeof(receiveLen), 335 &subID, sizeof(subID)); 336 if (!id && receiveLen) { 337 ALOGV("message receive buffer too small. %i", receiveLen); 338 } 339 return _env->NewStringUTF(buf); 340} 341 342static jint 343nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) 344{ 345 jint len = _env->GetArrayLength(data); 346 LOG_API("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len); 347 jint *ptr = _env->GetIntArrayElements(data, NULL); 348 size_t receiveLen; 349 uint32_t subID; 350 int id = rsContextGetMessage((RsContext)con, 351 ptr, len * 4, 352 &receiveLen, sizeof(receiveLen), 353 &subID, sizeof(subID)); 354 if (!id && receiveLen) { 355 ALOGV("message receive buffer too small. %i", receiveLen); 356 } 357 _env->ReleaseIntArrayElements(data, ptr, 0); 358 return id; 359} 360 361static jint 362nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData) 363{ 364 LOG_API("nContextPeekMessage, con(%p)", (RsContext)con); 365 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); 366 size_t receiveLen; 367 uint32_t subID; 368 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen), 369 &subID, sizeof(subID)); 370 auxDataPtr[0] = (jint)subID; 371 auxDataPtr[1] = (jint)receiveLen; 372 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); 373 return id; 374} 375 376static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con) 377{ 378 LOG_API("nContextInitToClient, con(%p)", (RsContext)con); 379 rsContextInitToClient((RsContext)con); 380} 381 382static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con) 383{ 384 LOG_API("nContextDeinitToClient, con(%p)", (RsContext)con); 385 rsContextDeinitToClient((RsContext)con); 386} 387 388static void 389nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data) 390{ 391 jint *ptr = NULL; 392 jint len = 0; 393 if (data) { 394 len = _env->GetArrayLength(data); 395 ptr = _env->GetIntArrayElements(data, NULL); 396 } 397 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); 398 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int)); 399 if (data) { 400 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 401 } 402} 403 404 405 406static jlong 407nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size) 408{ 409 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con, type, kind, norm, size); 410 return (jlong)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, norm, size); 411} 412 413static jlong 414nElementCreate2(JNIEnv *_env, jobject _this, jlong con, 415 jintArray _ids, jobjectArray _names, jintArray _arraySizes) 416{ 417 int fieldCount = _env->GetArrayLength(_ids); 418 LOG_API("nElementCreate2, con(%p)", (RsContext)con); 419 420 jint *ids = _env->GetIntArrayElements(_ids, NULL); 421 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL); 422 423 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); 424 425 const char **nameArray = names.c_str(); 426 size_t *sizeArray = names.c_str_len(); 427 428 jlong id = (jlong)rsElementCreate2((RsContext)con, 429 (RsElement *)ids, fieldCount, 430 nameArray, fieldCount * sizeof(size_t), sizeArray, 431 (const uint32_t *)arraySizes, fieldCount); 432 433 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); 434 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT); 435 return (jint)id; 436} 437 438static void 439nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData) 440{ 441 int dataSize = _env->GetArrayLength(_elementData); 442 LOG_API("nElementGetNativeData, con(%p)", (RsContext)con); 443 444 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements 445 assert(dataSize == 5); 446 447 uint32_t elementData[5]; 448 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize); 449 450 for(jint i = 0; i < dataSize; i ++) { 451 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]); 452 } 453} 454 455 456static void 457nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id, 458 jintArray _IDs, 459 jobjectArray _names, 460 jintArray _arraySizes) 461{ 462 int dataSize = _env->GetArrayLength(_IDs); 463 LOG_API("nElementGetSubElements, con(%p)", (RsContext)con); 464 465 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 466 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); 467 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 468 469 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize); 470 471 for(jint i = 0; i < dataSize; i++) { 472 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 473 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); 474 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]); 475 } 476 477 free(ids); 478 free(names); 479 free(arraySizes); 480} 481 482// ----------------------------------- 483 484static jlong 485nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid, 486 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) 487{ 488 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", 489 (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv); 490 491 return (jlong)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv); 492} 493 494static void 495nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _typeData) 496{ 497 // We are packing 6 items: mDimX; mDimY; mDimZ; 498 // mDimLOD; mDimFaces; mElement; into typeData 499 int elementCount = _env->GetArrayLength(_typeData); 500 501 assert(elementCount == 6); 502 LOG_API("nTypeCreate, con(%p)", (RsContext)con); 503 504 uint32_t typeData[6]; 505 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6); 506 507 for(jint i = 0; i < elementCount; i ++) { 508 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]); 509 } 510} 511 512// ----------------------------------- 513 514static jlong 515nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, jint pointer) 516{ 517 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", (RsContext)con, (RsElement)type, mips, usage, (void *)pointer); 518 return (jint) rsAllocationCreateTyped((RsContext)con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer); 519} 520 521static void 522nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits) 523{ 524 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, bits); 525 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits); 526} 527 528static jobject 529nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a) 530{ 531 LOG_API("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); 532 533 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a); 534 sp<IGraphicBufferProducer> bp = v; 535 v->decStrong(NULL); 536 537 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp); 538 return o; 539} 540 541static void 542nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur) 543{ 544 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", 545 (RsContext)con, (RsAllocation)alloc, (Surface *)sur); 546 547 sp<Surface> s; 548 if (sur != 0) { 549 s = android_view_Surface_getSurface(_env, sur); 550 } 551 552 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, static_cast<ANativeWindow *>(s.get())); 553} 554 555static void 556nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 557{ 558 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, alloc); 559 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc); 560} 561 562static void 563nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 564{ 565 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, alloc); 566 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc); 567} 568 569 570static void 571nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc) 572{ 573 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc); 574 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc); 575} 576 577static jlong 578nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) 579{ 580 SkBitmap const * nativeBitmap = 581 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 582 const SkBitmap& bitmap(*nativeBitmap); 583 584 bitmap.lockPixels(); 585 const void* ptr = bitmap.getPixels(); 586 jlong id = (jlong)rsAllocationCreateFromBitmap((RsContext)con, 587 (RsType)type, (RsAllocationMipmapControl)mip, 588 ptr, bitmap.getSize(), usage); 589 bitmap.unlockPixels(); 590 return id; 591} 592 593static jlong 594nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) 595{ 596 SkBitmap const * nativeBitmap = 597 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 598 const SkBitmap& bitmap(*nativeBitmap); 599 600 bitmap.lockPixels(); 601 const void* ptr = bitmap.getPixels(); 602 jlong id = (jlong)rsAllocationCreateTyped((RsContext)con, 603 (RsType)type, (RsAllocationMipmapControl)mip, 604 (uint32_t)usage, (size_t)ptr); 605 bitmap.unlockPixels(); 606 return id; 607} 608 609static jlong 610nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) 611{ 612 SkBitmap const * nativeBitmap = 613 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 614 const SkBitmap& bitmap(*nativeBitmap); 615 616 bitmap.lockPixels(); 617 const void* ptr = bitmap.getPixels(); 618 jlong id = (jlong)rsAllocationCubeCreateFromBitmap((RsContext)con, 619 (RsType)type, (RsAllocationMipmapControl)mip, 620 ptr, bitmap.getSize(), usage); 621 bitmap.unlockPixels(); 622 return id; 623} 624 625static void 626nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) 627{ 628 SkBitmap const * nativeBitmap = 629 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 630 const SkBitmap& bitmap(*nativeBitmap); 631 int w = bitmap.width(); 632 int h = bitmap.height(); 633 634 bitmap.lockPixels(); 635 const void* ptr = bitmap.getPixels(); 636 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0, 637 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 638 w, h, ptr, bitmap.getSize(), 0); 639 bitmap.unlockPixels(); 640} 641 642static void 643nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap) 644{ 645 SkBitmap const * nativeBitmap = 646 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); 647 const SkBitmap& bitmap(*nativeBitmap); 648 649 bitmap.lockPixels(); 650 void* ptr = bitmap.getPixels(); 651 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize()); 652 bitmap.unlockPixels(); 653 bitmap.notifyPixelsChanged(); 654} 655 656static void ReleaseBitmapCallback(void *bmp) 657{ 658 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; 659 nativeBitmap->unlockPixels(); 660} 661 662 663static void 664nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, 665 jint count, jobject data, int sizeBytes, int dataType) 666{ 667 RsAllocation *alloc = (RsAllocation *)_alloc; 668 LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)", 669 (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, dataType); 670 PER_ARRAY_TYPE(NULL, rsAllocation1DData, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); 671} 672 673static void 674// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); 675nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes) 676{ 677 jint len = _env->GetArrayLength(data); 678 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); 679 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 680 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx); 681 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 682} 683 684static void 685nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, 686 jint w, jint h, jobject data, int sizeBytes, int dataType) 687{ 688 RsAllocation *alloc = (RsAllocation *)_alloc; 689 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; 690 LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)", 691 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); 692 PER_ARRAY_TYPE(NULL, rsAllocation2DData, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); 693} 694 695static void 696nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con, 697 jlong dstAlloc, jint dstXoff, jint dstYoff, 698 jint dstMip, jint dstFace, 699 jint width, jint height, 700 jlong srcAlloc, jint srcXoff, jint srcYoff, 701 jint srcMip, jint srcFace) 702{ 703 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 704 " dstMip(%i), dstFace(%i), width(%i), height(%i)," 705 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", 706 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 707 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 708 709 rsAllocationCopy2DRange((RsContext)con, 710 (RsAllocation)dstAlloc, 711 dstXoff, dstYoff, 712 dstMip, dstFace, 713 width, height, 714 (RsAllocation)srcAlloc, 715 srcXoff, srcYoff, 716 srcMip, srcFace); 717} 718 719static void 720nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod, 721 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType) 722{ 723 RsAllocation *alloc = (RsAllocation *)_alloc; 724 LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)", 725 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes); 726 PER_ARRAY_TYPE(NULL, rsAllocation3DData, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 727} 728 729static void 730nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con, 731 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff, 732 jint dstMip, 733 jint width, jint height, jint depth, 734 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, 735 jint srcMip) 736{ 737 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 738 " dstMip(%i), width(%i), height(%i)," 739 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", 740 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, 741 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip); 742 743 rsAllocationCopy3DRange((RsContext)con, 744 (RsAllocation)dstAlloc, 745 dstXoff, dstYoff, dstZoff, dstMip, 746 width, height, depth, 747 (RsAllocation)srcAlloc, 748 srcXoff, srcYoff, srcZoff, srcMip); 749} 750 751 752static void 753nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType) 754{ 755 RsAllocation *alloc = (RsAllocation *)_alloc; 756 LOG_API("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); 757 PER_ARRAY_TYPE(0, rsAllocationRead, (RsContext)con, alloc, ptr, len * typeBytes); 758} 759 760static void 761nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, 762 jint count, jobject data, int sizeBytes, int dataType) 763{ 764 RsAllocation *alloc = (RsAllocation *)_alloc; 765 LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)", 766 (RsContext)con, alloc, offset, count, sizeBytes, dataType); 767 PER_ARRAY_TYPE(0, rsAllocation1DRead, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); 768} 769 770static void 771nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, 772 jint w, jint h, jobject data, int sizeBytes, int dataType) 773{ 774 RsAllocation *alloc = (RsAllocation *)_alloc; 775 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; 776 LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)", 777 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); 778 PER_ARRAY_TYPE(0, rsAllocation2DRead, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); 779} 780 781static jlong 782nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a) 783{ 784 LOG_API("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); 785 return (jlong) rsaAllocationGetType((RsContext)con, (RsAllocation)a); 786} 787 788static void 789nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX) 790{ 791 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, (RsAllocation)alloc, dimX); 792 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX); 793} 794 795// ----------------------------------- 796 797static jlong 798nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset) 799{ 800 ALOGV("______nFileA3D %u", (uint32_t) native_asset); 801 802 Asset* asset = reinterpret_cast<Asset*>(native_asset); 803 804 jlong id = (jlong)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength()); 805 return id; 806} 807 808static jlong 809nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path) 810{ 811 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); 812 if (mgr == NULL) { 813 return 0; 814 } 815 816 AutoJavaStringToUTF8 str(_env, _path); 817 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); 818 if (asset == NULL) { 819 return 0; 820 } 821 822 jlong id = (jlong)rsaFileA3DCreateFromAsset((RsContext)con, asset); 823 return id; 824} 825 826static jlong 827nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName) 828{ 829 AutoJavaStringToUTF8 fileNameUTF(_env, fileName); 830 jlong id = (jlong)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str()); 831 832 return id; 833} 834 835static jint 836nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D) 837{ 838 int32_t numEntries = 0; 839 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D); 840 return numEntries; 841} 842 843static void 844nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries) 845{ 846 ALOGV("______nFileA3D %u", (uint32_t) fileA3D); 847 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); 848 849 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); 850 851 for(jint i = 0; i < numEntries; i ++) { 852 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); 853 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); 854 } 855 856 free(fileEntries); 857} 858 859static int 860nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index) 861{ 862 ALOGV("______nFileA3D %u", (uint32_t) fileA3D); 863 jint id = (jint)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D); 864 return id; 865} 866 867// ----------------------------------- 868 869static int 870nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con, 871 jstring fileName, jfloat fontSize, jint dpi) 872{ 873 AutoJavaStringToUTF8 fileNameUTF(_env, fileName); 874 jint id = (jint)rsFontCreateFromFile((RsContext)con, 875 fileNameUTF.c_str(), fileNameUTF.length(), 876 fontSize, dpi); 877 878 return id; 879} 880 881static int 882nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, 883 jstring name, jfloat fontSize, jint dpi, jint native_asset) 884{ 885 Asset* asset = reinterpret_cast<Asset*>(native_asset); 886 AutoJavaStringToUTF8 nameUTF(_env, name); 887 888 jint id = (jint)rsFontCreateFromMemory((RsContext)con, 889 nameUTF.c_str(), nameUTF.length(), 890 fontSize, dpi, 891 asset->getBuffer(false), asset->getLength()); 892 return id; 893} 894 895static int 896nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path, 897 jfloat fontSize, jint dpi) 898{ 899 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); 900 if (mgr == NULL) { 901 return 0; 902 } 903 904 AutoJavaStringToUTF8 str(_env, _path); 905 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); 906 if (asset == NULL) { 907 return 0; 908 } 909 910 jint id = (jint)rsFontCreateFromMemory((RsContext)con, 911 str.c_str(), str.length(), 912 fontSize, dpi, 913 asset->getBuffer(false), asset->getLength()); 914 delete asset; 915 return id; 916} 917 918// ----------------------------------- 919 920static void 921nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot) 922{ 923 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); 924 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); 925} 926 927static void 928nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val) 929{ 930 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val); 931 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val); 932} 933 934static jint 935nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 936{ 937 LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 938 int value = 0; 939 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 940 return value; 941} 942 943static void 944nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) 945{ 946 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val); 947 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val); 948} 949 950static void 951nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) 952{ 953 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, (void *)script, slot, val); 954 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val); 955} 956 957static jlong 958nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 959{ 960 LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 961 jlong value = 0; 962 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 963 return value; 964} 965 966static void 967nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val) 968{ 969 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, slot, val); 970 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val); 971} 972 973static jfloat 974nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 975{ 976 LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 977 jfloat value = 0; 978 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 979 return value; 980} 981 982static void 983nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val) 984{ 985 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, slot, val); 986 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val); 987} 988 989static jdouble 990nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) 991{ 992 LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 993 jdouble value = 0; 994 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); 995 return value; 996} 997 998static void 999nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 1000{ 1001 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1002 jint len = _env->GetArrayLength(data); 1003 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 1004 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len); 1005 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1006} 1007 1008static void 1009nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 1010{ 1011 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1012 jint len = _env->GetArrayLength(data); 1013 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 1014 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len); 1015 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1016} 1017 1018static void 1019nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jlong elem, jintArray dims) 1020{ 1021 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1022 jint len = _env->GetArrayLength(data); 1023 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 1024 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); 1025 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL); 1026 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem, 1027 (const size_t*) dimsPtr, dimsLen); 1028 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1029 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); 1030} 1031 1032 1033static void 1034nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone) 1035{ 1036 LOG_API("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script); 1037 1038 jint length = _env->GetArrayLength(timeZone); 1039 jbyte* timeZone_ptr; 1040 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 1041 1042 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length); 1043 1044 if (timeZone_ptr) { 1045 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 1046 } 1047} 1048 1049static void 1050nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot) 1051{ 1052 LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj); 1053 rsScriptInvoke((RsContext)con, (RsScript)obj, slot); 1054} 1055 1056static void 1057nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) 1058{ 1059 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1060 jint len = _env->GetArrayLength(data); 1061 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 1062 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len); 1063 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 1064} 1065 1066static void 1067nScriptForEach(JNIEnv *_env, jobject _this, jlong con, 1068 jlong script, jint slot, jlong ain, jlong aout) 1069{ 1070 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1071 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0); 1072} 1073static void 1074nScriptForEachV(JNIEnv *_env, jobject _this, jlong con, 1075 jlong script, jint slot, jlong ain, jlong aout, jbyteArray params) 1076{ 1077 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1078 jint len = _env->GetArrayLength(params); 1079 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 1080 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0); 1081 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 1082} 1083 1084static void 1085nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con, 1086 jlong script, jint slot, jlong ain, jlong aout, 1087 jint xstart, jint xend, 1088 jint ystart, jint yend, jint zstart, jint zend) 1089{ 1090 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1091 RsScriptCall sc; 1092 sc.xStart = xstart; 1093 sc.xEnd = xend; 1094 sc.yStart = ystart; 1095 sc.yEnd = yend; 1096 sc.zStart = zstart; 1097 sc.zEnd = zend; 1098 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 1099 sc.arrayStart = 0; 1100 sc.arrayEnd = 0; 1101 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); 1102} 1103 1104static void 1105nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con, 1106 jlong script, jint slot, jlong ain, jlong aout, 1107 jbyteArray params, jint xstart, jint xend, 1108 jint ystart, jint yend, jint zstart, jint zend) 1109{ 1110 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); 1111 jint len = _env->GetArrayLength(params); 1112 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 1113 RsScriptCall sc; 1114 sc.xStart = xstart; 1115 sc.xEnd = xend; 1116 sc.yStart = ystart; 1117 sc.yEnd = yend; 1118 sc.zStart = zstart; 1119 sc.zEnd = zend; 1120 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 1121 sc.arrayStart = 0; 1122 sc.arrayEnd = 0; 1123 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc)); 1124 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 1125} 1126 1127// ----------------------------------- 1128 1129static jint 1130nScriptCCreate(JNIEnv *_env, jobject _this, jlong con, 1131 jstring resName, jstring cacheDir, 1132 jbyteArray scriptRef, jint length) 1133{ 1134 LOG_API("nScriptCCreate, con(%p)", (RsContext)con); 1135 1136 AutoJavaStringToUTF8 resNameUTF(_env, resName); 1137 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); 1138 jint ret = 0; 1139 jbyte* script_ptr = NULL; 1140 jint _exception = 0; 1141 jint remaining; 1142 if (!scriptRef) { 1143 _exception = 1; 1144 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); 1145 goto exit; 1146 } 1147 if (length < 0) { 1148 _exception = 1; 1149 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); 1150 goto exit; 1151 } 1152 remaining = _env->GetArrayLength(scriptRef); 1153 if (remaining < length) { 1154 _exception = 1; 1155 //jniThrowException(_env, "java/lang/IllegalArgumentException", 1156 // "length > script.length - offset"); 1157 goto exit; 1158 } 1159 script_ptr = (jbyte *) 1160 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 1161 1162 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length); 1163 1164 ret = (jint)rsScriptCCreate((RsContext)con, 1165 resNameUTF.c_str(), resNameUTF.length(), 1166 cacheDirUTF.c_str(), cacheDirUTF.length(), 1167 (const char *)script_ptr, length); 1168 1169exit: 1170 if (script_ptr) { 1171 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, 1172 _exception ? JNI_ABORT: 0); 1173 } 1174 1175 return ret; 1176} 1177 1178static jlong 1179nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid) 1180{ 1181 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid); 1182 return (jlong)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid); 1183} 1184 1185static jlong 1186nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig) 1187{ 1188 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, (void *)sid, slot, sig); 1189 return (jint)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig); 1190} 1191 1192static jlong 1193nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) 1194{ 1195 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot); 1196 return (jint)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot); 1197} 1198 1199static jlong 1200nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jintArray _kernels, jintArray _src, 1201 jintArray _dstk, jintArray _dstf, jintArray _types) 1202{ 1203 LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con); 1204 1205 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int); 1206 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL); 1207 jint srcLen = _env->GetArrayLength(_src) * sizeof(int); 1208 jint *srcPtr = _env->GetIntArrayElements(_src, NULL); 1209 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int); 1210 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL); 1211 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int); 1212 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL); 1213 jint typesLen = _env->GetArrayLength(_types) * sizeof(int); 1214 jint *typesPtr = _env->GetIntArrayElements(_types, NULL); 1215 1216 int id = (int)rsScriptGroupCreate((RsContext)con, 1217 (RsScriptKernelID *)kernelsPtr, kernelsLen, 1218 (RsScriptKernelID *)srcPtr, srcLen, 1219 (RsScriptKernelID *)dstkPtr, dstkLen, 1220 (RsScriptFieldID *)dstfPtr, dstfLen, 1221 (RsType *)typesPtr, typesLen); 1222 1223 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0); 1224 _env->ReleaseIntArrayElements(_src, srcPtr, 0); 1225 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0); 1226 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0); 1227 _env->ReleaseIntArrayElements(_types, typesPtr, 0); 1228 return id; 1229} 1230 1231static void 1232nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) 1233{ 1234 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, 1235 (void *)gid, (void *)kid, (void *)alloc); 1236 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 1237} 1238 1239static void 1240nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) 1241{ 1242 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, 1243 (void *)gid, (void *)kid, (void *)alloc); 1244 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 1245} 1246 1247static void 1248nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid) 1249{ 1250 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid); 1251 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid); 1252} 1253 1254// --------------------------------------------------------------------------- 1255 1256static jint 1257nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con, 1258 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA, 1259 jboolean depthMask, jboolean ditherEnable, 1260 jint srcFunc, jint destFunc, 1261 jint depthFunc) 1262{ 1263 LOG_API("nProgramStoreCreate, con(%p)", (RsContext)con); 1264 return (jint)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA, 1265 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc, 1266 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc); 1267} 1268 1269// --------------------------------------------------------------------------- 1270 1271static void 1272nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a) 1273{ 1274 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, (RsProgramVertex)vpv, slot, (RsAllocation)a); 1275 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a); 1276} 1277 1278static void 1279nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) 1280{ 1281 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 1282 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 1283} 1284 1285static void 1286nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) 1287{ 1288 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); 1289 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); 1290} 1291 1292// --------------------------------------------------------------------------- 1293 1294static jlong 1295nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, 1296 jobjectArray texNames, jintArray params) 1297{ 1298 AutoJavaStringToUTF8 shaderUTF(_env, shader); 1299 jint *paramPtr = _env->GetIntArrayElements(params, NULL); 1300 jint paramLen = _env->GetArrayLength(params); 1301 1302 int texCount = _env->GetArrayLength(texNames); 1303 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); 1304 const char ** nameArray = names.c_str(); 1305 size_t* sizeArray = names.c_str_len(); 1306 1307 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); 1308 1309 jlong ret = (jlong)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(), 1310 nameArray, texCount, sizeArray, 1311 (uint32_t *)paramPtr, paramLen); 1312 1313 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); 1314 return ret; 1315} 1316 1317 1318// --------------------------------------------------------------------------- 1319 1320static jlong 1321nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, 1322 jobjectArray texNames, jintArray params) 1323{ 1324 AutoJavaStringToUTF8 shaderUTF(_env, shader); 1325 jint *paramPtr = _env->GetIntArrayElements(params, NULL); 1326 jint paramLen = _env->GetArrayLength(params); 1327 1328 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); 1329 1330 int texCount = _env->GetArrayLength(texNames); 1331 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); 1332 const char ** nameArray = names.c_str(); 1333 size_t* sizeArray = names.c_str_len(); 1334 1335 jlong ret = (jlong)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(), 1336 nameArray, texCount, sizeArray, 1337 (uint32_t *)paramPtr, paramLen); 1338 1339 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); 1340 return ret; 1341} 1342 1343// --------------------------------------------------------------------------- 1344 1345static jlong 1346nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull) 1347{ 1348 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, pointSprite, cull); 1349 return (jint)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull); 1350} 1351 1352 1353// --------------------------------------------------------------------------- 1354 1355static void 1356nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jint script) 1357{ 1358 LOG_API("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script); 1359 rsContextBindRootScript((RsContext)con, (RsScript)script); 1360} 1361 1362static void 1363nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jint pfs) 1364{ 1365 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs); 1366 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs); 1367} 1368 1369static void 1370nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jint pf) 1371{ 1372 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, (RsProgramFragment)pf); 1373 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf); 1374} 1375 1376static void 1377nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jint pf) 1378{ 1379 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf); 1380 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf); 1381} 1382 1383static void 1384nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jint pf) 1385{ 1386 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf); 1387 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf); 1388} 1389 1390 1391// --------------------------------------------------------------------------- 1392 1393static jint 1394nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter, 1395 jint wrapS, jint wrapT, jint wrapR, jfloat aniso) 1396{ 1397 LOG_API("nSamplerCreate, con(%p)", (RsContext)con); 1398 return (jint)rsSamplerCreate((RsContext)con, 1399 (RsSamplerValue)magFilter, 1400 (RsSamplerValue)minFilter, 1401 (RsSamplerValue)wrapS, 1402 (RsSamplerValue)wrapT, 1403 (RsSamplerValue)wrapR, 1404 aniso); 1405} 1406 1407// --------------------------------------------------------------------------- 1408 1409static jlong 1410nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jint _loop, jfloat q) { 1411 LOG_API("nPathCreate, con(%p)", (RsContext)con); 1412 1413 jlong id = (jlong)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic, 1414 (RsAllocation)_vtx, 1415 (RsAllocation)_loop, q); 1416 return id; 1417} 1418 1419static jlong 1420nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jintArray _vtx, jintArray _idx, jintArray _prim) 1421{ 1422 LOG_API("nMeshCreate, con(%p)", (RsContext)con); 1423 1424 jint vtxLen = _env->GetArrayLength(_vtx); 1425 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL); 1426 jint idxLen = _env->GetArrayLength(_idx); 1427 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL); 1428 jint primLen = _env->GetArrayLength(_prim); 1429 jint *primPtr = _env->GetIntArrayElements(_prim, NULL); 1430 1431 int id = (int)rsMeshCreate((RsContext)con, 1432 (RsAllocation *)vtxPtr, vtxLen, 1433 (RsAllocation *)idxPtr, idxLen, 1434 (uint32_t *)primPtr, primLen); 1435 1436 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0); 1437 _env->ReleaseIntArrayElements(_idx, idxPtr, 0); 1438 _env->ReleaseIntArrayElements(_prim, primPtr, 0); 1439 return id; 1440} 1441 1442static jint 1443nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) 1444{ 1445 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1446 jint vtxCount = 0; 1447 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount); 1448 return vtxCount; 1449} 1450 1451static jint 1452nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) 1453{ 1454 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1455 jint idxCount = 0; 1456 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount); 1457 return idxCount; 1458} 1459 1460static void 1461nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jintArray _ids, int numVtxIDs) 1462{ 1463 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1464 1465 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); 1466 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); 1467 1468 for(jint i = 0; i < numVtxIDs; i ++) { 1469 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]); 1470 } 1471 1472 free(allocs); 1473} 1474 1475static void 1476nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jintArray _idxIds, jintArray _primitives, int numIndices) 1477{ 1478 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); 1479 1480 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); 1481 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); 1482 1483 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); 1484 1485 for(jint i = 0; i < numIndices; i ++) { 1486 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]); 1487 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]); 1488 } 1489 1490 free(allocs); 1491 free(prims); 1492} 1493 1494// --------------------------------------------------------------------------- 1495 1496 1497static const char *classPathName = "android/renderscript/RenderScript"; 1498 1499static JNINativeMethod methods[] = { 1500{"_nInit", "()V", (void*)_nInit }, 1501 1502{"nDeviceCreate", "()J", (void*)nDeviceCreate }, 1503{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy }, 1504{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig }, 1505{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage }, 1506{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage }, 1507{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage }, 1508 1509{"nContextInitToClient", "(J)V", (void*)nContextInitToClient }, 1510{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient }, 1511 1512 1513// All methods below are thread protected in java. 1514{"rsnContextCreate", "(JIII)J", (void*)nContextCreate }, 1515{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL }, 1516{"rsnContextFinish", "(J)V", (void*)nContextFinish }, 1517{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority }, 1518{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface }, 1519{"rsnContextDestroy", "(J)V", (void*)nContextDestroy }, 1520{"rsnContextDump", "(JI)V", (void*)nContextDump }, 1521{"rsnContextPause", "(J)V", (void*)nContextPause }, 1522{"rsnContextResume", "(J)V", (void*)nContextResume }, 1523{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage }, 1524{"rsnAssignName", "(JJ[B)V", (void*)nAssignName }, 1525{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName }, 1526{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy }, 1527 1528{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile }, 1529{"rsnFileA3DCreateFromAssetStream", "(JI)J", (void*)nFileA3DCreateFromAssetStream }, 1530{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset }, 1531{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries }, 1532{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, 1533{"rsnFileA3DGetEntryByIndex", "(JJI)I", (void*)nFileA3DGetEntryByIndex }, 1534 1535{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)I", (void*)nFontCreateFromFile }, 1536{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream }, 1537{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset }, 1538 1539{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate }, 1540{"rsnElementCreate2", "(J[I[Ljava/lang/String;[I)J", (void*)nElementCreate2 }, 1541{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData }, 1542{"rsnElementGetSubElements", "(JJ[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, 1543 1544{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate }, 1545{"rsnTypeGetNativeData", "(JJ[I)V", (void*)nTypeGetNativeData }, 1546 1547{"rsnAllocationCreateTyped", "(JJIII)J", (void*)nAllocationCreateTyped }, 1548{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap }, 1549{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation }, 1550{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap }, 1551 1552{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, 1553{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, 1554 1555{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll }, 1556{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface }, 1557{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface }, 1558{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend }, 1559{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive }, 1560{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D }, 1561{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D }, 1562{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D }, 1563{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc }, 1564{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D }, 1565{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc }, 1566{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead }, 1567{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D }, 1568{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D }, 1569{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType}, 1570{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D }, 1571{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps }, 1572 1573{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation }, 1574{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, 1575{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, 1576{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, 1577{"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach }, 1578{"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV }, 1579{"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped }, 1580{"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV }, 1581{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, 1582{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI }, 1583{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, 1584{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ }, 1585{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF }, 1586{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF }, 1587{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD }, 1588{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD }, 1589{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV }, 1590{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV }, 1591{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE }, 1592{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj }, 1593 1594{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate }, 1595{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate }, 1596{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate }, 1597{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate }, 1598{"rsnScriptGroupCreate", "(J[I[I[I[I[I)J", (void*)nScriptGroupCreate }, 1599{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput }, 1600{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput }, 1601{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute }, 1602 1603{"rsnProgramStoreCreate", "(JZZZZZZIII)I", (void*)nProgramStoreCreate }, 1604 1605{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants }, 1606{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture }, 1607{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler }, 1608 1609{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[I)J", (void*)nProgramFragmentCreate }, 1610{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate }, 1611{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[I)J", (void*)nProgramVertexCreate }, 1612 1613{"rsnContextBindRootScript", "(JI)V", (void*)nContextBindRootScript }, 1614{"rsnContextBindProgramStore", "(JI)V", (void*)nContextBindProgramStore }, 1615{"rsnContextBindProgramFragment", "(JI)V", (void*)nContextBindProgramFragment }, 1616{"rsnContextBindProgramVertex", "(JI)V", (void*)nContextBindProgramVertex }, 1617{"rsnContextBindProgramRaster", "(JI)V", (void*)nContextBindProgramRaster }, 1618 1619{"rsnSamplerCreate", "(JIIIIIF)I", (void*)nSamplerCreate }, 1620 1621{"rsnPathCreate", "(JIZJIF)J", (void*)nPathCreate }, 1622{"rsnMeshCreate", "(J[I[I[I)J", (void*)nMeshCreate }, 1623 1624{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount }, 1625{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount }, 1626{"rsnMeshGetVertices", "(JJ[II)V", (void*)nMeshGetVertices }, 1627{"rsnMeshGetIndices", "(JJ[I[II)V", (void*)nMeshGetIndices }, 1628 1629}; 1630 1631static int registerFuncs(JNIEnv *_env) 1632{ 1633 return android::AndroidRuntime::registerNativeMethods( 1634 _env, classPathName, methods, NELEM(methods)); 1635} 1636 1637// --------------------------------------------------------------------------- 1638 1639jint JNI_OnLoad(JavaVM* vm, void* reserved) 1640{ 1641 JNIEnv* env = NULL; 1642 jint result = -1; 1643 1644 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1645 ALOGE("ERROR: GetEnv failed\n"); 1646 goto bail; 1647 } 1648 assert(env != NULL); 1649 1650 if (registerFuncs(env) < 0) { 1651 ALOGE("ERROR: MediaPlayer native registration failed\n"); 1652 goto bail; 1653 } 1654 1655 /* success -- return valid version number */ 1656 result = JNI_VERSION_1_4; 1657 1658bail: 1659 return result; 1660} 1661