android_renderscript_RenderScript.cpp revision 0844cefe83fbcb544ed9d16715159d783f2da5f3
1/* 2 * Copyright (C) 2011-2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#define LOG_TAG "libRS_jni" 18 19#include <stdlib.h> 20#include <stdio.h> 21#include <fcntl.h> 22#include <unistd.h> 23#include <math.h> 24#include <android/bitmap.h> 25#include <android/log.h> 26#include "jni.h" 27#include <rs.h> 28#include <rsEnv.h> 29 30#include "rsDispatch.h" 31#include <dlfcn.h> 32 33//#define LOG_API ALOG 34#define LOG_API(...) 35 36#define NELEM(m) (sizeof(m) / sizeof((m)[0])) 37 38class AutoJavaStringToUTF8 { 39public: 40 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { 41 fCStr = env->GetStringUTFChars(str, NULL); 42 fLength = env->GetStringUTFLength(str); 43 } 44 ~AutoJavaStringToUTF8() { 45 fEnv->ReleaseStringUTFChars(fJStr, fCStr); 46 } 47 const char* c_str() const { return fCStr; } 48 jsize length() const { return fLength; } 49 50private: 51 JNIEnv* fEnv; 52 jstring fJStr; 53 const char* fCStr; 54 jsize fLength; 55}; 56 57class AutoJavaStringArrayToUTF8 { 58public: 59 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) 60 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { 61 mCStrings = NULL; 62 mSizeArray = NULL; 63 if (stringsLength > 0) { 64 mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); 65 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); 66 for (jsize ct = 0; ct < stringsLength; ct ++) { 67 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 68 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL); 69 mSizeArray[ct] = mEnv->GetStringUTFLength(s); 70 } 71 } 72 } 73 ~AutoJavaStringArrayToUTF8() { 74 for (jsize ct=0; ct < mStringsLength; ct++) { 75 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 76 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); 77 } 78 free(mCStrings); 79 free(mSizeArray); 80 } 81 const char **c_str() const { return mCStrings; } 82 size_t *c_str_len() const { return mSizeArray; } 83 jsize length() const { return mStringsLength; } 84 85private: 86 JNIEnv *mEnv; 87 jobjectArray mStrings; 88 const char **mCStrings; 89 size_t *mSizeArray; 90 jsize mStringsLength; 91}; 92 93 94// --------------------------------------------------------------------------- 95static dispatchTable dispatchTab; 96 97static jboolean nLoadSO(JNIEnv *_env, jobject _this, jboolean useNative) { 98 void* handle = NULL; 99 if (useNative) { 100 handle = dlopen("libRS.so", RTLD_LAZY | RTLD_LOCAL); 101 } else { 102 handle = dlopen("libRSSupport.so", RTLD_LAZY | RTLD_LOCAL); 103 } 104 if (handle == NULL) { 105 LOG_API("couldn't dlopen %s, %s", filename, dlerror()); 106 return false; 107 } 108 109 if (loadSymbols(handle, dispatchTab) == false) { 110 LOG_API("%s init failed!", filename); 111 return false; 112 } 113 LOG_API("Successfully loaded %s", filename); 114 return true; 115} 116 117// --------------------------------------------------------------------------- 118 119static void 120nContextFinish(JNIEnv *_env, jobject _this, RsContext con) 121{ 122 LOG_API("nContextFinish, con(%p)", con); 123 dispatchTab.ContextFinish(con); 124} 125 126static void 127nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj) 128{ 129 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); 130 dispatchTab.ObjDestroy(con, (void *)obj); 131} 132 133// --------------------------------------------------------------------------- 134 135static jint 136nDeviceCreate(JNIEnv *_env, jobject _this) 137{ 138 LOG_API("nDeviceCreate"); 139 return (jint)dispatchTab.DeviceCreate(); 140} 141 142static void 143nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 144{ 145 LOG_API("nDeviceDestroy"); 146 return dispatchTab.DeviceDestroy((RsDevice)dev); 147} 148 149static void 150nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) 151{ 152 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 153 return dispatchTab.DeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 154} 155 156static jint 157nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct) 158{ 159 LOG_API("nContextCreate"); 160 return (jint)dispatchTab.ContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0); 161} 162 163 164static void 165nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p) 166{ 167 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p); 168 dispatchTab.ContextSetPriority(con, p); 169} 170 171 172 173static void 174nContextDestroy(JNIEnv *_env, jobject _this, RsContext con) 175{ 176 LOG_API("nContextDestroy, con(%p)", con); 177 dispatchTab.ContextDestroy(con); 178} 179 180static void 181nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits) 182{ 183 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 184 dispatchTab.ContextDump((RsContext)con, bits); 185} 186 187 188static jstring 189nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con) 190{ 191 LOG_API("nContextGetErrorMessage, con(%p)", con); 192 char buf[1024]; 193 194 size_t receiveLen; 195 uint32_t subID; 196 int id = dispatchTab.ContextGetMessage(con, 197 buf, sizeof(buf), 198 &receiveLen, sizeof(receiveLen), 199 &subID, sizeof(subID)); 200 if (!id && receiveLen) { 201 // __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, 202 // "message receive buffer too small. %zu", receiveLen); 203 } 204 return _env->NewStringUTF(buf); 205} 206 207static jint 208nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data) 209{ 210 jint len = _env->GetArrayLength(data); 211 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); 212 jint *ptr = _env->GetIntArrayElements(data, NULL); 213 size_t receiveLen; 214 uint32_t subID; 215 int id = dispatchTab.ContextGetMessage(con, 216 ptr, len * 4, 217 &receiveLen, sizeof(receiveLen), 218 &subID, sizeof(subID)); 219 if (!id && receiveLen) { 220 // __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, 221 // "message receive buffer too small. %zu", receiveLen); 222 } 223 _env->ReleaseIntArrayElements(data, ptr, 0); 224 return id; 225} 226 227static jint 228nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData) 229{ 230 LOG_API("nContextPeekMessage, con(%p)", con); 231 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); 232 size_t receiveLen; 233 uint32_t subID; 234 int id = dispatchTab.ContextPeekMessage(con, &receiveLen, sizeof(receiveLen), 235 &subID, sizeof(subID)); 236 auxDataPtr[0] = (jint)subID; 237 auxDataPtr[1] = (jint)receiveLen; 238 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); 239 return id; 240} 241 242static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con) 243{ 244 LOG_API("nContextInitToClient, con(%p)", con); 245 dispatchTab.ContextInitToClient(con); 246} 247 248static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con) 249{ 250 LOG_API("nContextDeinitToClient, con(%p)", con); 251 dispatchTab.ContextDeinitToClient(con); 252} 253 254static void 255nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data) 256{ 257 jint *ptr = NULL; 258 jint len = 0; 259 if (data) { 260 len = _env->GetArrayLength(data); 261 jint *ptr = _env->GetIntArrayElements(data, NULL); 262 } 263 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len); 264 dispatchTab.ContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int)); 265 if (data) { 266 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 267 } 268} 269 270 271 272static jint 273nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size) 274{ 275 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size); 276 return (jint)dispatchTab.ElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size); 277} 278 279static jint 280nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, 281 jintArray _ids, jobjectArray _names, jintArray _arraySizes) 282{ 283 int fieldCount = _env->GetArrayLength(_ids); 284 LOG_API("nElementCreate2, con(%p)", con); 285 286 jint *ids = _env->GetIntArrayElements(_ids, NULL); 287 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL); 288 289 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); 290 291 const char **nameArray = names.c_str(); 292 size_t *sizeArray = names.c_str_len(); 293 294 jint id = (jint)dispatchTab.ElementCreate2(con, 295 (RsElement *)ids, fieldCount, 296 nameArray, fieldCount * sizeof(size_t), sizeArray, 297 (const uint32_t *)arraySizes, fieldCount); 298 299 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); 300 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT); 301 return (jint)id; 302} 303 304 305 306static void 307nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, 308 jintArray _IDs, 309 jobjectArray _names, 310 jintArray _arraySizes) 311{ 312 int dataSize = _env->GetArrayLength(_IDs); 313 LOG_API("nElementGetSubElements, con(%p)", con); 314 315 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 316 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); 317 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 318 319 dispatchTab.ElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize); 320 321 for(jint i = 0; i < dataSize; i++) { 322 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 323 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); 324 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]); 325 } 326 327 free(ids); 328 free(names); 329 free(arraySizes); 330} 331 332// ----------------------------------- 333 334static int 335nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid, 336 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) 337{ 338 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", 339 con, eid, dimx, dimy, dimz, mips, faces, yuv); 340 341 jint id = (jint)dispatchTab.TypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv); 342 return (jint)id; 343} 344 345// ----------------------------------- 346 347static jint 348nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer) 349{ 350 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer); 351 return (jint) dispatchTab.AllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer); 352} 353 354static void 355nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits) 356{ 357 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits); 358 dispatchTab.AllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits); 359} 360 361static void 362nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc) 363{ 364 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc); 365 dispatchTab.AllocationGenerateMipmaps(con, (RsAllocation)alloc); 366} 367 368static size_t GetBitmapSize(JNIEnv *env, jobject jbitmap) { 369 AndroidBitmapInfo info; 370 memset(&info, 0, sizeof(info)); 371 AndroidBitmap_getInfo(env, jbitmap, &info); 372 size_t s = info.width * info.height; 373 switch (info.format) { 374 case ANDROID_BITMAP_FORMAT_RGBA_8888: s *= 4; break; 375 case ANDROID_BITMAP_FORMAT_RGB_565: s *= 2; break; 376 case ANDROID_BITMAP_FORMAT_RGBA_4444: s *= 2; break; 377 } 378 return s; 379} 380 381static int 382nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 383{ 384 jint id = 0; 385 void *pixels = NULL; 386 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 387 388 if (pixels != NULL) { 389 id = (jint)dispatchTab.AllocationCreateFromBitmap(con, 390 (RsType)type, (RsAllocationMipmapControl)mip, 391 pixels, GetBitmapSize(_env, jbitmap), usage); 392 AndroidBitmap_unlockPixels(_env, jbitmap); 393 } 394 return id; 395} 396 397static int 398nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 399{ 400 jint id = 0; 401 void *pixels = NULL; 402 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 403 404 if (pixels != NULL) { 405 id = (jint)dispatchTab.AllocationCreateTyped(con, 406 (RsType)type, (RsAllocationMipmapControl)mip, 407 (uint32_t)usage, (uintptr_t)pixels); 408 AndroidBitmap_unlockPixels(_env, jbitmap); 409 } 410 return id; 411} 412 413static int 414nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 415{ 416 void *pixels = NULL; 417 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 418 419 jint id = 0; 420 if (pixels != NULL) { 421 id = (jint)dispatchTab.AllocationCubeCreateFromBitmap(con, 422 (RsType)type, (RsAllocationMipmapControl)mip, 423 pixels, GetBitmapSize(_env, jbitmap), usage); 424 AndroidBitmap_unlockPixels(_env, jbitmap); 425 } 426 return id; 427} 428 429static void 430nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 431{ 432 AndroidBitmapInfo info; 433 memset(&info, 0, sizeof(info)); 434 AndroidBitmap_getInfo(_env, jbitmap, &info); 435 436 void *pixels = NULL; 437 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 438 439 if (pixels != NULL) { 440 dispatchTab.Allocation2DData(con, (RsAllocation)alloc, 0, 0, 441 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 442 info.width, info.height, pixels, GetBitmapSize(_env, jbitmap), 0); 443 AndroidBitmap_unlockPixels(_env, jbitmap); 444 } 445} 446 447static void 448nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 449{ 450 AndroidBitmapInfo info; 451 memset(&info, 0, sizeof(info)); 452 AndroidBitmap_getInfo(_env, jbitmap, &info); 453 454 void *pixels = NULL; 455 AndroidBitmap_lockPixels(_env, jbitmap, &pixels); 456 457 if (pixels != NULL) { 458 dispatchTab.AllocationCopyToBitmap(con, (RsAllocation)alloc, pixels, GetBitmapSize(_env, jbitmap)); 459 AndroidBitmap_unlockPixels(_env, jbitmap); 460 } 461 //bitmap.notifyPixelsChanged(); 462} 463 464 465static void 466nAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes) 467{ 468 jint len = _env->GetArrayLength(data); 469 LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 470 jint *ptr = _env->GetIntArrayElements(data, NULL); 471 dispatchTab.Allocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 472 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 473} 474 475static void 476nAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes) 477{ 478 jint len = _env->GetArrayLength(data); 479 LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 480 jshort *ptr = _env->GetShortArrayElements(data, NULL); 481 dispatchTab.Allocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 482 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 483} 484 485static void 486nAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes) 487{ 488 jint len = _env->GetArrayLength(data); 489 LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 490 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 491 dispatchTab.Allocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 492 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 493} 494 495static void 496nAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes) 497{ 498 jint len = _env->GetArrayLength(data); 499 LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 500 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 501 dispatchTab.Allocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 502 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 503} 504 505static void 506// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); 507nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes) 508{ 509 jint len = _env->GetArrayLength(data); 510 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); 511 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 512 dispatchTab.Allocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx); 513 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 514} 515 516static void 517nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 518 jint w, jint h, jshortArray data, int sizeBytes) 519{ 520 jint len = _env->GetArrayLength(data); 521 LOG_API("nAllocation2DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 522 jshort *ptr = _env->GetShortArrayElements(data, NULL); 523 dispatchTab.Allocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 524 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 525} 526 527static void 528nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 529 jint w, jint h, jbyteArray data, int sizeBytes) 530{ 531 jint len = _env->GetArrayLength(data); 532 LOG_API("nAllocation2DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 533 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 534 dispatchTab.Allocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 535 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 536} 537 538static void 539nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 540 jint w, jint h, jintArray data, int sizeBytes) 541{ 542 jint len = _env->GetArrayLength(data); 543 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); 544 jint *ptr = _env->GetIntArrayElements(data, NULL); 545 dispatchTab.Allocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 546 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 547} 548 549static void 550nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 551 jint w, jint h, jfloatArray data, int sizeBytes) 552{ 553 jint len = _env->GetArrayLength(data); 554 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); 555 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 556 dispatchTab.Allocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0); 557 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 558} 559 560static void 561nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con, 562 jint dstAlloc, jint dstXoff, jint dstYoff, 563 jint dstMip, jint dstFace, 564 jint width, jint height, 565 jint srcAlloc, jint srcXoff, jint srcYoff, 566 jint srcMip, jint srcFace) 567{ 568 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 569 " dstMip(%i), dstFace(%i), width(%i), height(%i)," 570 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", 571 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 572 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 573 574 dispatchTab.AllocationCopy2DRange(con, 575 (RsAllocation)dstAlloc, 576 dstXoff, dstYoff, 577 dstMip, dstFace, 578 width, height, 579 (RsAllocation)srcAlloc, 580 srcXoff, srcYoff, 581 srcMip, srcFace); 582} 583 584static void 585nAllocationData3D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 586 jint w, jint h, jint d, jshortArray data, int sizeBytes) 587{ 588 jint len = _env->GetArrayLength(data); 589 LOG_API("nAllocation3DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 590 jshort *ptr = _env->GetShortArrayElements(data, NULL); 591 dispatchTab.Allocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 592 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 593} 594 595static void 596nAllocationData3D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 597 jint w, jint h, jint d, jbyteArray data, int sizeBytes) 598{ 599 jint len = _env->GetArrayLength(data); 600 LOG_API("nAllocation3DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 601 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 602 dispatchTab.Allocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 603 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 604} 605 606static void 607nAllocationData3D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 608 jint w, jint h, jint d, jintArray data, int sizeBytes) 609{ 610 jint len = _env->GetArrayLength(data); 611 LOG_API("nAllocation3DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 612 jint *ptr = _env->GetIntArrayElements(data, NULL); 613 dispatchTab.Allocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 614 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 615} 616 617static void 618nAllocationData3D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod, 619 jint w, jint h, jint d, jfloatArray data, int sizeBytes) 620{ 621 jint len = _env->GetArrayLength(data); 622 LOG_API("nAllocation3DData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len); 623 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 624 dispatchTab.Allocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); 625 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 626} 627 628static void 629nAllocationData3D_alloc(JNIEnv *_env, jobject _this, RsContext con, 630 jint dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff, 631 jint dstMip, 632 jint width, jint height, jint depth, 633 jint srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, 634 jint srcMip) 635{ 636 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 637 " dstMip(%i), width(%i), height(%i)," 638 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", 639 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 640 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 641 642 dispatchTab.AllocationCopy3DRange(con, 643 (RsAllocation)dstAlloc, 644 dstXoff, dstYoff, dstZoff, dstMip, 645 width, height, depth, 646 (RsAllocation)srcAlloc, 647 srcXoff, srcYoff, srcZoff, srcMip); 648} 649 650static void 651nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data) 652{ 653 jint len = _env->GetArrayLength(data); 654 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 655 jint *ptr = _env->GetIntArrayElements(data, NULL); 656 jsize length = _env->GetArrayLength(data); 657 dispatchTab.AllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int)); 658 _env->ReleaseIntArrayElements(data, ptr, 0); 659} 660 661static void 662nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data) 663{ 664 jint len = _env->GetArrayLength(data); 665 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 666 jshort *ptr = _env->GetShortArrayElements(data, NULL); 667 jsize length = _env->GetArrayLength(data); 668 dispatchTab.AllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short)); 669 _env->ReleaseShortArrayElements(data, ptr, 0); 670} 671 672static void 673nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data) 674{ 675 jint len = _env->GetArrayLength(data); 676 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 677 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 678 jsize length = _env->GetArrayLength(data); 679 dispatchTab.AllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char)); 680 _env->ReleaseByteArrayElements(data, ptr, 0); 681} 682 683static void 684nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data) 685{ 686 jint len = _env->GetArrayLength(data); 687 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 688 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 689 jsize length = _env->GetArrayLength(data); 690 dispatchTab.AllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float)); 691 _env->ReleaseFloatArrayElements(data, ptr, 0); 692} 693 694static jint 695nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a) 696{ 697 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a); 698 return (jint) dispatchTab.AllocationGetType(con, (RsAllocation)a); 699} 700 701static void 702nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX) 703{ 704 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX); 705 dispatchTab.AllocationResize1D(con, (RsAllocation)alloc, dimX); 706} 707 708// ----------------------------------- 709 710static void 711nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot) 712{ 713 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); 714 dispatchTab.ScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); 715} 716 717static void 718nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 719{ 720 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 721 dispatchTab.ScriptSetVarI(con, (RsScript)script, slot, val); 722} 723 724static void 725nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 726{ 727 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 728 dispatchTab.ScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val); 729} 730 731static void 732nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val) 733{ 734 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val); 735 dispatchTab.ScriptSetVarJ(con, (RsScript)script, slot, val); 736} 737 738static void 739nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val) 740{ 741 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val); 742 dispatchTab.ScriptSetVarF(con, (RsScript)script, slot, val); 743} 744 745static void 746nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val) 747{ 748 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val); 749 dispatchTab.ScriptSetVarD(con, (RsScript)script, slot, val); 750} 751 752static void 753nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 754{ 755 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 756 jint len = _env->GetArrayLength(data); 757 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 758 dispatchTab.ScriptSetVarV(con, (RsScript)script, slot, ptr, len); 759 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 760} 761 762static void 763nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims) 764{ 765 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 766 jint len = _env->GetArrayLength(data); 767 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 768 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); 769 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL); 770 dispatchTab.ScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem, 771 (const uint32_t *)dimsPtr, dimsLen); 772 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 773 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); 774} 775 776 777static void 778nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone) 779{ 780 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone); 781 782 jint length = _env->GetArrayLength(timeZone); 783 jbyte* timeZone_ptr; 784 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 785 786 dispatchTab.ScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); 787 788 if (timeZone_ptr) { 789 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 790 } 791} 792 793static void 794nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot) 795{ 796 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); 797 dispatchTab.ScriptInvoke(con, (RsScript)obj, slot); 798} 799 800static void 801nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 802{ 803 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 804 jint len = _env->GetArrayLength(data); 805 jbyte *ptr = _env->GetByteArrayElements(data, NULL); 806 dispatchTab.ScriptInvokeV(con, (RsScript)script, slot, ptr, len); 807 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 808} 809 810static void 811nScriptForEach(JNIEnv *_env, jobject _this, RsContext con, 812 jint script, jint slot, jint ain, jint aout) 813{ 814 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 815 dispatchTab.ScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0); 816} 817static void 818nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con, 819 jint script, jint slot, jint ain, jint aout, jbyteArray params) 820{ 821 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 822 jint len = _env->GetArrayLength(params); 823 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 824 dispatchTab.ScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0); 825 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 826} 827 828static void 829nScriptForEachClipped(JNIEnv *_env, jobject _this, RsContext con, 830 jint script, jint slot, jint ain, jint aout, 831 jint xstart, jint xend, 832 jint ystart, jint yend, jint zstart, jint zend) 833{ 834 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 835 RsScriptCall sc; 836 sc.xStart = xstart; 837 sc.xEnd = xend; 838 sc.yStart = ystart; 839 sc.yEnd = yend; 840 sc.zStart = zstart; 841 sc.zEnd = zend; 842 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 843 sc.arrayStart = 0; 844 sc.arrayEnd = 0; 845 dispatchTab.ScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); 846} 847 848static void 849nScriptForEachClippedV(JNIEnv *_env, jobject _this, RsContext con, 850 jint script, jint slot, jint ain, jint aout, 851 jbyteArray params, jint xstart, jint xend, 852 jint ystart, jint yend, jint zstart, jint zend) 853{ 854 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 855 jint len = _env->GetArrayLength(params); 856 jbyte *ptr = _env->GetByteArrayElements(params, NULL); 857 RsScriptCall sc; 858 sc.xStart = xstart; 859 sc.xEnd = xend; 860 sc.yStart = ystart; 861 sc.yEnd = yend; 862 sc.zStart = zstart; 863 sc.zEnd = zend; 864 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; 865 sc.arrayStart = 0; 866 sc.arrayEnd = 0; 867 dispatchTab.ScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc)); 868 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 869} 870 871// ----------------------------------- 872 873static jint 874nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, 875 jstring resName, jstring cacheDir, 876 jbyteArray scriptRef, jint length) 877{ 878 LOG_API("nScriptCCreate, con(%p)", con); 879 880 AutoJavaStringToUTF8 resNameUTF(_env, resName); 881 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); 882 jint ret = 0; 883 jbyte* script_ptr = NULL; 884 jint _exception = 0; 885 jint remaining; 886 if (!scriptRef) { 887 _exception = 1; 888 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); 889 goto exit; 890 } 891 if (length < 0) { 892 _exception = 1; 893 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); 894 goto exit; 895 } 896 remaining = _env->GetArrayLength(scriptRef); 897 if (remaining < length) { 898 _exception = 1; 899 //jniThrowException(_env, "java/lang/IllegalArgumentException", 900 // "length > script.length - offset"); 901 goto exit; 902 } 903 script_ptr = (jbyte *) 904 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 905 906 //rsScriptCSetText(con, (const char *)script_ptr, length); 907 908 ret = (jint)dispatchTab.ScriptCCreate(con, 909 resNameUTF.c_str(), resNameUTF.length(), 910 cacheDirUTF.c_str(), cacheDirUTF.length(), 911 (const char *)script_ptr, length); 912 913exit: 914 if (script_ptr) { 915 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, 916 _exception ? JNI_ABORT: 0); 917 } 918 919 return ret; 920} 921 922static jint 923nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid) 924{ 925 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid); 926 return (jint)dispatchTab.ScriptIntrinsicCreate(con, id, (RsElement)eid); 927} 928 929static jint 930nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig) 931{ 932 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig); 933 return (jint)dispatchTab.ScriptKernelIDCreate(con, (RsScript)sid, slot, sig); 934} 935 936static jint 937nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot) 938{ 939 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot); 940 return (jint)dispatchTab.ScriptFieldIDCreate(con, (RsScript)sid, slot); 941} 942 943static jint 944nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src, 945 jintArray _dstk, jintArray _dstf, jintArray _types) 946{ 947 LOG_API("nScriptGroupCreate, con(%p)", con); 948 949 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int); 950 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL); 951 jint srcLen = _env->GetArrayLength(_src) * sizeof(int); 952 jint *srcPtr = _env->GetIntArrayElements(_src, NULL); 953 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int); 954 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL); 955 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int); 956 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL); 957 jint typesLen = _env->GetArrayLength(_types) * sizeof(int); 958 jint *typesPtr = _env->GetIntArrayElements(_types, NULL); 959 960 int id = (int)dispatchTab.ScriptGroupCreate(con, 961 (RsScriptKernelID *)kernelsPtr, kernelsLen, 962 (RsScriptKernelID *)srcPtr, srcLen, 963 (RsScriptKernelID *)dstkPtr, dstkLen, 964 (RsScriptFieldID *)dstfPtr, dstfLen, 965 (RsType *)typesPtr, typesLen); 966 967 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0); 968 _env->ReleaseIntArrayElements(_src, srcPtr, 0); 969 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0); 970 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0); 971 _env->ReleaseIntArrayElements(_types, typesPtr, 0); 972 return id; 973} 974 975static void 976nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc) 977{ 978 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con, 979 (void *)gid, (void *)kid, (void *)alloc); 980 dispatchTab.ScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 981} 982 983static void 984nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc) 985{ 986 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con, 987 (void *)gid, (void *)kid, (void *)alloc); 988 dispatchTab.ScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); 989} 990 991static void 992nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid) 993{ 994 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid); 995 dispatchTab.ScriptGroupExecute(con, (RsScriptGroup)gid); 996} 997 998// --------------------------------------------------------------------------- 999 1000static jint 1001nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter, 1002 jint wrapS, jint wrapT, jint wrapR, jfloat aniso) 1003{ 1004 LOG_API("nSamplerCreate, con(%p)", con); 1005 return (jint)dispatchTab.SamplerCreate(con, 1006 (RsSamplerValue)magFilter, 1007 (RsSamplerValue)minFilter, 1008 (RsSamplerValue)wrapS, 1009 (RsSamplerValue)wrapT, 1010 (RsSamplerValue)wrapR, 1011 aniso); 1012} 1013 1014// --------------------------------------------------------------------------- 1015 1016 1017static const char *classPathName = "android/support/v8/renderscript/RenderScript"; 1018 1019static JNINativeMethod methods[] = { 1020{"nLoadSO", "(Z)Z", (bool*)nLoadSO }, 1021{"nDeviceCreate", "()I", (void*)nDeviceCreate }, 1022{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, 1023{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, 1024{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage }, 1025{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage }, 1026{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage }, 1027 1028{"nContextInitToClient", "(I)V", (void*)nContextInitToClient }, 1029{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient }, 1030 1031 1032// All methods below are thread protected in java. 1033{"rsnContextCreate", "(IIII)I", (void*)nContextCreate }, 1034{"rsnContextFinish", "(I)V", (void*)nContextFinish }, 1035{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority }, 1036{"rsnContextDestroy", "(I)V", (void*)nContextDestroy }, 1037{"rsnContextDump", "(II)V", (void*)nContextDump }, 1038{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage }, 1039{"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, 1040 1041{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, 1042{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, 1043{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, 1044 1045{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate }, 1046 1047{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped }, 1048{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, 1049{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation }, 1050{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, 1051 1052{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, 1053{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, 1054 1055{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll }, 1056{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i }, 1057{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s }, 1058{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b }, 1059{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f }, 1060{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D }, 1061{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i }, 1062{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s }, 1063{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b }, 1064{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f }, 1065{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc }, 1066{"rsnAllocationData3D", "(IIIIIIIII[II)V", (void*)nAllocationData3D_i }, 1067{"rsnAllocationData3D", "(IIIIIIIII[SI)V", (void*)nAllocationData3D_s }, 1068{"rsnAllocationData3D", "(IIIIIIIII[BI)V", (void*)nAllocationData3D_b }, 1069{"rsnAllocationData3D", "(IIIIIIIII[FI)V", (void*)nAllocationData3D_f }, 1070{"rsnAllocationData3D", "(IIIIIIIIIIIIII)V", (void*)nAllocationData3D_alloc }, 1071{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i }, 1072{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s }, 1073{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b }, 1074{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f }, 1075{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType}, 1076{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D }, 1077{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps }, 1078 1079{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation }, 1080{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone }, 1081{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke }, 1082{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV }, 1083{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach }, 1084{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV }, 1085{"rsnScriptForEachClipped", "(IIIIIIIIIII)V", (void*)nScriptForEachClipped }, 1086{"rsnScriptForEachClipped", "(IIIII[BIIIIII)V", (void*)nScriptForEachClippedV }, 1087{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI }, 1088{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ }, 1089{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF }, 1090{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD }, 1091{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, 1092{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE }, 1093{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, 1094 1095{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate }, 1096{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate }, 1097{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate }, 1098{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate }, 1099{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate }, 1100{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput }, 1101{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput }, 1102{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute }, 1103 1104{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate }, 1105 1106}; 1107 1108// --------------------------------------------------------------------------- 1109 1110jint JNI_OnLoad(JavaVM* vm, void* reserved) 1111{ 1112 JNIEnv* env = NULL; 1113 jclass clazz = NULL; 1114 jint result = -1; 1115 1116 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1117 // __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, 1118 // "ERROR: GetEnv failed\n"); 1119 goto bail; 1120 } 1121 if (env == NULL) { 1122 // __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "ERROR: env == NULL"); 1123 goto bail; 1124 } 1125 1126 clazz = env->FindClass(classPathName); 1127 if (clazz == NULL) { 1128 goto bail; 1129 } 1130 1131 if (env->RegisterNatives(clazz, methods, NELEM(methods)) < 0) { 1132 // __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, 1133 // "ERROR: MediaPlayer native registration failed\n"); 1134 goto bail; 1135 } 1136 1137 /* success -- return valid version number */ 1138 result = JNI_VERSION_1_4; 1139 1140bail: 1141 return result; 1142} 1143