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