blob: 2d9413164022f156528aababdec8699da4630149 [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
Jason Samsd19f10d2009-05-22 14:03:28 -070046#define LOG_API(...)
47
48using namespace android;
49
Stephen Hines414fa2c2014-04-17 01:02:42 -070050#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080051 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070052 void *ptr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080053 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070054 jint relFlag = 0; \
55 if (readonly) { \
56 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
57 relFlag = JNI_ABORT; \
58 } \
Jason Samse729a942013-11-06 11:22:02 -080059 switch(dataType) { \
60 case RS_TYPE_FLOAT_32: \
61 len = _env->GetArrayLength((jfloatArray)data); \
62 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080063 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080064 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070065 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080066 return; \
67 case RS_TYPE_FLOAT_64: \
68 len = _env->GetArrayLength((jdoubleArray)data); \
69 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080070 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -080071 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070072 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080073 return; \
74 case RS_TYPE_SIGNED_8: \
75 case RS_TYPE_UNSIGNED_8: \
76 len = _env->GetArrayLength((jbyteArray)data); \
77 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080078 typeBytes = 1; \
Jason Samse729a942013-11-06 11:22:02 -080079 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070080 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080081 return; \
82 case RS_TYPE_SIGNED_16: \
83 case RS_TYPE_UNSIGNED_16: \
84 len = _env->GetArrayLength((jshortArray)data); \
85 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080086 typeBytes = 2; \
Jason Samse729a942013-11-06 11:22:02 -080087 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070088 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080089 return; \
90 case RS_TYPE_SIGNED_32: \
91 case RS_TYPE_UNSIGNED_32: \
92 len = _env->GetArrayLength((jintArray)data); \
93 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080094 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080095 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070096 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080097 return; \
98 case RS_TYPE_SIGNED_64: \
99 case RS_TYPE_UNSIGNED_64: \
100 len = _env->GetArrayLength((jlongArray)data); \
101 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800102 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -0800103 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700104 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800105 return; \
106 default: \
107 break; \
108 } \
109}
110
111
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800112class AutoJavaStringToUTF8 {
113public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800114 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700115 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800116 fLength = env->GetStringUTFLength(str);
117 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800118 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800119 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
120 }
121 const char* c_str() const { return fCStr; }
122 jsize length() const { return fLength; }
123
124private:
125 JNIEnv* fEnv;
126 jstring fJStr;
127 const char* fCStr;
128 jsize fLength;
129};
130
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800131class AutoJavaStringArrayToUTF8 {
132public:
133 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
134 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700135 mCStrings = nullptr;
136 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800137 if (stringsLength > 0) {
138 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
139 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
140 for (jsize ct = 0; ct < stringsLength; ct ++) {
141 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700142 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800143 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
144 }
145 }
146 }
147 ~AutoJavaStringArrayToUTF8() {
148 for (jsize ct=0; ct < mStringsLength; ct++) {
149 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
150 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
151 }
152 free(mCStrings);
153 free(mSizeArray);
154 }
155 const char **c_str() const { return mCStrings; }
156 size_t *c_str_len() const { return mSizeArray; }
157 jsize length() const { return mStringsLength; }
158
159private:
160 JNIEnv *mEnv;
161 jobjectArray mStrings;
162 const char **mCStrings;
163 size_t *mSizeArray;
164 jsize mStringsLength;
165};
166
Jason Samsd19f10d2009-05-22 14:03:28 -0700167// ---------------------------------------------------------------------------
168
Jason Samsffe9f482009-06-01 17:45:53 -0700169static jfieldID gContextId = 0;
170static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700171static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700172
173static void _nInit(JNIEnv *_env, jclass _this)
174{
Tim Murrayeff663f2013-11-15 13:08:30 -0800175 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700176
177 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000178 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700179}
180
Jason Samsd19f10d2009-05-22 14:03:28 -0700181// ---------------------------------------------------------------------------
182
Jason Sams3eaa338e2009-06-10 15:04:38 -0700183static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800184nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700185{
Tim Murray71a01b82014-01-07 15:36:19 -0800186 LOG_API("nContextFinish, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800187 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700188}
189
190static void
Tim Murray460a0492013-11-19 12:45:54 -0800191nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700192{
Tim Murray71a01b82014-01-07 15:36:19 -0800193 LOG_API("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700194 jint len = _env->GetArrayLength(str);
195 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800196 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700197 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
198}
199
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700200static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800201nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700202{
Tim Murray71a01b82014-01-07 15:36:19 -0800203 LOG_API("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
Chris Wailes488230c32014-08-14 11:22:40 -0700204 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800205 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700206 if(name == nullptr || strlen(name) == 0) {
207 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700208 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700209 return _env->NewStringUTF(name);
210}
211
Jason Sams7ce033d2009-08-18 14:14:24 -0700212static void
Tim Murray460a0492013-11-19 12:45:54 -0800213nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700214{
Tim Murray71a01b82014-01-07 15:36:19 -0800215 LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
Tim Murrayeff663f2013-11-15 13:08:30 -0800216 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700217}
218
Jason Sams3eaa338e2009-06-10 15:04:38 -0700219// ---------------------------------------------------------------------------
220
Tim Murrayeff663f2013-11-15 13:08:30 -0800221static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700222nDeviceCreate(JNIEnv *_env, jobject _this)
223{
224 LOG_API("nDeviceCreate");
Tim Murray3aa89c12014-08-18 17:51:22 -0700225 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700226}
227
228static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800229nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700230{
231 LOG_API("nDeviceDestroy");
232 return rsDeviceDestroy((RsDevice)dev);
233}
234
Jason Samsebfb4362009-09-23 13:57:02 -0700235static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800236nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700237{
238 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
239 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
240}
241
Tim Murrayeff663f2013-11-15 13:08:30 -0800242static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800243nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700244{
245 LOG_API("nContextCreate");
Tim Murray3aa89c12014-08-18 17:51:22 -0700246 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0);
Jason Sams704ff642010-02-09 16:05:07 -0800247}
248
Tim Murrayeff663f2013-11-15 13:08:30 -0800249static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800250nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000251 jint colorMin, jint colorPref,
252 jint alphaMin, jint alphaPref,
253 jint depthMin, jint depthPref,
254 jint stencilMin, jint stencilPref,
255 jint samplesMin, jint samplesPref, jfloat samplesQ,
256 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800257{
Jason Sams11c8af92010-10-13 15:31:10 -0700258 RsSurfaceConfig sc;
259 sc.alphaMin = alphaMin;
260 sc.alphaPref = alphaPref;
261 sc.colorMin = colorMin;
262 sc.colorPref = colorPref;
263 sc.depthMin = depthMin;
264 sc.depthPref = depthPref;
265 sc.samplesMin = samplesMin;
266 sc.samplesPref = samplesPref;
267 sc.samplesQ = samplesQ;
268
Jason Sams704ff642010-02-09 16:05:07 -0800269 LOG_API("nContextCreateGL");
Tim Murray3aa89c12014-08-18 17:51:22 -0700270 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700271}
272
273static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800274nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800275{
Tim Murray71a01b82014-01-07 15:36:19 -0800276 LOG_API("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
Tim Murrayeff663f2013-11-15 13:08:30 -0800277 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800278}
279
280
281
282static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800283nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800284{
Tim Murray71a01b82014-01-07 15:36:19 -0800285 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800286
Chris Wailes488230c32014-08-14 11:22:40 -0700287 ANativeWindow * window = nullptr;
288 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800289
290 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700291 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800292 }
293
Tim Murrayeff663f2013-11-15 13:08:30 -0800294 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800295}
296
297static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800298nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700299{
Tim Murray71a01b82014-01-07 15:36:19 -0800300 LOG_API("nContextDestroy, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800301 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700302}
303
Jason Sams715333b2009-11-17 17:26:46 -0800304static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800305nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800306{
Jason Sams715333b2009-11-17 17:26:46 -0800307 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
308 rsContextDump((RsContext)con, bits);
309}
Jason Samsd19f10d2009-05-22 14:03:28 -0700310
311static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800312nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700313{
Tim Murray71a01b82014-01-07 15:36:19 -0800314 LOG_API("nContextPause, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800315 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700316}
317
318static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800319nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700320{
Tim Murray71a01b82014-01-07 15:36:19 -0800321 LOG_API("nContextResume, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800322 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700323}
324
Jason Sams1c415172010-11-08 17:06:46 -0800325
326static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800327nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800328{
Tim Murray71a01b82014-01-07 15:36:19 -0800329 LOG_API("nContextGetErrorMessage, con(%p)", (RsContext)con);
Jason Sams1c415172010-11-08 17:06:46 -0800330 char buf[1024];
331
332 size_t receiveLen;
333 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800334 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700335 buf, sizeof(buf),
336 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700337 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800338 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100339 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800340 }
341 return _env->NewStringUTF(buf);
342}
343
Jason Samsedbfabd2011-05-17 15:01:29 -0700344static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800345nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700346{
Jason Sams516c3192009-10-06 13:58:47 -0700347 jint len = _env->GetArrayLength(data);
Tim Murray71a01b82014-01-07 15:36:19 -0800348 LOG_API("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
Chris Wailes488230c32014-08-14 11:22:40 -0700349 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700350 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800351 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800352 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700353 ptr, len * 4,
354 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700355 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700356 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100357 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700358 }
359 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000360 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800361}
362
363static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800364nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800365{
Tim Murray71a01b82014-01-07 15:36:19 -0800366 LOG_API("nContextPeekMessage, con(%p)", (RsContext)con);
Chris Wailes488230c32014-08-14 11:22:40 -0700367 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800368 size_t receiveLen;
369 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800370 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700371 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800372 auxDataPtr[0] = (jint)subID;
373 auxDataPtr[1] = (jint)receiveLen;
374 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000375 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700376}
377
Tim Murrayeff663f2013-11-15 13:08:30 -0800378static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700379{
Tim Murray71a01b82014-01-07 15:36:19 -0800380 LOG_API("nContextInitToClient, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800381 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700382}
383
Tim Murrayeff663f2013-11-15 13:08:30 -0800384static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700385{
Tim Murray71a01b82014-01-07 15:36:19 -0800386 LOG_API("nContextDeinitToClient, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800387 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700388}
389
Jason Sams455d6442013-02-05 19:20:18 -0800390static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800391nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800392{
Chris Wailes488230c32014-08-14 11:22:40 -0700393 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800394 jint len = 0;
395 if (data) {
396 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700397 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800398 }
Tim Murray71a01b82014-01-07 15:36:19 -0800399 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
Tim Murrayeff663f2013-11-15 13:08:30 -0800400 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800401 if (data) {
402 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
403 }
404}
405
406
Jason Sams516c3192009-10-06 13:58:47 -0700407
Tim Murray460a0492013-11-19 12:45:54 -0800408static jlong
409nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700410{
Tim Murray71a01b82014-01-07 15:36:19 -0800411 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con, type, kind, norm, size);
Tim Murray3aa89c12014-08-18 17:51:22 -0700412 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700413}
414
Tim Murray460a0492013-11-19 12:45:54 -0800415static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800416nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000417 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700418{
Jason Sams718cd1f2009-12-23 14:35:29 -0800419 int fieldCount = _env->GetArrayLength(_ids);
Tim Murray71a01b82014-01-07 15:36:19 -0800420 LOG_API("nElementCreate2, con(%p)", (RsContext)con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800421
Chris Wailes488230c32014-08-14 11:22:40 -0700422 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
423 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000424
425 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
426 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
427
428 for(int i = 0; i < fieldCount; i ++) {
429 ids[i] = (RsElement)jIds[i];
430 arraySizes[i] = (uint32_t)jArraySizes[i];
431 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800432
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800433 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
434
435 const char **nameArray = names.c_str();
436 size_t *sizeArray = names.c_str_len();
437
Tim Murray3aa89c12014-08-18 17:51:22 -0700438 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000439 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700440 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700441 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800442
Ashok Bhat98071552014-02-12 09:54:43 +0000443 free(ids);
444 free(arraySizes);
445 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
446 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
447
Tim Murray3aa89c12014-08-18 17:51:22 -0700448 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700449}
450
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700451static void
Tim Murray460a0492013-11-19 12:45:54 -0800452nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700453{
454 int dataSize = _env->GetArrayLength(_elementData);
Tim Murray71a01b82014-01-07 15:36:19 -0800455 LOG_API("nElementGetNativeData, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700456
457 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
458 assert(dataSize == 5);
459
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000460 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800461 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700462
463 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000464 const jint data = (jint)elementData[i];
465 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700466 }
467}
468
469
470static void
Tim Murray460a0492013-11-19 12:45:54 -0800471nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000472 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700473 jobjectArray _names,
474 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700475{
Ashok Bhat98071552014-02-12 09:54:43 +0000476 uint32_t dataSize = _env->GetArrayLength(_IDs);
Tim Murray71a01b82014-01-07 15:36:19 -0800477 LOG_API("nElementGetSubElements, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700478
Ashok Bhat98071552014-02-12 09:54:43 +0000479 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
480 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000481 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700482
Tim Murrayeff663f2013-11-15 13:08:30 -0800483 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700484
Ashok Bhat98071552014-02-12 09:54:43 +0000485 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700486 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000487 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700488 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000489 _env->SetLongArrayRegion(_IDs, i, 1, &id);
490 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700491 }
492
493 free(ids);
494 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700495 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700496}
497
Jason Samsd19f10d2009-05-22 14:03:28 -0700498// -----------------------------------
499
Tim Murray460a0492013-11-19 12:45:54 -0800500static jlong
501nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800502 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700503{
Jason Samsb109cc72013-01-07 18:20:12 -0800504 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800505 (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700506
Tim Murray3aa89c12014-08-18 17:51:22 -0700507 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700508}
509
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700510static void
Ashok Bhat98071552014-02-12 09:54:43 +0000511nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700512{
513 // We are packing 6 items: mDimX; mDimY; mDimZ;
514 // mDimLOD; mDimFaces; mElement; into typeData
515 int elementCount = _env->GetArrayLength(_typeData);
516
517 assert(elementCount == 6);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000518 LOG_API("nTypeGetNativeData, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700519
Ashok Bhat98071552014-02-12 09:54:43 +0000520 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800521 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700522
523 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700524 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000525 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700526 }
527}
528
Jason Samsd19f10d2009-05-22 14:03:28 -0700529// -----------------------------------
530
Tim Murray460a0492013-11-19 12:45:54 -0800531static jlong
Ashok Bhat98071552014-02-12 09:54:43 +0000532nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700533{
Tim Murray71a01b82014-01-07 15:36:19 -0800534 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
Tim Murray3aa89c12014-08-18 17:51:22 -0700535 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700536}
537
Jason Samsd19f10d2009-05-22 14:03:28 -0700538static void
Tim Murray460a0492013-11-19 12:45:54 -0800539nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800540{
Tim Murray71a01b82014-01-07 15:36:19 -0800541 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, bits);
Tim Murrayeff663f2013-11-15 13:08:30 -0800542 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800543}
544
Jason Sams72226e02013-02-22 12:45:54 -0800545static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800546nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800547{
Tim Murray71a01b82014-01-07 15:36:19 -0800548 LOG_API("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
Jason Sams615e7ce2012-01-13 14:01:20 -0800549
Tim Murrayeff663f2013-11-15 13:08:30 -0800550 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800551 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -0700552 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700553
Jason Sams72226e02013-02-22 12:45:54 -0800554 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
555 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700556}
557
558static void
Tim Murray460a0492013-11-19 12:45:54 -0800559nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800560{
Stephen Hines06883b72012-05-16 18:01:34 -0700561 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Tim Murray71a01b82014-01-07 15:36:19 -0800562 (RsContext)con, (RsAllocation)alloc, (Surface *)sur);
Jason Sams163766c2012-02-15 12:04:24 -0800563
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700564 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800565 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700566 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800567 }
568
Tim Murray460a0492013-11-19 12:45:54 -0800569 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800570}
571
572static void
Tim Murray460a0492013-11-19 12:45:54 -0800573nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800574{
Tim Murray71a01b82014-01-07 15:36:19 -0800575 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, alloc);
Tim Murray460a0492013-11-19 12:45:54 -0800576 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800577}
578
579static void
Tim Murray460a0492013-11-19 12:45:54 -0800580nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800581{
Tim Murray71a01b82014-01-07 15:36:19 -0800582 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, alloc);
Tim Murray460a0492013-11-19 12:45:54 -0800583 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800584}
585
586
587static void
Tim Murray460a0492013-11-19 12:45:54 -0800588nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800589{
Tim Murray71a01b82014-01-07 15:36:19 -0800590 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -0800591 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800592}
593
Tim Murray460a0492013-11-19 12:45:54 -0800594static jlong
595nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700596{
Jason Samsffe9f482009-06-01 17:45:53 -0700597 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000598 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700599 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700600
Jason Sams5476b452010-12-08 16:14:36 -0800601 bitmap.lockPixels();
602 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700603 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700604 (RsType)type, (RsAllocationMipmapControl)mip,
605 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800606 bitmap.unlockPixels();
607 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700608}
Jason Samsfe08d992009-05-27 14:45:32 -0700609
Tim Murray460a0492013-11-19 12:45:54 -0800610static jlong
611nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800612{
613 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000614 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800615 const SkBitmap& bitmap(*nativeBitmap);
616
617 bitmap.lockPixels();
618 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700619 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800620 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000621 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800622 bitmap.unlockPixels();
623 return id;
624}
625
Tim Murray460a0492013-11-19 12:45:54 -0800626static jlong
627nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800628{
629 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000630 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800631 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800632
Jason Sams5476b452010-12-08 16:14:36 -0800633 bitmap.lockPixels();
634 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700635 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700636 (RsType)type, (RsAllocationMipmapControl)mip,
637 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800638 bitmap.unlockPixels();
639 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800640}
641
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700642static void
Tim Murray460a0492013-11-19 12:45:54 -0800643nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700644{
645 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000646 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700647 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800648 int w = bitmap.width();
649 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700650
Jason Sams4ef66502010-12-10 16:03:15 -0800651 bitmap.lockPixels();
652 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800653 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700654 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800655 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800656 bitmap.unlockPixels();
657}
658
659static void
Tim Murray460a0492013-11-19 12:45:54 -0800660nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800661{
662 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000663 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800664 const SkBitmap& bitmap(*nativeBitmap);
665
666 bitmap.lockPixels();
667 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800668 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800669 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700670 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700671}
672
Jason Sams8a647432010-03-01 15:31:04 -0800673static void ReleaseBitmapCallback(void *bmp)
674{
675 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
676 nativeBitmap->unlockPixels();
677}
678
Romain Guy650a3eb2009-08-31 14:06:43 -0700679
Stephen Hines414fa2c2014-04-17 01:02:42 -0700680// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700681static void
Tim Murray460a0492013-11-19 12:45:54 -0800682nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000683 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700684{
Jason Samse729a942013-11-06 11:22:02 -0800685 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murray71a01b82014-01-07 15:36:19 -0800686 LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
687 (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, dataType);
Chris Wailes488230c32014-08-14 11:22:40 -0700688 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700689}
690
Stephen Hines414fa2c2014-04-17 01:02:42 -0700691// Copies from the Java array data into the Allocation pointed to by alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700692static void
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000693// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
694nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700695{
696 jint len = _env->GetArrayLength(data);
Tim Murray71a01b82014-01-07 15:36:19 -0800697 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
Chris Wailes488230c32014-08-14 11:22:40 -0700698 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -0800699 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700700 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
701}
702
Stephen Hines414fa2c2014-04-17 01:02:42 -0700703// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -0700704static void
Tim Murray460a0492013-11-19 12:45:54 -0800705nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000706 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800707{
Jason Samse729a942013-11-06 11:22:02 -0800708 RsAllocation *alloc = (RsAllocation *)_alloc;
709 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
710 LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800711 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
Chris Wailes488230c32014-08-14 11:22:40 -0700712 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 -0700713}
714
Stephen Hines414fa2c2014-04-17 01:02:42 -0700715// Copies from the Allocation pointed to by srcAlloc into the Allocation
716// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -0700717static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800718nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800719 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700720 jint dstMip, jint dstFace,
721 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -0800722 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700723 jint srcMip, jint srcFace)
724{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800725 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700726 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
727 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800728 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700729 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
730
Tim Murrayeff663f2013-11-15 13:08:30 -0800731 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700732 (RsAllocation)dstAlloc,
733 dstXoff, dstYoff,
734 dstMip, dstFace,
735 width, height,
736 (RsAllocation)srcAlloc,
737 srcXoff, srcYoff,
738 srcMip, srcFace);
739}
740
Stephen Hines414fa2c2014-04-17 01:02:42 -0700741// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700742static void
Tim Murray460a0492013-11-19 12:45:54 -0800743nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -0800744 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700745{
Jason Samse729a942013-11-06 11:22:02 -0800746 RsAllocation *alloc = (RsAllocation *)_alloc;
747 LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800748 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes);
Chris Wailes488230c32014-08-14 11:22:40 -0700749 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 -0700750}
751
Stephen Hines414fa2c2014-04-17 01:02:42 -0700752// Copies from the Allocation pointed to by srcAlloc into the Allocation
753// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -0700754static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800755nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800756 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700757 jint dstMip,
758 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -0800759 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700760 jint srcMip)
761{
762 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
763 " dstMip(%i), width(%i), height(%i),"
764 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800765 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
766 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
Jason Samsb05d6892013-04-09 15:59:24 -0700767
Tim Murrayeff663f2013-11-15 13:08:30 -0800768 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -0700769 (RsAllocation)dstAlloc,
770 dstXoff, dstYoff, dstZoff, dstMip,
771 width, height, depth,
772 (RsAllocation)srcAlloc,
773 srcXoff, srcYoff, srcZoff, srcMip);
774}
775
Jason Sams21659ac2013-11-06 15:08:07 -0800776
Stephen Hines414fa2c2014-04-17 01:02:42 -0700777// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -0700778static void
Tim Murray460a0492013-11-19 12:45:54 -0800779nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700780{
Jason Sams21659ac2013-11-06 15:08:07 -0800781 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murray71a01b82014-01-07 15:36:19 -0800782 LOG_API("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700783 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700784}
785
Stephen Hines414fa2c2014-04-17 01:02:42 -0700786// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -0700787static void
Tim Murray460a0492013-11-19 12:45:54 -0800788nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -0800789 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800790{
Jason Sams21659ac2013-11-06 15:08:07 -0800791 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murray71a01b82014-01-07 15:36:19 -0800792 LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
793 (RsContext)con, alloc, offset, count, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700794 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800795}
796
Stephen Hines414fa2c2014-04-17 01:02:42 -0700797// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -0800798static void
Tim Murray460a0492013-11-19 12:45:54 -0800799nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -0800800 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800801{
Jason Sams21659ac2013-11-06 15:08:07 -0800802 RsAllocation *alloc = (RsAllocation *)_alloc;
803 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
804 LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800805 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700806 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700807}
Jason Samsd19f10d2009-05-22 14:03:28 -0700808
Tim Murray460a0492013-11-19 12:45:54 -0800809static jlong
810nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700811{
Tim Murray71a01b82014-01-07 15:36:19 -0800812 LOG_API("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
Tim Murray3aa89c12014-08-18 17:51:22 -0700813 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700814}
815
Jason Sams5edc6082010-10-05 13:32:49 -0700816static void
Tim Murray460a0492013-11-19 12:45:54 -0800817nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -0700818{
Tim Murray71a01b82014-01-07 15:36:19 -0800819 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, (RsAllocation)alloc, dimX);
Tim Murrayeff663f2013-11-15 13:08:30 -0800820 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -0700821}
822
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700823// -----------------------------------
824
Tim Murray460a0492013-11-19 12:45:54 -0800825static jlong
826nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700827{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700828 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000829 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700830
Tim Murray3aa89c12014-08-18 17:51:22 -0700831 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800832 return id;
833}
834
Tim Murray460a0492013-11-19 12:45:54 -0800835static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800836nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800837{
838 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -0700839 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800840 return 0;
841 }
842
843 AutoJavaStringToUTF8 str(_env, _path);
844 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -0700845 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800846 return 0;
847 }
848
Tim Murray3aa89c12014-08-18 17:51:22 -0700849 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800850 return id;
851}
852
Tim Murray460a0492013-11-19 12:45:54 -0800853static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800854nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800855{
856 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -0700857 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800858
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700859 return id;
860}
861
Tim Murray460a0492013-11-19 12:45:54 -0800862static jint
863nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700864{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700865 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800866 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000867 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700868}
869
870static void
Tim Murray460a0492013-11-19 12:45:54 -0800871nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700872{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000873 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700874 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
875
Tim Murrayeff663f2013-11-15 13:08:30 -0800876 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700877
878 for(jint i = 0; i < numEntries; i ++) {
879 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
880 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
881 }
882
883 free(fileEntries);
884}
885
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000886static jlong
Tim Murray460a0492013-11-19 12:45:54 -0800887nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700888{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000889 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -0700890 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700891 return id;
892}
Jason Samsd19f10d2009-05-22 14:03:28 -0700893
894// -----------------------------------
895
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000896static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800897nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800898 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700899{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800900 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -0700901 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700902 fileNameUTF.c_str(), fileNameUTF.length(),
903 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700904
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800905 return id;
906}
907
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000908static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800909nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000910 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800911{
912 Asset* asset = reinterpret_cast<Asset*>(native_asset);
913 AutoJavaStringToUTF8 nameUTF(_env, name);
914
Tim Murray3aa89c12014-08-18 17:51:22 -0700915 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700916 nameUTF.c_str(), nameUTF.length(),
917 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800918 asset->getBuffer(false), asset->getLength());
919 return id;
920}
921
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000922static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800923nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800924 jfloat fontSize, jint dpi)
925{
926 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -0700927 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800928 return 0;
929 }
930
931 AutoJavaStringToUTF8 str(_env, _path);
932 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -0700933 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800934 return 0;
935 }
936
Tim Murray3aa89c12014-08-18 17:51:22 -0700937 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700938 str.c_str(), str.length(),
939 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800940 asset->getBuffer(false), asset->getLength());
941 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700942 return id;
943}
944
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700945// -----------------------------------
946
947static void
Tim Murray460a0492013-11-19 12:45:54 -0800948nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700949{
Tim Murray71a01b82014-01-07 15:36:19 -0800950 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Tim Murrayeff663f2013-11-15 13:08:30 -0800951 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700952}
953
954static void
Tim Murray460a0492013-11-19 12:45:54 -0800955nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700956{
Tim Murray71a01b82014-01-07 15:36:19 -0800957 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800958 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700959}
960
Tim Murray7c4caad2013-04-10 16:21:40 -0700961static jint
Tim Murray460a0492013-11-19 12:45:54 -0800962nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -0700963{
Tim Murray71a01b82014-01-07 15:36:19 -0800964 LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -0700965 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800966 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -0700967 return value;
968}
969
Jason Sams4d339932010-05-11 14:03:58 -0700970static void
Tim Murray460a0492013-11-19 12:45:54 -0800971nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800972{
Tim Murray71a01b82014-01-07 15:36:19 -0800973 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800974 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800975}
976
977static void
Tim Murray460a0492013-11-19 12:45:54 -0800978nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -0700979{
Tim Murray71a01b82014-01-07 15:36:19 -0800980 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800981 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700982}
983
Tim Murray7c4caad2013-04-10 16:21:40 -0700984static jlong
Tim Murray460a0492013-11-19 12:45:54 -0800985nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -0700986{
Tim Murray71a01b82014-01-07 15:36:19 -0800987 LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -0700988 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800989 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -0700990 return value;
991}
992
Stephen Hines031ec58c2010-10-11 10:54:21 -0700993static void
Tim Murray460a0492013-11-19 12:45:54 -0800994nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700995{
Tim Murray71a01b82014-01-07 15:36:19 -0800996 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800997 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700998}
999
Tim Murray7c4caad2013-04-10 16:21:40 -07001000static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001001nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001002{
Tim Murray71a01b82014-01-07 15:36:19 -08001003 LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001004 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001005 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001006 return value;
1007}
1008
Jason Sams4d339932010-05-11 14:03:58 -07001009static void
Tim Murray460a0492013-11-19 12:45:54 -08001010nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001011{
Tim Murray71a01b82014-01-07 15:36:19 -08001012 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -08001013 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001014}
1015
Tim Murray7c4caad2013-04-10 16:21:40 -07001016static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001017nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001018{
Tim Murray71a01b82014-01-07 15:36:19 -08001019 LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001020 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001021 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001022 return value;
1023}
1024
Stephen Hinesca54ec32010-09-20 17:20:30 -07001025static void
Tim Murray460a0492013-11-19 12:45:54 -08001026nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001027{
Tim Murray71a01b82014-01-07 15:36:19 -08001028 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams4d339932010-05-11 14:03:58 -07001029 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001030 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001031 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001032 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1033}
1034
Stephen Hinesadeb8092012-04-20 14:26:06 -07001035static void
Tim Murray460a0492013-11-19 12:45:54 -08001036nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001037{
Tim Murray71a01b82014-01-07 15:36:19 -08001038 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001039 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001040 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001041 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001042 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001043}
1044
1045static void
Tim Murray460a0492013-11-19 12:45:54 -08001046nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001047{
Tim Murray71a01b82014-01-07 15:36:19 -08001048 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001049 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001050 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001051 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001052 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001053 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001054 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001055 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1056 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1057}
1058
Jason Samsd19f10d2009-05-22 14:03:28 -07001059
1060static void
Tim Murray460a0492013-11-19 12:45:54 -08001061nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001062{
Tim Murray71a01b82014-01-07 15:36:19 -08001063 LOG_API("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
Romain Guy584a3752009-07-30 18:45:01 -07001064
1065 jint length = _env->GetArrayLength(timeZone);
1066 jbyte* timeZone_ptr;
1067 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1068
Tim Murrayeff663f2013-11-15 13:08:30 -08001069 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001070
1071 if (timeZone_ptr) {
1072 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1073 }
1074}
1075
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001076static void
Tim Murray460a0492013-11-19 12:45:54 -08001077nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001078{
Tim Murray71a01b82014-01-07 15:36:19 -08001079 LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
Tim Murrayeff663f2013-11-15 13:08:30 -08001080 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001081}
1082
1083static void
Tim Murray460a0492013-11-19 12:45:54 -08001084nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001085{
Tim Murray71a01b82014-01-07 15:36:19 -08001086 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams4d339932010-05-11 14:03:58 -07001087 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001088 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001089 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001090 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1091}
1092
Jason Sams6e494d32011-04-27 16:33:11 -07001093static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001094nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1095 jlongArray ains, jlong aout, jbyteArray params,
1096 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001097{
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001098 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con,
1099 (void *)script, slot);
Jason Sams6e494d32011-04-27 16:33:11 -07001100
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001101 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001102 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001103
Chris Wailes488230c32014-08-14 11:22:40 -07001104 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001105
Chris Wailes488230c32014-08-14 11:22:40 -07001106 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001107 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001108 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001109
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001110 if (sizeof(RsAllocation) == sizeof(jlong)) {
1111 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001112
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001113 } else {
1114 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001115
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001116 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1117
1118 for (int index = in_len; --index >= 0;) {
1119 in_allocs[index] = (RsAllocation)in_ptr[index];
1120 }
1121 }
Chris Wailes94961062014-06-11 12:01:28 -07001122 }
1123
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001124 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001125 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001126
Chris Wailes488230c32014-08-14 11:22:40 -07001127 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001128 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001129 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001130 }
1131
Chris Wailes488230c32014-08-14 11:22:40 -07001132 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001133 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001134
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001135 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001136 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001137
Chris Wailes488230c32014-08-14 11:22:40 -07001138 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001139 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001140 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001141
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001142 assert(limit_len == 6);
Chris Wailes94961062014-06-11 12:01:28 -07001143
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001144 sc.xStart = limit_ptr[0];
1145 sc.xEnd = limit_ptr[1];
1146 sc.yStart = limit_ptr[2];
1147 sc.yEnd = limit_ptr[3];
1148 sc.zStart = limit_ptr[4];
1149 sc.zEnd = limit_ptr[5];
1150 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Chris Wailes94961062014-06-11 12:01:28 -07001151
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001152 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001153 }
1154
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001155 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1156 in_allocs, in_len, (RsAllocation)aout,
1157 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001158
Chris Wailes488230c32014-08-14 11:22:40 -07001159 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001160 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001161 }
1162
Chris Wailes488230c32014-08-14 11:22:40 -07001163 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001164 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1165 }
1166
Chris Wailes488230c32014-08-14 11:22:40 -07001167 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001168 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1169 }
Chris Wailes94961062014-06-11 12:01:28 -07001170}
1171
Jason Sams22534172009-08-04 16:58:20 -07001172// -----------------------------------
1173
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001174static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001175nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001176 jstring resName, jstring cacheDir,
1177 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001178{
Tim Murray71a01b82014-01-07 15:36:19 -08001179 LOG_API("nScriptCCreate, con(%p)", (RsContext)con);
Jason Sams22534172009-08-04 16:58:20 -07001180
Jason Samse4a06c52011-03-16 16:29:28 -07001181 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1182 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001183 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001184 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001185 jint _exception = 0;
1186 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001187 if (!scriptRef) {
1188 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001189 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001190 goto exit;
1191 }
Jack Palevich43702d82009-05-28 13:38:16 -07001192 if (length < 0) {
1193 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001194 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001195 goto exit;
1196 }
Jason Samse4a06c52011-03-16 16:29:28 -07001197 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001198 if (remaining < length) {
1199 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001200 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1201 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001202 goto exit;
1203 }
Jason Samse4a06c52011-03-16 16:29:28 -07001204 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001205 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001206
Tim Murrayeff663f2013-11-15 13:08:30 -08001207 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001208
Tim Murray3aa89c12014-08-18 17:51:22 -07001209 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001210 resNameUTF.c_str(), resNameUTF.length(),
1211 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001212 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001213
Jack Palevich43702d82009-05-28 13:38:16 -07001214exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001215 if (script_ptr) {
1216 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001217 _exception ? JNI_ABORT: 0);
1218 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001219
Tim Murray3aa89c12014-08-18 17:51:22 -07001220 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001221}
1222
Tim Murray460a0492013-11-19 12:45:54 -08001223static jlong
1224nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001225{
Tim Murray71a01b82014-01-07 15:36:19 -08001226 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid);
Tim Murray3aa89c12014-08-18 17:51:22 -07001227 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001228}
1229
Tim Murray460a0492013-11-19 12:45:54 -08001230static jlong
1231nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001232{
Tim Murray71a01b82014-01-07 15:36:19 -08001233 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, (void *)sid, slot, sig);
Tim Murray3aa89c12014-08-18 17:51:22 -07001234 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001235}
1236
Tim Murray460a0492013-11-19 12:45:54 -08001237static jlong
1238nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001239{
Tim Murray71a01b82014-01-07 15:36:19 -08001240 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot);
Tim Murray3aa89c12014-08-18 17:51:22 -07001241 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001242}
1243
Tim Murray460a0492013-11-19 12:45:54 -08001244static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001245nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1246 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001247{
Tim Murray71a01b82014-01-07 15:36:19 -08001248 LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con);
Jason Sams08a81582012-09-18 12:32:10 -07001249
Ashok Bhat98071552014-02-12 09:54:43 +00001250 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001251 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001252 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1253 for(int i = 0; i < kernelsLen; ++i) {
1254 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1255 }
Jason Sams08a81582012-09-18 12:32:10 -07001256
Ashok Bhat98071552014-02-12 09:54:43 +00001257 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001258 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001259 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1260 for(int i = 0; i < srcLen; ++i) {
1261 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1262 }
Jason Sams08a81582012-09-18 12:32:10 -07001263
Ashok Bhat98071552014-02-12 09:54:43 +00001264 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001265 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001266 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1267 for(int i = 0; i < dstkLen; ++i) {
1268 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1269 }
1270
1271 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001272 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001273 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1274 for(int i = 0; i < dstfLen; ++i) {
1275 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1276 }
1277
1278 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001279 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001280 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1281 for(int i = 0; i < typesLen; ++i) {
1282 typesPtr[i] = (RsType)jTypesPtr[i];
1283 }
1284
Tim Murray3aa89c12014-08-18 17:51:22 -07001285 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001286 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1287 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1288 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1289 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1290 (RsType *)typesPtr, typesLen * sizeof(RsType));
1291
1292 free(kernelsPtr);
1293 free(srcPtr);
1294 free(dstkPtr);
1295 free(dstfPtr);
1296 free(typesPtr);
1297 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1298 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1299 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1300 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1301 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001302 return id;
1303}
1304
1305static void
Tim Murray460a0492013-11-19 12:45:54 -08001306nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001307{
Tim Murray71a01b82014-01-07 15:36:19 -08001308 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001309 (void *)gid, (void *)kid, (void *)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -08001310 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001311}
1312
1313static void
Tim Murray460a0492013-11-19 12:45:54 -08001314nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001315{
Tim Murray71a01b82014-01-07 15:36:19 -08001316 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001317 (void *)gid, (void *)kid, (void *)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -08001318 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001319}
1320
1321static void
Tim Murray460a0492013-11-19 12:45:54 -08001322nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001323{
Tim Murray71a01b82014-01-07 15:36:19 -08001324 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
Tim Murrayeff663f2013-11-15 13:08:30 -08001325 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001326}
1327
Jason Samsd19f10d2009-05-22 14:03:28 -07001328// ---------------------------------------------------------------------------
1329
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001330static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001331nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001332 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1333 jboolean depthMask, jboolean ditherEnable,
1334 jint srcFunc, jint destFunc,
1335 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001336{
Tim Murray71a01b82014-01-07 15:36:19 -08001337 LOG_API("nProgramStoreCreate, con(%p)", (RsContext)con);
Tim Murray3aa89c12014-08-18 17:51:22 -07001338 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001339 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1340 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001341}
1342
Jason Sams0011bcf2009-12-15 12:58:36 -08001343// ---------------------------------------------------------------------------
1344
1345static void
Tim Murray460a0492013-11-19 12:45:54 -08001346nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001347{
Tim Murray71a01b82014-01-07 15:36:19 -08001348 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
Tim Murrayeff663f2013-11-15 13:08:30 -08001349 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001350}
Jason Sams54c0ec12009-11-30 14:49:55 -08001351
Jason Sams68afd012009-12-17 16:55:08 -08001352static void
Tim Murray460a0492013-11-19 12:45:54 -08001353nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001354{
Tim Murray71a01b82014-01-07 15:36:19 -08001355 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Tim Murrayeff663f2013-11-15 13:08:30 -08001356 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001357}
1358
1359static void
Tim Murray460a0492013-11-19 12:45:54 -08001360nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001361{
Tim Murray71a01b82014-01-07 15:36:19 -08001362 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Tim Murrayeff663f2013-11-15 13:08:30 -08001363 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001364}
1365
Jason Samsd19f10d2009-05-22 14:03:28 -07001366// ---------------------------------------------------------------------------
1367
Tim Murray460a0492013-11-19 12:45:54 -08001368static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001369nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001370 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001371{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001372 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001373 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001374 jint paramLen = _env->GetArrayLength(params);
1375
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001376 int texCount = _env->GetArrayLength(texNames);
1377 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1378 const char ** nameArray = names.c_str();
1379 size_t* sizeArray = names.c_str_len();
1380
Tim Murray71a01b82014-01-07 15:36:19 -08001381 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001382
Ashok Bhat98071552014-02-12 09:54:43 +00001383 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1384 for(int i = 0; i < paramLen; ++i) {
1385 paramPtr[i] = (uintptr_t)jParamPtr[i];
1386 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001387 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001388 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001389 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001390
Ashok Bhat98071552014-02-12 09:54:43 +00001391 free(paramPtr);
1392 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001393 return ret;
1394}
1395
1396
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001397// ---------------------------------------------------------------------------
1398
Tim Murray460a0492013-11-19 12:45:54 -08001399static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001400nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001401 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001402{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001403 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001404 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001405 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001406
Tim Murray71a01b82014-01-07 15:36:19 -08001407 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001408
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001409 int texCount = _env->GetArrayLength(texNames);
1410 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1411 const char ** nameArray = names.c_str();
1412 size_t* sizeArray = names.c_str_len();
1413
Ashok Bhat98071552014-02-12 09:54:43 +00001414 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1415 for(int i = 0; i < paramLen; ++i) {
1416 paramPtr[i] = (uintptr_t)jParamPtr[i];
1417 }
1418
Tim Murray3aa89c12014-08-18 17:51:22 -07001419 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001420 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001421 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001422
Ashok Bhat98071552014-02-12 09:54:43 +00001423 free(paramPtr);
1424 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001425 return ret;
1426}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001427
Jason Samsebfb4362009-09-23 13:57:02 -07001428// ---------------------------------------------------------------------------
1429
Tim Murray460a0492013-11-19 12:45:54 -08001430static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001431nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001432{
Tim Murray71a01b82014-01-07 15:36:19 -08001433 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, pointSprite, cull);
Tim Murray3aa89c12014-08-18 17:51:22 -07001434 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001435}
1436
Jason Samsd19f10d2009-05-22 14:03:28 -07001437
1438// ---------------------------------------------------------------------------
1439
1440static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001441nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001442{
Tim Murray71a01b82014-01-07 15:36:19 -08001443 LOG_API("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
Tim Murrayeff663f2013-11-15 13:08:30 -08001444 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001445}
1446
1447static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001448nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001449{
Tim Murray71a01b82014-01-07 15:36:19 -08001450 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
Tim Murrayeff663f2013-11-15 13:08:30 -08001451 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001452}
1453
1454static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001455nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001456{
Tim Murray71a01b82014-01-07 15:36:19 -08001457 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, (RsProgramFragment)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001458 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001459}
1460
Jason Sams0826a6f2009-06-15 19:04:56 -07001461static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001462nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001463{
Tim Murray71a01b82014-01-07 15:36:19 -08001464 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001465 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001466}
1467
Joe Onoratod7b37742009-08-09 22:57:44 -07001468static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001469nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001470{
Tim Murray71a01b82014-01-07 15:36:19 -08001471 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001472 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001473}
1474
Joe Onoratod7b37742009-08-09 22:57:44 -07001475
Jason Sams02fb2cb2009-05-28 15:37:57 -07001476// ---------------------------------------------------------------------------
1477
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001478static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001479nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001480 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001481{
Tim Murray71a01b82014-01-07 15:36:19 -08001482 LOG_API("nSamplerCreate, con(%p)", (RsContext)con);
Tim Murray3aa89c12014-08-18 17:51:22 -07001483 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001484 (RsSamplerValue)magFilter,
1485 (RsSamplerValue)minFilter,
1486 (RsSamplerValue)wrapS,
1487 (RsSamplerValue)wrapT,
1488 (RsSamplerValue)wrapR,
1489 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001490}
1491
Jason Samsbba134c2009-06-22 15:49:21 -07001492// ---------------------------------------------------------------------------
1493
Tim Murray460a0492013-11-19 12:45:54 -08001494static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001495nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Tim Murray71a01b82014-01-07 15:36:19 -08001496 LOG_API("nPathCreate, con(%p)", (RsContext)con);
Jason Samsf15ed012011-10-31 13:23:43 -07001497
Tim Murray3aa89c12014-08-18 17:51:22 -07001498 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08001499 (RsAllocation)_vtx,
1500 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001501 return id;
1502}
1503
Tim Murray460a0492013-11-19 12:45:54 -08001504static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001505nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001506{
Tim Murray71a01b82014-01-07 15:36:19 -08001507 LOG_API("nMeshCreate, con(%p)", (RsContext)con);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001508
1509 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07001510 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001511 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1512 for(int i = 0; i < vtxLen; ++i) {
1513 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1514 }
1515
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001516 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07001517 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001518 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1519 for(int i = 0; i < idxLen; ++i) {
1520 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1521 }
1522
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001523 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07001524 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001525
Tim Murray3aa89c12014-08-18 17:51:22 -07001526 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001527 (RsAllocation *)vtxPtr, vtxLen,
1528 (RsAllocation *)idxPtr, idxLen,
1529 (uint32_t *)primPtr, primLen);
1530
Ashok Bhat98071552014-02-12 09:54:43 +00001531 free(vtxPtr);
1532 free(idxPtr);
1533 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1534 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001535 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001536 return id;
1537}
1538
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001539static jint
Tim Murray460a0492013-11-19 12:45:54 -08001540nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001541{
Tim Murray71a01b82014-01-07 15:36:19 -08001542 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001543 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001544 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001545 return vtxCount;
1546}
1547
1548static jint
Tim Murray460a0492013-11-19 12:45:54 -08001549nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001550{
Tim Murray71a01b82014-01-07 15:36:19 -08001551 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001552 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001553 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001554 return idxCount;
1555}
1556
1557static void
Ashok Bhat98071552014-02-12 09:54:43 +00001558nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001559{
Tim Murray71a01b82014-01-07 15:36:19 -08001560 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001561
1562 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001563 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001564
1565 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001566 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001567 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001568 }
1569
1570 free(allocs);
1571}
1572
1573static void
Ashok Bhat98071552014-02-12 09:54:43 +00001574nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001575{
Tim Murray71a01b82014-01-07 15:36:19 -08001576 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001577
1578 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1579 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1580
Tim Murrayeff663f2013-11-15 13:08:30 -08001581 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001582
1583 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001584 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001585 const jint prim = (jint)prims[i];
1586 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1587 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001588 }
1589
1590 free(allocs);
1591 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001592}
1593
Tim Murray56f9e6f2014-05-16 11:47:26 -07001594static jint
1595nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1596 return (jint)sizeof(void*);
1597}
1598
1599
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001600// ---------------------------------------------------------------------------
1601
Jason Samsd19f10d2009-05-22 14:03:28 -07001602
Jason Sams94d8e90a2009-06-10 16:09:05 -07001603static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001604
1605static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001606{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001607
Tim Murrayeff663f2013-11-15 13:08:30 -08001608{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1609{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1610{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1611{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1612{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1613{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001614
Tim Murrayeff663f2013-11-15 13:08:30 -08001615{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1616{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001617
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001618
Jason Sams2e1872f2010-08-17 16:25:41 -07001619// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001620{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1621{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1622{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1623{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1624{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1625{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1626{"rsnContextDump", "(JI)V", (void*)nContextDump },
1627{"rsnContextPause", "(J)V", (void*)nContextPause },
1628{"rsnContextResume", "(J)V", (void*)nContextResume },
1629{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Tim Murray460a0492013-11-19 12:45:54 -08001630{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1631{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1632{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001633
Tim Murray460a0492013-11-19 12:45:54 -08001634{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001635{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001636{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1637{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1638{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001639{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001640
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001641{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1642{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1643{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001644
Tim Murray460a0492013-11-19 12:45:54 -08001645{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001646{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001647{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001648{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001649
Tim Murray460a0492013-11-19 12:45:54 -08001650{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001651{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001652
Ashok Bhat98071552014-02-12 09:54:43 +00001653{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001654{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1655{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1656{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001657
Tim Murray460a0492013-11-19 12:45:54 -08001658{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1659{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001660
Tim Murray460a0492013-11-19 12:45:54 -08001661{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1662{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1663{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1664{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1665{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1666{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1667{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1668{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1669{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1670{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1671{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1672{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1673{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1674{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1675{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1676{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1677{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001678
Tim Murray460a0492013-11-19 12:45:54 -08001679{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1680{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1681{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1682{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001683
1684{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
1685
Tim Murray460a0492013-11-19 12:45:54 -08001686{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1687{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1688{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1689{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1690{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1691{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1692{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
1693{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
1694{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
1695{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
1696{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
1697{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001698
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001699{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001700{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
1701{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
1702{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001703{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001704{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
1705{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
1706{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001707
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001708{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001709
Tim Murray460a0492013-11-19 12:45:54 -08001710{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
1711{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
1712{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001713
Ashok Bhat98071552014-02-12 09:54:43 +00001714{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001715{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001716{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001717
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001718{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
1719{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
1720{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
1721{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
1722{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001723
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001724{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001725
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001726{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001727{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001728
Tim Murray460a0492013-11-19 12:45:54 -08001729{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
1730{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00001731{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
1732{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001733
Tim Murray56f9e6f2014-05-16 11:47:26 -07001734{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07001735};
1736
1737static int registerFuncs(JNIEnv *_env)
1738{
1739 return android::AndroidRuntime::registerNativeMethods(
1740 _env, classPathName, methods, NELEM(methods));
1741}
1742
1743// ---------------------------------------------------------------------------
1744
1745jint JNI_OnLoad(JavaVM* vm, void* reserved)
1746{
Chris Wailes488230c32014-08-14 11:22:40 -07001747 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07001748 jint result = -1;
1749
Jason Samsd19f10d2009-05-22 14:03:28 -07001750 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001751 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001752 goto bail;
1753 }
Chris Wailes488230c32014-08-14 11:22:40 -07001754 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07001755
1756 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001757 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001758 goto bail;
1759 }
1760
1761 /* success -- return valid version number */
1762 result = JNI_VERSION_1_4;
1763
1764bail:
1765 return result;
1766}