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