android_renderscript_RenderScript.cpp revision 2e1872fe07cf8952812a417985e6e1f61bdeab5d
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 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 <surfaceflinger/Surface.h> 27 28#include <core/SkBitmap.h> 29#include <core/SkPixelRef.h> 30#include <core/SkStream.h> 31#include <core/SkTemplates.h> 32#include <images/SkImageDecoder.h> 33 34#include <utils/Asset.h> 35#include <utils/ResourceTypes.h> 36 37#include "jni.h" 38#include "JNIHelp.h" 39#include "android_runtime/AndroidRuntime.h" 40 41#include <RenderScript.h> 42#include <RenderScriptEnv.h> 43 44//#define LOG_API LOGE 45#define LOG_API(...) 46 47using namespace android; 48 49// --------------------------------------------------------------------------- 50 51static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) 52{ 53 jclass npeClazz = env->FindClass(exc); 54 env->ThrowNew(npeClazz, msg); 55} 56 57static jfieldID gContextId = 0; 58static jfieldID gNativeBitmapID = 0; 59static jfieldID gTypeNativeCache = 0; 60 61static RsElement g_A_8 = NULL; 62static RsElement g_RGBA_4444 = NULL; 63static RsElement g_RGBA_8888 = NULL; 64static RsElement g_RGB_565 = NULL; 65 66static void _nInit(JNIEnv *_env, jclass _this) 67{ 68 gContextId = _env->GetFieldID(_this, "mContext", "I"); 69 70 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); 71 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); 72 73 jclass typeClass = _env->FindClass("android/renderscript/Type"); 74 gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I"); 75} 76 77static void nInitElements(JNIEnv *_env, jobject _this, jint a8, jint rgba4444, jint rgba8888, jint rgb565) 78{ 79 g_A_8 = reinterpret_cast<RsElement>(a8); 80 g_RGBA_4444 = reinterpret_cast<RsElement>(rgba4444); 81 g_RGBA_8888 = reinterpret_cast<RsElement>(rgba8888); 82 g_RGB_565 = reinterpret_cast<RsElement>(rgb565); 83} 84 85// --------------------------------------------------------------------------- 86 87static void 88nContextFinish(JNIEnv *_env, jobject _this, RsContext con) 89{ 90 LOG_API("nContextFinish, con(%p)", con); 91 rsContextFinish(con); 92} 93 94static void 95nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str) 96{ 97 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj); 98 jint len = _env->GetArrayLength(str); 99 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 100 rsAssignName(con, (void *)obj, (const char *)cptr, len); 101 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 102} 103 104static jstring 105nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj) 106{ 107 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj); 108 const char *name = NULL; 109 rsGetName(con, (void *)obj, &name); 110 return _env->NewStringUTF(name); 111} 112 113static void 114nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj) 115{ 116 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); 117 rsObjDestroy(con, (void *)obj); 118} 119 120static void 121nObjDestroyOOB(JNIEnv *_env, jobject _this, RsContext con, jint obj) 122{ 123 // This function only differs from nObjDestroy in that it calls the 124 // special Out Of Band version of ObjDestroy which is thread safe. 125 LOG_API("nObjDestroyOOB, con(%p) obj(%p)", con, (void *)obj); 126 rsObjDestroyOOB(con, (void *)obj); 127} 128 129static jint 130nFileOpen(JNIEnv *_env, jobject _this, RsContext con, jbyteArray str) 131{ 132 LOG_API("nFileOpen, con(%p)", con); 133 jint len = _env->GetArrayLength(str); 134 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 135 jint ret = (jint)rsFileOpen(con, (const char *)cptr, len); 136 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 137 return ret; 138} 139 140// --------------------------------------------------------------------------- 141 142static jint 143nDeviceCreate(JNIEnv *_env, jobject _this) 144{ 145 LOG_API("nDeviceCreate"); 146 return (jint)rsDeviceCreate(); 147} 148 149static void 150nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 151{ 152 LOG_API("nDeviceDestroy"); 153 return rsDeviceDestroy((RsDevice)dev); 154} 155 156static void 157nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) 158{ 159 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 160 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 161} 162 163static jint 164nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver) 165{ 166 LOG_API("nContextCreate"); 167 return (jint)rsContextCreate((RsDevice)dev, ver); 168} 169 170static jint 171nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jboolean useDepth) 172{ 173 LOG_API("nContextCreateGL"); 174 return (jint)rsContextCreateGL((RsDevice)dev, ver, useDepth); 175} 176 177static void 178nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p) 179{ 180 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p); 181 rsContextSetPriority(con, p); 182} 183 184 185 186static void 187nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd) 188{ 189 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd); 190 191 Surface * window = NULL; 192 if (wnd == NULL) { 193 194 } else { 195 jclass surface_class = _env->FindClass("android/view/Surface"); 196 jfieldID surfaceFieldID = _env->GetFieldID(surface_class, ANDROID_VIEW_SURFACE_JNI_ID, "I"); 197 window = (Surface*)_env->GetIntField(wnd, surfaceFieldID); 198 } 199 200 rsContextSetSurface(con, width, height, window); 201} 202 203static void 204nContextDestroy(JNIEnv *_env, jobject _this, RsContext con) 205{ 206 LOG_API("nContextDestroy, con(%p)", con); 207 rsContextDestroy(con); 208} 209 210static void 211nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits) 212{ 213 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 214 rsContextDump((RsContext)con, bits); 215} 216 217static void 218nContextPause(JNIEnv *_env, jobject _this, RsContext con) 219{ 220 LOG_API("nContextPause, con(%p)", con); 221 rsContextPause(con); 222} 223 224static void 225nContextResume(JNIEnv *_env, jobject _this, RsContext con) 226{ 227 LOG_API("nContextResume, con(%p)", con); 228 rsContextResume(con); 229} 230 231static jint 232nContextGetMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data, jboolean wait) 233{ 234 jint len = _env->GetArrayLength(data); 235 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); 236 jint *ptr = _env->GetIntArrayElements(data, NULL); 237 size_t receiveLen; 238 int id = rsContextGetMessage(con, ptr, &receiveLen, len * 4, wait); 239 if (!id && receiveLen) { 240 LOGE("message receive buffer too small. %i", receiveLen); 241 } 242 _env->ReleaseIntArrayElements(data, ptr, 0); 243 return id; 244} 245 246static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con) 247{ 248 LOG_API("nContextInitToClient, con(%p)", con); 249 rsContextInitToClient(con); 250} 251 252static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con) 253{ 254 LOG_API("nContextDeinitToClient, con(%p)", con); 255 rsContextDeinitToClient(con); 256} 257 258 259static jint 260nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size) 261{ 262 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size); 263 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size); 264} 265 266static jint 267nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names) 268{ 269 int fieldCount = _env->GetArrayLength(_ids); 270 LOG_API("nElementCreate2, con(%p)", con); 271 272 jint *ids = _env->GetIntArrayElements(_ids, NULL); 273 const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *)); 274 size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t)); 275 276 for (int ct=0; ct < fieldCount; ct++) { 277 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); 278 nameArray[ct] = _env->GetStringUTFChars(s, NULL); 279 sizeArray[ct] = _env->GetStringUTFLength(s); 280 } 281 jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray); 282 for (int ct=0; ct < fieldCount; ct++) { 283 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); 284 _env->ReleaseStringUTFChars(s, nameArray[ct]); 285 } 286 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); 287 free(nameArray); 288 free(sizeArray); 289 return (jint)id; 290} 291 292static void 293nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData) 294{ 295 int dataSize = _env->GetArrayLength(_elementData); 296 LOG_API("nElementGetNativeData, con(%p)", con); 297 298 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements 299 assert(dataSize == 5); 300 301 uint32_t elementData[5]; 302 rsElementGetNativeData(con, (RsElement)id, elementData, dataSize); 303 304 for(jint i = 0; i < dataSize; i ++) { 305 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]); 306 } 307} 308 309 310static void 311nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _IDs, jobjectArray _names) 312{ 313 int dataSize = _env->GetArrayLength(_IDs); 314 LOG_API("nElementGetSubElements, con(%p)", con); 315 316 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 317 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); 318 319 rsElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize); 320 321 for(jint i = 0; i < dataSize; i ++) { 322 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 323 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); 324 } 325 326 free(ids); 327 free(names); 328} 329 330// ----------------------------------- 331 332static void 333nTypeBegin(JNIEnv *_env, jobject _this, RsContext con, jint eID) 334{ 335 LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID); 336 rsTypeBegin(con, (RsElement)eID); 337} 338 339static void 340nTypeAdd(JNIEnv *_env, jobject _this, RsContext con, jint dim, jint val) 341{ 342 LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val); 343 rsTypeAdd(con, (RsDimension)dim, val); 344} 345 346static jint 347nTypeCreate(JNIEnv *_env, jobject _this, RsContext con) 348{ 349 LOG_API("nTypeCreate, con(%p)", con); 350 return (jint)rsTypeCreate(con); 351} 352 353static void 354nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData) 355{ 356 // We are packing 6 items: mDimX; mDimY; mDimZ; 357 // mDimLOD; mDimFaces; mElement; into typeData 358 int elementCount = _env->GetArrayLength(_typeData); 359 360 assert(elementCount == 6); 361 LOG_API("nTypeCreate, con(%p)", con); 362 363 uint32_t typeData[6]; 364 rsTypeGetNativeData(con, (RsType)id, typeData, 6); 365 366 for(jint i = 0; i < elementCount; i ++) { 367 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]); 368 } 369} 370 371static void * SF_LoadInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 372{ 373 ((int32_t *)buffer)[0] = _env->GetIntField(_obj, _field); 374 return ((uint8_t *)buffer) + 4; 375} 376 377static void * SF_LoadShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 378{ 379 ((int16_t *)buffer)[0] = _env->GetShortField(_obj, _field); 380 return ((uint8_t *)buffer) + 2; 381} 382 383static void * SF_LoadByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 384{ 385 ((int8_t *)buffer)[0] = _env->GetByteField(_obj, _field); 386 return ((uint8_t *)buffer) + 1; 387} 388 389static void * SF_LoadFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 390{ 391 ((float *)buffer)[0] = _env->GetFloatField(_obj, _field); 392 return ((uint8_t *)buffer) + 4; 393} 394 395static void * SF_SaveInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 396{ 397 _env->SetIntField(_obj, _field, ((int32_t *)buffer)[0]); 398 return ((uint8_t *)buffer) + 4; 399} 400 401static void * SF_SaveShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 402{ 403 _env->SetShortField(_obj, _field, ((int16_t *)buffer)[0]); 404 return ((uint8_t *)buffer) + 2; 405} 406 407static void * SF_SaveByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 408{ 409 _env->SetByteField(_obj, _field, ((int8_t *)buffer)[0]); 410 return ((uint8_t *)buffer) + 1; 411} 412 413static void * SF_SaveFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 414{ 415 _env->SetFloatField(_obj, _field, ((float *)buffer)[0]); 416 return ((uint8_t *)buffer) + 4; 417} 418 419struct TypeFieldCache { 420 jfieldID field; 421 int bits; 422 void * (*ptr)(JNIEnv *, jobject, jfieldID, void *buffer); 423 void * (*readPtr)(JNIEnv *, jobject, jfieldID, void *buffer); 424}; 425 426struct TypeCache { 427 int fieldCount; 428 int size; 429 TypeFieldCache fields[1]; 430}; 431 432//{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy }, 433static void 434nTypeFinalDestroy(JNIEnv *_env, jobject _this, RsContext con, jobject _type) 435{ 436 TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); 437 free(tc); 438} 439 440// native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs); 441static void 442nTypeSetupFields(JNIEnv *_env, jobject _this, RsContext con, jobject _type, jintArray _types, jintArray _bits, jobjectArray _IDs) 443{ 444 int fieldCount = _env->GetArrayLength(_types); 445 size_t structSize = sizeof(TypeCache) + (sizeof(TypeFieldCache) * (fieldCount-1)); 446 TypeCache *tc = (TypeCache *)malloc(structSize); 447 memset(tc, 0, structSize); 448 449 TypeFieldCache *tfc = &tc->fields[0]; 450 tc->fieldCount = fieldCount; 451 _env->SetIntField(_type, gTypeNativeCache, (jint)tc); 452 453 jint *fType = _env->GetIntArrayElements(_types, NULL); 454 jint *fBits = _env->GetIntArrayElements(_bits, NULL); 455 for (int ct=0; ct < fieldCount; ct++) { 456 jobject field = _env->GetObjectArrayElement(_IDs, ct); 457 tfc[ct].field = _env->FromReflectedField(field); 458 tfc[ct].bits = fBits[ct]; 459 460 switch(fType[ct]) { 461 case RS_TYPE_FLOAT_32: 462 tfc[ct].ptr = SF_LoadFloat; 463 tfc[ct].readPtr = SF_SaveFloat; 464 break; 465 case RS_TYPE_UNSIGNED_32: 466 case RS_TYPE_SIGNED_32: 467 tfc[ct].ptr = SF_LoadInt; 468 tfc[ct].readPtr = SF_SaveInt; 469 break; 470 case RS_TYPE_UNSIGNED_16: 471 case RS_TYPE_SIGNED_16: 472 tfc[ct].ptr = SF_LoadShort; 473 tfc[ct].readPtr = SF_SaveShort; 474 break; 475 case RS_TYPE_UNSIGNED_8: 476 case RS_TYPE_SIGNED_8: 477 tfc[ct].ptr = SF_LoadByte; 478 tfc[ct].readPtr = SF_SaveByte; 479 break; 480 } 481 tc->size += 4; 482 } 483 484 _env->ReleaseIntArrayElements(_types, fType, JNI_ABORT); 485 _env->ReleaseIntArrayElements(_bits, fBits, JNI_ABORT); 486} 487 488 489// ----------------------------------- 490 491static jint 492nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint e) 493{ 494 LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e); 495 return (jint) rsAllocationCreateTyped(con, (RsElement)e); 496} 497 498static void 499nAllocationUploadToTexture(JNIEnv *_env, jobject _this, RsContext con, jint a, jboolean genMip, jint mip) 500{ 501 LOG_API("nAllocationUploadToTexture, con(%p), a(%p), genMip(%i), mip(%i)", con, (RsAllocation)a, genMip, mip); 502 rsAllocationUploadToTexture(con, (RsAllocation)a, genMip, mip); 503} 504 505static void 506nAllocationUploadToBufferObject(JNIEnv *_env, jobject _this, RsContext con, jint a) 507{ 508 LOG_API("nAllocationUploadToBufferObject, con(%p), a(%p)", con, (RsAllocation)a); 509 rsAllocationUploadToBufferObject(con, (RsAllocation)a); 510} 511 512static RsElement SkBitmapToPredefined(SkBitmap::Config cfg) 513{ 514 switch (cfg) { 515 case SkBitmap::kA8_Config: 516 return g_A_8; 517 case SkBitmap::kARGB_4444_Config: 518 return g_RGBA_4444; 519 case SkBitmap::kARGB_8888_Config: 520 return g_RGBA_8888; 521 case SkBitmap::kRGB_565_Config: 522 return g_RGB_565; 523 524 default: 525 break; 526 } 527 // If we don't have a conversion mark it as a user type. 528 LOGE("Unsupported bitmap type"); 529 return NULL; 530} 531 532static int 533nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint dstFmt, jboolean genMips, jobject jbitmap) 534{ 535 SkBitmap const * nativeBitmap = 536 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 537 const SkBitmap& bitmap(*nativeBitmap); 538 SkBitmap::Config config = bitmap.getConfig(); 539 540 RsElement e = SkBitmapToPredefined(config); 541 if (e) { 542 bitmap.lockPixels(); 543 const int w = bitmap.width(); 544 const int h = bitmap.height(); 545 const void* ptr = bitmap.getPixels(); 546 jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr); 547 bitmap.unlockPixels(); 548 return id; 549 } 550 return 0; 551} 552 553static void ReleaseBitmapCallback(void *bmp) 554{ 555 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; 556 nativeBitmap->unlockPixels(); 557} 558 559static int 560nAllocationCreateBitmapRef(JNIEnv *_env, jobject _this, RsContext con, jint type, jobject jbitmap) 561{ 562 SkBitmap * nativeBitmap = 563 (SkBitmap *)_env->GetIntField(jbitmap, gNativeBitmapID); 564 565 566 nativeBitmap->lockPixels(); 567 void* ptr = nativeBitmap->getPixels(); 568 jint id = (jint)rsAllocationCreateBitmapRef(con, (RsType)type, ptr, nativeBitmap, ReleaseBitmapCallback); 569 return id; 570} 571 572static int 573nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint dstFmt, jboolean genMips, jint native_asset) 574{ 575 Asset* asset = reinterpret_cast<Asset*>(native_asset); 576 SkBitmap bitmap; 577 SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(), 578 &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode); 579 580 SkBitmap::Config config = bitmap.getConfig(); 581 582 RsElement e = SkBitmapToPredefined(config); 583 584 if (e) { 585 bitmap.lockPixels(); 586 const int w = bitmap.width(); 587 const int h = bitmap.height(); 588 const void* ptr = bitmap.getPixels(); 589 jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr); 590 bitmap.unlockPixels(); 591 return id; 592 } 593 return 0; 594} 595 596static int 597nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, RsContext con, jint dstFmt, jboolean genMips, jobject jbitmap) 598{ 599 SkBitmap const * nativeBitmap = 600 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 601 const SkBitmap& bitmap(*nativeBitmap); 602 SkBitmap::Config config = bitmap.getConfig(); 603 604 RsElement e = SkBitmapToPredefined(config); 605 606 if (e) { 607 bitmap.lockPixels(); 608 const int w = bitmap.width(); 609 const int h = bitmap.height(); 610 const void* ptr = bitmap.getPixels(); 611 jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElement)dstFmt, e, genMips, ptr); 612 bitmap.unlockPixels(); 613 return id; 614 } 615 return 0; 616} 617 618 619static void 620nAllocationSubData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint count, jintArray data, int sizeBytes) 621{ 622 jint len = _env->GetArrayLength(data); 623 LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 624 jint *ptr = _env->GetIntArrayElements(data, NULL); 625 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 626 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 627} 628 629static void 630nAllocationSubData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint count, jshortArray data, int sizeBytes) 631{ 632 jint len = _env->GetArrayLength(data); 633 LOG_API("nAllocation1DSubData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 634 jshort *ptr = _env->GetShortArrayElements(data, NULL); 635 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 636 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 637} 638 639static void 640nAllocationSubData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint count, jbyteArray data, int sizeBytes) 641{ 642 jint len = _env->GetArrayLength(data); 643 LOG_API("nAllocation1DSubData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 644 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 645 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 646 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 647} 648 649static void 650nAllocationSubData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint count, jfloatArray data, int sizeBytes) 651{ 652 jint len = _env->GetArrayLength(data); 653 LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 654 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 655 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 656 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 657} 658 659static void 660nAllocationSubData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data, int sizeBytes) 661{ 662 jint len = _env->GetArrayLength(data); 663 LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 664 jint *ptr = _env->GetIntArrayElements(data, NULL); 665 rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes); 666 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 667} 668 669static void 670nAllocationSubData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data, int sizeBytes) 671{ 672 jint len = _env->GetArrayLength(data); 673 LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 674 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 675 rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes); 676 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 677} 678 679static void 680nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data) 681{ 682 jint len = _env->GetArrayLength(data); 683 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 684 jint *ptr = _env->GetIntArrayElements(data, NULL); 685 rsAllocationRead(con, (RsAllocation)alloc, ptr); 686 _env->ReleaseIntArrayElements(data, ptr, 0); 687} 688 689static void 690nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data) 691{ 692 jint len = _env->GetArrayLength(data); 693 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 694 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 695 rsAllocationRead(con, (RsAllocation)alloc, ptr); 696 _env->ReleaseFloatArrayElements(data, ptr, 0); 697} 698 699 700//{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject }, 701static void 702nAllocationSubDataFromObject(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject _type, jint offset, jobject _o) 703{ 704 LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc); 705 706 const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); 707 708 void * bufAlloc = malloc(tc->size); 709 void * buf = bufAlloc; 710 for (int ct=0; ct < tc->fieldCount; ct++) { 711 const TypeFieldCache *tfc = &tc->fields[ct]; 712 buf = tfc->ptr(_env, _o, tfc->field, buf); 713 } 714 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, 1, bufAlloc, tc->size); 715 free(bufAlloc); 716} 717 718static void 719nAllocationSubReadFromObject(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject _type, jint offset, jobject _o) 720{ 721 LOG_API("nAllocationReadFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc); 722 723 assert(offset == 0); 724 725 const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); 726 727 void * bufAlloc = malloc(tc->size); 728 void * buf = bufAlloc; 729 rsAllocationRead(con, (RsAllocation)alloc, bufAlloc); 730 731 for (int ct=0; ct < tc->fieldCount; ct++) { 732 const TypeFieldCache *tfc = &tc->fields[ct]; 733 buf = tfc->readPtr(_env, _o, tfc->field, buf); 734 } 735 free(bufAlloc); 736} 737 738static jint 739nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a) 740{ 741 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a); 742 return (jint) rsAllocationGetType(con, (RsAllocation)a); 743} 744 745// ----------------------------------- 746 747static int 748nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset) 749{ 750 LOGV("______nFileA3D %u", (uint32_t) native_asset); 751 752 Asset* asset = reinterpret_cast<Asset*>(native_asset); 753 754 jint id = (jint)rsFileA3DCreateFromAssetStream(con, asset->getBuffer(false), asset->getLength()); 755 return id; 756} 757 758static int 759nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D) 760{ 761 int32_t numEntries = 0; 762 rsFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D); 763 return numEntries; 764} 765 766static void 767nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries) 768{ 769 LOGV("______nFileA3D %u", (uint32_t) fileA3D); 770 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); 771 772 rsFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); 773 774 for(jint i = 0; i < numEntries; i ++) { 775 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); 776 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); 777 } 778 779 free(fileEntries); 780} 781 782static int 783nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index) 784{ 785 LOGV("______nFileA3D %u", (uint32_t) fileA3D); 786 jint id = (jint)rsFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D); 787 return id; 788} 789 790// ----------------------------------- 791 792static int 793nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jint fontSize, jint dpi) 794{ 795 const char* fileNameUTF = _env->GetStringUTFChars(fileName, NULL); 796 797 jint id = (jint)rsFontCreateFromFile(con, fileNameUTF, fontSize, dpi); 798 return id; 799} 800 801 802// ----------------------------------- 803 804static void 805nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint alloc) 806{ 807 LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc); 808 rsAdapter1DBindAllocation(con, (RsAdapter1D)adapter, (RsAllocation)alloc); 809} 810 811static void 812nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint dim, jint value) 813{ 814 LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value); 815 rsAdapter1DSetConstraint(con, (RsAdapter1D)adapter, (RsDimension)dim, value); 816} 817 818static void 819nAdapter1DData_i(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jintArray data) 820{ 821 jint len = _env->GetArrayLength(data); 822 LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); 823 jint *ptr = _env->GetIntArrayElements(data, NULL); 824 rsAdapter1DData(con, (RsAdapter1D)adapter, ptr); 825 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 826} 827 828static void 829nAdapter1DSubData_i(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint offset, jint count, jintArray data) 830{ 831 jint len = _env->GetArrayLength(data); 832 LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); 833 jint *ptr = _env->GetIntArrayElements(data, NULL); 834 rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr); 835 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 836} 837 838static void 839nAdapter1DData_f(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jfloatArray data) 840{ 841 jint len = _env->GetArrayLength(data); 842 LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); 843 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 844 rsAdapter1DData(con, (RsAdapter1D)adapter, ptr); 845 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 846} 847 848static void 849nAdapter1DSubData_f(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint offset, jint count, jfloatArray data) 850{ 851 jint len = _env->GetArrayLength(data); 852 LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); 853 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 854 rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr); 855 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 856} 857 858static jint 859nAdapter1DCreate(JNIEnv *_env, jobject _this, RsContext con) 860{ 861 LOG_API("nAdapter1DCreate, con(%p)", con); 862 return (jint)rsAdapter1DCreate(con); 863} 864 865// ----------------------------------- 866 867static void 868nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint alloc) 869{ 870 LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc); 871 rsAdapter2DBindAllocation(con, (RsAdapter2D)adapter, (RsAllocation)alloc); 872} 873 874static void 875nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint dim, jint value) 876{ 877 LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value); 878 rsAdapter2DSetConstraint(con, (RsAdapter2D)adapter, (RsDimension)dim, value); 879} 880 881static void 882nAdapter2DData_i(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jintArray data) 883{ 884 jint len = _env->GetArrayLength(data); 885 LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); 886 jint *ptr = _env->GetIntArrayElements(data, NULL); 887 rsAdapter2DData(con, (RsAdapter2D)adapter, ptr); 888 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 889} 890 891static void 892nAdapter2DData_f(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jfloatArray data) 893{ 894 jint len = _env->GetArrayLength(data); 895 LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); 896 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 897 rsAdapter2DData(con, (RsAdapter2D)adapter, ptr); 898 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 899} 900 901static void 902nAdapter2DSubData_i(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data) 903{ 904 jint len = _env->GetArrayLength(data); 905 LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 906 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); 907 jint *ptr = _env->GetIntArrayElements(data, NULL); 908 rsAdapter2DSubData(con, (RsAdapter2D)adapter, xoff, yoff, w, h, ptr); 909 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 910} 911 912static void 913nAdapter2DSubData_f(JNIEnv *_env, jobject _this, RsContext con, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data) 914{ 915 jint len = _env->GetArrayLength(data); 916 LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 917 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); 918 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 919 rsAdapter2DSubData(con, (RsAdapter1D)adapter, xoff, yoff, w, h, ptr); 920 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 921} 922 923static jint 924nAdapter2DCreate(JNIEnv *_env, jobject _this, RsContext con) 925{ 926 LOG_API("nAdapter2DCreate, con(%p)", con); 927 return (jint)rsAdapter2DCreate(con); 928} 929 930// ----------------------------------- 931 932static void 933nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot) 934{ 935 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); 936 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); 937} 938 939static void 940nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 941{ 942 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i), b(%f), a(%f)", con, (void *)script, slot, val); 943 rsScriptSetVarI(con, (RsScript)script, slot, val); 944} 945 946static void 947nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val) 948{ 949 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i), b(%f), a(%f)", con, (void *)script, slot, val); 950 rsScriptSetVarF(con, (RsScript)script, slot, val); 951} 952 953static void 954nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 955{ 956 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 957 jint len = _env->GetArrayLength(data); 958 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 959 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len); 960 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 961} 962 963 964static void 965nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone) 966{ 967 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone); 968 969 jint length = _env->GetArrayLength(timeZone); 970 jbyte* timeZone_ptr; 971 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 972 973 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); 974 975 if (timeZone_ptr) { 976 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 977 } 978} 979 980static void 981nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot) 982{ 983 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); 984 rsScriptInvoke(con, (RsScript)obj, slot); 985} 986 987static void 988nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 989{ 990 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 991 jint len = _env->GetArrayLength(data); 992 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 993 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len); 994 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 995} 996 997 998// ----------------------------------- 999 1000static void 1001nScriptCBegin(JNIEnv *_env, jobject _this, RsContext con) 1002{ 1003 LOG_API("nScriptCBegin, con(%p)", con); 1004 rsScriptCBegin(con); 1005} 1006 1007static void 1008nScriptCSetScript(JNIEnv *_env, jobject _this, RsContext con, jbyteArray scriptRef, 1009 jint offset, jint length) 1010{ 1011 LOG_API("!!! nScriptCSetScript, con(%p)", con); 1012 jint _exception = 0; 1013 jint remaining; 1014 jbyte* script_base = 0; 1015 jbyte* script_ptr; 1016 if (!scriptRef) { 1017 _exception = 1; 1018 //_env->ThrowNew(IAEClass, "script == null"); 1019 goto exit; 1020 } 1021 if (offset < 0) { 1022 _exception = 1; 1023 //_env->ThrowNew(IAEClass, "offset < 0"); 1024 goto exit; 1025 } 1026 if (length < 0) { 1027 _exception = 1; 1028 //_env->ThrowNew(IAEClass, "length < 0"); 1029 goto exit; 1030 } 1031 remaining = _env->GetArrayLength(scriptRef) - offset; 1032 if (remaining < length) { 1033 _exception = 1; 1034 //_env->ThrowNew(IAEClass, "length > script.length - offset"); 1035 goto exit; 1036 } 1037 script_base = (jbyte *) 1038 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 1039 script_ptr = script_base + offset; 1040 1041 rsScriptCSetText(con, (const char *)script_ptr, length); 1042 1043exit: 1044 if (script_base) { 1045 _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, 1046 _exception ? JNI_ABORT: 0); 1047 } 1048} 1049 1050static jint 1051nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con) 1052{ 1053 LOG_API("nScriptCCreate, con(%p)", con); 1054 return (jint)rsScriptCCreate(con); 1055} 1056 1057// --------------------------------------------------------------------------- 1058 1059static void 1060nProgramStoreBegin(JNIEnv *_env, jobject _this, RsContext con, jint in, jint out) 1061{ 1062 LOG_API("nProgramStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); 1063 rsProgramStoreBegin(con, (RsElement)in, (RsElement)out); 1064} 1065 1066static void 1067nProgramStoreDepthFunc(JNIEnv *_env, jobject _this, RsContext con, jint func) 1068{ 1069 LOG_API("nProgramStoreDepthFunc, con(%p), func(%i)", con, func); 1070 rsProgramStoreDepthFunc(con, (RsDepthFunc)func); 1071} 1072 1073static void 1074nProgramStoreDepthMask(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) 1075{ 1076 LOG_API("nProgramStoreDepthMask, con(%p), enable(%i)", con, enable); 1077 rsProgramStoreDepthMask(con, enable); 1078} 1079 1080static void 1081nProgramStoreColorMask(JNIEnv *_env, jobject _this, RsContext con, jboolean r, jboolean g, jboolean b, jboolean a) 1082{ 1083 LOG_API("nProgramStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); 1084 rsProgramStoreColorMask(con, r, g, b, a); 1085} 1086 1087static void 1088nProgramStoreBlendFunc(JNIEnv *_env, jobject _this, RsContext con, int src, int dst) 1089{ 1090 LOG_API("nProgramStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); 1091 rsProgramStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst); 1092} 1093 1094static void 1095nProgramStoreDither(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) 1096{ 1097 LOG_API("nProgramStoreDither, con(%p), enable(%i)", con, enable); 1098 rsProgramStoreDither(con, enable); 1099} 1100 1101static jint 1102nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con) 1103{ 1104 LOG_API("nProgramStoreCreate, con(%p)", con); 1105 return (jint)rsProgramStoreCreate(con); 1106} 1107 1108// --------------------------------------------------------------------------- 1109 1110static void 1111nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a) 1112{ 1113 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a); 1114 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a); 1115} 1116 1117static void 1118nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a) 1119{ 1120 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 1121 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 1122} 1123 1124static void 1125nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a) 1126{ 1127 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); 1128 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a); 1129} 1130 1131// --------------------------------------------------------------------------- 1132 1133static jint 1134nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray params) 1135{ 1136 jint *paramPtr = _env->GetIntArrayElements(params, NULL); 1137 jint paramLen = _env->GetArrayLength(params); 1138 1139 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen); 1140 1141 jint ret = (jint)rsProgramFragmentCreate(con, (uint32_t *)paramPtr, paramLen); 1142 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); 1143 return ret; 1144} 1145 1146static jint 1147nProgramFragmentCreate2(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) 1148{ 1149 const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); 1150 jint shaderLen = _env->GetStringUTFLength(shader); 1151 jint *paramPtr = _env->GetIntArrayElements(params, NULL); 1152 jint paramLen = _env->GetArrayLength(params); 1153 1154 LOG_API("nProgramFragmentCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); 1155 1156 jint ret = (jint)rsProgramFragmentCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); 1157 _env->ReleaseStringUTFChars(shader, shaderUTF); 1158 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); 1159 return ret; 1160} 1161 1162 1163// --------------------------------------------------------------------------- 1164 1165static jint 1166nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean texMat) 1167{ 1168 LOG_API("nProgramVertexCreate, con(%p), texMat(%i)", con, texMat); 1169 return (jint)rsProgramVertexCreate(con, texMat); 1170} 1171 1172static jint 1173nProgramVertexCreate2(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) 1174{ 1175 const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); 1176 jint shaderLen = _env->GetStringUTFLength(shader); 1177 jint *paramPtr = _env->GetIntArrayElements(params, NULL); 1178 jint paramLen = _env->GetArrayLength(params); 1179 1180 LOG_API("nProgramVertexCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); 1181 1182 jint ret = (jint)rsProgramVertexCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); 1183 _env->ReleaseStringUTFChars(shader, shaderUTF); 1184 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); 1185 return ret; 1186} 1187 1188// --------------------------------------------------------------------------- 1189 1190static jint 1191nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite) 1192{ 1193 LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)", 1194 con, pointSmooth, lineSmooth, pointSprite); 1195 return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite); 1196} 1197 1198static void 1199nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jfloat v) 1200{ 1201 LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); 1202 rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v); 1203} 1204 1205static void 1206nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jint v) 1207{ 1208 LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v); 1209 rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v); 1210} 1211 1212 1213// --------------------------------------------------------------------------- 1214 1215static void 1216nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script) 1217{ 1218 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script); 1219 rsContextBindRootScript(con, (RsScript)script); 1220} 1221 1222static void 1223nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs) 1224{ 1225 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs); 1226 rsContextBindProgramStore(con, (RsProgramStore)pfs); 1227} 1228 1229static void 1230nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf) 1231{ 1232 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf); 1233 rsContextBindProgramFragment(con, (RsProgramFragment)pf); 1234} 1235 1236static void 1237nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf) 1238{ 1239 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf); 1240 rsContextBindProgramVertex(con, (RsProgramVertex)pf); 1241} 1242 1243static void 1244nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf) 1245{ 1246 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf); 1247 rsContextBindProgramRaster(con, (RsProgramRaster)pf); 1248} 1249 1250 1251// --------------------------------------------------------------------------- 1252 1253static void 1254nSamplerBegin(JNIEnv *_env, jobject _this, RsContext con) 1255{ 1256 LOG_API("nSamplerBegin, con(%p)", con); 1257 rsSamplerBegin(con); 1258} 1259 1260static void 1261nSamplerSet(JNIEnv *_env, jobject _this, RsContext con, jint p, jint v) 1262{ 1263 LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v); 1264 rsSamplerSet(con, (RsSamplerParam)p, (RsSamplerValue)v); 1265} 1266 1267static jint 1268nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con) 1269{ 1270 LOG_API("nSamplerCreate, con(%p)", con); 1271 return (jint)rsSamplerCreate(con); 1272} 1273 1274// --------------------------------------------------------------------------- 1275 1276static jint 1277nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jint vtxCount, jint idxCount) 1278{ 1279 LOG_API("nMeshCreate, con(%p), vtxCount(%i), idxCount(%i)", con, vtxCount, idxCount); 1280 int id = (int)rsMeshCreate(con, vtxCount, idxCount); 1281 return id; 1282} 1283 1284static void 1285nMeshBindVertex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint slot) 1286{ 1287 LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)mesh, (RsAllocation)alloc, slot); 1288 rsMeshBindVertex(con, (RsMesh)mesh, (RsAllocation)alloc, slot); 1289} 1290 1291static void 1292nMeshBindIndex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint primID, jint slot) 1293{ 1294 LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)mesh, (RsAllocation)alloc); 1295 rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot); 1296} 1297 1298static jint 1299nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh) 1300{ 1301 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1302 jint vtxCount = 0; 1303 rsMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount); 1304 return vtxCount; 1305} 1306 1307static jint 1308nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh) 1309{ 1310 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1311 jint idxCount = 0; 1312 rsMeshGetIndexCount(con, (RsMesh)mesh, &idxCount); 1313 return idxCount; 1314} 1315 1316static void 1317nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs) 1318{ 1319 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1320 1321 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); 1322 rsMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); 1323 1324 for(jint i = 0; i < numVtxIDs; i ++) { 1325 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]); 1326 } 1327 1328 free(allocs); 1329} 1330 1331static void 1332nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices) 1333{ 1334 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1335 1336 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); 1337 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); 1338 1339 rsMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); 1340 1341 for(jint i = 0; i < numIndices; i ++) { 1342 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]); 1343 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]); 1344 } 1345 1346 free(allocs); 1347 free(prims); 1348} 1349 1350// --------------------------------------------------------------------------- 1351 1352 1353static const char *classPathName = "android/renderscript/RenderScript"; 1354 1355static JNINativeMethod methods[] = { 1356{"_nInit", "()V", (void*)_nInit }, 1357{"nInitElements", "(IIII)V", (void*)nInitElements }, 1358 1359{"nDeviceCreate", "()I", (void*)nDeviceCreate }, 1360{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, 1361{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, 1362{"nContextGetMessage", "(I[IZ)I", (void*)nContextGetMessage }, 1363{"nContextInitToClient", "(I)V", (void*)nContextInitToClient }, 1364{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient }, 1365 1366 1367// All methods below are thread protected in java. 1368{"rsnContextCreate", "(II)I", (void*)nContextCreate }, 1369{"rsnContextCreateGL", "(IIZ)I", (void*)nContextCreateGL }, 1370{"rsnContextFinish", "(I)V", (void*)nContextFinish }, 1371{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority }, 1372{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface }, 1373{"rsnContextDestroy", "(I)V", (void*)nContextDestroy }, 1374{"rsnContextDump", "(II)V", (void*)nContextDump }, 1375{"rsnContextPause", "(I)V", (void*)nContextPause }, 1376{"rsnContextResume", "(I)V", (void*)nContextResume }, 1377{"rsnAssignName", "(II[B)V", (void*)nAssignName }, 1378{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName }, 1379{"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, 1380{"rsnObjDestroyOOB", "(II)V", (void*)nObjDestroyOOB }, 1381 1382{"rsnFileOpen", "(I[B)I", (void*)nFileOpen }, 1383{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream }, 1384{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries }, 1385{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, 1386{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex }, 1387 1388{"rsnFontCreateFromFile", "(ILjava/lang/String;II)I", (void*)nFontCreateFromFile }, 1389 1390{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, 1391{"rsnElementCreate2", "(I[I[Ljava/lang/String;)I", (void*)nElementCreate2 }, 1392{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData }, 1393{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements }, 1394 1395{"rsnTypeBegin", "(II)V", (void*)nTypeBegin }, 1396{"rsnTypeAdd", "(III)V", (void*)nTypeAdd }, 1397{"rsnTypeCreate", "(I)I", (void*)nTypeCreate }, 1398{"rsnTypeFinalDestroy", "(ILandroid/renderscript/Type;)V", (void*)nTypeFinalDestroy }, 1399{"rsnTypeSetupFields", "(ILandroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields }, 1400{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData }, 1401 1402{"rsnAllocationCreateTyped", "(II)I", (void*)nAllocationCreateTyped }, 1403{"rsnAllocationCreateFromBitmap", "(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, 1404{"rsnAllocationCreateBitmapRef", "(IILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef }, 1405{"rsnAllocationCreateFromBitmapBoxed","(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed }, 1406{"rsnAllocationCreateFromAssetStream","(IIZI)I", (void*)nAllocationCreateFromAssetStream }, 1407{"rsnAllocationUploadToTexture", "(IIZI)V", (void*)nAllocationUploadToTexture }, 1408{"rsnAllocationUploadToBufferObject","(II)V", (void*)nAllocationUploadToBufferObject }, 1409{"rsnAllocationSubData1D", "(IIII[II)V", (void*)nAllocationSubData1D_i }, 1410{"rsnAllocationSubData1D", "(IIII[SI)V", (void*)nAllocationSubData1D_s }, 1411{"rsnAllocationSubData1D", "(IIII[BI)V", (void*)nAllocationSubData1D_b }, 1412{"rsnAllocationSubData1D", "(IIII[FI)V", (void*)nAllocationSubData1D_f }, 1413{"rsnAllocationSubData2D", "(IIIIII[II)V", (void*)nAllocationSubData2D_i }, 1414{"rsnAllocationSubData2D", "(IIIIII[FI)V", (void*)nAllocationSubData2D_f }, 1415{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i }, 1416{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f }, 1417{"rsnAllocationSubDataFromObject", "(IILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject }, 1418{"rsnAllocationSubReadFromObject", "(IILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubReadFromObject }, 1419{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType}, 1420 1421{"rsnAdapter1DBindAllocation", "(III)V", (void*)nAdapter1DBindAllocation }, 1422{"rsnAdapter1DSetConstraint", "(IIII)V", (void*)nAdapter1DSetConstraint }, 1423{"rsnAdapter1DData", "(II[I)V", (void*)nAdapter1DData_i }, 1424{"rsnAdapter1DData", "(II[F)V", (void*)nAdapter1DData_f }, 1425{"rsnAdapter1DSubData", "(IIII[I)V", (void*)nAdapter1DSubData_i }, 1426{"rsnAdapter1DSubData", "(IIII[F)V", (void*)nAdapter1DSubData_f }, 1427{"rsnAdapter1DCreate", "(I)I", (void*)nAdapter1DCreate }, 1428 1429{"rsnAdapter2DBindAllocation", "(III)V", (void*)nAdapter2DBindAllocation }, 1430{"rsnAdapter2DSetConstraint", "(IIII)V", (void*)nAdapter2DSetConstraint }, 1431{"rsnAdapter2DData", "(II[I)V", (void*)nAdapter2DData_i }, 1432{"rsnAdapter2DData", "(II[F)V", (void*)nAdapter2DData_f }, 1433{"rsnAdapter2DSubData", "(IIIIII[I)V", (void*)nAdapter2DSubData_i }, 1434{"rsnAdapter2DSubData", "(IIIIII[F)V", (void*)nAdapter2DSubData_f }, 1435{"rsnAdapter2DCreate", "(I)I", (void*)nAdapter2DCreate }, 1436 1437{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation }, 1438{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone }, 1439{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke }, 1440{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV }, 1441{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI }, 1442{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF }, 1443{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, 1444 1445{"rsnScriptCBegin", "(I)V", (void*)nScriptCBegin }, 1446{"rsnScriptCSetScript", "(I[BII)V", (void*)nScriptCSetScript }, 1447{"rsnScriptCCreate", "(I)I", (void*)nScriptCCreate }, 1448 1449{"rsnProgramStoreBegin", "(III)V", (void*)nProgramStoreBegin }, 1450{"rsnProgramStoreDepthFunc", "(II)V", (void*)nProgramStoreDepthFunc }, 1451{"rsnProgramStoreDepthMask", "(IZ)V", (void*)nProgramStoreDepthMask }, 1452{"rsnProgramStoreColorMask", "(IZZZZ)V", (void*)nProgramStoreColorMask }, 1453{"rsnProgramStoreBlendFunc", "(III)V", (void*)nProgramStoreBlendFunc }, 1454{"rsnProgramStoreDither", "(IZ)V", (void*)nProgramStoreDither }, 1455{"rsnProgramStoreCreate", "(I)I", (void*)nProgramStoreCreate }, 1456 1457{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants }, 1458{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture }, 1459{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler }, 1460 1461{"rsnProgramFragmentCreate", "(I[I)I", (void*)nProgramFragmentCreate }, 1462{"rsnProgramFragmentCreate2", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate2 }, 1463 1464{"rsnProgramRasterCreate", "(IZZZ)I", (void*)nProgramRasterCreate }, 1465{"rsnProgramRasterSetLineWidth", "(IIF)V", (void*)nProgramRasterSetLineWidth }, 1466{"rsnProgramRasterSetCullMode", "(III)V", (void*)nProgramRasterSetCullMode }, 1467 1468{"rsnProgramVertexCreate", "(IZ)I", (void*)nProgramVertexCreate }, 1469{"rsnProgramVertexCreate2", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate2 }, 1470 1471{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript }, 1472{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore }, 1473{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment }, 1474{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex }, 1475{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster }, 1476 1477{"rsnSamplerBegin", "(I)V", (void*)nSamplerBegin }, 1478{"rsnSamplerSet", "(III)V", (void*)nSamplerSet }, 1479{"rsnSamplerCreate", "(I)I", (void*)nSamplerCreate }, 1480 1481{"rsnMeshCreate", "(III)I", (void*)nMeshCreate }, 1482{"rsnMeshBindVertex", "(IIII)V", (void*)nMeshBindVertex }, 1483{"rsnMeshBindIndex", "(IIIII)V", (void*)nMeshBindIndex }, 1484 1485{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount }, 1486{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount }, 1487{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices }, 1488{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices }, 1489 1490}; 1491 1492static int registerFuncs(JNIEnv *_env) 1493{ 1494 return android::AndroidRuntime::registerNativeMethods( 1495 _env, classPathName, methods, NELEM(methods)); 1496} 1497 1498// --------------------------------------------------------------------------- 1499 1500jint JNI_OnLoad(JavaVM* vm, void* reserved) 1501{ 1502 JNIEnv* env = NULL; 1503 jint result = -1; 1504 1505 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1506 LOGE("ERROR: GetEnv failed\n"); 1507 goto bail; 1508 } 1509 assert(env != NULL); 1510 1511 if (registerFuncs(env) < 0) { 1512 LOGE("ERROR: MediaPlayer native registration failed\n"); 1513 goto bail; 1514 } 1515 1516 /* success -- return valid version number */ 1517 result = JNI_VERSION_1_4; 1518 1519bail: 1520 return result; 1521} 1522 1523