blob: 445f4b5c74e6a04a9bd0254564fb015ddbb075da [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
Mathias Agopian000479f2010-02-09 17:46:37 -080026#include <surfaceflinger/Surface.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070027
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>
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080035#include <utils/AssetManager.h>
Romain Guy650a3eb2009-08-31 14:06:43 -070036#include <utils/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070037
Jason Samsd19f10d2009-05-22 14:03:28 -070038#include "jni.h"
39#include "JNIHelp.h"
40#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070041#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080042#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070043
Jason Samse29d4712009-07-23 15:19:03 -070044#include <RenderScript.h>
45#include <RenderScriptEnv.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070046
47//#define LOG_API LOGE
48#define LOG_API(...)
49
50using namespace android;
51
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080052class AutoJavaStringToUTF8 {
53public:
54 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str)
55 {
56 fCStr = env->GetStringUTFChars(str, NULL);
57 fLength = env->GetStringUTFLength(str);
58 }
59 ~AutoJavaStringToUTF8()
60 {
61 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
62 }
63 const char* c_str() const { return fCStr; }
64 jsize length() const { return fLength; }
65
66private:
67 JNIEnv* fEnv;
68 jstring fJStr;
69 const char* fCStr;
70 jsize fLength;
71};
72
Jason Samsd19f10d2009-05-22 14:03:28 -070073// ---------------------------------------------------------------------------
74
Jason Samsffe9f482009-06-01 17:45:53 -070075static jfieldID gContextId = 0;
76static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -070077static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -070078
79static void _nInit(JNIEnv *_env, jclass _this)
80{
Jason Samsd19f10d2009-05-22 14:03:28 -070081 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -070082
83 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
84 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -070085}
86
Jason Samsd19f10d2009-05-22 14:03:28 -070087// ---------------------------------------------------------------------------
88
Jason Sams3eaa338e2009-06-10 15:04:38 -070089static void
Jason Sams2e1872f2010-08-17 16:25:41 -070090nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -070091{
Jason Sams96ed4cf2010-06-15 12:15:57 -070092 LOG_API("nContextFinish, con(%p)", con);
93 rsContextFinish(con);
94}
95
96static void
Jason Sams2e1872f2010-08-17 16:25:41 -070097nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -070098{
Jason Sams07ae4062009-08-27 20:23:34 -070099 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700100 jint len = _env->GetArrayLength(str);
101 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700102 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700103 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
104}
105
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700106static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700107nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700108{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700109 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700110 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700111 rsaGetName(con, (void *)obj, &name);
112 if(name == NULL || strlen(name) == 0) {
113 return NULL;
114 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700115 return _env->NewStringUTF(name);
116}
117
Jason Sams7ce033d2009-08-18 14:14:24 -0700118static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700119nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700120{
Jason Sams7ce033d2009-08-18 14:14:24 -0700121 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700122 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700123}
124
Jason Sams3eaa338e2009-06-10 15:04:38 -0700125// ---------------------------------------------------------------------------
126
Jason Samsd19f10d2009-05-22 14:03:28 -0700127static jint
128nDeviceCreate(JNIEnv *_env, jobject _this)
129{
130 LOG_API("nDeviceCreate");
131 return (jint)rsDeviceCreate();
132}
133
134static void
135nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
136{
137 LOG_API("nDeviceDestroy");
138 return rsDeviceDestroy((RsDevice)dev);
139}
140
Jason Samsebfb4362009-09-23 13:57:02 -0700141static void
142nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
143{
144 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
145 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
146}
147
Jason Samsd19f10d2009-05-22 14:03:28 -0700148static jint
Jason Sams704ff642010-02-09 16:05:07 -0800149nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver)
Jason Samsd19f10d2009-05-22 14:03:28 -0700150{
151 LOG_API("nContextCreate");
Jason Sams704ff642010-02-09 16:05:07 -0800152 return (jint)rsContextCreate((RsDevice)dev, ver);
153}
154
155static jint
Jason Sams11c8af92010-10-13 15:31:10 -0700156nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver,
157 int colorMin, int colorPref,
158 int alphaMin, int alphaPref,
159 int depthMin, int depthPref,
160 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700161 int samplesMin, int samplesPref, float samplesQ,
162 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800163{
Jason Sams11c8af92010-10-13 15:31:10 -0700164 RsSurfaceConfig sc;
165 sc.alphaMin = alphaMin;
166 sc.alphaPref = alphaPref;
167 sc.colorMin = colorMin;
168 sc.colorPref = colorPref;
169 sc.depthMin = depthMin;
170 sc.depthPref = depthPref;
171 sc.samplesMin = samplesMin;
172 sc.samplesPref = samplesPref;
173 sc.samplesQ = samplesQ;
174
Jason Sams704ff642010-02-09 16:05:07 -0800175 LOG_API("nContextCreateGL");
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700176 return (jint)rsContextCreateGL((RsDevice)dev, ver, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700177}
178
179static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700180nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800181{
Jason Sams7d787b42009-11-15 12:14:26 -0800182 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
183 rsContextSetPriority(con, p);
184}
185
186
187
188static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700189nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800190{
Jason Sams3bc47d42009-11-12 15:10:25 -0800191 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800192
193 Surface * window = NULL;
194 if (wnd == NULL) {
195
196 } else {
Jim Milleree956052010-08-19 18:56:00 -0700197 window = (Surface*) android_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800198 }
199
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700200 rsContextSetSurface(con, width, height, window, 1);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800201}
202
203static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700204nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700205{
Jason Sams2e1872f2010-08-17 16:25:41 -0700206 LOG_API("nContextDestroy, con(%p)", con);
207 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700208}
209
Jason Sams715333b2009-11-17 17:26:46 -0800210static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700211nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800212{
Jason Sams715333b2009-11-17 17:26:46 -0800213 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
214 rsContextDump((RsContext)con, bits);
215}
Jason Samsd19f10d2009-05-22 14:03:28 -0700216
217static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700218nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700219{
Jason Sams65e7aa52009-09-24 17:38:20 -0700220 LOG_API("nContextPause, con(%p)", con);
221 rsContextPause(con);
222}
223
224static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700225nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700226{
Jason Sams65e7aa52009-09-24 17:38:20 -0700227 LOG_API("nContextResume, con(%p)", con);
228 rsContextResume(con);
229}
230
Jason Sams1c415172010-11-08 17:06:46 -0800231
232static jstring
233nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
234{
235 LOG_API("nContextGetErrorMessage, con(%p)", con);
236 char buf[1024];
237
238 size_t receiveLen;
239 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700240 int id = rsContextGetMessage(con,
241 buf, sizeof(buf),
242 &receiveLen, sizeof(receiveLen),
243 &subID, sizeof(subID),
244 true);
Jason Sams1c415172010-11-08 17:06:46 -0800245 if (!id && receiveLen) {
246 LOGV("message receive buffer too small. %i", receiveLen);
247 }
248 return _env->NewStringUTF(buf);
249}
250
251static void
252nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700253{
Jason Sams516c3192009-10-06 13:58:47 -0700254 jint len = _env->GetArrayLength(data);
255 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
256 jint *ptr = _env->GetIntArrayElements(data, NULL);
257 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800258 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700259 int id = rsContextGetMessage(con,
260 ptr, len * 4,
261 &receiveLen, sizeof(receiveLen),
262 &subID, sizeof(subID),
263 true);
Jason Sams516c3192009-10-06 13:58:47 -0700264 if (!id && receiveLen) {
Jason Sams1d45c472010-08-25 14:31:48 -0700265 LOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700266 }
267 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams1c415172010-11-08 17:06:46 -0800268}
269
270static jint
271nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData, jboolean wait)
272{
273 LOG_API("nContextPeekMessage, con(%p)", con);
274 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
275 size_t receiveLen;
276 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700277 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
278 &subID, sizeof(subID), wait);
Jason Sams1c415172010-11-08 17:06:46 -0800279 auxDataPtr[0] = (jint)subID;
280 auxDataPtr[1] = (jint)receiveLen;
281 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700282 return id;
283}
284
Jason Sams2e1872f2010-08-17 16:25:41 -0700285static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700286{
Jason Sams516c3192009-10-06 13:58:47 -0700287 LOG_API("nContextInitToClient, con(%p)", con);
288 rsContextInitToClient(con);
289}
290
Jason Sams2e1872f2010-08-17 16:25:41 -0700291static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700292{
Jason Sams516c3192009-10-06 13:58:47 -0700293 LOG_API("nContextDeinitToClient, con(%p)", con);
294 rsContextDeinitToClient(con);
295}
296
297
Jason Sams718cd1f2009-12-23 14:35:29 -0800298static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700299nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700300{
Jason Sams718cd1f2009-12-23 14:35:29 -0800301 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
302 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700303}
304
305static jint
Jason Sams70d4e502010-09-02 17:35:23 -0700306nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700307{
Jason Sams718cd1f2009-12-23 14:35:29 -0800308 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800309 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800310
311 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700312 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800313 const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
314 size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
315
316 for (int ct=0; ct < fieldCount; ct++) {
317 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
318 nameArray[ct] = _env->GetStringUTFChars(s, NULL);
319 sizeArray[ct] = _env->GetStringUTFLength(s);
320 }
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700321 jint id = (jint)rsElementCreate2(con,
322 (RsElement *)ids, fieldCount,
323 nameArray, fieldCount,
324 sizeArray, fieldCount,
325 (const uint32_t *)arraySizes, fieldCount);
Jason Sams718cd1f2009-12-23 14:35:29 -0800326 for (int ct=0; ct < fieldCount; ct++) {
327 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
328 _env->ReleaseStringUTFChars(s, nameArray[ct]);
329 }
330 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700331 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800332 free(nameArray);
333 free(sizeArray);
334 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700335}
336
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700337static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700338nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700339{
340 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700341 LOG_API("nElementGetNativeData, con(%p)", con);
342
343 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
344 assert(dataSize == 5);
345
346 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700347 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700348
349 for(jint i = 0; i < dataSize; i ++) {
350 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
351 }
352}
353
354
355static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700356nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _IDs, jobjectArray _names)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700357{
358 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700359 LOG_API("nElementGetSubElements, con(%p)", con);
360
361 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
362 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
363
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700364 rsaElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700365
Jason Sams11c8af92010-10-13 15:31:10 -0700366 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700367 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
368 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
369 }
370
371 free(ids);
372 free(names);
373}
374
Jason Samsd19f10d2009-05-22 14:03:28 -0700375// -----------------------------------
376
Jason Sams3b9c52a2010-10-14 17:48:46 -0700377static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800378nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
379 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
Jason Samsd19f10d2009-05-22 14:03:28 -0700380{
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800381 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
382 con, eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700383
Jason Samsc5765372011-04-28 18:26:48 -0700384 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700385 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700386}
387
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700388static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700389nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700390{
391 // We are packing 6 items: mDimX; mDimY; mDimZ;
392 // mDimLOD; mDimFaces; mElement; into typeData
393 int elementCount = _env->GetArrayLength(_typeData);
394
395 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700396 LOG_API("nTypeCreate, con(%p)", con);
397
398 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700399 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700400
401 for(jint i = 0; i < elementCount; i ++) {
402 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
403 }
404}
405
Jason Samsd19f10d2009-05-22 14:03:28 -0700406// -----------------------------------
407
408static jint
Jason Sams5476b452010-12-08 16:14:36 -0800409nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage)
Jason Samsd19f10d2009-05-22 14:03:28 -0700410{
Jason Samsd4b23b52010-12-13 15:32:35 -0800411 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage);
Jason Samsc5765372011-04-28 18:26:48 -0700412 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage);
Jason Samsd19f10d2009-05-22 14:03:28 -0700413}
414
Jason Samsd19f10d2009-05-22 14:03:28 -0700415static void
Jason Sams5476b452010-12-08 16:14:36 -0800416nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
417{
418 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
419 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
420}
421
Jason Samsf7086092011-01-12 13:28:37 -0800422static void
423nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
424{
425 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
426 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
427}
428
Jason Samsffe9f482009-06-01 17:45:53 -0700429static int
Jason Sams5476b452010-12-08 16:14:36 -0800430nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700431{
Jason Samsffe9f482009-06-01 17:45:53 -0700432 SkBitmap const * nativeBitmap =
433 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
434 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700435
Jason Sams5476b452010-12-08 16:14:36 -0800436 bitmap.lockPixels();
437 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700438 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700439 (RsType)type, (RsAllocationMipmapControl)mip,
440 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800441 bitmap.unlockPixels();
442 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700443}
Jason Samsfe08d992009-05-27 14:45:32 -0700444
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800445static int
Jason Sams5476b452010-12-08 16:14:36 -0800446nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800447{
448 SkBitmap const * nativeBitmap =
449 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
450 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800451
Jason Sams5476b452010-12-08 16:14:36 -0800452 bitmap.lockPixels();
453 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700454 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700455 (RsType)type, (RsAllocationMipmapControl)mip,
456 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800457 bitmap.unlockPixels();
458 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800459}
460
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700461static void
Jason Sams4ef66502010-12-10 16:03:15 -0800462nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700463{
464 SkBitmap const * nativeBitmap =
465 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
466 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800467 int w = bitmap.width();
468 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700469
Jason Sams4ef66502010-12-10 16:03:15 -0800470 bitmap.lockPixels();
471 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800472 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
473 0, RS_ALLOCATION_CUBMAP_FACE_POSITVE_X,
474 w, h, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800475 bitmap.unlockPixels();
476}
477
478static void
479nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
480{
481 SkBitmap const * nativeBitmap =
482 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
483 const SkBitmap& bitmap(*nativeBitmap);
484
485 bitmap.lockPixels();
486 void* ptr = bitmap.getPixels();
487 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
488 bitmap.unlockPixels();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700489}
490
Jason Sams8a647432010-03-01 15:31:04 -0800491static void ReleaseBitmapCallback(void *bmp)
492{
493 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
494 nativeBitmap->unlockPixels();
495}
496
Romain Guy650a3eb2009-08-31 14:06:43 -0700497
Jason Samsd19f10d2009-05-22 14:03:28 -0700498static void
Jason Sams49a05d72010-12-29 14:31:29 -0800499nAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700500{
Jason Samsd19f10d2009-05-22 14:03:28 -0700501 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800502 LOG_API("nAllocation1DData_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 -0700503 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800504 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700505 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
506}
507
508static void
Jason Sams49a05d72010-12-29 14:31:29 -0800509nAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes)
Jason Sams768bc022009-09-21 19:41:04 -0700510{
Jason Sams768bc022009-09-21 19:41:04 -0700511 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800512 LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700513 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800514 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700515 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
516}
517
518static void
Jason Sams49a05d72010-12-29 14:31:29 -0800519nAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes)
Jason Sams768bc022009-09-21 19:41:04 -0700520{
Jason Sams768bc022009-09-21 19:41:04 -0700521 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800522 LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700523 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800524 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700525 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
526}
527
528static void
Jason Sams49a05d72010-12-29 14:31:29 -0800529nAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700530{
Jason Samsd19f10d2009-05-22 14:03:28 -0700531 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800532 LOG_API("nAllocation1DData_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 -0700533 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800534 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700535 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
536}
537
538static void
Jason Sams49a05d72010-12-29 14:31:29 -0800539// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
540nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700541{
542 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800543 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
Jason Sams49bdaf02010-08-31 13:50:42 -0700544 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800545 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, compIdx, sizeBytes);
Jason Sams49bdaf02010-08-31 13:50:42 -0700546 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
547}
548
549static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800550nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
551 jint w, jint h, jshortArray data, int sizeBytes)
552{
553 jint len = _env->GetArrayLength(data);
554 LOG_API("nAllocation2DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
555 jshort *ptr = _env->GetShortArrayElements(data, NULL);
556 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
557 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
558}
559
560static void
561nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
562 jint w, jint h, jbyteArray data, int sizeBytes)
563{
564 jint len = _env->GetArrayLength(data);
565 LOG_API("nAllocation2DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
566 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
567 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
568 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
569}
570
571static void
Jason Sams49a05d72010-12-29 14:31:29 -0800572nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
573 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700574{
Jason Samsd19f10d2009-05-22 14:03:28 -0700575 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800576 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
Jason Samsd19f10d2009-05-22 14:03:28 -0700577 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800578 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700579 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
580}
581
582static void
Jason Sams49a05d72010-12-29 14:31:29 -0800583nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
584 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700585{
Jason Samsd19f10d2009-05-22 14:03:28 -0700586 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800587 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
Jason Samsd19f10d2009-05-22 14:03:28 -0700588 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800589 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700590 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
591}
592
Jason Sams40a29e82009-08-10 14:55:26 -0700593static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700594nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700595{
Jason Sams40a29e82009-08-10 14:55:26 -0700596 jint len = _env->GetArrayLength(data);
597 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
598 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700599 jsize length = _env->GetArrayLength(data);
600 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700601 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700602}
603
604static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800605nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
606{
607 jint len = _env->GetArrayLength(data);
608 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
609 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700610 jsize length = _env->GetArrayLength(data);
611 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800612 _env->ReleaseShortArrayElements(data, ptr, 0);
613}
614
615static void
616nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
617{
618 jint len = _env->GetArrayLength(data);
619 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
620 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700621 jsize length = _env->GetArrayLength(data);
622 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800623 _env->ReleaseByteArrayElements(data, ptr, 0);
624}
625
626static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700627nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700628{
Jason Sams40a29e82009-08-10 14:55:26 -0700629 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700630 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700631 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700632 jsize length = _env->GetArrayLength(data);
633 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700634 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700635}
Jason Samsd19f10d2009-05-22 14:03:28 -0700636
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700637static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700638nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700639{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700640 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700641 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700642}
643
Jason Sams5edc6082010-10-05 13:32:49 -0700644static void
645nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
646{
647 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
648 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
649}
650
651static void
652nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
653{
654 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
655 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
656}
657
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700658// -----------------------------------
659
660static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700661nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700662{
663 LOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700664
665 Asset* asset = reinterpret_cast<Asset*>(native_asset);
666
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800667 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
668 return id;
669}
670
671static int
672nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
673{
674 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
675 if (mgr == NULL) {
676 return 0;
677 }
678
679 AutoJavaStringToUTF8 str(_env, _path);
680 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
681 if (asset == NULL) {
682 return 0;
683 }
684
685 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
686 return id;
687}
688
689static int
690nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
691{
692 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
693 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
694
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700695 return id;
696}
697
698static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700699nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700700{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700701 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700702 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700703 return numEntries;
704}
705
706static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700707nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700708{
709 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700710 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
711
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700712 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700713
714 for(jint i = 0; i < numEntries; i ++) {
715 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
716 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
717 }
718
719 free(fileEntries);
720}
721
722static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700723nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700724{
725 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700726 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700727 return id;
728}
Jason Samsd19f10d2009-05-22 14:03:28 -0700729
730// -----------------------------------
731
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700732static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800733nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
734 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700735{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800736 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700737 jint id = (jint)rsFontCreateFromFile(con,
738 fileNameUTF.c_str(), fileNameUTF.length(),
739 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700740
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800741 return id;
742}
743
744static int
745nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
746 jstring name, jfloat fontSize, jint dpi, jint native_asset)
747{
748 Asset* asset = reinterpret_cast<Asset*>(native_asset);
749 AutoJavaStringToUTF8 nameUTF(_env, name);
750
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700751 jint id = (jint)rsFontCreateFromMemory(con,
752 nameUTF.c_str(), nameUTF.length(),
753 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800754 asset->getBuffer(false), asset->getLength());
755 return id;
756}
757
758static int
759nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
760 jfloat fontSize, jint dpi)
761{
762 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
763 if (mgr == NULL) {
764 return 0;
765 }
766
767 AutoJavaStringToUTF8 str(_env, _path);
768 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
769 if (asset == NULL) {
770 return 0;
771 }
772
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700773 jint id = (jint)rsFontCreateFromMemory(con,
774 str.c_str(), str.length(),
775 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800776 asset->getBuffer(false), asset->getLength());
777 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700778 return id;
779}
780
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700781// -----------------------------------
782
783static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700784nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700785{
Jason Samsd19f10d2009-05-22 14:03:28 -0700786 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700787 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700788}
789
790static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700791nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700792{
Jason Samscfc04362010-09-14 14:59:03 -0700793 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700794 rsScriptSetVarI(con, (RsScript)script, slot, val);
795}
796
797static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800798nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
799{
800 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
801 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
802}
803
804static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700805nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
806{
807 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
808 rsScriptSetVarJ(con, (RsScript)script, slot, val);
809}
810
811static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700812nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700813{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700814 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700815 rsScriptSetVarF(con, (RsScript)script, slot, val);
816}
817
818static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700819nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
820{
821 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
822 rsScriptSetVarD(con, (RsScript)script, slot, val);
823}
824
825static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700826nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700827{
Jason Sams4d339932010-05-11 14:03:58 -0700828 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
829 jint len = _env->GetArrayLength(data);
830 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
831 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
832 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
833}
834
Jason Samsd19f10d2009-05-22 14:03:28 -0700835
836static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700837nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700838{
Jason Sams07ae4062009-08-27 20:23:34 -0700839 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700840
841 jint length = _env->GetArrayLength(timeZone);
842 jbyte* timeZone_ptr;
843 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
844
Jason Samsbc948de2009-08-17 18:35:48 -0700845 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700846
847 if (timeZone_ptr) {
848 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
849 }
850}
851
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700852static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700853nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -0700854{
Jason Samsbe2e8412009-09-16 15:04:38 -0700855 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
856 rsScriptInvoke(con, (RsScript)obj, slot);
857}
858
859static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700860nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700861{
Jason Sams4d339932010-05-11 14:03:58 -0700862 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
863 jint len = _env->GetArrayLength(data);
864 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
865 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
866 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
867}
868
Jason Sams6e494d32011-04-27 16:33:11 -0700869static void
870nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
871 jint script, jint slot, jint ain, jint aout)
872{
873 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
874 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
875}
876static void
877nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
878 jint script, jint slot, jint ain, jint aout, jbyteArray params)
879{
880 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
881 jint len = _env->GetArrayLength(params);
882 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
883 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
884 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
885}
886
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700887
Jason Sams22534172009-08-04 16:58:20 -0700888// -----------------------------------
889
Jason Samse4a06c52011-03-16 16:29:28 -0700890static jint
891nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
892 jstring resName, jstring cacheDir,
893 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -0700894{
Jason Samse4a06c52011-03-16 16:29:28 -0700895 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -0700896
Jason Samse4a06c52011-03-16 16:29:28 -0700897 AutoJavaStringToUTF8 resNameUTF(_env, resName);
898 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
899 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -0700900 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -0700901 jint _exception = 0;
902 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -0700903 if (!scriptRef) {
904 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700905 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -0700906 goto exit;
907 }
Jack Palevich43702d82009-05-28 13:38:16 -0700908 if (length < 0) {
909 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700910 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -0700911 goto exit;
912 }
Jason Samse4a06c52011-03-16 16:29:28 -0700913 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -0700914 if (remaining < length) {
915 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700916 //jniThrowException(_env, "java/lang/IllegalArgumentException",
917 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -0700918 goto exit;
919 }
Jason Samse4a06c52011-03-16 16:29:28 -0700920 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -0700921 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -0700922
Jason Samse4a06c52011-03-16 16:29:28 -0700923 //rsScriptCSetText(con, (const char *)script_ptr, length);
924
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700925 ret = (jint)rsScriptCCreate(con,
926 resNameUTF.c_str(), resNameUTF.length(),
927 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -0700928 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -0700929
Jack Palevich43702d82009-05-28 13:38:16 -0700930exit:
Jason Samse4a06c52011-03-16 16:29:28 -0700931 if (script_ptr) {
932 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -0700933 _exception ? JNI_ABORT: 0);
934 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700935
Jason Samse4a06c52011-03-16 16:29:28 -0700936 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -0700937}
938
939// ---------------------------------------------------------------------------
940
Jason Samsd19f10d2009-05-22 14:03:28 -0700941static jint
Jason Sams331bf9b2011-04-06 11:23:54 -0700942nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
943 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
944 jboolean depthMask, jboolean ditherEnable,
945 jint srcFunc, jint destFunc,
946 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -0700947{
Jason Sams54db59c2010-05-13 18:30:11 -0700948 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -0700949 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
950 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
951 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -0700952}
953
Jason Sams0011bcf2009-12-15 12:58:36 -0800954// ---------------------------------------------------------------------------
955
956static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700957nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -0800958{
Jason Sams0011bcf2009-12-15 12:58:36 -0800959 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
960 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
961}
Jason Sams54c0ec12009-11-30 14:49:55 -0800962
Jason Sams68afd012009-12-17 16:55:08 -0800963static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700964nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -0800965{
Jason Sams68afd012009-12-17 16:55:08 -0800966 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
967 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
968}
969
970static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700971nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -0800972{
Jason Sams68afd012009-12-17 16:55:08 -0800973 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
974 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
975}
976
Jason Samsd19f10d2009-05-22 14:03:28 -0700977// ---------------------------------------------------------------------------
978
Jason Samsd19f10d2009-05-22 14:03:28 -0700979static jint
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -0700980nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -0800981{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800982 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -0800983 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
984 jint paramLen = _env->GetArrayLength(params);
985
Jason Sams991040c2011-01-17 15:59:39 -0800986 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -0800987
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800988 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -0800989 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
990 return ret;
991}
992
993
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700994// ---------------------------------------------------------------------------
995
Jason Sams0011bcf2009-12-15 12:58:36 -0800996static jint
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -0700997nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700998{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800999 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001000 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1001 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001002
Jason Sams991040c2011-01-17 15:59:39 -08001003 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001004
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001005 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001006 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1007 return ret;
1008}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001009
Jason Samsebfb4362009-09-23 13:57:02 -07001010// ---------------------------------------------------------------------------
1011
1012static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001013nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth,
1014 jboolean lineSmooth, jboolean pointSprite, jfloat lineWidth, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001015{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001016 LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
1017 con, pointSmooth, lineSmooth, pointSprite);
Jason Sams331bf9b2011-04-06 11:23:54 -07001018 return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite, lineWidth, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001019}
1020
Jason Samsd19f10d2009-05-22 14:03:28 -07001021
1022// ---------------------------------------------------------------------------
1023
1024static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001025nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001026{
Jason Samsd19f10d2009-05-22 14:03:28 -07001027 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001028 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001029}
1030
1031static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001032nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001033{
Jason Sams54db59c2010-05-13 18:30:11 -07001034 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1035 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001036}
1037
1038static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001039nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001040{
Jason Samsd19f10d2009-05-22 14:03:28 -07001041 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001042 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001043}
1044
Jason Sams0826a6f2009-06-15 19:04:56 -07001045static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001046nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001047{
Jason Sams0826a6f2009-06-15 19:04:56 -07001048 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001049 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001050}
1051
Joe Onoratod7b37742009-08-09 22:57:44 -07001052static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001053nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001054{
Jason Samsebfb4362009-09-23 13:57:02 -07001055 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1056 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1057}
1058
Joe Onoratod7b37742009-08-09 22:57:44 -07001059
Jason Sams02fb2cb2009-05-28 15:37:57 -07001060// ---------------------------------------------------------------------------
1061
Jason Sams02fb2cb2009-05-28 15:37:57 -07001062static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001063nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1064 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001065{
Jason Samsbba134c2009-06-22 15:49:21 -07001066 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001067 return (jint)rsSamplerCreate(con,
1068 (RsSamplerValue)magFilter,
1069 (RsSamplerValue)minFilter,
1070 (RsSamplerValue)wrapS,
1071 (RsSamplerValue)wrapT,
1072 (RsSamplerValue)wrapR,
1073 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001074}
1075
Jason Samsbba134c2009-06-22 15:49:21 -07001076// ---------------------------------------------------------------------------
1077
Jason Samsbba134c2009-06-22 15:49:21 -07001078static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001079nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jint vtxCount, jint idxCount)
Jason Samsbba134c2009-06-22 15:49:21 -07001080{
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001081 LOG_API("nMeshCreate, con(%p), vtxCount(%i), idxCount(%i)", con, vtxCount, idxCount);
1082 int id = (int)rsMeshCreate(con, vtxCount, idxCount);
1083 return id;
1084}
1085
1086static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001087nMeshBindVertex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint slot)
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001088{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001089 LOG_API("nMeshBindVertex, con(%p), Mesh(%p), Alloc(%p), slot(%i)", con, (RsMesh)mesh, (RsAllocation)alloc, slot);
1090 rsMeshBindVertex(con, (RsMesh)mesh, (RsAllocation)alloc, slot);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001091}
1092
1093static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001094nMeshBindIndex(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jint alloc, jint primID, jint slot)
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001095{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001096 LOG_API("nMeshBindIndex, con(%p), Mesh(%p), Alloc(%p)", con, (RsMesh)mesh, (RsAllocation)alloc);
1097 rsMeshBindIndex(con, (RsMesh)mesh, (RsAllocation)alloc, primID, slot);
1098}
1099
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -08001100static void
1101nMeshInitVertexAttribs(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
1102{
1103 LOG_API("nMeshInitVertexAttribs, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1104 rsMeshInitVertexAttribs(con, (RsMesh)mesh);
1105}
1106
1107
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001108static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001109nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001110{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001111 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1112 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001113 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001114 return vtxCount;
1115}
1116
1117static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001118nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001119{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001120 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1121 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001122 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001123 return idxCount;
1124}
1125
1126static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001127nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001128{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001129 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1130
1131 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001132 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001133
1134 for(jint i = 0; i < numVtxIDs; i ++) {
1135 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1136 }
1137
1138 free(allocs);
1139}
1140
1141static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001142nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001143{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001144 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1145
1146 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1147 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1148
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001149 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001150
1151 for(jint i = 0; i < numIndices; i ++) {
1152 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1153 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1154 }
1155
1156 free(allocs);
1157 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001158}
1159
1160// ---------------------------------------------------------------------------
1161
Jason Samsd19f10d2009-05-22 14:03:28 -07001162
Jason Sams94d8e90a2009-06-10 16:09:05 -07001163static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001164
1165static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001166{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001167
Jason Sams1c415172010-11-08 17:06:46 -08001168{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1169{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1170{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
1171{"nContextGetUserMessage", "(I[I)V", (void*)nContextGetUserMessage },
1172{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1173{"nContextPeekMessage", "(I[IZ)I", (void*)nContextPeekMessage },
1174
1175{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1176{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001177
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001178
Jason Sams2e1872f2010-08-17 16:25:41 -07001179// All methods below are thread protected in java.
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001180{"rsnContextCreate", "(II)I", (void*)nContextCreate },
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -07001181{"rsnContextCreateGL", "(IIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001182{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1183{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1184{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001185{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001186{"rsnContextDump", "(II)V", (void*)nContextDump },
1187{"rsnContextPause", "(I)V", (void*)nContextPause },
1188{"rsnContextResume", "(I)V", (void*)nContextResume },
1189{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001190{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001191{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001192
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001193{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001194{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001195{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001196{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001197{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001198{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001199
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001200{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001201{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1202{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001203
Jason Sams2e1872f2010-08-17 16:25:41 -07001204{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001205{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001206{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001207{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001208
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001209{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001210{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001211
Jason Samsd4b23b52010-12-13 15:32:35 -08001212{"rsnAllocationCreateTyped", "(IIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001213{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
1214{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001215
Jason Sams4ef66502010-12-10 16:03:15 -08001216{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1217{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1218
Jason Sams5476b452010-12-08 16:14:36 -08001219{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams49a05d72010-12-29 14:31:29 -08001220{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1221{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1222{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1223{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1224{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1225{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001226{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1227{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001228{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001229{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001230{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1231{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001232{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001233{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001234{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1235{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001236{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001237
Jason Sams2e1872f2010-08-17 16:25:41 -07001238{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1239{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1240{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1241{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001242{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1243{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001244{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001245{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001246{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001247{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001248{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001249{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001250
Jason Samse4a06c52011-03-16 16:29:28 -07001251{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams0011bcf2009-12-15 12:58:36 -08001252
Jason Sams331bf9b2011-04-06 11:23:54 -07001253{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001254
Jason Sams2e1872f2010-08-17 16:25:41 -07001255{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1256{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1257{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001258
Jason Sams49a05d72010-12-29 14:31:29 -08001259{"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams331bf9b2011-04-06 11:23:54 -07001260{"rsnProgramRasterCreate", "(IZZZFI)I", (void*)nProgramRasterCreate },
Jason Sams49a05d72010-12-29 14:31:29 -08001261{"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001262
Jason Sams2e1872f2010-08-17 16:25:41 -07001263{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001264{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001265{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1266{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1267{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001268
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001269{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001270
Jason Sams2e1872f2010-08-17 16:25:41 -07001271{"rsnMeshCreate", "(III)I", (void*)nMeshCreate },
1272{"rsnMeshBindVertex", "(IIII)V", (void*)nMeshBindVertex },
1273{"rsnMeshBindIndex", "(IIIII)V", (void*)nMeshBindIndex },
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -08001274{"rsnMeshInitVertexAttribs", "(II)V", (void*)nMeshInitVertexAttribs },
Jason Sams2e1872f2010-08-17 16:25:41 -07001275
1276{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1277{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001278{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001279{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001280
Jason Samsd19f10d2009-05-22 14:03:28 -07001281};
1282
1283static int registerFuncs(JNIEnv *_env)
1284{
1285 return android::AndroidRuntime::registerNativeMethods(
1286 _env, classPathName, methods, NELEM(methods));
1287}
1288
1289// ---------------------------------------------------------------------------
1290
1291jint JNI_OnLoad(JavaVM* vm, void* reserved)
1292{
1293 JNIEnv* env = NULL;
1294 jint result = -1;
1295
Jason Samsd19f10d2009-05-22 14:03:28 -07001296 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1297 LOGE("ERROR: GetEnv failed\n");
1298 goto bail;
1299 }
1300 assert(env != NULL);
1301
1302 if (registerFuncs(env) < 0) {
1303 LOGE("ERROR: MediaPlayer native registration failed\n");
1304 goto bail;
1305 }
1306
1307 /* success -- return valid version number */
1308 result = JNI_VERSION_1_4;
1309
1310bail:
1311 return result;
1312}