blob: dced99a73c6ceb06a8a02a794c27c535a1a550b6 [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;
Chris Wailes94961062014-06-11 12:01:28 -07001385
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001386 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001387 }
1388
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001389 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1390 in_allocs, in_len, (RsAllocation)aout,
1391 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001392
Chris Wailes488230c32014-08-14 11:22:40 -07001393 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001394 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001395 }
1396
Chris Wailes488230c32014-08-14 11:22:40 -07001397 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001398 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1399 }
1400
Chris Wailes488230c32014-08-14 11:22:40 -07001401 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001402 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1403 }
Chris Wailes94961062014-06-11 12:01:28 -07001404}
1405
Jason Sams22534172009-08-04 16:58:20 -07001406// -----------------------------------
1407
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001408static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001409nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001410 jstring resName, jstring cacheDir,
1411 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001412{
Andreas Gampe67333922014-11-10 20:35:59 -08001413 if (kLogApi) {
1414 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1415 }
Jason Sams22534172009-08-04 16:58:20 -07001416
Jason Samse4a06c52011-03-16 16:29:28 -07001417 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1418 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001419 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001420 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001421 jint _exception = 0;
1422 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001423 if (!scriptRef) {
1424 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001425 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001426 goto exit;
1427 }
Jack Palevich43702d82009-05-28 13:38:16 -07001428 if (length < 0) {
1429 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001430 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001431 goto exit;
1432 }
Jason Samse4a06c52011-03-16 16:29:28 -07001433 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001434 if (remaining < length) {
1435 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001436 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1437 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001438 goto exit;
1439 }
Jason Samse4a06c52011-03-16 16:29:28 -07001440 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001441 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001442
Tim Murrayeff663f2013-11-15 13:08:30 -08001443 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001444
Tim Murray3aa89c12014-08-18 17:51:22 -07001445 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001446 resNameUTF.c_str(), resNameUTF.length(),
1447 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001448 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001449
Jack Palevich43702d82009-05-28 13:38:16 -07001450exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001451 if (script_ptr) {
1452 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001453 _exception ? JNI_ABORT: 0);
1454 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001455
Tim Murray3aa89c12014-08-18 17:51:22 -07001456 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001457}
1458
Tim Murray460a0492013-11-19 12:45:54 -08001459static jlong
1460nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001461{
Andreas Gampe67333922014-11-10 20:35:59 -08001462 if (kLogApi) {
1463 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1464 (void *)eid);
1465 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001466 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001467}
1468
Tim Murray460a0492013-11-19 12:45:54 -08001469static jlong
1470nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001471{
Andreas Gampe67333922014-11-10 20:35:59 -08001472 if (kLogApi) {
1473 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1474 (void *)sid, slot, sig);
1475 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001476 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001477}
1478
Tim Murray460a0492013-11-19 12:45:54 -08001479static jlong
1480nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001481{
Andreas Gampe67333922014-11-10 20:35:59 -08001482 if (kLogApi) {
1483 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1484 slot);
1485 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001486 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001487}
1488
Tim Murray460a0492013-11-19 12:45:54 -08001489static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001490nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1491 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001492{
Andreas Gampe67333922014-11-10 20:35:59 -08001493 if (kLogApi) {
1494 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1495 }
Jason Sams08a81582012-09-18 12:32:10 -07001496
Ashok Bhat98071552014-02-12 09:54:43 +00001497 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001498 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001499 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1500 for(int i = 0; i < kernelsLen; ++i) {
1501 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1502 }
Jason Sams08a81582012-09-18 12:32:10 -07001503
Ashok Bhat98071552014-02-12 09:54:43 +00001504 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001505 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001506 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1507 for(int i = 0; i < srcLen; ++i) {
1508 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1509 }
Jason Sams08a81582012-09-18 12:32:10 -07001510
Ashok Bhat98071552014-02-12 09:54:43 +00001511 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001512 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001513 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1514 for(int i = 0; i < dstkLen; ++i) {
1515 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1516 }
1517
1518 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001519 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001520 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1521 for(int i = 0; i < dstfLen; ++i) {
1522 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1523 }
1524
1525 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001526 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001527 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1528 for(int i = 0; i < typesLen; ++i) {
1529 typesPtr[i] = (RsType)jTypesPtr[i];
1530 }
1531
Tim Murray3aa89c12014-08-18 17:51:22 -07001532 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001533 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1534 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1535 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1536 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1537 (RsType *)typesPtr, typesLen * sizeof(RsType));
1538
1539 free(kernelsPtr);
1540 free(srcPtr);
1541 free(dstkPtr);
1542 free(dstfPtr);
1543 free(typesPtr);
1544 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1545 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1546 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1547 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1548 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001549 return id;
1550}
1551
1552static void
Tim Murray460a0492013-11-19 12:45:54 -08001553nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001554{
Andreas Gampe67333922014-11-10 20:35:59 -08001555 if (kLogApi) {
1556 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1557 (void *)gid, (void *)kid, (void *)alloc);
1558 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001559 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001560}
1561
1562static void
Tim Murray460a0492013-11-19 12:45:54 -08001563nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001564{
Andreas Gampe67333922014-11-10 20:35:59 -08001565 if (kLogApi) {
1566 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1567 (void *)gid, (void *)kid, (void *)alloc);
1568 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001569 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001570}
1571
1572static void
Tim Murray460a0492013-11-19 12:45:54 -08001573nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001574{
Andreas Gampe67333922014-11-10 20:35:59 -08001575 if (kLogApi) {
1576 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1577 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001578 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001579}
1580
Jason Samsd19f10d2009-05-22 14:03:28 -07001581// ---------------------------------------------------------------------------
1582
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001583static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001584nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001585 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1586 jboolean depthMask, jboolean ditherEnable,
1587 jint srcFunc, jint destFunc,
1588 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001589{
Andreas Gampe67333922014-11-10 20:35:59 -08001590 if (kLogApi) {
1591 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1592 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001593 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001594 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1595 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001596}
1597
Jason Sams0011bcf2009-12-15 12:58:36 -08001598// ---------------------------------------------------------------------------
1599
1600static void
Tim Murray460a0492013-11-19 12:45:54 -08001601nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001602{
Andreas Gampe67333922014-11-10 20:35:59 -08001603 if (kLogApi) {
1604 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
1605 (RsProgramVertex)vpv, slot, (RsAllocation)a);
1606 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001607 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001608}
Jason Sams54c0ec12009-11-30 14:49:55 -08001609
Jason Sams68afd012009-12-17 16:55:08 -08001610static void
Tim Murray460a0492013-11-19 12:45:54 -08001611nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001612{
Andreas Gampe67333922014-11-10 20:35:59 -08001613 if (kLogApi) {
1614 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1615 (RsProgramFragment)vpf, slot, (RsAllocation)a);
1616 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001617 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001618}
1619
1620static void
Tim Murray460a0492013-11-19 12:45:54 -08001621nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001622{
Andreas Gampe67333922014-11-10 20:35:59 -08001623 if (kLogApi) {
1624 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1625 (RsProgramFragment)vpf, slot, (RsSampler)a);
1626 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001627 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001628}
1629
Jason Samsd19f10d2009-05-22 14:03:28 -07001630// ---------------------------------------------------------------------------
1631
Tim Murray460a0492013-11-19 12:45:54 -08001632static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001633nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001634 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001635{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001636 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001637 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001638 jint paramLen = _env->GetArrayLength(params);
1639
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001640 int texCount = _env->GetArrayLength(texNames);
1641 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1642 const char ** nameArray = names.c_str();
1643 size_t* sizeArray = names.c_str_len();
1644
Andreas Gampe67333922014-11-10 20:35:59 -08001645 if (kLogApi) {
1646 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1647 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001648
Ashok Bhat98071552014-02-12 09:54:43 +00001649 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1650 for(int i = 0; i < paramLen; ++i) {
1651 paramPtr[i] = (uintptr_t)jParamPtr[i];
1652 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001653 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001654 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001655 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001656
Ashok Bhat98071552014-02-12 09:54:43 +00001657 free(paramPtr);
1658 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001659 return ret;
1660}
1661
1662
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001663// ---------------------------------------------------------------------------
1664
Tim Murray460a0492013-11-19 12:45:54 -08001665static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001666nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001667 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001668{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001669 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001670 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001671 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001672
Andreas Gampe67333922014-11-10 20:35:59 -08001673 if (kLogApi) {
1674 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1675 }
Jason Sams0011bcf2009-12-15 12:58:36 -08001676
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001677 int texCount = _env->GetArrayLength(texNames);
1678 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1679 const char ** nameArray = names.c_str();
1680 size_t* sizeArray = names.c_str_len();
1681
Ashok Bhat98071552014-02-12 09:54:43 +00001682 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1683 for(int i = 0; i < paramLen; ++i) {
1684 paramPtr[i] = (uintptr_t)jParamPtr[i];
1685 }
1686
Tim Murray3aa89c12014-08-18 17:51:22 -07001687 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001688 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001689 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001690
Ashok Bhat98071552014-02-12 09:54:43 +00001691 free(paramPtr);
1692 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001693 return ret;
1694}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001695
Jason Samsebfb4362009-09-23 13:57:02 -07001696// ---------------------------------------------------------------------------
1697
Tim Murray460a0492013-11-19 12:45:54 -08001698static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001699nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001700{
Andreas Gampe67333922014-11-10 20:35:59 -08001701 if (kLogApi) {
1702 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
1703 pointSprite, cull);
1704 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001705 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001706}
1707
Jason Samsd19f10d2009-05-22 14:03:28 -07001708
1709// ---------------------------------------------------------------------------
1710
1711static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001712nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001713{
Andreas Gampe67333922014-11-10 20:35:59 -08001714 if (kLogApi) {
1715 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
1716 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001717 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001718}
1719
1720static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001721nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001722{
Andreas Gampe67333922014-11-10 20:35:59 -08001723 if (kLogApi) {
1724 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
1725 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001726 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001727}
1728
1729static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001730nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001731{
Andreas Gampe67333922014-11-10 20:35:59 -08001732 if (kLogApi) {
1733 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
1734 (RsProgramFragment)pf);
1735 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001736 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001737}
1738
Jason Sams0826a6f2009-06-15 19:04:56 -07001739static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001740nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001741{
Andreas Gampe67333922014-11-10 20:35:59 -08001742 if (kLogApi) {
1743 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
1744 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001745 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001746}
1747
Joe Onoratod7b37742009-08-09 22:57:44 -07001748static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001749nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001750{
Andreas Gampe67333922014-11-10 20:35:59 -08001751 if (kLogApi) {
1752 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
1753 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001754 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001755}
1756
Joe Onoratod7b37742009-08-09 22:57:44 -07001757
Jason Sams02fb2cb2009-05-28 15:37:57 -07001758// ---------------------------------------------------------------------------
1759
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001760static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001761nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001762 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001763{
Andreas Gampe67333922014-11-10 20:35:59 -08001764 if (kLogApi) {
1765 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
1766 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001767 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001768 (RsSamplerValue)magFilter,
1769 (RsSamplerValue)minFilter,
1770 (RsSamplerValue)wrapS,
1771 (RsSamplerValue)wrapT,
1772 (RsSamplerValue)wrapR,
1773 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001774}
1775
Jason Samsbba134c2009-06-22 15:49:21 -07001776// ---------------------------------------------------------------------------
1777
Tim Murray460a0492013-11-19 12:45:54 -08001778static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001779nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Andreas Gampe67333922014-11-10 20:35:59 -08001780 if (kLogApi) {
1781 ALOGD("nPathCreate, con(%p)", (RsContext)con);
1782 }
Jason Samsf15ed012011-10-31 13:23:43 -07001783
Tim Murray3aa89c12014-08-18 17:51:22 -07001784 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08001785 (RsAllocation)_vtx,
1786 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001787 return id;
1788}
1789
Tim Murray460a0492013-11-19 12:45:54 -08001790static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001791nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001792{
Andreas Gampe67333922014-11-10 20:35:59 -08001793 if (kLogApi) {
1794 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
1795 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001796
1797 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07001798 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001799 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1800 for(int i = 0; i < vtxLen; ++i) {
1801 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1802 }
1803
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001804 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07001805 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001806 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1807 for(int i = 0; i < idxLen; ++i) {
1808 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1809 }
1810
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001811 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07001812 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001813
Tim Murray3aa89c12014-08-18 17:51:22 -07001814 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001815 (RsAllocation *)vtxPtr, vtxLen,
1816 (RsAllocation *)idxPtr, idxLen,
1817 (uint32_t *)primPtr, primLen);
1818
Ashok Bhat98071552014-02-12 09:54:43 +00001819 free(vtxPtr);
1820 free(idxPtr);
1821 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1822 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001823 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001824 return id;
1825}
1826
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001827static jint
Tim Murray460a0492013-11-19 12:45:54 -08001828nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001829{
Andreas Gampe67333922014-11-10 20:35:59 -08001830 if (kLogApi) {
1831 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1832 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001833 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001834 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001835 return vtxCount;
1836}
1837
1838static jint
Tim Murray460a0492013-11-19 12:45:54 -08001839nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001840{
Andreas Gampe67333922014-11-10 20:35:59 -08001841 if (kLogApi) {
1842 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1843 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001844 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001845 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001846 return idxCount;
1847}
1848
1849static void
Ashok Bhat98071552014-02-12 09:54:43 +00001850nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001851{
Andreas Gampe67333922014-11-10 20:35:59 -08001852 if (kLogApi) {
1853 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1854 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001855
1856 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001857 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001858
1859 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001860 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001861 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001862 }
1863
1864 free(allocs);
1865}
1866
1867static void
Ashok Bhat98071552014-02-12 09:54:43 +00001868nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001869{
Andreas Gampe67333922014-11-10 20:35:59 -08001870 if (kLogApi) {
1871 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1872 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001873
1874 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1875 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1876
Tim Murrayeff663f2013-11-15 13:08:30 -08001877 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001878
1879 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001880 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001881 const jint prim = (jint)prims[i];
1882 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1883 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001884 }
1885
1886 free(allocs);
1887 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001888}
1889
Tim Murray56f9e6f2014-05-16 11:47:26 -07001890static jint
1891nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1892 return (jint)sizeof(void*);
1893}
1894
1895
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001896// ---------------------------------------------------------------------------
1897
Jason Samsd19f10d2009-05-22 14:03:28 -07001898
Jason Sams94d8e90a2009-06-10 16:09:05 -07001899static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001900
1901static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001902{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001903
Tim Murrayeff663f2013-11-15 13:08:30 -08001904{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1905{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1906{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1907{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1908{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1909{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001910
Tim Murrayeff663f2013-11-15 13:08:30 -08001911{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1912{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001913
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001914
Jason Sams2e1872f2010-08-17 16:25:41 -07001915// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001916{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1917{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1918{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1919{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1920{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1921{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1922{"rsnContextDump", "(JI)V", (void*)nContextDump },
1923{"rsnContextPause", "(J)V", (void*)nContextPause },
1924{"rsnContextResume", "(J)V", (void*)nContextResume },
1925{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07001926{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
1927{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
1928{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08001929{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1930{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1931{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001932
Tim Murray460a0492013-11-19 12:45:54 -08001933{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001934{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001935{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1936{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1937{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001938{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001939
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001940{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1941{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1942{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001943
Tim Murray460a0492013-11-19 12:45:54 -08001944{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001945{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001946{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001947{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001948
Tim Murray460a0492013-11-19 12:45:54 -08001949{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001950{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001951
Ashok Bhat98071552014-02-12 09:54:43 +00001952{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001953{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1954{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1955{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001956
Tim Murray460a0492013-11-19 12:45:54 -08001957{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1958{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001959
Tim Murray460a0492013-11-19 12:45:54 -08001960{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1961{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1962{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1963{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1964{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1965{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1966{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1967{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1968{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1969{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1970{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1971{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1972{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1973{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1974{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1975{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1976{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001977
Tim Murray460a0492013-11-19 12:45:54 -08001978{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1979{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1980{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1981{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001982
1983{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
1984
Tim Murray460a0492013-11-19 12:45:54 -08001985{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1986{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1987{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1988{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1989{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1990{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1991{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
1992{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
1993{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
1994{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
1995{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
1996{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001997
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001998{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001999{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2000{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
2001{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002002{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002003{"rsnScriptGroup2Create", "(J[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002004{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2005{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2006{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002007{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002008
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002009{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002010
Tim Murray460a0492013-11-19 12:45:54 -08002011{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2012{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2013{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002014
Ashok Bhat98071552014-02-12 09:54:43 +00002015{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002016{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002017{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002018
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002019{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2020{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2021{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2022{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2023{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002024
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002025{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002026
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002027{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002028{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002029
Tim Murray460a0492013-11-19 12:45:54 -08002030{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2031{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002032{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2033{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002034
Tim Murray56f9e6f2014-05-16 11:47:26 -07002035{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002036};
2037
2038static int registerFuncs(JNIEnv *_env)
2039{
2040 return android::AndroidRuntime::registerNativeMethods(
2041 _env, classPathName, methods, NELEM(methods));
2042}
2043
2044// ---------------------------------------------------------------------------
2045
2046jint JNI_OnLoad(JavaVM* vm, void* reserved)
2047{
Chris Wailes488230c32014-08-14 11:22:40 -07002048 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002049 jint result = -1;
2050
Jason Samsd19f10d2009-05-22 14:03:28 -07002051 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002052 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002053 goto bail;
2054 }
Chris Wailes488230c32014-08-14 11:22:40 -07002055 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002056
2057 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002058 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002059 goto bail;
2060 }
2061
2062 /* success -- return valid version number */
2063 result = JNI_VERSION_1_4;
2064
2065bail:
2066 return result;
2067}