blob: f5227a0183eeabd695eaa8d94e334aa0621e0a30 [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 Samsd19f10d2009-05-22 14:03:28 -070053
54static void _nInit(JNIEnv *_env, jclass _this)
55{
Jason Samsd19f10d2009-05-22 14:03:28 -070056 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -070057
58 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
59 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -070060}
61
62
63// ---------------------------------------------------------------------------
64
Jason Sams3eaa338e2009-06-10 15:04:38 -070065static void
66nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str)
67{
68 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
69 LOG_API("nAssignName, con(%p), obj(%p)", con, obj);
70
71 jint len = _env->GetArrayLength(str);
72 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsd5680f92009-06-10 18:39:40 -070073 rsAssignName((void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -070074 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
75}
76
77
Jason Sams64676f32009-07-08 18:01:53 -070078static jint
79nFileOpen(JNIEnv *_env, jobject _this, jbyteArray str)
80{
81 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
82 LOG_API("nFileOpen, con(%p)", con);
83
84 jint len = _env->GetArrayLength(str);
85 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
86 jint ret = (jint)rsFileOpen((const char *)cptr, len);
87 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
88 return ret;
89}
90
Jason Sams3eaa338e2009-06-10 15:04:38 -070091// ---------------------------------------------------------------------------
92
Jason Samsd19f10d2009-05-22 14:03:28 -070093static jint
94nDeviceCreate(JNIEnv *_env, jobject _this)
95{
96 LOG_API("nDeviceCreate");
97 return (jint)rsDeviceCreate();
98}
99
100static void
101nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
102{
103 LOG_API("nDeviceDestroy");
104 return rsDeviceDestroy((RsDevice)dev);
105}
106
107static jint
108nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver)
109{
110 LOG_API("nContextCreate");
111
112 if (wnd == NULL) {
113 not_valid_surface:
114 doThrow(_env, "java/lang/IllegalArgumentException",
115 "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
116 return 0;
117 }
118 jclass surface_class = _env->FindClass("android/view/Surface");
119 jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I");
120 Surface * window = (Surface*)_env->GetIntField(wnd, surfaceFieldID);
121 if (window == NULL)
122 goto not_valid_surface;
123
Jason Samsd19f10d2009-05-22 14:03:28 -0700124 return (jint)rsContextCreate((RsDevice)dev, window, ver);
125}
126
127static void
128nContextDestroy(JNIEnv *_env, jobject _this, jint con)
129{
130 LOG_API("nContextDestroy, con(%p)", (RsContext)con);
131 return rsContextDestroy((RsContext)con);
132}
133
134
135static void
136nElementBegin(JNIEnv *_env, jobject _this)
137{
138 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
139 LOG_API("nElementBegin, con(%p)", con);
140 rsElementBegin();
141}
142
143static void
144nElementAddPredefined(JNIEnv *_env, jobject _this, jint predef)
145{
146 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
147 LOG_API("nElementAddPredefined, con(%p), predef(%i)", con, predef);
148 rsElementAddPredefined((RsElementPredefined)predef);
149}
150
151static void
152nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jint norm, jint bits)
153{
154 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
155 LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits);
156 rsElementAdd((RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits);
157}
158
159static jint
160nElementCreate(JNIEnv *_env, jobject _this)
161{
162 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
163 LOG_API("nElementCreate, con(%p)", con);
164 return (jint)rsElementCreate();
165}
166
167static jint
168nElementGetPredefined(JNIEnv *_env, jobject _this, jint predef)
169{
170 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
171 LOG_API("nElementGetPredefined, con(%p) predef(%i)", con, predef);
172 return (jint)rsElementGetPredefined((RsElementPredefined)predef);
173}
174
175static void
176nElementDestroy(JNIEnv *_env, jobject _this, jint e)
177{
178 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
179 LOG_API("nElementDestroy, con(%p) e(%p)", con, (RsElement)e);
180 rsElementDestroy((RsElement)e);
181}
182
183// -----------------------------------
184
185static void
186nTypeBegin(JNIEnv *_env, jobject _this, jint eID)
187{
188 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
189 LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID);
190 rsTypeBegin((RsElement)eID);
191}
192
193static void
194nTypeAdd(JNIEnv *_env, jobject _this, jint dim, jint val)
195{
196 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
197 LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val);
198 rsTypeAdd((RsDimension)dim, val);
199}
200
201static jint
202nTypeCreate(JNIEnv *_env, jobject _this)
203{
204 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
205 LOG_API("nTypeCreate, con(%p)", con);
206 return (jint)rsTypeCreate();
207}
208
209static void
210nTypeDestroy(JNIEnv *_env, jobject _this, jint eID)
211{
212 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
213 LOG_API("nTypeDestroy, con(%p), t(%p)", con, (RsType)eID);
214 rsTypeDestroy((RsType)eID);
215}
216
217// -----------------------------------
218
219static jint
220nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
221{
222 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
223 LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e);
224 return (jint) rsAllocationCreateTyped((RsElement)e);
225}
226
227static jint
228nAllocationCreatePredefSized(JNIEnv *_env, jobject _this, jint predef, jint count)
229{
230 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
231 LOG_API("nAllocationCreatePredefSized, con(%p), predef(%i), count(%i)", con, predef, count);
232 return (jint) rsAllocationCreatePredefSized((RsElementPredefined)predef, count);
233}
234
235static jint
236nAllocationCreateSized(JNIEnv *_env, jobject _this, jint e, jint count)
237{
238 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
239 LOG_API("nAllocationCreateSized, con(%p), e(%p), count(%i)", con, (RsElement)e, count);
240 return (jint) rsAllocationCreateSized((RsElement)e, count);
241}
242
243static void
244nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
245{
246 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
247 LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip);
248 rsAllocationUploadToTexture((RsAllocation)a, mip);
249}
250
Jason Samsffe9f482009-06-01 17:45:53 -0700251static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg)
Jason Samsfe08d992009-05-27 14:45:32 -0700252{
Jason Samsffe9f482009-06-01 17:45:53 -0700253 switch (cfg) {
254 case SkBitmap::kA8_Config:
255 return RS_ELEMENT_A_8;
256 case SkBitmap::kARGB_4444_Config:
257 return RS_ELEMENT_RGBA_4444;
258 case SkBitmap::kARGB_8888_Config:
259 return RS_ELEMENT_RGBA_8888;
260 case SkBitmap::kRGB_565_Config:
261 return RS_ELEMENT_RGB_565;
Jason Samsfe08d992009-05-27 14:45:32 -0700262
Jason Samsffe9f482009-06-01 17:45:53 -0700263 default:
264 break;
265 }
266 // If we don't have a conversion mark it as a user type.
267 LOGE("Unsupported bitmap type");
268 return RS_ELEMENT_USER_U8;
Jason Samsfe08d992009-05-27 14:45:32 -0700269}
270
Jason Samsffe9f482009-06-01 17:45:53 -0700271static int
272nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
273{
274 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
275 SkBitmap const * nativeBitmap =
276 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
277 const SkBitmap& bitmap(*nativeBitmap);
278 SkBitmap::Config config = bitmap.getConfig();
279
280 RsElementPredefined e = SkBitmapToPredefined(config);
281
282 if (e != RS_ELEMENT_USER_U8) {
283 bitmap.lockPixels();
284 const int w = bitmap.width();
285 const int h = bitmap.height();
286 const void* ptr = bitmap.getPixels();
287 jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
288 bitmap.unlockPixels();
289 return id;
290 }
291 return 0;
292}
Jason Samsfe08d992009-05-27 14:45:32 -0700293
Jason Samsb0ec1b42009-07-28 12:02:16 -0700294static int
295nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
296{
297 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
298 SkBitmap const * nativeBitmap =
299 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
300 const SkBitmap& bitmap(*nativeBitmap);
301 SkBitmap::Config config = bitmap.getConfig();
302
303 RsElementPredefined e = SkBitmapToPredefined(config);
304
305 if (e != RS_ELEMENT_USER_U8) {
306 bitmap.lockPixels();
307 const int w = bitmap.width();
308 const int h = bitmap.height();
309 const void* ptr = bitmap.getPixels();
310 jint id = (jint)rsAllocationCreateFromBitmapBoxed(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
311 bitmap.unlockPixels();
312 return id;
313 }
314 return 0;
315}
316
Jason Samsfe08d992009-05-27 14:45:32 -0700317
Jason Samsd19f10d2009-05-22 14:03:28 -0700318static void
319nAllocationDestroy(JNIEnv *_env, jobject _this, jint a)
320{
321 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
322 LOG_API("nAllocationDestroy, con(%p), a(%p)", con, (RsAllocation)a);
323 rsAllocationDestroy((RsAllocation)a);
324}
325
326static void
327nAllocationData_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data)
328{
329 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
330 jint len = _env->GetArrayLength(data);
331 LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
332 jint *ptr = _env->GetIntArrayElements(data, NULL);
333 rsAllocationData((RsAllocation)alloc, ptr);
334 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
335}
336
337static void
338nAllocationData_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data)
339{
340 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
341 jint len = _env->GetArrayLength(data);
342 LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
343 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
344 rsAllocationData((RsAllocation)alloc, ptr);
345 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
346}
347
348static void
349nAllocationSubData1D_i(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jintArray data)
350{
351 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
352 jint len = _env->GetArrayLength(data);
353 LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len);
354 jint *ptr = _env->GetIntArrayElements(data, NULL);
355 rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr);
356 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
357}
358
359static void
360nAllocationSubData1D_f(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jfloatArray data)
361{
362 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
363 jint len = _env->GetArrayLength(data);
364 LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len);
365 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
366 rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr);
367 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
368}
369
370static void
371nAllocationSubData2D_i(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data)
372{
373 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
374 jint len = _env->GetArrayLength(data);
375 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);
376 jint *ptr = _env->GetIntArrayElements(data, NULL);
377 rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr);
378 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
379}
380
381static void
382nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data)
383{
384 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
385 jint len = _env->GetArrayLength(data);
386 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);
387 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
388 rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr);
389 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
390}
391
392
393
394// -----------------------------------
395
396static void
397nTriangleMeshDestroy(JNIEnv *_env, jobject _this, jint tm)
398{
399 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
400 LOG_API("nTriangleMeshDestroy, con(%p), tm(%p)", con, (RsAllocation)tm);
401 rsTriangleMeshDestroy((RsTriangleMesh)tm);
402}
403
404static void
405nTriangleMeshBegin(JNIEnv *_env, jobject _this, jint v, jint i)
406{
407 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
408 LOG_API("nTriangleMeshBegin, con(%p), vertex(%p), index(%p)", con, (RsElement)v, (RsElement)i);
409 rsTriangleMeshBegin((RsElement)v, (RsElement)i);
410}
411
412static void
413nTriangleMeshAddVertex_XY(JNIEnv *_env, jobject _this, jfloat x, jfloat y)
414{
415 float v[] = {x, y};
416 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
417 LOG_API("nTriangleMeshAddVertex_XY, con(%p), x(%f), y(%f)", con, x, y);
418 rsTriangleMeshAddVertex(v);
419}
420
421static void
422nTriangleMeshAddVertex_XYZ(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z)
423{
424 float v[] = {x, y, z};
425 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
426 LOG_API("nTriangleMeshAddVertex_XYZ, con(%p), x(%f), y(%f), z(%f)", con, x, y, z);
427 rsTriangleMeshAddVertex(v);
428}
429
430static void
431nTriangleMeshAddVertex_XY_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat s, jfloat t)
432{
433 float v[] = {s, t, x, y};
434 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
435 LOG_API("nTriangleMeshAddVertex_XY_ST, con(%p), x(%f), y(%f), s(%f), t(%f)", con, x, y, s, t);
436 rsTriangleMeshAddVertex(v);
437}
438
439static void
440nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t)
441{
442 float v[] = {s, t, x, y, z};
443 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
444 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
445 rsTriangleMeshAddVertex(v);
446}
447
448static void
Jason Sams0826a6f2009-06-15 19:04:56 -0700449nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz)
450{
451 float v[] = {nx, ny, nz, s, t, x, y, z};
452 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
453 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
454 rsTriangleMeshAddVertex(v);
455}
456
457static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700458nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3)
459{
460 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
461 LOG_API("nTriangleMeshAddTriangle, con(%p), i1(%i), i2(%i), i3(%i)", con, i1, i2, i3);
462 rsTriangleMeshAddTriangle(i1, i2, i3);
463}
464
465static jint
466nTriangleMeshCreate(JNIEnv *_env, jobject _this)
467{
468 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
469 LOG_API("nTriangleMeshCreate, con(%p)", con);
470 return (jint) rsTriangleMeshCreate();
471}
472
473// -----------------------------------
474
475static void
476nAdapter1DDestroy(JNIEnv *_env, jobject _this, jint adapter)
477{
478 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
479 LOG_API("nAdapter1DDestroy, con(%p), adapter(%p)", con, (RsAdapter1D)adapter);
480 rsAdapter1DDestroy((RsAdapter1D)adapter);
481}
482
483static void
484nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc)
485{
486 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
487 LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc);
488 rsAdapter1DBindAllocation((RsAdapter1D)adapter, (RsAllocation)alloc);
489}
490
491static void
492nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value)
493{
494 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
495 LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value);
496 rsAdapter1DSetConstraint((RsAdapter1D)adapter, (RsDimension)dim, value);
497}
498
499static void
500nAdapter1DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data)
501{
502 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
503 jint len = _env->GetArrayLength(data);
504 LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len);
505 jint *ptr = _env->GetIntArrayElements(data, NULL);
506 rsAdapter1DData((RsAdapter1D)adapter, ptr);
507 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
508}
509
510static void
511nAdapter1DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jintArray data)
512{
513 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
514 jint len = _env->GetArrayLength(data);
515 LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len);
516 jint *ptr = _env->GetIntArrayElements(data, NULL);
517 rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr);
518 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
519}
520
521static void
522nAdapter1DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data)
523{
524 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
525 jint len = _env->GetArrayLength(data);
526 LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len);
527 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
528 rsAdapter1DData((RsAdapter1D)adapter, ptr);
529 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
530}
531
532static void
533nAdapter1DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jfloatArray data)
534{
535 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
536 jint len = _env->GetArrayLength(data);
537 LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len);
538 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
539 rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr);
540 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
541}
542
543static jint
544nAdapter1DCreate(JNIEnv *_env, jobject _this)
545{
546 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
547 LOG_API("nAdapter1DCreate, con(%p)", con);
548 return (jint)rsAdapter1DCreate();
549}
550
551// -----------------------------------
552
553static void
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700554nAdapter2DDestroy(JNIEnv *_env, jobject _this, jint adapter)
555{
556 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
557 LOG_API("nAdapter2DDestroy, con(%p), adapter(%p)", con, (RsAdapter2D)adapter);
558 rsAdapter2DDestroy((RsAdapter2D)adapter);
559}
560
561static void
562nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc)
563{
564 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
565 LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc);
566 rsAdapter2DBindAllocation((RsAdapter2D)adapter, (RsAllocation)alloc);
567}
568
569static void
570nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value)
571{
572 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
573 LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value);
574 rsAdapter2DSetConstraint((RsAdapter2D)adapter, (RsDimension)dim, value);
575}
576
577static void
578nAdapter2DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data)
579{
580 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
581 jint len = _env->GetArrayLength(data);
582 LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len);
583 jint *ptr = _env->GetIntArrayElements(data, NULL);
584 rsAdapter2DData((RsAdapter2D)adapter, ptr);
585 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
586}
587
588static void
589nAdapter2DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data)
590{
591 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
592 jint len = _env->GetArrayLength(data);
593 LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len);
594 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
595 rsAdapter2DData((RsAdapter2D)adapter, ptr);
596 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
597}
598
599static void
600nAdapter2DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data)
601{
602 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
603 jint len = _env->GetArrayLength(data);
604 LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)",
605 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len);
606 jint *ptr = _env->GetIntArrayElements(data, NULL);
607 rsAdapter2DSubData((RsAdapter2D)adapter, xoff, yoff, w, h, ptr);
608 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/);
609}
610
611static void
612nAdapter2DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data)
613{
614 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
615 jint len = _env->GetArrayLength(data);
616 LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)",
617 con, (RsAdapter2D)adapter, xoff, yoff, w, h, len);
618 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
619 rsAdapter2DSubData((RsAdapter1D)adapter, xoff, yoff, w, h, ptr);
620 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/);
621}
622
623static jint
624nAdapter2DCreate(JNIEnv *_env, jobject _this)
625{
626 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
627 LOG_API("nAdapter2DCreate, con(%p)", con);
628 return (jint)rsAdapter2DCreate();
629}
630
631// -----------------------------------
632
633static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700634nScriptDestroy(JNIEnv *_env, jobject _this, jint script)
635{
636 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
637 LOG_API("nScriptDestroy, con(%p), script(%p)", con, (RsScript)script);
638 rsScriptDestroy((RsScript)script);
639}
640
641static void
642nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint slot)
643{
644 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
645 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
646 rsScriptBindAllocation((RsScript)script, (RsAllocation)alloc, slot);
647}
648
649static void
650nScriptCBegin(JNIEnv *_env, jobject _this)
651{
652 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
653 LOG_API("nScriptCBegin, con(%p)", con);
654 rsScriptCBegin();
655}
656
657static void
658nScriptCSetClearColor(JNIEnv *_env, jobject _this, jfloat r, jfloat g, jfloat b, jfloat a)
659{
660 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
661 LOG_API("nScriptCSetClearColor, con(%p), r(%f), g(%f), b(%f), a(%f)", con, r, g, b, a);
662 rsScriptCSetClearColor(r, g, b, a);
663}
664
665static void
666nScriptCSetClearDepth(JNIEnv *_env, jobject _this, jfloat d)
667{
668 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Romain Guy584a3752009-07-30 18:45:01 -0700669 LOG_API("nScriptCSetClearDepth, con(%p), depth(%f)", con, d);
Jason Samsd19f10d2009-05-22 14:03:28 -0700670 rsScriptCSetClearDepth(d);
671}
672
673static void
674nScriptCSetClearStencil(JNIEnv *_env, jobject _this, jint stencil)
675{
676 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
677 LOG_API("nScriptCSetClearStencil, con(%p), stencil(%i)", con, stencil);
678 rsScriptCSetClearStencil(stencil);
679}
680
681static void
Romain Guy584a3752009-07-30 18:45:01 -0700682nScriptCSetTimeZone(JNIEnv *_env, jobject _this, jbyteArray timeZone)
683{
684 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
685 LOG_API("nScriptCSetTimeZone, con(%p), timeZone(%s)", con, timeZone);
686
687 jint length = _env->GetArrayLength(timeZone);
688 jbyte* timeZone_ptr;
689 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
690
691 rsScriptCSetTimeZone((const char *)timeZone_ptr, length);
692
693 if (timeZone_ptr) {
694 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
695 }
696}
697
698static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700699nScriptCAddType(JNIEnv *_env, jobject _this, jint type)
700{
701 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
702 LOG_API("nScriptCAddType, con(%p), type(%p)", con, (RsType)type);
703 rsScriptCAddType((RsType)type);
704}
705
706static void
707nScriptCSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot)
708{
709 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
710 LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot);
711 rsScriptCSetRoot(isRoot);
712}
713
714static void
Jack Palevich43702d82009-05-28 13:38:16 -0700715nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef,
716 jint offset, jint length)
Jason Samsd19f10d2009-05-22 14:03:28 -0700717{
718 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
719 LOG_API("!!! nScriptCSetScript, con(%p)", con);
Jack Palevich43702d82009-05-28 13:38:16 -0700720 jint _exception = 0;
721 jint remaining;
722 jbyte* script_base = 0;
723 jbyte* script_ptr;
Jack Palevich43702d82009-05-28 13:38:16 -0700724 if (!scriptRef) {
725 _exception = 1;
726 //_env->ThrowNew(IAEClass, "script == null");
727 goto exit;
728 }
729 if (offset < 0) {
730 _exception = 1;
731 //_env->ThrowNew(IAEClass, "offset < 0");
732 goto exit;
733 }
734 if (length < 0) {
735 _exception = 1;
736 //_env->ThrowNew(IAEClass, "length < 0");
737 goto exit;
738 }
739 remaining = _env->GetArrayLength(scriptRef) - offset;
740 if (remaining < length) {
741 _exception = 1;
742 //_env->ThrowNew(IAEClass, "length > script.length - offset");
743 goto exit;
744 }
745 script_base = (jbyte *)
746 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
747 script_ptr = script_base + offset;
748
Jason Sams39ddc9502009-06-05 17:35:09 -0700749 rsScriptCSetText((const char *)script_ptr, length);
750
Jack Palevich43702d82009-05-28 13:38:16 -0700751exit:
752 if (script_base) {
753 _env->ReleasePrimitiveArrayCritical(scriptRef, script_base,
754 _exception ? JNI_ABORT: 0);
755 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700756}
757
758static jint
759nScriptCCreate(JNIEnv *_env, jobject _this)
760{
761 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
762 LOG_API("nScriptCCreate, con(%p)", con);
763 return (jint)rsScriptCCreate();
764}
765
766// ---------------------------------------------------------------------------
767
768static void
769nProgramFragmentStoreBegin(JNIEnv *_env, jobject _this, jint in, jint out)
770{
771 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
772 LOG_API("nProgramFragmentStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
773 rsProgramFragmentStoreBegin((RsElement)in, (RsElement)out);
774}
775
776static void
777nProgramFragmentStoreDepthFunc(JNIEnv *_env, jobject _this, jint func)
778{
779 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
780 LOG_API("nProgramFragmentStoreDepthFunc, con(%p), func(%i)", con, func);
781 rsProgramFragmentStoreDepthFunc((RsDepthFunc)func);
782}
783
784static void
785nProgramFragmentStoreDepthMask(JNIEnv *_env, jobject _this, jboolean enable)
786{
787 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
788 LOG_API("nProgramFragmentStoreDepthMask, con(%p), enable(%i)", con, enable);
789 rsProgramFragmentStoreDepthMask(enable);
790}
791
792static void
793nProgramFragmentStoreColorMask(JNIEnv *_env, jobject _this, jboolean r, jboolean g, jboolean b, jboolean a)
794{
795 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
796 LOG_API("nProgramFragmentStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a);
797 rsProgramFragmentStoreColorMask(r, g, b, a);
798}
799
800static void
801nProgramFragmentStoreBlendFunc(JNIEnv *_env, jobject _this, int src, int dst)
802{
803 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
804 LOG_API("nProgramFragmentStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst);
805 rsProgramFragmentStoreBlendFunc((RsBlendSrcFunc)src, (RsBlendDstFunc)dst);
806}
807
808static void
809nProgramFragmentStoreDither(JNIEnv *_env, jobject _this, jboolean enable)
810{
811 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
812 LOG_API("nProgramFragmentStoreDither, con(%p), enable(%i)", con, enable);
813 rsProgramFragmentStoreDither(enable);
814}
815
816static jint
817nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this)
818{
819 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
820 LOG_API("nProgramFragmentStoreCreate, con(%p)", con);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700821
Jason Samsd19f10d2009-05-22 14:03:28 -0700822 return (jint)rsProgramFragmentStoreCreate();
823}
824
Jason Sams3eaa338e2009-06-10 15:04:38 -0700825static void
826nProgramFragmentStoreDestroy(JNIEnv *_env, jobject _this, jint pgm)
827{
828 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
829 LOG_API("nProgramFragmentStoreDestroy, con(%p), pgm(%i)", con, pgm);
830 rsProgramFragmentStoreDestroy((RsProgramFragmentStore)pgm);
831}
832
Jason Samsd19f10d2009-05-22 14:03:28 -0700833// ---------------------------------------------------------------------------
834
835static void
836nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out)
837{
838 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
839 LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
840 rsProgramFragmentBegin((RsElement)in, (RsElement)out);
841}
842
843static void
844nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
845{
846 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
847 LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
848 rsProgramFragmentBindTexture((RsProgramFragment)vpf, slot, (RsAllocation)a);
849}
850
851static void
852nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
853{
854 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
855 LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
856 rsProgramFragmentBindSampler((RsProgramFragment)vpf, slot, (RsSampler)a);
857}
858
859static void
860nProgramFragmentSetType(JNIEnv *_env, jobject _this, jint slot, jint vt)
861{
862 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
863 LOG_API("nProgramFragmentSetType, con(%p), slot(%i), vt(%p)", con, slot, (RsType)vt);
864 rsProgramFragmentSetType(slot, (RsType)vt);
865}
866
867static void
868nProgramFragmentSetEnvMode(JNIEnv *_env, jobject _this, jint slot, jint env)
869{
870 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
871 LOG_API("nProgramFragmentSetEnvMode, con(%p), slot(%i), vt(%i)", con, slot, env);
872 rsProgramFragmentSetEnvMode(slot, (RsTexEnvMode)env);
873}
874
875static void
876nProgramFragmentSetTexEnable(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
877{
878 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
879 LOG_API("nProgramFragmentSetTexEnable, con(%p), slot(%i), enable(%i)", con, slot, enable);
880 rsProgramFragmentSetTexEnable(slot, enable);
881}
882
883static jint
884nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
885{
886 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
887 LOG_API("nProgramFragmentCreate, con(%p)", con);
888 return (jint)rsProgramFragmentCreate();
889}
890
Jason Sams3eaa338e2009-06-10 15:04:38 -0700891static void
892nProgramFragmentDestroy(JNIEnv *_env, jobject _this, jint pgm)
893{
894 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
895 LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm);
896 rsProgramFragmentDestroy((RsProgramFragment)pgm);
897}
898
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700899// ---------------------------------------------------------------------------
900
901static void
902nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out)
903{
904 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
905 LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
906 rsProgramVertexBegin((RsElement)in, (RsElement)out);
907}
908
909static void
910nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint slot, jint a)
911{
912 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
913 LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
914 rsProgramVertexBindAllocation((RsProgramFragment)vpv, slot, (RsAllocation)a);
915}
916
917static void
918nProgramVertexSetType(JNIEnv *_env, jobject _this, jint slot, jint t)
919{
920 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
921 LOG_API("nProgramVertexSetType, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsType)t);
922 rsProgramVertexSetType(slot, (RsType)t);
923}
924
925static void
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700926nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
927{
928 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
929 LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable);
930 rsProgramVertexSetTextureMatrixEnable(enable);
931}
932
Jason Samsee411122009-07-21 12:20:54 -0700933static void
934nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light)
935{
936 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
937 LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light);
938 rsProgramVertexAddLight((RsLight)light);
939}
940
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700941static jint
942nProgramVertexCreate(JNIEnv *_env, jobject _this)
943{
944 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
945 LOG_API("nProgramVertexCreate, con(%p)", con);
946 return (jint)rsProgramVertexCreate();
947}
948
949static void
950nProgramVertexDestroy(JNIEnv *_env, jobject _this, jint pgm)
951{
952 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
953 LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm);
954 rsProgramFragmentDestroy((RsProgramFragment)pgm);
955}
956
957
958
Jason Samsd19f10d2009-05-22 14:03:28 -0700959
960// ---------------------------------------------------------------------------
961
962static void
963nContextBindRootScript(JNIEnv *_env, jobject _this, jint script)
964{
965 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
966 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
967 rsContextBindRootScript((RsScript)script);
968}
969
970static void
Jason Samsd19f10d2009-05-22 14:03:28 -0700971nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs)
972{
973 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
974 LOG_API("nContextBindProgramFragmentStore, con(%p), pfs(%p)", con, (RsProgramFragmentStore)pfs);
975 rsContextBindProgramFragmentStore((RsProgramFragmentStore)pfs);
976}
977
978static void
979nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf)
980{
981 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
982 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
983 rsContextBindProgramFragment((RsProgramFragment)pf);
984}
985
Jason Sams0826a6f2009-06-15 19:04:56 -0700986static void
987nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf)
988{
989 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
990 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
991 rsContextBindProgramVertex((RsProgramVertex)pf);
992}
993
Jason Sams02fb2cb2009-05-28 15:37:57 -0700994// ---------------------------------------------------------------------------
995
996static void
997nSamplerDestroy(JNIEnv *_env, jobject _this, jint s)
998{
999 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1000 LOG_API("nSamplerDestroy, con(%p), sampler(%p)", con, (RsSampler)s);
1001 rsSamplerDestroy((RsSampler)s);
1002}
1003
1004static void
1005nSamplerBegin(JNIEnv *_env, jobject _this)
1006{
1007 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1008 LOG_API("nSamplerBegin, con(%p)", con);
1009 rsSamplerBegin();
1010}
1011
1012static void
1013nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v)
1014{
1015 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1016 LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v);
1017 rsSamplerSet((RsSamplerParam)p, (RsSamplerValue)v);
1018}
1019
1020static jint
1021nSamplerCreate(JNIEnv *_env, jobject _this)
1022{
1023 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
Jason Samsbba134c2009-06-22 15:49:21 -07001024 LOG_API("nSamplerCreate, con(%p)", con);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001025 return (jint)rsSamplerCreate();
1026}
1027
Jason Samsbba134c2009-06-22 15:49:21 -07001028// ---------------------------------------------------------------------------
1029
1030static void
1031nLightBegin(JNIEnv *_env, jobject _this)
1032{
1033 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1034 LOG_API("nLightBegin, con(%p)", con);
1035 rsLightBegin();
1036}
1037
1038static void
1039nLightSetIsMono(JNIEnv *_env, jobject _this, jboolean isMono)
1040{
1041 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1042 LOG_API("nLightSetIsMono, con(%p), isMono(%i)", con, isMono);
1043 rsLightSetMonochromatic(isMono);
1044}
1045
1046static void
1047nLightSetIsLocal(JNIEnv *_env, jobject _this, jboolean isLocal)
1048{
1049 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1050 LOG_API("nLightSetIsLocal, con(%p), isLocal(%i)", con, isLocal);
1051 rsLightSetLocal(isLocal);
1052}
1053
1054static jint
1055nLightCreate(JNIEnv *_env, jobject _this)
1056{
1057 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1058 LOG_API("nLightCreate, con(%p)", con);
1059 return (jint)rsLightCreate();
1060}
1061
1062static void
1063nLightDestroy(JNIEnv *_env, jobject _this, jint light)
1064{
1065 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1066 LOG_API("nLightDestroy, con(%p), light(%p)", con, (RsLight)light);
1067 rsLightDestroy((RsLight)light);
1068}
1069
1070static void
1071nLightSetColor(JNIEnv *_env, jobject _this, jint light, float r, float g, float b)
1072{
1073 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1074 LOG_API("nLightSetColor, con(%p), light(%p), r(%f), g(%f), b(%f)", con, (RsLight)light, r, g, b);
1075 rsLightSetColor((RsLight)light, r, g, b);
1076}
1077
1078static void
1079nLightSetPosition(JNIEnv *_env, jobject _this, jint light, float x, float y, float z)
1080{
1081 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
1082 LOG_API("nLightSetPosition, con(%p), light(%p), x(%f), y(%f), z(%f)", con, (RsLight)light, x, y, z);
1083 rsLightSetPosition((RsLight)light, x, y, z);
1084}
Jason Samsd19f10d2009-05-22 14:03:28 -07001085
1086// ---------------------------------------------------------------------------
1087
1088
Jason Sams94d8e90a2009-06-10 16:09:05 -07001089static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001090
1091static JNINativeMethod methods[] = {
1092{"_nInit", "()V", (void*)_nInit },
1093{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1094{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1095{"nContextCreate", "(ILandroid/view/Surface;I)I", (void*)nContextCreate },
1096{"nContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams3eaa338e2009-06-10 15:04:38 -07001097{"nAssignName", "(I[B)V", (void*)nAssignName },
Jason Samsd19f10d2009-05-22 14:03:28 -07001098
Jason Sams64676f32009-07-08 18:01:53 -07001099{"nFileOpen", "([B)I", (void*)nFileOpen },
1100
Jason Samsd19f10d2009-05-22 14:03:28 -07001101{"nElementBegin", "()V", (void*)nElementBegin },
1102{"nElementAddPredefined", "(I)V", (void*)nElementAddPredefined },
1103{"nElementAdd", "(IIII)V", (void*)nElementAdd },
1104{"nElementCreate", "()I", (void*)nElementCreate },
1105{"nElementGetPredefined", "(I)I", (void*)nElementGetPredefined },
1106{"nElementDestroy", "(I)V", (void*)nElementDestroy },
1107
1108{"nTypeBegin", "(I)V", (void*)nTypeBegin },
1109{"nTypeAdd", "(II)V", (void*)nTypeAdd },
1110{"nTypeCreate", "()I", (void*)nTypeCreate },
1111{"nTypeDestroy", "(I)V", (void*)nTypeDestroy },
1112
1113{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
1114{"nAllocationCreatePredefSized", "(II)I", (void*)nAllocationCreatePredefSized },
1115{"nAllocationCreateSized", "(II)I", (void*)nAllocationCreateSized },
Jason Samsffe9f482009-06-01 17:45:53 -07001116{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
Jason Samsb0ec1b42009-07-28 12:02:16 -07001117{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
Jason Samsd19f10d2009-05-22 14:03:28 -07001118{"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture },
1119{"nAllocationDestroy", "(I)V", (void*)nAllocationDestroy },
1120{"nAllocationData", "(I[I)V", (void*)nAllocationData_i },
1121{"nAllocationData", "(I[F)V", (void*)nAllocationData_f },
1122{"nAllocationSubData1D", "(III[I)V", (void*)nAllocationSubData1D_i },
1123{"nAllocationSubData1D", "(III[F)V", (void*)nAllocationSubData1D_f },
1124{"nAllocationSubData2D", "(IIIII[I)V", (void*)nAllocationSubData2D_i },
1125{"nAllocationSubData2D", "(IIIII[F)V", (void*)nAllocationSubData2D_f },
1126
1127{"nTriangleMeshDestroy", "(I)V", (void*)nTriangleMeshDestroy },
1128{"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin },
1129{"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY },
1130{"nTriangleMeshAddVertex_XYZ", "(FFF)V", (void*)nTriangleMeshAddVertex_XYZ },
1131{"nTriangleMeshAddVertex_XY_ST", "(FFFF)V", (void*)nTriangleMeshAddVertex_XY_ST },
1132{"nTriangleMeshAddVertex_XYZ_ST", "(FFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST },
Jason Sams0826a6f2009-06-15 19:04:56 -07001133{"nTriangleMeshAddVertex_XYZ_ST_NORM", "(FFFFFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST_NORM },
Jason Samsd19f10d2009-05-22 14:03:28 -07001134{"nTriangleMeshAddTriangle", "(III)V", (void*)nTriangleMeshAddTriangle },
1135{"nTriangleMeshCreate", "()I", (void*)nTriangleMeshCreate },
1136
1137{"nAdapter1DDestroy", "(I)V", (void*)nAdapter1DDestroy },
1138{"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation },
1139{"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint },
1140{"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i },
Jason Samsd19f10d2009-05-22 14:03:28 -07001141{"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001142{"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i },
Jason Samsd19f10d2009-05-22 14:03:28 -07001143{"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f },
1144{"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate },
1145
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001146{"nAdapter2DDestroy", "(I)V", (void*)nAdapter2DDestroy },
1147{"nAdapter2DBindAllocation", "(II)V", (void*)nAdapter2DBindAllocation },
1148{"nAdapter2DSetConstraint", "(III)V", (void*)nAdapter2DSetConstraint },
1149{"nAdapter2DData", "(I[I)V", (void*)nAdapter2DData_i },
1150{"nAdapter2DData", "(I[F)V", (void*)nAdapter2DData_f },
1151{"nAdapter2DSubData", "(IIIII[I)V", (void*)nAdapter2DSubData_i },
1152{"nAdapter2DSubData", "(IIIII[F)V", (void*)nAdapter2DSubData_f },
1153{"nAdapter2DCreate", "()I", (void*)nAdapter2DCreate },
1154
Jason Samsd19f10d2009-05-22 14:03:28 -07001155{"nScriptDestroy", "(I)V", (void*)nScriptDestroy },
1156{"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation },
1157{"nScriptCBegin", "()V", (void*)nScriptCBegin },
1158{"nScriptCSetClearColor", "(FFFF)V", (void*)nScriptCSetClearColor },
1159{"nScriptCSetClearDepth", "(F)V", (void*)nScriptCSetClearDepth },
1160{"nScriptCSetClearStencil", "(I)V", (void*)nScriptCSetClearStencil },
Romain Guy584a3752009-07-30 18:45:01 -07001161{"nScriptCSetTimeZone", "([B)V", (void*)nScriptCSetTimeZone },
Jason Samsd19f10d2009-05-22 14:03:28 -07001162{"nScriptCAddType", "(I)V", (void*)nScriptCAddType },
1163{"nScriptCSetRoot", "(Z)V", (void*)nScriptCSetRoot },
Jack Palevich43702d82009-05-28 13:38:16 -07001164{"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript },
Jason Samsd19f10d2009-05-22 14:03:28 -07001165{"nScriptCCreate", "()I", (void*)nScriptCCreate },
1166
1167{"nProgramFragmentStoreBegin", "(II)V", (void*)nProgramFragmentStoreBegin },
1168{"nProgramFragmentStoreDepthFunc", "(I)V", (void*)nProgramFragmentStoreDepthFunc },
1169{"nProgramFragmentStoreDepthMask", "(Z)V", (void*)nProgramFragmentStoreDepthMask },
1170{"nProgramFragmentStoreColorMask", "(ZZZZ)V", (void*)nProgramFragmentStoreColorMask },
1171{"nProgramFragmentStoreBlendFunc", "(II)V", (void*)nProgramFragmentStoreBlendFunc },
1172{"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither },
1173{"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate },
Jason Sams3eaa338e2009-06-10 15:04:38 -07001174{"nProgramFragmentStoreDestroy", "(I)V", (void*)nProgramFragmentStoreDestroy },
Jason Samsd19f10d2009-05-22 14:03:28 -07001175
1176{"nProgramFragmentBegin", "(II)V", (void*)nProgramFragmentBegin },
1177{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture },
1178{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler },
1179{"nProgramFragmentSetType", "(II)V", (void*)nProgramFragmentSetType },
1180{"nProgramFragmentSetEnvMode", "(II)V", (void*)nProgramFragmentSetEnvMode },
1181{"nProgramFragmentSetTexEnable", "(IZ)V", (void*)nProgramFragmentSetTexEnable },
1182{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate },
Jason Sams3eaa338e2009-06-10 15:04:38 -07001183{"nProgramFragmentDestroy", "(I)V", (void*)nProgramFragmentDestroy },
Jason Samsd19f10d2009-05-22 14:03:28 -07001184
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001185{"nProgramVertexDestroy", "(I)V", (void*)nProgramVertexDestroy },
1186{"nProgramVertexBindAllocation", "(III)V", (void*)nProgramVertexBindAllocation },
1187{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin },
1188{"nProgramVertexSetType", "(II)V", (void*)nProgramVertexSetType },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001189{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable },
Jason Samsee411122009-07-21 12:20:54 -07001190{"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight },
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001191{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate },
1192
Jason Samsbba134c2009-06-22 15:49:21 -07001193{"nLightBegin", "()V", (void*)nLightBegin },
1194{"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono },
1195{"nLightSetIsLocal", "(Z)V", (void*)nLightSetIsLocal },
1196{"nLightCreate", "()I", (void*)nLightCreate },
1197{"nLightDestroy", "(I)V", (void*)nLightDestroy },
1198{"nLightSetColor", "(IFFF)V", (void*)nLightSetColor },
1199{"nLightSetPosition", "(IFFF)V", (void*)nLightSetPosition },
1200
Jason Samsd19f10d2009-05-22 14:03:28 -07001201{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript },
Jason Samsd19f10d2009-05-22 14:03:28 -07001202{"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore },
1203{"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment },
Jason Sams0826a6f2009-06-15 19:04:56 -07001204{"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001205
Jason Sams02fb2cb2009-05-28 15:37:57 -07001206{"nSamplerDestroy", "(I)V", (void*)nSamplerDestroy },
1207{"nSamplerBegin", "()V", (void*)nSamplerBegin },
1208{"nSamplerSet", "(II)V", (void*)nSamplerSet },
1209{"nSamplerCreate", "()I", (void*)nSamplerCreate },
1210
Jason Samsd19f10d2009-05-22 14:03:28 -07001211};
1212
1213static int registerFuncs(JNIEnv *_env)
1214{
1215 return android::AndroidRuntime::registerNativeMethods(
1216 _env, classPathName, methods, NELEM(methods));
1217}
1218
1219// ---------------------------------------------------------------------------
1220
1221jint JNI_OnLoad(JavaVM* vm, void* reserved)
1222{
1223 JNIEnv* env = NULL;
1224 jint result = -1;
1225
Jason Samsd19f10d2009-05-22 14:03:28 -07001226 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1227 LOGE("ERROR: GetEnv failed\n");
1228 goto bail;
1229 }
1230 assert(env != NULL);
1231
1232 if (registerFuncs(env) < 0) {
1233 LOGE("ERROR: MediaPlayer native registration failed\n");
1234 goto bail;
1235 }
1236
1237 /* success -- return valid version number */
1238 result = JNI_VERSION_1_4;
1239
1240bail:
1241 return result;
1242}