2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "libRS_jni"
24 #include <utils/misc.h>
26 #include <surfaceflinger/Surface.h>
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>
34 #include <utils/Asset.h>
35 #include <utils/AssetManager.h>
36 #include <utils/ResourceTypes.h>
40 #include "android_runtime/AndroidRuntime.h"
41 #include "android_runtime/android_view_Surface.h"
42 #include "android_runtime/android_util_AssetManager.h"
44 #include <RenderScript.h>
45 #include <RenderScriptEnv.h>
46 #include <gui/SurfaceTexture.h>
47 #include <gui/SurfaceTextureClient.h>
48 #include <android_runtime/android_graphics_SurfaceTexture.h>
50 //#define LOG_API LOGE
53 using namespace android;
55 class AutoJavaStringToUTF8 {
57 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str)
59 fCStr = env->GetStringUTFChars(str, NULL);
60 fLength = env->GetStringUTFLength(str);
62 ~AutoJavaStringToUTF8()
64 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
66 const char* c_str() const { return fCStr; }
67 jsize length() const { return fLength; }
76 // ---------------------------------------------------------------------------
78 static jfieldID gContextId = 0;
79 static jfieldID gNativeBitmapID = 0;
80 static jfieldID gTypeNativeCache = 0;
82 static void _nInit(JNIEnv *_env, jclass _this)
84 gContextId = _env->GetFieldID(_this, "mContext", "I");
86 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
87 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
90 // ---------------------------------------------------------------------------
93 nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
95 LOG_API("nContextFinish, con(%p)", con);
100 nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
102 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
103 jint len = _env->GetArrayLength(str);
104 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
105 rsAssignName(con, (void *)obj, (const char *)cptr, len);
106 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
110 nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
112 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
113 const char *name = NULL;
114 rsaGetName(con, (void *)obj, &name);
115 if(name == NULL || strlen(name) == 0) {
118 return _env->NewStringUTF(name);
122 nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
124 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
125 rsObjDestroy(con, (void *)obj);
128 // ---------------------------------------------------------------------------
131 nDeviceCreate(JNIEnv *_env, jobject _this)
133 LOG_API("nDeviceCreate");
134 return (jint)rsDeviceCreate();
138 nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
140 LOG_API("nDeviceDestroy");
141 return rsDeviceDestroy((RsDevice)dev);
145 nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
147 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
148 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
152 nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer)
154 LOG_API("nContextCreate");
155 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer);
159 nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
160 int colorMin, int colorPref,
161 int alphaMin, int alphaPref,
162 int depthMin, int depthPref,
163 int stencilMin, int stencilPref,
164 int samplesMin, int samplesPref, float samplesQ,
168 sc.alphaMin = alphaMin;
169 sc.alphaPref = alphaPref;
170 sc.colorMin = colorMin;
171 sc.colorPref = colorPref;
172 sc.depthMin = depthMin;
173 sc.depthPref = depthPref;
174 sc.samplesMin = samplesMin;
175 sc.samplesPref = samplesPref;
176 sc.samplesQ = samplesQ;
178 LOG_API("nContextCreateGL");
179 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
183 nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
185 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
186 rsContextSetPriority(con, p);
192 nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
194 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
196 ANativeWindow * window = NULL;
200 window = android_Surface_getNativeWindow(_env, wnd).get();
203 rsContextSetSurface(con, width, height, window);
207 nContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
209 LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);
211 sp<ANativeWindow> window;
212 sp<SurfaceTexture> st;
216 st = SurfaceTexture_getSurfaceTexture(_env, sur);
217 window = new SurfaceTextureClient(st);
220 rsContextSetSurface(con, width, height, window.get());
224 nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
226 LOG_API("nContextDestroy, con(%p)", con);
227 rsContextDestroy(con);
231 nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
233 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
234 rsContextDump((RsContext)con, bits);
238 nContextPause(JNIEnv *_env, jobject _this, RsContext con)
240 LOG_API("nContextPause, con(%p)", con);
245 nContextResume(JNIEnv *_env, jobject _this, RsContext con)
247 LOG_API("nContextResume, con(%p)", con);
248 rsContextResume(con);
253 nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
255 LOG_API("nContextGetErrorMessage, con(%p)", con);
260 int id = rsContextGetMessage(con,
262 &receiveLen, sizeof(receiveLen),
263 &subID, sizeof(subID));
264 if (!id && receiveLen) {
265 LOGV("message receive buffer too small. %i", receiveLen);
267 return _env->NewStringUTF(buf);
271 nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
273 jint len = _env->GetArrayLength(data);
274 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
275 jint *ptr = _env->GetIntArrayElements(data, NULL);
278 int id = rsContextGetMessage(con,
280 &receiveLen, sizeof(receiveLen),
281 &subID, sizeof(subID));
282 if (!id && receiveLen) {
283 LOGV("message receive buffer too small. %i", receiveLen);
285 _env->ReleaseIntArrayElements(data, ptr, 0);
290 nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
292 LOG_API("nContextPeekMessage, con(%p)", con);
293 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
296 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
297 &subID, sizeof(subID));
298 auxDataPtr[0] = (jint)subID;
299 auxDataPtr[1] = (jint)receiveLen;
300 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
304 static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
306 LOG_API("nContextInitToClient, con(%p)", con);
307 rsContextInitToClient(con);
310 static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
312 LOG_API("nContextDeinitToClient, con(%p)", con);
313 rsContextDeinitToClient(con);
318 nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
320 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
321 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
325 nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes)
327 int fieldCount = _env->GetArrayLength(_ids);
328 LOG_API("nElementCreate2, con(%p)", con);
330 jint *ids = _env->GetIntArrayElements(_ids, NULL);
331 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
332 const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
333 size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
335 for (int ct=0; ct < fieldCount; ct++) {
336 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
337 nameArray[ct] = _env->GetStringUTFChars(s, NULL);
338 sizeArray[ct] = _env->GetStringUTFLength(s);
340 jint id = (jint)rsElementCreate2(con,
341 (RsElement *)ids, fieldCount,
342 nameArray, fieldCount * sizeof(size_t), sizeArray,
343 (const uint32_t *)arraySizes, fieldCount);
344 for (int ct=0; ct < fieldCount; ct++) {
345 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
346 _env->ReleaseStringUTFChars(s, nameArray[ct]);
348 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
349 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
356 nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
358 int dataSize = _env->GetArrayLength(_elementData);
359 LOG_API("nElementGetNativeData, con(%p)", con);
361 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
362 assert(dataSize == 5);
364 uint32_t elementData[5];
365 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
367 for(jint i = 0; i < dataSize; i ++) {
368 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
374 nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
377 jintArray _arraySizes)
379 int dataSize = _env->GetArrayLength(_IDs);
380 LOG_API("nElementGetSubElements, con(%p)", con);
382 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
383 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
384 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
386 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
388 for(jint i = 0; i < dataSize; i++) {
389 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
390 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
391 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
399 // -----------------------------------
402 nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
403 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
405 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
406 con, eid, dimx, dimy, dimz, mips, faces);
408 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
413 nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
415 // We are packing 6 items: mDimX; mDimY; mDimZ;
416 // mDimLOD; mDimFaces; mElement; into typeData
417 int elementCount = _env->GetArrayLength(_typeData);
419 assert(elementCount == 6);
420 LOG_API("nTypeCreate, con(%p)", con);
422 uint32_t typeData[6];
423 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
425 for(jint i = 0; i < elementCount; i ++) {
426 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
430 // -----------------------------------
433 nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage)
435 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage);
436 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage);
440 nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
442 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
443 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
447 nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
449 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
450 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
454 nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
456 SkBitmap const * nativeBitmap =
457 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
458 const SkBitmap& bitmap(*nativeBitmap);
461 const void* ptr = bitmap.getPixels();
462 jint id = (jint)rsAllocationCreateFromBitmap(con,
463 (RsType)type, (RsAllocationMipmapControl)mip,
464 ptr, bitmap.getSize(), usage);
465 bitmap.unlockPixels();
470 nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
472 SkBitmap const * nativeBitmap =
473 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
474 const SkBitmap& bitmap(*nativeBitmap);
477 const void* ptr = bitmap.getPixels();
478 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
479 (RsType)type, (RsAllocationMipmapControl)mip,
480 ptr, bitmap.getSize(), usage);
481 bitmap.unlockPixels();
486 nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
488 SkBitmap const * nativeBitmap =
489 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
490 const SkBitmap& bitmap(*nativeBitmap);
491 int w = bitmap.width();
492 int h = bitmap.height();
495 const void* ptr = bitmap.getPixels();
496 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
497 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
498 w, h, ptr, bitmap.getSize());
499 bitmap.unlockPixels();
503 nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
505 SkBitmap const * nativeBitmap =
506 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
507 const SkBitmap& bitmap(*nativeBitmap);
510 void* ptr = bitmap.getPixels();
511 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
512 bitmap.unlockPixels();
513 bitmap.notifyPixelsChanged();
516 static void ReleaseBitmapCallback(void *bmp)
518 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
519 nativeBitmap->unlockPixels();
524 nAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes)
526 jint len = _env->GetArrayLength(data);
527 LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
528 jint *ptr = _env->GetIntArrayElements(data, NULL);
529 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
530 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
534 nAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes)
536 jint len = _env->GetArrayLength(data);
537 LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
538 jshort *ptr = _env->GetShortArrayElements(data, NULL);
539 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
540 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
544 nAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes)
546 jint len = _env->GetArrayLength(data);
547 LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
548 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
549 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
550 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
554 nAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes)
556 jint len = _env->GetArrayLength(data);
557 LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
558 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
559 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
560 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
564 // native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
565 nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes)
567 jint len = _env->GetArrayLength(data);
568 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
569 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
570 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, compIdx, sizeBytes);
571 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
575 nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
576 jint w, jint h, jshortArray data, int sizeBytes)
578 jint len = _env->GetArrayLength(data);
579 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);
580 jshort *ptr = _env->GetShortArrayElements(data, NULL);
581 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
582 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
586 nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
587 jint w, jint h, jbyteArray data, int sizeBytes)
589 jint len = _env->GetArrayLength(data);
590 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);
591 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
592 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
593 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
597 nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
598 jint w, jint h, jintArray data, int sizeBytes)
600 jint len = _env->GetArrayLength(data);
601 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);
602 jint *ptr = _env->GetIntArrayElements(data, NULL);
603 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
604 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
608 nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
609 jint w, jint h, jfloatArray data, int sizeBytes)
611 jint len = _env->GetArrayLength(data);
612 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);
613 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
614 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
615 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
619 nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
620 jint dstAlloc, jint dstXoff, jint dstYoff,
621 jint dstMip, jint dstFace,
622 jint width, jint height,
623 jint srcAlloc, jint srcXoff, jint srcYoff,
624 jint srcMip, jint srcFace)
626 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff, dstYoff,"
627 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
628 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
629 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
630 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
632 rsAllocationCopy2DRange(con,
633 (RsAllocation)dstAlloc,
637 (RsAllocation)srcAlloc,
643 nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
645 jint len = _env->GetArrayLength(data);
646 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
647 jint *ptr = _env->GetIntArrayElements(data, NULL);
648 jsize length = _env->GetArrayLength(data);
649 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
650 _env->ReleaseIntArrayElements(data, ptr, 0);
654 nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
656 jint len = _env->GetArrayLength(data);
657 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
658 jshort *ptr = _env->GetShortArrayElements(data, NULL);
659 jsize length = _env->GetArrayLength(data);
660 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
661 _env->ReleaseShortArrayElements(data, ptr, 0);
665 nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
667 jint len = _env->GetArrayLength(data);
668 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
669 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
670 jsize length = _env->GetArrayLength(data);
671 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
672 _env->ReleaseByteArrayElements(data, ptr, 0);
676 nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
678 jint len = _env->GetArrayLength(data);
679 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
680 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
681 jsize length = _env->GetArrayLength(data);
682 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
683 _env->ReleaseFloatArrayElements(data, ptr, 0);
687 nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
689 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
690 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
694 nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
696 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
697 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
701 nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
703 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
704 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
707 // -----------------------------------
710 nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
712 LOGV("______nFileA3D %u", (uint32_t) native_asset);
714 Asset* asset = reinterpret_cast<Asset*>(native_asset);
716 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
721 nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
723 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
728 AutoJavaStringToUTF8 str(_env, _path);
729 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
734 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
739 nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
741 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
742 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
748 nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
750 int32_t numEntries = 0;
751 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
756 nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
758 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
759 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
761 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
763 for(jint i = 0; i < numEntries; i ++) {
764 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
765 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
772 nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
774 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
775 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
779 // -----------------------------------
782 nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
783 jstring fileName, jfloat fontSize, jint dpi)
785 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
786 jint id = (jint)rsFontCreateFromFile(con,
787 fileNameUTF.c_str(), fileNameUTF.length(),
794 nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
795 jstring name, jfloat fontSize, jint dpi, jint native_asset)
797 Asset* asset = reinterpret_cast<Asset*>(native_asset);
798 AutoJavaStringToUTF8 nameUTF(_env, name);
800 jint id = (jint)rsFontCreateFromMemory(con,
801 nameUTF.c_str(), nameUTF.length(),
803 asset->getBuffer(false), asset->getLength());
808 nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
809 jfloat fontSize, jint dpi)
811 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
816 AutoJavaStringToUTF8 str(_env, _path);
817 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
822 jint id = (jint)rsFontCreateFromMemory(con,
823 str.c_str(), str.length(),
825 asset->getBuffer(false), asset->getLength());
830 // -----------------------------------
833 nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
835 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
836 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
840 nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
842 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
843 rsScriptSetVarI(con, (RsScript)script, slot, val);
847 nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
849 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
850 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
854 nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
856 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
857 rsScriptSetVarJ(con, (RsScript)script, slot, val);
861 nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
863 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
864 rsScriptSetVarF(con, (RsScript)script, slot, val);
868 nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
870 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
871 rsScriptSetVarD(con, (RsScript)script, slot, val);
875 nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
877 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
878 jint len = _env->GetArrayLength(data);
879 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
880 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
881 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
886 nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
888 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
890 jint length = _env->GetArrayLength(timeZone);
892 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
894 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
897 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
902 nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
904 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
905 rsScriptInvoke(con, (RsScript)obj, slot);
909 nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
911 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
912 jint len = _env->GetArrayLength(data);
913 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
914 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
915 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
919 nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
920 jint script, jint slot, jint ain, jint aout)
922 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
923 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
926 nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
927 jint script, jint slot, jint ain, jint aout, jbyteArray params)
929 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
930 jint len = _env->GetArrayLength(params);
931 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
932 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
933 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
937 // -----------------------------------
940 nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
941 jstring resName, jstring cacheDir,
942 jbyteArray scriptRef, jint length)
944 LOG_API("nScriptCCreate, con(%p)", con);
946 AutoJavaStringToUTF8 resNameUTF(_env, resName);
947 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
949 jbyte* script_ptr = NULL;
954 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
959 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
962 remaining = _env->GetArrayLength(scriptRef);
963 if (remaining < length) {
965 //jniThrowException(_env, "java/lang/IllegalArgumentException",
966 // "length > script.length - offset");
969 script_ptr = (jbyte *)
970 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
972 //rsScriptCSetText(con, (const char *)script_ptr, length);
974 ret = (jint)rsScriptCCreate(con,
975 resNameUTF.c_str(), resNameUTF.length(),
976 cacheDirUTF.c_str(), cacheDirUTF.length(),
977 (const char *)script_ptr, length);
981 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
982 _exception ? JNI_ABORT: 0);
988 // ---------------------------------------------------------------------------
991 nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
992 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
993 jboolean depthMask, jboolean ditherEnable,
994 jint srcFunc, jint destFunc,
997 LOG_API("nProgramStoreCreate, con(%p)", con);
998 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
999 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1000 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
1003 // ---------------------------------------------------------------------------
1006 nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
1008 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1009 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1013 nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
1015 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1016 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1020 nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
1022 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1023 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1026 // ---------------------------------------------------------------------------
1029 nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
1031 AutoJavaStringToUTF8 shaderUTF(_env, shader);
1032 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1033 jint paramLen = _env->GetArrayLength(params);
1035 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
1037 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
1038 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1043 // ---------------------------------------------------------------------------
1046 nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
1048 AutoJavaStringToUTF8 shaderUTF(_env, shader);
1049 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1050 jint paramLen = _env->GetArrayLength(params);
1052 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
1054 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
1055 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1059 // ---------------------------------------------------------------------------
1062 nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
1064 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1065 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
1069 // ---------------------------------------------------------------------------
1072 nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
1074 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
1075 rsContextBindRootScript(con, (RsScript)script);
1079 nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
1081 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1082 rsContextBindProgramStore(con, (RsProgramStore)pfs);
1086 nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
1088 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
1089 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
1093 nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
1095 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
1096 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
1100 nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
1102 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1103 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1107 // ---------------------------------------------------------------------------
1110 nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1111 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
1113 LOG_API("nSamplerCreate, con(%p)", con);
1114 return (jint)rsSamplerCreate(con,
1115 (RsSamplerValue)magFilter,
1116 (RsSamplerValue)minFilter,
1117 (RsSamplerValue)wrapS,
1118 (RsSamplerValue)wrapT,
1119 (RsSamplerValue)wrapR,
1123 // ---------------------------------------------------------------------------
1126 nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
1128 LOG_API("nMeshCreate, con(%p)", con);
1130 jint vtxLen = _env->GetArrayLength(_vtx);
1131 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1132 jint idxLen = _env->GetArrayLength(_idx);
1133 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1134 jint primLen = _env->GetArrayLength(_prim);
1135 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1137 int id = (int)rsMeshCreate(con,
1138 (RsAllocation *)vtxPtr, vtxLen,
1139 (RsAllocation *)idxPtr, idxLen,
1140 (uint32_t *)primPtr, primLen);
1142 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1143 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1144 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
1149 nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
1151 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1153 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
1158 nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
1160 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1162 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
1167 nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
1169 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1171 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
1172 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
1174 for(jint i = 0; i < numVtxIDs; i ++) {
1175 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1182 nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
1184 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1186 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1187 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1189 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
1191 for(jint i = 0; i < numIndices; i ++) {
1192 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1193 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1200 // ---------------------------------------------------------------------------
1203 static const char *classPathName = "android/renderscript/RenderScript";
1205 static JNINativeMethod methods[] = {
1206 {"_nInit", "()V", (void*)_nInit },
1208 {"nDeviceCreate", "()I", (void*)nDeviceCreate },
1209 {"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1210 {"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
1211 {"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
1212 {"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1213 {"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
1215 {"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1216 {"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
1219 // All methods below are thread protected in java.
1220 {"rsnContextCreate", "(III)I", (void*)nContextCreate },
1221 {"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
1222 {"rsnContextFinish", "(I)V", (void*)nContextFinish },
1223 {"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1224 {"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1225 {"rsnContextSetSurfaceTexture", "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
1226 {"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
1227 {"rsnContextDump", "(II)V", (void*)nContextDump },
1228 {"rsnContextPause", "(I)V", (void*)nContextPause },
1229 {"rsnContextResume", "(I)V", (void*)nContextResume },
1230 {"rsnAssignName", "(II[B)V", (void*)nAssignName },
1231 {"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
1232 {"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
1234 {"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
1235 {"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
1236 {"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
1237 {"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
1238 {"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
1239 {"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
1241 {"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
1242 {"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1243 {"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
1245 {"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
1246 {"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
1247 {"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
1248 {"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
1250 {"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
1251 {"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
1253 {"rsnAllocationCreateTyped", "(IIII)I", (void*)nAllocationCreateTyped },
1254 {"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
1255 {"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
1257 {"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1258 {"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1260 {"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
1261 {"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1262 {"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1263 {"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1264 {"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1265 {"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1266 {"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
1267 {"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1268 {"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
1269 {"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
1270 {"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
1271 {"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
1272 {"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1273 {"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
1274 {"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
1275 {"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
1276 {"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1277 {"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
1278 {"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
1280 {"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1281 {"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1282 {"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1283 {"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
1284 {"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1285 {"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
1286 {"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
1287 {"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
1288 {"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
1289 {"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
1290 {"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
1291 {"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
1293 {"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
1295 {"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
1297 {"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1298 {"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1299 {"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
1301 {"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate },
1302 {"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
1303 {"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate },
1305 {"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
1306 {"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
1307 {"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1308 {"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1309 {"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
1311 {"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
1313 {"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
1315 {"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1316 {"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
1317 {"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
1318 {"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
1322 static int registerFuncs(JNIEnv *_env)
1324 return android::AndroidRuntime::registerNativeMethods(
1325 _env, classPathName, methods, NELEM(methods));
1328 // ---------------------------------------------------------------------------
1330 jint JNI_OnLoad(JavaVM* vm, void* reserved)
1335 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1336 LOGE("ERROR: GetEnv failed\n");
1339 assert(env != NULL);
1341 if (registerFuncs(env) < 0) {
1342 LOGE("ERROR: MediaPlayer native registration failed\n");
1346 /* success -- return valid version number */
1347 result = JNI_VERSION_1_4;