blob: e56df0a28db8db4017634c8f81fd0c483d8dbd98 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070025
Jason Samsffe9f482009-06-01 17:45:53 -070026#include <core/SkBitmap.h>
Romain Guy650a3eb2009-08-31 14:06:43 -070027#include <core/SkPixelRef.h>
28#include <core/SkStream.h>
29#include <core/SkTemplates.h>
Jason Samsffe9f482009-06-01 17:45:53 -070030
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080031#include <androidfw/Asset.h>
32#include <androidfw/AssetManager.h>
33#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070034
Jason Samsd19f10d2009-05-22 14:03:28 -070035#include "jni.h"
36#include "JNIHelp.h"
37#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070038#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080039#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070040
Jason Sams1d6983a2012-02-16 16:07:49 -080041#include <rs.h>
42#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070043#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080044#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080045#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070046#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070047
Steve Block3762c312012-01-06 19:20:56 +000048//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070049#define LOG_API(...)
50
51using namespace android;
52
Jason Samse729a942013-11-06 11:22:02 -080053#define PER_ARRAY_TYPE(flag, fnc, ...) { \
54 jint len = 0; \
55 void *ptr = NULL; \
56 switch(dataType) { \
57 case RS_TYPE_FLOAT_32: \
58 len = _env->GetArrayLength((jfloatArray)data); \
59 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
60 fnc(__VA_ARGS__); \
61 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, JNI_ABORT); \
62 return; \
63 case RS_TYPE_FLOAT_64: \
64 len = _env->GetArrayLength((jdoubleArray)data); \
65 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
66 fnc(__VA_ARGS__); \
67 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, JNI_ABORT);\
68 return; \
69 case RS_TYPE_SIGNED_8: \
70 case RS_TYPE_UNSIGNED_8: \
71 len = _env->GetArrayLength((jbyteArray)data); \
72 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
73 fnc(__VA_ARGS__); \
74 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, JNI_ABORT); \
75 return; \
76 case RS_TYPE_SIGNED_16: \
77 case RS_TYPE_UNSIGNED_16: \
78 len = _env->GetArrayLength((jshortArray)data); \
79 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
80 fnc(__VA_ARGS__); \
81 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, JNI_ABORT); \
82 return; \
83 case RS_TYPE_SIGNED_32: \
84 case RS_TYPE_UNSIGNED_32: \
85 len = _env->GetArrayLength((jintArray)data); \
86 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
87 fnc(__VA_ARGS__); \
88 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, JNI_ABORT); \
89 return; \
90 case RS_TYPE_SIGNED_64: \
91 case RS_TYPE_UNSIGNED_64: \
92 len = _env->GetArrayLength((jlongArray)data); \
93 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
94 fnc(__VA_ARGS__); \
95 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, JNI_ABORT); \
96 return; \
97 default: \
98 break; \
99 } \
100}
101
102
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800103class AutoJavaStringToUTF8 {
104public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800105 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800106 fCStr = env->GetStringUTFChars(str, NULL);
107 fLength = env->GetStringUTFLength(str);
108 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800109 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800110 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
111 }
112 const char* c_str() const { return fCStr; }
113 jsize length() const { return fLength; }
114
115private:
116 JNIEnv* fEnv;
117 jstring fJStr;
118 const char* fCStr;
119 jsize fLength;
120};
121
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800122class AutoJavaStringArrayToUTF8 {
123public:
124 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
125 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
126 mCStrings = NULL;
127 mSizeArray = NULL;
128 if (stringsLength > 0) {
129 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
130 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
131 for (jsize ct = 0; ct < stringsLength; ct ++) {
132 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
133 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
134 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
135 }
136 }
137 }
138 ~AutoJavaStringArrayToUTF8() {
139 for (jsize ct=0; ct < mStringsLength; ct++) {
140 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
141 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
142 }
143 free(mCStrings);
144 free(mSizeArray);
145 }
146 const char **c_str() const { return mCStrings; }
147 size_t *c_str_len() const { return mSizeArray; }
148 jsize length() const { return mStringsLength; }
149
150private:
151 JNIEnv *mEnv;
152 jobjectArray mStrings;
153 const char **mCStrings;
154 size_t *mSizeArray;
155 jsize mStringsLength;
156};
157
Jason Samsd19f10d2009-05-22 14:03:28 -0700158// ---------------------------------------------------------------------------
159
Jason Samsffe9f482009-06-01 17:45:53 -0700160static jfieldID gContextId = 0;
161static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700162static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700163
164static void _nInit(JNIEnv *_env, jclass _this)
165{
Jason Samsd19f10d2009-05-22 14:03:28 -0700166 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700167
168 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
169 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -0700170}
171
Jason Samsd19f10d2009-05-22 14:03:28 -0700172// ---------------------------------------------------------------------------
173
Jason Sams3eaa338e2009-06-10 15:04:38 -0700174static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700175nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700176{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700177 LOG_API("nContextFinish, con(%p)", con);
178 rsContextFinish(con);
179}
180
181static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700182nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700183{
Jason Sams07ae4062009-08-27 20:23:34 -0700184 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700185 jint len = _env->GetArrayLength(str);
186 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700187 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700188 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
189}
190
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700191static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700192nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700193{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700194 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700195 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700196 rsaGetName(con, (void *)obj, &name);
197 if(name == NULL || strlen(name) == 0) {
198 return NULL;
199 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700200 return _env->NewStringUTF(name);
201}
202
Jason Sams7ce033d2009-08-18 14:14:24 -0700203static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700204nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700205{
Jason Sams7ce033d2009-08-18 14:14:24 -0700206 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700207 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700208}
209
Jason Sams3eaa338e2009-06-10 15:04:38 -0700210// ---------------------------------------------------------------------------
211
Jason Samsd19f10d2009-05-22 14:03:28 -0700212static jint
213nDeviceCreate(JNIEnv *_env, jobject _this)
214{
215 LOG_API("nDeviceCreate");
216 return (jint)rsDeviceCreate();
217}
218
219static void
220nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
221{
222 LOG_API("nDeviceDestroy");
223 return rsDeviceDestroy((RsDevice)dev);
224}
225
Jason Samsebfb4362009-09-23 13:57:02 -0700226static void
227nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
228{
229 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
230 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
231}
232
Jason Samsd19f10d2009-05-22 14:03:28 -0700233static jint
Jason Samsadd26dc2013-02-22 18:43:45 -0800234nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700235{
236 LOG_API("nContextCreate");
Tim Murray9578e642013-09-09 16:15:56 -0700237 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0);
Jason Sams704ff642010-02-09 16:05:07 -0800238}
239
240static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700241nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700242 int colorMin, int colorPref,
243 int alphaMin, int alphaPref,
244 int depthMin, int depthPref,
245 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700246 int samplesMin, int samplesPref, float samplesQ,
247 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800248{
Jason Sams11c8af92010-10-13 15:31:10 -0700249 RsSurfaceConfig sc;
250 sc.alphaMin = alphaMin;
251 sc.alphaPref = alphaPref;
252 sc.colorMin = colorMin;
253 sc.colorPref = colorPref;
254 sc.depthMin = depthMin;
255 sc.depthPref = depthPref;
256 sc.samplesMin = samplesMin;
257 sc.samplesPref = samplesPref;
258 sc.samplesQ = samplesQ;
259
Jason Sams704ff642010-02-09 16:05:07 -0800260 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700261 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700262}
263
264static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700265nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800266{
Jason Sams7d787b42009-11-15 12:14:26 -0800267 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
268 rsContextSetPriority(con, p);
269}
270
271
272
273static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700274nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800275{
Jason Sams3bc47d42009-11-12 15:10:25 -0800276 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800277
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700278 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800279 if (wnd == NULL) {
280
281 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700282 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800283 }
284
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700285 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800286}
287
288static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700289nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700290{
Jason Sams2e1872f2010-08-17 16:25:41 -0700291 LOG_API("nContextDestroy, con(%p)", con);
292 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700293}
294
Jason Sams715333b2009-11-17 17:26:46 -0800295static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700296nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800297{
Jason Sams715333b2009-11-17 17:26:46 -0800298 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
299 rsContextDump((RsContext)con, bits);
300}
Jason Samsd19f10d2009-05-22 14:03:28 -0700301
302static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700303nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700304{
Jason Sams65e7aa52009-09-24 17:38:20 -0700305 LOG_API("nContextPause, con(%p)", con);
306 rsContextPause(con);
307}
308
309static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700310nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700311{
Jason Sams65e7aa52009-09-24 17:38:20 -0700312 LOG_API("nContextResume, con(%p)", con);
313 rsContextResume(con);
314}
315
Jason Sams1c415172010-11-08 17:06:46 -0800316
317static jstring
318nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
319{
320 LOG_API("nContextGetErrorMessage, con(%p)", con);
321 char buf[1024];
322
323 size_t receiveLen;
324 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700325 int id = rsContextGetMessage(con,
326 buf, sizeof(buf),
327 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700328 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800329 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100330 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800331 }
332 return _env->NewStringUTF(buf);
333}
334
Jason Samsedbfabd2011-05-17 15:01:29 -0700335static jint
Jason Sams1c415172010-11-08 17:06:46 -0800336nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700337{
Jason Sams516c3192009-10-06 13:58:47 -0700338 jint len = _env->GetArrayLength(data);
339 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
340 jint *ptr = _env->GetIntArrayElements(data, NULL);
341 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800342 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700343 int id = rsContextGetMessage(con,
344 ptr, len * 4,
345 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700346 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700347 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100348 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700349 }
350 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700351 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800352}
353
354static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700355nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800356{
357 LOG_API("nContextPeekMessage, con(%p)", con);
358 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
359 size_t receiveLen;
360 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700361 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700362 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800363 auxDataPtr[0] = (jint)subID;
364 auxDataPtr[1] = (jint)receiveLen;
365 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700366 return id;
367}
368
Jason Sams2e1872f2010-08-17 16:25:41 -0700369static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700370{
Jason Sams516c3192009-10-06 13:58:47 -0700371 LOG_API("nContextInitToClient, con(%p)", con);
372 rsContextInitToClient(con);
373}
374
Jason Sams2e1872f2010-08-17 16:25:41 -0700375static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700376{
Jason Sams516c3192009-10-06 13:58:47 -0700377 LOG_API("nContextDeinitToClient, con(%p)", con);
378 rsContextDeinitToClient(con);
379}
380
Jason Sams455d6442013-02-05 19:20:18 -0800381static void
382nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data)
383{
384 jint *ptr = NULL;
385 jint len = 0;
386 if (data) {
387 len = _env->GetArrayLength(data);
388 jint *ptr = _env->GetIntArrayElements(data, NULL);
389 }
390 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len);
391 rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int));
392 if (data) {
393 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
394 }
395}
396
397
Jason Sams516c3192009-10-06 13:58:47 -0700398
Jason Sams718cd1f2009-12-23 14:35:29 -0800399static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700400nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700401{
Jason Sams718cd1f2009-12-23 14:35:29 -0800402 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
403 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700404}
405
406static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800407nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
408 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700409{
Jason Sams718cd1f2009-12-23 14:35:29 -0800410 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800411 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800412
413 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700414 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800415
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800416 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
417
418 const char **nameArray = names.c_str();
419 size_t *sizeArray = names.c_str_len();
420
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700421 jint id = (jint)rsElementCreate2(con,
422 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700423 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700424 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800425
Jason Sams718cd1f2009-12-23 14:35:29 -0800426 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700427 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800428 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700429}
430
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700431static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700432nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700433{
434 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700435 LOG_API("nElementGetNativeData, con(%p)", con);
436
437 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
438 assert(dataSize == 5);
439
440 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700441 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700442
443 for(jint i = 0; i < dataSize; i ++) {
444 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
445 }
446}
447
448
449static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700450nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
451 jintArray _IDs,
452 jobjectArray _names,
453 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700454{
455 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700456 LOG_API("nElementGetSubElements, con(%p)", con);
457
458 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
459 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700460 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700461
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700462 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700463
Jason Sams11c8af92010-10-13 15:31:10 -0700464 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700465 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
466 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700467 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700468 }
469
470 free(ids);
471 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700472 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700473}
474
Jason Samsd19f10d2009-05-22 14:03:28 -0700475// -----------------------------------
476
Jason Sams3b9c52a2010-10-14 17:48:46 -0700477static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800478nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800479 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700480{
Jason Samsb109cc72013-01-07 18:20:12 -0800481 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
482 con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700483
Jason Samsb109cc72013-01-07 18:20:12 -0800484 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700485 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700486}
487
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700488static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700489nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700490{
491 // We are packing 6 items: mDimX; mDimY; mDimZ;
492 // mDimLOD; mDimFaces; mElement; into typeData
493 int elementCount = _env->GetArrayLength(_typeData);
494
495 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700496 LOG_API("nTypeCreate, con(%p)", con);
497
498 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700499 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700500
501 for(jint i = 0; i < elementCount; i ++) {
502 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
503 }
504}
505
Jason Samsd19f10d2009-05-22 14:03:28 -0700506// -----------------------------------
507
508static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800509nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700510{
Jason Sams857d0c72011-11-23 15:02:15 -0800511 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
512 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700513}
514
Jason Samsd19f10d2009-05-22 14:03:28 -0700515static void
Jason Sams5476b452010-12-08 16:14:36 -0800516nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
517{
518 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
519 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
520}
521
Jason Sams72226e02013-02-22 12:45:54 -0800522static jobject
523nAllocationGetSurface(JNIEnv *_env, jobject _this, RsContext con, jint a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800524{
Jason Sams72226e02013-02-22 12:45:54 -0800525 LOG_API("nAllocationGetSurface, con(%p), a(%p)", con, (RsAllocation)a);
Jason Sams615e7ce2012-01-13 14:01:20 -0800526
Jason Sams72226e02013-02-22 12:45:54 -0800527 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface(con, (RsAllocation)a);
528 sp<IGraphicBufferProducer> bp = v;
529 v->decStrong(NULL);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700530
Jason Sams72226e02013-02-22 12:45:54 -0800531 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
532 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700533}
534
535static void
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700536nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800537{
Stephen Hines06883b72012-05-16 18:01:34 -0700538 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Jason Sams163766c2012-02-15 12:04:24 -0800539 con, alloc, (Surface *)sur);
540
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700541 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800542 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700543 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800544 }
545
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700546 rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800547}
548
549static void
550nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
551{
552 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
553 rsAllocationIoSend(con, alloc);
554}
555
556static void
557nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
558{
559 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
560 rsAllocationIoReceive(con, alloc);
561}
562
563
564static void
Jason Samsf7086092011-01-12 13:28:37 -0800565nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
566{
567 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
568 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
569}
570
Jason Samsffe9f482009-06-01 17:45:53 -0700571static int
Jason Sams5476b452010-12-08 16:14:36 -0800572nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700573{
Jason Samsffe9f482009-06-01 17:45:53 -0700574 SkBitmap const * nativeBitmap =
575 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
576 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700577
Jason Sams5476b452010-12-08 16:14:36 -0800578 bitmap.lockPixels();
579 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700580 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700581 (RsType)type, (RsAllocationMipmapControl)mip,
582 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800583 bitmap.unlockPixels();
584 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700585}
Jason Samsfe08d992009-05-27 14:45:32 -0700586
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800587static int
Tim Murraya3145512012-12-04 17:59:29 -0800588nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
589{
590 SkBitmap const * nativeBitmap =
591 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
592 const SkBitmap& bitmap(*nativeBitmap);
593
594 bitmap.lockPixels();
595 const void* ptr = bitmap.getPixels();
596 jint id = (jint)rsAllocationCreateTyped(con,
597 (RsType)type, (RsAllocationMipmapControl)mip,
598 (uint32_t)usage, (size_t)ptr);
599 bitmap.unlockPixels();
600 return id;
601}
602
603static int
Jason Sams5476b452010-12-08 16:14:36 -0800604nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800605{
606 SkBitmap const * nativeBitmap =
607 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
608 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800609
Jason Sams5476b452010-12-08 16:14:36 -0800610 bitmap.lockPixels();
611 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700612 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700613 (RsType)type, (RsAllocationMipmapControl)mip,
614 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800615 bitmap.unlockPixels();
616 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800617}
618
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700619static void
Jason Sams4ef66502010-12-10 16:03:15 -0800620nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700621{
622 SkBitmap const * nativeBitmap =
623 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
624 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800625 int w = bitmap.width();
626 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700627
Jason Sams4ef66502010-12-10 16:03:15 -0800628 bitmap.lockPixels();
629 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800630 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700631 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800632 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800633 bitmap.unlockPixels();
634}
635
636static void
637nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
638{
639 SkBitmap const * nativeBitmap =
640 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
641 const SkBitmap& bitmap(*nativeBitmap);
642
643 bitmap.lockPixels();
644 void* ptr = bitmap.getPixels();
645 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
646 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700647 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700648}
649
Jason Sams8a647432010-03-01 15:31:04 -0800650static void ReleaseBitmapCallback(void *bmp)
651{
652 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
653 nativeBitmap->unlockPixels();
654}
655
Romain Guy650a3eb2009-08-31 14:06:43 -0700656
Jason Samsd19f10d2009-05-22 14:03:28 -0700657static void
Jason Samse729a942013-11-06 11:22:02 -0800658nAllocationData1D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint offset, jint lod,
659 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700660{
Jason Samse729a942013-11-06 11:22:02 -0800661 RsAllocation *alloc = (RsAllocation *)_alloc;
662 LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i), dataType(%i)",
663 con, alloc, offset, count, len, sizeBytes, dataType);
664 PER_ARRAY_TYPE(NULL, rsAllocation1DData, con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700665}
666
667static void
Jason Sams49a05d72010-12-29 14:31:29 -0800668// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
669nAllocationElementData1D(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 -0700670{
671 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800672 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 -0700673 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800674 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700675 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
676}
677
678static void
Jason Samse729a942013-11-06 11:22:02 -0800679nAllocationData2D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint xoff, jint yoff, jint lod, jint _face,
680 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800681{
Jason Samse729a942013-11-06 11:22:02 -0800682 RsAllocation *alloc = (RsAllocation *)_alloc;
683 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
684 LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
685 con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
686 PER_ARRAY_TYPE(NULL, rsAllocation2DData, con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700687}
688
Jason Sams40a29e82009-08-10 14:55:26 -0700689static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700690nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
691 jint dstAlloc, jint dstXoff, jint dstYoff,
692 jint dstMip, jint dstFace,
693 jint width, jint height,
694 jint srcAlloc, jint srcXoff, jint srcYoff,
695 jint srcMip, jint srcFace)
696{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800697 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700698 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
699 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
700 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
701 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
702
703 rsAllocationCopy2DRange(con,
704 (RsAllocation)dstAlloc,
705 dstXoff, dstYoff,
706 dstMip, dstFace,
707 width, height,
708 (RsAllocation)srcAlloc,
709 srcXoff, srcYoff,
710 srcMip, srcFace);
711}
712
713static void
Jason Samse729a942013-11-06 11:22:02 -0800714nAllocationData3D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint xoff, jint yoff, jint zoff, jint lod,
715 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700716{
Jason Samse729a942013-11-06 11:22:02 -0800717 RsAllocation *alloc = (RsAllocation *)_alloc;
718 LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)",
719 con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes);
720 PER_ARRAY_TYPE(NULL, rsAllocation3DData, con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -0700721}
722
723static void
724nAllocationData3D_alloc(JNIEnv *_env, jobject _this, RsContext con,
725 jint dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
726 jint dstMip,
727 jint width, jint height, jint depth,
728 jint srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
729 jint srcMip)
730{
731 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
732 " dstMip(%i), width(%i), height(%i),"
733 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
734 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
735 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
736
737 rsAllocationCopy3DRange(con,
738 (RsAllocation)dstAlloc,
739 dstXoff, dstYoff, dstZoff, dstMip,
740 width, height, depth,
741 (RsAllocation)srcAlloc,
742 srcXoff, srcYoff, srcZoff, srcMip);
743}
744
745static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700746nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700747{
Jason Sams40a29e82009-08-10 14:55:26 -0700748 jint len = _env->GetArrayLength(data);
749 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
750 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700751 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700752 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700753 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700754}
755
756static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800757nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
758{
759 jint len = _env->GetArrayLength(data);
760 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
761 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700762 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700763 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800764 _env->ReleaseShortArrayElements(data, ptr, 0);
765}
766
767static void
768nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
769{
770 jint len = _env->GetArrayLength(data);
771 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
772 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700773 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700774 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800775 _env->ReleaseByteArrayElements(data, ptr, 0);
776}
777
778static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700779nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700780{
Jason Sams40a29e82009-08-10 14:55:26 -0700781 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700782 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700783 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700784 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700785 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700786 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700787}
Jason Samsd19f10d2009-05-22 14:03:28 -0700788
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700789static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700790nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700791{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700792 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700793 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700794}
795
Jason Sams5edc6082010-10-05 13:32:49 -0700796static void
797nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
798{
799 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
800 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
801}
802
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700803// -----------------------------------
804
805static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700806nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700807{
Steve Block71f2cf12011-10-20 11:56:00 +0100808 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700809
810 Asset* asset = reinterpret_cast<Asset*>(native_asset);
811
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800812 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
813 return id;
814}
815
816static int
817nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
818{
819 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
820 if (mgr == NULL) {
821 return 0;
822 }
823
824 AutoJavaStringToUTF8 str(_env, _path);
825 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
826 if (asset == NULL) {
827 return 0;
828 }
829
830 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
831 return id;
832}
833
834static int
835nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
836{
837 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
838 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
839
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700840 return id;
841}
842
843static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700844nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700845{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700846 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700847 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700848 return numEntries;
849}
850
851static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700852nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700853{
Steve Block71f2cf12011-10-20 11:56:00 +0100854 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700855 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
856
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700857 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700858
859 for(jint i = 0; i < numEntries; i ++) {
860 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
861 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
862 }
863
864 free(fileEntries);
865}
866
867static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700868nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700869{
Steve Block71f2cf12011-10-20 11:56:00 +0100870 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700871 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700872 return id;
873}
Jason Samsd19f10d2009-05-22 14:03:28 -0700874
875// -----------------------------------
876
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700877static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800878nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
879 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700880{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800881 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700882 jint id = (jint)rsFontCreateFromFile(con,
883 fileNameUTF.c_str(), fileNameUTF.length(),
884 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700885
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800886 return id;
887}
888
889static int
890nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
891 jstring name, jfloat fontSize, jint dpi, jint native_asset)
892{
893 Asset* asset = reinterpret_cast<Asset*>(native_asset);
894 AutoJavaStringToUTF8 nameUTF(_env, name);
895
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700896 jint id = (jint)rsFontCreateFromMemory(con,
897 nameUTF.c_str(), nameUTF.length(),
898 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800899 asset->getBuffer(false), asset->getLength());
900 return id;
901}
902
903static int
904nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
905 jfloat fontSize, jint dpi)
906{
907 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
908 if (mgr == NULL) {
909 return 0;
910 }
911
912 AutoJavaStringToUTF8 str(_env, _path);
913 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
914 if (asset == NULL) {
915 return 0;
916 }
917
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700918 jint id = (jint)rsFontCreateFromMemory(con,
919 str.c_str(), str.length(),
920 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800921 asset->getBuffer(false), asset->getLength());
922 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700923 return id;
924}
925
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700926// -----------------------------------
927
928static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700929nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700930{
Jason Samsd19f10d2009-05-22 14:03:28 -0700931 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700932 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700933}
934
935static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700936nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700937{
Jason Samscfc04362010-09-14 14:59:03 -0700938 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700939 rsScriptSetVarI(con, (RsScript)script, slot, val);
940}
941
Tim Murray7c4caad2013-04-10 16:21:40 -0700942static jint
943nScriptGetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
944{
945 LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
946 int value = 0;
947 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
948 return value;
949}
950
Jason Sams4d339932010-05-11 14:03:58 -0700951static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800952nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
953{
954 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
955 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
956}
957
958static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700959nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
960{
961 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
962 rsScriptSetVarJ(con, (RsScript)script, slot, val);
963}
964
Tim Murray7c4caad2013-04-10 16:21:40 -0700965static jlong
966nScriptGetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
967{
968 LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
969 jlong value = 0;
970 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
971 return value;
972}
973
Stephen Hines031ec58c2010-10-11 10:54:21 -0700974static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700975nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700976{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700977 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700978 rsScriptSetVarF(con, (RsScript)script, slot, val);
979}
980
Tim Murray7c4caad2013-04-10 16:21:40 -0700981static jfloat
982nScriptGetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
983{
984 LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
985 jfloat value = 0;
986 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
987 return value;
988}
989
Jason Sams4d339932010-05-11 14:03:58 -0700990static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700991nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
992{
993 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
994 rsScriptSetVarD(con, (RsScript)script, slot, val);
995}
996
Tim Murray7c4caad2013-04-10 16:21:40 -0700997static jdouble
998nScriptGetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
999{
1000 LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1001 jdouble value = 0;
1002 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
1003 return value;
1004}
1005
Stephen Hinesca54ec32010-09-20 17:20:30 -07001006static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001007nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001008{
Jason Sams4d339932010-05-11 14:03:58 -07001009 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1010 jint len = _env->GetArrayLength(data);
1011 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1012 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
1013 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1014}
1015
Stephen Hinesadeb8092012-04-20 14:26:06 -07001016static void
Tim Murray7c4caad2013-04-10 16:21:40 -07001017nScriptGetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
1018{
1019 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1020 jint len = _env->GetArrayLength(data);
1021 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1022 rsScriptGetVarV(con, (RsScript)script, slot, ptr, len);
1023 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1024}
1025
1026static void
Stephen Hinesadeb8092012-04-20 14:26:06 -07001027nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
1028{
1029 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1030 jint len = _env->GetArrayLength(data);
1031 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1032 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
1033 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
1034 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
1035 (const size_t*) dimsPtr, dimsLen);
1036 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1037 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1038}
1039
Jason Samsd19f10d2009-05-22 14:03:28 -07001040
1041static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001042nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001043{
Jason Sams07ae4062009-08-27 20:23:34 -07001044 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -07001045
1046 jint length = _env->GetArrayLength(timeZone);
1047 jbyte* timeZone_ptr;
1048 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1049
Jason Samsbc948de2009-08-17 18:35:48 -07001050 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001051
1052 if (timeZone_ptr) {
1053 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1054 }
1055}
1056
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001057static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001058nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001059{
Jason Samsbe2e8412009-09-16 15:04:38 -07001060 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
1061 rsScriptInvoke(con, (RsScript)obj, slot);
1062}
1063
1064static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001065nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001066{
Jason Sams4d339932010-05-11 14:03:58 -07001067 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1068 jint len = _env->GetArrayLength(data);
1069 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1070 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
1071 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1072}
1073
Jason Sams6e494d32011-04-27 16:33:11 -07001074static void
1075nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
1076 jint script, jint slot, jint ain, jint aout)
1077{
1078 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001079 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001080}
1081static void
1082nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1083 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1084{
1085 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1086 jint len = _env->GetArrayLength(params);
1087 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001088 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001089 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1090}
1091
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001092static void
1093nScriptForEachClipped(JNIEnv *_env, jobject _this, RsContext con,
1094 jint script, jint slot, jint ain, jint aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001095 jint xstart, jint xend,
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001096 jint ystart, jint yend, jint zstart, jint zend)
1097{
1098 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001099 RsScriptCall sc;
1100 sc.xStart = xstart;
1101 sc.xEnd = xend;
1102 sc.yStart = ystart;
1103 sc.yEnd = yend;
1104 sc.zStart = zstart;
1105 sc.zEnd = zend;
1106 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1107 sc.arrayStart = 0;
1108 sc.arrayEnd = 0;
1109 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
1110}
1111
1112static void
1113nScriptForEachClippedV(JNIEnv *_env, jobject _this, RsContext con,
1114 jint script, jint slot, jint ain, jint aout,
1115 jbyteArray params, jint xstart, jint xend,
1116 jint ystart, jint yend, jint zstart, jint zend)
1117{
1118 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001119 jint len = _env->GetArrayLength(params);
1120 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1121 RsScriptCall sc;
1122 sc.xStart = xstart;
1123 sc.xEnd = xend;
1124 sc.yStart = ystart;
1125 sc.yEnd = yend;
1126 sc.zStart = zstart;
1127 sc.zEnd = zend;
1128 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1129 sc.arrayStart = 0;
1130 sc.arrayEnd = 0;
1131 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc));
1132 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1133}
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001134
Jason Sams22534172009-08-04 16:58:20 -07001135// -----------------------------------
1136
Jason Samse4a06c52011-03-16 16:29:28 -07001137static jint
1138nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1139 jstring resName, jstring cacheDir,
1140 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001141{
Jason Samse4a06c52011-03-16 16:29:28 -07001142 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001143
Jason Samse4a06c52011-03-16 16:29:28 -07001144 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1145 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1146 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001147 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001148 jint _exception = 0;
1149 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001150 if (!scriptRef) {
1151 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001152 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001153 goto exit;
1154 }
Jack Palevich43702d82009-05-28 13:38:16 -07001155 if (length < 0) {
1156 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001157 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001158 goto exit;
1159 }
Jason Samse4a06c52011-03-16 16:29:28 -07001160 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001161 if (remaining < length) {
1162 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001163 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1164 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001165 goto exit;
1166 }
Jason Samse4a06c52011-03-16 16:29:28 -07001167 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001168 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001169
Jason Samse4a06c52011-03-16 16:29:28 -07001170 //rsScriptCSetText(con, (const char *)script_ptr, length);
1171
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001172 ret = (jint)rsScriptCCreate(con,
1173 resNameUTF.c_str(), resNameUTF.length(),
1174 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001175 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001176
Jack Palevich43702d82009-05-28 13:38:16 -07001177exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001178 if (script_ptr) {
1179 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001180 _exception ? JNI_ABORT: 0);
1181 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001182
Jason Samse4a06c52011-03-16 16:29:28 -07001183 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001184}
1185
Jason Sams6ab97682012-08-10 12:09:43 -07001186static jint
1187nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid)
1188{
1189 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid);
1190 return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid);
1191}
1192
Jason Sams08a81582012-09-18 12:32:10 -07001193static jint
1194nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig)
1195{
1196 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig);
1197 return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig);
1198}
1199
1200static jint
1201nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot)
1202{
1203 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot);
1204 return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot);
1205}
1206
1207static jint
1208nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src,
1209 jintArray _dstk, jintArray _dstf, jintArray _types)
1210{
1211 LOG_API("nScriptGroupCreate, con(%p)", con);
1212
1213 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int);
1214 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL);
1215 jint srcLen = _env->GetArrayLength(_src) * sizeof(int);
1216 jint *srcPtr = _env->GetIntArrayElements(_src, NULL);
1217 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int);
1218 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL);
1219 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int);
1220 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL);
1221 jint typesLen = _env->GetArrayLength(_types) * sizeof(int);
1222 jint *typesPtr = _env->GetIntArrayElements(_types, NULL);
1223
1224 int id = (int)rsScriptGroupCreate(con,
1225 (RsScriptKernelID *)kernelsPtr, kernelsLen,
1226 (RsScriptKernelID *)srcPtr, srcLen,
1227 (RsScriptKernelID *)dstkPtr, dstkLen,
1228 (RsScriptFieldID *)dstfPtr, dstfLen,
1229 (RsType *)typesPtr, typesLen);
1230
1231 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0);
1232 _env->ReleaseIntArrayElements(_src, srcPtr, 0);
1233 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0);
1234 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0);
1235 _env->ReleaseIntArrayElements(_types, typesPtr, 0);
1236 return id;
1237}
1238
1239static void
1240nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1241{
1242 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1243 (void *)gid, (void *)kid, (void *)alloc);
1244 rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1245}
1246
1247static void
1248nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1249{
1250 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1251 (void *)gid, (void *)kid, (void *)alloc);
1252 rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1253}
1254
1255static void
1256nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid)
1257{
1258 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid);
1259 rsScriptGroupExecute(con, (RsScriptGroup)gid);
1260}
1261
Jason Samsd19f10d2009-05-22 14:03:28 -07001262// ---------------------------------------------------------------------------
1263
Jason Samsd19f10d2009-05-22 14:03:28 -07001264static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001265nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1266 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1267 jboolean depthMask, jboolean ditherEnable,
1268 jint srcFunc, jint destFunc,
1269 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001270{
Jason Sams54db59c2010-05-13 18:30:11 -07001271 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001272 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1273 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1274 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001275}
1276
Jason Sams0011bcf2009-12-15 12:58:36 -08001277// ---------------------------------------------------------------------------
1278
1279static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001280nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001281{
Jason Sams0011bcf2009-12-15 12:58:36 -08001282 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1283 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1284}
Jason Sams54c0ec12009-11-30 14:49:55 -08001285
Jason Sams68afd012009-12-17 16:55:08 -08001286static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001287nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001288{
Jason Sams68afd012009-12-17 16:55:08 -08001289 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1290 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1291}
1292
1293static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001294nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001295{
Jason Sams68afd012009-12-17 16:55:08 -08001296 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1297 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1298}
1299
Jason Samsd19f10d2009-05-22 14:03:28 -07001300// ---------------------------------------------------------------------------
1301
Jason Samsd19f10d2009-05-22 14:03:28 -07001302static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001303nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1304 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001305{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001306 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001307 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1308 jint paramLen = _env->GetArrayLength(params);
1309
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001310 int texCount = _env->GetArrayLength(texNames);
1311 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1312 const char ** nameArray = names.c_str();
1313 size_t* sizeArray = names.c_str_len();
1314
Jason Sams991040c2011-01-17 15:59:39 -08001315 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001316
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001317 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1318 nameArray, texCount, sizeArray,
1319 (uint32_t *)paramPtr, paramLen);
1320
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001321 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1322 return ret;
1323}
1324
1325
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001326// ---------------------------------------------------------------------------
1327
Jason Sams0011bcf2009-12-15 12:58:36 -08001328static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001329nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1330 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001331{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001332 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001333 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1334 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001335
Jason Sams991040c2011-01-17 15:59:39 -08001336 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001337
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001338 int texCount = _env->GetArrayLength(texNames);
1339 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1340 const char ** nameArray = names.c_str();
1341 size_t* sizeArray = names.c_str_len();
1342
1343 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1344 nameArray, texCount, sizeArray,
1345 (uint32_t *)paramPtr, paramLen);
1346
Jason Sams0011bcf2009-12-15 12:58:36 -08001347 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1348 return ret;
1349}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001350
Jason Samsebfb4362009-09-23 13:57:02 -07001351// ---------------------------------------------------------------------------
1352
1353static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001354nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001355{
Jason Sams94aaed32011-09-23 14:18:53 -07001356 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1357 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001358}
1359
Jason Samsd19f10d2009-05-22 14:03:28 -07001360
1361// ---------------------------------------------------------------------------
1362
1363static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001364nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001365{
Jason Samsd19f10d2009-05-22 14:03:28 -07001366 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001367 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001368}
1369
1370static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001371nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001372{
Jason Sams54db59c2010-05-13 18:30:11 -07001373 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1374 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001375}
1376
1377static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001378nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001379{
Jason Samsd19f10d2009-05-22 14:03:28 -07001380 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001381 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001382}
1383
Jason Sams0826a6f2009-06-15 19:04:56 -07001384static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001385nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001386{
Jason Sams0826a6f2009-06-15 19:04:56 -07001387 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001388 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001389}
1390
Joe Onoratod7b37742009-08-09 22:57:44 -07001391static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001392nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001393{
Jason Samsebfb4362009-09-23 13:57:02 -07001394 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1395 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1396}
1397
Joe Onoratod7b37742009-08-09 22:57:44 -07001398
Jason Sams02fb2cb2009-05-28 15:37:57 -07001399// ---------------------------------------------------------------------------
1400
Jason Sams02fb2cb2009-05-28 15:37:57 -07001401static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001402nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1403 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001404{
Jason Samsbba134c2009-06-22 15:49:21 -07001405 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001406 return (jint)rsSamplerCreate(con,
1407 (RsSamplerValue)magFilter,
1408 (RsSamplerValue)minFilter,
1409 (RsSamplerValue)wrapS,
1410 (RsSamplerValue)wrapT,
1411 (RsSamplerValue)wrapR,
1412 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001413}
1414
Jason Samsbba134c2009-06-22 15:49:21 -07001415// ---------------------------------------------------------------------------
1416
Jason Samsf15ed012011-10-31 13:23:43 -07001417//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1418static jint
1419nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1420 LOG_API("nPathCreate, con(%p)", con);
1421
1422 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1423 (RsAllocation)_vtx,
1424 (RsAllocation)_loop, q);
1425 return id;
1426}
1427
Jason Samsbba134c2009-06-22 15:49:21 -07001428static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001429nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001430{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001431 LOG_API("nMeshCreate, con(%p)", con);
1432
1433 jint vtxLen = _env->GetArrayLength(_vtx);
1434 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1435 jint idxLen = _env->GetArrayLength(_idx);
1436 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1437 jint primLen = _env->GetArrayLength(_prim);
1438 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1439
1440 int id = (int)rsMeshCreate(con,
1441 (RsAllocation *)vtxPtr, vtxLen,
1442 (RsAllocation *)idxPtr, idxLen,
1443 (uint32_t *)primPtr, primLen);
1444
1445 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1446 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1447 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001448 return id;
1449}
1450
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001451static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001452nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001453{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001454 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1455 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001456 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001457 return vtxCount;
1458}
1459
1460static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001461nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001462{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001463 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1464 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001465 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001466 return idxCount;
1467}
1468
1469static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001470nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001471{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001472 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1473
1474 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001475 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001476
1477 for(jint i = 0; i < numVtxIDs; i ++) {
1478 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1479 }
1480
1481 free(allocs);
1482}
1483
1484static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001485nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001486{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001487 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1488
1489 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1490 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1491
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001492 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001493
1494 for(jint i = 0; i < numIndices; i ++) {
1495 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1496 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1497 }
1498
1499 free(allocs);
1500 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001501}
1502
1503// ---------------------------------------------------------------------------
1504
Jason Samsd19f10d2009-05-22 14:03:28 -07001505
Jason Sams94d8e90a2009-06-10 16:09:05 -07001506static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001507
1508static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001509{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001510
Jason Sams1c415172010-11-08 17:06:46 -08001511{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1512{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1513{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001514{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001515{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001516{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001517
1518{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1519{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001520
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001521
Jason Sams2e1872f2010-08-17 16:25:41 -07001522// All methods below are thread protected in java.
Jason Samsadd26dc2013-02-22 18:43:45 -08001523{"rsnContextCreate", "(IIII)I", (void*)nContextCreate },
Stephen Hines4382467a2011-08-01 15:02:34 -07001524{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001525{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1526{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1527{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001528{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001529{"rsnContextDump", "(II)V", (void*)nContextDump },
1530{"rsnContextPause", "(I)V", (void*)nContextPause },
1531{"rsnContextResume", "(I)V", (void*)nContextResume },
Jason Sams455d6442013-02-05 19:20:18 -08001532{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage },
Jason Sams2e1872f2010-08-17 16:25:41 -07001533{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001534{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001535{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001536
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001537{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001538{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001539{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001540{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001541{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001542{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001543
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001544{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001545{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1546{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001547
Jason Sams2e1872f2010-08-17 16:25:41 -07001548{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001549{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001550{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001551{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001552
Jason Samsb109cc72013-01-07 18:20:12 -08001553{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001554{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001555
Jason Sams857d0c72011-11-23 15:02:15 -08001556{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001557{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
Tim Murraya3145512012-12-04 17:59:29 -08001558{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation },
Jason Sams5476b452010-12-08 16:14:36 -08001559{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001560
Jason Sams4ef66502010-12-10 16:03:15 -08001561{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1562{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1563
Jason Sams5476b452010-12-08 16:14:36 -08001564{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams72226e02013-02-22 12:45:54 -08001565{"rsnAllocationGetSurface", "(II)Landroid/view/Surface;", (void*)nAllocationGetSurface },
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001566{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
Jason Sams163766c2012-02-15 12:04:24 -08001567{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1568{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Samse729a942013-11-06 11:22:02 -08001569{"rsnAllocationData1D", "(IIIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
Jason Sams49a05d72010-12-29 14:31:29 -08001570{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
Jason Samse729a942013-11-06 11:22:02 -08001571{"rsnAllocationData2D", "(IIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001572{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Samse729a942013-11-06 11:22:02 -08001573{"rsnAllocationData3D", "(IIIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
Jason Samsb05d6892013-04-09 15:59:24 -07001574{"rsnAllocationData3D", "(IIIIIIIIIIIIII)V", (void*)nAllocationData3D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001575{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001576{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1577{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001578{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001579{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001580{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
Jason Samsf7086092011-01-12 13:28:37 -08001581{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001582
Jason Sams2e1872f2010-08-17 16:25:41 -07001583{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1584{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1585{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1586{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001587{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1588{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001589{"rsnScriptForEachClipped", "(IIIIIIIIIII)V", (void*)nScriptForEachClipped },
1590{"rsnScriptForEachClipped", "(IIIII[BIIIIII)V", (void*)nScriptForEachClippedV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001591{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Tim Murray7c4caad2013-04-10 16:21:40 -07001592{"rsnScriptGetVarI", "(III)I", (void*)nScriptGetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001593{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Tim Murray7c4caad2013-04-10 16:21:40 -07001594{"rsnScriptGetVarJ", "(III)J", (void*)nScriptGetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001595{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Tim Murray7c4caad2013-04-10 16:21:40 -07001596{"rsnScriptGetVarF", "(III)F", (void*)nScriptGetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001597{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Tim Murray7c4caad2013-04-10 16:21:40 -07001598{"rsnScriptGetVarD", "(III)D", (void*)nScriptGetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001599{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Tim Murray7c4caad2013-04-10 16:21:40 -07001600{"rsnScriptGetVarV", "(III[B)V", (void*)nScriptGetVarV },
Stephen Hinesadeb8092012-04-20 14:26:06 -07001601{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001602{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001603
Jason Samse4a06c52011-03-16 16:29:28 -07001604{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams6ab97682012-08-10 12:09:43 -07001605{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate },
Jason Sams08a81582012-09-18 12:32:10 -07001606{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate },
1607{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate },
1608{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate },
1609{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput },
1610{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput },
1611{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001612
Jason Sams331bf9b2011-04-06 11:23:54 -07001613{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001614
Jason Sams2e1872f2010-08-17 16:25:41 -07001615{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1616{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1617{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001618
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001619{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001620{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001621{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001622
Jason Sams2e1872f2010-08-17 16:25:41 -07001623{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001624{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001625{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1626{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1627{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001628
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001629{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001630
Jason Samsf15ed012011-10-31 13:23:43 -07001631{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001632{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001633
1634{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1635{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001636{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001637{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001638
Jason Samsd19f10d2009-05-22 14:03:28 -07001639};
1640
1641static int registerFuncs(JNIEnv *_env)
1642{
1643 return android::AndroidRuntime::registerNativeMethods(
1644 _env, classPathName, methods, NELEM(methods));
1645}
1646
1647// ---------------------------------------------------------------------------
1648
1649jint JNI_OnLoad(JavaVM* vm, void* reserved)
1650{
1651 JNIEnv* env = NULL;
1652 jint result = -1;
1653
Jason Samsd19f10d2009-05-22 14:03:28 -07001654 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001655 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001656 goto bail;
1657 }
1658 assert(env != NULL);
1659
1660 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001661 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001662 goto bail;
1663 }
1664
1665 /* success -- return valid version number */
1666 result = JNI_VERSION_1_4;
1667
1668bail:
1669 return result;
1670}