blob: ef0cf68dd641bedc78e29ef46939accae4a502df [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
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
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070025
Jason Samsd19f10d2009-05-22 14:03:28 -070026#include <ui/Surface.h>
27
Jason Samsffe9f482009-06-01 17:45:53 -070028#include <core/SkBitmap.h>
29
Jason Samsf29ca502009-06-23 12:22:47 -070030
Jason Samsd19f10d2009-05-22 14:03:28 -070031#include "jni.h"
32#include "JNIHelp.h"
33#include "android_runtime/AndroidRuntime.h"
34
Jason Samse29d4712009-07-23 15:19:03 -070035#include <RenderScript.h>
36#include <RenderScriptEnv.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070037
38//#define LOG_API LOGE
39#define LOG_API(...)
40
41using namespace android;
42
Jason Samsd19f10d2009-05-22 14:03:28 -070043// ---------------------------------------------------------------------------
44
45static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
46{
47 jclass npeClazz = env->FindClass(exc);
48 env->ThrowNew(npeClazz, msg);
49}
50
Jason Samsffe9f482009-06-01 17:45:53 -070051static jfieldID gContextId = 0;
52static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -070053static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -070054
55static void _nInit(JNIEnv *_env, jclass _this)
56{
Jason Samsd19f10d2009-05-22 14:03:28 -070057 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -070058
59 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
60 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Sams43ee06852009-08-12 17:54:11 -070061
62 jclass typeClass = _env->FindClass("android/renderscript/Type");
63 gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -070064}
65
66
67// ---------------------------------------------------------------------------
68
Jason Sams3eaa338e2009-06-10 15:04:38 -070069static void
70nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str)
71{
72 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
73 LOG_API("nAssignName, con(%p), obj(%p)", con, obj);
74
75 jint len = _env->GetArrayLength(str);
76 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsd5680f92009-06-10 18:39:40 -070077 rsAssignName((void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -070078 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
79}
80
81
Jason Sams64676f32009-07-08 18:01:53 -070082static jint
83nFileOpen(JNIEnv *_env, jobject _this, jbyteArray str)
84{
85 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
86 LOG_API("nFileOpen, con(%p)", con);
87
88 jint len = _env->GetArrayLength(str);
89 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
90 jint ret = (jint)rsFileOpen((const char *)cptr, len);
91 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
92 return ret;
93}
94
Jason Sams3eaa338e2009-06-10 15:04:38 -070095// ---------------------------------------------------------------------------
96
Jason Samsd19f10d2009-05-22 14:03:28 -070097static jint
98nDeviceCreate(JNIEnv *_env, jobject _this)
99{
100 LOG_API("nDeviceCreate");
101 return (jint)rsDeviceCreate();
102}
103
104static void
105nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
106{
107 LOG_API("nDeviceDestroy");
108 return rsDeviceDestroy((RsDevice)dev);
109}
110
111static jint
112nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver)
113{
114 LOG_API("nContextCreate");
115
116 if (wnd == NULL) {
117 not_valid_surface:
118 doThrow(_env, "java/lang/IllegalArgumentException",
119 "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
120 return 0;
121 }
122 jclass surface_class = _env->FindClass("android/view/Surface");
123 jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I");
124 Surface * window = (Surface*)_env->GetIntField(wnd, surfaceFieldID);
125 if (window == NULL)
126 goto not_valid_surface;
127
Jason Samsd19f10d2009-05-22 14:03:28 -0700128 return (jint)rsContextCreate((RsDevice)dev, window, ver);
129}
130
131static void
132nContextDestroy(JNIEnv *_env, jobject _this, jint con)
133{
134 LOG_API("nContextDestroy, con(%p)", (RsContext)con);
135 return rsContextDestroy((RsContext)con);
136}
137
138
139static void
140nElementBegin(JNIEnv *_env, jobject _this)
141{
142 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
143 LOG_API("nElementBegin, con(%p)", con);
144 rsElementBegin();
145}
146
147static void
148nElementAddPredefined(JNIEnv *_env, jobject _this, jint predef)
149{
150 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
151 LOG_API("nElementAddPredefined, con(%p), predef(%i)", con, predef);
152 rsElementAddPredefined((RsElementPredefined)predef);
153}
154
155static void
Jason Sams43ee06852009-08-12 17:54:11 -0700156nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jint norm, jint bits, jstring name)
Jason Samsd19f10d2009-05-22 14:03:28 -0700157{
158 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams43ee06852009-08-12 17:54:11 -0700159 const char* n = NULL;
160 if (name) {
161 n = _env->GetStringUTFChars(name, NULL);
162 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700163 LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits);
Jason Sams43ee06852009-08-12 17:54:11 -0700164 rsElementAdd((RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits, n);
165 if (n) {
166 _env->ReleaseStringUTFChars(name, n);
167 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700168}
169
170static jint
171nElementCreate(JNIEnv *_env, jobject _this)
172{
173 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
174 LOG_API("nElementCreate, con(%p)", con);
175 return (jint)rsElementCreate();
176}
177
178static jint
179nElementGetPredefined(JNIEnv *_env, jobject _this, jint predef)
180{
181 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
182 LOG_API("nElementGetPredefined, con(%p) predef(%i)", con, predef);
183 return (jint)rsElementGetPredefined((RsElementPredefined)predef);
184}
185
186static void
187nElementDestroy(JNIEnv *_env, jobject _this, jint e)
188{
189 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
190 LOG_API("nElementDestroy, con(%p) e(%p)", con, (RsElement)e);
191 rsElementDestroy((RsElement)e);
192}
193
194// -----------------------------------
195
196static void
197nTypeBegin(JNIEnv *_env, jobject _this, jint eID)
198{
199 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
200 LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID);
201 rsTypeBegin((RsElement)eID);
202}
203
204static void
205nTypeAdd(JNIEnv *_env, jobject _this, jint dim, jint val)
206{
207 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
208 LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val);
209 rsTypeAdd((RsDimension)dim, val);
210}
211
212static jint
213nTypeCreate(JNIEnv *_env, jobject _this)
214{
215 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
216 LOG_API("nTypeCreate, con(%p)", con);
217 return (jint)rsTypeCreate();
218}
219
220static void
221nTypeDestroy(JNIEnv *_env, jobject _this, jint eID)
222{
223 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
224 LOG_API("nTypeDestroy, con(%p), t(%p)", con, (RsType)eID);
225 rsTypeDestroy((RsType)eID);
226}
227
Jason Sams43ee06852009-08-12 17:54:11 -0700228static void * SF_LoadInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
229{
230 ((int32_t *)buffer)[0] = _env->GetIntField(_obj, _field);
231 return ((uint8_t *)buffer) + 4;
232}
233
234static void * SF_LoadShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
235{
236 ((int16_t *)buffer)[0] = _env->GetShortField(_obj, _field);
237 return ((uint8_t *)buffer) + 2;
238}
239
240static void * SF_LoadByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
241{
242 ((int8_t *)buffer)[0] = _env->GetByteField(_obj, _field);
243 return ((uint8_t *)buffer) + 1;
244}
245
246static void * SF_LoadFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
247{
248 ((float *)buffer)[0] = _env->GetFloatField(_obj, _field);
249 return ((uint8_t *)buffer) + 4;
250}
251
252struct TypeFieldCache {
253 jfieldID field;
254 int bits;
255 void * (*ptr)(JNIEnv *, jobject, jfieldID, void *buffer);
256};
257
258struct TypeCache {
259 int fieldCount;
260 int size;
261 TypeFieldCache fields[1];
262};
263
264//{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy },
265static void
266nTypeFinalDestroy(JNIEnv *_env, jobject _this, jobject _type)
267{
268 TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
269 free(tc);
270}
271
272// native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
273static void
274nTypeSetupFields(JNIEnv *_env, jobject _this, jobject _type, jintArray _types, jintArray _bits, jobjectArray _IDs)
275{
276 int fieldCount = _env->GetArrayLength(_types);
277 size_t structSize = sizeof(TypeCache) + (sizeof(TypeFieldCache) * (fieldCount-1));
278 TypeCache *tc = (TypeCache *)malloc(structSize);
279 memset(tc, 0, structSize);
280
281 TypeFieldCache *tfc = &tc->fields[0];
282 tc->fieldCount = fieldCount;
283 _env->SetIntField(_type, gTypeNativeCache, (jint)tc);
284
285 jint *fType = _env->GetIntArrayElements(_types, NULL);
286 jint *fBits = _env->GetIntArrayElements(_bits, NULL);
287 for (int ct=0; ct < fieldCount; ct++) {
288 jobject field = _env->GetObjectArrayElement(_IDs, ct);
289 tfc[ct].field = _env->FromReflectedField(field);
290 tfc[ct].bits = fBits[ct];
291
292 switch(fType[ct]) {
293 case RS_TYPE_FLOAT:
294 tfc[ct].ptr = SF_LoadFloat;
295 break;
296 case RS_TYPE_UNSIGNED:
297 case RS_TYPE_SIGNED:
298 switch(tfc[ct].bits) {
299 case 32: tfc[ct].ptr = SF_LoadInt; break;
300 case 16: tfc[ct].ptr = SF_LoadShort; break;
301 case 8: tfc[ct].ptr = SF_LoadByte; break;
302 }
303 break;
304 }
305 tc->size += 4;
306 }
307
308 _env->ReleaseIntArrayElements(_types, fType, JNI_ABORT);
309 _env->ReleaseIntArrayElements(_bits, fBits, JNI_ABORT);
310}
311
312
Jason Samsd19f10d2009-05-22 14:03:28 -0700313// -----------------------------------
314
315static jint
316nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
317{
318 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
319 LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e);
320 return (jint) rsAllocationCreateTyped((RsElement)e);
321}
322
323static jint
324nAllocationCreatePredefSized(JNIEnv *_env, jobject _this, jint predef, jint count)
325{
326 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
327 LOG_API("nAllocationCreatePredefSized, con(%p), predef(%i), count(%i)", con, predef, count);
328 return (jint) rsAllocationCreatePredefSized((RsElementPredefined)predef, count);
329}
330
331static jint
332nAllocationCreateSized(JNIEnv *_env, jobject _this, jint e, jint count)
333{
334 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
335 LOG_API("nAllocationCreateSized, con(%p), e(%p), count(%i)", con, (RsElement)e, count);
336 return (jint) rsAllocationCreateSized((RsElement)e, count);
337}
338
339static void
340nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
341{
342 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
343 LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip);
344 rsAllocationUploadToTexture((RsAllocation)a, mip);
345}
346
Jason Samsffe9f482009-06-01 17:45:53 -0700347static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg)
Jason Samsfe08d992009-05-27 14:45:32 -0700348{
Jason Samsffe9f482009-06-01 17:45:53 -0700349 switch (cfg) {
350 case SkBitmap::kA8_Config:
351 return RS_ELEMENT_A_8;
352 case SkBitmap::kARGB_4444_Config:
353 return RS_ELEMENT_RGBA_4444;
354 case SkBitmap::kARGB_8888_Config:
355 return RS_ELEMENT_RGBA_8888;
356 case SkBitmap::kRGB_565_Config:
357 return RS_ELEMENT_RGB_565;
Jason Samsfe08d992009-05-27 14:45:32 -0700358
Jason Samsffe9f482009-06-01 17:45:53 -0700359 default:
360 break;
361 }
362 // If we don't have a conversion mark it as a user type.
363 LOGE("Unsupported bitmap type");
364 return RS_ELEMENT_USER_U8;
Jason Samsfe08d992009-05-27 14:45:32 -0700365}
366
Jason Samsffe9f482009-06-01 17:45:53 -0700367static int
368nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
369{
370 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
371 SkBitmap const * nativeBitmap =
372 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
373 const SkBitmap& bitmap(*nativeBitmap);
374 SkBitmap::Config config = bitmap.getConfig();
375
376 RsElementPredefined e = SkBitmapToPredefined(config);
377
378 if (e != RS_ELEMENT_USER_U8) {
379 bitmap.lockPixels();
380 const int w = bitmap.width();
381 const int h = bitmap.height();
382 const void* ptr = bitmap.getPixels();
383 jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
384 bitmap.unlockPixels();
385 return id;
386 }
387 return 0;
388}
Jason Samsfe08d992009-05-27 14:45:32 -0700389
Jason Samsb0ec1b42009-07-28 12:02:16 -0700390static int
391nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
392{
393 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
394 SkBitmap const * nativeBitmap =
395 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
396 const SkBitmap& bitmap(*nativeBitmap);
397 SkBitmap::Config config = bitmap.getConfig();
398
399 RsElementPredefined e = SkBitmapToPredefined(config);
400
401 if (e != RS_ELEMENT_USER_U8) {
402 bitmap.lockPixels();
403 const int w = bitmap.width();
404 const int h = bitmap.height();
405 const void* ptr = bitmap.getPixels();
406 jint id = (jint)rsAllocationCreateFromBitmapBoxed(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
407 bitmap.unlockPixels();
408 return id;
409 }
410 return 0;
411}
412
Jason Samsfe08d992009-05-27 14:45:32 -0700413
Jason Samsd19f10d2009-05-22 14:03:28 -0700414static void
415nAllocationDestroy(JNIEnv *_env, jobject _this, jint a)
416{
417 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
418 LOG_API("nAllocationDestroy, con(%p), a(%p)", con, (RsAllocation)a);
419 rsAllocationDestroy((RsAllocation)a);
420}
421
422static void
423nAllocationData_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data)
424{
425 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
426 jint len = _env->GetArrayLength(data);
427 LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
428 jint *ptr = _env->GetIntArrayElements(data, NULL);
429 rsAllocationData((RsAllocation)alloc, ptr);
430 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
431}
432
433static void
434nAllocationData_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data)
435{
436 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
437 jint len = _env->GetArrayLength(data);
438 LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
439 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
440 rsAllocationData((RsAllocation)alloc, ptr);
441 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
442}
443
444static void
445nAllocationSubData1D_i(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jintArray data)
446{
447 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
448 jint len = _env->GetArrayLength(data);
449 LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len);
450 jint *ptr = _env->GetIntArrayElements(data, NULL);
451 rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr);
452 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
453}
454
455static void
456nAllocationSubData1D_f(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jfloatArray data)
457{
458 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
459 jint len = _env->GetArrayLength(data);
460 LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len);
461 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
462 rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr);
463 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
464}
465
466static void
467nAllocationSubData2D_i(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data)
468{
469 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
470 jint len = _env->GetArrayLength(data);
471 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);
472 jint *ptr = _env->GetIntArrayElements(data, NULL);
473 rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr);
474 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
475}
476
477static void
478nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data)
479{
480 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
481 jint len = _env->GetArrayLength(data);
482 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);
483 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
484 rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr);
485 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
486}
487
Jason Sams40a29e82009-08-10 14:55:26 -0700488static void
489nAllocationRead_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data)
490{
491 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
492 jint len = _env->GetArrayLength(data);
493 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
494 jint *ptr = _env->GetIntArrayElements(data, NULL);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700495 rsAllocationRead((RsAllocation)alloc, ptr);
Jason Sams40a29e82009-08-10 14:55:26 -0700496 _env->ReleaseIntArrayElements(data, ptr, JNI_COMMIT);
497}
498
499static void
500nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data)
501{
502 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
503 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700504 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700505 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700506 rsAllocationRead((RsAllocation)alloc, ptr);
Jason Sams40a29e82009-08-10 14:55:26 -0700507 _env->ReleaseFloatArrayElements(data, ptr, JNI_COMMIT);
508}
Jason Samsd19f10d2009-05-22 14:03:28 -0700509
510
Jason Sams43ee06852009-08-12 17:54:11 -0700511//{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject },
512static void
513nAllocationDataFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jobject _o)
514{
515 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
516 LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc);
517
518 const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
519
520 void * bufAlloc = malloc(tc->size);
521 void * buf = bufAlloc;
522 for (int ct=0; ct < tc->fieldCount; ct++) {
523 const TypeFieldCache *tfc = &tc->fields[ct];
524 buf = tfc->ptr(_env, _o, tfc->field, buf);
525 }
526 rsAllocationData((RsAllocation)alloc, bufAlloc);
527 const uint32_t * tmp = (const uint32_t *)bufAlloc;
528 free(bufAlloc);
529}
530
Jason Samsd19f10d2009-05-22 14:03:28 -0700531// -----------------------------------
532
533static void
534nTriangleMeshDestroy(JNIEnv *_env, jobject _this, jint tm)
535{
536 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
537 LOG_API("nTriangleMeshDestroy, con(%p), tm(%p)", con, (RsAllocation)tm);
538 rsTriangleMeshDestroy((RsTriangleMesh)tm);
539}
540
541static void
542nTriangleMeshBegin(JNIEnv *_env, jobject _this, jint v, jint i)
543{
544 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
545 LOG_API("nTriangleMeshBegin, con(%p), vertex(%p), index(%p)", con, (RsElement)v, (RsElement)i);
546 rsTriangleMeshBegin((RsElement)v, (RsElement)i);
547}
548
549static void
550nTriangleMeshAddVertex_XY(JNIEnv *_env, jobject _this, jfloat x, jfloat y)
551{
552 float v[] = {x, y};
553 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
554 LOG_API("nTriangleMeshAddVertex_XY, con(%p), x(%f), y(%f)", con, x, y);
555 rsTriangleMeshAddVertex(v);
556}
557
558static void
559nTriangleMeshAddVertex_XYZ(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z)
560{
561 float v[] = {x, y, z};
562 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
563 LOG_API("nTriangleMeshAddVertex_XYZ, con(%p), x(%f), y(%f), z(%f)", con, x, y, z);
564 rsTriangleMeshAddVertex(v);
565}
566
567static void
568nTriangleMeshAddVertex_XY_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat s, jfloat t)
569{
570 float v[] = {s, t, x, y};
571 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
572 LOG_API("nTriangleMeshAddVertex_XY_ST, con(%p), x(%f), y(%f), s(%f), t(%f)", con, x, y, s, t);
573 rsTriangleMeshAddVertex(v);
574}
575
576static void
577nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t)
578{
579 float v[] = {s, t, x, y, z};
580 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
581 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
582 rsTriangleMeshAddVertex(v);
583}
584
585static void
Jason Sams0826a6f2009-06-15 19:04:56 -0700586nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz)
587{
588 float v[] = {nx, ny, nz, s, t, x, y, z};
589 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
590 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
591 rsTriangleMeshAddVertex(v);
592}
593
594static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700595nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3)
596{
597 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
598 LOG_API("nTriangleMeshAddTriangle, con(%p), i1(%i), i2(%i), i3(%i)", con, i1, i2, i3);
599 rsTriangleMeshAddTriangle(i1, i2, i3);
600}
601
602static jint
603nTriangleMeshCreate(JNIEnv *_env, jobject _this)
604{
605 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
606 LOG_API("nTriangleMeshCreate, con(%p)", con);
607 return (jint) rsTriangleMeshCreate();
608}
609
610// -----------------------------------
611
612static void
613nAdapter1DDestroy(JNIEnv *_env, jobject _this, jint adapter)
614{
615 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
616 LOG_API("nAdapter1DDestroy, con(%p), adapter(%p)", con, (RsAdapter1D)adapter);
617 rsAdapter1DDestroy((RsAdapter1D)adapter);
618}
619
620static void
621nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc)
622{
623 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
624 LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc);
625 rsAdapter1DBindAllocation((RsAdapter1D)adapter, (RsAllocation)alloc);
626}
627
628static void
629nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value)
630{
631 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
632 LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value);
633 rsAdapter1DSetConstraint((RsAdapter1D)adapter, (RsDimension)dim, value);
634}
635
636static void
637nAdapter1DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data)
638{
639 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
640 jint len = _env->GetArrayLength(data);
641 LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len);
642 jint *ptr = _env->GetIntArrayElements(data, NULL);
643 rsAdapter1DData((RsAdapter1D)adapter, ptr);
644 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
645}
646
647static void
648nAdapter1DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jintArray data)
649{
650 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
651 jint len = _env->GetArrayLength(data);
652 LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len);
653 jint *ptr = _env->GetIntArrayElements(data, NULL);
654 rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr);
655 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
656}
657
658static void
659nAdapter1DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data)
660{
661 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
662 jint len = _env->GetArrayLength(data);
663 LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len);
664 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
665 rsAdapter1DData((RsAdapter1D)adapter, ptr);
666 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
667}
668
669static void
670nAdapter1DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jfloatArray data)
671{
672 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
673 jint len = _env->GetArrayLength(data);
674 LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len);
675 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
676 rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr);
677 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
678}
679
680static jint
681nAdapter1DCreate(JNIEnv *_env, jobject _this)
682{
683 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
684 LOG_API("nAdapter1DCreate, con(%p)", con);
685 return (jint)rsAdapter1DCreate();
686}
687
688// -----------------------------------
689
690static void
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700691nAdapter2DDestroy(JNIEnv *_env, jobject _this, jint adapter)
692{
693 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
694 LOG_API("nAdapter2DDestroy, con(%p), adapter(%p)", con, (RsAdapter2D)adapter);
695 rsAdapter2DDestroy((RsAdapter2D)adapter);
696}
697
698static void
699nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc)
700{
701 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
702 LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc);
703 rsAdapter2DBindAllocation((RsAdapter2D)adapter, (RsAllocation)alloc);
704}
705
706static void
707nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value)
708{
709 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
710 LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value);
711 rsAdapter2DSetConstraint((RsAdapter2D)adapter, (RsDimension)dim, value);
712}
713
714static void
715nAdapter2DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data)
716{
717 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
718 jint len = _env->GetArrayLength(data);
719 LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len);
720 jint *ptr = _env->GetIntArrayElements(data, NULL);
721 rsAdapter2DData((RsAdapter2D)adapter, ptr);
722 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
723}
724
725static void
726nAdapter2DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data)
727{
728 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
729 jint len = _env->GetArrayLength(data);
730 LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len);
731 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
732 rsAdapter2DData((RsAdapter2D)adapter, ptr);
733 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
734}
735
736static void
737nAdapter2DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data)
738{
739 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
740 jint len = _env->GetArrayLength(data);
741 LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)",
742 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len);
743 jint *ptr = _env->GetIntArrayElements(data, NULL);
744 rsAdapter2DSubData((RsAdapter2D)adapter, xoff, yoff, w, h, ptr);
745 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
746}
747
748static void
749nAdapter2DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data)
750{
751 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
752 jint len = _env->GetArrayLength(data);
753 LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)",
754 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len);
755 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
756 rsAdapter2DSubData((RsAdapter1D)adapter, xoff, yoff, w, h, ptr);
757 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
758}
759
760static jint
761nAdapter2DCreate(JNIEnv *_env, jobject _this)
762{
763 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
764 LOG_API("nAdapter2DCreate, con(%p)", con);
765 return (jint)rsAdapter2DCreate();
766}
767
768// -----------------------------------
769
770static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700771nScriptDestroy(JNIEnv *_env, jobject _this, jint script)
772{
773 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
774 LOG_API("nScriptDestroy, con(%p), script(%p)", con, (RsScript)script);
775 rsScriptDestroy((RsScript)script);
776}
777
778static void
779nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint slot)
780{
781 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
782 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
783 rsScriptBindAllocation((RsScript)script, (RsAllocation)alloc, slot);
784}
785
786static void
Jason Sams22534172009-08-04 16:58:20 -0700787nScriptSetClearColor(JNIEnv *_env, jobject _this, jint script, jfloat r, jfloat g, jfloat b, jfloat a)
Jason Samsd19f10d2009-05-22 14:03:28 -0700788{
789 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams22534172009-08-04 16:58:20 -0700790 LOG_API("nScriptSetClearColor, con(%p), s(%p), r(%f), g(%f), b(%f), a(%f)", con, script, r, g, b, a);
791 rsScriptSetClearColor((RsScript)script, r, g, b, a);
Jason Samsd19f10d2009-05-22 14:03:28 -0700792}
793
794static void
Jason Sams22534172009-08-04 16:58:20 -0700795nScriptSetClearDepth(JNIEnv *_env, jobject _this, jint script, jfloat d)
Jason Samsd19f10d2009-05-22 14:03:28 -0700796{
797 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams22534172009-08-04 16:58:20 -0700798 LOG_API("nScriptCSetClearDepth, con(%p), s(%p), depth(%f)", con, script, d);
799 rsScriptSetClearDepth((RsScript)script, d);
Jason Samsd19f10d2009-05-22 14:03:28 -0700800}
801
802static void
Jason Sams22534172009-08-04 16:58:20 -0700803nScriptSetClearStencil(JNIEnv *_env, jobject _this, jint script, jint stencil)
Jason Samsd19f10d2009-05-22 14:03:28 -0700804{
805 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams22534172009-08-04 16:58:20 -0700806 LOG_API("nScriptCSetClearStencil, con(%p), s(%p), stencil(%i)", con, script, stencil);
807 rsScriptSetClearStencil((RsScript)script, stencil);
Jason Samsd19f10d2009-05-22 14:03:28 -0700808}
809
810static void
Jason Sams22534172009-08-04 16:58:20 -0700811nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700812{
813 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams22534172009-08-04 16:58:20 -0700814 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, script, timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700815
816 jint length = _env->GetArrayLength(timeZone);
817 jbyte* timeZone_ptr;
818 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
819
Jason Sams22534172009-08-04 16:58:20 -0700820 rsScriptSetTimeZone((RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700821
822 if (timeZone_ptr) {
823 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
824 }
825}
826
Jason Sams22534172009-08-04 16:58:20 -0700827// -----------------------------------
828
829static void
830nScriptCBegin(JNIEnv *_env, jobject _this)
831{
832 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
833 LOG_API("nScriptCBegin, con(%p)", con);
834 rsScriptCBegin();
835}
836
Romain Guy584a3752009-07-30 18:45:01 -0700837static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700838nScriptCAddType(JNIEnv *_env, jobject _this, jint type)
839{
840 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
841 LOG_API("nScriptCAddType, con(%p), type(%p)", con, (RsType)type);
842 rsScriptCAddType((RsType)type);
843}
844
845static void
846nScriptCSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot)
847{
848 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
849 LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot);
850 rsScriptCSetRoot(isRoot);
851}
852
853static void
Jack Palevich43702d82009-05-28 13:38:16 -0700854nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef,
855 jint offset, jint length)
Jason Samsd19f10d2009-05-22 14:03:28 -0700856{
857 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
858 LOG_API("!!! nScriptCSetScript, con(%p)", con);
Jack Palevich43702d82009-05-28 13:38:16 -0700859 jint _exception = 0;
860 jint remaining;
861 jbyte* script_base = 0;
862 jbyte* script_ptr;
Jack Palevich43702d82009-05-28 13:38:16 -0700863 if (!scriptRef) {
864 _exception = 1;
865 //_env->ThrowNew(IAEClass, "script == null");
866 goto exit;
867 }
868 if (offset < 0) {
869 _exception = 1;
870 //_env->ThrowNew(IAEClass, "offset < 0");
871 goto exit;
872 }
873 if (length < 0) {
874 _exception = 1;
875 //_env->ThrowNew(IAEClass, "length < 0");
876 goto exit;
877 }
878 remaining = _env->GetArrayLength(scriptRef) - offset;
879 if (remaining < length) {
880 _exception = 1;
881 //_env->ThrowNew(IAEClass, "length > script.length - offset");
882 goto exit;
883 }
884 script_base = (jbyte *)
885 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
886 script_ptr = script_base + offset;
887
Jason Sams39ddc9502009-06-05 17:35:09 -0700888 rsScriptCSetText((const char *)script_ptr, length);
889
Jack Palevich43702d82009-05-28 13:38:16 -0700890exit:
891 if (script_base) {
892 _env->ReleasePrimitiveArrayCritical(scriptRef, script_base,
893 _exception ? JNI_ABORT: 0);
894 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700895}
896
897static jint
898nScriptCCreate(JNIEnv *_env, jobject _this)
899{
900 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
901 LOG_API("nScriptCCreate, con(%p)", con);
902 return (jint)rsScriptCCreate();
903}
904
Joe Onoratod7b37742009-08-09 22:57:44 -0700905static void
906nScriptCAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value)
907{
908 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
909 const char* n = _env->GetStringUTFChars(name, NULL);
910 LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value);
911 rsScriptCSetDefineI32(n, value);
912 _env->ReleaseStringUTFChars(name, n);
913}
914
915static void
916nScriptCAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value)
917{
918 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
919 const char* n = _env->GetStringUTFChars(name, NULL);
920 LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value);
921 rsScriptCSetDefineF(n, value);
922 _env->ReleaseStringUTFChars(name, n);
923}
924
Jason Samsd19f10d2009-05-22 14:03:28 -0700925// ---------------------------------------------------------------------------
926
927static void
928nProgramFragmentStoreBegin(JNIEnv *_env, jobject _this, jint in, jint out)
929{
930 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
931 LOG_API("nProgramFragmentStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
932 rsProgramFragmentStoreBegin((RsElement)in, (RsElement)out);
933}
934
935static void
936nProgramFragmentStoreDepthFunc(JNIEnv *_env, jobject _this, jint func)
937{
938 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
939 LOG_API("nProgramFragmentStoreDepthFunc, con(%p), func(%i)", con, func);
940 rsProgramFragmentStoreDepthFunc((RsDepthFunc)func);
941}
942
943static void
944nProgramFragmentStoreDepthMask(JNIEnv *_env, jobject _this, jboolean enable)
945{
946 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
947 LOG_API("nProgramFragmentStoreDepthMask, con(%p), enable(%i)", con, enable);
948 rsProgramFragmentStoreDepthMask(enable);
949}
950
951static void
952nProgramFragmentStoreColorMask(JNIEnv *_env, jobject _this, jboolean r, jboolean g, jboolean b, jboolean a)
953{
954 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
955 LOG_API("nProgramFragmentStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a);
956 rsProgramFragmentStoreColorMask(r, g, b, a);
957}
958
959static void
960nProgramFragmentStoreBlendFunc(JNIEnv *_env, jobject _this, int src, int dst)
961{
962 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
963 LOG_API("nProgramFragmentStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst);
964 rsProgramFragmentStoreBlendFunc((RsBlendSrcFunc)src, (RsBlendDstFunc)dst);
965}
966
967static void
968nProgramFragmentStoreDither(JNIEnv *_env, jobject _this, jboolean enable)
969{
970 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
971 LOG_API("nProgramFragmentStoreDither, con(%p), enable(%i)", con, enable);
972 rsProgramFragmentStoreDither(enable);
973}
974
975static jint
976nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this)
977{
978 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
979 LOG_API("nProgramFragmentStoreCreate, con(%p)", con);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700980
Jason Samsd19f10d2009-05-22 14:03:28 -0700981 return (jint)rsProgramFragmentStoreCreate();
982}
983
Jason Sams3eaa338e2009-06-10 15:04:38 -0700984static void
985nProgramFragmentStoreDestroy(JNIEnv *_env, jobject _this, jint pgm)
986{
987 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
988 LOG_API("nProgramFragmentStoreDestroy, con(%p), pgm(%i)", con, pgm);
989 rsProgramFragmentStoreDestroy((RsProgramFragmentStore)pgm);
990}
991
Jason Samsd19f10d2009-05-22 14:03:28 -0700992// ---------------------------------------------------------------------------
993
994static void
995nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out)
996{
997 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
998 LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
999 rsProgramFragmentBegin((RsElement)in, (RsElement)out);
1000}
1001
1002static void
1003nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
1004{
1005 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1006 LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1007 rsProgramFragmentBindTexture((RsProgramFragment)vpf, slot, (RsAllocation)a);
1008}
1009
1010static void
1011nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
1012{
1013 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1014 LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1015 rsProgramFragmentBindSampler((RsProgramFragment)vpf, slot, (RsSampler)a);
1016}
1017
1018static void
1019nProgramFragmentSetType(JNIEnv *_env, jobject _this, jint slot, jint vt)
1020{
1021 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1022 LOG_API("nProgramFragmentSetType, con(%p), slot(%i), vt(%p)", con, slot, (RsType)vt);
1023 rsProgramFragmentSetType(slot, (RsType)vt);
1024}
1025
1026static void
1027nProgramFragmentSetEnvMode(JNIEnv *_env, jobject _this, jint slot, jint env)
1028{
1029 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1030 LOG_API("nProgramFragmentSetEnvMode, con(%p), slot(%i), vt(%i)", con, slot, env);
1031 rsProgramFragmentSetEnvMode(slot, (RsTexEnvMode)env);
1032}
1033
1034static void
1035nProgramFragmentSetTexEnable(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
1036{
1037 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1038 LOG_API("nProgramFragmentSetTexEnable, con(%p), slot(%i), enable(%i)", con, slot, enable);
1039 rsProgramFragmentSetTexEnable(slot, enable);
1040}
1041
1042static jint
1043nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
1044{
1045 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1046 LOG_API("nProgramFragmentCreate, con(%p)", con);
1047 return (jint)rsProgramFragmentCreate();
1048}
1049
Jason Sams3eaa338e2009-06-10 15:04:38 -07001050static void
1051nProgramFragmentDestroy(JNIEnv *_env, jobject _this, jint pgm)
1052{
1053 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1054 LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm);
1055 rsProgramFragmentDestroy((RsProgramFragment)pgm);
1056}
1057
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001058// ---------------------------------------------------------------------------
1059
1060static void
1061nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out)
1062{
1063 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1064 LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
1065 rsProgramVertexBegin((RsElement)in, (RsElement)out);
1066}
1067
1068static void
Jason Sams9bee51c2009-08-05 13:57:03 -07001069nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint a)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001070{
1071 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1072 LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
Jason Sams9bee51c2009-08-05 13:57:03 -07001073 rsProgramVertexBindAllocation((RsProgramFragment)vpv, (RsAllocation)a);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001074}
1075
1076static void
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001077nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
1078{
1079 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1080 LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable);
1081 rsProgramVertexSetTextureMatrixEnable(enable);
1082}
1083
Jason Samsee411122009-07-21 12:20:54 -07001084static void
1085nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light)
1086{
1087 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1088 LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light);
1089 rsProgramVertexAddLight((RsLight)light);
1090}
1091
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001092static jint
1093nProgramVertexCreate(JNIEnv *_env, jobject _this)
1094{
1095 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1096 LOG_API("nProgramVertexCreate, con(%p)", con);
1097 return (jint)rsProgramVertexCreate();
1098}
1099
1100static void
1101nProgramVertexDestroy(JNIEnv *_env, jobject _this, jint pgm)
1102{
1103 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1104 LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm);
1105 rsProgramFragmentDestroy((RsProgramFragment)pgm);
1106}
1107
1108
1109
Jason Samsd19f10d2009-05-22 14:03:28 -07001110
1111// ---------------------------------------------------------------------------
1112
1113static void
1114nContextBindRootScript(JNIEnv *_env, jobject _this, jint script)
1115{
1116 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1117 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
1118 rsContextBindRootScript((RsScript)script);
1119}
1120
1121static void
Jason Samsd19f10d2009-05-22 14:03:28 -07001122nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs)
1123{
1124 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1125 LOG_API("nContextBindProgramFragmentStore, con(%p), pfs(%p)", con, (RsProgramFragmentStore)pfs);
1126 rsContextBindProgramFragmentStore((RsProgramFragmentStore)pfs);
1127}
1128
1129static void
1130nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf)
1131{
1132 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1133 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
1134 rsContextBindProgramFragment((RsProgramFragment)pf);
1135}
1136
Jason Sams0826a6f2009-06-15 19:04:56 -07001137static void
1138nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf)
1139{
1140 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1141 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
1142 rsContextBindProgramVertex((RsProgramVertex)pf);
1143}
1144
Joe Onoratod7b37742009-08-09 22:57:44 -07001145static void
1146nContextAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value)
1147{
1148 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1149 const char* n = _env->GetStringUTFChars(name, NULL);
1150 LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value);
1151 rsContextSetDefineI32(n, value);
1152 _env->ReleaseStringUTFChars(name, n);
1153}
1154
1155static void
1156nContextAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value)
1157{
1158 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1159 const char* n = _env->GetStringUTFChars(name, NULL);
1160 LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value);
1161 rsContextSetDefineF(n, value);
1162 _env->ReleaseStringUTFChars(name, n);
1163}
1164
1165
Jason Sams02fb2cb2009-05-28 15:37:57 -07001166// ---------------------------------------------------------------------------
1167
1168static void
1169nSamplerDestroy(JNIEnv *_env, jobject _this, jint s)
1170{
1171 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1172 LOG_API("nSamplerDestroy, con(%p), sampler(%p)", con, (RsSampler)s);
1173 rsSamplerDestroy((RsSampler)s);
1174}
1175
1176static void
1177nSamplerBegin(JNIEnv *_env, jobject _this)
1178{
1179 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1180 LOG_API("nSamplerBegin, con(%p)", con);
1181 rsSamplerBegin();
1182}
1183
1184static void
1185nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v)
1186{
1187 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1188 LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v);
1189 rsSamplerSet((RsSamplerParam)p, (RsSamplerValue)v);
1190}
1191
1192static jint
1193nSamplerCreate(JNIEnv *_env, jobject _this)
1194{
1195 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Samsbba134c2009-06-22 15:49:21 -07001196 LOG_API("nSamplerCreate, con(%p)", con);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001197 return (jint)rsSamplerCreate();
1198}
1199
Jason Samsbba134c2009-06-22 15:49:21 -07001200// ---------------------------------------------------------------------------
1201
1202static void
1203nLightBegin(JNIEnv *_env, jobject _this)
1204{
1205 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1206 LOG_API("nLightBegin, con(%p)", con);
1207 rsLightBegin();
1208}
1209
1210static void
1211nLightSetIsMono(JNIEnv *_env, jobject _this, jboolean isMono)
1212{
1213 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1214 LOG_API("nLightSetIsMono, con(%p), isMono(%i)", con, isMono);
1215 rsLightSetMonochromatic(isMono);
1216}
1217
1218static void
1219nLightSetIsLocal(JNIEnv *_env, jobject _this, jboolean isLocal)
1220{
1221 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1222 LOG_API("nLightSetIsLocal, con(%p), isLocal(%i)", con, isLocal);
1223 rsLightSetLocal(isLocal);
1224}
1225
1226static jint
1227nLightCreate(JNIEnv *_env, jobject _this)
1228{
1229 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1230 LOG_API("nLightCreate, con(%p)", con);
1231 return (jint)rsLightCreate();
1232}
1233
1234static void
1235nLightDestroy(JNIEnv *_env, jobject _this, jint light)
1236{
1237 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1238 LOG_API("nLightDestroy, con(%p), light(%p)", con, (RsLight)light);
1239 rsLightDestroy((RsLight)light);
1240}
1241
1242static void
1243nLightSetColor(JNIEnv *_env, jobject _this, jint light, float r, float g, float b)
1244{
1245 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1246 LOG_API("nLightSetColor, con(%p), light(%p), r(%f), g(%f), b(%f)", con, (RsLight)light, r, g, b);
1247 rsLightSetColor((RsLight)light, r, g, b);
1248}
1249
1250static void
1251nLightSetPosition(JNIEnv *_env, jobject _this, jint light, float x, float y, float z)
1252{
1253 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1254 LOG_API("nLightSetPosition, con(%p), light(%p), x(%f), y(%f), z(%f)", con, (RsLight)light, x, y, z);
1255 rsLightSetPosition((RsLight)light, x, y, z);
1256}
Jason Samsd19f10d2009-05-22 14:03:28 -07001257
1258// ---------------------------------------------------------------------------
1259
Jason Sams1bada8c2009-08-09 17:01:55 -07001260static void
1261nSimpleMeshDestroy(JNIEnv *_env, jobject _this, jint s)
1262{
1263 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1264 LOG_API("nSimpleMeshDestroy, con(%p), SimpleMesh(%p)", con, (RsSimpleMesh)s);
1265 rsSimpleMeshDestroy((RsSimpleMesh)s);
1266}
1267
1268static jint
1269nSimpleMeshCreate(JNIEnv *_env, jobject _this, jint batchID, jint indexID, jintArray vtxIDs, jint primID)
1270{
1271 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1272 jint len = _env->GetArrayLength(vtxIDs);
1273 LOG_API("nSimpleMeshCreate, con(%p), batchID(%i), indexID(%i), vtxIDs.len(%i), primID(%i)",
1274 con, batchID, indexID, len, primID);
1275 jint *ptr = _env->GetIntArrayElements(vtxIDs, NULL);
1276 int id = (int)rsSimpleMeshCreate((void *)batchID, (void *)indexID, (void **)ptr, len, primID);
1277 _env->ReleaseIntArrayElements(vtxIDs, ptr, 0/*JNI_ABORT*/);
1278 return id;
1279}
1280
1281static void
1282nSimpleMeshBindVertex(JNIEnv *_env, jobject _this, jint s, jint alloc, jint slot)
1283{
1284 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1285 LOG_API("nSimpleMeshBindVertex, con(%p), SimpleMesh(%p), Alloc(%p), slot(%i)", con, (RsSimpleMesh)s, (RsAllocation)alloc, slot);
1286 rsSimpleMeshBindVertex((RsSimpleMesh)s, (RsAllocation)alloc, slot);
1287}
1288
1289static void
1290nSimpleMeshBindIndex(JNIEnv *_env, jobject _this, jint s, jint alloc)
1291{
1292 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1293 LOG_API("nSimpleMeshBindIndex, con(%p), SimpleMesh(%p), Alloc(%p)", con, (RsSimpleMesh)s, (RsAllocation)alloc);
1294 rsSimpleMeshBindIndex((RsSimpleMesh)s, (RsAllocation)alloc);
1295}
1296
1297// ---------------------------------------------------------------------------
1298
Jason Samsd19f10d2009-05-22 14:03:28 -07001299
Jason Sams94d8e90a2009-06-10 16:09:05 -07001300static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001301
1302static JNINativeMethod methods[] = {
1303{"_nInit", "()V", (void*)_nInit },
1304{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1305{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1306{"nContextCreate", "(ILandroid/view/Surface;I)I", (void*)nContextCreate },
1307{"nContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams3eaa338e2009-06-10 15:04:38 -07001308{"nAssignName", "(I[B)V", (void*)nAssignName },
Jason Samsd19f10d2009-05-22 14:03:28 -07001309
Jason Sams64676f32009-07-08 18:01:53 -07001310{"nFileOpen", "([B)I", (void*)nFileOpen },
1311
Jason Samsd19f10d2009-05-22 14:03:28 -07001312{"nElementBegin", "()V", (void*)nElementBegin },
1313{"nElementAddPredefined", "(I)V", (void*)nElementAddPredefined },
Jason Sams43ee06852009-08-12 17:54:11 -07001314{"nElementAdd", "(IIIILjava/lang/String;)V", (void*)nElementAdd },
Jason Samsd19f10d2009-05-22 14:03:28 -07001315{"nElementCreate", "()I", (void*)nElementCreate },
1316{"nElementGetPredefined", "(I)I", (void*)nElementGetPredefined },
1317{"nElementDestroy", "(I)V", (void*)nElementDestroy },
1318
1319{"nTypeBegin", "(I)V", (void*)nTypeBegin },
1320{"nTypeAdd", "(II)V", (void*)nTypeAdd },
1321{"nTypeCreate", "()I", (void*)nTypeCreate },
1322{"nTypeDestroy", "(I)V", (void*)nTypeDestroy },
Jason Sams43ee06852009-08-12 17:54:11 -07001323{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy },
1324{"nTypeSetupFields", "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields },
Jason Samsd19f10d2009-05-22 14:03:28 -07001325
1326{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
1327{"nAllocationCreatePredefSized", "(II)I", (void*)nAllocationCreatePredefSized },
1328{"nAllocationCreateSized", "(II)I", (void*)nAllocationCreateSized },
Jason Samsffe9f482009-06-01 17:45:53 -07001329{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
Jason Samsb0ec1b42009-07-28 12:02:16 -07001330{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
Jason Samsd19f10d2009-05-22 14:03:28 -07001331{"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture },
1332{"nAllocationDestroy", "(I)V", (void*)nAllocationDestroy },
1333{"nAllocationData", "(I[I)V", (void*)nAllocationData_i },
1334{"nAllocationData", "(I[F)V", (void*)nAllocationData_f },
1335{"nAllocationSubData1D", "(III[I)V", (void*)nAllocationSubData1D_i },
1336{"nAllocationSubData1D", "(III[F)V", (void*)nAllocationSubData1D_f },
1337{"nAllocationSubData2D", "(IIIII[I)V", (void*)nAllocationSubData2D_i },
1338{"nAllocationSubData2D", "(IIIII[F)V", (void*)nAllocationSubData2D_f },
Jason Sams40a29e82009-08-10 14:55:26 -07001339{"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i },
1340{"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f },
Jason Sams43ee06852009-08-12 17:54:11 -07001341{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject },
Jason Samsd19f10d2009-05-22 14:03:28 -07001342
1343{"nTriangleMeshDestroy", "(I)V", (void*)nTriangleMeshDestroy },
1344{"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin },
1345{"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY },
1346{"nTriangleMeshAddVertex_XYZ", "(FFF)V", (void*)nTriangleMeshAddVertex_XYZ },
1347{"nTriangleMeshAddVertex_XY_ST", "(FFFF)V", (void*)nTriangleMeshAddVertex_XY_ST },
1348{"nTriangleMeshAddVertex_XYZ_ST", "(FFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST },
Jason Sams0826a6f2009-06-15 19:04:56 -07001349{"nTriangleMeshAddVertex_XYZ_ST_NORM", "(FFFFFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST_NORM },
Jason Samsd19f10d2009-05-22 14:03:28 -07001350{"nTriangleMeshAddTriangle", "(III)V", (void*)nTriangleMeshAddTriangle },
1351{"nTriangleMeshCreate", "()I", (void*)nTriangleMeshCreate },
1352
1353{"nAdapter1DDestroy", "(I)V", (void*)nAdapter1DDestroy },
1354{"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation },
1355{"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint },
1356{"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i },
Jason Samsd19f10d2009-05-22 14:03:28 -07001357{"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001358{"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i },
Jason Samsd19f10d2009-05-22 14:03:28 -07001359{"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f },
1360{"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate },
1361
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001362{"nAdapter2DDestroy", "(I)V", (void*)nAdapter2DDestroy },
1363{"nAdapter2DBindAllocation", "(II)V", (void*)nAdapter2DBindAllocation },
1364{"nAdapter2DSetConstraint", "(III)V", (void*)nAdapter2DSetConstraint },
1365{"nAdapter2DData", "(I[I)V", (void*)nAdapter2DData_i },
1366{"nAdapter2DData", "(I[F)V", (void*)nAdapter2DData_f },
1367{"nAdapter2DSubData", "(IIIII[I)V", (void*)nAdapter2DSubData_i },
1368{"nAdapter2DSubData", "(IIIII[F)V", (void*)nAdapter2DSubData_f },
1369{"nAdapter2DCreate", "()I", (void*)nAdapter2DCreate },
1370
Jason Samsd19f10d2009-05-22 14:03:28 -07001371{"nScriptDestroy", "(I)V", (void*)nScriptDestroy },
1372{"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation },
Jason Sams22534172009-08-04 16:58:20 -07001373{"nScriptSetClearColor", "(IFFFF)V", (void*)nScriptSetClearColor },
1374{"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth },
1375{"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil },
1376{"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone },
1377
Jason Samsd19f10d2009-05-22 14:03:28 -07001378{"nScriptCBegin", "()V", (void*)nScriptCBegin },
Jason Samsd19f10d2009-05-22 14:03:28 -07001379{"nScriptCAddType", "(I)V", (void*)nScriptCAddType },
1380{"nScriptCSetRoot", "(Z)V", (void*)nScriptCSetRoot },
Jack Palevich43702d82009-05-28 13:38:16 -07001381{"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript },
Jason Samsd19f10d2009-05-22 14:03:28 -07001382{"nScriptCCreate", "()I", (void*)nScriptCCreate },
Joe Onoratod7b37742009-08-09 22:57:44 -07001383{"nScriptCAddDefineI32", "(Ljava/lang/String;I)V", (void*)nScriptCAddDefineI32 },
1384{"nScriptCAddDefineF", "(Ljava/lang/String;F)V", (void*)nScriptCAddDefineF },
Jason Samsd19f10d2009-05-22 14:03:28 -07001385
1386{"nProgramFragmentStoreBegin", "(II)V", (void*)nProgramFragmentStoreBegin },
1387{"nProgramFragmentStoreDepthFunc", "(I)V", (void*)nProgramFragmentStoreDepthFunc },
1388{"nProgramFragmentStoreDepthMask", "(Z)V", (void*)nProgramFragmentStoreDepthMask },
1389{"nProgramFragmentStoreColorMask", "(ZZZZ)V", (void*)nProgramFragmentStoreColorMask },
1390{"nProgramFragmentStoreBlendFunc", "(II)V", (void*)nProgramFragmentStoreBlendFunc },
1391{"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither },
1392{"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate },
Jason Sams3eaa338e2009-06-10 15:04:38 -07001393{"nProgramFragmentStoreDestroy", "(I)V", (void*)nProgramFragmentStoreDestroy },
Jason Samsd19f10d2009-05-22 14:03:28 -07001394
1395{"nProgramFragmentBegin", "(II)V", (void*)nProgramFragmentBegin },
1396{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture },
1397{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler },
1398{"nProgramFragmentSetType", "(II)V", (void*)nProgramFragmentSetType },
1399{"nProgramFragmentSetEnvMode", "(II)V", (void*)nProgramFragmentSetEnvMode },
1400{"nProgramFragmentSetTexEnable", "(IZ)V", (void*)nProgramFragmentSetTexEnable },
1401{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate },
Jason Sams3eaa338e2009-06-10 15:04:38 -07001402{"nProgramFragmentDestroy", "(I)V", (void*)nProgramFragmentDestroy },
Jason Samsd19f10d2009-05-22 14:03:28 -07001403
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001404{"nProgramVertexDestroy", "(I)V", (void*)nProgramVertexDestroy },
Jason Sams9bee51c2009-08-05 13:57:03 -07001405{"nProgramVertexBindAllocation", "(II)V", (void*)nProgramVertexBindAllocation },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001406{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001407{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable },
Jason Samsee411122009-07-21 12:20:54 -07001408{"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001409{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate },
1410
Jason Samsbba134c2009-06-22 15:49:21 -07001411{"nLightBegin", "()V", (void*)nLightBegin },
1412{"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono },
1413{"nLightSetIsLocal", "(Z)V", (void*)nLightSetIsLocal },
1414{"nLightCreate", "()I", (void*)nLightCreate },
1415{"nLightDestroy", "(I)V", (void*)nLightDestroy },
1416{"nLightSetColor", "(IFFF)V", (void*)nLightSetColor },
1417{"nLightSetPosition", "(IFFF)V", (void*)nLightSetPosition },
1418
Jason Samsd19f10d2009-05-22 14:03:28 -07001419{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript },
Jason Samsd19f10d2009-05-22 14:03:28 -07001420{"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore },
1421{"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment },
Jason Sams0826a6f2009-06-15 19:04:56 -07001422{"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001423
Jason Sams02fb2cb2009-05-28 15:37:57 -07001424{"nSamplerDestroy", "(I)V", (void*)nSamplerDestroy },
1425{"nSamplerBegin", "()V", (void*)nSamplerBegin },
1426{"nSamplerSet", "(II)V", (void*)nSamplerSet },
1427{"nSamplerCreate", "()I", (void*)nSamplerCreate },
1428
Jason Sams1bada8c2009-08-09 17:01:55 -07001429{"nSimpleMeshDestroy", "(I)V", (void*)nSimpleMeshDestroy },
1430{"nSimpleMeshCreate", "(II[II)I", (void*)nSimpleMeshCreate },
1431{"nSimpleMeshBindVertex", "(III)V", (void*)nSimpleMeshBindVertex },
1432{"nSimpleMeshBindIndex", "(II)V", (void*)nSimpleMeshBindIndex },
1433
Jason Samsd19f10d2009-05-22 14:03:28 -07001434};
1435
1436static int registerFuncs(JNIEnv *_env)
1437{
1438 return android::AndroidRuntime::registerNativeMethods(
1439 _env, classPathName, methods, NELEM(methods));
1440}
1441
1442// ---------------------------------------------------------------------------
1443
1444jint JNI_OnLoad(JavaVM* vm, void* reserved)
1445{
1446 JNIEnv* env = NULL;
1447 jint result = -1;
1448
Jason Samsd19f10d2009-05-22 14:03:28 -07001449 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1450 LOGE("ERROR: GetEnv failed\n");
1451 goto bail;
1452 }
1453 assert(env != NULL);
1454
1455 if (registerFuncs(env) < 0) {
1456 LOGE("ERROR: MediaPlayer native registration failed\n");
1457 goto bail;
1458 }
1459
1460 /* success -- return valid version number */
1461 result = JNI_VERSION_1_4;
1462
1463bail:
1464 return result;
1465}