android_renderscript_RenderScript.cpp revision 516c31911578db8ce53529483c3ded918ac7dc6b
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 <ui/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 88nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str) 89{ 90 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 91 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj); 92 93 jint len = _env->GetArrayLength(str); 94 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 95 rsAssignName(con, (void *)obj, (const char *)cptr, len); 96 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 97} 98 99static void 100nObjDestroy(JNIEnv *_env, jobject _this, jint obj) 101{ 102 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 103 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); 104 rsObjDestroy(con, (void *)obj); 105} 106 107static void 108nObjDestroyOOB(JNIEnv *_env, jobject _this, jint obj) 109{ 110 // This function only differs from nObjDestroy in that it calls the 111 // special Out Of Band version of ObjDestroy which is thread safe. 112 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 113 LOG_API("nObjDestroyOOB, con(%p) obj(%p)", con, (void *)obj); 114 rsObjDestroyOOB(con, (void *)obj); 115} 116 117static jint 118nFileOpen(JNIEnv *_env, jobject _this, jbyteArray str) 119{ 120 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 121 LOG_API("nFileOpen, con(%p)", con); 122 123 jint len = _env->GetArrayLength(str); 124 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 125 jint ret = (jint)rsFileOpen(con, (const char *)cptr, len); 126 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 127 return ret; 128} 129 130// --------------------------------------------------------------------------- 131 132static jint 133nDeviceCreate(JNIEnv *_env, jobject _this) 134{ 135 LOG_API("nDeviceCreate"); 136 return (jint)rsDeviceCreate(); 137} 138 139static void 140nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 141{ 142 LOG_API("nDeviceDestroy"); 143 return rsDeviceDestroy((RsDevice)dev); 144} 145 146static void 147nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) 148{ 149 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 150 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 151} 152 153static jint 154nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver, jboolean useDepth) 155{ 156 LOG_API("nContextCreate"); 157 158 if (wnd == NULL) { 159 not_valid_surface: 160 doThrow(_env, "java/lang/IllegalArgumentException", 161 "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"); 162 return 0; 163 } 164 jclass surface_class = _env->FindClass("android/view/Surface"); 165 jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I"); 166 Surface * window = (Surface*)_env->GetIntField(wnd, surfaceFieldID); 167 if (window == NULL) 168 goto not_valid_surface; 169 170 return (jint)rsContextCreate((RsDevice)dev, window, ver, useDepth); 171} 172 173static void 174nContextDestroy(JNIEnv *_env, jobject _this, jint con) 175{ 176 LOG_API("nContextDestroy, con(%p)", (RsContext)con); 177 return rsContextDestroy((RsContext)con); 178} 179 180 181static void 182nContextPause(JNIEnv *_env, jobject _this) 183{ 184 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 185 LOG_API("nContextPause, con(%p)", con); 186 rsContextPause(con); 187} 188 189static void 190nContextResume(JNIEnv *_env, jobject _this) 191{ 192 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 193 LOG_API("nContextResume, con(%p)", con); 194 rsContextResume(con); 195} 196 197static jint 198nContextGetMessage(JNIEnv *_env, jobject _this, jintArray data, jboolean wait) 199{ 200 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 201 jint len = _env->GetArrayLength(data); 202 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); 203 jint *ptr = _env->GetIntArrayElements(data, NULL); 204 size_t receiveLen; 205 int id = rsContextGetMessage(con, ptr, &receiveLen, len * 4, wait); 206 if (!id && receiveLen) { 207 LOGE("message receive buffer too small. %i", receiveLen); 208 } 209 _env->ReleaseIntArrayElements(data, ptr, 0); 210 return id; 211} 212 213static void nContextInitToClient(JNIEnv *_env, jobject _this) 214{ 215 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 216 LOG_API("nContextInitToClient, con(%p)", con); 217 rsContextInitToClient(con); 218} 219 220static void nContextDeinitToClient(JNIEnv *_env, jobject _this) 221{ 222 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 223 LOG_API("nContextDeinitToClient, con(%p)", con); 224 rsContextDeinitToClient(con); 225} 226 227 228static void 229nElementBegin(JNIEnv *_env, jobject _this) 230{ 231 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 232 LOG_API("nElementBegin, con(%p)", con); 233 rsElementBegin(con); 234} 235 236 237static void 238nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jboolean norm, jint bits, jstring name) 239{ 240 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 241 const char* n = NULL; 242 if (name) { 243 n = _env->GetStringUTFChars(name, NULL); 244 } 245 LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits); 246 rsElementAdd(con, (RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits, n); 247 if (n) { 248 _env->ReleaseStringUTFChars(name, n); 249 } 250} 251 252static jint 253nElementCreate(JNIEnv *_env, jobject _this) 254{ 255 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 256 LOG_API("nElementCreate, con(%p)", con); 257 return (jint)rsElementCreate(con); 258} 259 260// ----------------------------------- 261 262static void 263nTypeBegin(JNIEnv *_env, jobject _this, jint eID) 264{ 265 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 266 LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID); 267 rsTypeBegin(con, (RsElement)eID); 268} 269 270static void 271nTypeAdd(JNIEnv *_env, jobject _this, jint dim, jint val) 272{ 273 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 274 LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val); 275 rsTypeAdd(con, (RsDimension)dim, val); 276} 277 278static jint 279nTypeCreate(JNIEnv *_env, jobject _this) 280{ 281 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 282 LOG_API("nTypeCreate, con(%p)", con); 283 return (jint)rsTypeCreate(con); 284} 285 286static void * SF_LoadInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 287{ 288 ((int32_t *)buffer)[0] = _env->GetIntField(_obj, _field); 289 return ((uint8_t *)buffer) + 4; 290} 291 292static void * SF_LoadShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 293{ 294 ((int16_t *)buffer)[0] = _env->GetShortField(_obj, _field); 295 return ((uint8_t *)buffer) + 2; 296} 297 298static void * SF_LoadByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 299{ 300 ((int8_t *)buffer)[0] = _env->GetByteField(_obj, _field); 301 return ((uint8_t *)buffer) + 1; 302} 303 304static void * SF_LoadFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 305{ 306 ((float *)buffer)[0] = _env->GetFloatField(_obj, _field); 307 return ((uint8_t *)buffer) + 4; 308} 309 310static void * SF_SaveInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 311{ 312 _env->SetIntField(_obj, _field, ((int32_t *)buffer)[0]); 313 return ((uint8_t *)buffer) + 4; 314} 315 316static void * SF_SaveShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 317{ 318 _env->SetShortField(_obj, _field, ((int16_t *)buffer)[0]); 319 return ((uint8_t *)buffer) + 2; 320} 321 322static void * SF_SaveByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 323{ 324 _env->SetByteField(_obj, _field, ((int8_t *)buffer)[0]); 325 return ((uint8_t *)buffer) + 1; 326} 327 328static void * SF_SaveFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer) 329{ 330 _env->SetFloatField(_obj, _field, ((float *)buffer)[0]); 331 return ((uint8_t *)buffer) + 4; 332} 333 334struct TypeFieldCache { 335 jfieldID field; 336 int bits; 337 void * (*ptr)(JNIEnv *, jobject, jfieldID, void *buffer); 338 void * (*readPtr)(JNIEnv *, jobject, jfieldID, void *buffer); 339}; 340 341struct TypeCache { 342 int fieldCount; 343 int size; 344 TypeFieldCache fields[1]; 345}; 346 347//{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy }, 348static void 349nTypeFinalDestroy(JNIEnv *_env, jobject _this, jobject _type) 350{ 351 TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); 352 free(tc); 353} 354 355// native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs); 356static void 357nTypeSetupFields(JNIEnv *_env, jobject _this, jobject _type, jintArray _types, jintArray _bits, jobjectArray _IDs) 358{ 359 int fieldCount = _env->GetArrayLength(_types); 360 size_t structSize = sizeof(TypeCache) + (sizeof(TypeFieldCache) * (fieldCount-1)); 361 TypeCache *tc = (TypeCache *)malloc(structSize); 362 memset(tc, 0, structSize); 363 364 TypeFieldCache *tfc = &tc->fields[0]; 365 tc->fieldCount = fieldCount; 366 _env->SetIntField(_type, gTypeNativeCache, (jint)tc); 367 368 jint *fType = _env->GetIntArrayElements(_types, NULL); 369 jint *fBits = _env->GetIntArrayElements(_bits, NULL); 370 for (int ct=0; ct < fieldCount; ct++) { 371 jobject field = _env->GetObjectArrayElement(_IDs, ct); 372 tfc[ct].field = _env->FromReflectedField(field); 373 tfc[ct].bits = fBits[ct]; 374 375 switch(fType[ct]) { 376 case RS_TYPE_FLOAT: 377 tfc[ct].ptr = SF_LoadFloat; 378 tfc[ct].readPtr = SF_SaveFloat; 379 break; 380 case RS_TYPE_UNSIGNED: 381 case RS_TYPE_SIGNED: 382 switch(tfc[ct].bits) { 383 case 32: 384 tfc[ct].ptr = SF_LoadInt; 385 tfc[ct].readPtr = SF_SaveInt; 386 break; 387 case 16: 388 tfc[ct].ptr = SF_LoadShort; 389 tfc[ct].readPtr = SF_SaveShort; 390 break; 391 case 8: 392 tfc[ct].ptr = SF_LoadByte; 393 tfc[ct].readPtr = SF_SaveByte; 394 break; 395 } 396 break; 397 } 398 tc->size += 4; 399 } 400 401 _env->ReleaseIntArrayElements(_types, fType, JNI_ABORT); 402 _env->ReleaseIntArrayElements(_bits, fBits, JNI_ABORT); 403} 404 405 406// ----------------------------------- 407 408static jint 409nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e) 410{ 411 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 412 LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e); 413 return (jint) rsAllocationCreateTyped(con, (RsElement)e); 414} 415 416static void 417nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip) 418{ 419 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 420 LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip); 421 rsAllocationUploadToTexture(con, (RsAllocation)a, mip); 422} 423 424static void 425nAllocationUploadToBufferObject(JNIEnv *_env, jobject _this, jint a) 426{ 427 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 428 LOG_API("nAllocationUploadToBufferObject, con(%p), a(%p)", con, (RsAllocation)a); 429 rsAllocationUploadToBufferObject(con, (RsAllocation)a); 430} 431 432static RsElement SkBitmapToPredefined(SkBitmap::Config cfg) 433{ 434 switch (cfg) { 435 case SkBitmap::kA8_Config: 436 return g_A_8; 437 case SkBitmap::kARGB_4444_Config: 438 return g_RGBA_4444; 439 case SkBitmap::kARGB_8888_Config: 440 return g_RGBA_8888; 441 case SkBitmap::kRGB_565_Config: 442 return g_RGB_565; 443 444 default: 445 break; 446 } 447 // If we don't have a conversion mark it as a user type. 448 LOGE("Unsupported bitmap type"); 449 return NULL; 450} 451 452static int 453nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) 454{ 455 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 456 SkBitmap const * nativeBitmap = 457 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 458 const SkBitmap& bitmap(*nativeBitmap); 459 SkBitmap::Config config = bitmap.getConfig(); 460 461 RsElement e = SkBitmapToPredefined(config); 462 if (e) { 463 bitmap.lockPixels(); 464 const int w = bitmap.width(); 465 const int h = bitmap.height(); 466 const void* ptr = bitmap.getPixels(); 467 jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr); 468 bitmap.unlockPixels(); 469 return id; 470 } 471 return 0; 472} 473 474static int 475nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset) 476{ 477 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 478 479 Asset* asset = reinterpret_cast<Asset*>(native_asset); 480 SkBitmap bitmap; 481 SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(), 482 &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode); 483 484 SkBitmap::Config config = bitmap.getConfig(); 485 486 RsElement e = SkBitmapToPredefined(config); 487 488 if (e) { 489 bitmap.lockPixels(); 490 const int w = bitmap.width(); 491 const int h = bitmap.height(); 492 const void* ptr = bitmap.getPixels(); 493 jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr); 494 bitmap.unlockPixels(); 495 return id; 496 } 497 return 0; 498} 499 500static int 501nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) 502{ 503 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 504 SkBitmap const * nativeBitmap = 505 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 506 const SkBitmap& bitmap(*nativeBitmap); 507 SkBitmap::Config config = bitmap.getConfig(); 508 509 RsElement e = SkBitmapToPredefined(config); 510 511 if (e) { 512 bitmap.lockPixels(); 513 const int w = bitmap.width(); 514 const int h = bitmap.height(); 515 const void* ptr = bitmap.getPixels(); 516 jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElement)dstFmt, e, genMips, ptr); 517 bitmap.unlockPixels(); 518 return id; 519 } 520 return 0; 521} 522 523 524static void 525nAllocationSubData1D_i(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jintArray data, int sizeBytes) 526{ 527 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 528 jint len = _env->GetArrayLength(data); 529 LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 530 jint *ptr = _env->GetIntArrayElements(data, NULL); 531 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 532 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 533} 534 535static void 536nAllocationSubData1D_s(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jshortArray data, int sizeBytes) 537{ 538 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 539 jint len = _env->GetArrayLength(data); 540 LOG_API("nAllocation1DSubData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 541 jshort *ptr = _env->GetShortArrayElements(data, NULL); 542 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 543 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 544} 545 546static void 547nAllocationSubData1D_b(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jbyteArray data, int sizeBytes) 548{ 549 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 550 jint len = _env->GetArrayLength(data); 551 LOG_API("nAllocation1DSubData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 552 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 553 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 554 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 555} 556 557static void 558nAllocationSubData1D_f(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jfloatArray data, int sizeBytes) 559{ 560 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 561 jint len = _env->GetArrayLength(data); 562 LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 563 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 564 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes); 565 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 566} 567 568static void 569nAllocationSubData2D_i(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data, int sizeBytes) 570{ 571 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 572 jint len = _env->GetArrayLength(data); 573 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); 574 jint *ptr = _env->GetIntArrayElements(data, NULL); 575 rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes); 576 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 577} 578 579static void 580nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data, int sizeBytes) 581{ 582 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 583 jint len = _env->GetArrayLength(data); 584 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); 585 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 586 rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes); 587 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 588} 589 590static void 591nAllocationRead_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data) 592{ 593 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 594 jint len = _env->GetArrayLength(data); 595 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 596 jint *ptr = _env->GetIntArrayElements(data, NULL); 597 rsAllocationRead(con, (RsAllocation)alloc, ptr); 598 _env->ReleaseIntArrayElements(data, ptr, 0); 599} 600 601static void 602nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data) 603{ 604 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 605 jint len = _env->GetArrayLength(data); 606 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 607 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 608 rsAllocationRead(con, (RsAllocation)alloc, ptr); 609 _env->ReleaseFloatArrayElements(data, ptr, 0); 610} 611 612 613//{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject }, 614static void 615nAllocationSubDataFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jint offset, jobject _o) 616{ 617 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 618 LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc); 619 620 const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); 621 622 void * bufAlloc = malloc(tc->size); 623 void * buf = bufAlloc; 624 for (int ct=0; ct < tc->fieldCount; ct++) { 625 const TypeFieldCache *tfc = &tc->fields[ct]; 626 buf = tfc->ptr(_env, _o, tfc->field, buf); 627 } 628 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, 1, bufAlloc, tc->size); 629 free(bufAlloc); 630} 631 632static void 633nAllocationSubReadFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jint offset, jobject _o) 634{ 635 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 636 LOG_API("nAllocationReadFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc); 637 638 assert(offset == 0); 639 640 const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache); 641 642 void * bufAlloc = malloc(tc->size); 643 void * buf = bufAlloc; 644 rsAllocationRead(con, (RsAllocation)alloc, bufAlloc); 645 646 for (int ct=0; ct < tc->fieldCount; ct++) { 647 const TypeFieldCache *tfc = &tc->fields[ct]; 648 buf = tfc->readPtr(_env, _o, tfc->field, buf); 649 } 650 free(bufAlloc); 651} 652 653 654// ----------------------------------- 655 656static void 657nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) 658{ 659 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 660 LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc); 661 rsAdapter1DBindAllocation(con, (RsAdapter1D)adapter, (RsAllocation)alloc); 662} 663 664static void 665nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) 666{ 667 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 668 LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value); 669 rsAdapter1DSetConstraint(con, (RsAdapter1D)adapter, (RsDimension)dim, value); 670} 671 672static void 673nAdapter1DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) 674{ 675 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 676 jint len = _env->GetArrayLength(data); 677 LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); 678 jint *ptr = _env->GetIntArrayElements(data, NULL); 679 rsAdapter1DData(con, (RsAdapter1D)adapter, ptr); 680 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 681} 682 683static void 684nAdapter1DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jintArray data) 685{ 686 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 687 jint len = _env->GetArrayLength(data); 688 LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); 689 jint *ptr = _env->GetIntArrayElements(data, NULL); 690 rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr); 691 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 692} 693 694static void 695nAdapter1DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) 696{ 697 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 698 jint len = _env->GetArrayLength(data); 699 LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); 700 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 701 rsAdapter1DData(con, (RsAdapter1D)adapter, ptr); 702 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 703} 704 705static void 706nAdapter1DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jfloatArray data) 707{ 708 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 709 jint len = _env->GetArrayLength(data); 710 LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); 711 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 712 rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr); 713 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 714} 715 716static jint 717nAdapter1DCreate(JNIEnv *_env, jobject _this) 718{ 719 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 720 LOG_API("nAdapter1DCreate, con(%p)", con); 721 return (jint)rsAdapter1DCreate(con); 722} 723 724// ----------------------------------- 725 726static void 727nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) 728{ 729 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 730 LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc); 731 rsAdapter2DBindAllocation(con, (RsAdapter2D)adapter, (RsAllocation)alloc); 732} 733 734static void 735nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) 736{ 737 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 738 LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value); 739 rsAdapter2DSetConstraint(con, (RsAdapter2D)adapter, (RsDimension)dim, value); 740} 741 742static void 743nAdapter2DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) 744{ 745 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 746 jint len = _env->GetArrayLength(data); 747 LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); 748 jint *ptr = _env->GetIntArrayElements(data, NULL); 749 rsAdapter2DData(con, (RsAdapter2D)adapter, ptr); 750 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 751} 752 753static void 754nAdapter2DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) 755{ 756 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 757 jint len = _env->GetArrayLength(data); 758 LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); 759 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 760 rsAdapter2DData(con, (RsAdapter2D)adapter, ptr); 761 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 762} 763 764static void 765nAdapter2DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data) 766{ 767 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 768 jint len = _env->GetArrayLength(data); 769 LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 770 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); 771 jint *ptr = _env->GetIntArrayElements(data, NULL); 772 rsAdapter2DSubData(con, (RsAdapter2D)adapter, xoff, yoff, w, h, ptr); 773 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 774} 775 776static void 777nAdapter2DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data) 778{ 779 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 780 jint len = _env->GetArrayLength(data); 781 LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", 782 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); 783 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 784 rsAdapter2DSubData(con, (RsAdapter1D)adapter, xoff, yoff, w, h, ptr); 785 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 786} 787 788static jint 789nAdapter2DCreate(JNIEnv *_env, jobject _this) 790{ 791 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 792 LOG_API("nAdapter2DCreate, con(%p)", con); 793 return (jint)rsAdapter2DCreate(con); 794} 795 796// ----------------------------------- 797 798static void 799nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint slot) 800{ 801 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 802 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); 803 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); 804} 805 806static void 807nScriptSetClearColor(JNIEnv *_env, jobject _this, jint script, jfloat r, jfloat g, jfloat b, jfloat a) 808{ 809 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 810 LOG_API("nScriptSetClearColor, con(%p), s(%p), r(%f), g(%f), b(%f), a(%f)", con, (void *)script, r, g, b, a); 811 rsScriptSetClearColor(con, (RsScript)script, r, g, b, a); 812} 813 814static void 815nScriptSetClearDepth(JNIEnv *_env, jobject _this, jint script, jfloat d) 816{ 817 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 818 LOG_API("nScriptCSetClearDepth, con(%p), s(%p), depth(%f)", con, (void *)script, d); 819 rsScriptSetClearDepth(con, (RsScript)script, d); 820} 821 822static void 823nScriptSetClearStencil(JNIEnv *_env, jobject _this, jint script, jint stencil) 824{ 825 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 826 LOG_API("nScriptCSetClearStencil, con(%p), s(%p), stencil(%i)", con, (void *)script, stencil); 827 rsScriptSetClearStencil(con, (RsScript)script, stencil); 828} 829 830static void 831nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone) 832{ 833 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 834 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone); 835 836 jint length = _env->GetArrayLength(timeZone); 837 jbyte* timeZone_ptr; 838 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 839 840 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); 841 842 if (timeZone_ptr) { 843 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 844 } 845} 846 847static void 848nScriptSetType(JNIEnv *_env, jobject _this, jint type, jboolean writable, jstring _str, jint slot) 849{ 850 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 851 LOG_API("nScriptCAddType, con(%p), type(%p), writable(%i), slot(%i)", con, (RsType)type, writable, slot); 852 const char* n = NULL; 853 if (_str) { 854 n = _env->GetStringUTFChars(_str, NULL); 855 } 856 rsScriptSetType(con, (RsType)type, slot, writable, n); 857 if (n) { 858 _env->ReleaseStringUTFChars(_str, n); 859 } 860} 861 862static void 863nScriptSetInvoke(JNIEnv *_env, jobject _this, jstring _str, jint slot) 864{ 865 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 866 LOG_API("nScriptSetInvoke, con(%p)", con); 867 const char* n = NULL; 868 if (_str) { 869 n = _env->GetStringUTFChars(_str, NULL); 870 } 871 rsScriptSetInvoke(con, n, slot); 872 if (n) { 873 _env->ReleaseStringUTFChars(_str, n); 874 } 875} 876 877static void 878nScriptInvoke(JNIEnv *_env, jobject _this, jint obj, jint slot) 879{ 880 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 881 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); 882 rsScriptInvoke(con, (RsScript)obj, slot); 883} 884 885static void 886nScriptSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot) 887{ 888 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 889 LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot); 890 rsScriptSetRoot(con, isRoot); 891} 892 893// ----------------------------------- 894 895static void 896nScriptCBegin(JNIEnv *_env, jobject _this) 897{ 898 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 899 LOG_API("nScriptCBegin, con(%p)", con); 900 rsScriptCBegin(con); 901} 902 903static void 904nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef, 905 jint offset, jint length) 906{ 907 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 908 LOG_API("!!! nScriptCSetScript, con(%p)", con); 909 jint _exception = 0; 910 jint remaining; 911 jbyte* script_base = 0; 912 jbyte* script_ptr; 913 if (!scriptRef) { 914 _exception = 1; 915 //_env->ThrowNew(IAEClass, "script == null"); 916 goto exit; 917 } 918 if (offset < 0) { 919 _exception = 1; 920 //_env->ThrowNew(IAEClass, "offset < 0"); 921 goto exit; 922 } 923 if (length < 0) { 924 _exception = 1; 925 //_env->ThrowNew(IAEClass, "length < 0"); 926 goto exit; 927 } 928 remaining = _env->GetArrayLength(scriptRef) - offset; 929 if (remaining < length) { 930 _exception = 1; 931 //_env->ThrowNew(IAEClass, "length > script.length - offset"); 932 goto exit; 933 } 934 script_base = (jbyte *) 935 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 936 script_ptr = script_base + offset; 937 938 rsScriptCSetText(con, (const char *)script_ptr, length); 939 940exit: 941 if (script_base) { 942 _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, 943 _exception ? JNI_ABORT: 0); 944 } 945} 946 947static jint 948nScriptCCreate(JNIEnv *_env, jobject _this) 949{ 950 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 951 LOG_API("nScriptCCreate, con(%p)", con); 952 return (jint)rsScriptCCreate(con); 953} 954 955static void 956nScriptCAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value) 957{ 958 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 959 const char* n = _env->GetStringUTFChars(name, NULL); 960 LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value); 961 rsScriptCSetDefineI32(con, n, value); 962 _env->ReleaseStringUTFChars(name, n); 963} 964 965static void 966nScriptCAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value) 967{ 968 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 969 const char* n = _env->GetStringUTFChars(name, NULL); 970 LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value); 971 rsScriptCSetDefineF(con, n, value); 972 _env->ReleaseStringUTFChars(name, n); 973} 974 975// --------------------------------------------------------------------------- 976 977static void 978nProgramFragmentStoreBegin(JNIEnv *_env, jobject _this, jint in, jint out) 979{ 980 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 981 LOG_API("nProgramFragmentStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); 982 rsProgramFragmentStoreBegin(con, (RsElement)in, (RsElement)out); 983} 984 985static void 986nProgramFragmentStoreDepthFunc(JNIEnv *_env, jobject _this, jint func) 987{ 988 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 989 LOG_API("nProgramFragmentStoreDepthFunc, con(%p), func(%i)", con, func); 990 rsProgramFragmentStoreDepthFunc(con, (RsDepthFunc)func); 991} 992 993static void 994nProgramFragmentStoreDepthMask(JNIEnv *_env, jobject _this, jboolean enable) 995{ 996 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 997 LOG_API("nProgramFragmentStoreDepthMask, con(%p), enable(%i)", con, enable); 998 rsProgramFragmentStoreDepthMask(con, enable); 999} 1000 1001static void 1002nProgramFragmentStoreColorMask(JNIEnv *_env, jobject _this, jboolean r, jboolean g, jboolean b, jboolean a) 1003{ 1004 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1005 LOG_API("nProgramFragmentStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); 1006 rsProgramFragmentStoreColorMask(con, r, g, b, a); 1007} 1008 1009static void 1010nProgramFragmentStoreBlendFunc(JNIEnv *_env, jobject _this, int src, int dst) 1011{ 1012 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1013 LOG_API("nProgramFragmentStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); 1014 rsProgramFragmentStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst); 1015} 1016 1017static void 1018nProgramFragmentStoreDither(JNIEnv *_env, jobject _this, jboolean enable) 1019{ 1020 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1021 LOG_API("nProgramFragmentStoreDither, con(%p), enable(%i)", con, enable); 1022 rsProgramFragmentStoreDither(con, enable); 1023} 1024 1025static jint 1026nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this) 1027{ 1028 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1029 LOG_API("nProgramFragmentStoreCreate, con(%p)", con); 1030 1031 return (jint)rsProgramFragmentStoreCreate(con); 1032} 1033 1034// --------------------------------------------------------------------------- 1035 1036static void 1037nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out, jboolean pointSpriteEnable) 1038{ 1039 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1040 LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p) PointSprite(%i)", con, (RsElement)in, (RsElement)out, pointSpriteEnable); 1041 rsProgramFragmentBegin(con, (RsElement)in, (RsElement)out, pointSpriteEnable); 1042} 1043 1044static void 1045nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) 1046{ 1047 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1048 LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 1049 rsProgramFragmentBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 1050} 1051 1052static void 1053nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) 1054{ 1055 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1056 LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); 1057 rsProgramFragmentBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a); 1058} 1059 1060static void 1061nProgramFragmentSetSlot(JNIEnv *_env, jobject _this, jint slot, jboolean enable, jint env, jint vt) 1062{ 1063 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1064 LOG_API("nProgramFragmentSetType, con(%p), slot(%i), enable(%i), env(%i), vt(%p)", con, slot, enable, env, (RsType)vt); 1065 rsProgramFragmentSetSlot(con, slot, enable, (RsTexEnvMode)env, (RsType)vt); 1066} 1067 1068static jint 1069nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable) 1070{ 1071 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1072 LOG_API("nProgramFragmentCreate, con(%p)", con); 1073 return (jint)rsProgramFragmentCreate(con); 1074} 1075 1076// --------------------------------------------------------------------------- 1077 1078static void 1079nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out) 1080{ 1081 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1082 LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); 1083 rsProgramVertexBegin(con, (RsElement)in, (RsElement)out); 1084} 1085 1086static void 1087nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint a) 1088{ 1089 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1090 LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), a(%p)", con, (RsProgramVertex)vpv, (RsAllocation)a); 1091 rsProgramVertexBindAllocation(con, (RsProgramFragment)vpv, (RsAllocation)a); 1092} 1093 1094static void 1095nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable) 1096{ 1097 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1098 LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable); 1099 rsProgramVertexSetTextureMatrixEnable(con, enable); 1100} 1101 1102static void 1103nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light) 1104{ 1105 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1106 LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light); 1107 rsProgramVertexAddLight(con, (RsLight)light); 1108} 1109 1110static jint 1111nProgramVertexCreate(JNIEnv *_env, jobject _this) 1112{ 1113 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1114 LOG_API("nProgramVertexCreate, con(%p)", con); 1115 return (jint)rsProgramVertexCreate(con); 1116} 1117 1118 1119// --------------------------------------------------------------------------- 1120 1121static jint 1122nProgramRasterCreate(JNIEnv *_env, jobject _this, jint in, jint out, 1123 jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite) 1124{ 1125 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1126 LOG_API("nProgramRasterCreate, con(%p), in(%p), out(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)", 1127 con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite); 1128 return (jint)rsProgramRasterCreate(con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite); 1129} 1130 1131static void 1132nProgramRasterSetPointSize(JNIEnv *_env, jobject _this, jint vpr, jfloat v) 1133{ 1134 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1135 LOG_API("nProgramRasterSetPointSize, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); 1136 rsProgramRasterSetPointSize(con, (RsProgramFragment)vpr, v); 1137} 1138 1139static void 1140nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, jint vpr, jfloat v) 1141{ 1142 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1143 LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); 1144 rsProgramRasterSetLineWidth(con, (RsProgramFragment)vpr, v); 1145} 1146 1147 1148// --------------------------------------------------------------------------- 1149 1150static void 1151nContextBindRootScript(JNIEnv *_env, jobject _this, jint script) 1152{ 1153 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1154 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script); 1155 rsContextBindRootScript(con, (RsScript)script); 1156} 1157 1158static void 1159nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs) 1160{ 1161 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1162 LOG_API("nContextBindProgramFragmentStore, con(%p), pfs(%p)", con, (RsProgramFragmentStore)pfs); 1163 rsContextBindProgramFragmentStore(con, (RsProgramFragmentStore)pfs); 1164} 1165 1166static void 1167nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf) 1168{ 1169 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1170 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf); 1171 rsContextBindProgramFragment(con, (RsProgramFragment)pf); 1172} 1173 1174static void 1175nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf) 1176{ 1177 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1178 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf); 1179 rsContextBindProgramVertex(con, (RsProgramVertex)pf); 1180} 1181 1182static void 1183nContextBindProgramRaster(JNIEnv *_env, jobject _this, jint pf) 1184{ 1185 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1186 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf); 1187 rsContextBindProgramRaster(con, (RsProgramRaster)pf); 1188} 1189 1190static void 1191nContextAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value) 1192{ 1193 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1194 const char* n = _env->GetStringUTFChars(name, NULL); 1195 LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value); 1196 rsContextSetDefineI32(con, n, value); 1197 _env->ReleaseStringUTFChars(name, n); 1198} 1199 1200static void 1201nContextAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value) 1202{ 1203 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1204 const char* n = _env->GetStringUTFChars(name, NULL); 1205 LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value); 1206 rsContextSetDefineF(con, n, value); 1207 _env->ReleaseStringUTFChars(name, n); 1208} 1209 1210 1211// --------------------------------------------------------------------------- 1212 1213static void 1214nSamplerBegin(JNIEnv *_env, jobject _this) 1215{ 1216 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1217 LOG_API("nSamplerBegin, con(%p)", con); 1218 rsSamplerBegin(con); 1219} 1220 1221static void 1222nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v) 1223{ 1224 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1225 LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v); 1226 rsSamplerSet(con, (RsSamplerParam)p, (RsSamplerValue)v); 1227} 1228 1229static jint 1230nSamplerCreate(JNIEnv *_env, jobject _this) 1231{ 1232 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1233 LOG_API("nSamplerCreate, con(%p)", con); 1234 return (jint)rsSamplerCreate(con); 1235} 1236 1237// --------------------------------------------------------------------------- 1238 1239static void 1240nLightBegin(JNIEnv *_env, jobject _this) 1241{ 1242 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1243 LOG_API("nLightBegin, con(%p)", con); 1244 rsLightBegin(con); 1245} 1246 1247static void 1248nLightSetIsMono(JNIEnv *_env, jobject _this, jboolean isMono) 1249{ 1250 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1251 LOG_API("nLightSetIsMono, con(%p), isMono(%i)", con, isMono); 1252 rsLightSetMonochromatic(con, isMono); 1253} 1254 1255static void 1256nLightSetIsLocal(JNIEnv *_env, jobject _this, jboolean isLocal) 1257{ 1258 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1259 LOG_API("nLightSetIsLocal, con(%p), isLocal(%i)", con, isLocal); 1260 rsLightSetLocal(con, isLocal); 1261} 1262 1263static jint 1264nLightCreate(JNIEnv *_env, jobject _this) 1265{ 1266 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1267 LOG_API("nLightCreate, con(%p)", con); 1268 return (jint)rsLightCreate(con); 1269} 1270 1271static void 1272nLightSetColor(JNIEnv *_env, jobject _this, jint light, float r, float g, float b) 1273{ 1274 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1275 LOG_API("nLightSetColor, con(%p), light(%p), r(%f), g(%f), b(%f)", con, (RsLight)light, r, g, b); 1276 rsLightSetColor(con, (RsLight)light, r, g, b); 1277} 1278 1279static void 1280nLightSetPosition(JNIEnv *_env, jobject _this, jint light, float x, float y, float z) 1281{ 1282 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1283 LOG_API("nLightSetPosition, con(%p), light(%p), x(%f), y(%f), z(%f)", con, (RsLight)light, x, y, z); 1284 rsLightSetPosition(con, (RsLight)light, x, y, z); 1285} 1286 1287// --------------------------------------------------------------------------- 1288 1289static jint 1290nSimpleMeshCreate(JNIEnv *_env, jobject _this, jint batchID, jint indexID, jintArray vtxIDs, jint primID) 1291{ 1292 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1293 jint len = _env->GetArrayLength(vtxIDs); 1294 LOG_API("nSimpleMeshCreate, con(%p), batchID(%i), indexID(%i), vtxIDs.len(%i), primID(%i)", 1295 con, batchID, indexID, len, primID); 1296 jint *ptr = _env->GetIntArrayElements(vtxIDs, NULL); 1297 int id = (int)rsSimpleMeshCreate(con, (void *)batchID, (void *)indexID, (void **)ptr, len, primID); 1298 _env->ReleaseIntArrayElements(vtxIDs, ptr, 0/*JNI_ABORT*/); 1299 return id; 1300} 1301 1302static void 1303nSimpleMeshBindVertex(JNIEnv *_env, jobject _this, jint s, jint alloc, jint slot) 1304{ 1305 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1306 LOG_API("nSimpleMeshBindVertex, con(%p), SimpleMesh(%p), Alloc(%p), slot(%i)", con, (RsSimpleMesh)s, (RsAllocation)alloc, slot); 1307 rsSimpleMeshBindVertex(con, (RsSimpleMesh)s, (RsAllocation)alloc, slot); 1308} 1309 1310static void 1311nSimpleMeshBindIndex(JNIEnv *_env, jobject _this, jint s, jint alloc) 1312{ 1313 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 1314 LOG_API("nSimpleMeshBindIndex, con(%p), SimpleMesh(%p), Alloc(%p)", con, (RsSimpleMesh)s, (RsAllocation)alloc); 1315 rsSimpleMeshBindIndex(con, (RsSimpleMesh)s, (RsAllocation)alloc); 1316} 1317 1318// --------------------------------------------------------------------------- 1319 1320 1321static const char *classPathName = "android/renderscript/RenderScript"; 1322 1323static JNINativeMethod methods[] = { 1324{"_nInit", "()V", (void*)_nInit }, 1325{"nInitElements", "(IIII)V", (void*)nInitElements }, 1326 1327{"nDeviceCreate", "()I", (void*)nDeviceCreate }, 1328{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, 1329{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, 1330{"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate }, 1331{"nContextDestroy", "(I)V", (void*)nContextDestroy }, 1332{"nContextPause", "()V", (void*)nContextPause }, 1333{"nContextResume", "()V", (void*)nContextResume }, 1334{"nAssignName", "(I[B)V", (void*)nAssignName }, 1335{"nObjDestroy", "(I)V", (void*)nObjDestroy }, 1336{"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB }, 1337{"nContextGetMessage", "([IZ)I", (void*)nContextGetMessage }, 1338{"nContextInitToClient", "()V", (void*)nContextInitToClient }, 1339{"nContextDeinitToClient", "()V", (void*)nContextDeinitToClient }, 1340 1341{"nFileOpen", "([B)I", (void*)nFileOpen }, 1342 1343{"nElementBegin", "()V", (void*)nElementBegin }, 1344{"nElementAdd", "(IIZILjava/lang/String;)V", (void*)nElementAdd }, 1345{"nElementCreate", "()I", (void*)nElementCreate }, 1346 1347{"nTypeBegin", "(I)V", (void*)nTypeBegin }, 1348{"nTypeAdd", "(II)V", (void*)nTypeAdd }, 1349{"nTypeCreate", "()I", (void*)nTypeCreate }, 1350{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy }, 1351{"nTypeSetupFields", "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields }, 1352 1353{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped }, 1354{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, 1355{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed }, 1356{"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream }, 1357{"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture }, 1358{"nAllocationUploadToBufferObject","(I)V", (void*)nAllocationUploadToBufferObject }, 1359{"nAllocationSubData1D", "(III[II)V", (void*)nAllocationSubData1D_i }, 1360{"nAllocationSubData1D", "(III[SI)V", (void*)nAllocationSubData1D_s }, 1361{"nAllocationSubData1D", "(III[BI)V", (void*)nAllocationSubData1D_b }, 1362{"nAllocationSubData1D", "(III[FI)V", (void*)nAllocationSubData1D_f }, 1363{"nAllocationSubData2D", "(IIIII[II)V", (void*)nAllocationSubData2D_i }, 1364{"nAllocationSubData2D", "(IIIII[FI)V", (void*)nAllocationSubData2D_f }, 1365{"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i }, 1366{"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f }, 1367{"nAllocationSubDataFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject }, 1368{"nAllocationSubReadFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubReadFromObject }, 1369 1370{"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation }, 1371{"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint }, 1372{"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i }, 1373{"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f }, 1374{"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i }, 1375{"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f }, 1376{"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate }, 1377 1378{"nAdapter2DBindAllocation", "(II)V", (void*)nAdapter2DBindAllocation }, 1379{"nAdapter2DSetConstraint", "(III)V", (void*)nAdapter2DSetConstraint }, 1380{"nAdapter2DData", "(I[I)V", (void*)nAdapter2DData_i }, 1381{"nAdapter2DData", "(I[F)V", (void*)nAdapter2DData_f }, 1382{"nAdapter2DSubData", "(IIIII[I)V", (void*)nAdapter2DSubData_i }, 1383{"nAdapter2DSubData", "(IIIII[F)V", (void*)nAdapter2DSubData_f }, 1384{"nAdapter2DCreate", "()I", (void*)nAdapter2DCreate }, 1385 1386{"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation }, 1387{"nScriptSetClearColor", "(IFFFF)V", (void*)nScriptSetClearColor }, 1388{"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth }, 1389{"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil }, 1390{"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone }, 1391{"nScriptSetType", "(IZLjava/lang/String;I)V", (void*)nScriptSetType }, 1392{"nScriptSetRoot", "(Z)V", (void*)nScriptSetRoot }, 1393{"nScriptSetInvokable", "(Ljava/lang/String;I)V", (void*)nScriptSetInvoke }, 1394{"nScriptInvoke", "(II)V", (void*)nScriptInvoke }, 1395 1396{"nScriptCBegin", "()V", (void*)nScriptCBegin }, 1397{"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript }, 1398{"nScriptCCreate", "()I", (void*)nScriptCCreate }, 1399{"nScriptCAddDefineI32", "(Ljava/lang/String;I)V", (void*)nScriptCAddDefineI32 }, 1400{"nScriptCAddDefineF", "(Ljava/lang/String;F)V", (void*)nScriptCAddDefineF }, 1401 1402{"nProgramFragmentStoreBegin", "(II)V", (void*)nProgramFragmentStoreBegin }, 1403{"nProgramFragmentStoreDepthFunc", "(I)V", (void*)nProgramFragmentStoreDepthFunc }, 1404{"nProgramFragmentStoreDepthMask", "(Z)V", (void*)nProgramFragmentStoreDepthMask }, 1405{"nProgramFragmentStoreColorMask", "(ZZZZ)V", (void*)nProgramFragmentStoreColorMask }, 1406{"nProgramFragmentStoreBlendFunc", "(II)V", (void*)nProgramFragmentStoreBlendFunc }, 1407{"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither }, 1408{"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate }, 1409 1410{"nProgramFragmentBegin", "(IIZ)V", (void*)nProgramFragmentBegin }, 1411{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture }, 1412{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler }, 1413{"nProgramFragmentSetSlot", "(IZII)V", (void*)nProgramFragmentSetSlot }, 1414{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate }, 1415 1416{"nProgramRasterCreate", "(IIZZZ)I", (void*)nProgramRasterCreate }, 1417{"nProgramRasterSetPointSize", "(IF)V", (void*)nProgramRasterSetPointSize }, 1418{"nProgramRasterSetLineWidth", "(IF)V", (void*)nProgramRasterSetLineWidth }, 1419 1420{"nProgramVertexBindAllocation", "(II)V", (void*)nProgramVertexBindAllocation }, 1421{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin }, 1422{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable }, 1423{"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight }, 1424{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate }, 1425 1426{"nLightBegin", "()V", (void*)nLightBegin }, 1427{"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono }, 1428{"nLightSetIsLocal", "(Z)V", (void*)nLightSetIsLocal }, 1429{"nLightCreate", "()I", (void*)nLightCreate }, 1430{"nLightSetColor", "(IFFF)V", (void*)nLightSetColor }, 1431{"nLightSetPosition", "(IFFF)V", (void*)nLightSetPosition }, 1432 1433{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript }, 1434{"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore }, 1435{"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment }, 1436{"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex }, 1437{"nContextBindProgramRaster", "(I)V", (void*)nContextBindProgramRaster }, 1438 1439{"nSamplerBegin", "()V", (void*)nSamplerBegin }, 1440{"nSamplerSet", "(II)V", (void*)nSamplerSet }, 1441{"nSamplerCreate", "()I", (void*)nSamplerCreate }, 1442 1443{"nSimpleMeshCreate", "(II[II)I", (void*)nSimpleMeshCreate }, 1444{"nSimpleMeshBindVertex", "(III)V", (void*)nSimpleMeshBindVertex }, 1445{"nSimpleMeshBindIndex", "(II)V", (void*)nSimpleMeshBindIndex }, 1446 1447}; 1448 1449static int registerFuncs(JNIEnv *_env) 1450{ 1451 return android::AndroidRuntime::registerNativeMethods( 1452 _env, classPathName, methods, NELEM(methods)); 1453} 1454 1455// --------------------------------------------------------------------------- 1456 1457jint JNI_OnLoad(JavaVM* vm, void* reserved) 1458{ 1459 JNIEnv* env = NULL; 1460 jint result = -1; 1461 1462 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1463 LOGE("ERROR: GetEnv failed\n"); 1464 goto bail; 1465 } 1466 assert(env != NULL); 1467 1468 if (registerFuncs(env) < 0) { 1469 LOGE("ERROR: MediaPlayer native registration failed\n"); 1470 goto bail; 1471 } 1472 1473 /* success -- return valid version number */ 1474 result = JNI_VERSION_1_4; 1475 1476bail: 1477 return result; 1478} 1479