blob: 06f4defd2ad9f1edef98ccee121f4596274f3168 [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>
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +010025#include <inttypes.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050027#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070028
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080029#include <androidfw/Asset.h>
30#include <androidfw/AssetManager.h>
31#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070032
Jason Samsd19f10d2009-05-22 14:03:28 -070033#include "jni.h"
34#include "JNIHelp.h"
35#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070036#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080037#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070038
Jason Sams1d6983a2012-02-16 16:07:49 -080039#include <rs.h>
40#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070041#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080042#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080043#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070044#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070045
Steve Block3762c312012-01-06 19:20:56 +000046//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080047static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070048
49using namespace android;
50
Andreas Gampe67333922014-11-10 20:35:59 -080051template <typename... T>
52void UNUSED(T... t) {}
53
Stephen Hines414fa2c2014-04-17 01:02:42 -070054#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080055 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070056 void *ptr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080057 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070058 jint relFlag = 0; \
59 if (readonly) { \
60 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
61 relFlag = JNI_ABORT; \
62 } \
Jason Samse729a942013-11-06 11:22:02 -080063 switch(dataType) { \
64 case RS_TYPE_FLOAT_32: \
65 len = _env->GetArrayLength((jfloatArray)data); \
66 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080067 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080068 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070069 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080070 return; \
71 case RS_TYPE_FLOAT_64: \
72 len = _env->GetArrayLength((jdoubleArray)data); \
73 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080074 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -080075 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070076 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080077 return; \
78 case RS_TYPE_SIGNED_8: \
79 case RS_TYPE_UNSIGNED_8: \
80 len = _env->GetArrayLength((jbyteArray)data); \
81 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080082 typeBytes = 1; \
Jason Samse729a942013-11-06 11:22:02 -080083 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070084 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080085 return; \
86 case RS_TYPE_SIGNED_16: \
87 case RS_TYPE_UNSIGNED_16: \
88 len = _env->GetArrayLength((jshortArray)data); \
89 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080090 typeBytes = 2; \
Jason Samse729a942013-11-06 11:22:02 -080091 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070092 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080093 return; \
94 case RS_TYPE_SIGNED_32: \
95 case RS_TYPE_UNSIGNED_32: \
96 len = _env->GetArrayLength((jintArray)data); \
97 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080098 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080099 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700100 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800101 return; \
102 case RS_TYPE_SIGNED_64: \
103 case RS_TYPE_UNSIGNED_64: \
104 len = _env->GetArrayLength((jlongArray)data); \
105 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800106 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -0800107 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700108 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800109 return; \
110 default: \
111 break; \
112 } \
Andreas Gampe67333922014-11-10 20:35:59 -0800113 UNUSED(len, ptr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800114}
115
116
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800117class AutoJavaStringToUTF8 {
118public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800119 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700120 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800121 fLength = env->GetStringUTFLength(str);
122 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800123 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800124 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
125 }
126 const char* c_str() const { return fCStr; }
127 jsize length() const { return fLength; }
128
129private:
130 JNIEnv* fEnv;
131 jstring fJStr;
132 const char* fCStr;
133 jsize fLength;
134};
135
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800136class AutoJavaStringArrayToUTF8 {
137public:
138 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
139 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700140 mCStrings = nullptr;
141 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800142 if (stringsLength > 0) {
143 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
144 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
145 for (jsize ct = 0; ct < stringsLength; ct ++) {
146 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700147 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800148 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
149 }
150 }
151 }
152 ~AutoJavaStringArrayToUTF8() {
153 for (jsize ct=0; ct < mStringsLength; ct++) {
154 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
155 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
156 }
157 free(mCStrings);
158 free(mSizeArray);
159 }
160 const char **c_str() const { return mCStrings; }
161 size_t *c_str_len() const { return mSizeArray; }
162 jsize length() const { return mStringsLength; }
163
164private:
165 JNIEnv *mEnv;
166 jobjectArray mStrings;
167 const char **mCStrings;
168 size_t *mSizeArray;
169 jsize mStringsLength;
170};
171
Jason Samsd19f10d2009-05-22 14:03:28 -0700172// ---------------------------------------------------------------------------
173
Jason Samsffe9f482009-06-01 17:45:53 -0700174static jfieldID gContextId = 0;
175static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700176
177static void _nInit(JNIEnv *_env, jclass _this)
178{
Tim Murrayeff663f2013-11-15 13:08:30 -0800179 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700180
181 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000182 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700183}
184
Jason Samsd19f10d2009-05-22 14:03:28 -0700185// ---------------------------------------------------------------------------
186
Jason Sams3eaa338e2009-06-10 15:04:38 -0700187static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800188nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700189{
Andreas Gampe67333922014-11-10 20:35:59 -0800190 if (kLogApi) {
191 ALOGD("nContextFinish, con(%p)", (RsContext)con);
192 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800193 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700194}
195
Yang Ni281c3252014-10-24 08:52:24 -0700196static jlong
197nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
198 jlong returnValue, jlongArray fieldIDArray,
199 jlongArray valueArray, jintArray sizeArray,
200 jlongArray depClosureArray, jlongArray depFieldIDArray) {
201 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
202 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
203 RsScriptFieldID* fieldIDs =
204 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
205 for (int i = 0; i< fieldIDs_length; i++) {
206 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
207 }
208
209 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
210 jsize values_length = _env->GetArrayLength(valueArray);
211 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
212 for (int i = 0; i < values_length; i++) {
213 values[i] = (uintptr_t)jValues[i];
214 }
215
216 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
217 jsize sizes_length = _env->GetArrayLength(sizeArray);
218
219 jlong* jDepClosures =
220 _env->GetLongArrayElements(depClosureArray, nullptr);
221 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
222 RsClosure* depClosures =
223 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
224 for (int i = 0; i < depClosures_length; i++) {
225 depClosures[i] = (RsClosure)jDepClosures[i];
226 }
227
228 jlong* jDepFieldIDs =
229 _env->GetLongArrayElements(depFieldIDArray, nullptr);
230 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
231 RsScriptFieldID* depFieldIDs =
232 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
233 for (int i = 0; i < depClosures_length; i++) {
234 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
235 }
236
237 return (jlong)(uintptr_t)rsClosureCreate(
238 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
239 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
240 (size_t*)sizes, (size_t)sizes_length,
241 depClosures, (size_t)depClosures_length,
242 depFieldIDs, (size_t)depFieldIDs_length);
243}
244
245static void
246nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
247 jint index, jlong value, jint size) {
248 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
249 (uintptr_t)value, (size_t)size);
250}
251
252static void
253nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
254 jlong fieldID, jlong value, jint size) {
255 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
256 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
257}
258
259static long
260nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con,
261 jlongArray closureArray) {
262 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
263 jsize numClosures = _env->GetArrayLength(closureArray);
264 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
265 for (int i = 0; i < numClosures; i++) {
266 closures[i] = (RsClosure)jClosures[i];
267 }
268
269 return (jlong)(uintptr_t)rsScriptGroup2Create((RsContext)con, closures,
270 numClosures);
271}
272
273static void
274nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
275 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
276}
277
Jason Sams96ed4cf2010-06-15 12:15:57 -0700278static void
Tim Murray460a0492013-11-19 12:45:54 -0800279nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700280{
Andreas Gampe67333922014-11-10 20:35:59 -0800281 if (kLogApi) {
282 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
283 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700284 jint len = _env->GetArrayLength(str);
285 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800286 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700287 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
288}
289
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700290static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800291nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700292{
Andreas Gampe67333922014-11-10 20:35:59 -0800293 if (kLogApi) {
294 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
295 }
Chris Wailes488230c32014-08-14 11:22:40 -0700296 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800297 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700298 if(name == nullptr || strlen(name) == 0) {
299 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700300 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700301 return _env->NewStringUTF(name);
302}
303
Jason Sams7ce033d2009-08-18 14:14:24 -0700304static void
Tim Murray460a0492013-11-19 12:45:54 -0800305nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700306{
Andreas Gampe67333922014-11-10 20:35:59 -0800307 if (kLogApi) {
308 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
309 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800310 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700311}
312
Jason Sams3eaa338e2009-06-10 15:04:38 -0700313// ---------------------------------------------------------------------------
314
Tim Murrayeff663f2013-11-15 13:08:30 -0800315static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700316nDeviceCreate(JNIEnv *_env, jobject _this)
317{
Andreas Gampe67333922014-11-10 20:35:59 -0800318 if (kLogApi) {
319 ALOGD("nDeviceCreate");
320 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700321 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700322}
323
324static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800325nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700326{
Andreas Gampe67333922014-11-10 20:35:59 -0800327 if (kLogApi) {
328 ALOGD("nDeviceDestroy");
329 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700330 return rsDeviceDestroy((RsDevice)dev);
331}
332
Jason Samsebfb4362009-09-23 13:57:02 -0700333static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800334nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700335{
Andreas Gampe67333922014-11-10 20:35:59 -0800336 if (kLogApi) {
337 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
338 }
Jason Samsebfb4362009-09-23 13:57:02 -0700339 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
340}
341
Tim Murrayeff663f2013-11-15 13:08:30 -0800342static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800343nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700344{
Andreas Gampe67333922014-11-10 20:35:59 -0800345 if (kLogApi) {
346 ALOGD("nContextCreate");
347 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800348 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800349}
350
Tim Murrayeff663f2013-11-15 13:08:30 -0800351static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800352nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000353 jint colorMin, jint colorPref,
354 jint alphaMin, jint alphaPref,
355 jint depthMin, jint depthPref,
356 jint stencilMin, jint stencilPref,
357 jint samplesMin, jint samplesPref, jfloat samplesQ,
358 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800359{
Jason Sams11c8af92010-10-13 15:31:10 -0700360 RsSurfaceConfig sc;
361 sc.alphaMin = alphaMin;
362 sc.alphaPref = alphaPref;
363 sc.colorMin = colorMin;
364 sc.colorPref = colorPref;
365 sc.depthMin = depthMin;
366 sc.depthPref = depthPref;
367 sc.samplesMin = samplesMin;
368 sc.samplesPref = samplesPref;
369 sc.samplesQ = samplesQ;
370
Andreas Gampe67333922014-11-10 20:35:59 -0800371 if (kLogApi) {
372 ALOGD("nContextCreateGL");
373 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700374 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700375}
376
377static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800378nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800379{
Andreas Gampe67333922014-11-10 20:35:59 -0800380 if (kLogApi) {
381 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
382 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800383 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800384}
385
386
387
388static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800389nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800390{
Andreas Gampe67333922014-11-10 20:35:59 -0800391 if (kLogApi) {
392 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
393 width, height, (Surface *)wnd);
394 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800395
Chris Wailes488230c32014-08-14 11:22:40 -0700396 ANativeWindow * window = nullptr;
397 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800398
399 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700400 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800401 }
402
Tim Murrayeff663f2013-11-15 13:08:30 -0800403 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800404}
405
406static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800407nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700408{
Andreas Gampe67333922014-11-10 20:35:59 -0800409 if (kLogApi) {
410 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
411 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800412 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700413}
414
Jason Sams715333b2009-11-17 17:26:46 -0800415static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800416nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800417{
Andreas Gampe67333922014-11-10 20:35:59 -0800418 if (kLogApi) {
419 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
420 }
Jason Sams715333b2009-11-17 17:26:46 -0800421 rsContextDump((RsContext)con, bits);
422}
Jason Samsd19f10d2009-05-22 14:03:28 -0700423
424static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800425nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700426{
Andreas Gampe67333922014-11-10 20:35:59 -0800427 if (kLogApi) {
428 ALOGD("nContextPause, con(%p)", (RsContext)con);
429 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800430 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700431}
432
433static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800434nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700435{
Andreas Gampe67333922014-11-10 20:35:59 -0800436 if (kLogApi) {
437 ALOGD("nContextResume, con(%p)", (RsContext)con);
438 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800439 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700440}
441
Jason Sams1c415172010-11-08 17:06:46 -0800442
443static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800444nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800445{
Andreas Gampe67333922014-11-10 20:35:59 -0800446 if (kLogApi) {
447 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
448 }
Jason Sams1c415172010-11-08 17:06:46 -0800449 char buf[1024];
450
451 size_t receiveLen;
452 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800453 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700454 buf, sizeof(buf),
455 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700456 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800457 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100458 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800459 }
460 return _env->NewStringUTF(buf);
461}
462
Jason Samsedbfabd2011-05-17 15:01:29 -0700463static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800464nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700465{
Jason Sams516c3192009-10-06 13:58:47 -0700466 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800467 if (kLogApi) {
468 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
469 }
Chris Wailes488230c32014-08-14 11:22:40 -0700470 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700471 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800472 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800473 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700474 ptr, len * 4,
475 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700476 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700477 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100478 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700479 }
480 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000481 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800482}
483
484static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800485nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800486{
Andreas Gampe67333922014-11-10 20:35:59 -0800487 if (kLogApi) {
488 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
489 }
Chris Wailes488230c32014-08-14 11:22:40 -0700490 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800491 size_t receiveLen;
492 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800493 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700494 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800495 auxDataPtr[0] = (jint)subID;
496 auxDataPtr[1] = (jint)receiveLen;
497 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000498 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700499}
500
Tim Murrayeff663f2013-11-15 13:08:30 -0800501static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700502{
Andreas Gampe67333922014-11-10 20:35:59 -0800503 if (kLogApi) {
504 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
505 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800506 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700507}
508
Tim Murrayeff663f2013-11-15 13:08:30 -0800509static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700510{
Andreas Gampe67333922014-11-10 20:35:59 -0800511 if (kLogApi) {
512 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
513 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800514 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700515}
516
Jason Sams455d6442013-02-05 19:20:18 -0800517static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800518nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800519{
Chris Wailes488230c32014-08-14 11:22:40 -0700520 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800521 jint len = 0;
522 if (data) {
523 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700524 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800525 }
Andreas Gampe67333922014-11-10 20:35:59 -0800526 if (kLogApi) {
527 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
528 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800529 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800530 if (data) {
531 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
532 }
533}
534
535
Jason Sams516c3192009-10-06 13:58:47 -0700536
Tim Murray460a0492013-11-19 12:45:54 -0800537static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800538nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
539 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700540{
Andreas Gampe67333922014-11-10 20:35:59 -0800541 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100542 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800543 type, kind, norm, size);
544 }
545 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
546 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700547}
548
Tim Murray460a0492013-11-19 12:45:54 -0800549static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800550nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000551 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700552{
Jason Sams718cd1f2009-12-23 14:35:29 -0800553 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800554 if (kLogApi) {
555 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
556 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800557
Chris Wailes488230c32014-08-14 11:22:40 -0700558 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
559 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000560
561 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
562 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
563
564 for(int i = 0; i < fieldCount; i ++) {
565 ids[i] = (RsElement)jIds[i];
566 arraySizes[i] = (uint32_t)jArraySizes[i];
567 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800568
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800569 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
570
571 const char **nameArray = names.c_str();
572 size_t *sizeArray = names.c_str_len();
573
Tim Murray3aa89c12014-08-18 17:51:22 -0700574 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000575 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700576 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700577 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800578
Ashok Bhat98071552014-02-12 09:54:43 +0000579 free(ids);
580 free(arraySizes);
581 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
582 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
583
Tim Murray3aa89c12014-08-18 17:51:22 -0700584 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700585}
586
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700587static void
Tim Murray460a0492013-11-19 12:45:54 -0800588nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700589{
590 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800591 if (kLogApi) {
592 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
593 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700594
595 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
596 assert(dataSize == 5);
597
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000598 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800599 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700600
601 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000602 const jint data = (jint)elementData[i];
603 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700604 }
605}
606
607
608static void
Tim Murray460a0492013-11-19 12:45:54 -0800609nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000610 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700611 jobjectArray _names,
612 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700613{
Ashok Bhat98071552014-02-12 09:54:43 +0000614 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800615 if (kLogApi) {
616 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
617 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700618
Ashok Bhat98071552014-02-12 09:54:43 +0000619 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
620 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000621 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700622
Andreas Gampe67333922014-11-10 20:35:59 -0800623 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
624 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700625
Ashok Bhat98071552014-02-12 09:54:43 +0000626 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700627 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000628 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700629 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000630 _env->SetLongArrayRegion(_IDs, i, 1, &id);
631 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700632 }
633
634 free(ids);
635 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700636 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700637}
638
Jason Samsd19f10d2009-05-22 14:03:28 -0700639// -----------------------------------
640
Tim Murray460a0492013-11-19 12:45:54 -0800641static jlong
642nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800643 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700644{
Andreas Gampe67333922014-11-10 20:35:59 -0800645 if (kLogApi) {
646 ALOGD("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100647 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800648 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700649
Andreas Gampe67333922014-11-10 20:35:59 -0800650 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
651 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700652}
653
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700654static void
Ashok Bhat98071552014-02-12 09:54:43 +0000655nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700656{
657 // We are packing 6 items: mDimX; mDimY; mDimZ;
658 // mDimLOD; mDimFaces; mElement; into typeData
659 int elementCount = _env->GetArrayLength(_typeData);
660
661 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800662 if (kLogApi) {
663 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
664 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700665
Ashok Bhat98071552014-02-12 09:54:43 +0000666 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800667 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700668
669 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700670 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000671 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700672 }
673}
674
Jason Samsd19f10d2009-05-22 14:03:28 -0700675// -----------------------------------
676
Tim Murray460a0492013-11-19 12:45:54 -0800677static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800678nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
679 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700680{
Andreas Gampe67333922014-11-10 20:35:59 -0800681 if (kLogApi) {
682 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
683 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
684 }
685 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
686 (RsAllocationMipmapControl)mips,
687 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700688}
689
Jason Samsd19f10d2009-05-22 14:03:28 -0700690static void
Tim Murray460a0492013-11-19 12:45:54 -0800691nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800692{
Andreas Gampe67333922014-11-10 20:35:59 -0800693 if (kLogApi) {
694 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
695 bits);
696 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800697 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800698}
699
Jason Sams72226e02013-02-22 12:45:54 -0800700static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800701nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800702{
Andreas Gampe67333922014-11-10 20:35:59 -0800703 if (kLogApi) {
704 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
705 }
Jason Sams615e7ce2012-01-13 14:01:20 -0800706
Andreas Gampe67333922014-11-10 20:35:59 -0800707 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
708 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800709 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -0700710 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700711
Jason Sams72226e02013-02-22 12:45:54 -0800712 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
713 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700714}
715
716static void
Tim Murray460a0492013-11-19 12:45:54 -0800717nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800718{
Andreas Gampe67333922014-11-10 20:35:59 -0800719 if (kLogApi) {
720 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
721 (RsAllocation)alloc, (Surface *)sur);
722 }
Jason Sams163766c2012-02-15 12:04:24 -0800723
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700724 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800725 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700726 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800727 }
728
Andreas Gampe67333922014-11-10 20:35:59 -0800729 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
730 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800731}
732
733static void
Tim Murray460a0492013-11-19 12:45:54 -0800734nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800735{
Andreas Gampe67333922014-11-10 20:35:59 -0800736 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100737 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800738 }
Tim Murray460a0492013-11-19 12:45:54 -0800739 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800740}
741
742static void
Tim Murray460a0492013-11-19 12:45:54 -0800743nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800744{
Andreas Gampe67333922014-11-10 20:35:59 -0800745 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100746 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800747 }
Tim Murray460a0492013-11-19 12:45:54 -0800748 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800749}
750
751
752static void
Tim Murray460a0492013-11-19 12:45:54 -0800753nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800754{
Andreas Gampe67333922014-11-10 20:35:59 -0800755 if (kLogApi) {
756 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
757 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800758 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800759}
760
Tim Murray460a0492013-11-19 12:45:54 -0800761static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800762nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
763 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700764{
Jason Samsffe9f482009-06-01 17:45:53 -0700765 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000766 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700767 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700768
Jason Sams5476b452010-12-08 16:14:36 -0800769 bitmap.lockPixels();
770 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700771 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700772 (RsType)type, (RsAllocationMipmapControl)mip,
773 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800774 bitmap.unlockPixels();
775 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700776}
Jason Samsfe08d992009-05-27 14:45:32 -0700777
Tim Murray460a0492013-11-19 12:45:54 -0800778static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800779nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
780 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800781{
782 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000783 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800784 const SkBitmap& bitmap(*nativeBitmap);
785
786 bitmap.lockPixels();
787 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700788 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800789 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000790 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800791 bitmap.unlockPixels();
792 return id;
793}
794
Tim Murray460a0492013-11-19 12:45:54 -0800795static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800796nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
797 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800798{
799 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000800 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800801 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800802
Jason Sams5476b452010-12-08 16:14:36 -0800803 bitmap.lockPixels();
804 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700805 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700806 (RsType)type, (RsAllocationMipmapControl)mip,
807 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800808 bitmap.unlockPixels();
809 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800810}
811
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700812static void
Tim Murray460a0492013-11-19 12:45:54 -0800813nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700814{
815 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000816 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700817 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800818 int w = bitmap.width();
819 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700820
Jason Sams4ef66502010-12-10 16:03:15 -0800821 bitmap.lockPixels();
822 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800823 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700824 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800825 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800826 bitmap.unlockPixels();
827}
828
829static void
Tim Murray460a0492013-11-19 12:45:54 -0800830nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800831{
832 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000833 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800834 const SkBitmap& bitmap(*nativeBitmap);
835
836 bitmap.lockPixels();
837 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800838 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800839 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700840 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700841}
842
Stephen Hines414fa2c2014-04-17 01:02:42 -0700843// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700844static void
Tim Murray460a0492013-11-19 12:45:54 -0800845nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000846 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700847{
Jason Samse729a942013-11-06 11:22:02 -0800848 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800849 if (kLogApi) {
850 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
851 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
852 dataType);
853 }
854 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count,
855 ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700856}
857
Stephen Hines414fa2c2014-04-17 01:02:42 -0700858// Copies from the Java array data into the Allocation pointed to by alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700859static void
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000860// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
Andreas Gampe67333922014-11-10 20:35:59 -0800861nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod,
862 jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700863{
864 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800865 if (kLogApi) {
866 ALOGD("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), "
867 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len,
868 sizeBytes);
869 }
Chris Wailes488230c32014-08-14 11:22:40 -0700870 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -0800871 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700872 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
873}
874
Stephen Hines414fa2c2014-04-17 01:02:42 -0700875// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -0700876static void
Tim Murray460a0492013-11-19 12:45:54 -0800877nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000878 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800879{
Jason Samse729a942013-11-06 11:22:02 -0800880 RsAllocation *alloc = (RsAllocation *)_alloc;
881 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800882 if (kLogApi) {
883 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
884 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
885 }
Chris Wailes488230c32014-08-14 11:22:40 -0700886 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700887}
888
Stephen Hines414fa2c2014-04-17 01:02:42 -0700889// Copies from the Allocation pointed to by srcAlloc into the Allocation
890// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -0700891static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800892nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800893 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700894 jint dstMip, jint dstFace,
895 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -0800896 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700897 jint srcMip, jint srcFace)
898{
Andreas Gampe67333922014-11-10 20:35:59 -0800899 if (kLogApi) {
900 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
901 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
902 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
903 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
904 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
905 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700906
Tim Murrayeff663f2013-11-15 13:08:30 -0800907 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700908 (RsAllocation)dstAlloc,
909 dstXoff, dstYoff,
910 dstMip, dstFace,
911 width, height,
912 (RsAllocation)srcAlloc,
913 srcXoff, srcYoff,
914 srcMip, srcFace);
915}
916
Stephen Hines414fa2c2014-04-17 01:02:42 -0700917// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700918static void
Tim Murray460a0492013-11-19 12:45:54 -0800919nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -0800920 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700921{
Jason Samse729a942013-11-06 11:22:02 -0800922 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800923 if (kLogApi) {
924 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
925 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
926 lod, w, h, d, sizeBytes);
927 }
Chris Wailes488230c32014-08-14 11:22:40 -0700928 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -0700929}
930
Stephen Hines414fa2c2014-04-17 01:02:42 -0700931// Copies from the Allocation pointed to by srcAlloc into the Allocation
932// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -0700933static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800934nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800935 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700936 jint dstMip,
937 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -0800938 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700939 jint srcMip)
940{
Andreas Gampe67333922014-11-10 20:35:59 -0800941 if (kLogApi) {
942 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
943 " dstMip(%i), width(%i), height(%i),"
944 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
945 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
946 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
947 }
Jason Samsb05d6892013-04-09 15:59:24 -0700948
Tim Murrayeff663f2013-11-15 13:08:30 -0800949 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -0700950 (RsAllocation)dstAlloc,
951 dstXoff, dstYoff, dstZoff, dstMip,
952 width, height, depth,
953 (RsAllocation)srcAlloc,
954 srcXoff, srcYoff, srcZoff, srcMip);
955}
956
Jason Sams21659ac2013-11-06 15:08:07 -0800957
Stephen Hines414fa2c2014-04-17 01:02:42 -0700958// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -0700959static void
Tim Murray460a0492013-11-19 12:45:54 -0800960nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700961{
Jason Sams21659ac2013-11-06 15:08:07 -0800962 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800963 if (kLogApi) {
964 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
965 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700966 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700967}
968
Stephen Hines414fa2c2014-04-17 01:02:42 -0700969// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -0700970static void
Tim Murray460a0492013-11-19 12:45:54 -0800971nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -0800972 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800973{
Jason Sams21659ac2013-11-06 15:08:07 -0800974 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800975 if (kLogApi) {
976 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
977 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
978 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700979 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800980}
981
Stephen Hines414fa2c2014-04-17 01:02:42 -0700982// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -0800983static void
Tim Murray460a0492013-11-19 12:45:54 -0800984nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -0800985 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800986{
Jason Sams21659ac2013-11-06 15:08:07 -0800987 RsAllocation *alloc = (RsAllocation *)_alloc;
988 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800989 if (kLogApi) {
990 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
991 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
992 }
993 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h,
994 ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700995}
Jason Samsd19f10d2009-05-22 14:03:28 -0700996
Tim Murray460a0492013-11-19 12:45:54 -0800997static jlong
998nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700999{
Andreas Gampe67333922014-11-10 20:35:59 -08001000 if (kLogApi) {
1001 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1002 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001003 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001004}
1005
Jason Sams5edc6082010-10-05 13:32:49 -07001006static void
Tim Murray460a0492013-11-19 12:45:54 -08001007nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001008{
Andreas Gampe67333922014-11-10 20:35:59 -08001009 if (kLogApi) {
1010 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1011 (RsAllocation)alloc, dimX);
1012 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001013 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001014}
1015
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001016// -----------------------------------
1017
Tim Murray460a0492013-11-19 12:45:54 -08001018static jlong
1019nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001020{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001021 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001022 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001023
Tim Murray3aa89c12014-08-18 17:51:22 -07001024 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001025 return id;
1026}
1027
Tim Murray460a0492013-11-19 12:45:54 -08001028static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001029nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001030{
1031 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001032 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001033 return 0;
1034 }
1035
1036 AutoJavaStringToUTF8 str(_env, _path);
1037 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001038 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001039 return 0;
1040 }
1041
Tim Murray3aa89c12014-08-18 17:51:22 -07001042 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001043 return id;
1044}
1045
Tim Murray460a0492013-11-19 12:45:54 -08001046static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001047nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001048{
1049 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001050 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001051
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001052 return id;
1053}
1054
Tim Murray460a0492013-11-19 12:45:54 -08001055static jint
1056nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001057{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001058 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001059 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001060 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001061}
1062
1063static void
Tim Murray460a0492013-11-19 12:45:54 -08001064nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001065{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001066 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001067 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1068
Tim Murrayeff663f2013-11-15 13:08:30 -08001069 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001070
1071 for(jint i = 0; i < numEntries; i ++) {
1072 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1073 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1074 }
1075
1076 free(fileEntries);
1077}
1078
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001079static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001080nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001081{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001082 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001083 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001084 return id;
1085}
Jason Samsd19f10d2009-05-22 14:03:28 -07001086
1087// -----------------------------------
1088
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001089static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001090nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001091 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001092{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001093 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001094 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001095 fileNameUTF.c_str(), fileNameUTF.length(),
1096 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001097
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001098 return id;
1099}
1100
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001101static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001102nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001103 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001104{
1105 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1106 AutoJavaStringToUTF8 nameUTF(_env, name);
1107
Tim Murray3aa89c12014-08-18 17:51:22 -07001108 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001109 nameUTF.c_str(), nameUTF.length(),
1110 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001111 asset->getBuffer(false), asset->getLength());
1112 return id;
1113}
1114
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001115static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001116nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001117 jfloat fontSize, jint dpi)
1118{
1119 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001120 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001121 return 0;
1122 }
1123
1124 AutoJavaStringToUTF8 str(_env, _path);
1125 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001126 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001127 return 0;
1128 }
1129
Tim Murray3aa89c12014-08-18 17:51:22 -07001130 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001131 str.c_str(), str.length(),
1132 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001133 asset->getBuffer(false), asset->getLength());
1134 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001135 return id;
1136}
1137
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001138// -----------------------------------
1139
1140static void
Tim Murray460a0492013-11-19 12:45:54 -08001141nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001142{
Andreas Gampe67333922014-11-10 20:35:59 -08001143 if (kLogApi) {
1144 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1145 (RsScript)script, (RsAllocation)alloc, slot);
1146 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001147 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001148}
1149
1150static void
Tim Murray460a0492013-11-19 12:45:54 -08001151nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001152{
Andreas Gampe67333922014-11-10 20:35:59 -08001153 if (kLogApi) {
1154 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1155 slot, val);
1156 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001157 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001158}
1159
Tim Murray7c4caad2013-04-10 16:21:40 -07001160static jint
Tim Murray460a0492013-11-19 12:45:54 -08001161nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001162{
Andreas Gampe67333922014-11-10 20:35:59 -08001163 if (kLogApi) {
1164 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1165 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001166 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001167 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001168 return value;
1169}
1170
Jason Sams4d339932010-05-11 14:03:58 -07001171static void
Tim Murray460a0492013-11-19 12:45:54 -08001172nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001173{
Andreas Gampe67333922014-11-10 20:35:59 -08001174 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001175 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001176 slot, val);
1177 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001178 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001179}
1180
1181static void
Tim Murray460a0492013-11-19 12:45:54 -08001182nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001183{
Andreas Gampe67333922014-11-10 20:35:59 -08001184 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001185 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001186 slot, val);
1187 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001188 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001189}
1190
Tim Murray7c4caad2013-04-10 16:21:40 -07001191static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001192nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001193{
Andreas Gampe67333922014-11-10 20:35:59 -08001194 if (kLogApi) {
1195 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1196 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001197 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001198 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001199 return value;
1200}
1201
Stephen Hines031ec58c2010-10-11 10:54:21 -07001202static void
Tim Murray460a0492013-11-19 12:45:54 -08001203nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001204{
Andreas Gampe67333922014-11-10 20:35:59 -08001205 if (kLogApi) {
1206 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1207 slot, val);
1208 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001209 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001210}
1211
Tim Murray7c4caad2013-04-10 16:21:40 -07001212static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001213nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001214{
Andreas Gampe67333922014-11-10 20:35:59 -08001215 if (kLogApi) {
1216 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1217 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001218 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001219 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001220 return value;
1221}
1222
Jason Sams4d339932010-05-11 14:03:58 -07001223static void
Tim Murray460a0492013-11-19 12:45:54 -08001224nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001225{
Andreas Gampe67333922014-11-10 20:35:59 -08001226 if (kLogApi) {
1227 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1228 slot, val);
1229 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001230 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001231}
1232
Tim Murray7c4caad2013-04-10 16:21:40 -07001233static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001234nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001235{
Andreas Gampe67333922014-11-10 20:35:59 -08001236 if (kLogApi) {
1237 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1238 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001239 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001240 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001241 return value;
1242}
1243
Stephen Hinesca54ec32010-09-20 17:20:30 -07001244static void
Tim Murray460a0492013-11-19 12:45:54 -08001245nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001246{
Andreas Gampe67333922014-11-10 20:35:59 -08001247 if (kLogApi) {
1248 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1249 }
Jason Sams4d339932010-05-11 14:03:58 -07001250 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001251 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001252 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001253 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1254}
1255
Stephen Hinesadeb8092012-04-20 14:26:06 -07001256static void
Tim Murray460a0492013-11-19 12:45:54 -08001257nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001258{
Andreas Gampe67333922014-11-10 20:35:59 -08001259 if (kLogApi) {
1260 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1261 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001262 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001263 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001264 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001265 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001266}
1267
1268static void
Andreas Gampe67333922014-11-10 20:35:59 -08001269nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1270 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001271{
Andreas Gampe67333922014-11-10 20:35:59 -08001272 if (kLogApi) {
1273 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1274 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001275 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001276 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001277 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001278 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001279 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001280 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001281 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1282 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1283}
1284
Jason Samsd19f10d2009-05-22 14:03:28 -07001285
1286static void
Tim Murray460a0492013-11-19 12:45:54 -08001287nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001288{
Andreas Gampe67333922014-11-10 20:35:59 -08001289 if (kLogApi) {
1290 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1291 }
Romain Guy584a3752009-07-30 18:45:01 -07001292
1293 jint length = _env->GetArrayLength(timeZone);
1294 jbyte* timeZone_ptr;
1295 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1296
Tim Murrayeff663f2013-11-15 13:08:30 -08001297 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001298
1299 if (timeZone_ptr) {
1300 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1301 }
1302}
1303
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001304static void
Tim Murray460a0492013-11-19 12:45:54 -08001305nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001306{
Andreas Gampe67333922014-11-10 20:35:59 -08001307 if (kLogApi) {
1308 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1309 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001310 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001311}
1312
1313static void
Tim Murray460a0492013-11-19 12:45:54 -08001314nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001315{
Andreas Gampe67333922014-11-10 20:35:59 -08001316 if (kLogApi) {
1317 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1318 }
Jason Sams4d339932010-05-11 14:03:58 -07001319 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001320 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001321 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001322 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1323}
1324
Jason Sams6e494d32011-04-27 16:33:11 -07001325static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001326nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1327 jlongArray ains, jlong aout, jbyteArray params,
1328 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001329{
Andreas Gampe67333922014-11-10 20:35:59 -08001330 if (kLogApi) {
1331 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1332 }
Jason Sams6e494d32011-04-27 16:33:11 -07001333
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001334 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001335 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001336
Chris Wailes488230c32014-08-14 11:22:40 -07001337 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001338
Chris Wailes488230c32014-08-14 11:22:40 -07001339 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001340 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001341 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001342
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001343 if (sizeof(RsAllocation) == sizeof(jlong)) {
1344 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001345
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001346 } else {
1347 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001348
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001349 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1350
1351 for (int index = in_len; --index >= 0;) {
1352 in_allocs[index] = (RsAllocation)in_ptr[index];
1353 }
1354 }
Chris Wailes94961062014-06-11 12:01:28 -07001355 }
1356
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001357 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001358 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001359
Chris Wailes488230c32014-08-14 11:22:40 -07001360 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001361 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001362 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001363 }
1364
Chris Wailes488230c32014-08-14 11:22:40 -07001365 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001366 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001367
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001368 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001369 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001370
Chris Wailes488230c32014-08-14 11:22:40 -07001371 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001372 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001373 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001374
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001375 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001376 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001377
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001378 sc.xStart = limit_ptr[0];
1379 sc.xEnd = limit_ptr[1];
1380 sc.yStart = limit_ptr[2];
1381 sc.yEnd = limit_ptr[3];
1382 sc.zStart = limit_ptr[4];
1383 sc.zEnd = limit_ptr[5];
1384 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001385 sc.arrayStart = 0;
1386 sc.arrayEnd = 0;
1387 sc.array2Start = 0;
1388 sc.array2End = 0;
1389 sc.array3Start = 0;
1390 sc.array3End = 0;
1391 sc.array4Start = 0;
1392 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001393
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001394 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001395 }
1396
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001397 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1398 in_allocs, in_len, (RsAllocation)aout,
1399 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001400
Chris Wailes488230c32014-08-14 11:22:40 -07001401 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001402 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001403 }
1404
Chris Wailes488230c32014-08-14 11:22:40 -07001405 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001406 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1407 }
1408
Chris Wailes488230c32014-08-14 11:22:40 -07001409 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001410 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1411 }
Chris Wailes94961062014-06-11 12:01:28 -07001412}
1413
Jason Sams22534172009-08-04 16:58:20 -07001414// -----------------------------------
1415
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001416static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001417nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001418 jstring resName, jstring cacheDir,
1419 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001420{
Andreas Gampe67333922014-11-10 20:35:59 -08001421 if (kLogApi) {
1422 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1423 }
Jason Sams22534172009-08-04 16:58:20 -07001424
Jason Samse4a06c52011-03-16 16:29:28 -07001425 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1426 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001427 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001428 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001429 jint _exception = 0;
1430 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001431 if (!scriptRef) {
1432 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001433 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001434 goto exit;
1435 }
Jack Palevich43702d82009-05-28 13:38:16 -07001436 if (length < 0) {
1437 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001438 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001439 goto exit;
1440 }
Jason Samse4a06c52011-03-16 16:29:28 -07001441 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001442 if (remaining < length) {
1443 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001444 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1445 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001446 goto exit;
1447 }
Jason Samse4a06c52011-03-16 16:29:28 -07001448 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001449 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001450
Tim Murrayeff663f2013-11-15 13:08:30 -08001451 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001452
Tim Murray3aa89c12014-08-18 17:51:22 -07001453 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001454 resNameUTF.c_str(), resNameUTF.length(),
1455 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001456 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001457
Jack Palevich43702d82009-05-28 13:38:16 -07001458exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001459 if (script_ptr) {
1460 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001461 _exception ? JNI_ABORT: 0);
1462 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001463
Tim Murray3aa89c12014-08-18 17:51:22 -07001464 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001465}
1466
Tim Murray460a0492013-11-19 12:45:54 -08001467static jlong
1468nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001469{
Andreas Gampe67333922014-11-10 20:35:59 -08001470 if (kLogApi) {
1471 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1472 (void *)eid);
1473 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001474 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001475}
1476
Tim Murray460a0492013-11-19 12:45:54 -08001477static jlong
1478nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001479{
Andreas Gampe67333922014-11-10 20:35:59 -08001480 if (kLogApi) {
1481 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1482 (void *)sid, slot, sig);
1483 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001484 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001485}
1486
Tim Murray460a0492013-11-19 12:45:54 -08001487static jlong
1488nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001489{
Andreas Gampe67333922014-11-10 20:35:59 -08001490 if (kLogApi) {
1491 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1492 slot);
1493 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001494 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001495}
1496
Tim Murray460a0492013-11-19 12:45:54 -08001497static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001498nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1499 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001500{
Andreas Gampe67333922014-11-10 20:35:59 -08001501 if (kLogApi) {
1502 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1503 }
Jason Sams08a81582012-09-18 12:32:10 -07001504
Ashok Bhat98071552014-02-12 09:54:43 +00001505 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001506 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001507 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1508 for(int i = 0; i < kernelsLen; ++i) {
1509 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1510 }
Jason Sams08a81582012-09-18 12:32:10 -07001511
Ashok Bhat98071552014-02-12 09:54:43 +00001512 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001513 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001514 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1515 for(int i = 0; i < srcLen; ++i) {
1516 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1517 }
Jason Sams08a81582012-09-18 12:32:10 -07001518
Ashok Bhat98071552014-02-12 09:54:43 +00001519 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001520 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001521 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1522 for(int i = 0; i < dstkLen; ++i) {
1523 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1524 }
1525
1526 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001527 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001528 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1529 for(int i = 0; i < dstfLen; ++i) {
1530 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1531 }
1532
1533 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001534 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001535 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1536 for(int i = 0; i < typesLen; ++i) {
1537 typesPtr[i] = (RsType)jTypesPtr[i];
1538 }
1539
Tim Murray3aa89c12014-08-18 17:51:22 -07001540 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001541 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1542 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1543 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1544 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1545 (RsType *)typesPtr, typesLen * sizeof(RsType));
1546
1547 free(kernelsPtr);
1548 free(srcPtr);
1549 free(dstkPtr);
1550 free(dstfPtr);
1551 free(typesPtr);
1552 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1553 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1554 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1555 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1556 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001557 return id;
1558}
1559
1560static void
Tim Murray460a0492013-11-19 12:45:54 -08001561nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001562{
Andreas Gampe67333922014-11-10 20:35:59 -08001563 if (kLogApi) {
1564 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1565 (void *)gid, (void *)kid, (void *)alloc);
1566 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001567 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001568}
1569
1570static void
Tim Murray460a0492013-11-19 12:45:54 -08001571nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001572{
Andreas Gampe67333922014-11-10 20:35:59 -08001573 if (kLogApi) {
1574 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1575 (void *)gid, (void *)kid, (void *)alloc);
1576 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001577 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001578}
1579
1580static void
Tim Murray460a0492013-11-19 12:45:54 -08001581nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001582{
Andreas Gampe67333922014-11-10 20:35:59 -08001583 if (kLogApi) {
1584 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1585 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001586 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001587}
1588
Jason Samsd19f10d2009-05-22 14:03:28 -07001589// ---------------------------------------------------------------------------
1590
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001591static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001592nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001593 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1594 jboolean depthMask, jboolean ditherEnable,
1595 jint srcFunc, jint destFunc,
1596 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001597{
Andreas Gampe67333922014-11-10 20:35:59 -08001598 if (kLogApi) {
1599 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1600 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001601 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001602 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1603 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001604}
1605
Jason Sams0011bcf2009-12-15 12:58:36 -08001606// ---------------------------------------------------------------------------
1607
1608static void
Tim Murray460a0492013-11-19 12:45:54 -08001609nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001610{
Andreas Gampe67333922014-11-10 20:35:59 -08001611 if (kLogApi) {
1612 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
1613 (RsProgramVertex)vpv, slot, (RsAllocation)a);
1614 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001615 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001616}
Jason Sams54c0ec12009-11-30 14:49:55 -08001617
Jason Sams68afd012009-12-17 16:55:08 -08001618static void
Tim Murray460a0492013-11-19 12:45:54 -08001619nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001620{
Andreas Gampe67333922014-11-10 20:35:59 -08001621 if (kLogApi) {
1622 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1623 (RsProgramFragment)vpf, slot, (RsAllocation)a);
1624 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001625 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001626}
1627
1628static void
Tim Murray460a0492013-11-19 12:45:54 -08001629nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001630{
Andreas Gampe67333922014-11-10 20:35:59 -08001631 if (kLogApi) {
1632 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1633 (RsProgramFragment)vpf, slot, (RsSampler)a);
1634 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001635 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001636}
1637
Jason Samsd19f10d2009-05-22 14:03:28 -07001638// ---------------------------------------------------------------------------
1639
Tim Murray460a0492013-11-19 12:45:54 -08001640static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001641nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001642 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001643{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001644 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001645 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001646 jint paramLen = _env->GetArrayLength(params);
1647
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001648 int texCount = _env->GetArrayLength(texNames);
1649 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1650 const char ** nameArray = names.c_str();
1651 size_t* sizeArray = names.c_str_len();
1652
Andreas Gampe67333922014-11-10 20:35:59 -08001653 if (kLogApi) {
1654 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1655 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001656
Ashok Bhat98071552014-02-12 09:54:43 +00001657 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1658 for(int i = 0; i < paramLen; ++i) {
1659 paramPtr[i] = (uintptr_t)jParamPtr[i];
1660 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001661 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001662 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001663 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001664
Ashok Bhat98071552014-02-12 09:54:43 +00001665 free(paramPtr);
1666 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001667 return ret;
1668}
1669
1670
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001671// ---------------------------------------------------------------------------
1672
Tim Murray460a0492013-11-19 12:45:54 -08001673static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001674nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001675 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001676{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001677 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001678 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001679 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001680
Andreas Gampe67333922014-11-10 20:35:59 -08001681 if (kLogApi) {
1682 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1683 }
Jason Sams0011bcf2009-12-15 12:58:36 -08001684
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001685 int texCount = _env->GetArrayLength(texNames);
1686 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1687 const char ** nameArray = names.c_str();
1688 size_t* sizeArray = names.c_str_len();
1689
Ashok Bhat98071552014-02-12 09:54:43 +00001690 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1691 for(int i = 0; i < paramLen; ++i) {
1692 paramPtr[i] = (uintptr_t)jParamPtr[i];
1693 }
1694
Tim Murray3aa89c12014-08-18 17:51:22 -07001695 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001696 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001697 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001698
Ashok Bhat98071552014-02-12 09:54:43 +00001699 free(paramPtr);
1700 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001701 return ret;
1702}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001703
Jason Samsebfb4362009-09-23 13:57:02 -07001704// ---------------------------------------------------------------------------
1705
Tim Murray460a0492013-11-19 12:45:54 -08001706static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001707nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001708{
Andreas Gampe67333922014-11-10 20:35:59 -08001709 if (kLogApi) {
1710 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
1711 pointSprite, cull);
1712 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001713 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001714}
1715
Jason Samsd19f10d2009-05-22 14:03:28 -07001716
1717// ---------------------------------------------------------------------------
1718
1719static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001720nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001721{
Andreas Gampe67333922014-11-10 20:35:59 -08001722 if (kLogApi) {
1723 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
1724 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001725 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001726}
1727
1728static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001729nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001730{
Andreas Gampe67333922014-11-10 20:35:59 -08001731 if (kLogApi) {
1732 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
1733 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001734 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001735}
1736
1737static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001738nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001739{
Andreas Gampe67333922014-11-10 20:35:59 -08001740 if (kLogApi) {
1741 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
1742 (RsProgramFragment)pf);
1743 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001744 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001745}
1746
Jason Sams0826a6f2009-06-15 19:04:56 -07001747static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001748nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001749{
Andreas Gampe67333922014-11-10 20:35:59 -08001750 if (kLogApi) {
1751 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
1752 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001753 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001754}
1755
Joe Onoratod7b37742009-08-09 22:57:44 -07001756static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001757nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001758{
Andreas Gampe67333922014-11-10 20:35:59 -08001759 if (kLogApi) {
1760 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
1761 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001762 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001763}
1764
Joe Onoratod7b37742009-08-09 22:57:44 -07001765
Jason Sams02fb2cb2009-05-28 15:37:57 -07001766// ---------------------------------------------------------------------------
1767
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001768static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001769nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001770 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001771{
Andreas Gampe67333922014-11-10 20:35:59 -08001772 if (kLogApi) {
1773 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
1774 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001775 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001776 (RsSamplerValue)magFilter,
1777 (RsSamplerValue)minFilter,
1778 (RsSamplerValue)wrapS,
1779 (RsSamplerValue)wrapT,
1780 (RsSamplerValue)wrapR,
1781 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001782}
1783
Jason Samsbba134c2009-06-22 15:49:21 -07001784// ---------------------------------------------------------------------------
1785
Tim Murray460a0492013-11-19 12:45:54 -08001786static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001787nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Andreas Gampe67333922014-11-10 20:35:59 -08001788 if (kLogApi) {
1789 ALOGD("nPathCreate, con(%p)", (RsContext)con);
1790 }
Jason Samsf15ed012011-10-31 13:23:43 -07001791
Tim Murray3aa89c12014-08-18 17:51:22 -07001792 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08001793 (RsAllocation)_vtx,
1794 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001795 return id;
1796}
1797
Tim Murray460a0492013-11-19 12:45:54 -08001798static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001799nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001800{
Andreas Gampe67333922014-11-10 20:35:59 -08001801 if (kLogApi) {
1802 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
1803 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001804
1805 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07001806 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001807 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1808 for(int i = 0; i < vtxLen; ++i) {
1809 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1810 }
1811
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001812 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07001813 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001814 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1815 for(int i = 0; i < idxLen; ++i) {
1816 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1817 }
1818
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001819 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07001820 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001821
Tim Murray3aa89c12014-08-18 17:51:22 -07001822 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001823 (RsAllocation *)vtxPtr, vtxLen,
1824 (RsAllocation *)idxPtr, idxLen,
1825 (uint32_t *)primPtr, primLen);
1826
Ashok Bhat98071552014-02-12 09:54:43 +00001827 free(vtxPtr);
1828 free(idxPtr);
1829 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1830 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001831 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001832 return id;
1833}
1834
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001835static jint
Tim Murray460a0492013-11-19 12:45:54 -08001836nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001837{
Andreas Gampe67333922014-11-10 20:35:59 -08001838 if (kLogApi) {
1839 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1840 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001841 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001842 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001843 return vtxCount;
1844}
1845
1846static jint
Tim Murray460a0492013-11-19 12:45:54 -08001847nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001848{
Andreas Gampe67333922014-11-10 20:35:59 -08001849 if (kLogApi) {
1850 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1851 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001852 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001853 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001854 return idxCount;
1855}
1856
1857static void
Ashok Bhat98071552014-02-12 09:54:43 +00001858nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001859{
Andreas Gampe67333922014-11-10 20:35:59 -08001860 if (kLogApi) {
1861 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1862 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001863
1864 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001865 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001866
1867 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001868 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001869 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001870 }
1871
1872 free(allocs);
1873}
1874
1875static void
Ashok Bhat98071552014-02-12 09:54:43 +00001876nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001877{
Andreas Gampe67333922014-11-10 20:35:59 -08001878 if (kLogApi) {
1879 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1880 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001881
1882 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1883 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1884
Tim Murrayeff663f2013-11-15 13:08:30 -08001885 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001886
1887 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001888 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001889 const jint prim = (jint)prims[i];
1890 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1891 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001892 }
1893
1894 free(allocs);
1895 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001896}
1897
Tim Murray56f9e6f2014-05-16 11:47:26 -07001898static jint
1899nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1900 return (jint)sizeof(void*);
1901}
1902
1903
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001904// ---------------------------------------------------------------------------
1905
Jason Samsd19f10d2009-05-22 14:03:28 -07001906
Jason Sams94d8e90a2009-06-10 16:09:05 -07001907static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001908
1909static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001910{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001911
Tim Murrayeff663f2013-11-15 13:08:30 -08001912{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1913{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1914{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1915{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1916{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1917{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001918
Tim Murrayeff663f2013-11-15 13:08:30 -08001919{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1920{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001921
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001922
Jason Sams2e1872f2010-08-17 16:25:41 -07001923// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001924{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1925{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1926{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1927{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1928{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1929{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1930{"rsnContextDump", "(JI)V", (void*)nContextDump },
1931{"rsnContextPause", "(J)V", (void*)nContextPause },
1932{"rsnContextResume", "(J)V", (void*)nContextResume },
1933{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07001934{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
1935{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
1936{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08001937{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1938{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1939{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001940
Tim Murray460a0492013-11-19 12:45:54 -08001941{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001942{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001943{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1944{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1945{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001946{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001947
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001948{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1949{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1950{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001951
Tim Murray460a0492013-11-19 12:45:54 -08001952{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001953{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001954{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001955{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001956
Tim Murray460a0492013-11-19 12:45:54 -08001957{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001958{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001959
Ashok Bhat98071552014-02-12 09:54:43 +00001960{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001961{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1962{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1963{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001964
Tim Murray460a0492013-11-19 12:45:54 -08001965{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1966{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001967
Tim Murray460a0492013-11-19 12:45:54 -08001968{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1969{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1970{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1971{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1972{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1973{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1974{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1975{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1976{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1977{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1978{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1979{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1980{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1981{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1982{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1983{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1984{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001985
Tim Murray460a0492013-11-19 12:45:54 -08001986{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1987{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1988{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1989{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001990
1991{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
1992
Tim Murray460a0492013-11-19 12:45:54 -08001993{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1994{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1995{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1996{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1997{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1998{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1999{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2000{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2001{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2002{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2003{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2004{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002005
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002006{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002007{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2008{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
2009{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002010{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002011{"rsnScriptGroup2Create", "(J[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002012{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2013{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2014{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002015{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002016
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002017{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002018
Tim Murray460a0492013-11-19 12:45:54 -08002019{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2020{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2021{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002022
Ashok Bhat98071552014-02-12 09:54:43 +00002023{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002024{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002025{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002026
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002027{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2028{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2029{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2030{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2031{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002032
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002033{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002034
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002035{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002036{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002037
Tim Murray460a0492013-11-19 12:45:54 -08002038{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2039{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002040{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2041{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002042
Tim Murray56f9e6f2014-05-16 11:47:26 -07002043{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002044};
2045
2046static int registerFuncs(JNIEnv *_env)
2047{
2048 return android::AndroidRuntime::registerNativeMethods(
2049 _env, classPathName, methods, NELEM(methods));
2050}
2051
2052// ---------------------------------------------------------------------------
2053
2054jint JNI_OnLoad(JavaVM* vm, void* reserved)
2055{
Chris Wailes488230c32014-08-14 11:22:40 -07002056 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002057 jint result = -1;
2058
Jason Samsd19f10d2009-05-22 14:03:28 -07002059 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002060 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002061 goto bail;
2062 }
Chris Wailes488230c32014-08-14 11:22:40 -07002063 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002064
2065 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002066 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002067 goto bail;
2068 }
2069
2070 /* success -- return valid version number */
2071 result = JNI_VERSION_1_4;
2072
2073bail:
2074 return result;
2075}