blob: 7e53cc4df237090f6bbc7d70675ac5b37f2bee41 [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
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700193 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800194 if (wnd == NULL) {
195
196 } else {
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700197 window = android_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800198 }
199
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700200 rsContextSetSurface(con, width, height, window);
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),
Jason Samsedbfabd2011-05-17 15:01:29 -0700243 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800244 if (!id && receiveLen) {
245 LOGV("message receive buffer too small. %i", receiveLen);
246 }
247 return _env->NewStringUTF(buf);
248}
249
Jason Samsedbfabd2011-05-17 15:01:29 -0700250static jint
Jason Sams1c415172010-11-08 17:06:46 -0800251nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700252{
Jason Sams516c3192009-10-06 13:58:47 -0700253 jint len = _env->GetArrayLength(data);
254 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
255 jint *ptr = _env->GetIntArrayElements(data, NULL);
256 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800257 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700258 int id = rsContextGetMessage(con,
259 ptr, len * 4,
260 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700261 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700262 if (!id && receiveLen) {
Jason Sams1d45c472010-08-25 14:31:48 -0700263 LOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700264 }
265 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700266 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800267}
268
269static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700270nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800271{
272 LOG_API("nContextPeekMessage, con(%p)", con);
273 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
274 size_t receiveLen;
275 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700276 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700277 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800278 auxDataPtr[0] = (jint)subID;
279 auxDataPtr[1] = (jint)receiveLen;
280 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700281 return id;
282}
283
Jason Sams2e1872f2010-08-17 16:25:41 -0700284static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700285{
Jason Sams516c3192009-10-06 13:58:47 -0700286 LOG_API("nContextInitToClient, con(%p)", con);
287 rsContextInitToClient(con);
288}
289
Jason Sams2e1872f2010-08-17 16:25:41 -0700290static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700291{
Jason Sams516c3192009-10-06 13:58:47 -0700292 LOG_API("nContextDeinitToClient, con(%p)", con);
293 rsContextDeinitToClient(con);
294}
295
296
Jason Sams718cd1f2009-12-23 14:35:29 -0800297static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700298nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700299{
Jason Sams718cd1f2009-12-23 14:35:29 -0800300 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
301 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700302}
303
304static jint
Jason Sams70d4e502010-09-02 17:35:23 -0700305nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700306{
Jason Sams718cd1f2009-12-23 14:35:29 -0800307 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800308 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800309
310 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700311 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800312 const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
313 size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
314
315 for (int ct=0; ct < fieldCount; ct++) {
316 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
317 nameArray[ct] = _env->GetStringUTFChars(s, NULL);
318 sizeArray[ct] = _env->GetStringUTFLength(s);
319 }
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700320 jint id = (jint)rsElementCreate2(con,
321 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700322 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700323 (const uint32_t *)arraySizes, fieldCount);
Jason Sams718cd1f2009-12-23 14:35:29 -0800324 for (int ct=0; ct < fieldCount; ct++) {
325 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
326 _env->ReleaseStringUTFChars(s, nameArray[ct]);
327 }
328 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700329 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800330 free(nameArray);
331 free(sizeArray);
332 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700333}
334
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700335static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700336nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700337{
338 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700339 LOG_API("nElementGetNativeData, con(%p)", con);
340
341 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
342 assert(dataSize == 5);
343
344 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700345 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700346
347 for(jint i = 0; i < dataSize; i ++) {
348 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
349 }
350}
351
352
353static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700354nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _IDs, jobjectArray _names)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700355{
356 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700357 LOG_API("nElementGetSubElements, con(%p)", con);
358
359 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
360 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
361
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700362 rsaElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700363
Jason Sams11c8af92010-10-13 15:31:10 -0700364 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700365 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
366 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
367 }
368
369 free(ids);
370 free(names);
371}
372
Jason Samsd19f10d2009-05-22 14:03:28 -0700373// -----------------------------------
374
Jason Sams3b9c52a2010-10-14 17:48:46 -0700375static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800376nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
377 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
Jason Samsd19f10d2009-05-22 14:03:28 -0700378{
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800379 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
380 con, eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700381
Jason Samsc5765372011-04-28 18:26:48 -0700382 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700383 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700384}
385
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700386static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700387nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700388{
389 // We are packing 6 items: mDimX; mDimY; mDimZ;
390 // mDimLOD; mDimFaces; mElement; into typeData
391 int elementCount = _env->GetArrayLength(_typeData);
392
393 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700394 LOG_API("nTypeCreate, con(%p)", con);
395
396 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700397 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700398
399 for(jint i = 0; i < elementCount; i ++) {
400 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
401 }
402}
403
Jason Samsd19f10d2009-05-22 14:03:28 -0700404// -----------------------------------
405
406static jint
Jason Sams5476b452010-12-08 16:14:36 -0800407nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage)
Jason Samsd19f10d2009-05-22 14:03:28 -0700408{
Jason Samsd4b23b52010-12-13 15:32:35 -0800409 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage);
Jason Samsc5765372011-04-28 18:26:48 -0700410 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage);
Jason Samsd19f10d2009-05-22 14:03:28 -0700411}
412
Jason Samsd19f10d2009-05-22 14:03:28 -0700413static void
Jason Sams5476b452010-12-08 16:14:36 -0800414nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
415{
416 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
417 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
418}
419
Jason Samsf7086092011-01-12 13:28:37 -0800420static void
421nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
422{
423 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
424 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
425}
426
Jason Samsffe9f482009-06-01 17:45:53 -0700427static int
Jason Sams5476b452010-12-08 16:14:36 -0800428nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700429{
Jason Samsffe9f482009-06-01 17:45:53 -0700430 SkBitmap const * nativeBitmap =
431 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
432 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700433
Jason Sams5476b452010-12-08 16:14:36 -0800434 bitmap.lockPixels();
435 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700436 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700437 (RsType)type, (RsAllocationMipmapControl)mip,
438 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800439 bitmap.unlockPixels();
440 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700441}
Jason Samsfe08d992009-05-27 14:45:32 -0700442
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800443static int
Jason Sams5476b452010-12-08 16:14:36 -0800444nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800445{
446 SkBitmap const * nativeBitmap =
447 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
448 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800449
Jason Sams5476b452010-12-08 16:14:36 -0800450 bitmap.lockPixels();
451 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700452 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700453 (RsType)type, (RsAllocationMipmapControl)mip,
454 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800455 bitmap.unlockPixels();
456 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800457}
458
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700459static void
Jason Sams4ef66502010-12-10 16:03:15 -0800460nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700461{
462 SkBitmap const * nativeBitmap =
463 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
464 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800465 int w = bitmap.width();
466 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700467
Jason Sams4ef66502010-12-10 16:03:15 -0800468 bitmap.lockPixels();
469 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800470 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700471 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Samsf7086092011-01-12 13:28:37 -0800472 w, h, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800473 bitmap.unlockPixels();
474}
475
476static void
477nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
478{
479 SkBitmap const * nativeBitmap =
480 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
481 const SkBitmap& bitmap(*nativeBitmap);
482
483 bitmap.lockPixels();
484 void* ptr = bitmap.getPixels();
485 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
486 bitmap.unlockPixels();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700487}
488
Jason Sams8a647432010-03-01 15:31:04 -0800489static void ReleaseBitmapCallback(void *bmp)
490{
491 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
492 nativeBitmap->unlockPixels();
493}
494
Romain Guy650a3eb2009-08-31 14:06:43 -0700495
Jason Samsd19f10d2009-05-22 14:03:28 -0700496static void
Jason Sams49a05d72010-12-29 14:31:29 -0800497nAllocationData1D_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 -0700498{
Jason Samsd19f10d2009-05-22 14:03:28 -0700499 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800500 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 -0700501 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800502 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700503 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
504}
505
506static void
Jason Sams49a05d72010-12-29 14:31:29 -0800507nAllocationData1D_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 -0700508{
Jason Sams768bc022009-09-21 19:41:04 -0700509 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800510 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 -0700511 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800512 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700513 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
514}
515
516static void
Jason Sams49a05d72010-12-29 14:31:29 -0800517nAllocationData1D_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 -0700518{
Jason Sams768bc022009-09-21 19:41:04 -0700519 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800520 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 -0700521 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800522 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700523 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
524}
525
526static void
Jason Sams49a05d72010-12-29 14:31:29 -0800527nAllocationData1D_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 -0700528{
Jason Samsd19f10d2009-05-22 14:03:28 -0700529 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800530 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 -0700531 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800532 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700533 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
534}
535
536static void
Jason Sams49a05d72010-12-29 14:31:29 -0800537// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
538nAllocationElementData1D(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 -0700539{
540 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800541 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 -0700542 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800543 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, compIdx, sizeBytes);
Jason Sams49bdaf02010-08-31 13:50:42 -0700544 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
545}
546
547static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800548nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
549 jint w, jint h, jshortArray data, int sizeBytes)
550{
551 jint len = _env->GetArrayLength(data);
552 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);
553 jshort *ptr = _env->GetShortArrayElements(data, NULL);
554 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
555 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
556}
557
558static void
559nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
560 jint w, jint h, jbyteArray data, int sizeBytes)
561{
562 jint len = _env->GetArrayLength(data);
563 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);
564 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
565 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
566 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
567}
568
569static void
Jason Sams49a05d72010-12-29 14:31:29 -0800570nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
571 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700572{
Jason Samsd19f10d2009-05-22 14:03:28 -0700573 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800574 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 -0700575 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800576 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700577 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
578}
579
580static void
Jason Sams49a05d72010-12-29 14:31:29 -0800581nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
582 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700583{
Jason Samsd19f10d2009-05-22 14:03:28 -0700584 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800585 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 -0700586 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800587 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700588 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
589}
590
Jason Sams40a29e82009-08-10 14:55:26 -0700591static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700592nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
593 jint dstAlloc, jint dstXoff, jint dstYoff,
594 jint dstMip, jint dstFace,
595 jint width, jint height,
596 jint srcAlloc, jint srcXoff, jint srcYoff,
597 jint srcMip, jint srcFace)
598{
599 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff, dstYoff,"
600 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
601 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
602 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
603 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
604
605 rsAllocationCopy2DRange(con,
606 (RsAllocation)dstAlloc,
607 dstXoff, dstYoff,
608 dstMip, dstFace,
609 width, height,
610 (RsAllocation)srcAlloc,
611 srcXoff, srcYoff,
612 srcMip, srcFace);
613}
614
615static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700616nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700617{
Jason Sams40a29e82009-08-10 14:55:26 -0700618 jint len = _env->GetArrayLength(data);
619 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
620 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700621 jsize length = _env->GetArrayLength(data);
622 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700623 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700624}
625
626static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800627nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
628{
629 jint len = _env->GetArrayLength(data);
630 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
631 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700632 jsize length = _env->GetArrayLength(data);
633 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800634 _env->ReleaseShortArrayElements(data, ptr, 0);
635}
636
637static void
638nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
639{
640 jint len = _env->GetArrayLength(data);
641 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
642 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700643 jsize length = _env->GetArrayLength(data);
644 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800645 _env->ReleaseByteArrayElements(data, ptr, 0);
646}
647
648static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700649nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700650{
Jason Sams40a29e82009-08-10 14:55:26 -0700651 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700652 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700653 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700654 jsize length = _env->GetArrayLength(data);
655 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700656 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700657}
Jason Samsd19f10d2009-05-22 14:03:28 -0700658
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700659static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700660nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700661{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700662 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700663 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700664}
665
Jason Sams5edc6082010-10-05 13:32:49 -0700666static void
667nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
668{
669 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
670 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
671}
672
673static void
674nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
675{
676 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
677 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
678}
679
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700680// -----------------------------------
681
682static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700683nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700684{
685 LOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700686
687 Asset* asset = reinterpret_cast<Asset*>(native_asset);
688
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800689 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
690 return id;
691}
692
693static int
694nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
695{
696 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
697 if (mgr == NULL) {
698 return 0;
699 }
700
701 AutoJavaStringToUTF8 str(_env, _path);
702 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
703 if (asset == NULL) {
704 return 0;
705 }
706
707 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
708 return id;
709}
710
711static int
712nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
713{
714 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
715 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
716
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700717 return id;
718}
719
720static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700721nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700722{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700723 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700724 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700725 return numEntries;
726}
727
728static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700729nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700730{
731 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700732 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
733
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700734 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700735
736 for(jint i = 0; i < numEntries; i ++) {
737 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
738 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
739 }
740
741 free(fileEntries);
742}
743
744static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700745nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700746{
747 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700748 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700749 return id;
750}
Jason Samsd19f10d2009-05-22 14:03:28 -0700751
752// -----------------------------------
753
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700754static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800755nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
756 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700757{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800758 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700759 jint id = (jint)rsFontCreateFromFile(con,
760 fileNameUTF.c_str(), fileNameUTF.length(),
761 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700762
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800763 return id;
764}
765
766static int
767nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
768 jstring name, jfloat fontSize, jint dpi, jint native_asset)
769{
770 Asset* asset = reinterpret_cast<Asset*>(native_asset);
771 AutoJavaStringToUTF8 nameUTF(_env, name);
772
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700773 jint id = (jint)rsFontCreateFromMemory(con,
774 nameUTF.c_str(), nameUTF.length(),
775 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800776 asset->getBuffer(false), asset->getLength());
777 return id;
778}
779
780static int
781nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
782 jfloat fontSize, jint dpi)
783{
784 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
785 if (mgr == NULL) {
786 return 0;
787 }
788
789 AutoJavaStringToUTF8 str(_env, _path);
790 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
791 if (asset == NULL) {
792 return 0;
793 }
794
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700795 jint id = (jint)rsFontCreateFromMemory(con,
796 str.c_str(), str.length(),
797 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800798 asset->getBuffer(false), asset->getLength());
799 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700800 return id;
801}
802
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700803// -----------------------------------
804
805static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700806nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700807{
Jason Samsd19f10d2009-05-22 14:03:28 -0700808 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700809 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700810}
811
812static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700813nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700814{
Jason Samscfc04362010-09-14 14:59:03 -0700815 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700816 rsScriptSetVarI(con, (RsScript)script, slot, val);
817}
818
819static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800820nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
821{
822 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
823 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
824}
825
826static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700827nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
828{
829 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
830 rsScriptSetVarJ(con, (RsScript)script, slot, val);
831}
832
833static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700834nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700835{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700836 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700837 rsScriptSetVarF(con, (RsScript)script, slot, val);
838}
839
840static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700841nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
842{
843 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
844 rsScriptSetVarD(con, (RsScript)script, slot, val);
845}
846
847static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700848nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700849{
Jason Sams4d339932010-05-11 14:03:58 -0700850 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
851 jint len = _env->GetArrayLength(data);
852 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
853 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
854 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
855}
856
Jason Samsd19f10d2009-05-22 14:03:28 -0700857
858static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700859nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700860{
Jason Sams07ae4062009-08-27 20:23:34 -0700861 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700862
863 jint length = _env->GetArrayLength(timeZone);
864 jbyte* timeZone_ptr;
865 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
866
Jason Samsbc948de2009-08-17 18:35:48 -0700867 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700868
869 if (timeZone_ptr) {
870 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
871 }
872}
873
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700874static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700875nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -0700876{
Jason Samsbe2e8412009-09-16 15:04:38 -0700877 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
878 rsScriptInvoke(con, (RsScript)obj, slot);
879}
880
881static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700882nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700883{
Jason Sams4d339932010-05-11 14:03:58 -0700884 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
885 jint len = _env->GetArrayLength(data);
886 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
887 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
888 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
889}
890
Jason Sams6e494d32011-04-27 16:33:11 -0700891static void
892nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
893 jint script, jint slot, jint ain, jint aout)
894{
895 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
896 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
897}
898static void
899nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
900 jint script, jint slot, jint ain, jint aout, jbyteArray params)
901{
902 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
903 jint len = _env->GetArrayLength(params);
904 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
905 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
906 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
907}
908
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700909
Jason Sams22534172009-08-04 16:58:20 -0700910// -----------------------------------
911
Jason Samse4a06c52011-03-16 16:29:28 -0700912static jint
913nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
914 jstring resName, jstring cacheDir,
915 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -0700916{
Jason Samse4a06c52011-03-16 16:29:28 -0700917 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -0700918
Jason Samse4a06c52011-03-16 16:29:28 -0700919 AutoJavaStringToUTF8 resNameUTF(_env, resName);
920 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
921 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -0700922 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -0700923 jint _exception = 0;
924 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -0700925 if (!scriptRef) {
926 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700927 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -0700928 goto exit;
929 }
Jack Palevich43702d82009-05-28 13:38:16 -0700930 if (length < 0) {
931 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700932 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -0700933 goto exit;
934 }
Jason Samse4a06c52011-03-16 16:29:28 -0700935 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -0700936 if (remaining < length) {
937 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700938 //jniThrowException(_env, "java/lang/IllegalArgumentException",
939 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -0700940 goto exit;
941 }
Jason Samse4a06c52011-03-16 16:29:28 -0700942 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -0700943 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -0700944
Jason Samse4a06c52011-03-16 16:29:28 -0700945 //rsScriptCSetText(con, (const char *)script_ptr, length);
946
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700947 ret = (jint)rsScriptCCreate(con,
948 resNameUTF.c_str(), resNameUTF.length(),
949 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -0700950 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -0700951
Jack Palevich43702d82009-05-28 13:38:16 -0700952exit:
Jason Samse4a06c52011-03-16 16:29:28 -0700953 if (script_ptr) {
954 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -0700955 _exception ? JNI_ABORT: 0);
956 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700957
Jason Samse4a06c52011-03-16 16:29:28 -0700958 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -0700959}
960
961// ---------------------------------------------------------------------------
962
Jason Samsd19f10d2009-05-22 14:03:28 -0700963static jint
Jason Sams331bf9b2011-04-06 11:23:54 -0700964nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
965 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
966 jboolean depthMask, jboolean ditherEnable,
967 jint srcFunc, jint destFunc,
968 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -0700969{
Jason Sams54db59c2010-05-13 18:30:11 -0700970 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -0700971 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
972 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
973 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -0700974}
975
Jason Sams0011bcf2009-12-15 12:58:36 -0800976// ---------------------------------------------------------------------------
977
978static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700979nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -0800980{
Jason Sams0011bcf2009-12-15 12:58:36 -0800981 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
982 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
983}
Jason Sams54c0ec12009-11-30 14:49:55 -0800984
Jason Sams68afd012009-12-17 16:55:08 -0800985static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700986nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -0800987{
Jason Sams68afd012009-12-17 16:55:08 -0800988 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
989 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
990}
991
992static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700993nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -0800994{
Jason Sams68afd012009-12-17 16:55:08 -0800995 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
996 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
997}
998
Jason Samsd19f10d2009-05-22 14:03:28 -0700999// ---------------------------------------------------------------------------
1000
Jason Samsd19f10d2009-05-22 14:03:28 -07001001static jint
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001002nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001003{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001004 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001005 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1006 jint paramLen = _env->GetArrayLength(params);
1007
Jason Sams991040c2011-01-17 15:59:39 -08001008 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001009
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001010 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001011 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1012 return ret;
1013}
1014
1015
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001016// ---------------------------------------------------------------------------
1017
Jason Sams0011bcf2009-12-15 12:58:36 -08001018static jint
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001019nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001020{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001021 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001022 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1023 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001024
Jason Sams991040c2011-01-17 15:59:39 -08001025 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001026
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001027 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001028 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1029 return ret;
1030}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001031
Jason Samsebfb4362009-09-23 13:57:02 -07001032// ---------------------------------------------------------------------------
1033
1034static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001035nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth,
1036 jboolean lineSmooth, jboolean pointSprite, jfloat lineWidth, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001037{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001038 LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
1039 con, pointSmooth, lineSmooth, pointSprite);
Jason Sams331bf9b2011-04-06 11:23:54 -07001040 return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite, lineWidth, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001041}
1042
Jason Samsd19f10d2009-05-22 14:03:28 -07001043
1044// ---------------------------------------------------------------------------
1045
1046static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001047nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001048{
Jason Samsd19f10d2009-05-22 14:03:28 -07001049 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001050 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001051}
1052
1053static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001054nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001055{
Jason Sams54db59c2010-05-13 18:30:11 -07001056 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1057 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001058}
1059
1060static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001061nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001062{
Jason Samsd19f10d2009-05-22 14:03:28 -07001063 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001064 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001065}
1066
Jason Sams0826a6f2009-06-15 19:04:56 -07001067static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001068nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001069{
Jason Sams0826a6f2009-06-15 19:04:56 -07001070 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001071 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001072}
1073
Joe Onoratod7b37742009-08-09 22:57:44 -07001074static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001075nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001076{
Jason Samsebfb4362009-09-23 13:57:02 -07001077 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1078 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1079}
1080
Joe Onoratod7b37742009-08-09 22:57:44 -07001081
Jason Sams02fb2cb2009-05-28 15:37:57 -07001082// ---------------------------------------------------------------------------
1083
Jason Sams02fb2cb2009-05-28 15:37:57 -07001084static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001085nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1086 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001087{
Jason Samsbba134c2009-06-22 15:49:21 -07001088 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001089 return (jint)rsSamplerCreate(con,
1090 (RsSamplerValue)magFilter,
1091 (RsSamplerValue)minFilter,
1092 (RsSamplerValue)wrapS,
1093 (RsSamplerValue)wrapT,
1094 (RsSamplerValue)wrapR,
1095 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001096}
1097
Jason Samsbba134c2009-06-22 15:49:21 -07001098// ---------------------------------------------------------------------------
1099
Jason Samsbba134c2009-06-22 15:49:21 -07001100static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001101nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001102{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001103 LOG_API("nMeshCreate, con(%p)", con);
1104
1105 jint vtxLen = _env->GetArrayLength(_vtx);
1106 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1107 jint idxLen = _env->GetArrayLength(_idx);
1108 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1109 jint primLen = _env->GetArrayLength(_prim);
1110 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1111
1112 int id = (int)rsMeshCreate(con,
1113 (RsAllocation *)vtxPtr, vtxLen,
1114 (RsAllocation *)idxPtr, idxLen,
1115 (uint32_t *)primPtr, primLen);
1116
1117 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1118 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1119 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001120 return id;
1121}
1122
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001123static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001124nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001125{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001126 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1127 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001128 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001129 return vtxCount;
1130}
1131
1132static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001133nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001134{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001135 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1136 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001137 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001138 return idxCount;
1139}
1140
1141static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001142nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
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)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001147 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001148
1149 for(jint i = 0; i < numVtxIDs; i ++) {
1150 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1151 }
1152
1153 free(allocs);
1154}
1155
1156static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001157nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001158{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001159 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1160
1161 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1162 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1163
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001164 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001165
1166 for(jint i = 0; i < numIndices; i ++) {
1167 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1168 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1169 }
1170
1171 free(allocs);
1172 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001173}
1174
1175// ---------------------------------------------------------------------------
1176
Jason Samsd19f10d2009-05-22 14:03:28 -07001177
Jason Sams94d8e90a2009-06-10 16:09:05 -07001178static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001179
1180static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001181{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001182
Jason Sams1c415172010-11-08 17:06:46 -08001183{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1184{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1185{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001186{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001187{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001188{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001189
1190{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1191{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001192
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001193
Jason Sams2e1872f2010-08-17 16:25:41 -07001194// All methods below are thread protected in java.
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001195{"rsnContextCreate", "(II)I", (void*)nContextCreate },
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -07001196{"rsnContextCreateGL", "(IIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001197{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1198{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1199{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001200{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001201{"rsnContextDump", "(II)V", (void*)nContextDump },
1202{"rsnContextPause", "(I)V", (void*)nContextPause },
1203{"rsnContextResume", "(I)V", (void*)nContextResume },
1204{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001205{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001206{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001207
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001208{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001209{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001210{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001211{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001212{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001213{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001214
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001215{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001216{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1217{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001218
Jason Sams2e1872f2010-08-17 16:25:41 -07001219{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001220{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001221{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001222{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001223
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001224{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001225{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001226
Jason Samsd4b23b52010-12-13 15:32:35 -08001227{"rsnAllocationCreateTyped", "(IIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001228{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
1229{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001230
Jason Sams4ef66502010-12-10 16:03:15 -08001231{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1232{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1233
Jason Sams5476b452010-12-08 16:14:36 -08001234{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams49a05d72010-12-29 14:31:29 -08001235{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1236{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1237{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1238{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1239{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1240{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001241{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1242{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001243{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001244{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001245{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001246{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1247{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001248{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001249{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001250{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1251{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001252{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001253
Jason Sams2e1872f2010-08-17 16:25:41 -07001254{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1255{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1256{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1257{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001258{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1259{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001260{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001261{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001262{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001263{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001264{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001265{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001266
Jason Samse4a06c52011-03-16 16:29:28 -07001267{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams0011bcf2009-12-15 12:58:36 -08001268
Jason Sams331bf9b2011-04-06 11:23:54 -07001269{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001270
Jason Sams2e1872f2010-08-17 16:25:41 -07001271{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1272{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1273{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001274
Jason Sams49a05d72010-12-29 14:31:29 -08001275{"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams331bf9b2011-04-06 11:23:54 -07001276{"rsnProgramRasterCreate", "(IZZZFI)I", (void*)nProgramRasterCreate },
Jason Sams49a05d72010-12-29 14:31:29 -08001277{"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001278
Jason Sams2e1872f2010-08-17 16:25:41 -07001279{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001280{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001281{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1282{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1283{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001284
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001285{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001286
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001287{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001288
1289{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1290{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001291{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001292{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001293
Jason Samsd19f10d2009-05-22 14:03:28 -07001294};
1295
1296static int registerFuncs(JNIEnv *_env)
1297{
1298 return android::AndroidRuntime::registerNativeMethods(
1299 _env, classPathName, methods, NELEM(methods));
1300}
1301
1302// ---------------------------------------------------------------------------
1303
1304jint JNI_OnLoad(JavaVM* vm, void* reserved)
1305{
1306 JNIEnv* env = NULL;
1307 jint result = -1;
1308
Jason Samsd19f10d2009-05-22 14:03:28 -07001309 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1310 LOGE("ERROR: GetEnv failed\n");
1311 goto bail;
1312 }
1313 assert(env != NULL);
1314
1315 if (registerFuncs(env) < 0) {
1316 LOGE("ERROR: MediaPlayer native registration failed\n");
1317 goto bail;
1318 }
1319
1320 /* success -- return valid version number */
1321 result = JNI_VERSION_1_4;
1322
1323bail:
1324 return result;
1325}