1d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams/*
24cbe25a86b4aa3353c8016a129028671e902611fStephen Hines * Copyright (C) 2011-2012 The Android Open Source Project
3d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams *
4d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * you may not use this file except in compliance with the License.
6d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * You may obtain a copy of the License at
7d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams *
8d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams *
10d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * Unless required by applicable law or agreed to in writing, software
11d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * See the License for the specific language governing permissions and
14d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams * limitations under the License.
15d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams */
16d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
17f29ca50d80e3dc379de1642e85b7963175b2ca38Jason Sams#define LOG_TAG "libRS_jni"
18f29ca50d80e3dc379de1642e85b7963175b2ca38Jason Sams
19d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include <stdlib.h>
20d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include <stdio.h>
21d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include <fcntl.h>
22d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include <unistd.h>
23d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include <math.h>
24d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include <utils/misc.h>
25d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
26ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams#include <core/SkBitmap.h>
27650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy#include <core/SkPixelRef.h>
28650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy#include <core/SkStream.h>
29650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy#include <core/SkTemplates.h>
30650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy#include <images/SkImageDecoder.h>
31ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams
32b13b9bdad2baf6ad1ec2e56b6b7598fa20f55fc4Mathias Agopian#include <androidfw/Asset.h>
33b13b9bdad2baf6ad1ec2e56b6b7598fa20f55fc4Mathias Agopian#include <androidfw/AssetManager.h>
34b13b9bdad2baf6ad1ec2e56b6b7598fa20f55fc4Mathias Agopian#include <androidfw/ResourceTypes.h>
35f29ca50d80e3dc379de1642e85b7963175b2ca38Jason Sams
36d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include "jni.h"
37d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include "JNIHelp.h"
38d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#include "android_runtime/AndroidRuntime.h"
39ee956053d6e3f7a7a82e41853b9b251fdc226d7aJim Miller#include "android_runtime/android_view_Surface.h"
40b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk#include "android_runtime/android_util_AssetManager.h"
41d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
421d6983af336b2b1d3a24aece58ce0850aa79e8a0Jason Sams#include <rs.h>
431d6983af336b2b1d3a24aece58ce0850aa79e8a0Jason Sams#include <rsEnv.h>
44fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams#include <gui/Surface.h>
45faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams#include <gui/SurfaceTexture.h>
46faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams#include <gui/SurfaceTextureClient.h>
47faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams#include <android_runtime/android_graphics_SurfaceTexture.h>
48d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
493762c311729fe9f3af085c14c5c1fb471d994c03Steve Block//#define LOG_API ALOGE
50d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams#define LOG_API(...)
51d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
52d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsusing namespace android;
53d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
54b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukclass AutoJavaStringToUTF8 {
55b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukpublic:
562123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
57b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        fCStr = env->GetStringUTFChars(str, NULL);
58b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        fLength = env->GetStringUTFLength(str);
59b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
602123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    ~AutoJavaStringToUTF8() {
61b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        fEnv->ReleaseStringUTFChars(fJStr, fCStr);
62b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
63b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    const char* c_str() const { return fCStr; }
64b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    jsize length() const { return fLength; }
65b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
66b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukprivate:
67b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    JNIEnv*     fEnv;
68b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    jstring     fJStr;
69b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    const char* fCStr;
70b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    jsize       fLength;
71b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk};
72b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
732123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchoukclass AutoJavaStringArrayToUTF8 {
742123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchoukpublic:
752123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
762123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
772123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        mCStrings = NULL;
782123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        mSizeArray = NULL;
792123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        if (stringsLength > 0) {
802123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk            mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
812123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk            mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
822123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk            for (jsize ct = 0; ct < stringsLength; ct ++) {
832123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk                jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
842123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk                mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
852123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk                mSizeArray[ct] = mEnv->GetStringUTFLength(s);
862123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk            }
872123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        }
882123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    }
892123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    ~AutoJavaStringArrayToUTF8() {
902123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        for (jsize ct=0; ct < mStringsLength; ct++) {
912123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk            jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
922123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk            mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
932123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        }
942123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        free(mCStrings);
952123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        free(mSizeArray);
962123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    }
972123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    const char **c_str() const { return mCStrings; }
982123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    size_t *c_str_len() const { return mSizeArray; }
992123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    jsize length() const { return mStringsLength; }
1002123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk
1012123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchoukprivate:
1022123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    JNIEnv      *mEnv;
1032123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    jobjectArray mStrings;
1042123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    const char **mCStrings;
1052123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    size_t      *mSizeArray;
1062123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    jsize        mStringsLength;
1072123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk};
1082123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk
109d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams// ---------------------------------------------------------------------------
110d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
111ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Samsstatic jfieldID gContextId = 0;
112ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Samsstatic jfieldID gNativeBitmapID = 0;
11343ee06857bb7f99446d1d84f8789016c5d105558Jason Samsstatic jfieldID gTypeNativeCache = 0;
114d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
115d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void _nInit(JNIEnv *_env, jclass _this)
116d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
117d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    gContextId             = _env->GetFieldID(_this, "mContext", "I");
118ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams
119ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams    jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
120ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams    gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
121d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
122d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
123d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams// ---------------------------------------------------------------------------
124d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
1253eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Samsstatic void
1262e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnContextFinish(JNIEnv *_env, jobject _this, RsContext con)
12796ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams{
12896ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    LOG_API("nContextFinish, con(%p)", con);
12996ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    rsContextFinish(con);
13096ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams}
13196ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams
13296ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Samsstatic void
1332e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
1343eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams{
13507ae40623737a6060b8a925fd2e6bba76780dcd4Jason Sams    LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
1363eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams    jint len = _env->GetArrayLength(str);
1373eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams    jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
138bc948dedcee57a66fe2cb38d4c79d04a10c7efb3Jason Sams    rsAssignName(con, (void *)obj, (const char *)cptr, len);
1393eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams    _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
1403eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams}
1413eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams
142fb10c16a0528a418053e4b8e75eebe57476b86efAlex Sakhartchoukstatic jstring
1432e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
144fb10c16a0528a418053e4b8e75eebe57476b86efAlex Sakhartchouk{
145fb10c16a0528a418053e4b8e75eebe57476b86efAlex Sakhartchouk    LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
146fb10c16a0528a418053e4b8e75eebe57476b86efAlex Sakhartchouk    const char *name = NULL;
147581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    rsaGetName(con, (void *)obj, &name);
148581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    if(name == NULL || strlen(name) == 0) {
149581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk        return NULL;
150581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    }
151fb10c16a0528a418053e4b8e75eebe57476b86efAlex Sakhartchouk    return _env->NewStringUTF(name);
152fb10c16a0528a418053e4b8e75eebe57476b86efAlex Sakhartchouk}
153fb10c16a0528a418053e4b8e75eebe57476b86efAlex Sakhartchouk
1547ce033d797e5df5e2131e2ed459fba181eaf4658Jason Samsstatic void
1552e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
1567ce033d797e5df5e2131e2ed459fba181eaf4658Jason Sams{
1577ce033d797e5df5e2131e2ed459fba181eaf4658Jason Sams    LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
1589c25aee52672f9c8908e062bde502341c189970eJason Sams    rsObjDestroy(con, (void *)obj);
1597ce033d797e5df5e2131e2ed459fba181eaf4658Jason Sams}
1607ce033d797e5df5e2131e2ed459fba181eaf4658Jason Sams
1613eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams// ---------------------------------------------------------------------------
1623eaa338e11a3b0d6b87d705e5bb95625e82347bdJason Sams
163d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic jint
164d19f10d43aa400e1183aa21a97099d02074131a2Jason SamsnDeviceCreate(JNIEnv *_env, jobject _this)
165d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
166d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    LOG_API("nDeviceCreate");
167d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    return (jint)rsDeviceCreate();
168d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
169d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
170d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
171d19f10d43aa400e1183aa21a97099d02074131a2Jason SamsnDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
172d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
173d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    LOG_API("nDeviceDestroy");
174d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    return rsDeviceDestroy((RsDevice)dev);
175d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
176d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
177ebfb436a49673693b98469683451bd9ede797557Jason Samsstatic void
178ebfb436a49673693b98469683451bd9ede797557Jason SamsnDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
179ebfb436a49673693b98469683451bd9ede797557Jason Sams{
180ebfb436a49673693b98469683451bd9ede797557Jason Sams    LOG_API("nDeviceSetConfig  dev(%p), param(%i), value(%i)", (void *)dev, p, value);
181ebfb436a49673693b98469683451bd9ede797557Jason Sams    return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
182ebfb436a49673693b98469683451bd9ede797557Jason Sams}
183ebfb436a49673693b98469683451bd9ede797557Jason Sams
184d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic jint
1854382467a80dd12c6362d57edca7f2367f7ae877cStephen HinesnContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer)
186d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
187d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    LOG_API("nContextCreate");
1884382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer);
189704ff64b099406bb328898a7443921f22dbffd6dJason Sams}
190704ff64b099406bb328898a7443921f22dbffd6dJason Sams
191704ff64b099406bb328898a7443921f22dbffd6dJason Samsstatic jint
1924382467a80dd12c6362d57edca7f2367f7ae877cStephen HinesnContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
19311c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int colorMin, int colorPref,
19411c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int alphaMin, int alphaPref,
19511c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int depthMin, int depthPref,
19611c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int stencilMin, int stencilPref,
1972c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int samplesMin, int samplesPref, float samplesQ,
1982c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int dpi)
19911c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams{
20011c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    RsSurfaceConfig sc;
20111c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.alphaMin = alphaMin;
20211c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.alphaPref = alphaPref;
20311c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.colorMin = colorMin;
20411c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.colorPref = colorPref;
20511c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.depthMin = depthMin;
20611c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.depthPref = depthPref;
20711c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.samplesMin = samplesMin;
20811c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.samplesPref = samplesPref;
20911c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    sc.samplesQ = samplesQ;
21011c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams
211704ff64b099406bb328898a7443921f22dbffd6dJason Sams    LOG_API("nContextCreateGL");
2124382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
213d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
214d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
215d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
2162e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
2177d787b4722eaeb79cab42c36060336e092b77b5fJason Sams{
2187d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
2197d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    rsContextSetPriority(con, p);
2207d787b4722eaeb79cab42c36060336e092b77b5fJason Sams}
2217d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
2227d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
2237d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
2247d787b4722eaeb79cab42c36060336e092b77b5fJason Samsstatic void
2252e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
226efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams{
2273bc47d438171dce294e816366d53bc9eca772c5bJason Sams    LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
228efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
2296c72eec06e69559b4d990777c7b280aa81586797Alex Sakhartchouk    ANativeWindow * window = NULL;
230efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    if (wnd == NULL) {
231efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
232efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    } else {
23364a55af0ac700baecb0877235eb42caac59a3560Jeff Brown        window = android_view_Surface_getNativeWindow(_env, wnd).get();
234efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    }
235efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
2366c72eec06e69559b4d990777c7b280aa81586797Alex Sakhartchouk    rsContextSetSurface(con, width, height, window);
237efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams}
238efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
239efd9b6fb2e0f31b50db089352118e5daeb268879Jason Samsstatic void
240faa32b33b50ad941f631716dd0915e936bdc3ac5Jason SamsnContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
241faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams{
242faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);
243faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams
244faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    sp<ANativeWindow> window;
245faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    sp<SurfaceTexture> st;
246faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    if (sur == 0) {
247faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams
248faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    } else {
249faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        st = SurfaceTexture_getSurfaceTexture(_env, sur);
250faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        window = new SurfaceTextureClient(st);
251faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    }
252faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams
253faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    rsContextSetSurface(con, width, height, window.get());
254faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams}
255faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams
256faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Samsstatic void
2572e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
258d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
2592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    LOG_API("nContextDestroy, con(%p)", con);
2602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    rsContextDestroy(con);
261d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
262d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
263715333b832fb448c32165c7d97d408a3fa43f7cbJason Samsstatic void
2642e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
265715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams{
266715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    LOG_API("nContextDump, con(%p)  bits(%i)", (RsContext)con, bits);
267715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    rsContextDump((RsContext)con, bits);
268715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams}
269d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
270d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
2712e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnContextPause(JNIEnv *_env, jobject _this, RsContext con)
27265e7aa56f56097418d617663683544c25b3988eaJason Sams{
27365e7aa56f56097418d617663683544c25b3988eaJason Sams    LOG_API("nContextPause, con(%p)", con);
27465e7aa56f56097418d617663683544c25b3988eaJason Sams    rsContextPause(con);
27565e7aa56f56097418d617663683544c25b3988eaJason Sams}
27665e7aa56f56097418d617663683544c25b3988eaJason Sams
27765e7aa56f56097418d617663683544c25b3988eaJason Samsstatic void
2782e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnContextResume(JNIEnv *_env, jobject _this, RsContext con)
27965e7aa56f56097418d617663683544c25b3988eaJason Sams{
28065e7aa56f56097418d617663683544c25b3988eaJason Sams    LOG_API("nContextResume, con(%p)", con);
28165e7aa56f56097418d617663683544c25b3988eaJason Sams    rsContextResume(con);
28265e7aa56f56097418d617663683544c25b3988eaJason Sams}
28365e7aa56f56097418d617663683544c25b3988eaJason Sams
2841c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
2851c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Samsstatic jstring
2861c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason SamsnContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
2871c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams{
2881c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    LOG_API("nContextGetErrorMessage, con(%p)", con);
2891c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    char buf[1024];
2901c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
2911c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    size_t receiveLen;
2921c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    uint32_t subID;
29365bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams    int id = rsContextGetMessage(con,
29465bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                 buf, sizeof(buf),
29565bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                 &receiveLen, sizeof(receiveLen),
296edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                                 &subID, sizeof(subID));
2971c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    if (!id && receiveLen) {
29871f2cf116aab893e224056c38ab146bd1538dd3eSteve Block        ALOGV("message receive buffer too small.  %i", receiveLen);
2991c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    }
3001c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    return _env->NewStringUTF(buf);
3011c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams}
3021c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
303edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Samsstatic jint
3041c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason SamsnContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
305516c31911578db8ce53529483c3ded918ac7dc6bJason Sams{
306516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    jint len = _env->GetArrayLength(data);
307516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
308516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    jint *ptr = _env->GetIntArrayElements(data, NULL);
309516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    size_t receiveLen;
3101c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    uint32_t subID;
31165bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams    int id = rsContextGetMessage(con,
31265bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                 ptr, len * 4,
31365bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                 &receiveLen, sizeof(receiveLen),
314edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                                 &subID, sizeof(subID));
315516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    if (!id && receiveLen) {
31671f2cf116aab893e224056c38ab146bd1538dd3eSteve Block        ALOGV("message receive buffer too small.  %i", receiveLen);
317516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
318516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    _env->ReleaseIntArrayElements(data, ptr, 0);
319edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams    return id;
3201c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams}
3211c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
3221c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Samsstatic jint
323edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason SamsnContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
3241c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams{
3251c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    LOG_API("nContextPeekMessage, con(%p)", con);
3261c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
3271c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    size_t receiveLen;
3281c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    uint32_t subID;
32965bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams    int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
330edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                                  &subID, sizeof(subID));
3311c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    auxDataPtr[0] = (jint)subID;
3321c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    auxDataPtr[1] = (jint)receiveLen;
3331c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
334516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    return id;
335516c31911578db8ce53529483c3ded918ac7dc6bJason Sams}
336516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
3372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Samsstatic void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
338516c31911578db8ce53529483c3ded918ac7dc6bJason Sams{
339516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    LOG_API("nContextInitToClient, con(%p)", con);
340516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    rsContextInitToClient(con);
341516c31911578db8ce53529483c3ded918ac7dc6bJason Sams}
342516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
3432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Samsstatic void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
344516c31911578db8ce53529483c3ded918ac7dc6bJason Sams{
345516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    LOG_API("nContextDeinitToClient, con(%p)", con);
346516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    rsContextDeinitToClient(con);
347516c31911578db8ce53529483c3ded918ac7dc6bJason Sams}
348516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
349516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
350718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Samsstatic jint
3512e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
352d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
353718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams    LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
354718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams    return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
355d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
356d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
357718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Samsstatic jint
3582123b46ba85adb2cfb78068f8368e830640118d3Alex SakhartchouknElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
3592123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk                jintArray _ids, jobjectArray _names, jintArray _arraySizes)
360d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
361718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams    int fieldCount = _env->GetArrayLength(_ids);
362704ff64b099406bb328898a7443921f22dbffd6dJason Sams    LOG_API("nElementCreate2, con(%p)", con);
363718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams
364718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams    jint *ids = _env->GetIntArrayElements(_ids, NULL);
36570d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
366718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams
3672123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
3682123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk
3692123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    const char **nameArray = names.c_str();
3702123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    size_t *sizeArray = names.c_str_len();
3712123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk
372e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jint id = (jint)rsElementCreate2(con,
373e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                     (RsElement *)ids, fieldCount,
3747a22e107d100caea2a661ec73e4525d69f0f9759Jason Sams                                     nameArray, fieldCount * sizeof(size_t),  sizeArray,
375e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                     (const uint32_t *)arraySizes, fieldCount);
3762123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk
377718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams    _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
37870d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
379718cd1f322ee5b62b6a49cb36195bcb18a5ab711Jason Sams    return (jint)id;
380d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
381d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
382dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchoukstatic void
3832e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
384dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk{
385dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    int dataSize = _env->GetArrayLength(_elementData);
386dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    LOG_API("nElementGetNativeData, con(%p)", con);
387dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
388dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
389dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    assert(dataSize == 5);
390dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
391dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    uint32_t elementData[5];
392581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
393dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
394dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    for(jint i = 0; i < dataSize; i ++) {
395dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk        _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
396dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    }
397dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk}
398dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
399dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
400dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchoukstatic void
4017d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex SakhartchouknElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
4027d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk                       jintArray _IDs,
4037d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk                       jobjectArray _names,
4047d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk                       jintArray _arraySizes)
405dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk{
406dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    int dataSize = _env->GetArrayLength(_IDs);
407dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    LOG_API("nElementGetSubElements, con(%p)", con);
408dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
409dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
410dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
4117d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
412dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
4137d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
414dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
41511c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams    for(jint i = 0; i < dataSize; i++) {
416dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk        _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
417dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk        _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
4187d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk        _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
419dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    }
420dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
421dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    free(ids);
422dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    free(names);
4237d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    free(arraySizes);
424dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk}
425dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
426d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams// -----------------------------------
427d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
4283b9c52ab8c1ab240d2299358d01a8efbe392d111Jason Samsstatic int
429bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason SamsnTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
430bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams            jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
431d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
432bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
433bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams            con, eid, dimx, dimy, dimz, mips, faces);
4343b9c52ab8c1ab240d2299358d01a8efbe392d111Jason Sams
435c576537166fa3f829e4b5d8c6617a36b47e75fc3Jason Sams    jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
4363b9c52ab8c1ab240d2299358d01a8efbe392d111Jason Sams    return (jint)id;
437d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
438d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
439dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchoukstatic void
4402e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
441dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk{
442dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    // We are packing 6 items: mDimX; mDimY; mDimZ;
443dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    // mDimLOD; mDimFaces; mElement; into typeData
444dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    int elementCount = _env->GetArrayLength(_typeData);
445dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
446dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    assert(elementCount == 6);
447dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    LOG_API("nTypeCreate, con(%p)", con);
448dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
449dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    uint32_t typeData[6];
450581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
451dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
452dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    for(jint i = 0; i < elementCount; i ++) {
453dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk        _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
454dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    }
455dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk}
456dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
457d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams// -----------------------------------
458d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
459d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic jint
460857d0c7017da763a420e825fffa2f260eb982c97Jason SamsnAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
461d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
462857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
463857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
464d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
465d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
466d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
4675476b450e50939940dcf3f15c92335cee2fc572dJason SamsnAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
4685476b450e50939940dcf3f15c92335cee2fc572dJason Sams{
4695476b450e50939940dcf3f15c92335cee2fc572dJason Sams    LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
4705476b450e50939940dcf3f15c92335cee2fc572dJason Sams    rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
4715476b450e50939940dcf3f15c92335cee2fc572dJason Sams}
4725476b450e50939940dcf3f15c92335cee2fc572dJason Sams
473615e7cee03d1a53072b0369fa9f247811ac56845Jason Samsstatic jint
474615e7cee03d1a53072b0369fa9f247811ac56845Jason SamsnAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a)
475615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams{
476615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams    LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
477615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams    return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
478615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams}
479615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams
480f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Samsstatic void
481fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason SamsnAllocationGetSurfaceTextureID2(JNIEnv *_env, jobject _this, RsContext con, jint a, jobject jst)
482fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams{
483fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    LOG_API("nAllocationGetSurfaceTextureID2, con(%p), a(%p)", con, (RsAllocation)a);
484fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, jst);
485fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams
486fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    rsAllocationGetSurfaceTextureID2(con, (RsAllocation)a, st.get(), sizeof(SurfaceTexture *));
487fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams}
488fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams
489fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Samsstatic void
490fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason SamsnAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
491163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams{
49206883b71d0b75eee255b292ba66684eddc5fb172Stephen Hines    LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
493163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams            con, alloc, (Surface *)sur);
494163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
495fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    sp<Surface> s;
496163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    if (sur != 0) {
49764a55af0ac700baecb0877235eb42caac59a3560Jeff Brown        s = android_view_Surface_getSurface(_env, sur);
498163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
499163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
500fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
501163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams}
502163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
503163766cbe798baf8e86eb8201bc6c3def931d59aJason Samsstatic void
504163766cbe798baf8e86eb8201bc6c3def931d59aJason SamsnAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
505163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams{
506163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
507163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    rsAllocationIoSend(con, alloc);
508163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams}
509163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
510163766cbe798baf8e86eb8201bc6c3def931d59aJason Samsstatic void
511163766cbe798baf8e86eb8201bc6c3def931d59aJason SamsnAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
512163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams{
513163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
514163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    rsAllocationIoReceive(con, alloc);
515163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams}
516163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
517163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
518163766cbe798baf8e86eb8201bc6c3def931d59aJason Samsstatic void
519f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason SamsnAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
520f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams{
521f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
522f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
523f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams}
524f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams
525fe08d99725efd0dde7ba67ff1979a04fec2ba99fJason Samsstatic int
5265476b450e50939940dcf3f15c92335cee2fc572dJason SamsnAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
527fe08d99725efd0dde7ba67ff1979a04fec2ba99fJason Sams{
528ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams    SkBitmap const * nativeBitmap =
529ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
530ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams    const SkBitmap& bitmap(*nativeBitmap);
531fe08d99725efd0dde7ba67ff1979a04fec2ba99fJason Sams
5325476b450e50939940dcf3f15c92335cee2fc572dJason Sams    bitmap.lockPixels();
5335476b450e50939940dcf3f15c92335cee2fc572dJason Sams    const void* ptr = bitmap.getPixels();
534c576537166fa3f829e4b5d8c6617a36b47e75fc3Jason Sams    jint id = (jint)rsAllocationCreateFromBitmap(con,
53565bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                                  (RsType)type, (RsAllocationMipmapControl)mip,
53665bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                                  ptr, bitmap.getSize(), usage);
5375476b450e50939940dcf3f15c92335cee2fc572dJason Sams    bitmap.unlockPixels();
5385476b450e50939940dcf3f15c92335cee2fc572dJason Sams    return id;
539ffe9f48890dde7173a0845d32887fdf94a49b0a7Jason Sams}
540fe08d99725efd0dde7ba67ff1979a04fec2ba99fJason Sams
54167f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchoukstatic int
5425476b450e50939940dcf3f15c92335cee2fc572dJason SamsnAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
54367f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk{
54467f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk    SkBitmap const * nativeBitmap =
54567f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
54667f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk    const SkBitmap& bitmap(*nativeBitmap);
54767f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk
5485476b450e50939940dcf3f15c92335cee2fc572dJason Sams    bitmap.lockPixels();
5495476b450e50939940dcf3f15c92335cee2fc572dJason Sams    const void* ptr = bitmap.getPixels();
550c576537166fa3f829e4b5d8c6617a36b47e75fc3Jason Sams    jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
55165bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                                      (RsType)type, (RsAllocationMipmapControl)mip,
55265bdaf1c6d463d9441125d2c87a36015bfef2d95Jason Sams                                                      ptr, bitmap.getSize(), usage);
5535476b450e50939940dcf3f15c92335cee2fc572dJason Sams    bitmap.unlockPixels();
5545476b450e50939940dcf3f15c92335cee2fc572dJason Sams    return id;
55567f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk}
55667f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk
55726ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchoukstatic void
5584ef6650bd05a39a09958ea1db92f120ea4949cb1Jason SamsnAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
55926ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk{
56026ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk    SkBitmap const * nativeBitmap =
56126ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
56226ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk    const SkBitmap& bitmap(*nativeBitmap);
563f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    int w = bitmap.width();
564f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    int h = bitmap.height();
56526ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk
5664ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    bitmap.lockPixels();
5674ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    const void* ptr = bitmap.getPixels();
568f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
569304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                       0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
570f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams                       w, h, ptr, bitmap.getSize());
5714ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    bitmap.unlockPixels();
5728a64743f37ed35af7c2204acd18bb3d62d8f66d5Jason Sams}
5738a64743f37ed35af7c2204acd18bb3d62d8f66d5Jason Sams
5744ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Samsstatic void
5754ef6650bd05a39a09958ea1db92f120ea4949cb1Jason SamsnAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
5768a64743f37ed35af7c2204acd18bb3d62d8f66d5Jason Sams{
5774ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    SkBitmap const * nativeBitmap =
5784ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
5794ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    const SkBitmap& bitmap(*nativeBitmap);
5808a64743f37ed35af7c2204acd18bb3d62d8f66d5Jason Sams
5814ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    bitmap.lockPixels();
5824ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    void* ptr = bitmap.getPixels();
5834ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
5844ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    bitmap.unlockPixels();
585835b8544cc333ef87e42b1d71cf8ad3cddccdc19Alex Sakhartchouk    bitmap.notifyPixelsChanged();
5868a64743f37ed35af7c2204acd18bb3d62d8f66d5Jason Sams}
5878a64743f37ed35af7c2204acd18bb3d62d8f66d5Jason Sams
5884ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Samsstatic void ReleaseBitmapCallback(void *bmp)
589650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy{
5904ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
5914ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    nativeBitmap->unlockPixels();
592650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy}
593650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy
5944ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams
595d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
59649a05d7b82956009f03acbb92a064eed054eb031Jason SamsnAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes)
597d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
598d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint len = _env->GetArrayLength(data);
59949a05d7b82956009f03acbb92a064eed054eb031Jason Sams    LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
600d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint *ptr = _env->GetIntArrayElements(data, NULL);
60149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
602d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
603d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
604d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
605d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
60649a05d7b82956009f03acbb92a064eed054eb031Jason SamsnAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes)
607d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
608d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint len = _env->GetArrayLength(data);
60949a05d7b82956009f03acbb92a064eed054eb031Jason Sams    LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
610768bc02d815a94ad29146f1ed60c847d1af118ccJason Sams    jshort *ptr = _env->GetShortArrayElements(data, NULL);
61149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
612768bc02d815a94ad29146f1ed60c847d1af118ccJason Sams    _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
613d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
614d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
615d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
61649a05d7b82956009f03acbb92a064eed054eb031Jason SamsnAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes)
617d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
618d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint len = _env->GetArrayLength(data);
61949a05d7b82956009f03acbb92a064eed054eb031Jason Sams    LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
620768bc02d815a94ad29146f1ed60c847d1af118ccJason Sams    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
62149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
622768bc02d815a94ad29146f1ed60c847d1af118ccJason Sams    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
623d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
624d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
625d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
62649a05d7b82956009f03acbb92a064eed054eb031Jason SamsnAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes)
627d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
628d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint len = _env->GetArrayLength(data);
62949a05d7b82956009f03acbb92a064eed054eb031Jason Sams    LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
630d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
63149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
632d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
633d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
634d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
635d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
63649a05d7b82956009f03acbb92a064eed054eb031Jason Sams//    native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
63749a05d7b82956009f03acbb92a064eed054eb031Jason SamsnAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes)
63849bdaf0293408159df18a1d8540360f9623c40f7Jason Sams{
63949bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    jint len = _env->GetArrayLength(data);
64049a05d7b82956009f03acbb92a064eed054eb031Jason Sams    LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
64149bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
6424cbe25a86b4aa3353c8016a129028671e902611fStephen Hines    rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
64349bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
64449bdaf0293408159df18a1d8540360f9623c40f7Jason Sams}
64549bdaf0293408159df18a1d8540360f9623c40f7Jason Sams
64649bdaf0293408159df18a1d8540360f9623c40f7Jason Samsstatic void
647fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason SamsnAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
648fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams                    jint w, jint h, jshortArray data, int sizeBytes)
649fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams{
650fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jint len = _env->GetArrayLength(data);
651fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    LOG_API("nAllocation2DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
652fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jshort *ptr = _env->GetShortArrayElements(data, NULL);
653fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
654fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
655fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams}
656fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams
657fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Samsstatic void
658fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason SamsnAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
659fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams                    jint w, jint h, jbyteArray data, int sizeBytes)
660fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams{
661fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jint len = _env->GetArrayLength(data);
662fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    LOG_API("nAllocation2DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
663fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
664fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
665fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
666fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams}
667fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams
668fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Samsstatic void
66949a05d7b82956009f03acbb92a064eed054eb031Jason SamsnAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
67049a05d7b82956009f03acbb92a064eed054eb031Jason Sams                    jint w, jint h, jintArray data, int sizeBytes)
671d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
672d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint len = _env->GetArrayLength(data);
67349a05d7b82956009f03acbb92a064eed054eb031Jason Sams    LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
674d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint *ptr = _env->GetIntArrayElements(data, NULL);
67549a05d7b82956009f03acbb92a064eed054eb031Jason Sams    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
676d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
677d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
678d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
679d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
68049a05d7b82956009f03acbb92a064eed054eb031Jason SamsnAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
68149a05d7b82956009f03acbb92a064eed054eb031Jason Sams                    jint w, jint h, jfloatArray data, int sizeBytes)
682d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
683d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jint len = _env->GetArrayLength(data);
68449a05d7b82956009f03acbb92a064eed054eb031Jason Sams    LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
685d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
68649a05d7b82956009f03acbb92a064eed054eb031Jason Sams    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
687d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
688d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
689d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
69040a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Samsstatic void
691304b1f5497155bcf91e7b855cfab7a675e80bf26Alex SakhartchouknAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
692304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                        jint dstAlloc, jint dstXoff, jint dstYoff,
693304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                        jint dstMip, jint dstFace,
694304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                        jint width, jint height,
695304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                        jint srcAlloc, jint srcXoff, jint srcYoff,
696304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                        jint srcMip, jint srcFace)
697304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk{
6984c2e4c80ce519e09e5b00fd7533e64a834d70639Jason Sams    LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
699304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk            " dstMip(%i), dstFace(%i), width(%i), height(%i),"
700304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk            " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
701304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk            con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
702304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk            width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
703304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk
704304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    rsAllocationCopy2DRange(con,
705304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            (RsAllocation)dstAlloc,
706304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstXoff, dstYoff,
707304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstMip, dstFace,
708304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            width, height,
709304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            (RsAllocation)srcAlloc,
710304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcXoff, srcYoff,
711304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcMip, srcFace);
712304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk}
713304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk
714304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchoukstatic void
7152e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
71640a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams{
71740a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams    jint len = _env->GetArrayLength(data);
71840a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams    LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
71940a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams    jint *ptr = _env->GetIntArrayElements(data, NULL);
720e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jsize length = _env->GetArrayLength(data);
7213655e44d8b291128e79a7a9b5277b6da217144fcJason Sams    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
722ae209acd8d48755df7d49459b1bcbc3b8e20561dJoe Onorato    _env->ReleaseIntArrayElements(data, ptr, 0);
72340a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams}
72440a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams
72540a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Samsstatic void
726fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason SamsnAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
727fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams{
728fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jint len = _env->GetArrayLength(data);
729fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
730fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jshort *ptr = _env->GetShortArrayElements(data, NULL);
731e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jsize length = _env->GetArrayLength(data);
7323655e44d8b291128e79a7a9b5277b6da217144fcJason Sams    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
733fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    _env->ReleaseShortArrayElements(data, ptr, 0);
734fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams}
735fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams
736fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Samsstatic void
737fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason SamsnAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
738fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams{
739fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jint len = _env->GetArrayLength(data);
740fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
741fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
742e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jsize length = _env->GetArrayLength(data);
7433655e44d8b291128e79a7a9b5277b6da217144fcJason Sams    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
744fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams    _env->ReleaseByteArrayElements(data, ptr, 0);
745fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams}
746fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Sams
747fb9f82ca4f11cf7e43a001f3e6fd1b381cc86210Jason Samsstatic void
7482e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
74940a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams{
75040a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams    jint len = _env->GetArrayLength(data);
751a8f2acee39aae94f9d7148f775ca8e35344da4b4Joe Onorato    LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
75240a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams    jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
753e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jsize length = _env->GetArrayLength(data);
7543655e44d8b291128e79a7a9b5277b6da217144fcJason Sams    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
755ae209acd8d48755df7d49459b1bcbc3b8e20561dJoe Onorato    _env->ReleaseFloatArrayElements(data, ptr, 0);
75640a29e8e28772b37ab0f9fe9708ecdcba24abb84Jason Sams}
757d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
758dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchoukstatic jint
7592e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
760dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk{
761dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk    LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
762581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    return (jint) rsaAllocationGetType(con, (RsAllocation)a);
763dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk}
764dfac814c18f73dd7289f9927edca3e3b6ec6bc00Alex Sakhartchouk
7655edc608a0749ed4b7074b5c1243043eb722c3c31Jason Samsstatic void
7665edc608a0749ed4b7074b5c1243043eb722c3c31Jason SamsnAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
7675edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams{
7685edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
7695edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
7705edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams}
7715edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams
7725edc608a0749ed4b7074b5c1243043eb722c3c31Jason Samsstatic void
7735edc608a0749ed4b7074b5c1243043eb722c3c31Jason SamsnAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
7745edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams{
7755edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
7765edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
7775edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams}
7785edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams
779aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk// -----------------------------------
780aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
781aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchoukstatic int
7822e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
783aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk{
78471f2cf116aab893e224056c38ab146bd1538dd3eSteve Block    ALOGV("______nFileA3D %u", (uint32_t) native_asset);
785aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
786aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    Asset* asset = reinterpret_cast<Asset*>(native_asset);
787aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
788b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
789b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    return id;
790b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk}
791b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
792b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukstatic int
793b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex SakhartchouknFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
794b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk{
795b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
796b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    if (mgr == NULL) {
797b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return 0;
798b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
799b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
800b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    AutoJavaStringToUTF8 str(_env, _path);
801b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
802b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    if (asset == NULL) {
803b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return 0;
804b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
805b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
806b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
807b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    return id;
808b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk}
809b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
810b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukstatic int
811b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex SakhartchouknFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
812b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk{
813b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
814b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
815b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
816aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    return id;
817aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk}
818aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
819aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchoukstatic int
8202e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
821aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk{
822aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    int32_t numEntries = 0;
823581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
824aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    return numEntries;
825aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk}
826aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
827aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchoukstatic void
8282e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
829aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk{
83071f2cf116aab893e224056c38ab146bd1538dd3eSteve Block    ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
831aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
832aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
833581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
834aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
835aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    for(jint i = 0; i < numEntries; i ++) {
836aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk        _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
837aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk        _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
838aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    }
839aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
840aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    free(fileEntries);
841aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk}
842aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk
843aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchoukstatic int
8442e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
845aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk{
84671f2cf116aab893e224056c38ab146bd1538dd3eSteve Block    ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
847581cc64028e8b8f66cec8105bf530b16d5fb34ebAlex Sakhartchouk    jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
848aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk    return id;
849aae74ad6144470c66e72b075ac3afeddb186fa98Alex Sakhartchouk}
850d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
851d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams// -----------------------------------
852d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
8539b949fce39f0f39ce9275b71d7c347210775e7a8Alex Sakhartchoukstatic int
854b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex SakhartchouknFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
855b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk                    jstring fileName, jfloat fontSize, jint dpi)
8569b949fce39f0f39ce9275b71d7c347210775e7a8Alex Sakhartchouk{
857b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
858e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jint id = (jint)rsFontCreateFromFile(con,
859e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                         fileNameUTF.c_str(), fileNameUTF.length(),
860e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                         fontSize, dpi);
861b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
862b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    return id;
863b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk}
864b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
865b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukstatic int
866b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex SakhartchouknFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
867b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk                           jstring name, jfloat fontSize, jint dpi, jint native_asset)
868b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk{
869b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    Asset* asset = reinterpret_cast<Asset*>(native_asset);
870b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    AutoJavaStringToUTF8 nameUTF(_env, name);
871b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
872e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jint id = (jint)rsFontCreateFromMemory(con,
873e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                           nameUTF.c_str(), nameUTF.length(),
874e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                           fontSize, dpi,
875b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk                                           asset->getBuffer(false), asset->getLength());
876b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    return id;
877b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk}
878b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
879b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukstatic int
880b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex SakhartchouknFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
881b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk                     jfloat fontSize, jint dpi)
882b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk{
883b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
884b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    if (mgr == NULL) {
885b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return 0;
886b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
887b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk
888b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    AutoJavaStringToUTF8 str(_env, _path);
889b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
890b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    if (asset == NULL) {
891b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return 0;
892b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
8939b949fce39f0f39ce9275b71d7c347210775e7a8Alex Sakhartchouk
894e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    jint id = (jint)rsFontCreateFromMemory(con,
895e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                           str.c_str(), str.length(),
896e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                           fontSize, dpi,
897b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk                                           asset->getBuffer(false), asset->getLength());
898b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    delete asset;
8999b949fce39f0f39ce9275b71d7c347210775e7a8Alex Sakhartchouk    return id;
9009b949fce39f0f39ce9275b71d7c347210775e7a8Alex Sakhartchouk}
9019b949fce39f0f39ce9275b71d7c347210775e7a8Alex Sakhartchouk
902bd1c3ad0cdf8e60b849a009cdc0b36764cc1dacbJason Sams// -----------------------------------
903bd1c3ad0cdf8e60b849a009cdc0b36764cc1dacbJason Sams
904bd1c3ad0cdf8e60b849a009cdc0b36764cc1dacbJason Samsstatic void
9052e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
906d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
907d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams    LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
908bc948dedcee57a66fe2cb38d4c79d04a10c7efb3Jason Sams    rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
909d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams}
910d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
911d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
9122e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
9134d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams{
914cfc04366998cd0c626594c9cf70336a11bdf5996Jason Sams    LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
9154d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    rsScriptSetVarI(con, (RsScript)script, slot, val);
9164d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams}
9174d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
9184d3399337d18ef04116bc8a2e5799274655d0c30Jason Samsstatic void
9196f4cf0b8885403ead157ae00fd43cf1282331c23Jason SamsnScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
9206f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams{
9216f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
9226f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
9236f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams}
9246f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams
9256f4cf0b8885403ead157ae00fd43cf1282331c23Jason Samsstatic void
926031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen HinesnScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
927031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines{
928031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
929031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    rsScriptSetVarJ(con, (RsScript)script, slot, val);
930031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines}
931031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines
932031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hinesstatic void
9332e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
9344d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams{
935ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
9364d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    rsScriptSetVarF(con, (RsScript)script, slot, val);
9374d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams}
9384d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
9394d3399337d18ef04116bc8a2e5799274655d0c30Jason Samsstatic void
940ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen HinesnScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
941ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines{
942ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
943ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    rsScriptSetVarD(con, (RsScript)script, slot, val);
944ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines}
945ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines
946ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hinesstatic void
9472e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
9484d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams{
9494d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
9504d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    jint len = _env->GetArrayLength(data);
9514d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
9524d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
9534d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
9544d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams}
9554d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
956adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hinesstatic void
957adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen HinesnScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
958adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines{
959adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
960adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    jint len = _env->GetArrayLength(data);
961adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
962adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
963adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
964adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
965adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines                     (const size_t*) dimsPtr, dimsLen);
966adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
967adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
968adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines}
969adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines
970d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
971d19f10d43aa400e1183aa21a97099d02074131a2Jason Samsstatic void
9722e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
973584a375df68ed7d62b38389078c6804edf228f9cRomain Guy{
97407ae40623737a6060b8a925fd2e6bba76780dcd4Jason Sams    LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
975584a375df68ed7d62b38389078c6804edf228f9cRomain Guy
976584a375df68ed7d62b38389078c6804edf228f9cRomain Guy    jint length = _env->GetArrayLength(timeZone);
977584a375df68ed7d62b38389078c6804edf228f9cRomain Guy    jbyte* timeZone_ptr;
978584a375df68ed7d62b38389078c6804edf228f9cRomain Guy    timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
979584a375df68ed7d62b38389078c6804edf228f9cRomain Guy
980bc948dedcee57a66fe2cb38d4c79d04a10c7efb3Jason Sams    rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
981584a375df68ed7d62b38389078c6804edf228f9cRomain Guy
982584a375df68ed7d62b38389078c6804edf228f9cRomain Guy    if (timeZone_ptr) {
983584a375df68ed7d62b38389078c6804edf228f9cRomain Guy        _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
984584a375df68ed7d62b38389078c6804edf228f9cRomain Guy    }
985584a375df68ed7d62b38389078c6804edf228f9cRomain Guy}
986584a375df68ed7d62b38389078c6804edf228f9cRomain Guy
98722534176fb5c1257130ef4ee589739ca42766a32Jason Samsstatic void
9882e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
98922534176fb5c1257130ef4ee589739ca42766a32Jason Sams{
9904d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
9914d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    rsScriptInvoke(con, (RsScript)obj, slot);
99222534176fb5c1257130ef4ee589739ca42766a32Jason Sams}
99322534176fb5c1257130ef4ee589739ca42766a32Jason Sams
994584a375df68ed7d62b38389078c6804edf228f9cRomain Guystatic void
9952e1872fe07cf8952812a417985e6e1f61bdeab5dJason SamsnScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
996be2e84193f709419634de4cc3ba0e67acf6976f3Jason Sams{
9974d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
9984d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    jint len = _env->GetArrayLength(data);
9994d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
10004d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
10014d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1002be2e84193f709419634de4cc3ba0e67acf6976f3Jason Sams}
1003be2e84193f709419634de4cc3ba0e67acf6976f3Jason Sams
10046e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Samsstatic void
10056e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason SamsnScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
10066e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams               jint script, jint slot, jint ain, jint aout)
10076e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams{
10086e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
10096e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
10106e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams}
10116e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Samsstatic void
10126e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason SamsnScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
10136e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams                jint script, jint slot, jint ain, jint aout, jbyteArray params)
10146e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams{
10156e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
10166e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    jint len = _env->GetArrayLength(params);
10176e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    jbyte *ptr = _env->GetByteArrayElements(params, NULL);
10186e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
10196e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
10206e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams}
10216e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams
1022d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams
1023fbf0b9ecda03fbdbd4ebabfd18da09a789686249Jason Sams// -----------------------------------
1024fbf0b9ecda03fbdbd4ebabfd18da09a789686249Jason Sams
1025e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Samsstatic jint
1026e4a06c5fc738bf219f2a495e12a637b2d0871651Jason SamsnScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1027e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams               jstring resName, jstring cacheDir,
1028e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams               jbyteArray scriptRef, jint length)
1029d19f10d43aa400e1183aa21a97099d02074131a2Jason Sams{
1030e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    LOG_API("nScriptCCreate, con(%p)", con);
1031e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams
1032e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    AutoJavaStringToUTF8 resNameUTF(_env, resName);
1033e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1034e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    jint ret = 0;
10358451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes    jbyte* script_ptr = NULL;
103643702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    jint _exception = 0;
103743702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    jint remaining;
103843702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    if (!scriptRef) {
103943702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich        _exception = 1;
10408451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
104143702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich        goto exit;
104243702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    }
104343702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    if (length < 0) {
104443702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich        _exception = 1;
10458451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
104643702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich        goto exit;
104743702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    }
1048e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    remaining = _env->GetArrayLength(scriptRef);
104943702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    if (remaining < length) {
105043702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich        _exception = 1;
10518451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        //jniThrowException(_env, "java/lang/IllegalArgumentException",
10528451b25a4422656bbd6657a5855e69c0f4d53c74Elliott Hughes        //        "length > script.length - offset");
105343702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich        goto exit;
105443702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    }
1055e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    script_ptr = (jbyte *)
105643702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich        _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
105743702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich
1058e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    //rsScriptCSetText(con, (const char *)script_ptr, length);
1059e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams
1060e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk    ret = (jint)rsScriptCCreate(con,
1061e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                resNameUTF.c_str(), resNameUTF.length(),
1062e7c4a7565c7f8c8fc1ec92dc0692577fcc474750Alex Sakhartchouk                                cacheDirUTF.c_str(), cacheDirUTF.length(),