blob: 51387196dea9f7cb8d4c2bb360594b61d4051fca [file] [log] [blame]
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001/*
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08002 * Copyright (C) 2008-2012 The Android Open Source Project
Jack Palevich60aa3ea2009-05-26 13:45:08 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Sams94d8e90a2009-06-10 16:09:05 -070017package android.renderscript;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070018
Tim Murray2f2472c2013-08-22 14:55:26 -070019import java.lang.reflect.Method;
Tim Murray06b45672014-01-07 11:13:56 -080020import java.util.concurrent.locks.ReentrantReadWriteLock;
Jason Sams36e612a2009-07-31 16:26:13 -070021
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080022import android.content.Context;
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080023import android.content.res.AssetManager;
Jason Samsb8c5a842009-07-31 20:40:47 -070024import android.graphics.Bitmap;
Jason Samsfaa32b32011-06-20 16:58:04 -070025import android.graphics.SurfaceTexture;
Glenn Kasten260c77a2011-06-01 17:25:54 -070026import android.os.Process;
Jason Sams36e612a2009-07-31 16:26:13 -070027import android.util.Log;
28import android.view.Surface;
Dan Morrille4d9a012013-03-28 18:10:43 -070029import android.os.SystemProperties;
Tim Murray6d7a53c2013-05-23 16:59:23 -070030import android.os.Trace;
Jason Samse16da122015-03-18 17:04:18 -070031import java.util.ArrayList;
Stephen Hines4382467a2011-08-01 15:02:34 -070032
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070033/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070034 * This class provides access to a RenderScript context, which controls RenderScript
35 * initialization, resource management, and teardown. An instance of the RenderScript
36 * class must be created before any other RS objects can be created.
Jason Sams27676fe2010-11-10 17:00:59 -080037 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080038 * <div class="special reference">
39 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070040 * <p>For more information about creating an application that uses RenderScript, read the
41 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080042 * </div>
Jason Samse29d4712009-07-23 15:19:03 -070043 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070044public class RenderScript {
Tim Murray6d7a53c2013-05-23 16:59:23 -070045 static final long TRACE_TAG = Trace.TRACE_TAG_RS;
46
Jason Sams3bc47d42009-11-12 15:10:25 -080047 static final String LOG_TAG = "RenderScript_jni";
Jason Samsbf6ef8d72010-12-06 15:59:59 -080048 static final boolean DEBUG = false;
Romain Guy650a3eb2009-08-31 14:06:43 -070049 @SuppressWarnings({"UnusedDeclaration", "deprecation"})
Joe Onorato43a17652011-04-06 19:22:23 -070050 static final boolean LOG_ENABLED = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070051
Jason Samse16da122015-03-18 17:04:18 -070052 static private ArrayList<RenderScript> mProcessContextList = new ArrayList<RenderScript>();
53 private boolean mIsProcessContext = false;
54 private int mContextFlags = 0;
55 private int mContextSdkVersion = 0;
56
57
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080058 private Context mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070059
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080060 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070061 * We use a class initializer to allow the native code to cache some
62 * field offsets.
63 */
Dan Morrille4d9a012013-03-28 18:10:43 -070064 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
Jason Samsbf6ef8d72010-12-06 15:59:59 -080065 static boolean sInitialized;
66 native static void _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070067
Tim Murray2f2472c2013-08-22 14:55:26 -070068 static Object sRuntime;
69 static Method registerNativeAllocation;
70 static Method registerNativeFree;
Jason Samsdba3ba52009-07-30 14:56:12 -070071
Jason Sams26e90512014-05-07 14:23:27 -070072 /*
Tim Murrayfd710e72014-06-06 11:10:45 -070073 * Context creation flag that specifies a normal context.
Jason Sams26e90512014-05-07 14:23:27 -070074 */
Tim Murrayfd710e72014-06-06 11:10:45 -070075 public static final int CREATE_FLAG_NONE = 0x0000;
Jason Sams26e90512014-05-07 14:23:27 -070076
77 /*
78 * Context creation flag which specifies a context optimized for low
79 * latency over peak performance. This is a hint and may have no effect
80 * on some implementations.
81 */
Tim Murrayfd710e72014-06-06 11:10:45 -070082 public static final int CREATE_FLAG_LOW_LATENCY = 0x0002;
Jason Sams26e90512014-05-07 14:23:27 -070083
84 /*
85 * Context creation flag which specifies a context optimized for long
86 * battery life over peak performance. This is a hint and may have no effect
87 * on some implementations.
88 */
Tim Murrayfd710e72014-06-06 11:10:45 -070089 public static final int CREATE_FLAG_LOW_POWER = 0x0004;
Jason Sams26e90512014-05-07 14:23:27 -070090
Tim Murray56f9e6f2014-05-16 11:47:26 -070091 /*
92 * Detect the bitness of the VM to allow FieldPacker to do the right thing.
93 */
94 static native int rsnSystemGetPointerSize();
95 static int sPointerSize;
96
Jack Palevich60aa3ea2009-05-26 13:45:08 -070097 static {
98 sInitialized = false;
Dan Morrille4d9a012013-03-28 18:10:43 -070099 if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
100 try {
Tim Murray2f2472c2013-08-22 14:55:26 -0700101 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
102 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
103 sRuntime = get_runtime.invoke(null);
104 registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
105 registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
106 } catch (Exception e) {
107 Log.e(LOG_TAG, "Error loading GC methods: " + e);
108 throw new RSRuntimeException("Error loading GC methods: " + e);
109 }
110 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700111 System.loadLibrary("rs_jni");
112 _nInit();
113 sInitialized = true;
Tim Murray56f9e6f2014-05-16 11:47:26 -0700114 sPointerSize = rsnSystemGetPointerSize();
Dan Morrille4d9a012013-03-28 18:10:43 -0700115 } catch (UnsatisfiedLinkError e) {
116 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
117 throw new RSRuntimeException("Error loading RS jni library: " + e);
118 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700119 }
120 }
121
Jason Sams2e1872f2010-08-17 16:25:41 -0700122 // Non-threadsafe functions.
Tim Murrayeff663f2013-11-15 13:08:30 -0800123 native long nDeviceCreate();
124 native void nDeviceDestroy(long dev);
125 native void nDeviceSetConfig(long dev, int param, int value);
126 native int nContextGetUserMessage(long con, int[] data);
127 native String nContextGetErrorMessage(long con);
128 native int nContextPeekMessage(long con, int[] subID);
129 native void nContextInitToClient(long con);
130 native void nContextDeinitToClient(long con);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700131
Tim Murray67cc2d02014-02-06 16:39:38 -0800132 // this should be a monotonically increasing ID
133 // used in conjunction with the API version of a device
134 static final long sMinorID = 1;
135
136 /**
137 * Returns an identifier that can be used to identify a particular
138 * minor version of RS.
139 *
140 * @hide
141 */
142 public static long getMinorID() {
143 return sMinorID;
144 }
145
Jason Sams02d56d92013-04-12 16:40:50 -0700146 /**
147 * ContextType specifies the specific type of context to be created.
148 *
149 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800150 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700151 /**
152 * NORMAL context, this is the default and what shipping apps should
153 * use.
154 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800155 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700156
157 /**
158 * DEBUG context, perform extra runtime checks to validate the
159 * kernels and APIs are being used as intended. Get and SetElementAt
160 * will be bounds checked in this mode.
161 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800162 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700163
164 /**
165 * PROFILE context, Intended to be used once the first time an
166 * application is run on a new device. This mode allows the runtime to
167 * do additional testing and performance tuning.
168 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800169 PROFILE (2);
170
171 int mID;
172 ContextType(int id) {
173 mID = id;
174 }
175 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800176
Stephen Hines42028a82013-04-17 19:22:01 -0700177 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800178 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700179
Jason Sams2e1872f2010-08-17 16:25:41 -0700180 // Methods below are wrapped to protect the non-threadsafe
181 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800182 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700183 int colorMin, int colorPref,
184 int alphaMin, int alphaPref,
185 int depthMin, int depthPref,
186 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700187 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800188 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700189 int colorMin, int colorPref,
190 int alphaMin, int alphaPref,
191 int depthMin, int depthPref,
192 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700193 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700194 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700195 alphaMin, alphaPref, depthMin, depthPref,
196 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700197 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700198 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800199 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
200 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800201 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700202 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800203 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700204 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800205 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800206
207 // take teardown lock
208 // teardown lock can only be taken when no objects are being destroyed
209 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
210 wlock.lock();
211
212 long curCon = mContext;
213 // context is considered dead as of this point
214 mContext = 0;
215
216 wlock.unlock();
217 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700218 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800219 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700220 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800221 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700222 rsnContextSetSurface(mContext, w, h, sur);
223 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800224 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700225 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
226 validate();
227 rsnContextSetSurfaceTexture(mContext, w, h, sur);
228 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800229 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700230 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800231 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700232 rsnContextSetPriority(mContext, p);
233 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800234 native void rsnContextDump(long con, int bits);
Jason Sams2e1872f2010-08-17 16:25:41 -0700235 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800236 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700237 rsnContextDump(mContext, bits);
238 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800239 native void rsnContextFinish(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700240 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800241 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700242 rsnContextFinish(mContext);
243 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700244
Tim Murrayeff663f2013-11-15 13:08:30 -0800245 native void rsnContextSendMessage(long con, int id, int[] data);
Jason Sams455d6442013-02-05 19:20:18 -0800246 synchronized void nContextSendMessage(int id, int[] data) {
247 validate();
248 rsnContextSendMessage(mContext, id, data);
249 }
250
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000251 native void rsnContextBindRootScript(long con, long script);
252 synchronized void nContextBindRootScript(long script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800253 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700254 rsnContextBindRootScript(mContext, script);
255 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800256 native void rsnContextBindSampler(long con, int sampler, int slot);
Jason Sams2e1872f2010-08-17 16:25:41 -0700257 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800258 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700259 rsnContextBindSampler(mContext, sampler, slot);
260 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000261 native void rsnContextBindProgramStore(long con, long pfs);
262 synchronized void nContextBindProgramStore(long pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800263 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700264 rsnContextBindProgramStore(mContext, pfs);
265 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000266 native void rsnContextBindProgramFragment(long con, long pf);
267 synchronized void nContextBindProgramFragment(long pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800268 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700269 rsnContextBindProgramFragment(mContext, pf);
270 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000271 native void rsnContextBindProgramVertex(long con, long pv);
272 synchronized void nContextBindProgramVertex(long pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800273 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700274 rsnContextBindProgramVertex(mContext, pv);
275 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000276 native void rsnContextBindProgramRaster(long con, long pr);
277 synchronized void nContextBindProgramRaster(long pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800278 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700279 rsnContextBindProgramRaster(mContext, pr);
280 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800281 native void rsnContextPause(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700282 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800283 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700284 rsnContextPause(mContext);
285 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800286 native void rsnContextResume(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700287 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800288 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700289 rsnContextResume(mContext);
290 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700291
Yang Ni281c3252014-10-24 08:52:24 -0700292 native long rsnClosureCreate(long con, long kernelID, long returnValue,
293 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
294 long[] depFieldIDs);
295 synchronized long nClosureCreate(long kernelID, long returnValue,
296 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
297 long[] depFieldIDs) {
298 validate();
299 return rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
300 sizes, depClosures, depFieldIDs);
301 }
302
Yang Nibe392ad2015-01-23 17:16:02 -0800303 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
304 long[] fieldIDs, long[] values, int[] sizes);
305 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
306 long[] fieldIDs, long[] values, int[] sizes) {
307 validate();
308 return rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
309 values, sizes);
310 }
311
Yang Ni281c3252014-10-24 08:52:24 -0700312 native void rsnClosureSetArg(long con, long closureID, int index,
313 long value, int size);
314 synchronized void nClosureSetArg(long closureID, int index, long value,
315 int size) {
316 validate();
317 rsnClosureSetArg(mContext, closureID, index, value, size);
318 }
319
320 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
321 long value, int size);
322 // Does this have to be synchronized?
323 synchronized void nClosureSetGlobal(long closureID, long fieldID,
324 long value, int size) {
325 validate(); // TODO: is this necessary?
326 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
327 }
328
Yang Niebf63402015-01-16 11:06:26 -0800329 native long rsnScriptGroup2Create(long con, String cachePath, long[] closures);
330 synchronized long nScriptGroup2Create(String cachePath, long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700331 validate();
Yang Niebf63402015-01-16 11:06:26 -0800332 return rsnScriptGroup2Create(mContext, cachePath, closures);
Yang Ni281c3252014-10-24 08:52:24 -0700333 }
334
335 native void rsnScriptGroup2Execute(long con, long groupID);
336 synchronized void nScriptGroup2Execute(long groupID) {
337 validate();
338 rsnScriptGroup2Execute(mContext, groupID);
339 }
340
Tim Murray460a0492013-11-19 12:45:54 -0800341 native void rsnAssignName(long con, long obj, byte[] name);
342 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800343 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700344 rsnAssignName(mContext, obj, name);
345 }
Tim Murray460a0492013-11-19 12:45:54 -0800346 native String rsnGetName(long con, long obj);
347 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800348 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700349 return rsnGetName(mContext, obj);
350 }
Tim Murray06b45672014-01-07 11:13:56 -0800351
352 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800353 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800354 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800355 // There is a race condition here. The calling code may be run
356 // by the gc while teardown is occuring. This protects againts
357 // deleting dead objects.
358 if (mContext != 0) {
359 rsnObjDestroy(mContext, id);
360 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700361 }
Jason Samsfe08d992009-05-27 14:45:32 -0700362
Tim Murray460a0492013-11-19 12:45:54 -0800363 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
364 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800365 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700366 return rsnElementCreate(mContext, type, kind, norm, vecSize);
367 }
Ashok Bhat98071552014-02-12 09:54:43 +0000368 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
369 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800370 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700371 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700372 }
Tim Murray460a0492013-11-19 12:45:54 -0800373 native void rsnElementGetNativeData(long con, long id, int[] elementData);
374 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800375 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700376 rsnElementGetNativeData(mContext, id, elementData);
377 }
Tim Murray460a0492013-11-19 12:45:54 -0800378 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000379 long[] IDs, String[] names, int[] arraySizes);
380 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800381 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700382 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700383 }
Jason Sams768bc022009-09-21 19:41:04 -0700384
Tim Murray460a0492013-11-19 12:45:54 -0800385 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
386 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800387 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800388 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700389 }
Ashok Bhat98071552014-02-12 09:54:43 +0000390 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
391 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800392 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700393 rsnTypeGetNativeData(mContext, id, typeData);
394 }
Jason Sams768bc022009-09-21 19:41:04 -0700395
Ashok Bhat98071552014-02-12 09:54:43 +0000396 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
397 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800398 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800399 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700400 }
Tim Murray460a0492013-11-19 12:45:54 -0800401 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
402 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800403 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800404 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700405 }
Tim Murraya3145512012-12-04 17:59:29 -0800406
Tim Murray460a0492013-11-19 12:45:54 -0800407 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
408 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800409 validate();
410 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
411 }
412
Tim Murray460a0492013-11-19 12:45:54 -0800413 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
414 synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800415 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800416 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800417 }
Tim Murray460a0492013-11-19 12:45:54 -0800418 native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
419 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800420 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700421 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
422 }
Tim Murray460a0492013-11-19 12:45:54 -0800423 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
424 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800425 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800426 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
427 }
428
Tim Murray460a0492013-11-19 12:45:54 -0800429 native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
430 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800431 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800432 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
433 }
434
435
Tim Murray460a0492013-11-19 12:45:54 -0800436 native void rsnAllocationSyncAll(long con, long alloc, int src);
437 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800438 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800439 rsnAllocationSyncAll(mContext, alloc, src);
440 }
Tim Murray460a0492013-11-19 12:45:54 -0800441 native Surface rsnAllocationGetSurface(long con, long alloc);
442 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800443 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800444 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700445 }
Tim Murray460a0492013-11-19 12:45:54 -0800446 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
447 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800448 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700449 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800450 }
Tim Murray460a0492013-11-19 12:45:54 -0800451 native void rsnAllocationIoSend(long con, long alloc);
452 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800453 validate();
454 rsnAllocationIoSend(mContext, alloc);
455 }
Tim Murray460a0492013-11-19 12:45:54 -0800456 native void rsnAllocationIoReceive(long con, long alloc);
457 synchronized void nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800458 validate();
459 rsnAllocationIoReceive(mContext, alloc);
460 }
461
Jason Sams615e7ce2012-01-13 14:01:20 -0800462
Tim Murray460a0492013-11-19 12:45:54 -0800463 native void rsnAllocationGenerateMipmaps(long con, long alloc);
464 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800465 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800466 rsnAllocationGenerateMipmaps(mContext, alloc);
467 }
Tim Murray460a0492013-11-19 12:45:54 -0800468 native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
469 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800470 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800471 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700472 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700473
Jason Sams49a05d72010-12-29 14:31:29 -0800474
Miao Wang87e908d2015-03-02 15:15:15 -0800475 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
476 int mSize, boolean usePadding);
477 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
478 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800479 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800480 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700481 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700482
Miao Wangc8e237e2015-02-20 18:36:32 -0800483 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
484 synchronized void nAllocationElementData(long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800485 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800486 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700487 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700488
Tim Murrayeff663f2013-11-15 13:08:30 -0800489 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800490 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700491 int dstMip, int dstFace,
492 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800493 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700494 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800495 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700496 int dstMip, int dstFace,
497 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800498 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700499 int srcMip, int srcFace) {
500 validate();
501 rsnAllocationData2D(mContext,
502 dstAlloc, dstXoff, dstYoff,
503 dstMip, dstFace,
504 width, height,
505 srcAlloc, srcXoff, srcYoff,
506 srcMip, srcFace);
507 }
508
Tim Murray460a0492013-11-19 12:45:54 -0800509 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800510 int w, int h, Object d, int sizeBytes, int dt,
511 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800512 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800513 int w, int h, Object d, int sizeBytes, Element.DataType dt,
514 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800515 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800516 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700517 }
Jason Sams21659ac2013-11-06 15:08:07 -0800518
Tim Murray460a0492013-11-19 12:45:54 -0800519 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
520 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800521 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800522 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
523 }
Jason Sams49a05d72010-12-29 14:31:29 -0800524
Tim Murrayeff663f2013-11-15 13:08:30 -0800525 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800526 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700527 int dstMip,
528 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800529 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700530 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800531 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700532 int dstMip,
533 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800534 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700535 int srcMip) {
536 validate();
537 rsnAllocationData3D(mContext,
538 dstAlloc, dstXoff, dstYoff, dstZoff,
539 dstMip, width, height, depth,
540 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
541 }
542
Tim Murray460a0492013-11-19 12:45:54 -0800543 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800544 int w, int h, int depth, Object d, int sizeBytes, int dt,
545 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800546 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800547 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
548 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700549 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800550 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
551 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700552 }
Jason Samsb05d6892013-04-09 15:59:24 -0700553
Miao Wang87e908d2015-03-02 15:15:15 -0800554 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
555 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800556 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800557 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800558 }
Jason Sams21659ac2013-11-06 15:08:07 -0800559
Tim Murray460a0492013-11-19 12:45:54 -0800560 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800561 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800562 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800563 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800564 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800565 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800566 }
Jason Sams21659ac2013-11-06 15:08:07 -0800567
Miao Wangc8e237e2015-02-20 18:36:32 -0800568 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800569 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800570 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800571 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800572 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800573 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800574 }
575
Tim Murray460a0492013-11-19 12:45:54 -0800576 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800577 int w, int h, Object d, int sizeBytes, int dt,
578 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800579 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800580 int w, int h, Object d, int sizeBytes, Element.DataType dt,
581 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800582 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800583 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700584 }
Jason Sams21659ac2013-11-06 15:08:07 -0800585
Miao Wangc8e237e2015-02-20 18:36:32 -0800586 native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800587 int w, int h, int depth, Object d, int sizeBytes, int dt,
588 int mSize, boolean usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800589 synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800590 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
591 int mSize, boolean usePadding) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800592 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800593 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800594 }
595
Tim Murray460a0492013-11-19 12:45:54 -0800596 native long rsnAllocationGetType(long con, long id);
597 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800598 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700599 return rsnAllocationGetType(mContext, id);
600 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700601
Tim Murray460a0492013-11-19 12:45:54 -0800602 native void rsnAllocationResize1D(long con, long id, int dimX);
603 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800604 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700605 rsnAllocationResize1D(mContext, id, dimX);
606 }
Jason Sams5edc6082010-10-05 13:32:49 -0700607
Jason Sams46ba27e32015-02-06 17:45:15 -0800608 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
609 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
610 validate();
611 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
612 }
613
614 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
615 int mip, int face, int a1, int a2, int a3, int a4);
616 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
617 int mip, int face, int a1, int a2, int a3, int a4) {
618 validate();
619 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
620 }
621
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000622 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
623 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800624 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700625 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
626 }
Tim Murray460a0492013-11-19 12:45:54 -0800627 native long rsnFileA3DCreateFromFile(long con, String path);
628 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800629 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800630 return rsnFileA3DCreateFromFile(mContext, path);
631 }
Tim Murray460a0492013-11-19 12:45:54 -0800632 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
633 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800634 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800635 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
636 }
Tim Murray460a0492013-11-19 12:45:54 -0800637 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
638 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800639 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700640 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
641 }
Tim Murray460a0492013-11-19 12:45:54 -0800642 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
643 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800644 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700645 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
646 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000647 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
648 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800649 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700650 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
651 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700652
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000653 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
654 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800655 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700656 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
657 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000658 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
659 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800660 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800661 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
662 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000663 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
664 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800665 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800666 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
667 }
Jason Sams22534172009-08-04 16:58:20 -0700668
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700669
Tim Murray460a0492013-11-19 12:45:54 -0800670 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
671 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800672 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700673 rsnScriptBindAllocation(mContext, script, alloc, slot);
674 }
Tim Murray460a0492013-11-19 12:45:54 -0800675 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
676 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800677 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700678 rsnScriptSetTimeZone(mContext, script, timeZone);
679 }
Tim Murray460a0492013-11-19 12:45:54 -0800680 native void rsnScriptInvoke(long con, long id, int slot);
681 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800682 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700683 rsnScriptInvoke(mContext, id, slot);
684 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700685
686 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
687 long aout, byte[] params, int[] limits);
688
689 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
690 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700691 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700692 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700693 }
694
Tim Murray460a0492013-11-19 12:45:54 -0800695 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
696 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800697 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700698 rsnScriptInvokeV(mContext, id, slot, params);
699 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700700
Tim Murray460a0492013-11-19 12:45:54 -0800701 native void rsnScriptSetVarI(long con, long id, int slot, int val);
702 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800703 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700704 rsnScriptSetVarI(mContext, id, slot, val);
705 }
Tim Murray460a0492013-11-19 12:45:54 -0800706 native int rsnScriptGetVarI(long con, long id, int slot);
707 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700708 validate();
709 return rsnScriptGetVarI(mContext, id, slot);
710 }
711
Tim Murray460a0492013-11-19 12:45:54 -0800712 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
713 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800714 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700715 rsnScriptSetVarJ(mContext, id, slot, val);
716 }
Tim Murray460a0492013-11-19 12:45:54 -0800717 native long rsnScriptGetVarJ(long con, long id, int slot);
718 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700719 validate();
720 return rsnScriptGetVarJ(mContext, id, slot);
721 }
722
Tim Murray460a0492013-11-19 12:45:54 -0800723 native void rsnScriptSetVarF(long con, long id, int slot, float val);
724 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800725 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700726 rsnScriptSetVarF(mContext, id, slot, val);
727 }
Tim Murray460a0492013-11-19 12:45:54 -0800728 native float rsnScriptGetVarF(long con, long id, int slot);
729 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700730 validate();
731 return rsnScriptGetVarF(mContext, id, slot);
732 }
Tim Murray460a0492013-11-19 12:45:54 -0800733 native void rsnScriptSetVarD(long con, long id, int slot, double val);
734 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800735 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700736 rsnScriptSetVarD(mContext, id, slot, val);
737 }
Tim Murray460a0492013-11-19 12:45:54 -0800738 native double rsnScriptGetVarD(long con, long id, int slot);
739 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700740 validate();
741 return rsnScriptGetVarD(mContext, id, slot);
742 }
Tim Murray460a0492013-11-19 12:45:54 -0800743 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
744 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800745 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700746 rsnScriptSetVarV(mContext, id, slot, val);
747 }
Tim Murray460a0492013-11-19 12:45:54 -0800748 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
749 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700750 validate();
751 rsnScriptGetVarV(mContext, id, slot, val);
752 }
Tim Murray460a0492013-11-19 12:45:54 -0800753 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
754 long e, int[] dims);
755 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
756 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700757 validate();
758 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
759 }
Tim Murray460a0492013-11-19 12:45:54 -0800760 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
761 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800762 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800763 rsnScriptSetVarObj(mContext, id, slot, val);
764 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700765
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000766 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700767 byte[] script, int length);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000768 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800769 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700770 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700771 }
Jason Samsebfb4362009-09-23 13:57:02 -0700772
Tim Murray460a0492013-11-19 12:45:54 -0800773 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
774 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700775 validate();
776 return rsnScriptIntrinsicCreate(mContext, id, eid);
777 }
778
Tim Murray460a0492013-11-19 12:45:54 -0800779 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
780 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700781 validate();
782 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
783 }
784
Yang Nibe392ad2015-01-23 17:16:02 -0800785 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
786 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
787 validate();
788 return rsnScriptInvokeIDCreate(mContext, sid, slot);
789 }
790
Tim Murray460a0492013-11-19 12:45:54 -0800791 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
792 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700793 validate();
794 return rsnScriptFieldIDCreate(mContext, sid, slot);
795 }
796
Ashok Bhat98071552014-02-12 09:54:43 +0000797 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
798 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700799 validate();
800 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
801 }
802
Tim Murray460a0492013-11-19 12:45:54 -0800803 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
804 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700805 validate();
806 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
807 }
808
Tim Murray460a0492013-11-19 12:45:54 -0800809 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
810 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700811 validate();
812 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
813 }
814
Tim Murray460a0492013-11-19 12:45:54 -0800815 native void rsnScriptGroupExecute(long con, long group);
816 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700817 validate();
818 rsnScriptGroupExecute(mContext, group);
819 }
820
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000821 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700822 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000823 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700824 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800825 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700826 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700827 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800828
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000829 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700830 boolean depthMask, boolean dither,
831 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000832 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700833 boolean depthMask, boolean dither,
834 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800835 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700836 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
837 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700838 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700839
Tim Murray460a0492013-11-19 12:45:54 -0800840 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
841 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800842 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700843 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700844 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700845
Tim Murray460a0492013-11-19 12:45:54 -0800846 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
847 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800848 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700849 rsnProgramBindConstants(mContext, pv, slot, mID);
850 }
Tim Murray460a0492013-11-19 12:45:54 -0800851 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
852 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800853 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700854 rsnProgramBindTexture(mContext, vpf, slot, a);
855 }
Tim Murray460a0492013-11-19 12:45:54 -0800856 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
857 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800858 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700859 rsnProgramBindSampler(mContext, vpf, slot, s);
860 }
Ashok Bhat98071552014-02-12 09:54:43 +0000861 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
862 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800863 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800864 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700865 }
Ashok Bhat98071552014-02-12 09:54:43 +0000866 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
867 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800868 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800869 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700870 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700871
Ashok Bhat98071552014-02-12 09:54:43 +0000872 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
873 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800874 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700875 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800876 }
Tim Murray460a0492013-11-19 12:45:54 -0800877 native int rsnMeshGetVertexBufferCount(long con, long id);
878 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800879 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700880 return rsnMeshGetVertexBufferCount(mContext, id);
881 }
Tim Murray460a0492013-11-19 12:45:54 -0800882 native int rsnMeshGetIndexCount(long con, long id);
883 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800884 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700885 return rsnMeshGetIndexCount(mContext, id);
886 }
Ashok Bhat98071552014-02-12 09:54:43 +0000887 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
888 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800889 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700890 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
891 }
Ashok Bhat98071552014-02-12 09:54:43 +0000892 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
893 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800894 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700895 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
896 }
897
Tim Murray25207df2015-01-12 16:47:56 -0800898 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
899 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
900 float alpha, long A, long B, float beta, long C, int incX, int incY,
901 int KL, int KU);
902 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
903 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
904 float alpha, long A, long B, float beta, long C, int incX, int incY,
905 int KL, int KU) {
906 validate();
907 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
908 }
909
910 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
911 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
912 double alpha, long A, long B, double beta, long C, int incX, int incY,
913 int KL, int KU);
914 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
915 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
916 double alpha, long A, long B, double beta, long C, int incX, int incY,
917 int KL, int KU) {
918 validate();
919 rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
920 }
921
922 native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA,
923 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
924 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
925 int KL, int KU);
926 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
927 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
928 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
929 int KL, int KU) {
930 validate();
931 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
932 }
933
934 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
935 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
936 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
937 int KL, int KU);
938 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
939 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
940 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
941 int KL, int KU) {
942 validate();
943 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
944 }
945
946
Tim Murrayeff663f2013-11-15 13:08:30 -0800947 long mDev;
948 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -0800949 private boolean mDestroyed = false;
950
Romain Guy650a3eb2009-08-31 14:06:43 -0700951 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800952 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700953
Jason Sams8cb39de2010-06-01 15:47:01 -0700954 Element mElement_U8;
955 Element mElement_I8;
956 Element mElement_U16;
957 Element mElement_I16;
958 Element mElement_U32;
959 Element mElement_I32;
Stephen Hines52d83632010-10-11 16:10:42 -0700960 Element mElement_U64;
Stephen Hinesef1dac22010-10-01 15:39:33 -0700961 Element mElement_I64;
Jason Samsa5835a22014-11-05 15:16:26 -0800962 Element mElement_F16;
Jason Sams8cb39de2010-06-01 15:47:01 -0700963 Element mElement_F32;
Stephen Hines02f417052010-09-30 15:19:22 -0700964 Element mElement_F64;
Jason Samsf110d4b2010-06-21 17:42:41 -0700965 Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -0700966
Jason Sams8cb39de2010-06-01 15:47:01 -0700967 Element mElement_ELEMENT;
968 Element mElement_TYPE;
969 Element mElement_ALLOCATION;
970 Element mElement_SAMPLER;
971 Element mElement_SCRIPT;
972 Element mElement_MESH;
973 Element mElement_PROGRAM_FRAGMENT;
974 Element mElement_PROGRAM_VERTEX;
975 Element mElement_PROGRAM_RASTER;
976 Element mElement_PROGRAM_STORE;
Stephen Hines3a291412012-04-11 17:27:29 -0700977 Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -0700978
Jason Sams3c0dfba2009-09-27 17:50:38 -0700979 Element mElement_A_8;
980 Element mElement_RGB_565;
981 Element mElement_RGB_888;
982 Element mElement_RGBA_5551;
983 Element mElement_RGBA_4444;
984 Element mElement_RGBA_8888;
985
Jason Samsa5835a22014-11-05 15:16:26 -0800986 Element mElement_HALF_2;
987 Element mElement_HALF_3;
988 Element mElement_HALF_4;
989
Jason Sams8cb39de2010-06-01 15:47:01 -0700990 Element mElement_FLOAT_2;
991 Element mElement_FLOAT_3;
992 Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -0700993
994 Element mElement_DOUBLE_2;
995 Element mElement_DOUBLE_3;
996 Element mElement_DOUBLE_4;
997
998 Element mElement_UCHAR_2;
999 Element mElement_UCHAR_3;
Jason Sams8cb39de2010-06-01 15:47:01 -07001000 Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001001
Stephen Hines836c4a52011-06-01 14:38:10 -07001002 Element mElement_CHAR_2;
1003 Element mElement_CHAR_3;
1004 Element mElement_CHAR_4;
1005
1006 Element mElement_USHORT_2;
1007 Element mElement_USHORT_3;
1008 Element mElement_USHORT_4;
1009
1010 Element mElement_SHORT_2;
1011 Element mElement_SHORT_3;
1012 Element mElement_SHORT_4;
1013
1014 Element mElement_UINT_2;
1015 Element mElement_UINT_3;
1016 Element mElement_UINT_4;
1017
1018 Element mElement_INT_2;
1019 Element mElement_INT_3;
1020 Element mElement_INT_4;
1021
1022 Element mElement_ULONG_2;
1023 Element mElement_ULONG_3;
1024 Element mElement_ULONG_4;
1025
1026 Element mElement_LONG_2;
1027 Element mElement_LONG_3;
1028 Element mElement_LONG_4;
1029
Tim Murray932e78e2013-09-03 11:42:26 -07001030 Element mElement_YUV;
1031
Jason Sams1d45c472010-08-25 14:31:48 -07001032 Element mElement_MATRIX_4X4;
1033 Element mElement_MATRIX_3X3;
1034 Element mElement_MATRIX_2X2;
1035
Jason Sams4d339932010-05-11 14:03:58 -07001036 Sampler mSampler_CLAMP_NEAREST;
1037 Sampler mSampler_CLAMP_LINEAR;
1038 Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1039 Sampler mSampler_WRAP_NEAREST;
1040 Sampler mSampler_WRAP_LINEAR;
1041 Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
Tim Murray6b9b2ca2013-02-15 13:25:55 -08001042 Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1043 Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1044 Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001045
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001046 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1047 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001048 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1049 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001050
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001051 ProgramRaster mProgramRaster_CULL_BACK;
1052 ProgramRaster mProgramRaster_CULL_FRONT;
1053 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001054
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001055 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001056 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001057
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001058 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001059 * The base class from which an application should derive in order
1060 * to receive RS messages from scripts. When a script calls {@code
1061 * rsSendToClient}, the data fields will be filled, and the run
1062 * method will be called on a separate thread. This will occur
1063 * some time after {@code rsSendToClient} completes in the script,
1064 * as {@code rsSendToClient} is asynchronous. Message handlers are
1065 * not guaranteed to have completed when {@link
1066 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001067 *
1068 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001069 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001070 protected int[] mData;
1071 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001072 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001073 public void run() {
1074 }
1075 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001076 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001077 * If an application is expecting messages, it should set this
1078 * field to an instance of {@link RSMessageHandler}. This
1079 * instance will receive all the user messages sent from {@code
1080 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001081 *
1082 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001083 RSMessageHandler mMessageCallback = null;
1084
1085 public void setMessageHandler(RSMessageHandler msg) {
1086 mMessageCallback = msg;
1087 }
1088 public RSMessageHandler getMessageHandler() {
1089 return mMessageCallback;
1090 }
Jason Sams516c3192009-10-06 13:58:47 -07001091
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001092 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001093 * Place a message into the message queue to be sent back to the message
1094 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001095 *
1096 * @param id
1097 * @param data
1098 */
1099 public void sendMessage(int id, int[] data) {
1100 nContextSendMessage(id, data);
1101 }
1102
1103 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001104 * The runtime error handler base class. An application should derive from this class
1105 * if it wishes to install an error handler. When errors occur at runtime,
1106 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001107 *
1108 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001109 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001110 protected String mErrorMessage;
1111 protected int mErrorNum;
1112 public void run() {
1113 }
1114 }
Jason Sams27676fe2010-11-10 17:00:59 -08001115
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001116 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001117 * Application Error handler. All runtime errors will be dispatched to the
1118 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001119 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001120 * This will cause program termaination.
1121 *
1122 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001123 RSErrorHandler mErrorCallback = null;
1124
1125 public void setErrorHandler(RSErrorHandler msg) {
1126 mErrorCallback = msg;
1127 }
1128 public RSErrorHandler getErrorHandler() {
1129 return mErrorCallback;
1130 }
Jason Sams1c415172010-11-08 17:06:46 -08001131
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001132 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001133 * RenderScript worker thread priority enumeration. The default value is
1134 * NORMAL. Applications wishing to do background processing should set
1135 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001136 */
Jason Sams7d787b42009-11-15 12:14:26 -08001137 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001138 // These values used to represent official thread priority values
1139 // now they are simply enums to be used by the runtime side
1140 LOW (15),
1141 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001142
1143 int mID;
1144 Priority(int id) {
1145 mID = id;
1146 }
1147 }
1148
Jason Sams678cc7f2014-03-05 16:09:02 -08001149 void validateObject(BaseObj o) {
1150 if (o != null) {
1151 if (o.mRS != this) {
1152 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1153 }
1154 }
1155 }
1156
Jason Sams771bebb2009-12-07 12:40:12 -08001157 void validate() {
1158 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001159 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001160 }
1161 }
1162
Jason Sams27676fe2010-11-10 17:00:59 -08001163
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001164 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001165 * Change the priority of the worker threads for this context.
1166 *
1167 * @param p New priority to be set.
1168 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001169 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001170 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001171 nContextSetPriority(p.mID);
1172 }
1173
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001174 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001175 RenderScript mRS;
1176 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001177 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001178
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001179 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1180 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1181 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1182 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1183 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001184 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001185
Stephen Hines42028a82013-04-17 19:22:01 -07001186 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001187 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001188
Jason Sams516c3192009-10-06 13:58:47 -07001189 MessageThread(RenderScript rs) {
1190 super("RSMessageThread");
1191 mRS = rs;
1192
1193 }
1194
1195 public void run() {
1196 // This function is a temporary solution. The final solution will
1197 // used typed allocations where the message id is the type indicator.
1198 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001199 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001200 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001201 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001202 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001203 int size = mAuxData[1];
1204 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001205
1206 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1207 if ((size>>2) >= rbuf.length) {
1208 rbuf = new int[(size + 3) >> 2];
1209 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001210 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1211 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001212 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001213 }
Jason Sams1c415172010-11-08 17:06:46 -08001214
1215 if(mRS.mMessageCallback != null) {
1216 mRS.mMessageCallback.mData = rbuf;
1217 mRS.mMessageCallback.mID = subID;
1218 mRS.mMessageCallback.mLength = size;
1219 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001220 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001221 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001222 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001223 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001224 }
Jason Sams1c415172010-11-08 17:06:46 -08001225
1226 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1227 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1228
Stephen Hines42028a82013-04-17 19:22:01 -07001229 // Throw RSRuntimeException under the following conditions:
1230 //
1231 // 1) It is an unknown fatal error.
1232 // 2) It is a debug fatal error, and we are not in a
1233 // debug context.
1234 // 3) It is a debug fatal error, and we do not have an
1235 // error callback.
1236 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1237 (subID >= RS_ERROR_FATAL_DEBUG &&
1238 (mRS.mContextType != ContextType.DEBUG ||
1239 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001240 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1241 }
1242
Jason Sams1c415172010-11-08 17:06:46 -08001243 if(mRS.mErrorCallback != null) {
1244 mRS.mErrorCallback.mErrorMessage = e;
1245 mRS.mErrorCallback.mErrorNum = subID;
1246 mRS.mErrorCallback.run();
1247 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001248 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001249 // Do not throw here. In these cases, we do not have
1250 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001251 }
1252 continue;
1253 }
1254
Jason Sams739c8262013-04-11 18:07:52 -07001255 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001256 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1257 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1258 throw new RSDriverException("Error processing message from RenderScript.");
1259 }
1260 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1261 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001262 continue;
1263 }
1264
Jason Sams1c415172010-11-08 17:06:46 -08001265 // 2: teardown.
1266 // But we want to avoid starving other threads during
1267 // teardown by yielding until the next line in the destructor
1268 // can execute to set mRun = false
1269 try {
1270 sleep(1, 0);
1271 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001272 }
Jason Sams516c3192009-10-06 13:58:47 -07001273 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001274 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001275 }
1276 }
1277
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001278 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001279 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001280 if (ctx != null) {
1281 mApplicationContext = ctx.getApplicationContext();
1282 }
Tim Murray06b45672014-01-07 11:13:56 -08001283 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001284 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001285 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001286 } catch (Exception e) {
1287 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1288 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1289 }
1290
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001291 }
1292
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001293 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001294 * Gets the application context associated with the RenderScript context.
1295 *
1296 * @return The application context.
1297 */
1298 public final Context getApplicationContext() {
1299 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001300 }
1301
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001302 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001303 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001304 *
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001305 * @hide
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001306 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001307 * @return RenderScript
1308 */
Jason Samse16da122015-03-18 17:04:18 -07001309 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001310 if (!sInitialized) {
1311 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1312 return null;
1313 }
1314
Jason Samsb69c7912014-05-20 18:48:35 -07001315 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER)) != 0) {
1316 throw new RSIllegalArgumentException("Invalid flags passed.");
1317 }
1318
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001319 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001320
1321 rs.mDev = rs.nDeviceCreate();
Tim Murrayfd710e72014-06-06 11:10:45 -07001322 rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001323 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001324 rs.mContextFlags = flags;
1325 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001326 if (rs.mContext == 0) {
1327 throw new RSDriverException("Failed to create RS context.");
1328 }
Jason Sams704ff642010-02-09 16:05:07 -08001329 rs.mMessageThread = new MessageThread(rs);
1330 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001331 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001332 }
1333
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001334 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001335 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001336 *
1337 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001338 *
1339 * @param ctx The context.
1340 * @return RenderScript
1341 */
1342 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001343 return create(ctx, ContextType.NORMAL);
1344 }
1345
1346 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001347 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001348 *
Jason Samse16da122015-03-18 17:04:18 -07001349 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001350 *
1351 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001352 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001353 * @return RenderScript
1354 */
1355 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001356 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001357 }
1358
Miao Wanga4e5adf2015-03-23 11:09:56 -07001359
1360 /**
Jason Samse16da122015-03-18 17:04:18 -07001361 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001362 *
Jason Samse16da122015-03-18 17:04:18 -07001363 * The returned context will be cached for future reuse within
1364 * the process. When an application is finished using
1365 * RenderScript it should call releaseAllContexts()
1366 *
1367 * A process context is a context designed for easy creation and
1368 * lifecycle management. Multiple calls to this function will
1369 * return the same object provided they are called with the same
1370 * options. This allows it to be used any time a RenderScript
1371 * context is needed.
1372 *
1373 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001374 *
1375 * @param ctx The context.
1376 * @param ct The type of context to be created.
1377 * @param flags The OR of the CREATE_FLAG_* options desired
1378 * @return RenderScript
1379 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001380 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001381 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001382 return create(ctx, v, ct, flags);
1383 }
1384
1385 /**
1386 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1387 *
1388 * Used by the RenderScriptThunker to maintain backward compatibility.
1389 *
1390 * @hide
1391 * @param ctx The context.
1392 * @param sdkVersion The target SDK Version.
1393 * @return RenderScript
1394 */
1395 public static RenderScript create(Context ctx, int sdkVersion) {
1396 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1397 }
1398
1399 /**
1400 * Gets or creates a RenderScript context of the specified type.
1401 *
1402 * @hide
1403 * @param ctx The context.
1404 * @param ct The type of context to be created.
1405 * @param sdkVersion The target SDK Version.
1406 * @param flags The OR of the CREATE_FLAG_* options desired
1407 * @return RenderScript
1408 */
1409 public static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
1410 if (sdkVersion < 23) {
1411 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001412 }
1413
1414 synchronized (mProcessContextList) {
1415 for (RenderScript prs : mProcessContextList) {
1416 if ((prs.mContextType == ct) &&
1417 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001418 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001419
1420 return prs;
1421 }
1422 }
1423
Miao Wanga4e5adf2015-03-23 11:09:56 -07001424 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001425 prs.mIsProcessContext = true;
1426 mProcessContextList.add(prs);
1427 return prs;
1428 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001429 }
1430
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001431 /**
Jason Samse16da122015-03-18 17:04:18 -07001432 * @hide
1433 *
1434 * Releases all the process contexts. This is the same as
1435 * calling .destroy() on each unique context retreived with
1436 * create(...). If no contexts have been created this
1437 * function does nothing.
1438 *
1439 * Typically you call this when your application is losing focus
1440 * and will not be using a context for some time.
1441 *
1442 * This has no effect on a context created with
1443 * createMultiContext()
1444 */
1445 public static void releaseAllContexts() {
1446 ArrayList<RenderScript> oldList;
1447 synchronized (mProcessContextList) {
1448 oldList = mProcessContextList;
1449 mProcessContextList = new ArrayList<RenderScript>();
1450 }
1451
1452 for (RenderScript prs : oldList) {
1453 prs.mIsProcessContext = false;
1454 prs.destroy();
1455 }
1456 oldList.clear();
1457 }
1458
1459
1460
1461 /**
1462 * Create a RenderScript context.
1463 *
1464 * This is an advanced function intended for applications which
1465 * need to create more than one RenderScript context to be used
1466 * at the same time.
1467 *
1468 * If you need a single context please use create()
1469 *
1470 * @hide
1471 * @param ctx The context.
1472 * @return RenderScript
1473 */
1474 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1475 return internalCreate(ctx, API_number, ct, flags);
1476 }
1477
1478
1479 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001480 * Print the currently available debugging information about the state of
1481 * the RS context to the log.
1482 *
Jason Sams27676fe2010-11-10 17:00:59 -08001483 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001484 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001485 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001486 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001487 }
1488
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001489 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001490 * Wait for any pending asynchronous opeations (such as copies to a RS
1491 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001492 *
1493 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001494 public void finish() {
1495 nContextFinish();
1496 }
1497
Jason Samsd22a6f02015-02-19 17:19:52 -08001498 private void helpDestroy() {
1499 boolean shouldDestroy = false;
1500 synchronized(this) {
1501 if (!mDestroyed) {
1502 shouldDestroy = true;
1503 mDestroyed = true;
1504 }
1505 }
1506
1507 if (shouldDestroy) {
1508 nContextFinish();
1509
1510 nContextDeinitToClient(mContext);
1511 mMessageThread.mRun = false;
1512 try {
1513 mMessageThread.join();
1514 } catch(InterruptedException e) {
1515 }
1516
1517 nContextDestroy();
1518
1519 nDeviceDestroy(mDev);
1520 mDev = 0;
1521 }
1522 }
1523
1524 protected void finalize() throws Throwable {
1525 helpDestroy();
1526 super.finalize();
1527 }
1528
1529
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001530 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001531 * Destroys this RenderScript context. Once this function is called,
1532 * using this context or any objects belonging to this context is
1533 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001534 *
Jason Samse16da122015-03-18 17:04:18 -07001535 * API 23+, this function is a NOP if the context was created
1536 * with create(). Please use releaseAllContexts() to clean up
1537 * contexts created with the create function.
1538 *
Jason Sams27676fe2010-11-10 17:00:59 -08001539 */
Jason Samsf5b45962009-08-25 14:49:07 -07001540 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001541 if (mIsProcessContext) {
1542 // users cannot destroy a process context
1543 return;
1544 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001545 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001546 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001547 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001548
Jason Samsa9e7a052009-09-25 14:51:22 -07001549 boolean isAlive() {
1550 return mContext != 0;
1551 }
1552
Tim Murray460a0492013-11-19 12:45:54 -08001553 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001554 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001555 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001556 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001557 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001558 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001559}