blob: b56b92ea6e715c8e3b4d3a09e6afbaac6f0d2d8f [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 Sams6fcf2e12013-11-06 11:22:02 -080053#define PER_ARRAY_TYPE(flag, fnc, ...) { \
54 jint len = 0; \
55 void *ptr = NULL; \
Jason Sams29868dfa2013-11-06 15:08:07 -080056 size_t typeBytes = 0; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080057 switch(dataType) { \
58 case RS_TYPE_FLOAT_32: \
59 len = _env->GetArrayLength((jfloatArray)data); \
60 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080061 typeBytes = 4; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080062 fnc(__VA_ARGS__); \
63 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, JNI_ABORT); \
64 return; \
65 case RS_TYPE_FLOAT_64: \
66 len = _env->GetArrayLength((jdoubleArray)data); \
67 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080068 typeBytes = 8; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080069 fnc(__VA_ARGS__); \
70 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, JNI_ABORT);\
71 return; \
72 case RS_TYPE_SIGNED_8: \
73 case RS_TYPE_UNSIGNED_8: \
74 len = _env->GetArrayLength((jbyteArray)data); \
75 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080076 typeBytes = 1; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080077 fnc(__VA_ARGS__); \
78 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, JNI_ABORT); \
79 return; \
80 case RS_TYPE_SIGNED_16: \
81 case RS_TYPE_UNSIGNED_16: \
82 len = _env->GetArrayLength((jshortArray)data); \
83 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080084 typeBytes = 2; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080085 fnc(__VA_ARGS__); \
86 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, JNI_ABORT); \
87 return; \
88 case RS_TYPE_SIGNED_32: \
89 case RS_TYPE_UNSIGNED_32: \
90 len = _env->GetArrayLength((jintArray)data); \
91 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080092 typeBytes = 4; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080093 fnc(__VA_ARGS__); \
94 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, JNI_ABORT); \
95 return; \
96 case RS_TYPE_SIGNED_64: \
97 case RS_TYPE_UNSIGNED_64: \
98 len = _env->GetArrayLength((jlongArray)data); \
99 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -0800100 typeBytes = 8; \
Jason Sams6fcf2e12013-11-06 11:22:02 -0800101 fnc(__VA_ARGS__); \
102 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, JNI_ABORT); \
103 return; \
104 default: \
105 break; \
106 } \
107}
108
109
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800110class AutoJavaStringToUTF8 {
111public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800112 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800113 fCStr = env->GetStringUTFChars(str, NULL);
114 fLength = env->GetStringUTFLength(str);
115 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800116 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800117 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
118 }
119 const char* c_str() const { return fCStr; }
120 jsize length() const { return fLength; }
121
122private:
123 JNIEnv* fEnv;
124 jstring fJStr;
125 const char* fCStr;
126 jsize fLength;
127};
128
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800129class AutoJavaStringArrayToUTF8 {
130public:
131 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
132 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
133 mCStrings = NULL;
134 mSizeArray = NULL;
135 if (stringsLength > 0) {
136 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
137 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
138 for (jsize ct = 0; ct < stringsLength; ct ++) {
139 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
140 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
141 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
142 }
143 }
144 }
145 ~AutoJavaStringArrayToUTF8() {
146 for (jsize ct=0; ct < mStringsLength; ct++) {
147 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
148 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
149 }
150 free(mCStrings);
151 free(mSizeArray);
152 }
153 const char **c_str() const { return mCStrings; }
154 size_t *c_str_len() const { return mSizeArray; }
155 jsize length() const { return mStringsLength; }
156
157private:
158 JNIEnv *mEnv;
159 jobjectArray mStrings;
160 const char **mCStrings;
161 size_t *mSizeArray;
162 jsize mStringsLength;
163};
164
Jason Samsd19f10d2009-05-22 14:03:28 -0700165// ---------------------------------------------------------------------------
166
Jason Samsffe9f482009-06-01 17:45:53 -0700167static jfieldID gContextId = 0;
168static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700169static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700170
171static void _nInit(JNIEnv *_env, jclass _this)
172{
Jason Samsd19f10d2009-05-22 14:03:28 -0700173 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700174
175 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhata0398432014-01-20 20:08:01 +0000176 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700177}
178
Jason Samsd19f10d2009-05-22 14:03:28 -0700179// ---------------------------------------------------------------------------
180
Jason Sams3eaa338e2009-06-10 15:04:38 -0700181static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700182nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700183{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700184 LOG_API("nContextFinish, con(%p)", con);
185 rsContextFinish(con);
186}
187
188static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700189nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700190{
Jason Sams07ae4062009-08-27 20:23:34 -0700191 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700192 jint len = _env->GetArrayLength(str);
193 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700194 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700195 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
196}
197
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700198static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700199nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700200{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700201 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700202 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700203 rsaGetName(con, (void *)obj, &name);
204 if(name == NULL || strlen(name) == 0) {
205 return NULL;
206 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700207 return _env->NewStringUTF(name);
208}
209
Jason Sams7ce033d2009-08-18 14:14:24 -0700210static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700211nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700212{
Jason Sams7ce033d2009-08-18 14:14:24 -0700213 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700214 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700215}
216
Jason Sams3eaa338e2009-06-10 15:04:38 -0700217// ---------------------------------------------------------------------------
218
Jason Samsd19f10d2009-05-22 14:03:28 -0700219static jint
220nDeviceCreate(JNIEnv *_env, jobject _this)
221{
222 LOG_API("nDeviceCreate");
223 return (jint)rsDeviceCreate();
224}
225
226static void
227nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
228{
229 LOG_API("nDeviceDestroy");
230 return rsDeviceDestroy((RsDevice)dev);
231}
232
Jason Samsebfb4362009-09-23 13:57:02 -0700233static void
234nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
235{
236 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
237 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
238}
239
Jason Samsd19f10d2009-05-22 14:03:28 -0700240static jint
Jason Samsadd26dc2013-02-22 18:43:45 -0800241nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700242{
243 LOG_API("nContextCreate");
Tim Murray9578e642013-09-09 16:15:56 -0700244 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0);
Jason Sams704ff642010-02-09 16:05:07 -0800245}
246
247static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700248nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700249 int colorMin, int colorPref,
250 int alphaMin, int alphaPref,
251 int depthMin, int depthPref,
252 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700253 int samplesMin, int samplesPref, float samplesQ,
254 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800255{
Jason Sams11c8af92010-10-13 15:31:10 -0700256 RsSurfaceConfig sc;
257 sc.alphaMin = alphaMin;
258 sc.alphaPref = alphaPref;
259 sc.colorMin = colorMin;
260 sc.colorPref = colorPref;
261 sc.depthMin = depthMin;
262 sc.depthPref = depthPref;
263 sc.samplesMin = samplesMin;
264 sc.samplesPref = samplesPref;
265 sc.samplesQ = samplesQ;
266
Jason Sams704ff642010-02-09 16:05:07 -0800267 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700268 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700269}
270
271static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700272nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800273{
Jason Sams7d787b42009-11-15 12:14:26 -0800274 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
275 rsContextSetPriority(con, p);
276}
277
278
279
280static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700281nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800282{
Jason Sams3bc47d42009-11-12 15:10:25 -0800283 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800284
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700285 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800286 if (wnd == NULL) {
287
288 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700289 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800290 }
291
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700292 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800293}
294
295static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700296nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700297{
Jason Sams2e1872f2010-08-17 16:25:41 -0700298 LOG_API("nContextDestroy, con(%p)", con);
299 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700300}
301
Jason Sams715333b2009-11-17 17:26:46 -0800302static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700303nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800304{
Jason Sams715333b2009-11-17 17:26:46 -0800305 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
306 rsContextDump((RsContext)con, bits);
307}
Jason Samsd19f10d2009-05-22 14:03:28 -0700308
309static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700310nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700311{
Jason Sams65e7aa52009-09-24 17:38:20 -0700312 LOG_API("nContextPause, con(%p)", con);
313 rsContextPause(con);
314}
315
316static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700317nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700318{
Jason Sams65e7aa52009-09-24 17:38:20 -0700319 LOG_API("nContextResume, con(%p)", con);
320 rsContextResume(con);
321}
322
Jason Sams1c415172010-11-08 17:06:46 -0800323
324static jstring
325nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
326{
327 LOG_API("nContextGetErrorMessage, con(%p)", con);
328 char buf[1024];
329
330 size_t receiveLen;
331 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700332 int id = rsContextGetMessage(con,
333 buf, sizeof(buf),
334 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700335 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800336 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100337 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800338 }
339 return _env->NewStringUTF(buf);
340}
341
Jason Samsedbfabd2011-05-17 15:01:29 -0700342static jint
Jason Sams1c415172010-11-08 17:06:46 -0800343nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700344{
Jason Sams516c3192009-10-06 13:58:47 -0700345 jint len = _env->GetArrayLength(data);
346 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
347 jint *ptr = _env->GetIntArrayElements(data, NULL);
348 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800349 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700350 int id = rsContextGetMessage(con,
351 ptr, len * 4,
352 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700353 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700354 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100355 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700356 }
357 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700358 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800359}
360
361static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700362nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800363{
364 LOG_API("nContextPeekMessage, con(%p)", con);
365 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
366 size_t receiveLen;
367 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700368 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700369 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800370 auxDataPtr[0] = (jint)subID;
371 auxDataPtr[1] = (jint)receiveLen;
372 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700373 return id;
374}
375
Jason Sams2e1872f2010-08-17 16:25:41 -0700376static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700377{
Jason Sams516c3192009-10-06 13:58:47 -0700378 LOG_API("nContextInitToClient, con(%p)", con);
379 rsContextInitToClient(con);
380}
381
Jason Sams2e1872f2010-08-17 16:25:41 -0700382static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700383{
Jason Sams516c3192009-10-06 13:58:47 -0700384 LOG_API("nContextDeinitToClient, con(%p)", con);
385 rsContextDeinitToClient(con);
386}
387
Jason Sams455d6442013-02-05 19:20:18 -0800388static void
389nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data)
390{
391 jint *ptr = NULL;
392 jint len = 0;
393 if (data) {
394 len = _env->GetArrayLength(data);
Stephen Hines57cf5602013-12-18 16:21:30 -0800395 ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams455d6442013-02-05 19:20:18 -0800396 }
397 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len);
398 rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int));
399 if (data) {
400 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
401 }
402}
403
404
Jason Sams516c3192009-10-06 13:58:47 -0700405
Jason Sams718cd1f2009-12-23 14:35:29 -0800406static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700407nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700408{
Jason Sams718cd1f2009-12-23 14:35:29 -0800409 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
410 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700411}
412
413static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800414nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
415 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700416{
Jason Sams718cd1f2009-12-23 14:35:29 -0800417 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800418 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800419
420 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700421 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800422
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800423 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
424
425 const char **nameArray = names.c_str();
426 size_t *sizeArray = names.c_str_len();
427
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700428 jint id = (jint)rsElementCreate2(con,
429 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700430 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700431 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800432
Jason Sams718cd1f2009-12-23 14:35:29 -0800433 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700434 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800435 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700436}
437
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700438static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700439nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700440{
441 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700442 LOG_API("nElementGetNativeData, con(%p)", con);
443
444 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
445 assert(dataSize == 5);
446
447 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700448 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700449
450 for(jint i = 0; i < dataSize; i ++) {
451 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
452 }
453}
454
455
456static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700457nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
458 jintArray _IDs,
459 jobjectArray _names,
460 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700461{
462 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700463 LOG_API("nElementGetSubElements, con(%p)", con);
464
465 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
466 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700467 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700468
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700469 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700470
Jason Sams11c8af92010-10-13 15:31:10 -0700471 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700472 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
473 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700474 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700475 }
476
477 free(ids);
478 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700479 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700480}
481
Jason Samsd19f10d2009-05-22 14:03:28 -0700482// -----------------------------------
483
Jason Sams3b9c52a2010-10-14 17:48:46 -0700484static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800485nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800486 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700487{
Jason Samsb109cc72013-01-07 18:20:12 -0800488 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
489 con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700490
Jason Samsb109cc72013-01-07 18:20:12 -0800491 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700492 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700493}
494
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700495static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700496nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700497{
498 // We are packing 6 items: mDimX; mDimY; mDimZ;
499 // mDimLOD; mDimFaces; mElement; into typeData
500 int elementCount = _env->GetArrayLength(_typeData);
501
502 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700503 LOG_API("nTypeCreate, con(%p)", con);
504
505 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700506 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700507
508 for(jint i = 0; i < elementCount; i ++) {
509 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
510 }
511}
512
Jason Samsd19f10d2009-05-22 14:03:28 -0700513// -----------------------------------
514
515static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800516nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700517{
Jason Sams857d0c72011-11-23 15:02:15 -0800518 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
519 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700520}
521
Jason Samsd19f10d2009-05-22 14:03:28 -0700522static void
Jason Sams5476b452010-12-08 16:14:36 -0800523nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
524{
525 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
526 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
527}
528
Jason Sams72226e02013-02-22 12:45:54 -0800529static jobject
530nAllocationGetSurface(JNIEnv *_env, jobject _this, RsContext con, jint a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800531{
Jason Sams72226e02013-02-22 12:45:54 -0800532 LOG_API("nAllocationGetSurface, con(%p), a(%p)", con, (RsAllocation)a);
Jason Sams615e7ce2012-01-13 14:01:20 -0800533
Jason Sams72226e02013-02-22 12:45:54 -0800534 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface(con, (RsAllocation)a);
535 sp<IGraphicBufferProducer> bp = v;
536 v->decStrong(NULL);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700537
Jason Sams72226e02013-02-22 12:45:54 -0800538 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
539 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700540}
541
542static void
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700543nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800544{
Stephen Hines06883b72012-05-16 18:01:34 -0700545 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Jason Sams163766c2012-02-15 12:04:24 -0800546 con, alloc, (Surface *)sur);
547
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700548 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800549 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700550 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800551 }
552
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700553 rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800554}
555
556static void
557nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
558{
559 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
560 rsAllocationIoSend(con, alloc);
561}
562
563static void
564nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
565{
566 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
567 rsAllocationIoReceive(con, alloc);
568}
569
570
571static void
Jason Samsf7086092011-01-12 13:28:37 -0800572nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
573{
574 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
575 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
576}
577
Jason Samsffe9f482009-06-01 17:45:53 -0700578static int
Jason Sams5476b452010-12-08 16:14:36 -0800579nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700580{
Jason Samsffe9f482009-06-01 17:45:53 -0700581 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000582 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700583 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700584
Jason Sams5476b452010-12-08 16:14:36 -0800585 bitmap.lockPixels();
586 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700587 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700588 (RsType)type, (RsAllocationMipmapControl)mip,
589 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800590 bitmap.unlockPixels();
591 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700592}
Jason Samsfe08d992009-05-27 14:45:32 -0700593
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800594static int
Tim Murraya3145512012-12-04 17:59:29 -0800595nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
596{
597 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000598 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800599 const SkBitmap& bitmap(*nativeBitmap);
600
601 bitmap.lockPixels();
602 const void* ptr = bitmap.getPixels();
603 jint id = (jint)rsAllocationCreateTyped(con,
604 (RsType)type, (RsAllocationMipmapControl)mip,
605 (uint32_t)usage, (size_t)ptr);
606 bitmap.unlockPixels();
607 return id;
608}
609
610static int
Jason Sams5476b452010-12-08 16:14:36 -0800611nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800612{
613 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000614 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800615 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800616
Jason Sams5476b452010-12-08 16:14:36 -0800617 bitmap.lockPixels();
618 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700619 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700620 (RsType)type, (RsAllocationMipmapControl)mip,
621 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800622 bitmap.unlockPixels();
623 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800624}
625
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700626static void
Jason Sams4ef66502010-12-10 16:03:15 -0800627nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700628{
629 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000630 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700631 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800632 int w = bitmap.width();
633 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700634
Jason Sams4ef66502010-12-10 16:03:15 -0800635 bitmap.lockPixels();
636 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800637 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700638 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800639 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800640 bitmap.unlockPixels();
641}
642
643static void
644nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
645{
646 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000647 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800648 const SkBitmap& bitmap(*nativeBitmap);
649
650 bitmap.lockPixels();
651 void* ptr = bitmap.getPixels();
652 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
653 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700654 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700655}
656
Jason Sams8a647432010-03-01 15:31:04 -0800657static void ReleaseBitmapCallback(void *bmp)
658{
659 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
660 nativeBitmap->unlockPixels();
661}
662
Romain Guy650a3eb2009-08-31 14:06:43 -0700663
Jason Samsd19f10d2009-05-22 14:03:28 -0700664static void
Jason Sams6fcf2e12013-11-06 11:22:02 -0800665nAllocationData1D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint offset, jint lod,
666 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700667{
Jason Sams6fcf2e12013-11-06 11:22:02 -0800668 RsAllocation *alloc = (RsAllocation *)_alloc;
669 LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i), dataType(%i)",
670 con, alloc, offset, count, len, sizeBytes, dataType);
671 PER_ARRAY_TYPE(NULL, rsAllocation1DData, con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700672}
673
674static void
Jason Sams49a05d72010-12-29 14:31:29 -0800675// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
676nAllocationElementData1D(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 -0700677{
678 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800679 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 -0700680 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800681 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700682 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
683}
684
685static void
Jason Sams6fcf2e12013-11-06 11:22:02 -0800686nAllocationData2D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint xoff, jint yoff, jint lod, jint _face,
687 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800688{
Jason Sams6fcf2e12013-11-06 11:22:02 -0800689 RsAllocation *alloc = (RsAllocation *)_alloc;
690 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
691 LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
692 con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
693 PER_ARRAY_TYPE(NULL, rsAllocation2DData, con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700694}
695
Jason Sams40a29e82009-08-10 14:55:26 -0700696static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700697nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
698 jint dstAlloc, jint dstXoff, jint dstYoff,
699 jint dstMip, jint dstFace,
700 jint width, jint height,
701 jint srcAlloc, jint srcXoff, jint srcYoff,
702 jint srcMip, jint srcFace)
703{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800704 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700705 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
706 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
707 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
708 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
709
710 rsAllocationCopy2DRange(con,
711 (RsAllocation)dstAlloc,
712 dstXoff, dstYoff,
713 dstMip, dstFace,
714 width, height,
715 (RsAllocation)srcAlloc,
716 srcXoff, srcYoff,
717 srcMip, srcFace);
718}
719
720static void
Jason Sams6fcf2e12013-11-06 11:22:02 -0800721nAllocationData3D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint xoff, jint yoff, jint zoff, jint lod,
722 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700723{
Jason Sams6fcf2e12013-11-06 11:22:02 -0800724 RsAllocation *alloc = (RsAllocation *)_alloc;
725 LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)",
726 con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes);
727 PER_ARRAY_TYPE(NULL, rsAllocation3DData, con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -0700728}
729
730static void
731nAllocationData3D_alloc(JNIEnv *_env, jobject _this, RsContext con,
732 jint dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
733 jint dstMip,
734 jint width, jint height, jint depth,
735 jint srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
736 jint srcMip)
737{
738 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
739 " dstMip(%i), width(%i), height(%i),"
740 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
741 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
742 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
743
744 rsAllocationCopy3DRange(con,
745 (RsAllocation)dstAlloc,
746 dstXoff, dstYoff, dstZoff, dstMip,
747 width, height, depth,
748 (RsAllocation)srcAlloc,
749 srcXoff, srcYoff, srcZoff, srcMip);
750}
751
Jason Sams29868dfa2013-11-06 15:08:07 -0800752
Jason Samsb05d6892013-04-09 15:59:24 -0700753static void
Jason Sams29868dfa2013-11-06 15:08:07 -0800754nAllocationRead(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700755{
Jason Sams29868dfa2013-11-06 15:08:07 -0800756 RsAllocation *alloc = (RsAllocation *)_alloc;
757 LOG_API("nAllocationRead, con(%p), alloc(%p)", con, (RsAllocation)alloc);
758 PER_ARRAY_TYPE(0, rsAllocationRead, con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700759}
760
761static void
Jason Sams29868dfa2013-11-06 15:08:07 -0800762nAllocationRead1D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint offset, jint lod,
763 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800764{
Jason Sams29868dfa2013-11-06 15:08:07 -0800765 RsAllocation *alloc = (RsAllocation *)_alloc;
766 LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i), dataType(%i)",
767 con, alloc, offset, count, len, sizeBytes, dataType);
768 PER_ARRAY_TYPE(0, rsAllocation1DRead, con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800769}
770
771static void
Jason Sams29868dfa2013-11-06 15:08:07 -0800772nAllocationRead2D(JNIEnv *_env, jobject _this, RsContext con, jint _alloc, jint xoff, jint yoff, jint lod, jint _face,
773 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800774{
Jason Sams29868dfa2013-11-06 15:08:07 -0800775 RsAllocation *alloc = (RsAllocation *)_alloc;
776 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
777 LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
778 con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
779 PER_ARRAY_TYPE(0, rsAllocation2DRead, con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700780}
Jason Samsd19f10d2009-05-22 14:03:28 -0700781
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700782static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700783nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700784{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700785 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700786 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700787}
788
Jason Sams5edc6082010-10-05 13:32:49 -0700789static void
790nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
791{
792 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
793 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
794}
795
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700796// -----------------------------------
797
798static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700799nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700800{
Steve Block71f2cf12011-10-20 11:56:00 +0100801 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700802
803 Asset* asset = reinterpret_cast<Asset*>(native_asset);
804
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800805 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
806 return id;
807}
808
809static int
810nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
811{
812 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
813 if (mgr == NULL) {
814 return 0;
815 }
816
817 AutoJavaStringToUTF8 str(_env, _path);
818 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
819 if (asset == NULL) {
820 return 0;
821 }
822
823 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
824 return id;
825}
826
827static int
828nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
829{
830 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
831 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
832
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700833 return id;
834}
835
836static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700837nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700838{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700839 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700840 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700841 return numEntries;
842}
843
844static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700845nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700846{
Steve Block71f2cf12011-10-20 11:56:00 +0100847 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700848 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
849
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700850 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700851
852 for(jint i = 0; i < numEntries; i ++) {
853 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
854 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
855 }
856
857 free(fileEntries);
858}
859
860static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700861nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700862{
Steve Block71f2cf12011-10-20 11:56:00 +0100863 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700864 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700865 return id;
866}
Jason Samsd19f10d2009-05-22 14:03:28 -0700867
868// -----------------------------------
869
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700870static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800871nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
872 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700873{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800874 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700875 jint id = (jint)rsFontCreateFromFile(con,
876 fileNameUTF.c_str(), fileNameUTF.length(),
877 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700878
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800879 return id;
880}
881
882static int
883nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
884 jstring name, jfloat fontSize, jint dpi, jint native_asset)
885{
886 Asset* asset = reinterpret_cast<Asset*>(native_asset);
887 AutoJavaStringToUTF8 nameUTF(_env, name);
888
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700889 jint id = (jint)rsFontCreateFromMemory(con,
890 nameUTF.c_str(), nameUTF.length(),
891 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800892 asset->getBuffer(false), asset->getLength());
893 return id;
894}
895
896static int
897nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
898 jfloat fontSize, jint dpi)
899{
900 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
901 if (mgr == NULL) {
902 return 0;
903 }
904
905 AutoJavaStringToUTF8 str(_env, _path);
906 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
907 if (asset == NULL) {
908 return 0;
909 }
910
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700911 jint id = (jint)rsFontCreateFromMemory(con,
912 str.c_str(), str.length(),
913 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800914 asset->getBuffer(false), asset->getLength());
915 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700916 return id;
917}
918
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700919// -----------------------------------
920
921static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700922nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700923{
Jason Samsd19f10d2009-05-22 14:03:28 -0700924 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700925 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700926}
927
928static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700929nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700930{
Jason Samscfc04362010-09-14 14:59:03 -0700931 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700932 rsScriptSetVarI(con, (RsScript)script, slot, val);
933}
934
Tim Murray7c4caad2013-04-10 16:21:40 -0700935static jint
936nScriptGetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
937{
938 LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
939 int value = 0;
940 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
941 return value;
942}
943
Jason Sams4d339932010-05-11 14:03:58 -0700944static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800945nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
946{
947 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
948 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
949}
950
951static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700952nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
953{
954 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
955 rsScriptSetVarJ(con, (RsScript)script, slot, val);
956}
957
Tim Murray7c4caad2013-04-10 16:21:40 -0700958static jlong
959nScriptGetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
960{
961 LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
962 jlong value = 0;
963 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
964 return value;
965}
966
Stephen Hines031ec58c2010-10-11 10:54:21 -0700967static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700968nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700969{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700970 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700971 rsScriptSetVarF(con, (RsScript)script, slot, val);
972}
973
Tim Murray7c4caad2013-04-10 16:21:40 -0700974static jfloat
975nScriptGetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
976{
977 LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
978 jfloat value = 0;
979 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
980 return value;
981}
982
Jason Sams4d339932010-05-11 14:03:58 -0700983static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700984nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
985{
986 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
987 rsScriptSetVarD(con, (RsScript)script, slot, val);
988}
989
Tim Murray7c4caad2013-04-10 16:21:40 -0700990static jdouble
991nScriptGetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
992{
993 LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
994 jdouble value = 0;
995 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
996 return value;
997}
998
Stephen Hinesca54ec32010-09-20 17:20:30 -0700999static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001000nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001001{
Jason Sams4d339932010-05-11 14:03:58 -07001002 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1003 jint len = _env->GetArrayLength(data);
1004 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1005 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
1006 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1007}
1008
Stephen Hinesadeb8092012-04-20 14:26:06 -07001009static void
Tim Murray7c4caad2013-04-10 16:21:40 -07001010nScriptGetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
1011{
1012 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1013 jint len = _env->GetArrayLength(data);
1014 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1015 rsScriptGetVarV(con, (RsScript)script, slot, ptr, len);
1016 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1017}
1018
1019static void
Stephen Hinesadeb8092012-04-20 14:26:06 -07001020nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
1021{
1022 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1023 jint len = _env->GetArrayLength(data);
1024 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1025 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
1026 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
1027 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
1028 (const size_t*) dimsPtr, dimsLen);
1029 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1030 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1031}
1032
Jason Samsd19f10d2009-05-22 14:03:28 -07001033
1034static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001035nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001036{
Jason Sams07ae4062009-08-27 20:23:34 -07001037 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -07001038
1039 jint length = _env->GetArrayLength(timeZone);
1040 jbyte* timeZone_ptr;
1041 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1042
Jason Samsbc948de2009-08-17 18:35:48 -07001043 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001044
1045 if (timeZone_ptr) {
1046 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1047 }
1048}
1049
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001050static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001051nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001052{
Jason Samsbe2e8412009-09-16 15:04:38 -07001053 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
1054 rsScriptInvoke(con, (RsScript)obj, slot);
1055}
1056
1057static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001058nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001059{
Jason Sams4d339932010-05-11 14:03:58 -07001060 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1061 jint len = _env->GetArrayLength(data);
1062 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1063 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
1064 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1065}
1066
Jason Sams6e494d32011-04-27 16:33:11 -07001067static void
1068nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
1069 jint script, jint slot, jint ain, jint aout)
1070{
1071 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001072 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001073}
1074static void
1075nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1076 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1077{
1078 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1079 jint len = _env->GetArrayLength(params);
1080 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001081 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001082 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1083}
1084
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001085static void
1086nScriptForEachClipped(JNIEnv *_env, jobject _this, RsContext con,
1087 jint script, jint slot, jint ain, jint aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001088 jint xstart, jint xend,
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001089 jint ystart, jint yend, jint zstart, jint zend)
1090{
1091 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001092 RsScriptCall sc;
1093 sc.xStart = xstart;
1094 sc.xEnd = xend;
1095 sc.yStart = ystart;
1096 sc.yEnd = yend;
1097 sc.zStart = zstart;
1098 sc.zEnd = zend;
1099 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1100 sc.arrayStart = 0;
1101 sc.arrayEnd = 0;
1102 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
1103}
1104
1105static void
1106nScriptForEachClippedV(JNIEnv *_env, jobject _this, RsContext con,
1107 jint script, jint slot, jint ain, jint aout,
1108 jbyteArray params, jint xstart, jint xend,
1109 jint ystart, jint yend, jint zstart, jint zend)
1110{
1111 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001112 jint len = _env->GetArrayLength(params);
1113 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1114 RsScriptCall sc;
1115 sc.xStart = xstart;
1116 sc.xEnd = xend;
1117 sc.yStart = ystart;
1118 sc.yEnd = yend;
1119 sc.zStart = zstart;
1120 sc.zEnd = zend;
1121 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1122 sc.arrayStart = 0;
1123 sc.arrayEnd = 0;
1124 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc));
1125 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1126}
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001127
Jason Sams22534172009-08-04 16:58:20 -07001128// -----------------------------------
1129
Jason Samse4a06c52011-03-16 16:29:28 -07001130static jint
1131nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1132 jstring resName, jstring cacheDir,
1133 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001134{
Jason Samse4a06c52011-03-16 16:29:28 -07001135 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001136
Jason Samse4a06c52011-03-16 16:29:28 -07001137 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1138 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1139 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001140 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001141 jint _exception = 0;
1142 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001143 if (!scriptRef) {
1144 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001145 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001146 goto exit;
1147 }
Jack Palevich43702d82009-05-28 13:38:16 -07001148 if (length < 0) {
1149 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001150 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001151 goto exit;
1152 }
Jason Samse4a06c52011-03-16 16:29:28 -07001153 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001154 if (remaining < length) {
1155 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001156 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1157 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001158 goto exit;
1159 }
Jason Samse4a06c52011-03-16 16:29:28 -07001160 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001161 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001162
Jason Samse4a06c52011-03-16 16:29:28 -07001163 //rsScriptCSetText(con, (const char *)script_ptr, length);
1164
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001165 ret = (jint)rsScriptCCreate(con,
1166 resNameUTF.c_str(), resNameUTF.length(),
1167 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001168 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001169
Jack Palevich43702d82009-05-28 13:38:16 -07001170exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001171 if (script_ptr) {
1172 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001173 _exception ? JNI_ABORT: 0);
1174 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001175
Jason Samse4a06c52011-03-16 16:29:28 -07001176 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001177}
1178
Jason Sams6ab97682012-08-10 12:09:43 -07001179static jint
1180nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid)
1181{
1182 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid);
1183 return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid);
1184}
1185
Jason Sams08a81582012-09-18 12:32:10 -07001186static jint
1187nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig)
1188{
1189 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig);
1190 return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig);
1191}
1192
1193static jint
1194nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot)
1195{
1196 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot);
1197 return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot);
1198}
1199
1200static jint
1201nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src,
1202 jintArray _dstk, jintArray _dstf, jintArray _types)
1203{
1204 LOG_API("nScriptGroupCreate, con(%p)", con);
1205
1206 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int);
1207 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL);
1208 jint srcLen = _env->GetArrayLength(_src) * sizeof(int);
1209 jint *srcPtr = _env->GetIntArrayElements(_src, NULL);
1210 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int);
1211 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL);
1212 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int);
1213 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL);
1214 jint typesLen = _env->GetArrayLength(_types) * sizeof(int);
1215 jint *typesPtr = _env->GetIntArrayElements(_types, NULL);
1216
1217 int id = (int)rsScriptGroupCreate(con,
1218 (RsScriptKernelID *)kernelsPtr, kernelsLen,
1219 (RsScriptKernelID *)srcPtr, srcLen,
1220 (RsScriptKernelID *)dstkPtr, dstkLen,
1221 (RsScriptFieldID *)dstfPtr, dstfLen,
1222 (RsType *)typesPtr, typesLen);
1223
1224 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0);
1225 _env->ReleaseIntArrayElements(_src, srcPtr, 0);
1226 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0);
1227 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0);
1228 _env->ReleaseIntArrayElements(_types, typesPtr, 0);
1229 return id;
1230}
1231
1232static void
1233nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1234{
1235 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1236 (void *)gid, (void *)kid, (void *)alloc);
1237 rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1238}
1239
1240static void
1241nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1242{
1243 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1244 (void *)gid, (void *)kid, (void *)alloc);
1245 rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1246}
1247
1248static void
1249nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid)
1250{
1251 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid);
1252 rsScriptGroupExecute(con, (RsScriptGroup)gid);
1253}
1254
Jason Samsd19f10d2009-05-22 14:03:28 -07001255// ---------------------------------------------------------------------------
1256
Jason Samsd19f10d2009-05-22 14:03:28 -07001257static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001258nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1259 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1260 jboolean depthMask, jboolean ditherEnable,
1261 jint srcFunc, jint destFunc,
1262 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001263{
Jason Sams54db59c2010-05-13 18:30:11 -07001264 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001265 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1266 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1267 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001268}
1269
Jason Sams0011bcf2009-12-15 12:58:36 -08001270// ---------------------------------------------------------------------------
1271
1272static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001273nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001274{
Jason Sams0011bcf2009-12-15 12:58:36 -08001275 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1276 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1277}
Jason Sams54c0ec12009-11-30 14:49:55 -08001278
Jason Sams68afd012009-12-17 16:55:08 -08001279static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001280nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001281{
Jason Sams68afd012009-12-17 16:55:08 -08001282 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1283 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1284}
1285
1286static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001287nProgramBindSampler(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("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1290 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1291}
1292
Jason Samsd19f10d2009-05-22 14:03:28 -07001293// ---------------------------------------------------------------------------
1294
Jason Samsd19f10d2009-05-22 14:03:28 -07001295static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001296nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1297 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001298{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001299 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001300 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1301 jint paramLen = _env->GetArrayLength(params);
1302
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001303 int texCount = _env->GetArrayLength(texNames);
1304 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1305 const char ** nameArray = names.c_str();
1306 size_t* sizeArray = names.c_str_len();
1307
Jason Sams991040c2011-01-17 15:59:39 -08001308 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001309
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001310 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1311 nameArray, texCount, sizeArray,
1312 (uint32_t *)paramPtr, paramLen);
1313
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001314 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1315 return ret;
1316}
1317
1318
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001319// ---------------------------------------------------------------------------
1320
Jason Sams0011bcf2009-12-15 12:58:36 -08001321static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001322nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1323 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001324{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001325 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001326 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1327 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001328
Jason Sams991040c2011-01-17 15:59:39 -08001329 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001330
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001331 int texCount = _env->GetArrayLength(texNames);
1332 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1333 const char ** nameArray = names.c_str();
1334 size_t* sizeArray = names.c_str_len();
1335
1336 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1337 nameArray, texCount, sizeArray,
1338 (uint32_t *)paramPtr, paramLen);
1339
Jason Sams0011bcf2009-12-15 12:58:36 -08001340 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1341 return ret;
1342}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001343
Jason Samsebfb4362009-09-23 13:57:02 -07001344// ---------------------------------------------------------------------------
1345
1346static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001347nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001348{
Jason Sams94aaed32011-09-23 14:18:53 -07001349 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1350 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001351}
1352
Jason Samsd19f10d2009-05-22 14:03:28 -07001353
1354// ---------------------------------------------------------------------------
1355
1356static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001357nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001358{
Jason Samsd19f10d2009-05-22 14:03:28 -07001359 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001360 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001361}
1362
1363static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001364nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001365{
Jason Sams54db59c2010-05-13 18:30:11 -07001366 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1367 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001368}
1369
1370static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001371nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001372{
Jason Samsd19f10d2009-05-22 14:03:28 -07001373 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001374 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001375}
1376
Jason Sams0826a6f2009-06-15 19:04:56 -07001377static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001378nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001379{
Jason Sams0826a6f2009-06-15 19:04:56 -07001380 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001381 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001382}
1383
Joe Onoratod7b37742009-08-09 22:57:44 -07001384static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001385nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001386{
Jason Samsebfb4362009-09-23 13:57:02 -07001387 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1388 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1389}
1390
Joe Onoratod7b37742009-08-09 22:57:44 -07001391
Jason Sams02fb2cb2009-05-28 15:37:57 -07001392// ---------------------------------------------------------------------------
1393
Jason Sams02fb2cb2009-05-28 15:37:57 -07001394static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001395nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1396 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001397{
Jason Samsbba134c2009-06-22 15:49:21 -07001398 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001399 return (jint)rsSamplerCreate(con,
1400 (RsSamplerValue)magFilter,
1401 (RsSamplerValue)minFilter,
1402 (RsSamplerValue)wrapS,
1403 (RsSamplerValue)wrapT,
1404 (RsSamplerValue)wrapR,
1405 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001406}
1407
Jason Samsbba134c2009-06-22 15:49:21 -07001408// ---------------------------------------------------------------------------
1409
Jason Samsf15ed012011-10-31 13:23:43 -07001410//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1411static jint
1412nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1413 LOG_API("nPathCreate, con(%p)", con);
1414
1415 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1416 (RsAllocation)_vtx,
1417 (RsAllocation)_loop, q);
1418 return id;
1419}
1420
Jason Samsbba134c2009-06-22 15:49:21 -07001421static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001422nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001423{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001424 LOG_API("nMeshCreate, con(%p)", con);
1425
1426 jint vtxLen = _env->GetArrayLength(_vtx);
1427 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1428 jint idxLen = _env->GetArrayLength(_idx);
1429 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1430 jint primLen = _env->GetArrayLength(_prim);
1431 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1432
1433 int id = (int)rsMeshCreate(con,
1434 (RsAllocation *)vtxPtr, vtxLen,
1435 (RsAllocation *)idxPtr, idxLen,
1436 (uint32_t *)primPtr, primLen);
1437
1438 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1439 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1440 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001441 return id;
1442}
1443
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001444static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001445nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001446{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001447 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1448 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001449 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001450 return vtxCount;
1451}
1452
1453static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001454nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001455{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001456 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1457 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001458 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001459 return idxCount;
1460}
1461
1462static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001463nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001464{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001465 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1466
1467 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001468 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001469
1470 for(jint i = 0; i < numVtxIDs; i ++) {
1471 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1472 }
1473
1474 free(allocs);
1475}
1476
1477static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001478nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001479{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001480 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1481
1482 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1483 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1484
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001485 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001486
1487 for(jint i = 0; i < numIndices; i ++) {
1488 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1489 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1490 }
1491
1492 free(allocs);
1493 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001494}
1495
1496// ---------------------------------------------------------------------------
1497
Jason Samsd19f10d2009-05-22 14:03:28 -07001498
Jason Sams94d8e90a2009-06-10 16:09:05 -07001499static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001500
1501static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001502{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001503
Jason Sams1c415172010-11-08 17:06:46 -08001504{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1505{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1506{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001507{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001508{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001509{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001510
1511{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1512{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001513
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001514
Jason Sams2e1872f2010-08-17 16:25:41 -07001515// All methods below are thread protected in java.
Jason Samsadd26dc2013-02-22 18:43:45 -08001516{"rsnContextCreate", "(IIII)I", (void*)nContextCreate },
Stephen Hines4382467a2011-08-01 15:02:34 -07001517{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001518{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1519{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1520{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001521{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001522{"rsnContextDump", "(II)V", (void*)nContextDump },
1523{"rsnContextPause", "(I)V", (void*)nContextPause },
1524{"rsnContextResume", "(I)V", (void*)nContextResume },
Jason Sams455d6442013-02-05 19:20:18 -08001525{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage },
Jason Sams2e1872f2010-08-17 16:25:41 -07001526{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001527{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001528{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001529
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001530{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001531{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001532{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001533{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001534{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001535{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001536
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001537{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001538{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1539{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001540
Jason Sams2e1872f2010-08-17 16:25:41 -07001541{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001542{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001543{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001544{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001545
Jason Samsb109cc72013-01-07 18:20:12 -08001546{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001547{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001548
Jason Sams857d0c72011-11-23 15:02:15 -08001549{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001550{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
Tim Murraya3145512012-12-04 17:59:29 -08001551{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation },
Jason Sams5476b452010-12-08 16:14:36 -08001552{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001553
Jason Sams4ef66502010-12-10 16:03:15 -08001554{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1555{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1556
Jason Sams5476b452010-12-08 16:14:36 -08001557{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams72226e02013-02-22 12:45:54 -08001558{"rsnAllocationGetSurface", "(II)Landroid/view/Surface;", (void*)nAllocationGetSurface },
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001559{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
Jason Sams163766c2012-02-15 12:04:24 -08001560{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1561{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams6fcf2e12013-11-06 11:22:02 -08001562{"rsnAllocationData1D", "(IIIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
Jason Sams49a05d72010-12-29 14:31:29 -08001563{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
Jason Sams6fcf2e12013-11-06 11:22:02 -08001564{"rsnAllocationData2D", "(IIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001565{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams6fcf2e12013-11-06 11:22:02 -08001566{"rsnAllocationData3D", "(IIIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
Jason Samsb05d6892013-04-09 15:59:24 -07001567{"rsnAllocationData3D", "(IIIIIIIIIIIIII)V", (void*)nAllocationData3D_alloc },
Jason Sams29868dfa2013-11-06 15:08:07 -08001568{"rsnAllocationRead", "(IILjava/lang/Object;I)V", (void*)nAllocationRead },
1569{"rsnAllocationRead1D", "(IIIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1570{"rsnAllocationRead2D", "(IIIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
Jason Sams2e1872f2010-08-17 16:25:41 -07001571{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001572{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
Jason Samsf7086092011-01-12 13:28:37 -08001573{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001574
Jason Sams2e1872f2010-08-17 16:25:41 -07001575{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1576{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1577{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1578{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001579{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1580{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001581{"rsnScriptForEachClipped", "(IIIIIIIIIII)V", (void*)nScriptForEachClipped },
1582{"rsnScriptForEachClipped", "(IIIII[BIIIIII)V", (void*)nScriptForEachClippedV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001583{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Tim Murray7c4caad2013-04-10 16:21:40 -07001584{"rsnScriptGetVarI", "(III)I", (void*)nScriptGetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001585{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Tim Murray7c4caad2013-04-10 16:21:40 -07001586{"rsnScriptGetVarJ", "(III)J", (void*)nScriptGetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001587{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Tim Murray7c4caad2013-04-10 16:21:40 -07001588{"rsnScriptGetVarF", "(III)F", (void*)nScriptGetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001589{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Tim Murray7c4caad2013-04-10 16:21:40 -07001590{"rsnScriptGetVarD", "(III)D", (void*)nScriptGetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001591{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Tim Murray7c4caad2013-04-10 16:21:40 -07001592{"rsnScriptGetVarV", "(III[B)V", (void*)nScriptGetVarV },
Stephen Hinesadeb8092012-04-20 14:26:06 -07001593{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001594{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001595
Jason Samse4a06c52011-03-16 16:29:28 -07001596{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams6ab97682012-08-10 12:09:43 -07001597{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate },
Jason Sams08a81582012-09-18 12:32:10 -07001598{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate },
1599{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate },
1600{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate },
1601{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput },
1602{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput },
1603{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001604
Jason Sams331bf9b2011-04-06 11:23:54 -07001605{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001606
Jason Sams2e1872f2010-08-17 16:25:41 -07001607{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1608{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1609{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001610
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001611{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001612{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001613{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001614
Jason Sams2e1872f2010-08-17 16:25:41 -07001615{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001616{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001617{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1618{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1619{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001620
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001621{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001622
Jason Samsf15ed012011-10-31 13:23:43 -07001623{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001624{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001625
1626{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1627{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001628{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001629{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001630
Jason Samsd19f10d2009-05-22 14:03:28 -07001631};
1632
1633static int registerFuncs(JNIEnv *_env)
1634{
1635 return android::AndroidRuntime::registerNativeMethods(
1636 _env, classPathName, methods, NELEM(methods));
1637}
1638
1639// ---------------------------------------------------------------------------
1640
1641jint JNI_OnLoad(JavaVM* vm, void* reserved)
1642{
1643 JNIEnv* env = NULL;
1644 jint result = -1;
1645
Jason Samsd19f10d2009-05-22 14:03:28 -07001646 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001647 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001648 goto bail;
1649 }
1650 assert(env != NULL);
1651
1652 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001653 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001654 goto bail;
1655 }
1656
1657 /* success -- return valid version number */
1658 result = JNI_VERSION_1_4;
1659
1660bail:
1661 return result;
1662}