blob: 7133a212c481fbec668f82af80acacfd8e20f4b2 [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
Stephen Hines414fa2c2014-04-17 01:02:42 -070053#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Sams6fcf2e12013-11-06 11:22:02 -080054 jint len = 0; \
55 void *ptr = NULL; \
Jason Sams29868dfa2013-11-06 15:08:07 -080056 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070057 jint relFlag = 0; \
58 if (readonly) { \
59 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
60 relFlag = JNI_ABORT; \
61 } \
Jason Sams6fcf2e12013-11-06 11:22:02 -080062 switch(dataType) { \
63 case RS_TYPE_FLOAT_32: \
64 len = _env->GetArrayLength((jfloatArray)data); \
65 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080066 typeBytes = 4; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080067 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070068 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Sams6fcf2e12013-11-06 11:22:02 -080069 return; \
70 case RS_TYPE_FLOAT_64: \
71 len = _env->GetArrayLength((jdoubleArray)data); \
72 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080073 typeBytes = 8; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080074 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070075 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Sams6fcf2e12013-11-06 11:22:02 -080076 return; \
77 case RS_TYPE_SIGNED_8: \
78 case RS_TYPE_UNSIGNED_8: \
79 len = _env->GetArrayLength((jbyteArray)data); \
80 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080081 typeBytes = 1; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080082 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070083 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Sams6fcf2e12013-11-06 11:22:02 -080084 return; \
85 case RS_TYPE_SIGNED_16: \
86 case RS_TYPE_UNSIGNED_16: \
87 len = _env->GetArrayLength((jshortArray)data); \
88 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080089 typeBytes = 2; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080090 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070091 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Sams6fcf2e12013-11-06 11:22:02 -080092 return; \
93 case RS_TYPE_SIGNED_32: \
94 case RS_TYPE_UNSIGNED_32: \
95 len = _env->GetArrayLength((jintArray)data); \
96 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -080097 typeBytes = 4; \
Jason Sams6fcf2e12013-11-06 11:22:02 -080098 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070099 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Sams6fcf2e12013-11-06 11:22:02 -0800100 return; \
101 case RS_TYPE_SIGNED_64: \
102 case RS_TYPE_UNSIGNED_64: \
103 len = _env->GetArrayLength((jlongArray)data); \
104 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams29868dfa2013-11-06 15:08:07 -0800105 typeBytes = 8; \
Jason Sams6fcf2e12013-11-06 11:22:02 -0800106 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700107 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Sams6fcf2e12013-11-06 11:22:02 -0800108 return; \
109 default: \
110 break; \
111 } \
112}
113
114
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800115class AutoJavaStringToUTF8 {
116public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800117 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800118 fCStr = env->GetStringUTFChars(str, NULL);
119 fLength = env->GetStringUTFLength(str);
120 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800121 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800122 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
123 }
124 const char* c_str() const { return fCStr; }
125 jsize length() const { return fLength; }
126
127private:
128 JNIEnv* fEnv;
129 jstring fJStr;
130 const char* fCStr;
131 jsize fLength;
132};
133
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800134class AutoJavaStringArrayToUTF8 {
135public:
136 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
137 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
138 mCStrings = NULL;
139 mSizeArray = NULL;
140 if (stringsLength > 0) {
141 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
142 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
143 for (jsize ct = 0; ct < stringsLength; ct ++) {
144 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
145 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
146 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
147 }
148 }
149 }
150 ~AutoJavaStringArrayToUTF8() {
151 for (jsize ct=0; ct < mStringsLength; ct++) {
152 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
153 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
154 }
155 free(mCStrings);
156 free(mSizeArray);
157 }
158 const char **c_str() const { return mCStrings; }
159 size_t *c_str_len() const { return mSizeArray; }
160 jsize length() const { return mStringsLength; }
161
162private:
163 JNIEnv *mEnv;
164 jobjectArray mStrings;
165 const char **mCStrings;
166 size_t *mSizeArray;
167 jsize mStringsLength;
168};
169
Jason Samsd19f10d2009-05-22 14:03:28 -0700170// ---------------------------------------------------------------------------
171
Jason Samsffe9f482009-06-01 17:45:53 -0700172static jfieldID gContextId = 0;
173static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700174static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700175
176static void _nInit(JNIEnv *_env, jclass _this)
177{
Tim Murraya78e9ad2013-11-15 13:08:30 -0800178 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700179
180 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhata0398432014-01-20 20:08:01 +0000181 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700182}
183
Jason Samsd19f10d2009-05-22 14:03:28 -0700184// ---------------------------------------------------------------------------
185
Jason Sams3eaa338e2009-06-10 15:04:38 -0700186static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800187nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700188{
Tim Murraye926ddd2014-01-07 15:36:19 -0800189 LOG_API("nContextFinish, con(%p)", (RsContext)con);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800190 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700191}
192
193static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800194nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700195{
Tim Murraye926ddd2014-01-07 15:36:19 -0800196 LOG_API("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700197 jint len = _env->GetArrayLength(str);
198 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800199 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700200 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
201}
202
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700203static jstring
Tim Murray7a629fa2013-11-19 12:45:54 -0800204nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700205{
Tim Murraye926ddd2014-01-07 15:36:19 -0800206 LOG_API("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700207 const char *name = NULL;
Tim Murraya78e9ad2013-11-15 13:08:30 -0800208 rsaGetName((RsContext)con, (void *)obj, &name);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700209 if(name == NULL || strlen(name) == 0) {
210 return NULL;
211 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700212 return _env->NewStringUTF(name);
213}
214
Jason Sams7ce033d2009-08-18 14:14:24 -0700215static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800216nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700217{
Tim Murraye926ddd2014-01-07 15:36:19 -0800218 LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800219 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700220}
221
Jason Sams3eaa338e2009-06-10 15:04:38 -0700222// ---------------------------------------------------------------------------
223
Tim Murraya78e9ad2013-11-15 13:08:30 -0800224static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700225nDeviceCreate(JNIEnv *_env, jobject _this)
226{
227 LOG_API("nDeviceCreate");
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000228 return (jlong)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700229}
230
231static void
Tim Murrayb75c27e2014-01-10 11:25:52 -0800232nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700233{
234 LOG_API("nDeviceDestroy");
235 return rsDeviceDestroy((RsDevice)dev);
236}
237
Jason Samsebfb4362009-09-23 13:57:02 -0700238static void
Tim Murrayb75c27e2014-01-10 11:25:52 -0800239nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700240{
241 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
242 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
243}
244
Tim Murraya78e9ad2013-11-15 13:08:30 -0800245static jlong
Tim Murrayb75c27e2014-01-10 11:25:52 -0800246nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700247{
248 LOG_API("nContextCreate");
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000249 return (jlong)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0);
Jason Sams704ff642010-02-09 16:05:07 -0800250}
251
Tim Murraya78e9ad2013-11-15 13:08:30 -0800252static jlong
Tim Murrayb75c27e2014-01-10 11:25:52 -0800253nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000254 jint colorMin, jint colorPref,
255 jint alphaMin, jint alphaPref,
256 jint depthMin, jint depthPref,
257 jint stencilMin, jint stencilPref,
258 jint samplesMin, jint samplesPref, jfloat samplesQ,
259 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800260{
Jason Sams11c8af92010-10-13 15:31:10 -0700261 RsSurfaceConfig sc;
262 sc.alphaMin = alphaMin;
263 sc.alphaPref = alphaPref;
264 sc.colorMin = colorMin;
265 sc.colorPref = colorPref;
266 sc.depthMin = depthMin;
267 sc.depthPref = depthPref;
268 sc.samplesMin = samplesMin;
269 sc.samplesPref = samplesPref;
270 sc.samplesQ = samplesQ;
271
Jason Sams704ff642010-02-09 16:05:07 -0800272 LOG_API("nContextCreateGL");
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000273 return (jlong)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700274}
275
276static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800277nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800278{
Tim Murraye926ddd2014-01-07 15:36:19 -0800279 LOG_API("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800280 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800281}
282
283
284
285static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800286nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800287{
Tim Murraye926ddd2014-01-07 15:36:19 -0800288 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800289
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700290 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800291 if (wnd == NULL) {
292
293 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700294 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800295 }
296
Tim Murraya78e9ad2013-11-15 13:08:30 -0800297 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800298}
299
300static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800301nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700302{
Tim Murraye926ddd2014-01-07 15:36:19 -0800303 LOG_API("nContextDestroy, con(%p)", (RsContext)con);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800304 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700305}
306
Jason Sams715333b2009-11-17 17:26:46 -0800307static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800308nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800309{
Jason Sams715333b2009-11-17 17:26:46 -0800310 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
311 rsContextDump((RsContext)con, bits);
312}
Jason Samsd19f10d2009-05-22 14:03:28 -0700313
314static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800315nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700316{
Tim Murraye926ddd2014-01-07 15:36:19 -0800317 LOG_API("nContextPause, con(%p)", (RsContext)con);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800318 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700319}
320
321static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800322nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700323{
Tim Murraye926ddd2014-01-07 15:36:19 -0800324 LOG_API("nContextResume, con(%p)", (RsContext)con);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800325 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700326}
327
Jason Sams1c415172010-11-08 17:06:46 -0800328
329static jstring
Tim Murraya78e9ad2013-11-15 13:08:30 -0800330nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800331{
Tim Murraye926ddd2014-01-07 15:36:19 -0800332 LOG_API("nContextGetErrorMessage, con(%p)", (RsContext)con);
Jason Sams1c415172010-11-08 17:06:46 -0800333 char buf[1024];
334
335 size_t receiveLen;
336 uint32_t subID;
Tim Murraya78e9ad2013-11-15 13:08:30 -0800337 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700338 buf, sizeof(buf),
339 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700340 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800341 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100342 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800343 }
344 return _env->NewStringUTF(buf);
345}
346
Jason Samsedbfabd2011-05-17 15:01:29 -0700347static jint
Tim Murraya78e9ad2013-11-15 13:08:30 -0800348nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700349{
Jason Sams516c3192009-10-06 13:58:47 -0700350 jint len = _env->GetArrayLength(data);
Tim Murraye926ddd2014-01-07 15:36:19 -0800351 LOG_API("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
Jason Sams516c3192009-10-06 13:58:47 -0700352 jint *ptr = _env->GetIntArrayElements(data, NULL);
353 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800354 uint32_t subID;
Tim Murraya78e9ad2013-11-15 13:08:30 -0800355 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700356 ptr, len * 4,
357 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700358 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700359 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100360 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700361 }
362 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000363 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800364}
365
366static jint
Tim Murraya78e9ad2013-11-15 13:08:30 -0800367nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800368{
Tim Murraye926ddd2014-01-07 15:36:19 -0800369 LOG_API("nContextPeekMessage, con(%p)", (RsContext)con);
Jason Sams1c415172010-11-08 17:06:46 -0800370 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
371 size_t receiveLen;
372 uint32_t subID;
Tim Murraya78e9ad2013-11-15 13:08:30 -0800373 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700374 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800375 auxDataPtr[0] = (jint)subID;
376 auxDataPtr[1] = (jint)receiveLen;
377 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000378 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700379}
380
Tim Murraya78e9ad2013-11-15 13:08:30 -0800381static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700382{
Tim Murraye926ddd2014-01-07 15:36:19 -0800383 LOG_API("nContextInitToClient, con(%p)", (RsContext)con);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800384 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700385}
386
Tim Murraya78e9ad2013-11-15 13:08:30 -0800387static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700388{
Tim Murraye926ddd2014-01-07 15:36:19 -0800389 LOG_API("nContextDeinitToClient, con(%p)", (RsContext)con);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800390 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700391}
392
Jason Sams455d6442013-02-05 19:20:18 -0800393static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800394nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800395{
396 jint *ptr = NULL;
397 jint len = 0;
398 if (data) {
399 len = _env->GetArrayLength(data);
400 jint *ptr = _env->GetIntArrayElements(data, NULL);
401 }
Tim Murraye926ddd2014-01-07 15:36:19 -0800402 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800403 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800404 if (data) {
405 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
406 }
407}
408
409
Jason Sams516c3192009-10-06 13:58:47 -0700410
Tim Murray7a629fa2013-11-19 12:45:54 -0800411static jlong
412nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700413{
Tim Murraye926ddd2014-01-07 15:36:19 -0800414 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con, type, kind, norm, size);
Tim Murray7a629fa2013-11-19 12:45:54 -0800415 return (jlong)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700416}
417
Tim Murray7a629fa2013-11-19 12:45:54 -0800418static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -0800419nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000420 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700421{
Jason Sams718cd1f2009-12-23 14:35:29 -0800422 int fieldCount = _env->GetArrayLength(_ids);
Tim Murraye926ddd2014-01-07 15:36:19 -0800423 LOG_API("nElementCreate2, con(%p)", (RsContext)con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800424
Ashok Bhat98071552014-02-12 09:54:43 +0000425 jlong *jIds = _env->GetLongArrayElements(_ids, NULL);
426 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
427
428 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
429 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
430
431 for(int i = 0; i < fieldCount; i ++) {
432 ids[i] = (RsElement)jIds[i];
433 arraySizes[i] = (uint32_t)jArraySizes[i];
434 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800435
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800436 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
437
438 const char **nameArray = names.c_str();
439 size_t *sizeArray = names.c_str_len();
440
Tim Murray7a629fa2013-11-19 12:45:54 -0800441 jlong id = (jlong)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000442 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700443 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700444 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800445
Ashok Bhat98071552014-02-12 09:54:43 +0000446 free(ids);
447 free(arraySizes);
448 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
449 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
450
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000451 return (jlong)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700452}
453
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700454static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800455nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700456{
457 int dataSize = _env->GetArrayLength(_elementData);
Tim Murraye926ddd2014-01-07 15:36:19 -0800458 LOG_API("nElementGetNativeData, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700459
460 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
461 assert(dataSize == 5);
462
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000463 uintptr_t elementData[5];
Tim Murraya78e9ad2013-11-15 13:08:30 -0800464 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700465
466 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000467 const jint data = (jint)elementData[i];
468 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700469 }
470}
471
472
473static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800474nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000475 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700476 jobjectArray _names,
477 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700478{
Ashok Bhat98071552014-02-12 09:54:43 +0000479 uint32_t dataSize = _env->GetArrayLength(_IDs);
Tim Murraye926ddd2014-01-07 15:36:19 -0800480 LOG_API("nElementGetSubElements, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700481
Ashok Bhat98071552014-02-12 09:54:43 +0000482 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
483 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000484 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700485
Tim Murraya78e9ad2013-11-15 13:08:30 -0800486 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700487
Ashok Bhat98071552014-02-12 09:54:43 +0000488 for(uint32_t i = 0; i < dataSize; i++) {
489 const jlong id = (jlong)ids[i];
490 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700491 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000492 _env->SetLongArrayRegion(_IDs, i, 1, &id);
493 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700494 }
495
496 free(ids);
497 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700498 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700499}
500
Jason Samsd19f10d2009-05-22 14:03:28 -0700501// -----------------------------------
502
Tim Murray7a629fa2013-11-19 12:45:54 -0800503static jlong
504nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800505 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700506{
Jason Samsb109cc72013-01-07 18:20:12 -0800507 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
Tim Murraye926ddd2014-01-07 15:36:19 -0800508 (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700509
Tim Murray7a629fa2013-11-19 12:45:54 -0800510 return (jlong)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700511}
512
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700513static void
Ashok Bhat98071552014-02-12 09:54:43 +0000514nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700515{
516 // We are packing 6 items: mDimX; mDimY; mDimZ;
517 // mDimLOD; mDimFaces; mElement; into typeData
518 int elementCount = _env->GetArrayLength(_typeData);
519
520 assert(elementCount == 6);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000521 LOG_API("nTypeGetNativeData, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700522
Ashok Bhat98071552014-02-12 09:54:43 +0000523 uintptr_t typeData[6];
Tim Murraya78e9ad2013-11-15 13:08:30 -0800524 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700525
526 for(jint i = 0; i < elementCount; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000527 const jlong data = (jlong)typeData[i];
528 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700529 }
530}
531
Jason Samsd19f10d2009-05-22 14:03:28 -0700532// -----------------------------------
533
Tim Murray7a629fa2013-11-19 12:45:54 -0800534static jlong
Ashok Bhat98071552014-02-12 09:54:43 +0000535nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700536{
Tim Murraye926ddd2014-01-07 15:36:19 -0800537 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
Ashok Bhat98071552014-02-12 09:54:43 +0000538 return (jlong) rsAllocationCreateTyped((RsContext)con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700539}
540
Jason Samsd19f10d2009-05-22 14:03:28 -0700541static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800542nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800543{
Tim Murraye926ddd2014-01-07 15:36:19 -0800544 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, bits);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800545 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800546}
547
Jason Sams72226e02013-02-22 12:45:54 -0800548static jobject
Tim Murray7a629fa2013-11-19 12:45:54 -0800549nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800550{
Tim Murraye926ddd2014-01-07 15:36:19 -0800551 LOG_API("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
Jason Sams615e7ce2012-01-13 14:01:20 -0800552
Tim Murraya78e9ad2013-11-15 13:08:30 -0800553 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800554 sp<IGraphicBufferProducer> bp = v;
555 v->decStrong(NULL);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700556
Jason Sams72226e02013-02-22 12:45:54 -0800557 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
558 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700559}
560
561static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800562nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800563{
Stephen Hines06883b72012-05-16 18:01:34 -0700564 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Tim Murraye926ddd2014-01-07 15:36:19 -0800565 (RsContext)con, (RsAllocation)alloc, (Surface *)sur);
Jason Sams163766c2012-02-15 12:04:24 -0800566
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700567 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800568 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700569 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800570 }
571
Tim Murray7a629fa2013-11-19 12:45:54 -0800572 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800573}
574
575static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800576nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800577{
Tim Murraye926ddd2014-01-07 15:36:19 -0800578 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, alloc);
Tim Murray7a629fa2013-11-19 12:45:54 -0800579 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800580}
581
582static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800583nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800584{
Tim Murraye926ddd2014-01-07 15:36:19 -0800585 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, alloc);
Tim Murray7a629fa2013-11-19 12:45:54 -0800586 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800587}
588
589
590static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800591nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800592{
Tim Murraye926ddd2014-01-07 15:36:19 -0800593 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800594 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800595}
596
Tim Murray7a629fa2013-11-19 12:45:54 -0800597static jlong
598nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700599{
Jason Samsffe9f482009-06-01 17:45:53 -0700600 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000601 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700602 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700603
Jason Sams5476b452010-12-08 16:14:36 -0800604 bitmap.lockPixels();
605 const void* ptr = bitmap.getPixels();
Tim Murray7a629fa2013-11-19 12:45:54 -0800606 jlong id = (jlong)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700607 (RsType)type, (RsAllocationMipmapControl)mip,
608 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800609 bitmap.unlockPixels();
610 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700611}
Jason Samsfe08d992009-05-27 14:45:32 -0700612
Tim Murray7a629fa2013-11-19 12:45:54 -0800613static jlong
614nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800615{
616 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000617 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800618 const SkBitmap& bitmap(*nativeBitmap);
619
620 bitmap.lockPixels();
621 const void* ptr = bitmap.getPixels();
Tim Murray7a629fa2013-11-19 12:45:54 -0800622 jlong id = (jlong)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800623 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000624 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800625 bitmap.unlockPixels();
626 return id;
627}
628
Tim Murray7a629fa2013-11-19 12:45:54 -0800629static jlong
630nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800631{
632 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000633 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800634 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800635
Jason Sams5476b452010-12-08 16:14:36 -0800636 bitmap.lockPixels();
637 const void* ptr = bitmap.getPixels();
Tim Murray7a629fa2013-11-19 12:45:54 -0800638 jlong id = (jlong)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700639 (RsType)type, (RsAllocationMipmapControl)mip,
640 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800641 bitmap.unlockPixels();
642 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800643}
644
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700645static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800646nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700647{
648 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000649 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700650 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800651 int w = bitmap.width();
652 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700653
Jason Sams4ef66502010-12-10 16:03:15 -0800654 bitmap.lockPixels();
655 const void* ptr = bitmap.getPixels();
Tim Murraya78e9ad2013-11-15 13:08:30 -0800656 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700657 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800658 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800659 bitmap.unlockPixels();
660}
661
662static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800663nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800664{
665 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000666 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800667 const SkBitmap& bitmap(*nativeBitmap);
668
669 bitmap.lockPixels();
670 void* ptr = bitmap.getPixels();
Tim Murraya78e9ad2013-11-15 13:08:30 -0800671 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800672 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700673 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700674}
675
Jason Sams8a647432010-03-01 15:31:04 -0800676static void ReleaseBitmapCallback(void *bmp)
677{
678 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
679 nativeBitmap->unlockPixels();
680}
681
Romain Guy650a3eb2009-08-31 14:06:43 -0700682
Stephen Hines414fa2c2014-04-17 01:02:42 -0700683// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700684static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800685nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000686 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700687{
Jason Sams6fcf2e12013-11-06 11:22:02 -0800688 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murraye926ddd2014-01-07 15:36:19 -0800689 LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
690 (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700691 PER_ARRAY_TYPE(NULL, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700692}
693
Stephen Hines414fa2c2014-04-17 01:02:42 -0700694// Copies from the Java array data into the Allocation pointed to by alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700695static void
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000696// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
697nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700698{
699 jint len = _env->GetArrayLength(data);
Tim Murraye926ddd2014-01-07 15:36:19 -0800700 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
Jason Sams49bdaf02010-08-31 13:50:42 -0700701 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800702 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700703 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
704}
705
Stephen Hines414fa2c2014-04-17 01:02:42 -0700706// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -0700707static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800708nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000709 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800710{
Jason Sams6fcf2e12013-11-06 11:22:02 -0800711 RsAllocation *alloc = (RsAllocation *)_alloc;
712 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
713 LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
Tim Murraye926ddd2014-01-07 15:36:19 -0800714 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700715 PER_ARRAY_TYPE(NULL, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700716}
717
Stephen Hines414fa2c2014-04-17 01:02:42 -0700718// Copies from the Allocation pointed to by srcAlloc into the Allocation
719// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -0700720static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800721nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray7a629fa2013-11-19 12:45:54 -0800722 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700723 jint dstMip, jint dstFace,
724 jint width, jint height,
Tim Murray7a629fa2013-11-19 12:45:54 -0800725 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700726 jint srcMip, jint srcFace)
727{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800728 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700729 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
730 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
Tim Murraye926ddd2014-01-07 15:36:19 -0800731 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700732 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
733
Tim Murraya78e9ad2013-11-15 13:08:30 -0800734 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700735 (RsAllocation)dstAlloc,
736 dstXoff, dstYoff,
737 dstMip, dstFace,
738 width, height,
739 (RsAllocation)srcAlloc,
740 srcXoff, srcYoff,
741 srcMip, srcFace);
742}
743
Stephen Hines414fa2c2014-04-17 01:02:42 -0700744// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700745static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800746nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Sams6fcf2e12013-11-06 11:22:02 -0800747 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700748{
Jason Sams6fcf2e12013-11-06 11:22:02 -0800749 RsAllocation *alloc = (RsAllocation *)_alloc;
750 LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)",
Tim Murraye926ddd2014-01-07 15:36:19 -0800751 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700752 PER_ARRAY_TYPE(NULL, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -0700753}
754
Stephen Hines414fa2c2014-04-17 01:02:42 -0700755// Copies from the Allocation pointed to by srcAlloc into the Allocation
756// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -0700757static void
Tim Murraya78e9ad2013-11-15 13:08:30 -0800758nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray7a629fa2013-11-19 12:45:54 -0800759 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700760 jint dstMip,
761 jint width, jint height, jint depth,
Tim Murray7a629fa2013-11-19 12:45:54 -0800762 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700763 jint srcMip)
764{
765 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
766 " dstMip(%i), width(%i), height(%i),"
767 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
Tim Murraye926ddd2014-01-07 15:36:19 -0800768 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
769 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
Jason Samsb05d6892013-04-09 15:59:24 -0700770
Tim Murraya78e9ad2013-11-15 13:08:30 -0800771 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -0700772 (RsAllocation)dstAlloc,
773 dstXoff, dstYoff, dstZoff, dstMip,
774 width, height, depth,
775 (RsAllocation)srcAlloc,
776 srcXoff, srcYoff, srcZoff, srcMip);
777}
778
Jason Sams29868dfa2013-11-06 15:08:07 -0800779
Stephen Hines414fa2c2014-04-17 01:02:42 -0700780// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -0700781static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800782nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700783{
Jason Sams29868dfa2013-11-06 15:08:07 -0800784 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murraye926ddd2014-01-07 15:36:19 -0800785 LOG_API("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700786 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700787}
788
Stephen Hines414fa2c2014-04-17 01:02:42 -0700789// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -0700790static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800791nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams29868dfa2013-11-06 15:08:07 -0800792 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800793{
Jason Sams29868dfa2013-11-06 15:08:07 -0800794 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murraye926ddd2014-01-07 15:36:19 -0800795 LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
796 (RsContext)con, alloc, offset, count, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700797 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800798}
799
Stephen Hines414fa2c2014-04-17 01:02:42 -0700800// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -0800801static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800802nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams29868dfa2013-11-06 15:08:07 -0800803 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800804{
Jason Sams29868dfa2013-11-06 15:08:07 -0800805 RsAllocation *alloc = (RsAllocation *)_alloc;
806 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
807 LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
Tim Murraye926ddd2014-01-07 15:36:19 -0800808 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700809 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700810}
Jason Samsd19f10d2009-05-22 14:03:28 -0700811
Tim Murray7a629fa2013-11-19 12:45:54 -0800812static jlong
813nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700814{
Tim Murraye926ddd2014-01-07 15:36:19 -0800815 LOG_API("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
Tim Murray7a629fa2013-11-19 12:45:54 -0800816 return (jlong) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700817}
818
Jason Sams5edc6082010-10-05 13:32:49 -0700819static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800820nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -0700821{
Tim Murraye926ddd2014-01-07 15:36:19 -0800822 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, (RsAllocation)alloc, dimX);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800823 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -0700824}
825
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700826// -----------------------------------
827
Tim Murray7a629fa2013-11-19 12:45:54 -0800828static jlong
829nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700830{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700831 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000832 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700833
Tim Murray7a629fa2013-11-19 12:45:54 -0800834 jlong id = (jlong)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800835 return id;
836}
837
Tim Murray7a629fa2013-11-19 12:45:54 -0800838static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -0800839nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800840{
841 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
842 if (mgr == NULL) {
843 return 0;
844 }
845
846 AutoJavaStringToUTF8 str(_env, _path);
847 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
848 if (asset == NULL) {
849 return 0;
850 }
851
Tim Murray7a629fa2013-11-19 12:45:54 -0800852 jlong id = (jlong)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800853 return id;
854}
855
Tim Murray7a629fa2013-11-19 12:45:54 -0800856static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -0800857nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800858{
859 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray7a629fa2013-11-19 12:45:54 -0800860 jlong id = (jlong)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800861
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700862 return id;
863}
864
Tim Murray7a629fa2013-11-19 12:45:54 -0800865static jint
866nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700867{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700868 int32_t numEntries = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -0800869 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000870 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700871}
872
873static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800874nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700875{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000876 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700877 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
878
Tim Murraya78e9ad2013-11-15 13:08:30 -0800879 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700880
881 for(jint i = 0; i < numEntries; i ++) {
882 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
883 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
884 }
885
886 free(fileEntries);
887}
888
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000889static jlong
Tim Murray7a629fa2013-11-19 12:45:54 -0800890nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700891{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000892 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
893 jlong id = (jlong)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700894 return id;
895}
Jason Samsd19f10d2009-05-22 14:03:28 -0700896
897// -----------------------------------
898
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000899static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -0800900nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800901 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700902{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800903 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000904 jlong id = (jlong)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700905 fileNameUTF.c_str(), fileNameUTF.length(),
906 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700907
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800908 return id;
909}
910
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000911static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -0800912nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000913 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800914{
915 Asset* asset = reinterpret_cast<Asset*>(native_asset);
916 AutoJavaStringToUTF8 nameUTF(_env, name);
917
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000918 jlong id = (jlong)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700919 nameUTF.c_str(), nameUTF.length(),
920 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800921 asset->getBuffer(false), asset->getLength());
922 return id;
923}
924
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000925static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -0800926nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800927 jfloat fontSize, jint dpi)
928{
929 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
930 if (mgr == NULL) {
931 return 0;
932 }
933
934 AutoJavaStringToUTF8 str(_env, _path);
935 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
936 if (asset == NULL) {
937 return 0;
938 }
939
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000940 jlong id = (jlong)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700941 str.c_str(), str.length(),
942 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800943 asset->getBuffer(false), asset->getLength());
944 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700945 return id;
946}
947
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700948// -----------------------------------
949
950static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800951nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700952{
Tim Murraye926ddd2014-01-07 15:36:19 -0800953 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800954 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700955}
956
957static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800958nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700959{
Tim Murraye926ddd2014-01-07 15:36:19 -0800960 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800961 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700962}
963
Tim Murray7c4caad2013-04-10 16:21:40 -0700964static jint
Tim Murray7a629fa2013-11-19 12:45:54 -0800965nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -0700966{
Tim Murraye926ddd2014-01-07 15:36:19 -0800967 LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -0700968 int value = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -0800969 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -0700970 return value;
971}
972
Jason Sams4d339932010-05-11 14:03:58 -0700973static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800974nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800975{
Tim Murraye926ddd2014-01-07 15:36:19 -0800976 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800977 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800978}
979
980static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800981nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -0700982{
Tim Murraye926ddd2014-01-07 15:36:19 -0800983 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, (void *)script, slot, val);
Tim Murraya78e9ad2013-11-15 13:08:30 -0800984 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700985}
986
Tim Murray7c4caad2013-04-10 16:21:40 -0700987static jlong
Tim Murray7a629fa2013-11-19 12:45:54 -0800988nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -0700989{
Tim Murraye926ddd2014-01-07 15:36:19 -0800990 LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -0700991 jlong value = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -0800992 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -0700993 return value;
994}
995
Stephen Hines031ec58c2010-10-11 10:54:21 -0700996static void
Tim Murray7a629fa2013-11-19 12:45:54 -0800997nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700998{
Tim Murraye926ddd2014-01-07 15:36:19 -0800999 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, slot, val);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001000 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001001}
1002
Tim Murray7c4caad2013-04-10 16:21:40 -07001003static jfloat
Tim Murray7a629fa2013-11-19 12:45:54 -08001004nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001005{
Tim Murraye926ddd2014-01-07 15:36:19 -08001006 LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001007 jfloat value = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -08001008 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001009 return value;
1010}
1011
Jason Sams4d339932010-05-11 14:03:58 -07001012static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001013nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001014{
Tim Murraye926ddd2014-01-07 15:36:19 -08001015 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, slot, val);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001016 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001017}
1018
Tim Murray7c4caad2013-04-10 16:21:40 -07001019static jdouble
Tim Murray7a629fa2013-11-19 12:45:54 -08001020nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001021{
Tim Murraye926ddd2014-01-07 15:36:19 -08001022 LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001023 jdouble value = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -08001024 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001025 return value;
1026}
1027
Stephen Hinesca54ec32010-09-20 17:20:30 -07001028static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001029nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001030{
Tim Murraye926ddd2014-01-07 15:36:19 -08001031 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams4d339932010-05-11 14:03:58 -07001032 jint len = _env->GetArrayLength(data);
1033 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001034 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001035 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1036}
1037
Stephen Hinesadeb8092012-04-20 14:26:06 -07001038static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001039nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001040{
Tim Murraye926ddd2014-01-07 15:36:19 -08001041 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001042 jint len = _env->GetArrayLength(data);
1043 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001044 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001045 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001046}
1047
1048static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001049nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001050{
Tim Murraye926ddd2014-01-07 15:36:19 -08001051 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001052 jint len = _env->GetArrayLength(data);
1053 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1054 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
1055 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001056 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001057 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001058 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1059 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1060}
1061
Jason Samsd19f10d2009-05-22 14:03:28 -07001062
1063static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001064nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001065{
Tim Murraye926ddd2014-01-07 15:36:19 -08001066 LOG_API("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
Romain Guy584a3752009-07-30 18:45:01 -07001067
1068 jint length = _env->GetArrayLength(timeZone);
1069 jbyte* timeZone_ptr;
1070 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1071
Tim Murraya78e9ad2013-11-15 13:08:30 -08001072 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001073
1074 if (timeZone_ptr) {
1075 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1076 }
1077}
1078
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001079static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001080nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001081{
Tim Murraye926ddd2014-01-07 15:36:19 -08001082 LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001083 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001084}
1085
1086static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001087nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001088{
Tim Murraye926ddd2014-01-07 15:36:19 -08001089 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams4d339932010-05-11 14:03:58 -07001090 jint len = _env->GetArrayLength(data);
1091 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001092 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001093 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1094}
1095
Jason Sams6e494d32011-04-27 16:33:11 -07001096static void
Tim Murraya78e9ad2013-11-15 13:08:30 -08001097nScriptForEach(JNIEnv *_env, jobject _this, jlong con,
Tim Murray7a629fa2013-11-19 12:45:54 -08001098 jlong script, jint slot, jlong ain, jlong aout)
Jason Sams6e494d32011-04-27 16:33:11 -07001099{
Tim Murraye926ddd2014-01-07 15:36:19 -08001100 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001101 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001102}
1103static void
Tim Murraya78e9ad2013-11-15 13:08:30 -08001104nScriptForEachV(JNIEnv *_env, jobject _this, jlong con,
Tim Murray7a629fa2013-11-19 12:45:54 -08001105 jlong script, jint slot, jlong ain, jlong aout, jbyteArray params)
Jason Sams6e494d32011-04-27 16:33:11 -07001106{
Tim Murraye926ddd2014-01-07 15:36:19 -08001107 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams6e494d32011-04-27 16:33:11 -07001108 jint len = _env->GetArrayLength(params);
1109 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001110 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001111 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1112}
1113
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001114static void
Tim Murraya78e9ad2013-11-15 13:08:30 -08001115nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con,
Tim Murray7a629fa2013-11-19 12:45:54 -08001116 jlong script, jint slot, jlong ain, jlong aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001117 jint xstart, jint xend,
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001118 jint ystart, jint yend, jint zstart, jint zend)
1119{
Tim Murraye926ddd2014-01-07 15:36:19 -08001120 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001121 RsScriptCall sc;
1122 sc.xStart = xstart;
1123 sc.xEnd = xend;
1124 sc.yStart = ystart;
1125 sc.yEnd = yend;
1126 sc.zStart = zstart;
1127 sc.zEnd = zend;
1128 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1129 sc.arrayStart = 0;
1130 sc.arrayEnd = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -08001131 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001132}
1133
1134static void
Tim Murraya78e9ad2013-11-15 13:08:30 -08001135nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con,
Tim Murray7a629fa2013-11-19 12:45:54 -08001136 jlong script, jint slot, jlong ain, jlong aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001137 jbyteArray params, jint xstart, jint xend,
1138 jint ystart, jint yend, jint zstart, jint zend)
1139{
Tim Murraye926ddd2014-01-07 15:36:19 -08001140 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001141 jint len = _env->GetArrayLength(params);
1142 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1143 RsScriptCall sc;
1144 sc.xStart = xstart;
1145 sc.xEnd = xend;
1146 sc.yStart = ystart;
1147 sc.yEnd = yend;
1148 sc.zStart = zstart;
1149 sc.zEnd = zend;
1150 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1151 sc.arrayStart = 0;
1152 sc.arrayEnd = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -08001153 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc));
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001154 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1155}
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001156
Chris Wailes94961062014-06-11 12:01:28 -07001157static void
1158nScriptForEachMultiClipped(JNIEnv *_env, jobject _this, jlong con,
1159 jlong script, jint slot, jlongArray ains, jlong aout,
1160 jint xstart, jint xend,
1161 jint ystart, jint yend, jint zstart, jint zend)
1162{
1163 LOG_API("nScriptForEachMultiClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1164
1165 jint in_len = _env->GetArrayLength(ains);
1166 jlong* in_ptr = _env->GetLongArrayElements(ains, NULL);
1167
1168 RsAllocation *in_allocs = NULL;
1169
1170 if (sizeof(RsAllocation) == sizeof(jlong)) {
1171 in_allocs = (RsAllocation*)in_ptr;
1172
1173 } else {
1174 // Convert from 64-bit jlong types to the native pointer type.
1175
1176 in_allocs = new RsAllocation[in_len];
1177
1178 for (int index = in_len; --index >= 0;) {
1179 in_allocs[index] = (RsAllocation)in_ptr[index];
1180 }
1181 }
1182
1183 RsScriptCall sc;
1184 sc.xStart = xstart;
1185 sc.xEnd = xend;
1186 sc.yStart = ystart;
1187 sc.yEnd = yend;
1188 sc.zStart = zstart;
1189 sc.zEnd = zend;
1190 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1191 sc.arrayStart = 0;
1192 sc.arrayEnd = 0;
1193
1194 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
1195
1196 if (sizeof(RsAllocation) != sizeof(jlong)) {
1197 delete[] in_allocs;
1198 }
1199
1200 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
1201}
1202
1203static void
1204nScriptForEachMultiClippedV(JNIEnv *_env, jobject _this, jlong con,
1205 jlong script, jint slot, jlongArray ains, jlong aout,
1206 jbyteArray params, jint xstart, jint xend,
1207 jint ystart, jint yend, jint zstart, jint zend)
1208{
1209 LOG_API("nScriptForEachMultiClippedV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1210
1211 jint in_len = _env->GetArrayLength(ains);
1212 jlong* in_ptr = _env->GetLongArrayElements(ains, NULL);
1213
1214 RsAllocation *in_allocs = NULL;
1215
1216 if (sizeof(RsAllocation) == sizeof(jlong)) {
1217 in_allocs = (RsAllocation*)in_ptr;
1218
1219 } else {
1220 // Convert from 64-bit jlong types to the native pointer type.
1221
1222 in_allocs = new RsAllocation[in_len];
1223
1224 for (int index = in_len; --index >= 0;) {
1225 in_allocs[index] = (RsAllocation)in_ptr[index];
1226 }
1227 }
1228
1229 jint param_len = _env->GetArrayLength(params);
1230 jbyte* param_ptr = _env->GetByteArrayElements(params, NULL);
1231
1232 RsScriptCall sc;
1233 sc.xStart = xstart;
1234 sc.xEnd = xend;
1235 sc.yStart = ystart;
1236 sc.yEnd = yend;
1237 sc.zStart = zstart;
1238 sc.zEnd = zend;
1239 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1240 sc.arrayStart = 0;
1241 sc.arrayEnd = 0;
1242 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, param_ptr, param_len, &sc, sizeof(sc));
1243
1244 if (sizeof(RsAllocation) != sizeof(jlong)) {
1245 delete[] in_allocs;
1246 }
1247
1248 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
1249 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1250}
1251
Jason Sams22534172009-08-04 16:58:20 -07001252// -----------------------------------
1253
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001254static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -08001255nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001256 jstring resName, jstring cacheDir,
1257 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001258{
Tim Murraye926ddd2014-01-07 15:36:19 -08001259 LOG_API("nScriptCCreate, con(%p)", (RsContext)con);
Jason Sams22534172009-08-04 16:58:20 -07001260
Jason Samse4a06c52011-03-16 16:29:28 -07001261 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1262 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001263 jlong ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001264 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001265 jint _exception = 0;
1266 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001267 if (!scriptRef) {
1268 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001269 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001270 goto exit;
1271 }
Jack Palevich43702d82009-05-28 13:38:16 -07001272 if (length < 0) {
1273 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001274 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001275 goto exit;
1276 }
Jason Samse4a06c52011-03-16 16:29:28 -07001277 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001278 if (remaining < length) {
1279 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001280 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1281 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001282 goto exit;
1283 }
Jason Samse4a06c52011-03-16 16:29:28 -07001284 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001285 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001286
Tim Murraya78e9ad2013-11-15 13:08:30 -08001287 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001288
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001289 ret = (jlong)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001290 resNameUTF.c_str(), resNameUTF.length(),
1291 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001292 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001293
Jack Palevich43702d82009-05-28 13:38:16 -07001294exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001295 if (script_ptr) {
1296 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001297 _exception ? JNI_ABORT: 0);
1298 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001299
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001300 return (jlong)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001301}
1302
Tim Murray7a629fa2013-11-19 12:45:54 -08001303static jlong
1304nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001305{
Tim Murraye926ddd2014-01-07 15:36:19 -08001306 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid);
Tim Murray7a629fa2013-11-19 12:45:54 -08001307 return (jlong)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001308}
1309
Tim Murray7a629fa2013-11-19 12:45:54 -08001310static jlong
1311nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001312{
Tim Murraye926ddd2014-01-07 15:36:19 -08001313 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, (void *)sid, slot, sig);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001314 return (jlong)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001315}
1316
Tim Murray7a629fa2013-11-19 12:45:54 -08001317static jlong
1318nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001319{
Tim Murraye926ddd2014-01-07 15:36:19 -08001320 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001321 return (jlong)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001322}
1323
Tim Murray7a629fa2013-11-19 12:45:54 -08001324static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001325nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1326 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001327{
Tim Murraye926ddd2014-01-07 15:36:19 -08001328 LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con);
Jason Sams08a81582012-09-18 12:32:10 -07001329
Ashok Bhat98071552014-02-12 09:54:43 +00001330 jint kernelsLen = _env->GetArrayLength(_kernels);
1331 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, NULL);
1332 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1333 for(int i = 0; i < kernelsLen; ++i) {
1334 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1335 }
Jason Sams08a81582012-09-18 12:32:10 -07001336
Ashok Bhat98071552014-02-12 09:54:43 +00001337 jint srcLen = _env->GetArrayLength(_src);
1338 jlong *jSrcPtr = _env->GetLongArrayElements(_src, NULL);
1339 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1340 for(int i = 0; i < srcLen; ++i) {
1341 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1342 }
Jason Sams08a81582012-09-18 12:32:10 -07001343
Ashok Bhat98071552014-02-12 09:54:43 +00001344 jint dstkLen = _env->GetArrayLength(_dstk);
1345 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, NULL);
1346 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1347 for(int i = 0; i < dstkLen; ++i) {
1348 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1349 }
1350
1351 jint dstfLen = _env->GetArrayLength(_dstf);
1352 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, NULL);
1353 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1354 for(int i = 0; i < dstfLen; ++i) {
1355 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1356 }
1357
1358 jint typesLen = _env->GetArrayLength(_types);
1359 jlong *jTypesPtr = _env->GetLongArrayElements(_types, NULL);
1360 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1361 for(int i = 0; i < typesLen; ++i) {
1362 typesPtr[i] = (RsType)jTypesPtr[i];
1363 }
1364
1365 jlong id = (jlong)rsScriptGroupCreate((RsContext)con,
1366 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1367 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1368 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1369 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1370 (RsType *)typesPtr, typesLen * sizeof(RsType));
1371
1372 free(kernelsPtr);
1373 free(srcPtr);
1374 free(dstkPtr);
1375 free(dstfPtr);
1376 free(typesPtr);
1377 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1378 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1379 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1380 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1381 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001382 return id;
1383}
1384
1385static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001386nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001387{
Tim Murraye926ddd2014-01-07 15:36:19 -08001388 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001389 (void *)gid, (void *)kid, (void *)alloc);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001390 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001391}
1392
1393static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001394nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001395{
Tim Murraye926ddd2014-01-07 15:36:19 -08001396 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001397 (void *)gid, (void *)kid, (void *)alloc);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001398 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001399}
1400
1401static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001402nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001403{
Tim Murraye926ddd2014-01-07 15:36:19 -08001404 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001405 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001406}
1407
Jason Samsd19f10d2009-05-22 14:03:28 -07001408// ---------------------------------------------------------------------------
1409
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001410static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -08001411nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001412 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1413 jboolean depthMask, jboolean ditherEnable,
1414 jint srcFunc, jint destFunc,
1415 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001416{
Tim Murraye926ddd2014-01-07 15:36:19 -08001417 LOG_API("nProgramStoreCreate, con(%p)", (RsContext)con);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001418 return (jlong)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001419 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1420 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001421}
1422
Jason Sams0011bcf2009-12-15 12:58:36 -08001423// ---------------------------------------------------------------------------
1424
1425static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001426nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001427{
Tim Murraye926ddd2014-01-07 15:36:19 -08001428 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001429 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001430}
Jason Sams54c0ec12009-11-30 14:49:55 -08001431
Jason Sams68afd012009-12-17 16:55:08 -08001432static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001433nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001434{
Tim Murraye926ddd2014-01-07 15:36:19 -08001435 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001436 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001437}
1438
1439static void
Tim Murray7a629fa2013-11-19 12:45:54 -08001440nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001441{
Tim Murraye926ddd2014-01-07 15:36:19 -08001442 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001443 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001444}
1445
Jason Samsd19f10d2009-05-22 14:03:28 -07001446// ---------------------------------------------------------------------------
1447
Tim Murray7a629fa2013-11-19 12:45:54 -08001448static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -08001449nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001450 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001451{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001452 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Ashok Bhat98071552014-02-12 09:54:43 +00001453 jlong *jParamPtr = _env->GetLongArrayElements(params, NULL);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001454 jint paramLen = _env->GetArrayLength(params);
1455
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001456 int texCount = _env->GetArrayLength(texNames);
1457 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1458 const char ** nameArray = names.c_str();
1459 size_t* sizeArray = names.c_str_len();
1460
Tim Murraye926ddd2014-01-07 15:36:19 -08001461 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001462
Ashok Bhat98071552014-02-12 09:54:43 +00001463 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1464 for(int i = 0; i < paramLen; ++i) {
1465 paramPtr[i] = (uintptr_t)jParamPtr[i];
1466 }
Tim Murray7a629fa2013-11-19 12:45:54 -08001467 jlong ret = (jlong)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001468 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001469 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001470
Ashok Bhat98071552014-02-12 09:54:43 +00001471 free(paramPtr);
1472 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001473 return ret;
1474}
1475
1476
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001477// ---------------------------------------------------------------------------
1478
Tim Murray7a629fa2013-11-19 12:45:54 -08001479static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -08001480nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001481 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001482{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001483 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Ashok Bhat98071552014-02-12 09:54:43 +00001484 jlong *jParamPtr = _env->GetLongArrayElements(params, NULL);
Jason Sams0011bcf2009-12-15 12:58:36 -08001485 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001486
Tim Murraye926ddd2014-01-07 15:36:19 -08001487 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001488
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001489 int texCount = _env->GetArrayLength(texNames);
1490 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1491 const char ** nameArray = names.c_str();
1492 size_t* sizeArray = names.c_str_len();
1493
Ashok Bhat98071552014-02-12 09:54:43 +00001494 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1495 for(int i = 0; i < paramLen; ++i) {
1496 paramPtr[i] = (uintptr_t)jParamPtr[i];
1497 }
1498
Tim Murray7a629fa2013-11-19 12:45:54 -08001499 jlong ret = (jlong)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001500 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001501 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001502
Ashok Bhat98071552014-02-12 09:54:43 +00001503 free(paramPtr);
1504 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001505 return ret;
1506}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001507
Jason Samsebfb4362009-09-23 13:57:02 -07001508// ---------------------------------------------------------------------------
1509
Tim Murray7a629fa2013-11-19 12:45:54 -08001510static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -08001511nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001512{
Tim Murraye926ddd2014-01-07 15:36:19 -08001513 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, pointSprite, cull);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001514 return (jlong)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001515}
1516
Jason Samsd19f10d2009-05-22 14:03:28 -07001517
1518// ---------------------------------------------------------------------------
1519
1520static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001521nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001522{
Tim Murraye926ddd2014-01-07 15:36:19 -08001523 LOG_API("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001524 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001525}
1526
1527static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001528nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001529{
Tim Murraye926ddd2014-01-07 15:36:19 -08001530 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001531 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001532}
1533
1534static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001535nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001536{
Tim Murraye926ddd2014-01-07 15:36:19 -08001537 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, (RsProgramFragment)pf);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001538 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001539}
1540
Jason Sams0826a6f2009-06-15 19:04:56 -07001541static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001542nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001543{
Tim Murraye926ddd2014-01-07 15:36:19 -08001544 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001545 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001546}
1547
Joe Onoratod7b37742009-08-09 22:57:44 -07001548static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001549nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001550{
Tim Murraye926ddd2014-01-07 15:36:19 -08001551 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
Tim Murraya78e9ad2013-11-15 13:08:30 -08001552 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001553}
1554
Joe Onoratod7b37742009-08-09 22:57:44 -07001555
Jason Sams02fb2cb2009-05-28 15:37:57 -07001556// ---------------------------------------------------------------------------
1557
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001558static jlong
Tim Murraya78e9ad2013-11-15 13:08:30 -08001559nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001560 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001561{
Tim Murraye926ddd2014-01-07 15:36:19 -08001562 LOG_API("nSamplerCreate, con(%p)", (RsContext)con);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001563 return (jlong)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001564 (RsSamplerValue)magFilter,
1565 (RsSamplerValue)minFilter,
1566 (RsSamplerValue)wrapS,
1567 (RsSamplerValue)wrapT,
1568 (RsSamplerValue)wrapR,
1569 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001570}
1571
Jason Samsbba134c2009-06-22 15:49:21 -07001572// ---------------------------------------------------------------------------
1573
Tim Murray7a629fa2013-11-19 12:45:54 -08001574static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001575nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Tim Murraye926ddd2014-01-07 15:36:19 -08001576 LOG_API("nPathCreate, con(%p)", (RsContext)con);
Jason Samsf15ed012011-10-31 13:23:43 -07001577
Tim Murray7a629fa2013-11-19 12:45:54 -08001578 jlong id = (jlong)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
1579 (RsAllocation)_vtx,
1580 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001581 return id;
1582}
1583
Tim Murray7a629fa2013-11-19 12:45:54 -08001584static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001585nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001586{
Tim Murraye926ddd2014-01-07 15:36:19 -08001587 LOG_API("nMeshCreate, con(%p)", (RsContext)con);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001588
1589 jint vtxLen = _env->GetArrayLength(_vtx);
Ashok Bhat98071552014-02-12 09:54:43 +00001590 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, NULL);
1591 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1592 for(int i = 0; i < vtxLen; ++i) {
1593 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1594 }
1595
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001596 jint idxLen = _env->GetArrayLength(_idx);
Ashok Bhat98071552014-02-12 09:54:43 +00001597 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, NULL);
1598 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1599 for(int i = 0; i < idxLen; ++i) {
1600 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1601 }
1602
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001603 jint primLen = _env->GetArrayLength(_prim);
1604 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1605
Ashok Bhat98071552014-02-12 09:54:43 +00001606 jlong id = (jlong)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001607 (RsAllocation *)vtxPtr, vtxLen,
1608 (RsAllocation *)idxPtr, idxLen,
1609 (uint32_t *)primPtr, primLen);
1610
Ashok Bhat98071552014-02-12 09:54:43 +00001611 free(vtxPtr);
1612 free(idxPtr);
1613 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1614 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001615 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001616 return id;
1617}
1618
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001619static jint
Tim Murray7a629fa2013-11-19 12:45:54 -08001620nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001621{
Tim Murraye926ddd2014-01-07 15:36:19 -08001622 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001623 jint vtxCount = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -08001624 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001625 return vtxCount;
1626}
1627
1628static jint
Tim Murray7a629fa2013-11-19 12:45:54 -08001629nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001630{
Tim Murraye926ddd2014-01-07 15:36:19 -08001631 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001632 jint idxCount = 0;
Tim Murraya78e9ad2013-11-15 13:08:30 -08001633 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001634 return idxCount;
1635}
1636
1637static void
Ashok Bhat98071552014-02-12 09:54:43 +00001638nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001639{
Tim Murraye926ddd2014-01-07 15:36:19 -08001640 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001641
1642 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murraya78e9ad2013-11-15 13:08:30 -08001643 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001644
1645 for(jint i = 0; i < numVtxIDs; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +00001646 const jlong alloc = (jlong)allocs[i];
1647 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001648 }
1649
1650 free(allocs);
1651}
1652
1653static void
Ashok Bhat98071552014-02-12 09:54:43 +00001654nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001655{
Tim Murraye926ddd2014-01-07 15:36:19 -08001656 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001657
1658 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1659 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1660
Tim Murraya78e9ad2013-11-15 13:08:30 -08001661 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001662
1663 for(jint i = 0; i < numIndices; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +00001664 const jlong alloc = (jlong)allocs[i];
1665 const jint prim = (jint)prims[i];
1666 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1667 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001668 }
1669
1670 free(allocs);
1671 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001672}
1673
Tim Murrayf0c62b22014-05-16 11:47:26 -07001674static jint
1675nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1676 return (jint)sizeof(void*);
1677}
1678
1679
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001680// ---------------------------------------------------------------------------
1681
Jason Samsd19f10d2009-05-22 14:03:28 -07001682
Jason Sams94d8e90a2009-06-10 16:09:05 -07001683static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001684
1685static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001686{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001687
Tim Murraya78e9ad2013-11-15 13:08:30 -08001688{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1689{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1690{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1691{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1692{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1693{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001694
Tim Murraya78e9ad2013-11-15 13:08:30 -08001695{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1696{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001697
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001698
Jason Sams2e1872f2010-08-17 16:25:41 -07001699// All methods below are thread protected in java.
Tim Murraya78e9ad2013-11-15 13:08:30 -08001700{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1701{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1702{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1703{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1704{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1705{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1706{"rsnContextDump", "(JI)V", (void*)nContextDump },
1707{"rsnContextPause", "(J)V", (void*)nContextPause },
1708{"rsnContextResume", "(J)V", (void*)nContextResume },
1709{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Tim Murray7a629fa2013-11-19 12:45:54 -08001710{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1711{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1712{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001713
Tim Murray7a629fa2013-11-19 12:45:54 -08001714{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001715{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray7a629fa2013-11-19 12:45:54 -08001716{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1717{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1718{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001719{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001720
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001721{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1722{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1723{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001724
Tim Murray7a629fa2013-11-19 12:45:54 -08001725{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001726{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray7a629fa2013-11-19 12:45:54 -08001727{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001728{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001729
Tim Murray7a629fa2013-11-19 12:45:54 -08001730{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001731{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001732
Ashok Bhat98071552014-02-12 09:54:43 +00001733{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray7a629fa2013-11-19 12:45:54 -08001734{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1735{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1736{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001737
Tim Murray7a629fa2013-11-19 12:45:54 -08001738{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1739{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001740
Tim Murray7a629fa2013-11-19 12:45:54 -08001741{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1742{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1743{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1744{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1745{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1746{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1747{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1748{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1749{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1750{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1751{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1752{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1753{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1754{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1755{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1756{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1757{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001758
Tim Murray7a629fa2013-11-19 12:45:54 -08001759{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1760{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1761{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1762{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
1763{"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach },
1764{"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV },
1765{"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped },
1766{"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV },
Chris Wailes94961062014-06-11 12:01:28 -07001767{"rsnScriptForEachMultiClipped", "(JJI[JJIIIIII)V", (void*)nScriptForEachMultiClipped },
1768{"rsnScriptForEachMultiClipped", "(JJI[JJ[BIIIIII)V", (void*)nScriptForEachMultiClippedV },
Tim Murray7a629fa2013-11-19 12:45:54 -08001769{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1770{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1771{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1772{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1773{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1774{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1775{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
1776{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
1777{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
1778{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
1779{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
1780{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001781
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001782{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray7a629fa2013-11-19 12:45:54 -08001783{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
1784{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
1785{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001786{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Tim Murray7a629fa2013-11-19 12:45:54 -08001787{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
1788{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
1789{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001790
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001791{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001792
Tim Murray7a629fa2013-11-19 12:45:54 -08001793{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
1794{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
1795{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001796
Ashok Bhat98071552014-02-12 09:54:43 +00001797{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray7a629fa2013-11-19 12:45:54 -08001798{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001799{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001800
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001801{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
1802{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
1803{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
1804{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
1805{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001806
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001807{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001808
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001809{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001810{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001811
Tim Murray7a629fa2013-11-19 12:45:54 -08001812{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
1813{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00001814{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
1815{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001816
Tim Murrayf0c62b22014-05-16 11:47:26 -07001817{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07001818};
1819
1820static int registerFuncs(JNIEnv *_env)
1821{
1822 return android::AndroidRuntime::registerNativeMethods(
1823 _env, classPathName, methods, NELEM(methods));
1824}
1825
1826// ---------------------------------------------------------------------------
1827
1828jint JNI_OnLoad(JavaVM* vm, void* reserved)
1829{
1830 JNIEnv* env = NULL;
1831 jint result = -1;
1832
Jason Samsd19f10d2009-05-22 14:03:28 -07001833 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001834 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001835 goto bail;
1836 }
1837 assert(env != NULL);
1838
1839 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001840 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001841 goto bail;
1842 }
1843
1844 /* success -- return valid version number */
1845 result = JNI_VERSION_1_4;
1846
1847bail:
1848 return result;
1849}