blob: 4a8f8a3ccee921cc59420fac137fea14062d767a [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>
Romain Guy650a3eb2009-08-31 14:06:43 -070029#include <core/SkPixelRef.h>
30#include <core/SkStream.h>
31#include <core/SkTemplates.h>
32#include <images/SkImageDecoder.h>
Jason Samsffe9f482009-06-01 17:45:53 -070033
Romain Guy650a3eb2009-08-31 14:06:43 -070034#include <utils/Asset.h>
35#include <utils/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070036
Jason Samsd19f10d2009-05-22 14:03:28 -070037#include "jni.h"
38#include "JNIHelp.h"
39#include "android_runtime/AndroidRuntime.h"
40
Jason Samse29d4712009-07-23 15:19:03 -070041#include <RenderScript.h>
42#include <RenderScriptEnv.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070043
44//#define LOG_API LOGE
45#define LOG_API(...)
46
47using namespace android;
48
Jason Samsd19f10d2009-05-22 14:03:28 -070049// ---------------------------------------------------------------------------
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
Jason Samsffe9f482009-06-01 17:45:53 -070057static jfieldID gContextId = 0;
58static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -070059static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -070060
Jason Samsea84a7c2009-09-04 14:42:41 -070061static RsElement g_A_8 = NULL;
62static RsElement g_RGBA_4444 = NULL;
63static RsElement g_RGBA_8888 = NULL;
64static RsElement g_RGB_565 = NULL;
65
Jason Samsd19f10d2009-05-22 14:03:28 -070066static void _nInit(JNIEnv *_env, jclass _this)
67{
Jason Samsd19f10d2009-05-22 14:03:28 -070068 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -070069
70 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
71 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Sams43ee06852009-08-12 17:54:11 -070072
73 jclass typeClass = _env->FindClass("android/renderscript/Type");
74 gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -070075}
76
Jason Samsea84a7c2009-09-04 14:42:41 -070077static 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}
Jason Samsd19f10d2009-05-22 14:03:28 -070084
85// ---------------------------------------------------------------------------
86
Jason Sams3eaa338e2009-06-10 15:04:38 -070087static void
88nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str)
89{
90 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams07ae4062009-08-27 20:23:34 -070091 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -070092
93 jint len = _env->GetArrayLength(str);
94 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -070095 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -070096 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
97}
98
Jason Sams7ce033d2009-08-18 14:14:24 -070099static 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
Jason Sams730ee652009-08-18 17:07:09 -0700107static 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}
Jason Sams3eaa338e2009-06-10 15:04:38 -0700116
Jason Sams64676f32009-07-08 18:01:53 -0700117static 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);
Jason Samsbc948de2009-08-17 18:35:48 -0700125 jint ret = (jint)rsFileOpen(con, (const char *)cptr, len);
Jason Sams64676f32009-07-08 18:01:53 -0700126 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
127 return ret;
128}
129
Jason Sams3eaa338e2009-06-10 15:04:38 -0700130// ---------------------------------------------------------------------------
131
Jason Samsd19f10d2009-05-22 14:03:28 -0700132static 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
Jason Samsebfb4362009-09-23 13:57:02 -0700146static 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
Jason Samsd19f10d2009-05-22 14:03:28 -0700153static jint
Jason Samsb13ada52009-08-25 11:34:49 -0700154nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver, jboolean useDepth)
Jason Samsd19f10d2009-05-22 14:03:28 -0700155{
156 LOG_API("nContextCreate");
157
158 if (wnd == NULL) {
159 not_valid_surface:
160 doThrow(_env, "java/lang/IllegalArgumentException",
161 "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
162 return 0;
163 }
164 jclass surface_class = _env->FindClass("android/view/Surface");
165 jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I");
166 Surface * window = (Surface*)_env->GetIntField(wnd, surfaceFieldID);
167 if (window == NULL)
168 goto not_valid_surface;
169
Jason Samsb13ada52009-08-25 11:34:49 -0700170 return (jint)rsContextCreate((RsDevice)dev, window, ver, useDepth);
Jason Samsd19f10d2009-05-22 14:03:28 -0700171}
172
173static void
174nContextDestroy(JNIEnv *_env, jobject _this, jint con)
175{
176 LOG_API("nContextDestroy, con(%p)", (RsContext)con);
177 return rsContextDestroy((RsContext)con);
178}
179
180
181static void
182nElementBegin(JNIEnv *_env, jobject _this)
183{
184 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
185 LOG_API("nElementBegin, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700186 rsElementBegin(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700187}
188
Jason Samsd19f10d2009-05-22 14:03:28 -0700189
190static void
Jason Sams768bc022009-09-21 19:41:04 -0700191nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jboolean norm, jint bits, jstring name)
Jason Samsd19f10d2009-05-22 14:03:28 -0700192{
193 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams43ee06852009-08-12 17:54:11 -0700194 const char* n = NULL;
195 if (name) {
196 n = _env->GetStringUTFChars(name, NULL);
197 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700198 LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits);
Jason Samsbc948de2009-08-17 18:35:48 -0700199 rsElementAdd(con, (RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits, n);
Jason Sams43ee06852009-08-12 17:54:11 -0700200 if (n) {
201 _env->ReleaseStringUTFChars(name, n);
202 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700203}
204
205static jint
206nElementCreate(JNIEnv *_env, jobject _this)
207{
208 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
209 LOG_API("nElementCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700210 return (jint)rsElementCreate(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700211}
212
Jason Samsd19f10d2009-05-22 14:03:28 -0700213// -----------------------------------
214
215static void
216nTypeBegin(JNIEnv *_env, jobject _this, jint eID)
217{
218 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
219 LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID);
Jason Samsbc948de2009-08-17 18:35:48 -0700220 rsTypeBegin(con, (RsElement)eID);
Jason Samsd19f10d2009-05-22 14:03:28 -0700221}
222
223static void
224nTypeAdd(JNIEnv *_env, jobject _this, jint dim, jint val)
225{
226 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
227 LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val);
Jason Samsbc948de2009-08-17 18:35:48 -0700228 rsTypeAdd(con, (RsDimension)dim, val);
Jason Samsd19f10d2009-05-22 14:03:28 -0700229}
230
231static jint
232nTypeCreate(JNIEnv *_env, jobject _this)
233{
234 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
235 LOG_API("nTypeCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700236 return (jint)rsTypeCreate(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700237}
238
Jason Sams43ee06852009-08-12 17:54:11 -0700239static void * SF_LoadInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
240{
241 ((int32_t *)buffer)[0] = _env->GetIntField(_obj, _field);
242 return ((uint8_t *)buffer) + 4;
243}
244
245static void * SF_LoadShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
246{
247 ((int16_t *)buffer)[0] = _env->GetShortField(_obj, _field);
248 return ((uint8_t *)buffer) + 2;
249}
250
251static void * SF_LoadByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
252{
253 ((int8_t *)buffer)[0] = _env->GetByteField(_obj, _field);
254 return ((uint8_t *)buffer) + 1;
255}
256
257static void * SF_LoadFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
258{
259 ((float *)buffer)[0] = _env->GetFloatField(_obj, _field);
260 return ((uint8_t *)buffer) + 4;
261}
262
Jason Sams5f43fd22009-09-15 12:39:22 -0700263static void * SF_SaveInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
264{
Jason Sams5f43fd22009-09-15 12:39:22 -0700265 _env->SetIntField(_obj, _field, ((int32_t *)buffer)[0]);
266 return ((uint8_t *)buffer) + 4;
267}
268
269static void * SF_SaveShort(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
270{
Jason Sams5f43fd22009-09-15 12:39:22 -0700271 _env->SetShortField(_obj, _field, ((int16_t *)buffer)[0]);
272 return ((uint8_t *)buffer) + 2;
273}
274
275static void * SF_SaveByte(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
276{
Jason Sams5f43fd22009-09-15 12:39:22 -0700277 _env->SetByteField(_obj, _field, ((int8_t *)buffer)[0]);
278 return ((uint8_t *)buffer) + 1;
279}
280
281static void * SF_SaveFloat(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
282{
Jason Sams5f43fd22009-09-15 12:39:22 -0700283 _env->SetFloatField(_obj, _field, ((float *)buffer)[0]);
284 return ((uint8_t *)buffer) + 4;
285}
286
Jason Sams43ee06852009-08-12 17:54:11 -0700287struct TypeFieldCache {
288 jfieldID field;
289 int bits;
290 void * (*ptr)(JNIEnv *, jobject, jfieldID, void *buffer);
Jason Sams5f43fd22009-09-15 12:39:22 -0700291 void * (*readPtr)(JNIEnv *, jobject, jfieldID, void *buffer);
Jason Sams43ee06852009-08-12 17:54:11 -0700292};
293
294struct TypeCache {
295 int fieldCount;
296 int size;
297 TypeFieldCache fields[1];
298};
299
300//{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy },
301static void
302nTypeFinalDestroy(JNIEnv *_env, jobject _this, jobject _type)
303{
304 TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
305 free(tc);
306}
307
308// native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
309static void
310nTypeSetupFields(JNIEnv *_env, jobject _this, jobject _type, jintArray _types, jintArray _bits, jobjectArray _IDs)
311{
312 int fieldCount = _env->GetArrayLength(_types);
313 size_t structSize = sizeof(TypeCache) + (sizeof(TypeFieldCache) * (fieldCount-1));
314 TypeCache *tc = (TypeCache *)malloc(structSize);
315 memset(tc, 0, structSize);
316
317 TypeFieldCache *tfc = &tc->fields[0];
318 tc->fieldCount = fieldCount;
319 _env->SetIntField(_type, gTypeNativeCache, (jint)tc);
320
321 jint *fType = _env->GetIntArrayElements(_types, NULL);
322 jint *fBits = _env->GetIntArrayElements(_bits, NULL);
323 for (int ct=0; ct < fieldCount; ct++) {
324 jobject field = _env->GetObjectArrayElement(_IDs, ct);
325 tfc[ct].field = _env->FromReflectedField(field);
326 tfc[ct].bits = fBits[ct];
327
328 switch(fType[ct]) {
329 case RS_TYPE_FLOAT:
330 tfc[ct].ptr = SF_LoadFloat;
Jason Sams5f43fd22009-09-15 12:39:22 -0700331 tfc[ct].readPtr = SF_SaveFloat;
Jason Sams43ee06852009-08-12 17:54:11 -0700332 break;
333 case RS_TYPE_UNSIGNED:
334 case RS_TYPE_SIGNED:
335 switch(tfc[ct].bits) {
Jason Sams5f43fd22009-09-15 12:39:22 -0700336 case 32:
337 tfc[ct].ptr = SF_LoadInt;
338 tfc[ct].readPtr = SF_SaveInt;
339 break;
340 case 16:
341 tfc[ct].ptr = SF_LoadShort;
342 tfc[ct].readPtr = SF_SaveShort;
343 break;
344 case 8:
345 tfc[ct].ptr = SF_LoadByte;
346 tfc[ct].readPtr = SF_SaveByte;
347 break;
Jason Sams43ee06852009-08-12 17:54:11 -0700348 }
349 break;
350 }
351 tc->size += 4;
352 }
353
354 _env->ReleaseIntArrayElements(_types, fType, JNI_ABORT);
355 _env->ReleaseIntArrayElements(_bits, fBits, JNI_ABORT);
356}
357
358
Jason Samsd19f10d2009-05-22 14:03:28 -0700359// -----------------------------------
360
361static jint
362nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
363{
364 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
365 LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e);
Jason Samsbc948de2009-08-17 18:35:48 -0700366 return (jint) rsAllocationCreateTyped(con, (RsElement)e);
Jason Samsd19f10d2009-05-22 14:03:28 -0700367}
368
Jason Samsd19f10d2009-05-22 14:03:28 -0700369static void
370nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
371{
372 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
373 LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip);
Jason Samsbc948de2009-08-17 18:35:48 -0700374 rsAllocationUploadToTexture(con, (RsAllocation)a, mip);
Jason Samsd19f10d2009-05-22 14:03:28 -0700375}
376
Jason Sams07ae4062009-08-27 20:23:34 -0700377static void
378nAllocationUploadToBufferObject(JNIEnv *_env, jobject _this, jint a)
379{
380 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
381 LOG_API("nAllocationUploadToBufferObject, con(%p), a(%p)", con, (RsAllocation)a);
382 rsAllocationUploadToBufferObject(con, (RsAllocation)a);
383}
384
Jason Samsea84a7c2009-09-04 14:42:41 -0700385static RsElement SkBitmapToPredefined(SkBitmap::Config cfg)
Jason Samsfe08d992009-05-27 14:45:32 -0700386{
Jason Samsffe9f482009-06-01 17:45:53 -0700387 switch (cfg) {
388 case SkBitmap::kA8_Config:
Jason Samsea84a7c2009-09-04 14:42:41 -0700389 return g_A_8;
Jason Samsffe9f482009-06-01 17:45:53 -0700390 case SkBitmap::kARGB_4444_Config:
Jason Samsea84a7c2009-09-04 14:42:41 -0700391 return g_RGBA_4444;
Jason Samsffe9f482009-06-01 17:45:53 -0700392 case SkBitmap::kARGB_8888_Config:
Jason Samsea84a7c2009-09-04 14:42:41 -0700393 return g_RGBA_8888;
Jason Samsffe9f482009-06-01 17:45:53 -0700394 case SkBitmap::kRGB_565_Config:
Jason Samsea84a7c2009-09-04 14:42:41 -0700395 return g_RGB_565;
Jason Samsfe08d992009-05-27 14:45:32 -0700396
Jason Samsffe9f482009-06-01 17:45:53 -0700397 default:
398 break;
399 }
400 // If we don't have a conversion mark it as a user type.
401 LOGE("Unsupported bitmap type");
Jason Samsea84a7c2009-09-04 14:42:41 -0700402 return NULL;
Jason Samsfe08d992009-05-27 14:45:32 -0700403}
404
Jason Samsffe9f482009-06-01 17:45:53 -0700405static int
406nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
407{
408 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
409 SkBitmap const * nativeBitmap =
410 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
411 const SkBitmap& bitmap(*nativeBitmap);
412 SkBitmap::Config config = bitmap.getConfig();
413
Jason Samsea84a7c2009-09-04 14:42:41 -0700414 RsElement e = SkBitmapToPredefined(config);
415 if (e) {
Jason Samsffe9f482009-06-01 17:45:53 -0700416 bitmap.lockPixels();
417 const int w = bitmap.width();
418 const int h = bitmap.height();
419 const void* ptr = bitmap.getPixels();
Jason Samsea84a7c2009-09-04 14:42:41 -0700420 jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
Jason Samsffe9f482009-06-01 17:45:53 -0700421 bitmap.unlockPixels();
422 return id;
423 }
424 return 0;
425}
Jason Samsfe08d992009-05-27 14:45:32 -0700426
Jason Samsb0ec1b42009-07-28 12:02:16 -0700427static int
Romain Guy650a3eb2009-08-31 14:06:43 -0700428nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset)
429{
430 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
431
432 Asset* asset = reinterpret_cast<Asset*>(native_asset);
433 SkBitmap bitmap;
434 SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),
435 &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode);
436
437 SkBitmap::Config config = bitmap.getConfig();
438
Jason Samsea84a7c2009-09-04 14:42:41 -0700439 RsElement e = SkBitmapToPredefined(config);
Romain Guy650a3eb2009-08-31 14:06:43 -0700440
Jason Samsea84a7c2009-09-04 14:42:41 -0700441 if (e) {
Romain Guy650a3eb2009-08-31 14:06:43 -0700442 bitmap.lockPixels();
443 const int w = bitmap.width();
444 const int h = bitmap.height();
445 const void* ptr = bitmap.getPixels();
Jason Samsea84a7c2009-09-04 14:42:41 -0700446 jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
Romain Guy650a3eb2009-08-31 14:06:43 -0700447 bitmap.unlockPixels();
448 return id;
449 }
450 return 0;
451}
452
453static int
Jason Samsb0ec1b42009-07-28 12:02:16 -0700454nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
455{
456 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
457 SkBitmap const * nativeBitmap =
458 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
459 const SkBitmap& bitmap(*nativeBitmap);
460 SkBitmap::Config config = bitmap.getConfig();
461
Jason Samsea84a7c2009-09-04 14:42:41 -0700462 RsElement e = SkBitmapToPredefined(config);
Jason Samsb0ec1b42009-07-28 12:02:16 -0700463
Jason Samsea84a7c2009-09-04 14:42:41 -0700464 if (e) {
Jason Samsb0ec1b42009-07-28 12:02:16 -0700465 bitmap.lockPixels();
466 const int w = bitmap.width();
467 const int h = bitmap.height();
468 const void* ptr = bitmap.getPixels();
Jason Samsea84a7c2009-09-04 14:42:41 -0700469 jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
Jason Samsb0ec1b42009-07-28 12:02:16 -0700470 bitmap.unlockPixels();
471 return id;
472 }
473 return 0;
474}
475
Jason Samsfe08d992009-05-27 14:45:32 -0700476
Jason Samsd19f10d2009-05-22 14:03:28 -0700477static void
Jason Sams07ae4062009-08-27 20:23:34 -0700478nAllocationSubData1D_i(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700479{
480 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
481 jint len = _env->GetArrayLength(data);
Jason Sams768bc022009-09-21 19:41:04 -0700482 LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700483 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams07ae4062009-08-27 20:23:34 -0700484 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700485 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
486}
487
488static void
Jason Sams768bc022009-09-21 19:41:04 -0700489nAllocationSubData1D_s(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jshortArray data, int sizeBytes)
490{
491 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
492 jint len = _env->GetArrayLength(data);
493 LOG_API("nAllocation1DSubData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
494 jshort *ptr = _env->GetShortArrayElements(data, NULL);
495 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes);
496 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
497}
498
499static void
500nAllocationSubData1D_b(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jbyteArray data, int sizeBytes)
501{
502 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
503 jint len = _env->GetArrayLength(data);
504 LOG_API("nAllocation1DSubData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
505 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
506 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes);
507 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
508}
509
510static void
Jason Sams07ae4062009-08-27 20:23:34 -0700511nAllocationSubData1D_f(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700512{
513 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
514 jint len = _env->GetArrayLength(data);
Jason Sams768bc022009-09-21 19:41:04 -0700515 LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700516 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams07ae4062009-08-27 20:23:34 -0700517 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700518 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
519}
520
521static void
Jason Sams07ae4062009-08-27 20:23:34 -0700522nAllocationSubData2D_i(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700523{
524 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
525 jint len = _env->GetArrayLength(data);
526 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);
527 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams07ae4062009-08-27 20:23:34 -0700528 rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700529 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
530}
531
532static void
Jason Sams07ae4062009-08-27 20:23:34 -0700533nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700534{
535 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
536 jint len = _env->GetArrayLength(data);
537 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);
538 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams07ae4062009-08-27 20:23:34 -0700539 rsAllocation2DSubData(con, (RsAllocation)alloc, xoff, yoff, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700540 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
541}
542
Jason Sams40a29e82009-08-10 14:55:26 -0700543static void
544nAllocationRead_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data)
545{
546 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
547 jint len = _env->GetArrayLength(data);
548 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
549 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700550 rsAllocationRead(con, (RsAllocation)alloc, ptr);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700551 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700552}
553
554static void
555nAllocationRead_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data)
556{
557 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
558 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700559 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700560 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700561 rsAllocationRead(con, (RsAllocation)alloc, ptr);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700562 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700563}
Jason Samsd19f10d2009-05-22 14:03:28 -0700564
565
Jason Sams43ee06852009-08-12 17:54:11 -0700566//{"nAllocationDataFromObject", "(ILandroid/renderscript/Type;Ljava/lang/Object;)V", (void*)nAllocationDataFromObject },
567static void
Jason Sams2525a812009-09-03 15:43:13 -0700568nAllocationSubDataFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jint offset, jobject _o)
Jason Sams43ee06852009-08-12 17:54:11 -0700569{
570 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
571 LOG_API("nAllocationDataFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc);
572
573 const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
574
575 void * bufAlloc = malloc(tc->size);
576 void * buf = bufAlloc;
577 for (int ct=0; ct < tc->fieldCount; ct++) {
578 const TypeFieldCache *tfc = &tc->fields[ct];
579 buf = tfc->ptr(_env, _o, tfc->field, buf);
580 }
Jason Sams2525a812009-09-03 15:43:13 -0700581 rsAllocation1DSubData(con, (RsAllocation)alloc, offset, 1, bufAlloc, tc->size);
Jason Sams5f43fd22009-09-15 12:39:22 -0700582 free(bufAlloc);
583}
584
585static void
586nAllocationSubReadFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _type, jint offset, jobject _o)
587{
588 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
589 LOG_API("nAllocationReadFromObject con(%p), alloc(%p)", con, (RsAllocation)alloc);
590
591 assert(offset == 0);
592
593 const TypeCache *tc = (TypeCache *)_env->GetIntField(_type, gTypeNativeCache);
594
595 void * bufAlloc = malloc(tc->size);
596 void * buf = bufAlloc;
597 rsAllocationRead(con, (RsAllocation)alloc, bufAlloc);
598
Jason Sams5f43fd22009-09-15 12:39:22 -0700599 for (int ct=0; ct < tc->fieldCount; ct++) {
600 const TypeFieldCache *tfc = &tc->fields[ct];
Jason Sams5f43fd22009-09-15 12:39:22 -0700601 buf = tfc->readPtr(_env, _o, tfc->field, buf);
602 }
Jason Sams43ee06852009-08-12 17:54:11 -0700603 free(bufAlloc);
604}
605
Jason Samsd19f10d2009-05-22 14:03:28 -0700606// -----------------------------------
607
608static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700609nTriangleMeshBegin(JNIEnv *_env, jobject _this, jint v, jint i)
610{
611 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
612 LOG_API("nTriangleMeshBegin, con(%p), vertex(%p), index(%p)", con, (RsElement)v, (RsElement)i);
Jason Samsbc948de2009-08-17 18:35:48 -0700613 rsTriangleMeshBegin(con, (RsElement)v, (RsElement)i);
Jason Samsd19f10d2009-05-22 14:03:28 -0700614}
615
616static void
617nTriangleMeshAddVertex_XY(JNIEnv *_env, jobject _this, jfloat x, jfloat y)
618{
619 float v[] = {x, y};
620 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
621 LOG_API("nTriangleMeshAddVertex_XY, con(%p), x(%f), y(%f)", con, x, y);
Jason Samsbc948de2009-08-17 18:35:48 -0700622 rsTriangleMeshAddVertex(con, v);
Jason Samsd19f10d2009-05-22 14:03:28 -0700623}
624
625static void
626nTriangleMeshAddVertex_XYZ(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z)
627{
628 float v[] = {x, y, z};
629 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
630 LOG_API("nTriangleMeshAddVertex_XYZ, con(%p), x(%f), y(%f), z(%f)", con, x, y, z);
Jason Samsbc948de2009-08-17 18:35:48 -0700631 rsTriangleMeshAddVertex(con, v);
Jason Samsd19f10d2009-05-22 14:03:28 -0700632}
633
634static void
635nTriangleMeshAddVertex_XY_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat s, jfloat t)
636{
637 float v[] = {s, t, x, y};
638 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
639 LOG_API("nTriangleMeshAddVertex_XY_ST, con(%p), x(%f), y(%f), s(%f), t(%f)", con, x, y, s, t);
Jason Samsbc948de2009-08-17 18:35:48 -0700640 rsTriangleMeshAddVertex(con, v);
Jason Samsd19f10d2009-05-22 14:03:28 -0700641}
642
643static void
644nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t)
645{
646 float v[] = {s, t, x, y, z};
647 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
648 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
Jason Samsbc948de2009-08-17 18:35:48 -0700649 rsTriangleMeshAddVertex(con, v);
Jason Samsd19f10d2009-05-22 14:03:28 -0700650}
651
652static void
Jason Sams0826a6f2009-06-15 19:04:56 -0700653nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz)
654{
655 float v[] = {nx, ny, nz, s, t, x, y, z};
656 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
657 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
Jason Samsbc948de2009-08-17 18:35:48 -0700658 rsTriangleMeshAddVertex(con, v);
Jason Sams0826a6f2009-06-15 19:04:56 -0700659}
660
661static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700662nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3)
663{
664 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
665 LOG_API("nTriangleMeshAddTriangle, con(%p), i1(%i), i2(%i), i3(%i)", con, i1, i2, i3);
Jason Samsbc948de2009-08-17 18:35:48 -0700666 rsTriangleMeshAddTriangle(con, i1, i2, i3);
Jason Samsd19f10d2009-05-22 14:03:28 -0700667}
668
669static jint
670nTriangleMeshCreate(JNIEnv *_env, jobject _this)
671{
672 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
673 LOG_API("nTriangleMeshCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700674 return (jint) rsTriangleMeshCreate(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700675}
676
677// -----------------------------------
678
679static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700680nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc)
681{
682 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
683 LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc);
Jason Samsbc948de2009-08-17 18:35:48 -0700684 rsAdapter1DBindAllocation(con, (RsAdapter1D)adapter, (RsAllocation)alloc);
Jason Samsd19f10d2009-05-22 14:03:28 -0700685}
686
687static void
688nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value)
689{
690 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
691 LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value);
Jason Samsbc948de2009-08-17 18:35:48 -0700692 rsAdapter1DSetConstraint(con, (RsAdapter1D)adapter, (RsDimension)dim, value);
Jason Samsd19f10d2009-05-22 14:03:28 -0700693}
694
695static void
696nAdapter1DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data)
697{
698 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
699 jint len = _env->GetArrayLength(data);
700 LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len);
701 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700702 rsAdapter1DData(con, (RsAdapter1D)adapter, ptr);
Jason Samsd19f10d2009-05-22 14:03:28 -0700703 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
704}
705
706static void
707nAdapter1DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jintArray data)
708{
709 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
710 jint len = _env->GetArrayLength(data);
711 LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len);
712 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700713 rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr);
Jason Samsd19f10d2009-05-22 14:03:28 -0700714 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
715}
716
717static void
718nAdapter1DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data)
719{
720 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
721 jint len = _env->GetArrayLength(data);
722 LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len);
723 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700724 rsAdapter1DData(con, (RsAdapter1D)adapter, ptr);
Jason Samsd19f10d2009-05-22 14:03:28 -0700725 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
726}
727
728static void
729nAdapter1DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jfloatArray data)
730{
731 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
732 jint len = _env->GetArrayLength(data);
733 LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len);
734 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700735 rsAdapter1DSubData(con, (RsAdapter1D)adapter, offset, count, ptr);
Jason Samsd19f10d2009-05-22 14:03:28 -0700736 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
737}
738
739static jint
740nAdapter1DCreate(JNIEnv *_env, jobject _this)
741{
742 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
743 LOG_API("nAdapter1DCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700744 return (jint)rsAdapter1DCreate(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700745}
746
747// -----------------------------------
748
749static void
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700750nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc)
751{
752 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
753 LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc);
Jason Samsbc948de2009-08-17 18:35:48 -0700754 rsAdapter2DBindAllocation(con, (RsAdapter2D)adapter, (RsAllocation)alloc);
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700755}
756
757static void
758nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value)
759{
760 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
761 LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value);
Jason Samsbc948de2009-08-17 18:35:48 -0700762 rsAdapter2DSetConstraint(con, (RsAdapter2D)adapter, (RsDimension)dim, value);
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700763}
764
765static void
766nAdapter2DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data)
767{
768 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
769 jint len = _env->GetArrayLength(data);
770 LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len);
771 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700772 rsAdapter2DData(con, (RsAdapter2D)adapter, ptr);
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700773 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
774}
775
776static void
777nAdapter2DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data)
778{
779 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
780 jint len = _env->GetArrayLength(data);
781 LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len);
782 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700783 rsAdapter2DData(con, (RsAdapter2D)adapter, ptr);
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700784 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
785}
786
787static void
788nAdapter2DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data)
789{
790 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
791 jint len = _env->GetArrayLength(data);
792 LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)",
793 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len);
794 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700795 rsAdapter2DSubData(con, (RsAdapter2D)adapter, xoff, yoff, w, h, ptr);
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700796 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
797}
798
799static void
800nAdapter2DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data)
801{
802 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
803 jint len = _env->GetArrayLength(data);
804 LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)",
805 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len);
806 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -0700807 rsAdapter2DSubData(con, (RsAdapter1D)adapter, xoff, yoff, w, h, ptr);
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700808 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
809}
810
811static jint
812nAdapter2DCreate(JNIEnv *_env, jobject _this)
813{
814 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
815 LOG_API("nAdapter2DCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700816 return (jint)rsAdapter2DCreate(con);
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700817}
818
819// -----------------------------------
820
821static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700822nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint slot)
823{
824 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
825 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700826 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700827}
828
829static void
Jason Sams22534172009-08-04 16:58:20 -0700830nScriptSetClearColor(JNIEnv *_env, jobject _this, jint script, jfloat r, jfloat g, jfloat b, jfloat a)
Jason Samsd19f10d2009-05-22 14:03:28 -0700831{
832 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams07ae4062009-08-27 20:23:34 -0700833 LOG_API("nScriptSetClearColor, con(%p), s(%p), r(%f), g(%f), b(%f), a(%f)", con, (void *)script, r, g, b, a);
Jason Samsbc948de2009-08-17 18:35:48 -0700834 rsScriptSetClearColor(con, (RsScript)script, r, g, b, a);
Jason Samsd19f10d2009-05-22 14:03:28 -0700835}
836
837static void
Jason Sams22534172009-08-04 16:58:20 -0700838nScriptSetClearDepth(JNIEnv *_env, jobject _this, jint script, jfloat d)
Jason Samsd19f10d2009-05-22 14:03:28 -0700839{
840 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams07ae4062009-08-27 20:23:34 -0700841 LOG_API("nScriptCSetClearDepth, con(%p), s(%p), depth(%f)", con, (void *)script, d);
Jason Samsbc948de2009-08-17 18:35:48 -0700842 rsScriptSetClearDepth(con, (RsScript)script, d);
Jason Samsd19f10d2009-05-22 14:03:28 -0700843}
844
845static void
Jason Sams22534172009-08-04 16:58:20 -0700846nScriptSetClearStencil(JNIEnv *_env, jobject _this, jint script, jint stencil)
Jason Samsd19f10d2009-05-22 14:03:28 -0700847{
848 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams07ae4062009-08-27 20:23:34 -0700849 LOG_API("nScriptCSetClearStencil, con(%p), s(%p), stencil(%i)", con, (void *)script, stencil);
Jason Samsbc948de2009-08-17 18:35:48 -0700850 rsScriptSetClearStencil(con, (RsScript)script, stencil);
Jason Samsd19f10d2009-05-22 14:03:28 -0700851}
852
853static void
Jason Sams22534172009-08-04 16:58:20 -0700854nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700855{
856 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams07ae4062009-08-27 20:23:34 -0700857 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700858
859 jint length = _env->GetArrayLength(timeZone);
860 jbyte* timeZone_ptr;
861 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
862
Jason Samsbc948de2009-08-17 18:35:48 -0700863 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700864
865 if (timeZone_ptr) {
866 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
867 }
868}
869
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700870static void
Jason Sams334ea0c2009-08-17 13:56:09 -0700871nScriptSetType(JNIEnv *_env, jobject _this, jint type, jboolean writable, jstring _str, jint slot)
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700872{
873 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams334ea0c2009-08-17 13:56:09 -0700874 LOG_API("nScriptCAddType, con(%p), type(%p), writable(%i), slot(%i)", con, (RsType)type, writable, slot);
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700875 const char* n = NULL;
876 if (_str) {
877 n = _env->GetStringUTFChars(_str, NULL);
878 }
Jason Samsbc948de2009-08-17 18:35:48 -0700879 rsScriptSetType(con, (RsType)type, slot, writable, n);
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700880 if (n) {
881 _env->ReleaseStringUTFChars(_str, n);
882 }
883}
884
885static void
Jason Samsbe2e8412009-09-16 15:04:38 -0700886nScriptSetInvoke(JNIEnv *_env, jobject _this, jstring _str, jint slot)
887{
888 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
889 LOG_API("nScriptSetInvoke, con(%p)", con);
890 const char* n = NULL;
891 if (_str) {
892 n = _env->GetStringUTFChars(_str, NULL);
893 }
894 rsScriptSetInvoke(con, n, slot);
895 if (n) {
896 _env->ReleaseStringUTFChars(_str, n);
897 }
898}
899
900static void
901nScriptInvoke(JNIEnv *_env, jobject _this, jint obj, jint slot)
902{
903 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
904 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
905 rsScriptInvoke(con, (RsScript)obj, slot);
906}
907
908static void
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700909nScriptSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot)
910{
911 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
912 LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot);
Jason Samsbc948de2009-08-17 18:35:48 -0700913 rsScriptSetRoot(con, isRoot);
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700914}
915
Jason Sams22534172009-08-04 16:58:20 -0700916// -----------------------------------
917
918static void
919nScriptCBegin(JNIEnv *_env, jobject _this)
920{
921 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
922 LOG_API("nScriptCBegin, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700923 rsScriptCBegin(con);
Jason Sams22534172009-08-04 16:58:20 -0700924}
925
Romain Guy584a3752009-07-30 18:45:01 -0700926static void
Jack Palevich43702d82009-05-28 13:38:16 -0700927nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef,
928 jint offset, jint length)
Jason Samsd19f10d2009-05-22 14:03:28 -0700929{
930 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
931 LOG_API("!!! nScriptCSetScript, con(%p)", con);
Jack Palevich43702d82009-05-28 13:38:16 -0700932 jint _exception = 0;
933 jint remaining;
934 jbyte* script_base = 0;
935 jbyte* script_ptr;
Jack Palevich43702d82009-05-28 13:38:16 -0700936 if (!scriptRef) {
937 _exception = 1;
938 //_env->ThrowNew(IAEClass, "script == null");
939 goto exit;
940 }
941 if (offset < 0) {
942 _exception = 1;
943 //_env->ThrowNew(IAEClass, "offset < 0");
944 goto exit;
945 }
946 if (length < 0) {
947 _exception = 1;
948 //_env->ThrowNew(IAEClass, "length < 0");
949 goto exit;
950 }
951 remaining = _env->GetArrayLength(scriptRef) - offset;
952 if (remaining < length) {
953 _exception = 1;
954 //_env->ThrowNew(IAEClass, "length > script.length - offset");
955 goto exit;
956 }
957 script_base = (jbyte *)
958 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
959 script_ptr = script_base + offset;
960
Jason Samsbc948de2009-08-17 18:35:48 -0700961 rsScriptCSetText(con, (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -0700962
Jack Palevich43702d82009-05-28 13:38:16 -0700963exit:
964 if (script_base) {
965 _env->ReleasePrimitiveArrayCritical(scriptRef, script_base,
966 _exception ? JNI_ABORT: 0);
967 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700968}
969
970static jint
971nScriptCCreate(JNIEnv *_env, jobject _this)
972{
973 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
974 LOG_API("nScriptCCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -0700975 return (jint)rsScriptCCreate(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700976}
977
Joe Onoratod7b37742009-08-09 22:57:44 -0700978static void
979nScriptCAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value)
980{
981 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
982 const char* n = _env->GetStringUTFChars(name, NULL);
983 LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value);
Jason Samsbc948de2009-08-17 18:35:48 -0700984 rsScriptCSetDefineI32(con, n, value);
Joe Onoratod7b37742009-08-09 22:57:44 -0700985 _env->ReleaseStringUTFChars(name, n);
986}
987
988static void
989nScriptCAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value)
990{
991 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
992 const char* n = _env->GetStringUTFChars(name, NULL);
993 LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value);
Jason Samsbc948de2009-08-17 18:35:48 -0700994 rsScriptCSetDefineF(con, n, value);
Joe Onoratod7b37742009-08-09 22:57:44 -0700995 _env->ReleaseStringUTFChars(name, n);
996}
997
Jason Samsd19f10d2009-05-22 14:03:28 -0700998// ---------------------------------------------------------------------------
999
1000static void
1001nProgramFragmentStoreBegin(JNIEnv *_env, jobject _this, jint in, jint out)
1002{
1003 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1004 LOG_API("nProgramFragmentStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
Jason Samsbc948de2009-08-17 18:35:48 -07001005 rsProgramFragmentStoreBegin(con, (RsElement)in, (RsElement)out);
Jason Samsd19f10d2009-05-22 14:03:28 -07001006}
1007
1008static void
1009nProgramFragmentStoreDepthFunc(JNIEnv *_env, jobject _this, jint func)
1010{
1011 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1012 LOG_API("nProgramFragmentStoreDepthFunc, con(%p), func(%i)", con, func);
Jason Samsbc948de2009-08-17 18:35:48 -07001013 rsProgramFragmentStoreDepthFunc(con, (RsDepthFunc)func);
Jason Samsd19f10d2009-05-22 14:03:28 -07001014}
1015
1016static void
1017nProgramFragmentStoreDepthMask(JNIEnv *_env, jobject _this, jboolean enable)
1018{
1019 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1020 LOG_API("nProgramFragmentStoreDepthMask, con(%p), enable(%i)", con, enable);
Jason Samsbc948de2009-08-17 18:35:48 -07001021 rsProgramFragmentStoreDepthMask(con, enable);
Jason Samsd19f10d2009-05-22 14:03:28 -07001022}
1023
1024static void
1025nProgramFragmentStoreColorMask(JNIEnv *_env, jobject _this, jboolean r, jboolean g, jboolean b, jboolean a)
1026{
1027 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1028 LOG_API("nProgramFragmentStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a);
Jason Samsbc948de2009-08-17 18:35:48 -07001029 rsProgramFragmentStoreColorMask(con, r, g, b, a);
Jason Samsd19f10d2009-05-22 14:03:28 -07001030}
1031
1032static void
1033nProgramFragmentStoreBlendFunc(JNIEnv *_env, jobject _this, int src, int dst)
1034{
1035 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1036 LOG_API("nProgramFragmentStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst);
Jason Samsbc948de2009-08-17 18:35:48 -07001037 rsProgramFragmentStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst);
Jason Samsd19f10d2009-05-22 14:03:28 -07001038}
1039
1040static void
1041nProgramFragmentStoreDither(JNIEnv *_env, jobject _this, jboolean enable)
1042{
1043 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1044 LOG_API("nProgramFragmentStoreDither, con(%p), enable(%i)", con, enable);
Jason Samsbc948de2009-08-17 18:35:48 -07001045 rsProgramFragmentStoreDither(con, enable);
Jason Samsd19f10d2009-05-22 14:03:28 -07001046}
1047
1048static jint
1049nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this)
1050{
1051 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1052 LOG_API("nProgramFragmentStoreCreate, con(%p)", con);
Jason Sams3eaa338e2009-06-10 15:04:38 -07001053
Jason Samsbc948de2009-08-17 18:35:48 -07001054 return (jint)rsProgramFragmentStoreCreate(con);
Jason Samsd19f10d2009-05-22 14:03:28 -07001055}
1056
1057// ---------------------------------------------------------------------------
1058
1059static void
Jason Sams25ffcdc2009-08-20 16:10:36 -07001060nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out, jboolean pointSpriteEnable)
Jason Samsd19f10d2009-05-22 14:03:28 -07001061{
1062 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams25ffcdc2009-08-20 16:10:36 -07001063 LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p) PointSprite(%i)", con, (RsElement)in, (RsElement)out, pointSpriteEnable);
1064 rsProgramFragmentBegin(con, (RsElement)in, (RsElement)out, pointSpriteEnable);
Jason Samsd19f10d2009-05-22 14:03:28 -07001065}
1066
1067static void
1068nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
1069{
1070 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1071 LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Samsbc948de2009-08-17 18:35:48 -07001072 rsProgramFragmentBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Samsd19f10d2009-05-22 14:03:28 -07001073}
1074
1075static void
1076nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
1077{
1078 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1079 LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Samsbc948de2009-08-17 18:35:48 -07001080 rsProgramFragmentBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Samsd19f10d2009-05-22 14:03:28 -07001081}
1082
1083static void
Jason Sams25ffcdc2009-08-20 16:10:36 -07001084nProgramFragmentSetSlot(JNIEnv *_env, jobject _this, jint slot, jboolean enable, jint env, jint vt)
Jason Samsd19f10d2009-05-22 14:03:28 -07001085{
1086 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams25ffcdc2009-08-20 16:10:36 -07001087 LOG_API("nProgramFragmentSetType, con(%p), slot(%i), enable(%i), env(%i), vt(%p)", con, slot, enable, env, (RsType)vt);
1088 rsProgramFragmentSetSlot(con, slot, enable, (RsTexEnvMode)env, (RsType)vt);
Jason Samsd19f10d2009-05-22 14:03:28 -07001089}
1090
1091static jint
1092nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
1093{
1094 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1095 LOG_API("nProgramFragmentCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -07001096 return (jint)rsProgramFragmentCreate(con);
Jason Samsd19f10d2009-05-22 14:03:28 -07001097}
1098
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001099// ---------------------------------------------------------------------------
1100
1101static void
1102nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out)
1103{
1104 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1105 LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
Jason Samsbc948de2009-08-17 18:35:48 -07001106 rsProgramVertexBegin(con, (RsElement)in, (RsElement)out);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001107}
1108
1109static void
Jason Sams9bee51c2009-08-05 13:57:03 -07001110nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint a)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001111{
1112 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Sams07ae4062009-08-27 20:23:34 -07001113 LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), a(%p)", con, (RsProgramVertex)vpv, (RsAllocation)a);
Jason Samsbc948de2009-08-17 18:35:48 -07001114 rsProgramVertexBindAllocation(con, (RsProgramFragment)vpv, (RsAllocation)a);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001115}
1116
1117static void
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001118nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
1119{
1120 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1121 LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable);
Jason Samsbc948de2009-08-17 18:35:48 -07001122 rsProgramVertexSetTextureMatrixEnable(con, enable);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001123}
1124
Jason Samsee411122009-07-21 12:20:54 -07001125static void
1126nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light)
1127{
1128 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1129 LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light);
Jason Samsbc948de2009-08-17 18:35:48 -07001130 rsProgramVertexAddLight(con, (RsLight)light);
Jason Samsee411122009-07-21 12:20:54 -07001131}
1132
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001133static jint
1134nProgramVertexCreate(JNIEnv *_env, jobject _this)
1135{
1136 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1137 LOG_API("nProgramVertexCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -07001138 return (jint)rsProgramVertexCreate(con);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001139}
1140
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001141
Jason Samsebfb4362009-09-23 13:57:02 -07001142// ---------------------------------------------------------------------------
1143
1144static jint
1145nProgramRasterCreate(JNIEnv *_env, jobject _this, jint in, jint out,
1146 jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite)
1147{
1148 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1149 LOG_API("nProgramRasterCreate, con(%p), in(%p), out(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
1150 con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite);
1151 return (jint)rsProgramRasterCreate(con, (RsElement)in, (RsElement)out, pointSmooth, lineSmooth, pointSprite);
1152}
1153
1154static void
1155nProgramRasterSetPointSize(JNIEnv *_env, jobject _this, jint vpr, jfloat v)
1156{
1157 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1158 LOG_API("nProgramRasterSetPointSize, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v);
1159 rsProgramRasterSetPointSize(con, (RsProgramFragment)vpr, v);
1160}
1161
1162static void
1163nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, jint vpr, jfloat v)
1164{
1165 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1166 LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v);
1167 rsProgramRasterSetLineWidth(con, (RsProgramFragment)vpr, v);
1168}
1169
Jason Samsd19f10d2009-05-22 14:03:28 -07001170
1171// ---------------------------------------------------------------------------
1172
1173static void
1174nContextBindRootScript(JNIEnv *_env, jobject _this, jint script)
1175{
1176 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1177 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001178 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001179}
1180
1181static void
Jason Samsd19f10d2009-05-22 14:03:28 -07001182nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs)
1183{
1184 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1185 LOG_API("nContextBindProgramFragmentStore, con(%p), pfs(%p)", con, (RsProgramFragmentStore)pfs);
Jason Samsbc948de2009-08-17 18:35:48 -07001186 rsContextBindProgramFragmentStore(con, (RsProgramFragmentStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001187}
1188
1189static void
1190nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf)
1191{
1192 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1193 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001194 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001195}
1196
Jason Sams0826a6f2009-06-15 19:04:56 -07001197static void
1198nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf)
1199{
1200 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1201 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001202 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001203}
1204
Joe Onoratod7b37742009-08-09 22:57:44 -07001205static void
Jason Samsebfb4362009-09-23 13:57:02 -07001206nContextBindProgramRaster(JNIEnv *_env, jobject _this, jint pf)
1207{
1208 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1209 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1210 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1211}
1212
1213static void
Joe Onoratod7b37742009-08-09 22:57:44 -07001214nContextAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value)
1215{
1216 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1217 const char* n = _env->GetStringUTFChars(name, NULL);
1218 LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value);
Jason Samsbc948de2009-08-17 18:35:48 -07001219 rsContextSetDefineI32(con, n, value);
Joe Onoratod7b37742009-08-09 22:57:44 -07001220 _env->ReleaseStringUTFChars(name, n);
1221}
1222
1223static void
1224nContextAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value)
1225{
1226 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1227 const char* n = _env->GetStringUTFChars(name, NULL);
1228 LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value);
Jason Samsbc948de2009-08-17 18:35:48 -07001229 rsContextSetDefineF(con, n, value);
Joe Onoratod7b37742009-08-09 22:57:44 -07001230 _env->ReleaseStringUTFChars(name, n);
1231}
1232
1233
Jason Sams02fb2cb2009-05-28 15:37:57 -07001234// ---------------------------------------------------------------------------
1235
1236static void
Jason Sams02fb2cb2009-05-28 15:37:57 -07001237nSamplerBegin(JNIEnv *_env, jobject _this)
1238{
1239 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1240 LOG_API("nSamplerBegin, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -07001241 rsSamplerBegin(con);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001242}
1243
1244static void
1245nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v)
1246{
1247 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1248 LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v);
Jason Samsbc948de2009-08-17 18:35:48 -07001249 rsSamplerSet(con, (RsSamplerParam)p, (RsSamplerValue)v);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001250}
1251
1252static jint
1253nSamplerCreate(JNIEnv *_env, jobject _this)
1254{
1255 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Samsbba134c2009-06-22 15:49:21 -07001256 LOG_API("nSamplerCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -07001257 return (jint)rsSamplerCreate(con);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001258}
1259
Jason Samsbba134c2009-06-22 15:49:21 -07001260// ---------------------------------------------------------------------------
1261
1262static void
1263nLightBegin(JNIEnv *_env, jobject _this)
1264{
1265 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1266 LOG_API("nLightBegin, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -07001267 rsLightBegin(con);
Jason Samsbba134c2009-06-22 15:49:21 -07001268}
1269
1270static void
1271nLightSetIsMono(JNIEnv *_env, jobject _this, jboolean isMono)
1272{
1273 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1274 LOG_API("nLightSetIsMono, con(%p), isMono(%i)", con, isMono);
Jason Samsbc948de2009-08-17 18:35:48 -07001275 rsLightSetMonochromatic(con, isMono);
Jason Samsbba134c2009-06-22 15:49:21 -07001276}
1277
1278static void
1279nLightSetIsLocal(JNIEnv *_env, jobject _this, jboolean isLocal)
1280{
1281 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1282 LOG_API("nLightSetIsLocal, con(%p), isLocal(%i)", con, isLocal);
Jason Samsbc948de2009-08-17 18:35:48 -07001283 rsLightSetLocal(con, isLocal);
Jason Samsbba134c2009-06-22 15:49:21 -07001284}
1285
1286static jint
1287nLightCreate(JNIEnv *_env, jobject _this)
1288{
1289 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1290 LOG_API("nLightCreate, con(%p)", con);
Jason Samsbc948de2009-08-17 18:35:48 -07001291 return (jint)rsLightCreate(con);
Jason Samsbba134c2009-06-22 15:49:21 -07001292}
1293
1294static void
Jason Samsbba134c2009-06-22 15:49:21 -07001295nLightSetColor(JNIEnv *_env, jobject _this, jint light, float r, float g, float b)
1296{
1297 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1298 LOG_API("nLightSetColor, con(%p), light(%p), r(%f), g(%f), b(%f)", con, (RsLight)light, r, g, b);
Jason Samsbc948de2009-08-17 18:35:48 -07001299 rsLightSetColor(con, (RsLight)light, r, g, b);
Jason Samsbba134c2009-06-22 15:49:21 -07001300}
1301
1302static void
1303nLightSetPosition(JNIEnv *_env, jobject _this, jint light, float x, float y, float z)
1304{
1305 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1306 LOG_API("nLightSetPosition, con(%p), light(%p), x(%f), y(%f), z(%f)", con, (RsLight)light, x, y, z);
Jason Samsbc948de2009-08-17 18:35:48 -07001307 rsLightSetPosition(con, (RsLight)light, x, y, z);
Jason Samsbba134c2009-06-22 15:49:21 -07001308}
Jason Samsd19f10d2009-05-22 14:03:28 -07001309
1310// ---------------------------------------------------------------------------
1311
Jason Sams1bada8c2009-08-09 17:01:55 -07001312static jint
1313nSimpleMeshCreate(JNIEnv *_env, jobject _this, jint batchID, jint indexID, jintArray vtxIDs, jint primID)
1314{
1315 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1316 jint len = _env->GetArrayLength(vtxIDs);
1317 LOG_API("nSimpleMeshCreate, con(%p), batchID(%i), indexID(%i), vtxIDs.len(%i), primID(%i)",
1318 con, batchID, indexID, len, primID);
1319 jint *ptr = _env->GetIntArrayElements(vtxIDs, NULL);
Jason Samsbc948de2009-08-17 18:35:48 -07001320 int id = (int)rsSimpleMeshCreate(con, (void *)batchID, (void *)indexID, (void **)ptr, len, primID);
Jason Sams1bada8c2009-08-09 17:01:55 -07001321 _env->ReleaseIntArrayElements(vtxIDs, ptr, 0/*JNI_ABORT*/);
1322 return id;
1323}
1324
1325static void
1326nSimpleMeshBindVertex(JNIEnv *_env, jobject _this, jint s, jint alloc, jint slot)
1327{
1328 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1329 LOG_API("nSimpleMeshBindVertex, con(%p), SimpleMesh(%p), Alloc(%p), slot(%i)", con, (RsSimpleMesh)s, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -07001330 rsSimpleMeshBindVertex(con, (RsSimpleMesh)s, (RsAllocation)alloc, slot);
Jason Sams1bada8c2009-08-09 17:01:55 -07001331}
1332
1333static void
1334nSimpleMeshBindIndex(JNIEnv *_env, jobject _this, jint s, jint alloc)
1335{
1336 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1337 LOG_API("nSimpleMeshBindIndex, con(%p), SimpleMesh(%p), Alloc(%p)", con, (RsSimpleMesh)s, (RsAllocation)alloc);
Jason Samsbc948de2009-08-17 18:35:48 -07001338 rsSimpleMeshBindIndex(con, (RsSimpleMesh)s, (RsAllocation)alloc);
Jason Sams1bada8c2009-08-09 17:01:55 -07001339}
1340
1341// ---------------------------------------------------------------------------
1342
Jason Samsd19f10d2009-05-22 14:03:28 -07001343
Jason Sams94d8e90a2009-06-10 16:09:05 -07001344static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001345
1346static JNINativeMethod methods[] = {
1347{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001348{"nInitElements", "(IIII)V", (void*)nInitElements },
1349
Jason Samsd19f10d2009-05-22 14:03:28 -07001350{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1351{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
Jason Samsebfb4362009-09-23 13:57:02 -07001352{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsb13ada52009-08-25 11:34:49 -07001353{"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001354{"nContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams3eaa338e2009-06-10 15:04:38 -07001355{"nAssignName", "(I[B)V", (void*)nAssignName },
Jason Sams7ce033d2009-08-18 14:14:24 -07001356{"nObjDestroy", "(I)V", (void*)nObjDestroy },
Jason Sams730ee652009-08-18 17:07:09 -07001357{"nObjDestroyOOB", "(I)V", (void*)nObjDestroyOOB },
Jason Samsd19f10d2009-05-22 14:03:28 -07001358
Jason Sams64676f32009-07-08 18:01:53 -07001359{"nFileOpen", "([B)I", (void*)nFileOpen },
1360
Jason Samsd19f10d2009-05-22 14:03:28 -07001361{"nElementBegin", "()V", (void*)nElementBegin },
Jason Sams768bc022009-09-21 19:41:04 -07001362{"nElementAdd", "(IIZILjava/lang/String;)V", (void*)nElementAdd },
Jason Samsd19f10d2009-05-22 14:03:28 -07001363{"nElementCreate", "()I", (void*)nElementCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001364
1365{"nTypeBegin", "(I)V", (void*)nTypeBegin },
1366{"nTypeAdd", "(II)V", (void*)nTypeAdd },
1367{"nTypeCreate", "()I", (void*)nTypeCreate },
Jason Sams43ee06852009-08-12 17:54:11 -07001368{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy },
1369{"nTypeSetupFields", "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields },
Jason Samsd19f10d2009-05-22 14:03:28 -07001370
1371{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
Jason Samsffe9f482009-06-01 17:45:53 -07001372{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
Jason Sams07ae4062009-08-27 20:23:34 -07001373{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
Romain Guy650a3eb2009-08-31 14:06:43 -07001374{"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream },
Jason Samsd19f10d2009-05-22 14:03:28 -07001375{"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture },
Jason Sams07ae4062009-08-27 20:23:34 -07001376{"nAllocationUploadToBufferObject","(I)V", (void*)nAllocationUploadToBufferObject },
Jason Sams07ae4062009-08-27 20:23:34 -07001377{"nAllocationSubData1D", "(III[II)V", (void*)nAllocationSubData1D_i },
Jason Sams768bc022009-09-21 19:41:04 -07001378{"nAllocationSubData1D", "(III[SI)V", (void*)nAllocationSubData1D_s },
1379{"nAllocationSubData1D", "(III[BI)V", (void*)nAllocationSubData1D_b },
Jason Sams07ae4062009-08-27 20:23:34 -07001380{"nAllocationSubData1D", "(III[FI)V", (void*)nAllocationSubData1D_f },
1381{"nAllocationSubData2D", "(IIIII[II)V", (void*)nAllocationSubData2D_i },
1382{"nAllocationSubData2D", "(IIIII[FI)V", (void*)nAllocationSubData2D_f },
Jason Sams40a29e82009-08-10 14:55:26 -07001383{"nAllocationRead", "(I[I)V", (void*)nAllocationRead_i },
1384{"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f },
Jason Sams2525a812009-09-03 15:43:13 -07001385{"nAllocationSubDataFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject },
Jason Sams5f43fd22009-09-15 12:39:22 -07001386{"nAllocationSubReadFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubReadFromObject },
Jason Samsd19f10d2009-05-22 14:03:28 -07001387
Jason Samsd19f10d2009-05-22 14:03:28 -07001388{"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin },
1389{"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY },
1390{"nTriangleMeshAddVertex_XYZ", "(FFF)V", (void*)nTriangleMeshAddVertex_XYZ },
1391{"nTriangleMeshAddVertex_XY_ST", "(FFFF)V", (void*)nTriangleMeshAddVertex_XY_ST },
1392{"nTriangleMeshAddVertex_XYZ_ST", "(FFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST },
Jason Sams0826a6f2009-06-15 19:04:56 -07001393{"nTriangleMeshAddVertex_XYZ_ST_NORM", "(FFFFFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST_NORM },
Jason Samsd19f10d2009-05-22 14:03:28 -07001394{"nTriangleMeshAddTriangle", "(III)V", (void*)nTriangleMeshAddTriangle },
1395{"nTriangleMeshCreate", "()I", (void*)nTriangleMeshCreate },
1396
Jason Samsd19f10d2009-05-22 14:03:28 -07001397{"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation },
1398{"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint },
1399{"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i },
Jason Samsd19f10d2009-05-22 14:03:28 -07001400{"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001401{"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i },
Jason Samsd19f10d2009-05-22 14:03:28 -07001402{"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f },
1403{"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate },
1404
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001405{"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
Jason Samsd19f10d2009-05-22 14:03:28 -07001413{"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation },
Jason Sams22534172009-08-04 16:58:20 -07001414{"nScriptSetClearColor", "(IFFFF)V", (void*)nScriptSetClearColor },
1415{"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth },
1416{"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil },
1417{"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone },
Jason Sams334ea0c2009-08-17 13:56:09 -07001418{"nScriptSetType", "(IZLjava/lang/String;I)V", (void*)nScriptSetType },
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001419{"nScriptSetRoot", "(Z)V", (void*)nScriptSetRoot },
Jason Samsbe2e8412009-09-16 15:04:38 -07001420{"nScriptSetInvokable", "(Ljava/lang/String;I)V", (void*)nScriptSetInvoke },
1421{"nScriptInvoke", "(II)V", (void*)nScriptInvoke },
Jason Sams22534172009-08-04 16:58:20 -07001422
Jason Samsd19f10d2009-05-22 14:03:28 -07001423{"nScriptCBegin", "()V", (void*)nScriptCBegin },
Jack Palevich43702d82009-05-28 13:38:16 -07001424{"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript },
Jason Samsd19f10d2009-05-22 14:03:28 -07001425{"nScriptCCreate", "()I", (void*)nScriptCCreate },
Joe Onoratod7b37742009-08-09 22:57:44 -07001426{"nScriptCAddDefineI32", "(Ljava/lang/String;I)V", (void*)nScriptCAddDefineI32 },
1427{"nScriptCAddDefineF", "(Ljava/lang/String;F)V", (void*)nScriptCAddDefineF },
Jason Samsd19f10d2009-05-22 14:03:28 -07001428
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
Jason Sams25ffcdc2009-08-20 16:10:36 -07001437{"nProgramFragmentBegin", "(IIZ)V", (void*)nProgramFragmentBegin },
Jason Samsd19f10d2009-05-22 14:03:28 -07001438{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture },
1439{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler },
Jason Sams25ffcdc2009-08-20 16:10:36 -07001440{"nProgramFragmentSetSlot", "(IZII)V", (void*)nProgramFragmentSetSlot },
Jason Samsd19f10d2009-05-22 14:03:28 -07001441{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate },
1442
Jason Samsebfb4362009-09-23 13:57:02 -07001443{"nProgramRasterCreate", "(IIZZZ)I", (void*)nProgramRasterCreate },
1444{"nProgramRasterSetPointSize", "(IF)V", (void*)nProgramRasterSetPointSize },
1445{"nProgramRasterSetLineWidth", "(IF)V", (void*)nProgramRasterSetLineWidth },
1446
Jason Sams9bee51c2009-08-05 13:57:03 -07001447{"nProgramVertexBindAllocation", "(II)V", (void*)nProgramVertexBindAllocation },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001448{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001449{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable },
Jason Samsee411122009-07-21 12:20:54 -07001450{"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001451{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate },
1452
Jason Samsbba134c2009-06-22 15:49:21 -07001453{"nLightBegin", "()V", (void*)nLightBegin },
1454{"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono },
1455{"nLightSetIsLocal", "(Z)V", (void*)nLightSetIsLocal },
1456{"nLightCreate", "()I", (void*)nLightCreate },
Jason Samsbba134c2009-06-22 15:49:21 -07001457{"nLightSetColor", "(IFFF)V", (void*)nLightSetColor },
1458{"nLightSetPosition", "(IFFF)V", (void*)nLightSetPosition },
1459
Jason Samsd19f10d2009-05-22 14:03:28 -07001460{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript },
Jason Samsd19f10d2009-05-22 14:03:28 -07001461{"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore },
1462{"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment },
Jason Sams0826a6f2009-06-15 19:04:56 -07001463{"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex },
Jason Samsebfb4362009-09-23 13:57:02 -07001464{"nContextBindProgramRaster", "(I)V", (void*)nContextBindProgramRaster },
Jason Samsd19f10d2009-05-22 14:03:28 -07001465
Jason Sams02fb2cb2009-05-28 15:37:57 -07001466{"nSamplerBegin", "()V", (void*)nSamplerBegin },
1467{"nSamplerSet", "(II)V", (void*)nSamplerSet },
1468{"nSamplerCreate", "()I", (void*)nSamplerCreate },
1469
Jason Sams1bada8c2009-08-09 17:01:55 -07001470{"nSimpleMeshCreate", "(II[II)I", (void*)nSimpleMeshCreate },
1471{"nSimpleMeshBindVertex", "(III)V", (void*)nSimpleMeshBindVertex },
1472{"nSimpleMeshBindIndex", "(II)V", (void*)nSimpleMeshBindIndex },
1473
Jason Samsd19f10d2009-05-22 14:03:28 -07001474};
1475
1476static int registerFuncs(JNIEnv *_env)
1477{
1478 return android::AndroidRuntime::registerNativeMethods(
1479 _env, classPathName, methods, NELEM(methods));
1480}
1481
1482// ---------------------------------------------------------------------------
1483
1484jint JNI_OnLoad(JavaVM* vm, void* reserved)
1485{
1486 JNIEnv* env = NULL;
1487 jint result = -1;
1488
Jason Samsd19f10d2009-05-22 14:03:28 -07001489 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1490 LOGE("ERROR: GetEnv failed\n");
1491 goto bail;
1492 }
1493 assert(env != NULL);
1494
1495 if (registerFuncs(env) < 0) {
1496 LOGE("ERROR: MediaPlayer native registration failed\n");
1497 goto bail;
1498 }
1499
1500 /* success -- return valid version number */
1501 result = JNI_VERSION_1_4;
1502
1503bail:
1504 return result;
1505}