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