android_renderscript_RenderScript.cpp revision 49a05d7b82956009f03acbb92a064eed054eb031
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#include "android_runtime/android_view_Surface.h" 41 42#include <RenderScript.h> 43#include <RenderScriptEnv.h> 44 45//#define LOG_API LOGE 46#define LOG_API(...) 47 48using namespace android; 49 50// --------------------------------------------------------------------------- 51 52static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) 53{ 54 jclass npeClazz = env->FindClass(exc); 55 env->ThrowNew(npeClazz, msg); 56} 57 58static jfieldID gContextId = 0; 59static jfieldID gNativeBitmapID = 0; 60static jfieldID gTypeNativeCache = 0; 61 62static void _nInit(JNIEnv *_env, jclass _this) 63{ 64 gContextId = _env->GetFieldID(_this, "mContext", "I"); 65 66 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); 67 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); 68} 69 70// --------------------------------------------------------------------------- 71 72static void 73nContextFinish(JNIEnv *_env, jobject _this, RsContext con) 74{ 75 LOG_API("nContextFinish, con(%p)", con); 76 rsContextFinish(con); 77} 78 79static void 80nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str) 81{ 82 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj); 83 jint len = _env->GetArrayLength(str); 84 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 85 rsAssignName(con, (void *)obj, (const char *)cptr, len); 86 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 87} 88 89static jstring 90nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj) 91{ 92 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj); 93 const char *name = NULL; 94 rsaGetName(con, (void *)obj, &name); 95 if(name == NULL || strlen(name) == 0) { 96 return NULL; 97 } 98 return _env->NewStringUTF(name); 99} 100 101static void 102nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj) 103{ 104 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); 105 rsObjDestroy(con, (void *)obj); 106} 107 108// --------------------------------------------------------------------------- 109 110static jint 111nDeviceCreate(JNIEnv *_env, jobject _this) 112{ 113 LOG_API("nDeviceCreate"); 114 return (jint)rsDeviceCreate(); 115} 116 117static void 118nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 119{ 120 LOG_API("nDeviceDestroy"); 121 return rsDeviceDestroy((RsDevice)dev); 122} 123 124static void 125nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) 126{ 127 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 128 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 129} 130 131static jint 132nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver) 133{ 134 LOG_API("nContextCreate"); 135 return (jint)rsContextCreate((RsDevice)dev, ver); 136} 137 138static jint 139nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, 140 int colorMin, int colorPref, 141 int alphaMin, int alphaPref, 142 int depthMin, int depthPref, 143 int stencilMin, int stencilPref, 144 int samplesMin, int samplesPref, float samplesQ) 145{ 146 RsSurfaceConfig sc; 147 sc.alphaMin = alphaMin; 148 sc.alphaPref = alphaPref; 149 sc.colorMin = colorMin; 150 sc.colorPref = colorPref; 151 sc.depthMin = depthMin; 152 sc.depthPref = depthPref; 153 sc.samplesMin = samplesMin; 154 sc.samplesPref = samplesPref; 155 sc.samplesQ = samplesQ; 156 157 LOG_API("nContextCreateGL"); 158 return (jint)rsContextCreateGL((RsDevice)dev, ver, sc); 159} 160 161static void 162nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p) 163{ 164 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p); 165 rsContextSetPriority(con, p); 166} 167 168 169 170static void 171nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd) 172{ 173 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd); 174 175 Surface * window = NULL; 176 if (wnd == NULL) { 177 178 } else { 179 window = (Surface*) android_Surface_getNativeWindow(_env, wnd).get(); 180 } 181 182 rsContextSetSurface(con, width, height, window); 183} 184 185static void 186nContextDestroy(JNIEnv *_env, jobject _this, RsContext con) 187{ 188 LOG_API("nContextDestroy, con(%p)", con); 189 rsContextDestroy(con); 190} 191 192static void 193nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits) 194{ 195 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 196 rsContextDump((RsContext)con, bits); 197} 198 199static void 200nContextPause(JNIEnv *_env, jobject _this, RsContext con) 201{ 202 LOG_API("nContextPause, con(%p)", con); 203 rsContextPause(con); 204} 205 206static void 207nContextResume(JNIEnv *_env, jobject _this, RsContext con) 208{ 209 LOG_API("nContextResume, con(%p)", con); 210 rsContextResume(con); 211} 212 213 214static jstring 215nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con) 216{ 217 LOG_API("nContextGetErrorMessage, con(%p)", con); 218 char buf[1024]; 219 220 size_t receiveLen; 221 uint32_t subID; 222 int id = rsContextGetMessage(con, buf, &receiveLen, &subID, sizeof(buf), true); 223 if (!id && receiveLen) { 224 LOGV("message receive buffer too small. %i", receiveLen); 225 } 226 return _env->NewStringUTF(buf); 227} 228 229static void 230nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data) 231{ 232 jint len = _env->GetArrayLength(data); 233 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); 234 jint *ptr = _env->GetIntArrayElements(data, NULL); 235 size_t receiveLen; 236 uint32_t subID; 237 int id = rsContextGetMessage(con, ptr, &receiveLen, &subID, len * 4, true); 238 if (!id && receiveLen) { 239 LOGV("message receive buffer too small. %i", receiveLen); 240 } 241 _env->ReleaseIntArrayElements(data, ptr, 0); 242} 243 244static jint 245nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData, jboolean wait) 246{ 247 LOG_API("nContextPeekMessage, con(%p)", con); 248 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); 249 size_t receiveLen; 250 uint32_t subID; 251 int id = rsContextPeekMessage(con, &receiveLen, &subID, wait); 252 auxDataPtr[0] = (jint)subID; 253 auxDataPtr[1] = (jint)receiveLen; 254 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); 255 return id; 256} 257 258static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con) 259{ 260 LOG_API("nContextInitToClient, con(%p)", con); 261 rsContextInitToClient(con); 262} 263 264static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con) 265{ 266 LOG_API("nContextDeinitToClient, con(%p)", con); 267 rsContextDeinitToClient(con); 268} 269 270 271static jint 272nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size) 273{ 274 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size); 275 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size); 276} 277 278static jint 279nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes) 280{ 281 int fieldCount = _env->GetArrayLength(_ids); 282 LOG_API("nElementCreate2, con(%p)", con); 283 284 jint *ids = _env->GetIntArrayElements(_ids, NULL); 285 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL); 286 const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *)); 287 size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t)); 288 289 for (int ct=0; ct < fieldCount; ct++) { 290 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); 291 nameArray[ct] = _env->GetStringUTFChars(s, NULL); 292 sizeArray[ct] = _env->GetStringUTFLength(s); 293 } 294 jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray, (const uint32_t *)arraySizes); 295 for (int ct=0; ct < fieldCount; ct++) { 296 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); 297 _env->ReleaseStringUTFChars(s, nameArray[ct]); 298 } 299 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); 300 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT); 301 free(nameArray); 302 free(sizeArray); 303 return (jint)id; 304} 305 306static void 307nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData) 308{ 309 int dataSize = _env->GetArrayLength(_elementData); 310 LOG_API("nElementGetNativeData, con(%p)", con); 311 312 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements 313 assert(dataSize == 5); 314 315 uint32_t elementData[5]; 316 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize); 317 318 for(jint i = 0; i < dataSize; i ++) { 319 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]); 320 } 321} 322 323 324static void 325nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _IDs, jobjectArray _names) 326{ 327 int dataSize = _env->GetArrayLength(_IDs); 328 LOG_API("nElementGetSubElements, con(%p)", con); 329 330 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 331 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); 332 333 rsaElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize); 334 335 for(jint i = 0; i < dataSize; i++) { 336 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 337 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); 338 } 339 340 free(ids); 341 free(names); 342} 343 344// ----------------------------------- 345 346static int 347nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid, 348 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces) 349{ 350 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)", 351 con, eid, dimx, dimy, dimz, mips, faces); 352 353 jint id = (jint)rsaTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces); 354 return (jint)id; 355} 356 357static void 358nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData) 359{ 360 // We are packing 6 items: mDimX; mDimY; mDimZ; 361 // mDimLOD; mDimFaces; mElement; into typeData 362 int elementCount = _env->GetArrayLength(_typeData); 363 364 assert(elementCount == 6); 365 LOG_API("nTypeCreate, con(%p)", con); 366 367 uint32_t typeData[6]; 368 rsaTypeGetNativeData(con, (RsType)id, typeData, 6); 369 370 for(jint i = 0; i < elementCount; i ++) { 371 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]); 372 } 373} 374 375// ----------------------------------- 376 377static jint 378nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage) 379{ 380 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage); 381 return (jint) rsaAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage); 382} 383 384static void 385nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits) 386{ 387 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits); 388 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits); 389} 390 391static int 392nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 393{ 394 SkBitmap const * nativeBitmap = 395 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 396 const SkBitmap& bitmap(*nativeBitmap); 397 398 bitmap.lockPixels(); 399 const void* ptr = bitmap.getPixels(); 400 jint id = (jint)rsaAllocationCreateFromBitmap(con, (RsType)type, (RsAllocationMipmapControl)mip, ptr, usage); 401 bitmap.unlockPixels(); 402 return id; 403} 404 405static int 406nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 407{ 408 SkBitmap const * nativeBitmap = 409 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 410 const SkBitmap& bitmap(*nativeBitmap); 411 412 bitmap.lockPixels(); 413 const void* ptr = bitmap.getPixels(); 414 jint id = (jint)rsaAllocationCubeCreateFromBitmap(con, (RsType)type, (RsAllocationMipmapControl)mip, ptr, usage); 415 bitmap.unlockPixels(); 416 return id; 417} 418 419static void 420nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 421{ 422 SkBitmap const * nativeBitmap = 423 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 424 const SkBitmap& bitmap(*nativeBitmap); 425 426 bitmap.lockPixels(); 427 const void* ptr = bitmap.getPixels(); 428 rsAllocationCopyFromBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize()); 429 bitmap.unlockPixels(); 430} 431 432static void 433nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 434{ 435 SkBitmap const * nativeBitmap = 436 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 437 const SkBitmap& bitmap(*nativeBitmap); 438 439 bitmap.lockPixels(); 440 void* ptr = bitmap.getPixels(); 441 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize()); 442 bitmap.unlockPixels(); 443} 444 445static void ReleaseBitmapCallback(void *bmp) 446{ 447 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; 448 nativeBitmap->unlockPixels(); 449} 450 451 452static void 453nAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes) 454{ 455 jint len = _env->GetArrayLength(data); 456 LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 457 jint *ptr = _env->GetIntArrayElements(data, NULL); 458 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 459 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 460} 461 462static void 463nAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes) 464{ 465 jint len = _env->GetArrayLength(data); 466 LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 467 jshort *ptr = _env->GetShortArrayElements(data, NULL); 468 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 469 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 470} 471 472static void 473nAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes) 474{ 475 jint len = _env->GetArrayLength(data); 476 LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 477 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 478 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 479 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 480} 481 482static void 483nAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes) 484{ 485 jint len = _env->GetArrayLength(data); 486 LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 487 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 488 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 489 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 490} 491 492static void 493// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); 494nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes) 495{ 496 jint len = _env->GetArrayLength(data); 497 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); 498 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 499 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, compIdx, sizeBytes); 500 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 501} 502 503static void 504nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 505 jint w, jint h, jintArray data, int sizeBytes) 506{ 507 jint len = _env->GetArrayLength(data); 508 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 509 jint *ptr = _env->GetIntArrayElements(data, NULL); 510 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); 511 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 512} 513 514static void 515nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 516 jint w, jint h, jfloatArray data, int sizeBytes) 517{ 518 jint len = _env->GetArrayLength(data); 519 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 520 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 521 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); 522 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 523} 524 525static void 526nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data) 527{ 528 jint len = _env->GetArrayLength(data); 529 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 530 jint *ptr = _env->GetIntArrayElements(data, NULL); 531 rsAllocationRead(con, (RsAllocation)alloc, ptr); 532 _env->ReleaseIntArrayElements(data, ptr, 0); 533} 534 535static void 536nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data) 537{ 538 jint len = _env->GetArrayLength(data); 539 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 540 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 541 rsAllocationRead(con, (RsAllocation)alloc, ptr); 542 _env->ReleaseFloatArrayElements(data, ptr, 0); 543} 544 545static jint 546nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a) 547{ 548 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a); 549 return (jint) rsaAllocationGetType(con, (RsAllocation)a); 550} 551 552static void 553nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX) 554{ 555 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX); 556 rsAllocationResize1D(con, (RsAllocation)alloc, dimX); 557} 558 559static void 560nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY) 561{ 562 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY); 563 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY); 564} 565 566// ----------------------------------- 567 568static int 569nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset) 570{ 571 LOGV("______nFileA3D %u", (uint32_t) native_asset); 572 573 Asset* asset = reinterpret_cast<Asset*>(native_asset); 574 575 jint id = (jint)rsaFileA3DCreateFromAssetStream(con, asset->getBuffer(false), asset->getLength()); 576 return id; 577} 578 579static int 580nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D) 581{ 582 int32_t numEntries = 0; 583 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D); 584 return numEntries; 585} 586 587static void 588nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries) 589{ 590 LOGV("______nFileA3D %u", (uint32_t) fileA3D); 591 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry)); 592 593 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D); 594 595 for(jint i = 0; i < numEntries; i ++) { 596 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName)); 597 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID); 598 } 599 600 free(fileEntries); 601} 602 603static int 604nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index) 605{ 606 LOGV("______nFileA3D %u", (uint32_t) fileA3D); 607 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D); 608 return id; 609} 610 611// ----------------------------------- 612 613static int 614nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jfloat fontSize, jint dpi) 615{ 616 const char* fileNameUTF = _env->GetStringUTFChars(fileName, NULL); 617 618 jint id = (jint)rsFontCreateFromFile(con, fileNameUTF, fontSize, dpi); 619 return id; 620} 621 622// ----------------------------------- 623 624static void 625nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot) 626{ 627 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); 628 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); 629} 630 631static void 632nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 633{ 634 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 635 rsScriptSetVarI(con, (RsScript)script, slot, val); 636} 637 638static void 639nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 640{ 641 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 642 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val); 643} 644 645static void 646nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val) 647{ 648 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val); 649 rsScriptSetVarJ(con, (RsScript)script, slot, val); 650} 651 652static void 653nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val) 654{ 655 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val); 656 rsScriptSetVarF(con, (RsScript)script, slot, val); 657} 658 659static void 660nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val) 661{ 662 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val); 663 rsScriptSetVarD(con, (RsScript)script, slot, val); 664} 665 666static void 667nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 668{ 669 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 670 jint len = _env->GetArrayLength(data); 671 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 672 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len); 673 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 674} 675 676 677static void 678nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone) 679{ 680 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone); 681 682 jint length = _env->GetArrayLength(timeZone); 683 jbyte* timeZone_ptr; 684 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 685 686 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); 687 688 if (timeZone_ptr) { 689 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 690 } 691} 692 693static void 694nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot) 695{ 696 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); 697 rsScriptInvoke(con, (RsScript)obj, slot); 698} 699 700static void 701nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 702{ 703 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 704 jint len = _env->GetArrayLength(data); 705 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 706 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len); 707 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 708} 709 710 711// ----------------------------------- 712 713static void 714nScriptCBegin(JNIEnv *_env, jobject _this, RsContext con) 715{ 716 LOG_API("nScriptCBegin, con(%p)", con); 717 rsScriptCBegin(con); 718} 719 720static void 721nScriptCSetScript(JNIEnv *_env, jobject _this, RsContext con, jbyteArray scriptRef, 722 jint offset, jint length) 723{ 724 LOG_API("!!! nScriptCSetScript, con(%p)", con); 725 jint _exception = 0; 726 jint remaining; 727 jbyte* script_base = 0; 728 jbyte* script_ptr; 729 if (!scriptRef) { 730 _exception = 1; 731 //_env->ThrowNew(IAEClass, "script == null"); 732 goto exit; 733 } 734 if (offset < 0) { 735 _exception = 1; 736 //_env->ThrowNew(IAEClass, "offset < 0"); 737 goto exit; 738 } 739 if (length < 0) { 740 _exception = 1; 741 //_env->ThrowNew(IAEClass, "length < 0"); 742 goto exit; 743 } 744 remaining = _env->GetArrayLength(scriptRef) - offset; 745 if (remaining < length) { 746 _exception = 1; 747 //_env->ThrowNew(IAEClass, "length > script.length - offset"); 748 goto exit; 749 } 750 script_base = (jbyte *) 751 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 752 script_ptr = script_base + offset; 753 754 rsScriptCSetText(con, (const char *)script_ptr, length); 755 756exit: 757 if (script_base) { 758 _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, 759 _exception ? JNI_ABORT: 0); 760 } 761} 762 763static jint 764nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring packageName, jstring resName, jstring cacheDir) 765{ 766 LOG_API("nScriptCCreate, con(%p)", con); 767 const char* packageNameUTF = _env->GetStringUTFChars(packageName, NULL); 768 const char* resNameUTF = _env->GetStringUTFChars(resName, NULL); 769 const char* cacheDirUTF = _env->GetStringUTFChars(cacheDir, NULL); 770 jint i = (jint)rsScriptCCreate(con, packageNameUTF, resNameUTF, cacheDirUTF); 771 _env->ReleaseStringUTFChars(packageName, packageNameUTF); 772 _env->ReleaseStringUTFChars(resName, resNameUTF); 773 _env->ReleaseStringUTFChars(cacheDir, cacheDirUTF); 774 return i; 775} 776 777// --------------------------------------------------------------------------- 778 779static void 780nProgramStoreBegin(JNIEnv *_env, jobject _this, RsContext con, jint in, jint out) 781{ 782 LOG_API("nProgramStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); 783 rsProgramStoreBegin(con, (RsElement)in, (RsElement)out); 784} 785 786static void 787nProgramStoreDepthFunc(JNIEnv *_env, jobject _this, RsContext con, jint func) 788{ 789 LOG_API("nProgramStoreDepthFunc, con(%p), func(%i)", con, func); 790 rsProgramStoreDepthFunc(con, (RsDepthFunc)func); 791} 792 793static void 794nProgramStoreDepthMask(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) 795{ 796 LOG_API("nProgramStoreDepthMask, con(%p), enable(%i)", con, enable); 797 rsProgramStoreDepthMask(con, enable); 798} 799 800static void 801nProgramStoreColorMask(JNIEnv *_env, jobject _this, RsContext con, jboolean r, jboolean g, jboolean b, jboolean a) 802{ 803 LOG_API("nProgramStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); 804 rsProgramStoreColorMask(con, r, g, b, a); 805} 806 807static void 808nProgramStoreBlendFunc(JNIEnv *_env, jobject _this, RsContext con, int src, int dst) 809{ 810 LOG_API("nProgramStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); 811 rsProgramStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst); 812} 813 814static void 815nProgramStoreDither(JNIEnv *_env, jobject _this, RsContext con, jboolean enable) 816{ 817 LOG_API("nProgramStoreDither, con(%p), enable(%i)", con, enable); 818 rsProgramStoreDither(con, enable); 819} 820 821static jint 822nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con) 823{ 824 LOG_API("nProgramStoreCreate, con(%p)", con); 825 return (jint)rsProgramStoreCreate(con); 826} 827 828// --------------------------------------------------------------------------- 829 830static void 831nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a) 832{ 833 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a); 834 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a); 835} 836 837static void 838nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a) 839{ 840 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 841 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 842} 843 844static void 845nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a) 846{ 847 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); 848 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a); 849} 850 851// --------------------------------------------------------------------------- 852 853static jint 854nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) 855{ 856 const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); 857 jint shaderLen = _env->GetStringUTFLength(shader); 858 jint *paramPtr = _env->GetIntArrayElements(params, NULL); 859 jint paramLen = _env->GetArrayLength(params); 860 861 LOG_API("nProgramFragmentCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); 862 863 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); 864 _env->ReleaseStringUTFChars(shader, shaderUTF); 865 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); 866 return ret; 867} 868 869 870// --------------------------------------------------------------------------- 871 872static jint 873nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) 874{ 875 const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); 876 jint shaderLen = _env->GetStringUTFLength(shader); 877 jint *paramPtr = _env->GetIntArrayElements(params, NULL); 878 jint paramLen = _env->GetArrayLength(params); 879 880 LOG_API("nProgramVertexCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); 881 882 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); 883 _env->ReleaseStringUTFChars(shader, shaderUTF); 884 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); 885 return ret; 886} 887 888// --------------------------------------------------------------------------- 889 890static jint 891nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite) 892{ 893 LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)", 894 con, pointSmooth, lineSmooth, pointSprite); 895 return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite); 896} 897 898static void 899nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jfloat v) 900{ 901 LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v); 902 rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v); 903} 904 905static void 906nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jint v) 907{ 908 LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v); 909 rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v); 910} 911 912 913// --------------------------------------------------------------------------- 914 915static void 916nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script) 917{ 918 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script); 919 rsContextBindRootScript(con, (RsScript)script); 920} 921 922static void 923nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs) 924{ 925 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs); 926 rsContextBindProgramStore(con, (RsProgramStore)pfs); 927} 928 929static void 930nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf) 931{ 932 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf); 933 rsContextBindProgramFragment(con, (RsProgramFragment)pf); 934} 935 936static void 937nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf) 938{ 939 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf); 940 rsContextBindProgramVertex(con, (RsProgramVertex)pf); 941} 942 943static void 944nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf) 945{ 946 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf); 947 rsContextBindProgramRaster(con, (RsProgramRaster)pf); 948} 949 950 951// --------------------------------------------------------------------------- 952 953static void 954nSamplerBegin(JNIEnv *_env, jobject _this, RsContext con) 955{ 956 LOG_API("nSamplerBegin, con(%p)", con); 957 rsSamplerBegin(con); 958} 959 960static void 961nSamplerSet(JNIEnv *_env, jobject _this, RsContext con, jint p, jint v) 962{ 963 LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v); 964 rsSamplerSet(con, (RsSamplerParam)p, (RsSamplerValue)v); 965} 966 967static void 968nSamplerSet2(JNIEnv *_env, jobject _this, RsContext con, jint p, jfloat v) 969{ 970 LOG_API("nSamplerSet2, con(%p), param(%i), value(%f)", con, p, v); 971 rsSamplerSet2(con, (RsSamplerParam)p, v); 972} 973 974static jint 975nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con) 976{ 977 LOG_API("nSamplerCreate, con(%p)", con); 978 return (jint)rsSamplerCreate(con); 979} 980 981// --------------------------------------------------------------------------- 982 983static jint 984nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jint vtxCount, jint idxCount) 985{ 986 LOG_API("nMeshCreate, con(%p), vtxCount(%i), idxCount(%i)", con, vtxCount, idxCount); 987 int id = (int)rsMeshCreate(con, vtxCount, idxCount); 988 return id; 989} 990 991static void 992nMeshBindVertex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint slot) 993{ 994 LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)mesh, (RsAllocation)alloc, slot); 995 rsMeshBindVertex(con, (RsMesh)mesh, (RsAllocation)alloc, slot); 996} 997 998static void 999nMeshBindIndex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint primID, jint slot) 1000{ 1001 LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)mesh, (RsAllocation)alloc); 1002 rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot); 1003} 1004 1005static void 1006nMeshInitVertexAttribs(JNIEnv *_env, jobject _this, RsContext con, jint mesh) 1007{ 1008 LOG_API("nMeshInitVertexAttribs, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1009 rsMeshInitVertexAttribs(con, (RsMesh)mesh); 1010} 1011 1012 1013static jint 1014nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh) 1015{ 1016 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1017 jint vtxCount = 0; 1018 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount); 1019 return vtxCount; 1020} 1021 1022static jint 1023nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh) 1024{ 1025 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1026 jint idxCount = 0; 1027 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount); 1028 return idxCount; 1029} 1030 1031static void 1032nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs) 1033{ 1034 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1035 1036 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); 1037 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); 1038 1039 for(jint i = 0; i < numVtxIDs; i ++) { 1040 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]); 1041 } 1042 1043 free(allocs); 1044} 1045 1046static void 1047nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices) 1048{ 1049 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh); 1050 1051 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); 1052 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); 1053 1054 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices); 1055 1056 for(jint i = 0; i < numIndices; i ++) { 1057 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]); 1058 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]); 1059 } 1060 1061 free(allocs); 1062 free(prims); 1063} 1064 1065// --------------------------------------------------------------------------- 1066 1067 1068static const char *classPathName = "android/renderscript/RenderScript"; 1069 1070static JNINativeMethod methods[] = { 1071{"_nInit", "()V", (void*)_nInit }, 1072 1073{"nDeviceCreate", "()I", (void*)nDeviceCreate }, 1074{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, 1075{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, 1076{"nContextGetUserMessage", "(I[I)V", (void*)nContextGetUserMessage }, 1077{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage }, 1078{"nContextPeekMessage", "(I[IZ)I", (void*)nContextPeekMessage }, 1079 1080{"nContextInitToClient", "(I)V", (void*)nContextInitToClient }, 1081{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient }, 1082 1083 1084// All methods below are thread protected in java. 1085{"rsnContextCreate", "(II)I", (void*)nContextCreate }, 1086{"rsnContextCreateGL", "(IIIIIIIIIIIIF)I", (void*)nContextCreateGL }, 1087{"rsnContextFinish", "(I)V", (void*)nContextFinish }, 1088{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority }, 1089{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface }, 1090{"rsnContextDestroy", "(I)V", (void*)nContextDestroy }, 1091{"rsnContextDump", "(II)V", (void*)nContextDump }, 1092{"rsnContextPause", "(I)V", (void*)nContextPause }, 1093{"rsnContextResume", "(I)V", (void*)nContextResume }, 1094{"rsnAssignName", "(II[B)V", (void*)nAssignName }, 1095{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName }, 1096{"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, 1097 1098{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream }, 1099{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries }, 1100{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, 1101{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex }, 1102 1103{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile }, 1104 1105{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, 1106{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, 1107{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData }, 1108{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements }, 1109 1110{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate }, 1111{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData }, 1112 1113{"rsnAllocationCreateTyped", "(IIII)I", (void*)nAllocationCreateTyped }, 1114{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, 1115{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, 1116 1117{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, 1118{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, 1119 1120{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll }, 1121{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i }, 1122{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s }, 1123{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b }, 1124{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f }, 1125{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D }, 1126{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i }, 1127{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f }, 1128{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i }, 1129{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f }, 1130{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType}, 1131{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D }, 1132{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D }, 1133 1134{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation }, 1135{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone }, 1136{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke }, 1137{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV }, 1138{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI }, 1139{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ }, 1140{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF }, 1141{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD }, 1142{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, 1143{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, 1144 1145{"rsnScriptCBegin", "(I)V", (void*)nScriptCBegin }, 1146{"rsnScriptCSetScript", "(I[BII)V", (void*)nScriptCSetScript }, 1147{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", (void*)nScriptCCreate }, 1148 1149{"rsnProgramStoreBegin", "(III)V", (void*)nProgramStoreBegin }, 1150{"rsnProgramStoreDepthFunc", "(II)V", (void*)nProgramStoreDepthFunc }, 1151{"rsnProgramStoreDepthMask", "(IZ)V", (void*)nProgramStoreDepthMask }, 1152{"rsnProgramStoreColorMask", "(IZZZZ)V", (void*)nProgramStoreColorMask }, 1153{"rsnProgramStoreBlendFunc", "(III)V", (void*)nProgramStoreBlendFunc }, 1154{"rsnProgramStoreDither", "(IZ)V", (void*)nProgramStoreDither }, 1155{"rsnProgramStoreCreate", "(I)I", (void*)nProgramStoreCreate }, 1156 1157{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants }, 1158{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture }, 1159{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler }, 1160 1161{"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate }, 1162 1163{"rsnProgramRasterCreate", "(IZZZ)I", (void*)nProgramRasterCreate }, 1164{"rsnProgramRasterSetLineWidth", "(IIF)V", (void*)nProgramRasterSetLineWidth }, 1165{"rsnProgramRasterSetCullMode", "(III)V", (void*)nProgramRasterSetCullMode }, 1166 1167{"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate }, 1168 1169{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript }, 1170{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore }, 1171{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment }, 1172{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex }, 1173{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster }, 1174 1175{"rsnSamplerBegin", "(I)V", (void*)nSamplerBegin }, 1176{"rsnSamplerSet", "(III)V", (void*)nSamplerSet }, 1177{"rsnSamplerSet2", "(IIF)V", (void*)nSamplerSet2 }, 1178{"rsnSamplerCreate", "(I)I", (void*)nSamplerCreate }, 1179 1180{"rsnMeshCreate", "(III)I", (void*)nMeshCreate }, 1181{"rsnMeshBindVertex", "(IIII)V", (void*)nMeshBindVertex }, 1182{"rsnMeshBindIndex", "(IIIII)V", (void*)nMeshBindIndex }, 1183{"rsnMeshInitVertexAttribs", "(II)V", (void*)nMeshInitVertexAttribs }, 1184 1185{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount }, 1186{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount }, 1187{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices }, 1188{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices }, 1189 1190}; 1191 1192static int registerFuncs(JNIEnv *_env) 1193{ 1194 return android::AndroidRuntime::registerNativeMethods( 1195 _env, classPathName, methods, NELEM(methods)); 1196} 1197 1198// --------------------------------------------------------------------------- 1199 1200jint JNI_OnLoad(JavaVM* vm, void* reserved) 1201{ 1202 JNIEnv* env = NULL; 1203 jint result = -1; 1204 1205 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1206 LOGE("ERROR: GetEnv failed\n"); 1207 goto bail; 1208 } 1209 assert(env != NULL); 1210 1211 if (registerFuncs(env) < 0) { 1212 LOGE("ERROR: MediaPlayer native registration failed\n"); 1213 goto bail; 1214 } 1215 1216 /* success -- return valid version number */ 1217 result = JNI_VERSION_1_4; 1218 1219bail: 1220 return result; 1221} 1222