blob: ff37150c1511ac3b2e59d3a0cdaed0cad5861647 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070025
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050026#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070027
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080028#include <androidfw/Asset.h>
29#include <androidfw/AssetManager.h>
30#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070031
Jason Samsd19f10d2009-05-22 14:03:28 -070032#include "jni.h"
33#include "JNIHelp.h"
34#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070035#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080036#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070037
Jason Sams1d6983a2012-02-16 16:07:49 -080038#include <rs.h>
39#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070040#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080041#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080042#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070043#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070044
Steve Block3762c312012-01-06 19:20:56 +000045//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080046static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070047
48using namespace android;
49
Andreas Gampe67333922014-11-10 20:35:59 -080050template <typename... T>
51void UNUSED(T... t) {}
52
Stephen Hines414fa2c2014-04-17 01:02:42 -070053#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080054 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070055 void *ptr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080056 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070057 jint relFlag = 0; \
58 if (readonly) { \
59 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
60 relFlag = JNI_ABORT; \
61 } \
Jason Samse729a942013-11-06 11:22:02 -080062 switch(dataType) { \
63 case RS_TYPE_FLOAT_32: \
64 len = _env->GetArrayLength((jfloatArray)data); \
65 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080066 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080067 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070068 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080069 return; \
70 case RS_TYPE_FLOAT_64: \
71 len = _env->GetArrayLength((jdoubleArray)data); \
72 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080073 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -080074 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070075 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080076 return; \
77 case RS_TYPE_SIGNED_8: \
78 case RS_TYPE_UNSIGNED_8: \
79 len = _env->GetArrayLength((jbyteArray)data); \
80 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080081 typeBytes = 1; \
Jason Samse729a942013-11-06 11:22:02 -080082 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070083 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080084 return; \
85 case RS_TYPE_SIGNED_16: \
86 case RS_TYPE_UNSIGNED_16: \
87 len = _env->GetArrayLength((jshortArray)data); \
88 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080089 typeBytes = 2; \
Jason Samse729a942013-11-06 11:22:02 -080090 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070091 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080092 return; \
93 case RS_TYPE_SIGNED_32: \
94 case RS_TYPE_UNSIGNED_32: \
95 len = _env->GetArrayLength((jintArray)data); \
96 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080097 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080098 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070099 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800100 return; \
101 case RS_TYPE_SIGNED_64: \
102 case RS_TYPE_UNSIGNED_64: \
103 len = _env->GetArrayLength((jlongArray)data); \
104 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800105 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -0800106 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700107 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800108 return; \
109 default: \
110 break; \
111 } \
Andreas Gampe67333922014-11-10 20:35:59 -0800112 UNUSED(len, ptr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800113}
114
115
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800116class AutoJavaStringToUTF8 {
117public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800118 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700119 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800120 fLength = env->GetStringUTFLength(str);
121 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800122 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800123 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
124 }
125 const char* c_str() const { return fCStr; }
126 jsize length() const { return fLength; }
127
128private:
129 JNIEnv* fEnv;
130 jstring fJStr;
131 const char* fCStr;
132 jsize fLength;
133};
134
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800135class AutoJavaStringArrayToUTF8 {
136public:
137 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
138 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700139 mCStrings = nullptr;
140 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800141 if (stringsLength > 0) {
142 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
143 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
144 for (jsize ct = 0; ct < stringsLength; ct ++) {
145 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700146 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800147 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
148 }
149 }
150 }
151 ~AutoJavaStringArrayToUTF8() {
152 for (jsize ct=0; ct < mStringsLength; ct++) {
153 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
154 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
155 }
156 free(mCStrings);
157 free(mSizeArray);
158 }
159 const char **c_str() const { return mCStrings; }
160 size_t *c_str_len() const { return mSizeArray; }
161 jsize length() const { return mStringsLength; }
162
163private:
164 JNIEnv *mEnv;
165 jobjectArray mStrings;
166 const char **mCStrings;
167 size_t *mSizeArray;
168 jsize mStringsLength;
169};
170
Jason Samsd19f10d2009-05-22 14:03:28 -0700171// ---------------------------------------------------------------------------
172
Jason Samsffe9f482009-06-01 17:45:53 -0700173static jfieldID gContextId = 0;
174static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700175
176static void _nInit(JNIEnv *_env, jclass _this)
177{
Tim Murrayeff663f2013-11-15 13:08:30 -0800178 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700179
180 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000181 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700182}
183
Jason Samsd19f10d2009-05-22 14:03:28 -0700184// ---------------------------------------------------------------------------
185
Jason Sams3eaa338e2009-06-10 15:04:38 -0700186static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800187nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700188{
Andreas Gampe67333922014-11-10 20:35:59 -0800189 if (kLogApi) {
190 ALOGD("nContextFinish, con(%p)", (RsContext)con);
191 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800192 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700193}
194
195static void
Tim Murray460a0492013-11-19 12:45:54 -0800196nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700197{
Andreas Gampe67333922014-11-10 20:35:59 -0800198 if (kLogApi) {
199 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
200 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700201 jint len = _env->GetArrayLength(str);
202 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800203 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700204 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
205}
206
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700207static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800208nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700209{
Andreas Gampe67333922014-11-10 20:35:59 -0800210 if (kLogApi) {
211 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
212 }
Chris Wailes488230c32014-08-14 11:22:40 -0700213 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800214 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700215 if(name == nullptr || strlen(name) == 0) {
216 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700217 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700218 return _env->NewStringUTF(name);
219}
220
Jason Sams7ce033d2009-08-18 14:14:24 -0700221static void
Tim Murray460a0492013-11-19 12:45:54 -0800222nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700223{
Andreas Gampe67333922014-11-10 20:35:59 -0800224 if (kLogApi) {
225 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
226 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800227 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700228}
229
Jason Sams3eaa338e2009-06-10 15:04:38 -0700230// ---------------------------------------------------------------------------
231
Tim Murrayeff663f2013-11-15 13:08:30 -0800232static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700233nDeviceCreate(JNIEnv *_env, jobject _this)
234{
Andreas Gampe67333922014-11-10 20:35:59 -0800235 if (kLogApi) {
236 ALOGD("nDeviceCreate");
237 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700238 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700239}
240
241static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800242nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700243{
Andreas Gampe67333922014-11-10 20:35:59 -0800244 if (kLogApi) {
245 ALOGD("nDeviceDestroy");
246 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700247 return rsDeviceDestroy((RsDevice)dev);
248}
249
Jason Samsebfb4362009-09-23 13:57:02 -0700250static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800251nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700252{
Andreas Gampe67333922014-11-10 20:35:59 -0800253 if (kLogApi) {
254 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
255 }
Jason Samsebfb4362009-09-23 13:57:02 -0700256 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
257}
258
Tim Murrayeff663f2013-11-15 13:08:30 -0800259static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800260nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700261{
Andreas Gampe67333922014-11-10 20:35:59 -0800262 if (kLogApi) {
263 ALOGD("nContextCreate");
264 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700265 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0);
Jason Sams704ff642010-02-09 16:05:07 -0800266}
267
Tim Murrayeff663f2013-11-15 13:08:30 -0800268static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800269nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000270 jint colorMin, jint colorPref,
271 jint alphaMin, jint alphaPref,
272 jint depthMin, jint depthPref,
273 jint stencilMin, jint stencilPref,
274 jint samplesMin, jint samplesPref, jfloat samplesQ,
275 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800276{
Jason Sams11c8af92010-10-13 15:31:10 -0700277 RsSurfaceConfig sc;
278 sc.alphaMin = alphaMin;
279 sc.alphaPref = alphaPref;
280 sc.colorMin = colorMin;
281 sc.colorPref = colorPref;
282 sc.depthMin = depthMin;
283 sc.depthPref = depthPref;
284 sc.samplesMin = samplesMin;
285 sc.samplesPref = samplesPref;
286 sc.samplesQ = samplesQ;
287
Andreas Gampe67333922014-11-10 20:35:59 -0800288 if (kLogApi) {
289 ALOGD("nContextCreateGL");
290 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700291 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700292}
293
294static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800295nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800296{
Andreas Gampe67333922014-11-10 20:35:59 -0800297 if (kLogApi) {
298 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
299 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800300 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800301}
302
303
304
305static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800306nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800307{
Andreas Gampe67333922014-11-10 20:35:59 -0800308 if (kLogApi) {
309 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
310 width, height, (Surface *)wnd);
311 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800312
Chris Wailes488230c32014-08-14 11:22:40 -0700313 ANativeWindow * window = nullptr;
314 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800315
316 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700317 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800318 }
319
Tim Murrayeff663f2013-11-15 13:08:30 -0800320 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800321}
322
323static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800324nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700325{
Andreas Gampe67333922014-11-10 20:35:59 -0800326 if (kLogApi) {
327 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
328 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800329 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700330}
331
Jason Sams715333b2009-11-17 17:26:46 -0800332static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800333nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800334{
Andreas Gampe67333922014-11-10 20:35:59 -0800335 if (kLogApi) {
336 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
337 }
Jason Sams715333b2009-11-17 17:26:46 -0800338 rsContextDump((RsContext)con, bits);
339}
Jason Samsd19f10d2009-05-22 14:03:28 -0700340
341static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800342nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700343{
Andreas Gampe67333922014-11-10 20:35:59 -0800344 if (kLogApi) {
345 ALOGD("nContextPause, con(%p)", (RsContext)con);
346 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800347 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700348}
349
350static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800351nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700352{
Andreas Gampe67333922014-11-10 20:35:59 -0800353 if (kLogApi) {
354 ALOGD("nContextResume, con(%p)", (RsContext)con);
355 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800356 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700357}
358
Jason Sams1c415172010-11-08 17:06:46 -0800359
360static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800361nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800362{
Andreas Gampe67333922014-11-10 20:35:59 -0800363 if (kLogApi) {
364 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
365 }
Jason Sams1c415172010-11-08 17:06:46 -0800366 char buf[1024];
367
368 size_t receiveLen;
369 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800370 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700371 buf, sizeof(buf),
372 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700373 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800374 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100375 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800376 }
377 return _env->NewStringUTF(buf);
378}
379
Jason Samsedbfabd2011-05-17 15:01:29 -0700380static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800381nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700382{
Jason Sams516c3192009-10-06 13:58:47 -0700383 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800384 if (kLogApi) {
385 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
386 }
Chris Wailes488230c32014-08-14 11:22:40 -0700387 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700388 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800389 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800390 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700391 ptr, len * 4,
392 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700393 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700394 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100395 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700396 }
397 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000398 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800399}
400
401static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800402nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800403{
Andreas Gampe67333922014-11-10 20:35:59 -0800404 if (kLogApi) {
405 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
406 }
Chris Wailes488230c32014-08-14 11:22:40 -0700407 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800408 size_t receiveLen;
409 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800410 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700411 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800412 auxDataPtr[0] = (jint)subID;
413 auxDataPtr[1] = (jint)receiveLen;
414 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000415 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700416}
417
Tim Murrayeff663f2013-11-15 13:08:30 -0800418static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700419{
Andreas Gampe67333922014-11-10 20:35:59 -0800420 if (kLogApi) {
421 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
422 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800423 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700424}
425
Tim Murrayeff663f2013-11-15 13:08:30 -0800426static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700427{
Andreas Gampe67333922014-11-10 20:35:59 -0800428 if (kLogApi) {
429 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
430 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800431 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700432}
433
Jason Sams455d6442013-02-05 19:20:18 -0800434static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800435nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800436{
Chris Wailes488230c32014-08-14 11:22:40 -0700437 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800438 jint len = 0;
439 if (data) {
440 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700441 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800442 }
Andreas Gampe67333922014-11-10 20:35:59 -0800443 if (kLogApi) {
444 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
445 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800446 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800447 if (data) {
448 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
449 }
450}
451
452
Jason Sams516c3192009-10-06 13:58:47 -0700453
Tim Murray460a0492013-11-19 12:45:54 -0800454static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800455nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
456 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700457{
Andreas Gampe67333922014-11-10 20:35:59 -0800458 if (kLogApi) {
459 ALOGD("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con,
460 type, kind, norm, size);
461 }
462 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
463 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700464}
465
Tim Murray460a0492013-11-19 12:45:54 -0800466static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800467nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000468 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700469{
Jason Sams718cd1f2009-12-23 14:35:29 -0800470 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800471 if (kLogApi) {
472 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
473 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800474
Chris Wailes488230c32014-08-14 11:22:40 -0700475 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
476 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000477
478 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
479 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
480
481 for(int i = 0; i < fieldCount; i ++) {
482 ids[i] = (RsElement)jIds[i];
483 arraySizes[i] = (uint32_t)jArraySizes[i];
484 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800485
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800486 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
487
488 const char **nameArray = names.c_str();
489 size_t *sizeArray = names.c_str_len();
490
Tim Murray3aa89c12014-08-18 17:51:22 -0700491 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000492 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700493 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700494 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800495
Ashok Bhat98071552014-02-12 09:54:43 +0000496 free(ids);
497 free(arraySizes);
498 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
499 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
500
Tim Murray3aa89c12014-08-18 17:51:22 -0700501 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700502}
503
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700504static void
Tim Murray460a0492013-11-19 12:45:54 -0800505nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700506{
507 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800508 if (kLogApi) {
509 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
510 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700511
512 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
513 assert(dataSize == 5);
514
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000515 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800516 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700517
518 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000519 const jint data = (jint)elementData[i];
520 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700521 }
522}
523
524
525static void
Tim Murray460a0492013-11-19 12:45:54 -0800526nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000527 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700528 jobjectArray _names,
529 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700530{
Ashok Bhat98071552014-02-12 09:54:43 +0000531 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800532 if (kLogApi) {
533 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
534 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700535
Ashok Bhat98071552014-02-12 09:54:43 +0000536 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
537 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000538 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700539
Andreas Gampe67333922014-11-10 20:35:59 -0800540 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
541 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700542
Ashok Bhat98071552014-02-12 09:54:43 +0000543 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700544 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000545 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700546 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000547 _env->SetLongArrayRegion(_IDs, i, 1, &id);
548 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700549 }
550
551 free(ids);
552 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700553 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700554}
555
Jason Samsd19f10d2009-05-22 14:03:28 -0700556// -----------------------------------
557
Tim Murray460a0492013-11-19 12:45:54 -0800558static jlong
559nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800560 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700561{
Andreas Gampe67333922014-11-10 20:35:59 -0800562 if (kLogApi) {
563 ALOGD("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
564 (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv);
565 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700566
Andreas Gampe67333922014-11-10 20:35:59 -0800567 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
568 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700569}
570
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700571static void
Ashok Bhat98071552014-02-12 09:54:43 +0000572nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700573{
574 // We are packing 6 items: mDimX; mDimY; mDimZ;
575 // mDimLOD; mDimFaces; mElement; into typeData
576 int elementCount = _env->GetArrayLength(_typeData);
577
578 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800579 if (kLogApi) {
580 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
581 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700582
Ashok Bhat98071552014-02-12 09:54:43 +0000583 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800584 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700585
586 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700587 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000588 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700589 }
590}
591
Jason Samsd19f10d2009-05-22 14:03:28 -0700592// -----------------------------------
593
Tim Murray460a0492013-11-19 12:45:54 -0800594static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800595nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
596 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700597{
Andreas Gampe67333922014-11-10 20:35:59 -0800598 if (kLogApi) {
599 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
600 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
601 }
602 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
603 (RsAllocationMipmapControl)mips,
604 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700605}
606
Jason Samsd19f10d2009-05-22 14:03:28 -0700607static void
Tim Murray460a0492013-11-19 12:45:54 -0800608nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800609{
Andreas Gampe67333922014-11-10 20:35:59 -0800610 if (kLogApi) {
611 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
612 bits);
613 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800614 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800615}
616
Jason Sams72226e02013-02-22 12:45:54 -0800617static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800618nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800619{
Andreas Gampe67333922014-11-10 20:35:59 -0800620 if (kLogApi) {
621 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
622 }
Jason Sams615e7ce2012-01-13 14:01:20 -0800623
Andreas Gampe67333922014-11-10 20:35:59 -0800624 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
625 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800626 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -0700627 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700628
Jason Sams72226e02013-02-22 12:45:54 -0800629 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
630 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700631}
632
633static void
Tim Murray460a0492013-11-19 12:45:54 -0800634nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800635{
Andreas Gampe67333922014-11-10 20:35:59 -0800636 if (kLogApi) {
637 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
638 (RsAllocation)alloc, (Surface *)sur);
639 }
Jason Sams163766c2012-02-15 12:04:24 -0800640
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700641 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800642 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700643 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800644 }
645
Andreas Gampe67333922014-11-10 20:35:59 -0800646 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
647 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800648}
649
650static void
Tim Murray460a0492013-11-19 12:45:54 -0800651nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800652{
Andreas Gampe67333922014-11-10 20:35:59 -0800653 if (kLogApi) {
654 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, alloc);
655 }
Tim Murray460a0492013-11-19 12:45:54 -0800656 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800657}
658
659static void
Tim Murray460a0492013-11-19 12:45:54 -0800660nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800661{
Andreas Gampe67333922014-11-10 20:35:59 -0800662 if (kLogApi) {
663 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, alloc);
664 }
Tim Murray460a0492013-11-19 12:45:54 -0800665 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800666}
667
668
669static void
Tim Murray460a0492013-11-19 12:45:54 -0800670nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800671{
Andreas Gampe67333922014-11-10 20:35:59 -0800672 if (kLogApi) {
673 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
674 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800675 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800676}
677
Tim Murray460a0492013-11-19 12:45:54 -0800678static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800679nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
680 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700681{
Jason Samsffe9f482009-06-01 17:45:53 -0700682 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000683 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700684 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700685
Jason Sams5476b452010-12-08 16:14:36 -0800686 bitmap.lockPixels();
687 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700688 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700689 (RsType)type, (RsAllocationMipmapControl)mip,
690 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800691 bitmap.unlockPixels();
692 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700693}
Jason Samsfe08d992009-05-27 14:45:32 -0700694
Tim Murray460a0492013-11-19 12:45:54 -0800695static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800696nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
697 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800698{
699 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000700 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800701 const SkBitmap& bitmap(*nativeBitmap);
702
703 bitmap.lockPixels();
704 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700705 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800706 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000707 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800708 bitmap.unlockPixels();
709 return id;
710}
711
Tim Murray460a0492013-11-19 12:45:54 -0800712static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800713nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
714 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800715{
716 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000717 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800718 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800719
Jason Sams5476b452010-12-08 16:14:36 -0800720 bitmap.lockPixels();
721 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700722 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700723 (RsType)type, (RsAllocationMipmapControl)mip,
724 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800725 bitmap.unlockPixels();
726 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800727}
728
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700729static void
Tim Murray460a0492013-11-19 12:45:54 -0800730nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700731{
732 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000733 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700734 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800735 int w = bitmap.width();
736 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700737
Jason Sams4ef66502010-12-10 16:03:15 -0800738 bitmap.lockPixels();
739 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800740 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700741 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800742 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800743 bitmap.unlockPixels();
744}
745
746static void
Tim Murray460a0492013-11-19 12:45:54 -0800747nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800748{
749 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000750 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800751 const SkBitmap& bitmap(*nativeBitmap);
752
753 bitmap.lockPixels();
754 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800755 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800756 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700757 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700758}
759
Stephen Hines414fa2c2014-04-17 01:02:42 -0700760// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700761static void
Tim Murray460a0492013-11-19 12:45:54 -0800762nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000763 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700764{
Jason Samse729a942013-11-06 11:22:02 -0800765 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800766 if (kLogApi) {
767 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
768 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
769 dataType);
770 }
771 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count,
772 ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700773}
774
Stephen Hines414fa2c2014-04-17 01:02:42 -0700775// Copies from the Java array data into the Allocation pointed to by alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700776static void
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000777// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
Andreas Gampe67333922014-11-10 20:35:59 -0800778nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod,
779 jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700780{
781 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800782 if (kLogApi) {
783 ALOGD("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), "
784 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len,
785 sizeBytes);
786 }
Chris Wailes488230c32014-08-14 11:22:40 -0700787 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -0800788 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700789 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
790}
791
Stephen Hines414fa2c2014-04-17 01:02:42 -0700792// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -0700793static void
Tim Murray460a0492013-11-19 12:45:54 -0800794nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000795 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800796{
Jason Samse729a942013-11-06 11:22:02 -0800797 RsAllocation *alloc = (RsAllocation *)_alloc;
798 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800799 if (kLogApi) {
800 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
801 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
802 }
Chris Wailes488230c32014-08-14 11:22:40 -0700803 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 -0700804}
805
Stephen Hines414fa2c2014-04-17 01:02:42 -0700806// Copies from the Allocation pointed to by srcAlloc into the Allocation
807// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -0700808static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800809nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800810 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700811 jint dstMip, jint dstFace,
812 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -0800813 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700814 jint srcMip, jint srcFace)
815{
Andreas Gampe67333922014-11-10 20:35:59 -0800816 if (kLogApi) {
817 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
818 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
819 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
820 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
821 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
822 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700823
Tim Murrayeff663f2013-11-15 13:08:30 -0800824 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700825 (RsAllocation)dstAlloc,
826 dstXoff, dstYoff,
827 dstMip, dstFace,
828 width, height,
829 (RsAllocation)srcAlloc,
830 srcXoff, srcYoff,
831 srcMip, srcFace);
832}
833
Stephen Hines414fa2c2014-04-17 01:02:42 -0700834// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700835static void
Tim Murray460a0492013-11-19 12:45:54 -0800836nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -0800837 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700838{
Jason Samse729a942013-11-06 11:22:02 -0800839 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800840 if (kLogApi) {
841 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
842 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
843 lod, w, h, d, sizeBytes);
844 }
Chris Wailes488230c32014-08-14 11:22:40 -0700845 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 -0700846}
847
Stephen Hines414fa2c2014-04-17 01:02:42 -0700848// Copies from the Allocation pointed to by srcAlloc into the Allocation
849// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -0700850static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800851nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800852 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700853 jint dstMip,
854 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -0800855 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700856 jint srcMip)
857{
Andreas Gampe67333922014-11-10 20:35:59 -0800858 if (kLogApi) {
859 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
860 " dstMip(%i), width(%i), height(%i),"
861 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
862 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
863 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
864 }
Jason Samsb05d6892013-04-09 15:59:24 -0700865
Tim Murrayeff663f2013-11-15 13:08:30 -0800866 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -0700867 (RsAllocation)dstAlloc,
868 dstXoff, dstYoff, dstZoff, dstMip,
869 width, height, depth,
870 (RsAllocation)srcAlloc,
871 srcXoff, srcYoff, srcZoff, srcMip);
872}
873
Jason Sams21659ac2013-11-06 15:08:07 -0800874
Stephen Hines414fa2c2014-04-17 01:02:42 -0700875// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -0700876static void
Tim Murray460a0492013-11-19 12:45:54 -0800877nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700878{
Jason Sams21659ac2013-11-06 15:08:07 -0800879 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800880 if (kLogApi) {
881 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
882 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700883 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700884}
885
Stephen Hines414fa2c2014-04-17 01:02:42 -0700886// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -0700887static void
Tim Murray460a0492013-11-19 12:45:54 -0800888nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -0800889 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800890{
Jason Sams21659ac2013-11-06 15:08:07 -0800891 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800892 if (kLogApi) {
893 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
894 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
895 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700896 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800897}
898
Stephen Hines414fa2c2014-04-17 01:02:42 -0700899// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -0800900static void
Tim Murray460a0492013-11-19 12:45:54 -0800901nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -0800902 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800903{
Jason Sams21659ac2013-11-06 15:08:07 -0800904 RsAllocation *alloc = (RsAllocation *)_alloc;
905 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800906 if (kLogApi) {
907 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
908 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
909 }
910 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h,
911 ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700912}
Jason Samsd19f10d2009-05-22 14:03:28 -0700913
Tim Murray460a0492013-11-19 12:45:54 -0800914static jlong
915nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700916{
Andreas Gampe67333922014-11-10 20:35:59 -0800917 if (kLogApi) {
918 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
919 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700920 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700921}
922
Jason Sams5edc6082010-10-05 13:32:49 -0700923static void
Tim Murray460a0492013-11-19 12:45:54 -0800924nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -0700925{
Andreas Gampe67333922014-11-10 20:35:59 -0800926 if (kLogApi) {
927 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
928 (RsAllocation)alloc, dimX);
929 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800930 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -0700931}
932
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700933// -----------------------------------
934
Tim Murray460a0492013-11-19 12:45:54 -0800935static jlong
936nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700937{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700938 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000939 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700940
Tim Murray3aa89c12014-08-18 17:51:22 -0700941 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800942 return id;
943}
944
Tim Murray460a0492013-11-19 12:45:54 -0800945static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800946nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800947{
948 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -0700949 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800950 return 0;
951 }
952
953 AutoJavaStringToUTF8 str(_env, _path);
954 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -0700955 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800956 return 0;
957 }
958
Tim Murray3aa89c12014-08-18 17:51:22 -0700959 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800960 return id;
961}
962
Tim Murray460a0492013-11-19 12:45:54 -0800963static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800964nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800965{
966 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -0700967 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800968
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700969 return id;
970}
971
Tim Murray460a0492013-11-19 12:45:54 -0800972static jint
973nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700974{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700975 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800976 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000977 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700978}
979
980static void
Tim Murray460a0492013-11-19 12:45:54 -0800981nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700982{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000983 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700984 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
985
Tim Murrayeff663f2013-11-15 13:08:30 -0800986 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700987
988 for(jint i = 0; i < numEntries; i ++) {
989 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
990 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
991 }
992
993 free(fileEntries);
994}
995
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000996static jlong
Tim Murray460a0492013-11-19 12:45:54 -0800997nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700998{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000999 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001000 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001001 return id;
1002}
Jason Samsd19f10d2009-05-22 14:03:28 -07001003
1004// -----------------------------------
1005
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001006static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001007nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001008 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001009{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001010 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001011 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001012 fileNameUTF.c_str(), fileNameUTF.length(),
1013 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001014
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001015 return id;
1016}
1017
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001018static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001019nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001020 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001021{
1022 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1023 AutoJavaStringToUTF8 nameUTF(_env, name);
1024
Tim Murray3aa89c12014-08-18 17:51:22 -07001025 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001026 nameUTF.c_str(), nameUTF.length(),
1027 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001028 asset->getBuffer(false), asset->getLength());
1029 return id;
1030}
1031
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001032static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001033nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001034 jfloat fontSize, jint dpi)
1035{
1036 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001037 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001038 return 0;
1039 }
1040
1041 AutoJavaStringToUTF8 str(_env, _path);
1042 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001043 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001044 return 0;
1045 }
1046
Tim Murray3aa89c12014-08-18 17:51:22 -07001047 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001048 str.c_str(), str.length(),
1049 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001050 asset->getBuffer(false), asset->getLength());
1051 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001052 return id;
1053}
1054
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001055// -----------------------------------
1056
1057static void
Tim Murray460a0492013-11-19 12:45:54 -08001058nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001059{
Andreas Gampe67333922014-11-10 20:35:59 -08001060 if (kLogApi) {
1061 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1062 (RsScript)script, (RsAllocation)alloc, slot);
1063 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001064 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001065}
1066
1067static void
Tim Murray460a0492013-11-19 12:45:54 -08001068nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001069{
Andreas Gampe67333922014-11-10 20:35:59 -08001070 if (kLogApi) {
1071 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1072 slot, val);
1073 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001074 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001075}
1076
Tim Murray7c4caad2013-04-10 16:21:40 -07001077static jint
Tim Murray460a0492013-11-19 12:45:54 -08001078nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001079{
Andreas Gampe67333922014-11-10 20:35:59 -08001080 if (kLogApi) {
1081 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1082 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001083 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001084 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001085 return value;
1086}
1087
Jason Sams4d339932010-05-11 14:03:58 -07001088static void
Tim Murray460a0492013-11-19 12:45:54 -08001089nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001090{
Andreas Gampe67333922014-11-10 20:35:59 -08001091 if (kLogApi) {
1092 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1093 slot, val);
1094 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001095 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001096}
1097
1098static void
Tim Murray460a0492013-11-19 12:45:54 -08001099nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001100{
Andreas Gampe67333922014-11-10 20:35:59 -08001101 if (kLogApi) {
1102 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, (void *)script,
1103 slot, val);
1104 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001105 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001106}
1107
Tim Murray7c4caad2013-04-10 16:21:40 -07001108static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001109nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001110{
Andreas Gampe67333922014-11-10 20:35:59 -08001111 if (kLogApi) {
1112 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1113 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001114 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001115 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001116 return value;
1117}
1118
Stephen Hines031ec58c2010-10-11 10:54:21 -07001119static void
Tim Murray460a0492013-11-19 12:45:54 -08001120nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001121{
Andreas Gampe67333922014-11-10 20:35:59 -08001122 if (kLogApi) {
1123 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1124 slot, val);
1125 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001126 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001127}
1128
Tim Murray7c4caad2013-04-10 16:21:40 -07001129static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001130nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001131{
Andreas Gampe67333922014-11-10 20:35:59 -08001132 if (kLogApi) {
1133 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1134 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001135 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001136 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001137 return value;
1138}
1139
Jason Sams4d339932010-05-11 14:03:58 -07001140static void
Tim Murray460a0492013-11-19 12:45:54 -08001141nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001142{
Andreas Gampe67333922014-11-10 20:35:59 -08001143 if (kLogApi) {
1144 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1145 slot, val);
1146 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001147 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001148}
1149
Tim Murray7c4caad2013-04-10 16:21:40 -07001150static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001151nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001152{
Andreas Gampe67333922014-11-10 20:35:59 -08001153 if (kLogApi) {
1154 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1155 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001156 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001157 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001158 return value;
1159}
1160
Stephen Hinesca54ec32010-09-20 17:20:30 -07001161static void
Tim Murray460a0492013-11-19 12:45:54 -08001162nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001163{
Andreas Gampe67333922014-11-10 20:35:59 -08001164 if (kLogApi) {
1165 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1166 }
Jason Sams4d339932010-05-11 14:03:58 -07001167 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001168 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001169 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001170 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1171}
1172
Stephen Hinesadeb8092012-04-20 14:26:06 -07001173static void
Tim Murray460a0492013-11-19 12:45:54 -08001174nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001175{
Andreas Gampe67333922014-11-10 20:35:59 -08001176 if (kLogApi) {
1177 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1178 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001179 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001180 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001181 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001182 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001183}
1184
1185static void
Andreas Gampe67333922014-11-10 20:35:59 -08001186nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1187 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001188{
Andreas Gampe67333922014-11-10 20:35:59 -08001189 if (kLogApi) {
1190 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1191 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001192 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001193 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001194 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001195 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001196 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001197 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001198 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1199 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1200}
1201
Jason Samsd19f10d2009-05-22 14:03:28 -07001202
1203static void
Tim Murray460a0492013-11-19 12:45:54 -08001204nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001205{
Andreas Gampe67333922014-11-10 20:35:59 -08001206 if (kLogApi) {
1207 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1208 }
Romain Guy584a3752009-07-30 18:45:01 -07001209
1210 jint length = _env->GetArrayLength(timeZone);
1211 jbyte* timeZone_ptr;
1212 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1213
Tim Murrayeff663f2013-11-15 13:08:30 -08001214 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001215
1216 if (timeZone_ptr) {
1217 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1218 }
1219}
1220
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001221static void
Tim Murray460a0492013-11-19 12:45:54 -08001222nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001223{
Andreas Gampe67333922014-11-10 20:35:59 -08001224 if (kLogApi) {
1225 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1226 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001227 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001228}
1229
1230static void
Tim Murray460a0492013-11-19 12:45:54 -08001231nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001232{
Andreas Gampe67333922014-11-10 20:35:59 -08001233 if (kLogApi) {
1234 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1235 }
Jason Sams4d339932010-05-11 14:03:58 -07001236 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001237 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001238 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001239 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1240}
1241
Jason Sams6e494d32011-04-27 16:33:11 -07001242static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001243nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1244 jlongArray ains, jlong aout, jbyteArray params,
1245 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001246{
Andreas Gampe67333922014-11-10 20:35:59 -08001247 if (kLogApi) {
1248 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1249 }
Jason Sams6e494d32011-04-27 16:33:11 -07001250
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001251 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001252 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001253
Chris Wailes488230c32014-08-14 11:22:40 -07001254 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001255
Chris Wailes488230c32014-08-14 11:22:40 -07001256 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001257 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001258 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001259
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001260 if (sizeof(RsAllocation) == sizeof(jlong)) {
1261 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001262
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001263 } else {
1264 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001265
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001266 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1267
1268 for (int index = in_len; --index >= 0;) {
1269 in_allocs[index] = (RsAllocation)in_ptr[index];
1270 }
1271 }
Chris Wailes94961062014-06-11 12:01:28 -07001272 }
1273
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001274 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001275 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001276
Chris Wailes488230c32014-08-14 11:22:40 -07001277 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001278 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001279 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001280 }
1281
Chris Wailes488230c32014-08-14 11:22:40 -07001282 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001283 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001284
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001285 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001286 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001287
Chris Wailes488230c32014-08-14 11:22:40 -07001288 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001289 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001290 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001291
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001292 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001293 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001294
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001295 sc.xStart = limit_ptr[0];
1296 sc.xEnd = limit_ptr[1];
1297 sc.yStart = limit_ptr[2];
1298 sc.yEnd = limit_ptr[3];
1299 sc.zStart = limit_ptr[4];
1300 sc.zEnd = limit_ptr[5];
1301 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Chris Wailes94961062014-06-11 12:01:28 -07001302
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001303 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001304 }
1305
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001306 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1307 in_allocs, in_len, (RsAllocation)aout,
1308 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001309
Chris Wailes488230c32014-08-14 11:22:40 -07001310 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001311 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001312 }
1313
Chris Wailes488230c32014-08-14 11:22:40 -07001314 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001315 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1316 }
1317
Chris Wailes488230c32014-08-14 11:22:40 -07001318 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001319 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1320 }
Chris Wailes94961062014-06-11 12:01:28 -07001321}
1322
Jason Sams22534172009-08-04 16:58:20 -07001323// -----------------------------------
1324
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001325static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001326nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001327 jstring resName, jstring cacheDir,
1328 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001329{
Andreas Gampe67333922014-11-10 20:35:59 -08001330 if (kLogApi) {
1331 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1332 }
Jason Sams22534172009-08-04 16:58:20 -07001333
Jason Samse4a06c52011-03-16 16:29:28 -07001334 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1335 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001336 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001337 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001338 jint _exception = 0;
1339 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001340 if (!scriptRef) {
1341 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001342 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001343 goto exit;
1344 }
Jack Palevich43702d82009-05-28 13:38:16 -07001345 if (length < 0) {
1346 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001347 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001348 goto exit;
1349 }
Jason Samse4a06c52011-03-16 16:29:28 -07001350 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001351 if (remaining < length) {
1352 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001353 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1354 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001355 goto exit;
1356 }
Jason Samse4a06c52011-03-16 16:29:28 -07001357 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001358 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001359
Tim Murrayeff663f2013-11-15 13:08:30 -08001360 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001361
Tim Murray3aa89c12014-08-18 17:51:22 -07001362 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001363 resNameUTF.c_str(), resNameUTF.length(),
1364 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001365 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001366
Jack Palevich43702d82009-05-28 13:38:16 -07001367exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001368 if (script_ptr) {
1369 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001370 _exception ? JNI_ABORT: 0);
1371 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001372
Tim Murray3aa89c12014-08-18 17:51:22 -07001373 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001374}
1375
Tim Murray460a0492013-11-19 12:45:54 -08001376static jlong
1377nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001378{
Andreas Gampe67333922014-11-10 20:35:59 -08001379 if (kLogApi) {
1380 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1381 (void *)eid);
1382 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001383 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001384}
1385
Tim Murray460a0492013-11-19 12:45:54 -08001386static jlong
1387nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001388{
Andreas Gampe67333922014-11-10 20:35:59 -08001389 if (kLogApi) {
1390 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1391 (void *)sid, slot, sig);
1392 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001393 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001394}
1395
Tim Murray460a0492013-11-19 12:45:54 -08001396static jlong
1397nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001398{
Andreas Gampe67333922014-11-10 20:35:59 -08001399 if (kLogApi) {
1400 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1401 slot);
1402 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001403 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001404}
1405
Tim Murray460a0492013-11-19 12:45:54 -08001406static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001407nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1408 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001409{
Andreas Gampe67333922014-11-10 20:35:59 -08001410 if (kLogApi) {
1411 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1412 }
Jason Sams08a81582012-09-18 12:32:10 -07001413
Ashok Bhat98071552014-02-12 09:54:43 +00001414 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001415 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001416 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1417 for(int i = 0; i < kernelsLen; ++i) {
1418 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1419 }
Jason Sams08a81582012-09-18 12:32:10 -07001420
Ashok Bhat98071552014-02-12 09:54:43 +00001421 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001422 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001423 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1424 for(int i = 0; i < srcLen; ++i) {
1425 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1426 }
Jason Sams08a81582012-09-18 12:32:10 -07001427
Ashok Bhat98071552014-02-12 09:54:43 +00001428 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001429 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001430 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1431 for(int i = 0; i < dstkLen; ++i) {
1432 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1433 }
1434
1435 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001436 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001437 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1438 for(int i = 0; i < dstfLen; ++i) {
1439 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1440 }
1441
1442 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001443 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001444 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1445 for(int i = 0; i < typesLen; ++i) {
1446 typesPtr[i] = (RsType)jTypesPtr[i];
1447 }
1448
Tim Murray3aa89c12014-08-18 17:51:22 -07001449 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001450 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1451 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1452 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1453 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1454 (RsType *)typesPtr, typesLen * sizeof(RsType));
1455
1456 free(kernelsPtr);
1457 free(srcPtr);
1458 free(dstkPtr);
1459 free(dstfPtr);
1460 free(typesPtr);
1461 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1462 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1463 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1464 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1465 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001466 return id;
1467}
1468
1469static void
Tim Murray460a0492013-11-19 12:45:54 -08001470nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001471{
Andreas Gampe67333922014-11-10 20:35:59 -08001472 if (kLogApi) {
1473 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1474 (void *)gid, (void *)kid, (void *)alloc);
1475 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001476 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001477}
1478
1479static void
Tim Murray460a0492013-11-19 12:45:54 -08001480nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001481{
Andreas Gampe67333922014-11-10 20:35:59 -08001482 if (kLogApi) {
1483 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1484 (void *)gid, (void *)kid, (void *)alloc);
1485 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001486 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001487}
1488
1489static void
Tim Murray460a0492013-11-19 12:45:54 -08001490nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001491{
Andreas Gampe67333922014-11-10 20:35:59 -08001492 if (kLogApi) {
1493 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1494 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001495 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001496}
1497
Jason Samsd19f10d2009-05-22 14:03:28 -07001498// ---------------------------------------------------------------------------
1499
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001500static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001501nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001502 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1503 jboolean depthMask, jboolean ditherEnable,
1504 jint srcFunc, jint destFunc,
1505 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001506{
Andreas Gampe67333922014-11-10 20:35:59 -08001507 if (kLogApi) {
1508 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1509 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001510 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001511 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1512 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001513}
1514
Jason Sams0011bcf2009-12-15 12:58:36 -08001515// ---------------------------------------------------------------------------
1516
1517static void
Tim Murray460a0492013-11-19 12:45:54 -08001518nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001519{
Andreas Gampe67333922014-11-10 20:35:59 -08001520 if (kLogApi) {
1521 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
1522 (RsProgramVertex)vpv, slot, (RsAllocation)a);
1523 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001524 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001525}
Jason Sams54c0ec12009-11-30 14:49:55 -08001526
Jason Sams68afd012009-12-17 16:55:08 -08001527static void
Tim Murray460a0492013-11-19 12:45:54 -08001528nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001529{
Andreas Gampe67333922014-11-10 20:35:59 -08001530 if (kLogApi) {
1531 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1532 (RsProgramFragment)vpf, slot, (RsAllocation)a);
1533 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001534 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001535}
1536
1537static void
Tim Murray460a0492013-11-19 12:45:54 -08001538nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001539{
Andreas Gampe67333922014-11-10 20:35:59 -08001540 if (kLogApi) {
1541 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1542 (RsProgramFragment)vpf, slot, (RsSampler)a);
1543 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001544 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001545}
1546
Jason Samsd19f10d2009-05-22 14:03:28 -07001547// ---------------------------------------------------------------------------
1548
Tim Murray460a0492013-11-19 12:45:54 -08001549static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001550nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001551 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001552{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001553 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001554 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001555 jint paramLen = _env->GetArrayLength(params);
1556
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001557 int texCount = _env->GetArrayLength(texNames);
1558 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1559 const char ** nameArray = names.c_str();
1560 size_t* sizeArray = names.c_str_len();
1561
Andreas Gampe67333922014-11-10 20:35:59 -08001562 if (kLogApi) {
1563 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1564 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001565
Ashok Bhat98071552014-02-12 09:54:43 +00001566 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1567 for(int i = 0; i < paramLen; ++i) {
1568 paramPtr[i] = (uintptr_t)jParamPtr[i];
1569 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001570 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001571 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001572 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001573
Ashok Bhat98071552014-02-12 09:54:43 +00001574 free(paramPtr);
1575 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001576 return ret;
1577}
1578
1579
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001580// ---------------------------------------------------------------------------
1581
Tim Murray460a0492013-11-19 12:45:54 -08001582static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001583nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001584 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001585{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001586 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001587 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001588 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001589
Andreas Gampe67333922014-11-10 20:35:59 -08001590 if (kLogApi) {
1591 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1592 }
Jason Sams0011bcf2009-12-15 12:58:36 -08001593
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001594 int texCount = _env->GetArrayLength(texNames);
1595 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1596 const char ** nameArray = names.c_str();
1597 size_t* sizeArray = names.c_str_len();
1598
Ashok Bhat98071552014-02-12 09:54:43 +00001599 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1600 for(int i = 0; i < paramLen; ++i) {
1601 paramPtr[i] = (uintptr_t)jParamPtr[i];
1602 }
1603
Tim Murray3aa89c12014-08-18 17:51:22 -07001604 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001605 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001606 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001607
Ashok Bhat98071552014-02-12 09:54:43 +00001608 free(paramPtr);
1609 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001610 return ret;
1611}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001612
Jason Samsebfb4362009-09-23 13:57:02 -07001613// ---------------------------------------------------------------------------
1614
Tim Murray460a0492013-11-19 12:45:54 -08001615static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001616nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001617{
Andreas Gampe67333922014-11-10 20:35:59 -08001618 if (kLogApi) {
1619 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
1620 pointSprite, cull);
1621 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001622 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001623}
1624
Jason Samsd19f10d2009-05-22 14:03:28 -07001625
1626// ---------------------------------------------------------------------------
1627
1628static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001629nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001630{
Andreas Gampe67333922014-11-10 20:35:59 -08001631 if (kLogApi) {
1632 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
1633 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001634 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001635}
1636
1637static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001638nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001639{
Andreas Gampe67333922014-11-10 20:35:59 -08001640 if (kLogApi) {
1641 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
1642 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001643 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001644}
1645
1646static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001647nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001648{
Andreas Gampe67333922014-11-10 20:35:59 -08001649 if (kLogApi) {
1650 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
1651 (RsProgramFragment)pf);
1652 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001653 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001654}
1655
Jason Sams0826a6f2009-06-15 19:04:56 -07001656static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001657nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001658{
Andreas Gampe67333922014-11-10 20:35:59 -08001659 if (kLogApi) {
1660 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
1661 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001662 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001663}
1664
Joe Onoratod7b37742009-08-09 22:57:44 -07001665static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001666nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001667{
Andreas Gampe67333922014-11-10 20:35:59 -08001668 if (kLogApi) {
1669 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
1670 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001671 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001672}
1673
Joe Onoratod7b37742009-08-09 22:57:44 -07001674
Jason Sams02fb2cb2009-05-28 15:37:57 -07001675// ---------------------------------------------------------------------------
1676
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001677static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001678nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001679 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001680{
Andreas Gampe67333922014-11-10 20:35:59 -08001681 if (kLogApi) {
1682 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
1683 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001684 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001685 (RsSamplerValue)magFilter,
1686 (RsSamplerValue)minFilter,
1687 (RsSamplerValue)wrapS,
1688 (RsSamplerValue)wrapT,
1689 (RsSamplerValue)wrapR,
1690 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001691}
1692
Jason Samsbba134c2009-06-22 15:49:21 -07001693// ---------------------------------------------------------------------------
1694
Tim Murray460a0492013-11-19 12:45:54 -08001695static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001696nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Andreas Gampe67333922014-11-10 20:35:59 -08001697 if (kLogApi) {
1698 ALOGD("nPathCreate, con(%p)", (RsContext)con);
1699 }
Jason Samsf15ed012011-10-31 13:23:43 -07001700
Tim Murray3aa89c12014-08-18 17:51:22 -07001701 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08001702 (RsAllocation)_vtx,
1703 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001704 return id;
1705}
1706
Tim Murray460a0492013-11-19 12:45:54 -08001707static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001708nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001709{
Andreas Gampe67333922014-11-10 20:35:59 -08001710 if (kLogApi) {
1711 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
1712 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001713
1714 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07001715 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001716 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1717 for(int i = 0; i < vtxLen; ++i) {
1718 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1719 }
1720
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001721 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07001722 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001723 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1724 for(int i = 0; i < idxLen; ++i) {
1725 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1726 }
1727
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001728 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07001729 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001730
Tim Murray3aa89c12014-08-18 17:51:22 -07001731 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001732 (RsAllocation *)vtxPtr, vtxLen,
1733 (RsAllocation *)idxPtr, idxLen,
1734 (uint32_t *)primPtr, primLen);
1735
Ashok Bhat98071552014-02-12 09:54:43 +00001736 free(vtxPtr);
1737 free(idxPtr);
1738 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1739 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001740 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001741 return id;
1742}
1743
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001744static jint
Tim Murray460a0492013-11-19 12:45:54 -08001745nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001746{
Andreas Gampe67333922014-11-10 20:35:59 -08001747 if (kLogApi) {
1748 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1749 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001750 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001751 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001752 return vtxCount;
1753}
1754
1755static jint
Tim Murray460a0492013-11-19 12:45:54 -08001756nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001757{
Andreas Gampe67333922014-11-10 20:35:59 -08001758 if (kLogApi) {
1759 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1760 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001761 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001762 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001763 return idxCount;
1764}
1765
1766static void
Ashok Bhat98071552014-02-12 09:54:43 +00001767nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001768{
Andreas Gampe67333922014-11-10 20:35:59 -08001769 if (kLogApi) {
1770 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1771 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001772
1773 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001774 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001775
1776 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001777 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001778 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001779 }
1780
1781 free(allocs);
1782}
1783
1784static void
Ashok Bhat98071552014-02-12 09:54:43 +00001785nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001786{
Andreas Gampe67333922014-11-10 20:35:59 -08001787 if (kLogApi) {
1788 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1789 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001790
1791 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1792 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1793
Tim Murrayeff663f2013-11-15 13:08:30 -08001794 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001795
1796 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001797 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001798 const jint prim = (jint)prims[i];
1799 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1800 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001801 }
1802
1803 free(allocs);
1804 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001805}
1806
Tim Murray56f9e6f2014-05-16 11:47:26 -07001807static jint
1808nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1809 return (jint)sizeof(void*);
1810}
1811
1812
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001813// ---------------------------------------------------------------------------
1814
Jason Samsd19f10d2009-05-22 14:03:28 -07001815
Jason Sams94d8e90a2009-06-10 16:09:05 -07001816static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001817
1818static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001819{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001820
Tim Murrayeff663f2013-11-15 13:08:30 -08001821{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1822{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1823{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1824{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1825{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1826{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001827
Tim Murrayeff663f2013-11-15 13:08:30 -08001828{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1829{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001830
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001831
Jason Sams2e1872f2010-08-17 16:25:41 -07001832// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001833{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1834{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1835{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1836{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1837{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1838{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1839{"rsnContextDump", "(JI)V", (void*)nContextDump },
1840{"rsnContextPause", "(J)V", (void*)nContextPause },
1841{"rsnContextResume", "(J)V", (void*)nContextResume },
1842{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Tim Murray460a0492013-11-19 12:45:54 -08001843{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1844{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1845{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001846
Tim Murray460a0492013-11-19 12:45:54 -08001847{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001848{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001849{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1850{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1851{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001852{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001853
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001854{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1855{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1856{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001857
Tim Murray460a0492013-11-19 12:45:54 -08001858{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001859{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001860{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001861{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001862
Tim Murray460a0492013-11-19 12:45:54 -08001863{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001864{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001865
Ashok Bhat98071552014-02-12 09:54:43 +00001866{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001867{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1868{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1869{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001870
Tim Murray460a0492013-11-19 12:45:54 -08001871{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1872{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001873
Tim Murray460a0492013-11-19 12:45:54 -08001874{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1875{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1876{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1877{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1878{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1879{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1880{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1881{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1882{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1883{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1884{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1885{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1886{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1887{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1888{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1889{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1890{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001891
Tim Murray460a0492013-11-19 12:45:54 -08001892{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1893{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1894{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1895{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001896
1897{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
1898
Tim Murray460a0492013-11-19 12:45:54 -08001899{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1900{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1901{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1902{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1903{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1904{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1905{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
1906{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
1907{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
1908{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
1909{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
1910{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001911
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001912{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001913{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
1914{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
1915{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001916{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001917{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
1918{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
1919{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001920
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001921{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001922
Tim Murray460a0492013-11-19 12:45:54 -08001923{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
1924{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
1925{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001926
Ashok Bhat98071552014-02-12 09:54:43 +00001927{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001928{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001929{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001930
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001931{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
1932{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
1933{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
1934{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
1935{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001936
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001937{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001938
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001939{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001940{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001941
Tim Murray460a0492013-11-19 12:45:54 -08001942{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
1943{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00001944{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
1945{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001946
Tim Murray56f9e6f2014-05-16 11:47:26 -07001947{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07001948};
1949
1950static int registerFuncs(JNIEnv *_env)
1951{
1952 return android::AndroidRuntime::registerNativeMethods(
1953 _env, classPathName, methods, NELEM(methods));
1954}
1955
1956// ---------------------------------------------------------------------------
1957
1958jint JNI_OnLoad(JavaVM* vm, void* reserved)
1959{
Chris Wailes488230c32014-08-14 11:22:40 -07001960 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07001961 jint result = -1;
1962
Jason Samsd19f10d2009-05-22 14:03:28 -07001963 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001964 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001965 goto bail;
1966 }
Chris Wailes488230c32014-08-14 11:22:40 -07001967 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07001968
1969 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001970 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001971 goto bail;
1972 }
1973
1974 /* success -- return valid version number */
1975 result = JNI_VERSION_1_4;
1976
1977bail:
1978 return result;
1979}