blob: 4d53c8d94c65fac0748a664096ad28a07ac366d3 [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 Murray47f31582015-04-07 15:43:24 -070019import java.io.File;
Tim Murray2f2472c2013-08-22 14:55:26 -070020import java.lang.reflect.Method;
Tim Murray06b45672014-01-07 11:13:56 -080021import java.util.concurrent.locks.ReentrantReadWriteLock;
Jason Sams36e612a2009-07-31 16:26:13 -070022
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080023import android.content.Context;
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080024import android.content.res.AssetManager;
Jason Samsb8c5a842009-07-31 20:40:47 -070025import android.graphics.Bitmap;
Jason Samsfaa32b32011-06-20 16:58:04 -070026import android.graphics.SurfaceTexture;
Glenn Kasten260c77a2011-06-01 17:25:54 -070027import android.os.Process;
Jason Sams36e612a2009-07-31 16:26:13 -070028import android.util.Log;
29import android.view.Surface;
Dan Morrille4d9a012013-03-28 18:10:43 -070030import android.os.SystemProperties;
Tim Murray6d7a53c2013-05-23 16:59:23 -070031import android.os.Trace;
Jason Samse16da122015-03-18 17:04:18 -070032import java.util.ArrayList;
Stephen Hines4382467a2011-08-01 15:02:34 -070033
Matt Wala36eb1f72015-07-20 15:35:27 -070034// TODO: Clean up the whitespace that separates methods in this class.
35
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070036/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070037 * This class provides access to a RenderScript context, which controls RenderScript
38 * initialization, resource management, and teardown. An instance of the RenderScript
39 * class must be created before any other RS objects can be created.
Jason Sams27676fe2010-11-10 17:00:59 -080040 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080041 * <div class="special reference">
42 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070043 * <p>For more information about creating an application that uses RenderScript, read the
44 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080045 * </div>
Jason Samse29d4712009-07-23 15:19:03 -070046 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070047public class RenderScript {
Tim Murray6d7a53c2013-05-23 16:59:23 -070048 static final long TRACE_TAG = Trace.TRACE_TAG_RS;
49
Jason Sams3bc47d42009-11-12 15:10:25 -080050 static final String LOG_TAG = "RenderScript_jni";
Jason Samsbf6ef8d72010-12-06 15:59:59 -080051 static final boolean DEBUG = false;
Romain Guy650a3eb2009-08-31 14:06:43 -070052 @SuppressWarnings({"UnusedDeclaration", "deprecation"})
Joe Onorato43a17652011-04-06 19:22:23 -070053 static final boolean LOG_ENABLED = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070054
Jason Samse16da122015-03-18 17:04:18 -070055 static private ArrayList<RenderScript> mProcessContextList = new ArrayList<RenderScript>();
56 private boolean mIsProcessContext = false;
57 private int mContextFlags = 0;
58 private int mContextSdkVersion = 0;
59
60
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080061 private Context mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070062
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080063 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070064 * We use a class initializer to allow the native code to cache some
65 * field offsets.
66 */
Dan Morrille4d9a012013-03-28 18:10:43 -070067 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
Jason Samsbf6ef8d72010-12-06 15:59:59 -080068 static boolean sInitialized;
69 native static void _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070070
Tim Murray2f2472c2013-08-22 14:55:26 -070071 static Object sRuntime;
72 static Method registerNativeAllocation;
73 static Method registerNativeFree;
Jason Samsdba3ba52009-07-30 14:56:12 -070074
Jason Sams26e90512014-05-07 14:23:27 -070075 /*
Tim Murrayfd710e72014-06-06 11:10:45 -070076 * Context creation flag that specifies a normal context.
Jason Sams26e90512014-05-07 14:23:27 -070077 */
Tim Murrayfd710e72014-06-06 11:10:45 -070078 public static final int CREATE_FLAG_NONE = 0x0000;
Jason Sams26e90512014-05-07 14:23:27 -070079
80 /*
81 * Context creation flag which specifies a context optimized for low
82 * latency over peak performance. This is a hint and may have no effect
83 * on some implementations.
84 */
Tim Murrayfd710e72014-06-06 11:10:45 -070085 public static final int CREATE_FLAG_LOW_LATENCY = 0x0002;
Jason Sams26e90512014-05-07 14:23:27 -070086
87 /*
88 * Context creation flag which specifies a context optimized for long
89 * battery life over peak performance. This is a hint and may have no effect
90 * on some implementations.
91 */
Tim Murrayfd710e72014-06-06 11:10:45 -070092 public static final int CREATE_FLAG_LOW_POWER = 0x0004;
Jason Sams26e90512014-05-07 14:23:27 -070093
Stephen McGroarty62cb9bd2015-05-08 15:56:58 +010094 /**
95 * @hide
96 * Context creation flag which instructs the implementation to wait for
97 * a debugger to be attached before continuing execution.
98 */
99 public static final int CREATE_FLAG_WAIT_FOR_ATTACH = 0x0008;
100
verena beckhamc9659ea2015-05-22 16:47:53 +0100101
Tim Murray56f9e6f2014-05-16 11:47:26 -0700102 /*
103 * Detect the bitness of the VM to allow FieldPacker to do the right thing.
104 */
105 static native int rsnSystemGetPointerSize();
106 static int sPointerSize;
107
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700108 static {
109 sInitialized = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700110 if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
111 try {
Tim Murray2f2472c2013-08-22 14:55:26 -0700112 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
113 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
114 sRuntime = get_runtime.invoke(null);
115 registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
116 registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
117 } catch (Exception e) {
118 Log.e(LOG_TAG, "Error loading GC methods: " + e);
119 throw new RSRuntimeException("Error loading GC methods: " + e);
120 }
121 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700122 System.loadLibrary("rs_jni");
123 _nInit();
124 sInitialized = true;
Tim Murray56f9e6f2014-05-16 11:47:26 -0700125 sPointerSize = rsnSystemGetPointerSize();
Dan Morrille4d9a012013-03-28 18:10:43 -0700126 } catch (UnsatisfiedLinkError e) {
127 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
128 throw new RSRuntimeException("Error loading RS jni library: " + e);
129 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700130 }
131 }
132
Jason Sams2e1872f2010-08-17 16:25:41 -0700133 // Non-threadsafe functions.
Tim Murrayeff663f2013-11-15 13:08:30 -0800134 native long nDeviceCreate();
135 native void nDeviceDestroy(long dev);
136 native void nDeviceSetConfig(long dev, int param, int value);
137 native int nContextGetUserMessage(long con, int[] data);
138 native String nContextGetErrorMessage(long con);
139 native int nContextPeekMessage(long con, int[] subID);
140 native void nContextInitToClient(long con);
141 native void nContextDeinitToClient(long con);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700142
Tim Murray67cc2d02014-02-06 16:39:38 -0800143 // this should be a monotonically increasing ID
144 // used in conjunction with the API version of a device
145 static final long sMinorID = 1;
146
147 /**
148 * Returns an identifier that can be used to identify a particular
149 * minor version of RS.
150 *
151 * @hide
152 */
153 public static long getMinorID() {
154 return sMinorID;
155 }
156
Jason Sams02d56d92013-04-12 16:40:50 -0700157 /**
158 * ContextType specifies the specific type of context to be created.
159 *
160 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800161 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700162 /**
163 * NORMAL context, this is the default and what shipping apps should
164 * use.
165 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800166 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700167
168 /**
169 * DEBUG context, perform extra runtime checks to validate the
170 * kernels and APIs are being used as intended. Get and SetElementAt
171 * will be bounds checked in this mode.
172 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800173 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700174
175 /**
176 * PROFILE context, Intended to be used once the first time an
177 * application is run on a new device. This mode allows the runtime to
178 * do additional testing and performance tuning.
179 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800180 PROFILE (2);
181
182 int mID;
183 ContextType(int id) {
184 mID = id;
185 }
186 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800187
Stephen Hines42028a82013-04-17 19:22:01 -0700188 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800189 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700190
Jason Sams2e1872f2010-08-17 16:25:41 -0700191 // Methods below are wrapped to protect the non-threadsafe
192 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800193 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700194 int colorMin, int colorPref,
195 int alphaMin, int alphaPref,
196 int depthMin, int depthPref,
197 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700198 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800199 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700200 int colorMin, int colorPref,
201 int alphaMin, int alphaPref,
202 int depthMin, int depthPref,
203 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700204 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700205 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700206 alphaMin, alphaPref, depthMin, depthPref,
207 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700208 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700209 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800210 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
211 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800212 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700213 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800214 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700215 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800216 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800217
218 // take teardown lock
219 // teardown lock can only be taken when no objects are being destroyed
220 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
221 wlock.lock();
222
223 long curCon = mContext;
224 // context is considered dead as of this point
225 mContext = 0;
226
227 wlock.unlock();
228 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700229 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800230 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700231 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800232 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700233 rsnContextSetSurface(mContext, w, h, sur);
234 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800235 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700236 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
237 validate();
238 rsnContextSetSurfaceTexture(mContext, w, h, sur);
239 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800240 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700241 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800242 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700243 rsnContextSetPriority(mContext, p);
244 }
Tim Murray47f31582015-04-07 15:43:24 -0700245 native void rsnContextSetCacheDir(long con, String cacheDir);
246 synchronized void nContextSetCacheDir(String cacheDir) {
247 validate();
248 rsnContextSetCacheDir(mContext, cacheDir);
249 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800250 native void rsnContextDump(long con, int bits);
Jason Sams2e1872f2010-08-17 16:25:41 -0700251 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800252 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700253 rsnContextDump(mContext, bits);
254 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800255 native void rsnContextFinish(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700256 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800257 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700258 rsnContextFinish(mContext);
259 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700260
Tim Murrayeff663f2013-11-15 13:08:30 -0800261 native void rsnContextSendMessage(long con, int id, int[] data);
Jason Sams455d6442013-02-05 19:20:18 -0800262 synchronized void nContextSendMessage(int id, int[] data) {
263 validate();
264 rsnContextSendMessage(mContext, id, data);
265 }
266
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000267 native void rsnContextBindRootScript(long con, long script);
268 synchronized void nContextBindRootScript(long script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800269 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700270 rsnContextBindRootScript(mContext, script);
271 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800272 native void rsnContextBindSampler(long con, int sampler, int slot);
Jason Sams2e1872f2010-08-17 16:25:41 -0700273 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800274 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700275 rsnContextBindSampler(mContext, sampler, slot);
276 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000277 native void rsnContextBindProgramStore(long con, long pfs);
278 synchronized void nContextBindProgramStore(long pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800279 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700280 rsnContextBindProgramStore(mContext, pfs);
281 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000282 native void rsnContextBindProgramFragment(long con, long pf);
283 synchronized void nContextBindProgramFragment(long pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800284 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700285 rsnContextBindProgramFragment(mContext, pf);
286 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000287 native void rsnContextBindProgramVertex(long con, long pv);
288 synchronized void nContextBindProgramVertex(long pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800289 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700290 rsnContextBindProgramVertex(mContext, pv);
291 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000292 native void rsnContextBindProgramRaster(long con, long pr);
293 synchronized void nContextBindProgramRaster(long pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800294 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700295 rsnContextBindProgramRaster(mContext, pr);
296 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800297 native void rsnContextPause(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700298 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800299 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700300 rsnContextPause(mContext);
301 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800302 native void rsnContextResume(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700303 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800304 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700305 rsnContextResume(mContext);
306 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700307
Yang Ni281c3252014-10-24 08:52:24 -0700308 native long rsnClosureCreate(long con, long kernelID, long returnValue,
309 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
310 long[] depFieldIDs);
311 synchronized long nClosureCreate(long kernelID, long returnValue,
312 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
313 long[] depFieldIDs) {
314 validate();
Yang Ni4e90b9b2015-04-30 16:13:54 -0700315 long c = rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
Yang Ni281c3252014-10-24 08:52:24 -0700316 sizes, depClosures, depFieldIDs);
Yang Ni4e90b9b2015-04-30 16:13:54 -0700317 if (c == 0) {
318 throw new RSRuntimeException("Failed creating closure.");
319 }
320 return c;
Yang Ni281c3252014-10-24 08:52:24 -0700321 }
322
Yang Nibe392ad2015-01-23 17:16:02 -0800323 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
324 long[] fieldIDs, long[] values, int[] sizes);
325 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
326 long[] fieldIDs, long[] values, int[] sizes) {
327 validate();
Yang Ni4e90b9b2015-04-30 16:13:54 -0700328 long c = rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
Yang Nibe392ad2015-01-23 17:16:02 -0800329 values, sizes);
Yang Ni4e90b9b2015-04-30 16:13:54 -0700330 if (c == 0) {
331 throw new RSRuntimeException("Failed creating closure.");
332 }
333 return c;
Yang Nibe392ad2015-01-23 17:16:02 -0800334 }
335
Yang Ni281c3252014-10-24 08:52:24 -0700336 native void rsnClosureSetArg(long con, long closureID, int index,
337 long value, int size);
338 synchronized void nClosureSetArg(long closureID, int index, long value,
339 int size) {
340 validate();
341 rsnClosureSetArg(mContext, closureID, index, value, size);
342 }
343
344 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
345 long value, int size);
346 // Does this have to be synchronized?
347 synchronized void nClosureSetGlobal(long closureID, long fieldID,
348 long value, int size) {
349 validate(); // TODO: is this necessary?
350 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
351 }
352
Yang Ni35be56c2015-04-02 17:47:56 -0700353 native long rsnScriptGroup2Create(long con, String name, String cachePath,
354 long[] closures);
355 synchronized long nScriptGroup2Create(String name, String cachePath,
356 long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700357 validate();
Yang Ni4e90b9b2015-04-30 16:13:54 -0700358 long g = rsnScriptGroup2Create(mContext, name, cachePath, closures);
359 if (g == 0) {
360 throw new RSRuntimeException("Failed creating script group.");
361 }
362 return g;
Yang Ni281c3252014-10-24 08:52:24 -0700363 }
364
365 native void rsnScriptGroup2Execute(long con, long groupID);
366 synchronized void nScriptGroup2Execute(long groupID) {
367 validate();
368 rsnScriptGroup2Execute(mContext, groupID);
369 }
370
Tim Murray460a0492013-11-19 12:45:54 -0800371 native void rsnAssignName(long con, long obj, byte[] name);
372 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800373 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700374 rsnAssignName(mContext, obj, name);
375 }
Tim Murray460a0492013-11-19 12:45:54 -0800376 native String rsnGetName(long con, long obj);
377 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800378 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700379 return rsnGetName(mContext, obj);
380 }
Tim Murray06b45672014-01-07 11:13:56 -0800381
382 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800383 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800384 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800385 // There is a race condition here. The calling code may be run
386 // by the gc while teardown is occuring. This protects againts
387 // deleting dead objects.
388 if (mContext != 0) {
389 rsnObjDestroy(mContext, id);
390 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700391 }
Jason Samsfe08d992009-05-27 14:45:32 -0700392
Tim Murray460a0492013-11-19 12:45:54 -0800393 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
394 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800395 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700396 return rsnElementCreate(mContext, type, kind, norm, vecSize);
397 }
Ashok Bhat98071552014-02-12 09:54:43 +0000398 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
399 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800400 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700401 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700402 }
Tim Murray460a0492013-11-19 12:45:54 -0800403 native void rsnElementGetNativeData(long con, long id, int[] elementData);
404 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800405 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700406 rsnElementGetNativeData(mContext, id, elementData);
407 }
Tim Murray460a0492013-11-19 12:45:54 -0800408 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000409 long[] IDs, String[] names, int[] arraySizes);
410 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800411 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700412 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700413 }
Jason Sams768bc022009-09-21 19:41:04 -0700414
Tim Murray460a0492013-11-19 12:45:54 -0800415 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
416 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800417 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800418 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700419 }
Ashok Bhat98071552014-02-12 09:54:43 +0000420 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
421 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800422 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700423 rsnTypeGetNativeData(mContext, id, typeData);
424 }
Jason Sams768bc022009-09-21 19:41:04 -0700425
Ashok Bhat98071552014-02-12 09:54:43 +0000426 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
427 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800428 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800429 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700430 }
Tim Murray460a0492013-11-19 12:45:54 -0800431 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
432 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800433 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800434 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700435 }
Tim Murraya3145512012-12-04 17:59:29 -0800436
Tim Murray460a0492013-11-19 12:45:54 -0800437 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
438 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800439 validate();
440 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
441 }
442
Tim Murray460a0492013-11-19 12:45:54 -0800443 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
444 synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800445 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800446 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800447 }
Tim Murray460a0492013-11-19 12:45:54 -0800448 native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
449 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800450 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700451 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
452 }
Tim Murray460a0492013-11-19 12:45:54 -0800453 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
454 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800455 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800456 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
457 }
458
Tim Murray460a0492013-11-19 12:45:54 -0800459 native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
460 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800461 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800462 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
463 }
464
465
Tim Murray460a0492013-11-19 12:45:54 -0800466 native void rsnAllocationSyncAll(long con, long alloc, int src);
467 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800468 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800469 rsnAllocationSyncAll(mContext, alloc, src);
470 }
Tim Murray460a0492013-11-19 12:45:54 -0800471 native Surface rsnAllocationGetSurface(long con, long alloc);
472 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800473 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800474 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700475 }
Tim Murray460a0492013-11-19 12:45:54 -0800476 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
477 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800478 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700479 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800480 }
Tim Murray460a0492013-11-19 12:45:54 -0800481 native void rsnAllocationIoSend(long con, long alloc);
482 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800483 validate();
484 rsnAllocationIoSend(mContext, alloc);
485 }
Tim Murray460a0492013-11-19 12:45:54 -0800486 native void rsnAllocationIoReceive(long con, long alloc);
487 synchronized void nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800488 validate();
489 rsnAllocationIoReceive(mContext, alloc);
490 }
491
Jason Sams615e7ce2012-01-13 14:01:20 -0800492
Tim Murray460a0492013-11-19 12:45:54 -0800493 native void rsnAllocationGenerateMipmaps(long con, long alloc);
494 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800495 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800496 rsnAllocationGenerateMipmaps(mContext, alloc);
497 }
Tim Murray460a0492013-11-19 12:45:54 -0800498 native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
499 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800500 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800501 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700502 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700503
Jason Sams49a05d72010-12-29 14:31:29 -0800504
Miao Wang87e908d2015-03-02 15:15:15 -0800505 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
506 int mSize, boolean usePadding);
507 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
508 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800509 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800510 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700511 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700512
Miao Wangc8e237e2015-02-20 18:36:32 -0800513 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
514 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 -0800515 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800516 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700517 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700518
Tim Murrayeff663f2013-11-15 13:08:30 -0800519 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800520 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700521 int dstMip, int dstFace,
522 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800523 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700524 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800525 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700526 int dstMip, int dstFace,
527 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800528 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700529 int srcMip, int srcFace) {
530 validate();
531 rsnAllocationData2D(mContext,
532 dstAlloc, dstXoff, dstYoff,
533 dstMip, dstFace,
534 width, height,
535 srcAlloc, srcXoff, srcYoff,
536 srcMip, srcFace);
537 }
538
Tim Murray460a0492013-11-19 12:45:54 -0800539 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800540 int w, int h, Object d, int sizeBytes, int dt,
541 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800542 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800543 int w, int h, Object d, int sizeBytes, Element.DataType dt,
544 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800545 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800546 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700547 }
Jason Sams21659ac2013-11-06 15:08:07 -0800548
Tim Murray460a0492013-11-19 12:45:54 -0800549 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
550 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800551 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800552 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
553 }
Jason Sams49a05d72010-12-29 14:31:29 -0800554
Tim Murrayeff663f2013-11-15 13:08:30 -0800555 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800556 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700557 int dstMip,
558 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800559 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700560 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800561 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700562 int dstMip,
563 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800564 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700565 int srcMip) {
566 validate();
567 rsnAllocationData3D(mContext,
568 dstAlloc, dstXoff, dstYoff, dstZoff,
569 dstMip, width, height, depth,
570 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
571 }
572
Tim Murray460a0492013-11-19 12:45:54 -0800573 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800574 int w, int h, int depth, Object d, int sizeBytes, int dt,
575 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800576 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800577 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
578 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700579 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800580 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
581 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700582 }
Jason Samsb05d6892013-04-09 15:59:24 -0700583
Miao Wang87e908d2015-03-02 15:15:15 -0800584 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
585 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800586 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800587 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800588 }
Jason Sams21659ac2013-11-06 15:08:07 -0800589
Tim Murray460a0492013-11-19 12:45:54 -0800590 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800591 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800592 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800593 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800594 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800595 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800596 }
Jason Sams21659ac2013-11-06 15:08:07 -0800597
Miao Wangc8e237e2015-02-20 18:36:32 -0800598 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800599 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800600 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800601 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800602 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800603 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800604 }
605
Tim Murray460a0492013-11-19 12:45:54 -0800606 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800607 int w, int h, Object d, int sizeBytes, int dt,
608 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800609 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800610 int w, int h, Object d, int sizeBytes, Element.DataType dt,
611 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800612 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800613 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700614 }
Jason Sams21659ac2013-11-06 15:08:07 -0800615
Miao Wangc8e237e2015-02-20 18:36:32 -0800616 native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800617 int w, int h, int depth, Object d, int sizeBytes, int dt,
618 int mSize, boolean usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800619 synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800620 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
621 int mSize, boolean usePadding) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800622 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800623 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800624 }
625
Tim Murray460a0492013-11-19 12:45:54 -0800626 native long rsnAllocationGetType(long con, long id);
627 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800628 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700629 return rsnAllocationGetType(mContext, id);
630 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700631
Tim Murray460a0492013-11-19 12:45:54 -0800632 native void rsnAllocationResize1D(long con, long id, int dimX);
633 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800634 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700635 rsnAllocationResize1D(mContext, id, dimX);
636 }
Jason Sams5edc6082010-10-05 13:32:49 -0700637
Jason Sams46ba27e32015-02-06 17:45:15 -0800638 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
639 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
640 validate();
641 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
642 }
643
644 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
645 int mip, int face, int a1, int a2, int a3, int a4);
646 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
647 int mip, int face, int a1, int a2, int a3, int a4) {
648 validate();
649 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
650 }
651
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000652 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
653 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800654 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700655 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
656 }
Tim Murray460a0492013-11-19 12:45:54 -0800657 native long rsnFileA3DCreateFromFile(long con, String path);
658 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800659 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800660 return rsnFileA3DCreateFromFile(mContext, path);
661 }
Tim Murray460a0492013-11-19 12:45:54 -0800662 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
663 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800664 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800665 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
666 }
Tim Murray460a0492013-11-19 12:45:54 -0800667 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
668 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800669 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700670 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
671 }
Tim Murray460a0492013-11-19 12:45:54 -0800672 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
673 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800674 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700675 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
676 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000677 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
678 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800679 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700680 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
681 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700682
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000683 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
684 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800685 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700686 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
687 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000688 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
689 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800690 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800691 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
692 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000693 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
694 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800695 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800696 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
697 }
Jason Sams22534172009-08-04 16:58:20 -0700698
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700699
Tim Murray460a0492013-11-19 12:45:54 -0800700 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
701 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800702 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700703 rsnScriptBindAllocation(mContext, script, alloc, slot);
704 }
Tim Murray460a0492013-11-19 12:45:54 -0800705 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
706 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800707 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700708 rsnScriptSetTimeZone(mContext, script, timeZone);
709 }
Tim Murray460a0492013-11-19 12:45:54 -0800710 native void rsnScriptInvoke(long con, long id, int slot);
711 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800712 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700713 rsnScriptInvoke(mContext, id, slot);
714 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700715
716 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
717 long aout, byte[] params, int[] limits);
718
719 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
720 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700721 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700722 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700723 }
724
Matt Wala36eb1f72015-07-20 15:35:27 -0700725 native void rsnScriptReduce(long con, long id, int slot, long ain,
726 long aout, int[] limits);
727 synchronized void nScriptReduce(long id, int slot, long ain, long aout,
728 int[] limits) {
729 validate();
730 rsnScriptReduce(mContext, id, slot, ain, aout, limits);
731 }
732
Tim Murray460a0492013-11-19 12:45:54 -0800733 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
734 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800735 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700736 rsnScriptInvokeV(mContext, id, slot, params);
737 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700738
Tim Murray460a0492013-11-19 12:45:54 -0800739 native void rsnScriptSetVarI(long con, long id, int slot, int val);
740 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800741 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700742 rsnScriptSetVarI(mContext, id, slot, val);
743 }
Tim Murray460a0492013-11-19 12:45:54 -0800744 native int rsnScriptGetVarI(long con, long id, int slot);
745 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700746 validate();
747 return rsnScriptGetVarI(mContext, id, slot);
748 }
749
Tim Murray460a0492013-11-19 12:45:54 -0800750 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
751 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800752 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700753 rsnScriptSetVarJ(mContext, id, slot, val);
754 }
Tim Murray460a0492013-11-19 12:45:54 -0800755 native long rsnScriptGetVarJ(long con, long id, int slot);
756 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700757 validate();
758 return rsnScriptGetVarJ(mContext, id, slot);
759 }
760
Tim Murray460a0492013-11-19 12:45:54 -0800761 native void rsnScriptSetVarF(long con, long id, int slot, float val);
762 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800763 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700764 rsnScriptSetVarF(mContext, id, slot, val);
765 }
Tim Murray460a0492013-11-19 12:45:54 -0800766 native float rsnScriptGetVarF(long con, long id, int slot);
767 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700768 validate();
769 return rsnScriptGetVarF(mContext, id, slot);
770 }
Tim Murray460a0492013-11-19 12:45:54 -0800771 native void rsnScriptSetVarD(long con, long id, int slot, double val);
772 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800773 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700774 rsnScriptSetVarD(mContext, id, slot, val);
775 }
Tim Murray460a0492013-11-19 12:45:54 -0800776 native double rsnScriptGetVarD(long con, long id, int slot);
777 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700778 validate();
779 return rsnScriptGetVarD(mContext, id, slot);
780 }
Tim Murray460a0492013-11-19 12:45:54 -0800781 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
782 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800783 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700784 rsnScriptSetVarV(mContext, id, slot, val);
785 }
Tim Murray460a0492013-11-19 12:45:54 -0800786 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
787 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700788 validate();
789 rsnScriptGetVarV(mContext, id, slot, val);
790 }
Tim Murray460a0492013-11-19 12:45:54 -0800791 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
792 long e, int[] dims);
793 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
794 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700795 validate();
796 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
797 }
Tim Murray460a0492013-11-19 12:45:54 -0800798 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
799 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800800 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800801 rsnScriptSetVarObj(mContext, id, slot, val);
802 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700803
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000804 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700805 byte[] script, int length);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000806 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800807 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700808 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700809 }
Jason Samsebfb4362009-09-23 13:57:02 -0700810
Tim Murray460a0492013-11-19 12:45:54 -0800811 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
812 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700813 validate();
814 return rsnScriptIntrinsicCreate(mContext, id, eid);
815 }
816
Tim Murray460a0492013-11-19 12:45:54 -0800817 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
818 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700819 validate();
820 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
821 }
822
Yang Nibe392ad2015-01-23 17:16:02 -0800823 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
824 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
825 validate();
826 return rsnScriptInvokeIDCreate(mContext, sid, slot);
827 }
828
Tim Murray460a0492013-11-19 12:45:54 -0800829 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
830 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700831 validate();
832 return rsnScriptFieldIDCreate(mContext, sid, slot);
833 }
834
Ashok Bhat98071552014-02-12 09:54:43 +0000835 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
836 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700837 validate();
838 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
839 }
840
Tim Murray460a0492013-11-19 12:45:54 -0800841 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
842 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700843 validate();
844 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
845 }
846
Tim Murray460a0492013-11-19 12:45:54 -0800847 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
848 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700849 validate();
850 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
851 }
852
Tim Murray460a0492013-11-19 12:45:54 -0800853 native void rsnScriptGroupExecute(long con, long group);
854 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700855 validate();
856 rsnScriptGroupExecute(mContext, group);
857 }
858
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000859 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700860 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000861 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700862 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800863 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700864 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700865 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800866
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000867 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700868 boolean depthMask, boolean dither,
869 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000870 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700871 boolean depthMask, boolean dither,
872 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800873 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700874 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
875 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700876 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700877
Tim Murray460a0492013-11-19 12:45:54 -0800878 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
879 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800880 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700881 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700882 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700883
Tim Murray460a0492013-11-19 12:45:54 -0800884 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
885 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800886 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700887 rsnProgramBindConstants(mContext, pv, slot, mID);
888 }
Tim Murray460a0492013-11-19 12:45:54 -0800889 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
890 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800891 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700892 rsnProgramBindTexture(mContext, vpf, slot, a);
893 }
Tim Murray460a0492013-11-19 12:45:54 -0800894 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
895 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800896 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700897 rsnProgramBindSampler(mContext, vpf, slot, s);
898 }
Ashok Bhat98071552014-02-12 09:54:43 +0000899 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
900 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800901 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800902 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700903 }
Ashok Bhat98071552014-02-12 09:54:43 +0000904 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
905 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800906 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800907 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700908 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700909
Ashok Bhat98071552014-02-12 09:54:43 +0000910 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
911 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800912 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700913 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800914 }
Tim Murray460a0492013-11-19 12:45:54 -0800915 native int rsnMeshGetVertexBufferCount(long con, long id);
916 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800917 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700918 return rsnMeshGetVertexBufferCount(mContext, id);
919 }
Tim Murray460a0492013-11-19 12:45:54 -0800920 native int rsnMeshGetIndexCount(long con, long id);
921 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800922 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700923 return rsnMeshGetIndexCount(mContext, id);
924 }
Ashok Bhat98071552014-02-12 09:54:43 +0000925 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
926 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800927 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700928 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
929 }
Ashok Bhat98071552014-02-12 09:54:43 +0000930 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
931 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800932 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700933 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
934 }
935
Tim Murray25207df2015-01-12 16:47:56 -0800936 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
937 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
938 float alpha, long A, long B, float beta, long C, int incX, int incY,
939 int KL, int KU);
940 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
941 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
942 float alpha, long A, long B, float beta, long C, int incX, int incY,
943 int KL, int KU) {
944 validate();
945 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
946 }
947
948 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
949 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
950 double alpha, long A, long B, double beta, long C, int incX, int incY,
951 int KL, int KU);
952 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
953 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
954 double alpha, long A, long B, double beta, long C, int incX, int incY,
955 int KL, int KU) {
956 validate();
957 rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
958 }
959
960 native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA,
961 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
962 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
963 int KL, int KU);
964 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
965 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
966 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
967 int KL, int KU) {
968 validate();
969 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
970 }
971
972 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
973 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
974 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
975 int KL, int KU);
976 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
977 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
978 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
979 int KL, int KU) {
980 validate();
981 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
982 }
983
Tim Murray9cb16a22015-04-01 11:07:16 -0700984 native void rsnScriptIntrinsicBLAS_BNNM(long con, long id, int M, int N, int K,
985 long A, int a_offset, long B, int b_offset, long C, int c_offset,
986 int c_mult_int);
987 synchronized void nScriptIntrinsicBLAS_BNNM(long id, int M, int N, int K,
988 long A, int a_offset, long B, int b_offset, long C, int c_offset,
989 int c_mult_int) {
990 validate();
991 rsnScriptIntrinsicBLAS_BNNM(mContext, id, M, N, K, A, a_offset, B, b_offset, C, c_offset, c_mult_int);
992 }
993
994
Tim Murray25207df2015-01-12 16:47:56 -0800995
Tim Murrayeff663f2013-11-15 13:08:30 -0800996 long mDev;
997 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -0800998 private boolean mDestroyed = false;
999
Romain Guy650a3eb2009-08-31 14:06:43 -07001000 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001001 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001002
Jason Sams8cb39de2010-06-01 15:47:01 -07001003 Element mElement_U8;
1004 Element mElement_I8;
1005 Element mElement_U16;
1006 Element mElement_I16;
1007 Element mElement_U32;
1008 Element mElement_I32;
Stephen Hines52d83632010-10-11 16:10:42 -07001009 Element mElement_U64;
Stephen Hinesef1dac22010-10-01 15:39:33 -07001010 Element mElement_I64;
Jason Samsa5835a22014-11-05 15:16:26 -08001011 Element mElement_F16;
Jason Sams8cb39de2010-06-01 15:47:01 -07001012 Element mElement_F32;
Stephen Hines02f417052010-09-30 15:19:22 -07001013 Element mElement_F64;
Jason Samsf110d4b2010-06-21 17:42:41 -07001014 Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -07001015
Jason Sams8cb39de2010-06-01 15:47:01 -07001016 Element mElement_ELEMENT;
1017 Element mElement_TYPE;
1018 Element mElement_ALLOCATION;
1019 Element mElement_SAMPLER;
1020 Element mElement_SCRIPT;
1021 Element mElement_MESH;
1022 Element mElement_PROGRAM_FRAGMENT;
1023 Element mElement_PROGRAM_VERTEX;
1024 Element mElement_PROGRAM_RASTER;
1025 Element mElement_PROGRAM_STORE;
Stephen Hines3a291412012-04-11 17:27:29 -07001026 Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -07001027
Jason Sams3c0dfba2009-09-27 17:50:38 -07001028 Element mElement_A_8;
1029 Element mElement_RGB_565;
1030 Element mElement_RGB_888;
1031 Element mElement_RGBA_5551;
1032 Element mElement_RGBA_4444;
1033 Element mElement_RGBA_8888;
1034
Jason Samsa5835a22014-11-05 15:16:26 -08001035 Element mElement_HALF_2;
1036 Element mElement_HALF_3;
1037 Element mElement_HALF_4;
1038
Jason Sams8cb39de2010-06-01 15:47:01 -07001039 Element mElement_FLOAT_2;
1040 Element mElement_FLOAT_3;
1041 Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001042
1043 Element mElement_DOUBLE_2;
1044 Element mElement_DOUBLE_3;
1045 Element mElement_DOUBLE_4;
1046
1047 Element mElement_UCHAR_2;
1048 Element mElement_UCHAR_3;
Jason Sams8cb39de2010-06-01 15:47:01 -07001049 Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001050
Stephen Hines836c4a52011-06-01 14:38:10 -07001051 Element mElement_CHAR_2;
1052 Element mElement_CHAR_3;
1053 Element mElement_CHAR_4;
1054
1055 Element mElement_USHORT_2;
1056 Element mElement_USHORT_3;
1057 Element mElement_USHORT_4;
1058
1059 Element mElement_SHORT_2;
1060 Element mElement_SHORT_3;
1061 Element mElement_SHORT_4;
1062
1063 Element mElement_UINT_2;
1064 Element mElement_UINT_3;
1065 Element mElement_UINT_4;
1066
1067 Element mElement_INT_2;
1068 Element mElement_INT_3;
1069 Element mElement_INT_4;
1070
1071 Element mElement_ULONG_2;
1072 Element mElement_ULONG_3;
1073 Element mElement_ULONG_4;
1074
1075 Element mElement_LONG_2;
1076 Element mElement_LONG_3;
1077 Element mElement_LONG_4;
1078
Tim Murray932e78e2013-09-03 11:42:26 -07001079 Element mElement_YUV;
1080
Jason Sams1d45c472010-08-25 14:31:48 -07001081 Element mElement_MATRIX_4X4;
1082 Element mElement_MATRIX_3X3;
1083 Element mElement_MATRIX_2X2;
1084
Jason Sams4d339932010-05-11 14:03:58 -07001085 Sampler mSampler_CLAMP_NEAREST;
1086 Sampler mSampler_CLAMP_LINEAR;
1087 Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1088 Sampler mSampler_WRAP_NEAREST;
1089 Sampler mSampler_WRAP_LINEAR;
1090 Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
Tim Murray6b9b2ca2013-02-15 13:25:55 -08001091 Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1092 Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1093 Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001094
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001095 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1096 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001097 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1098 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001099
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001100 ProgramRaster mProgramRaster_CULL_BACK;
1101 ProgramRaster mProgramRaster_CULL_FRONT;
1102 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001103
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001104 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001105 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001106
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001107 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001108 * The base class from which an application should derive in order
1109 * to receive RS messages from scripts. When a script calls {@code
1110 * rsSendToClient}, the data fields will be filled, and the run
1111 * method will be called on a separate thread. This will occur
1112 * some time after {@code rsSendToClient} completes in the script,
1113 * as {@code rsSendToClient} is asynchronous. Message handlers are
1114 * not guaranteed to have completed when {@link
1115 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001116 *
1117 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001118 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001119 protected int[] mData;
1120 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001121 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001122 public void run() {
1123 }
1124 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001125 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001126 * If an application is expecting messages, it should set this
1127 * field to an instance of {@link RSMessageHandler}. This
1128 * instance will receive all the user messages sent from {@code
1129 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001130 *
1131 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001132 RSMessageHandler mMessageCallback = null;
1133
1134 public void setMessageHandler(RSMessageHandler msg) {
1135 mMessageCallback = msg;
1136 }
1137 public RSMessageHandler getMessageHandler() {
1138 return mMessageCallback;
1139 }
Jason Sams516c3192009-10-06 13:58:47 -07001140
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001141 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001142 * Place a message into the message queue to be sent back to the message
1143 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001144 *
1145 * @param id
1146 * @param data
1147 */
1148 public void sendMessage(int id, int[] data) {
1149 nContextSendMessage(id, data);
1150 }
1151
1152 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001153 * The runtime error handler base class. An application should derive from this class
1154 * if it wishes to install an error handler. When errors occur at runtime,
1155 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001156 *
1157 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001158 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001159 protected String mErrorMessage;
1160 protected int mErrorNum;
1161 public void run() {
1162 }
1163 }
Jason Sams27676fe2010-11-10 17:00:59 -08001164
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001165 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001166 * Application Error handler. All runtime errors will be dispatched to the
1167 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001168 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001169 * This will cause program termaination.
1170 *
1171 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001172 RSErrorHandler mErrorCallback = null;
1173
1174 public void setErrorHandler(RSErrorHandler msg) {
1175 mErrorCallback = msg;
1176 }
1177 public RSErrorHandler getErrorHandler() {
1178 return mErrorCallback;
1179 }
Jason Sams1c415172010-11-08 17:06:46 -08001180
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001181 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001182 * RenderScript worker thread priority enumeration. The default value is
1183 * NORMAL. Applications wishing to do background processing should set
1184 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001185 */
Jason Sams7d787b42009-11-15 12:14:26 -08001186 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001187 // These values used to represent official thread priority values
1188 // now they are simply enums to be used by the runtime side
1189 LOW (15),
1190 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001191
1192 int mID;
1193 Priority(int id) {
1194 mID = id;
1195 }
1196 }
1197
Jason Sams678cc7f2014-03-05 16:09:02 -08001198 void validateObject(BaseObj o) {
1199 if (o != null) {
1200 if (o.mRS != this) {
1201 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1202 }
1203 }
1204 }
1205
Jason Sams771bebb2009-12-07 12:40:12 -08001206 void validate() {
1207 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001208 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001209 }
1210 }
1211
Jason Sams27676fe2010-11-10 17:00:59 -08001212
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001213 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001214 * Change the priority of the worker threads for this context.
1215 *
1216 * @param p New priority to be set.
1217 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001218 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001219 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001220 nContextSetPriority(p.mID);
1221 }
1222
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001223 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001224 RenderScript mRS;
1225 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001226 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001227
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001228 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1229 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1230 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1231 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1232 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001233 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001234
Stephen Hines42028a82013-04-17 19:22:01 -07001235 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001236 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001237
Jason Sams516c3192009-10-06 13:58:47 -07001238 MessageThread(RenderScript rs) {
1239 super("RSMessageThread");
1240 mRS = rs;
1241
1242 }
1243
1244 public void run() {
1245 // This function is a temporary solution. The final solution will
1246 // used typed allocations where the message id is the type indicator.
1247 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001248 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001249 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001250 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001251 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001252 int size = mAuxData[1];
1253 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001254
1255 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1256 if ((size>>2) >= rbuf.length) {
1257 rbuf = new int[(size + 3) >> 2];
1258 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001259 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1260 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001261 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001262 }
Jason Sams1c415172010-11-08 17:06:46 -08001263
1264 if(mRS.mMessageCallback != null) {
1265 mRS.mMessageCallback.mData = rbuf;
1266 mRS.mMessageCallback.mID = subID;
1267 mRS.mMessageCallback.mLength = size;
1268 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001269 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001270 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001271 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001272 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001273 }
Jason Sams1c415172010-11-08 17:06:46 -08001274
1275 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1276 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1277
Stephen Hines42028a82013-04-17 19:22:01 -07001278 // Throw RSRuntimeException under the following conditions:
1279 //
1280 // 1) It is an unknown fatal error.
1281 // 2) It is a debug fatal error, and we are not in a
1282 // debug context.
1283 // 3) It is a debug fatal error, and we do not have an
1284 // error callback.
1285 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1286 (subID >= RS_ERROR_FATAL_DEBUG &&
1287 (mRS.mContextType != ContextType.DEBUG ||
1288 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001289 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1290 }
1291
Jason Sams1c415172010-11-08 17:06:46 -08001292 if(mRS.mErrorCallback != null) {
1293 mRS.mErrorCallback.mErrorMessage = e;
1294 mRS.mErrorCallback.mErrorNum = subID;
1295 mRS.mErrorCallback.run();
1296 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001297 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001298 // Do not throw here. In these cases, we do not have
1299 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001300 }
1301 continue;
1302 }
1303
Jason Sams739c8262013-04-11 18:07:52 -07001304 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001305 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1306 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1307 throw new RSDriverException("Error processing message from RenderScript.");
1308 }
1309 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1310 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001311 continue;
1312 }
1313
Jason Sams1c415172010-11-08 17:06:46 -08001314 // 2: teardown.
1315 // But we want to avoid starving other threads during
1316 // teardown by yielding until the next line in the destructor
1317 // can execute to set mRun = false
1318 try {
1319 sleep(1, 0);
1320 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001321 }
Jason Sams516c3192009-10-06 13:58:47 -07001322 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001323 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001324 }
1325 }
1326
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001327 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001328 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001329 if (ctx != null) {
1330 mApplicationContext = ctx.getApplicationContext();
1331 }
Tim Murray06b45672014-01-07 11:13:56 -08001332 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001333 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001334 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001335 } catch (Exception e) {
1336 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1337 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1338 }
1339
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001340 }
1341
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001342 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001343 * Gets the application context associated with the RenderScript context.
1344 *
1345 * @return The application context.
1346 */
1347 public final Context getApplicationContext() {
1348 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001349 }
1350
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001351 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001352 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001353 *
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001354 * @hide
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001355 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001356 * @return RenderScript
1357 */
Jason Samse16da122015-03-18 17:04:18 -07001358 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001359 if (!sInitialized) {
1360 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1361 return null;
1362 }
1363
verena beckhamc9659ea2015-05-22 16:47:53 +01001364 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER |
Stephen McGroarty88891e62015-09-02 15:54:05 +01001365 CREATE_FLAG_WAIT_FOR_ATTACH)) != 0) {
Jason Samsb69c7912014-05-20 18:48:35 -07001366 throw new RSIllegalArgumentException("Invalid flags passed.");
1367 }
1368
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001369 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001370
1371 rs.mDev = rs.nDeviceCreate();
Tim Murrayfd710e72014-06-06 11:10:45 -07001372 rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001373 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001374 rs.mContextFlags = flags;
1375 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001376 if (rs.mContext == 0) {
1377 throw new RSDriverException("Failed to create RS context.");
1378 }
Tim Murray47f31582015-04-07 15:43:24 -07001379
1380 // set up cache directory for entire context
1381 final String CACHE_PATH = "com.android.renderscript.cache";
1382 File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
1383 String mCachePath = f.getAbsolutePath();
1384 f.mkdirs();
1385 rs.nContextSetCacheDir(mCachePath);
1386
Jason Sams704ff642010-02-09 16:05:07 -08001387 rs.mMessageThread = new MessageThread(rs);
1388 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001389 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001390 }
1391
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001392 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001393 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001394 *
1395 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001396 *
1397 * @param ctx The context.
1398 * @return RenderScript
1399 */
1400 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001401 return create(ctx, ContextType.NORMAL);
1402 }
1403
1404 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001405 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001406 *
Jason Samse16da122015-03-18 17:04:18 -07001407 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001408 *
1409 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001410 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001411 * @return RenderScript
1412 */
1413 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001414 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001415 }
1416
Miao Wanga4e5adf2015-03-23 11:09:56 -07001417
1418 /**
Jason Samse16da122015-03-18 17:04:18 -07001419 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001420 *
Jason Samse16da122015-03-18 17:04:18 -07001421 * The returned context will be cached for future reuse within
1422 * the process. When an application is finished using
1423 * RenderScript it should call releaseAllContexts()
1424 *
1425 * A process context is a context designed for easy creation and
1426 * lifecycle management. Multiple calls to this function will
1427 * return the same object provided they are called with the same
1428 * options. This allows it to be used any time a RenderScript
1429 * context is needed.
1430 *
1431 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001432 *
1433 * @param ctx The context.
1434 * @param ct The type of context to be created.
1435 * @param flags The OR of the CREATE_FLAG_* options desired
1436 * @return RenderScript
1437 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001438 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001439 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001440 return create(ctx, v, ct, flags);
1441 }
1442
1443 /**
1444 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1445 *
1446 * Used by the RenderScriptThunker to maintain backward compatibility.
1447 *
1448 * @hide
1449 * @param ctx The context.
1450 * @param sdkVersion The target SDK Version.
1451 * @return RenderScript
1452 */
1453 public static RenderScript create(Context ctx, int sdkVersion) {
1454 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1455 }
1456
1457 /**
1458 * Gets or creates a RenderScript context of the specified type.
1459 *
1460 * @hide
1461 * @param ctx The context.
1462 * @param ct The type of context to be created.
1463 * @param sdkVersion The target SDK Version.
1464 * @param flags The OR of the CREATE_FLAG_* options desired
1465 * @return RenderScript
1466 */
1467 public static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
1468 if (sdkVersion < 23) {
1469 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001470 }
1471
1472 synchronized (mProcessContextList) {
1473 for (RenderScript prs : mProcessContextList) {
1474 if ((prs.mContextType == ct) &&
1475 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001476 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001477
1478 return prs;
1479 }
1480 }
1481
Miao Wanga4e5adf2015-03-23 11:09:56 -07001482 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001483 prs.mIsProcessContext = true;
1484 mProcessContextList.add(prs);
1485 return prs;
1486 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001487 }
1488
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001489 /**
Jason Samse16da122015-03-18 17:04:18 -07001490 * @hide
1491 *
1492 * Releases all the process contexts. This is the same as
1493 * calling .destroy() on each unique context retreived with
1494 * create(...). If no contexts have been created this
1495 * function does nothing.
1496 *
1497 * Typically you call this when your application is losing focus
1498 * and will not be using a context for some time.
1499 *
1500 * This has no effect on a context created with
1501 * createMultiContext()
1502 */
1503 public static void releaseAllContexts() {
1504 ArrayList<RenderScript> oldList;
1505 synchronized (mProcessContextList) {
1506 oldList = mProcessContextList;
1507 mProcessContextList = new ArrayList<RenderScript>();
1508 }
1509
1510 for (RenderScript prs : oldList) {
1511 prs.mIsProcessContext = false;
1512 prs.destroy();
1513 }
1514 oldList.clear();
1515 }
1516
1517
1518
1519 /**
1520 * Create a RenderScript context.
1521 *
1522 * This is an advanced function intended for applications which
1523 * need to create more than one RenderScript context to be used
1524 * at the same time.
1525 *
1526 * If you need a single context please use create()
1527 *
1528 * @hide
1529 * @param ctx The context.
1530 * @return RenderScript
1531 */
1532 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1533 return internalCreate(ctx, API_number, ct, flags);
1534 }
1535
1536
1537 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001538 * Print the currently available debugging information about the state of
1539 * the RS context to the log.
1540 *
Jason Sams27676fe2010-11-10 17:00:59 -08001541 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001542 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001543 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001544 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001545 }
1546
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001547 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001548 * Wait for any pending asynchronous opeations (such as copies to a RS
1549 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001550 *
1551 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001552 public void finish() {
1553 nContextFinish();
1554 }
1555
Jason Samsd22a6f02015-02-19 17:19:52 -08001556 private void helpDestroy() {
1557 boolean shouldDestroy = false;
1558 synchronized(this) {
1559 if (!mDestroyed) {
1560 shouldDestroy = true;
1561 mDestroyed = true;
1562 }
1563 }
1564
1565 if (shouldDestroy) {
1566 nContextFinish();
1567
1568 nContextDeinitToClient(mContext);
1569 mMessageThread.mRun = false;
1570 try {
1571 mMessageThread.join();
1572 } catch(InterruptedException e) {
1573 }
1574
1575 nContextDestroy();
1576
1577 nDeviceDestroy(mDev);
1578 mDev = 0;
1579 }
1580 }
1581
1582 protected void finalize() throws Throwable {
1583 helpDestroy();
1584 super.finalize();
1585 }
1586
1587
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001588 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001589 * Destroys this RenderScript context. Once this function is called,
1590 * using this context or any objects belonging to this context is
1591 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001592 *
Jason Samse16da122015-03-18 17:04:18 -07001593 * API 23+, this function is a NOP if the context was created
1594 * with create(). Please use releaseAllContexts() to clean up
1595 * contexts created with the create function.
1596 *
Jason Sams27676fe2010-11-10 17:00:59 -08001597 */
Jason Samsf5b45962009-08-25 14:49:07 -07001598 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001599 if (mIsProcessContext) {
1600 // users cannot destroy a process context
1601 return;
1602 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001603 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001604 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001605 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001606
Jason Samsa9e7a052009-09-25 14:51:22 -07001607 boolean isAlive() {
1608 return mContext != 0;
1609 }
1610
Tim Murray460a0492013-11-19 12:45:54 -08001611 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001612 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001613 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001614 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001615 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001616 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001617}