blob: 429315782a63bdfe9498fc68e95ad59c6f52b224 [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;
Miao Wang0facf022015-11-25 11:21:13 -080021import java.nio.ByteBuffer;
22import java.util.ArrayList;
Tim Murray06b45672014-01-07 11:13:56 -080023import java.util.concurrent.locks.ReentrantReadWriteLock;
Jason Sams36e612a2009-07-31 16:26:13 -070024
Mathew Inwoodf0c90b12018-08-01 10:05:11 +010025import android.annotation.UnsupportedAppUsage;
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080026import android.content.Context;
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080027import android.content.res.AssetManager;
Jason Samsb8c5a842009-07-31 20:40:47 -070028import android.graphics.Bitmap;
Jason Samsfaa32b32011-06-20 16:58:04 -070029import android.graphics.SurfaceTexture;
Dan Morrille4d9a012013-03-28 18:10:43 -070030import android.os.SystemProperties;
Tim Murray6d7a53c2013-05-23 16:59:23 -070031import android.os.Trace;
Miao Wang0facf022015-11-25 11:21:13 -080032import android.util.Log;
33import android.view.Surface;
Stephen Hines4382467a2011-08-01 15:02:34 -070034
Matt Wala36eb1f72015-07-20 15:35:27 -070035// TODO: Clean up the whitespace that separates methods in this class.
36
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070037/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070038 * This class provides access to a RenderScript context, which controls RenderScript
39 * initialization, resource management, and teardown. An instance of the RenderScript
40 * class must be created before any other RS objects can be created.
Jason Sams27676fe2010-11-10 17:00:59 -080041 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080042 * <div class="special reference">
43 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070044 * <p>For more information about creating an application that uses RenderScript, read the
45 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080046 * </div>
Jason Samse29d4712009-07-23 15:19:03 -070047 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070048public class RenderScript {
Tim Murray6d7a53c2013-05-23 16:59:23 -070049 static final long TRACE_TAG = Trace.TRACE_TAG_RS;
50
Jason Sams3bc47d42009-11-12 15:10:25 -080051 static final String LOG_TAG = "RenderScript_jni";
Jason Samsbf6ef8d72010-12-06 15:59:59 -080052 static final boolean DEBUG = false;
Romain Guy650a3eb2009-08-31 14:06:43 -070053 @SuppressWarnings({"UnusedDeclaration", "deprecation"})
Joe Onorato43a17652011-04-06 19:22:23 -070054 static final boolean LOG_ENABLED = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070055
Jason Samse16da122015-03-18 17:04:18 -070056 static private ArrayList<RenderScript> mProcessContextList = new ArrayList<RenderScript>();
57 private boolean mIsProcessContext = false;
58 private int mContextFlags = 0;
59 private int mContextSdkVersion = 0;
60
61
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080062 private Context mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070063
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080064 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070065 * We use a class initializer to allow the native code to cache some
66 * field offsets.
67 */
Dan Morrille4d9a012013-03-28 18:10:43 -070068 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
Jason Samsbf6ef8d72010-12-06 15:59:59 -080069 static boolean sInitialized;
70 native static void _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070071
Tim Murray2f2472c2013-08-22 14:55:26 -070072 static Object sRuntime;
73 static Method registerNativeAllocation;
74 static Method registerNativeFree;
Jason Samsdba3ba52009-07-30 14:56:12 -070075
Jason Sams26e90512014-05-07 14:23:27 -070076 /*
Tim Murrayfd710e72014-06-06 11:10:45 -070077 * Context creation flag that specifies a normal context.
Jason Sams26e90512014-05-07 14:23:27 -070078 */
Tim Murrayfd710e72014-06-06 11:10:45 -070079 public static final int CREATE_FLAG_NONE = 0x0000;
Jason Sams26e90512014-05-07 14:23:27 -070080
81 /*
82 * Context creation flag which specifies a context optimized for low
83 * latency over peak performance. This is a hint and may have no effect
84 * on some implementations.
85 */
Tim Murrayfd710e72014-06-06 11:10:45 -070086 public static final int CREATE_FLAG_LOW_LATENCY = 0x0002;
Jason Sams26e90512014-05-07 14:23:27 -070087
88 /*
89 * Context creation flag which specifies a context optimized for long
90 * battery life over peak performance. This is a hint and may have no effect
91 * on some implementations.
92 */
Tim Murrayfd710e72014-06-06 11:10:45 -070093 public static final int CREATE_FLAG_LOW_POWER = 0x0004;
Jason Sams26e90512014-05-07 14:23:27 -070094
Stephen McGroarty62cb9bd2015-05-08 15:56:58 +010095 /**
96 * @hide
97 * Context creation flag which instructs the implementation to wait for
98 * a debugger to be attached before continuing execution.
99 */
100 public static final int CREATE_FLAG_WAIT_FOR_ATTACH = 0x0008;
101
verena beckhamc9659ea2015-05-22 16:47:53 +0100102
Tim Murray56f9e6f2014-05-16 11:47:26 -0700103 /*
104 * Detect the bitness of the VM to allow FieldPacker to do the right thing.
105 */
106 static native int rsnSystemGetPointerSize();
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100107 @UnsupportedAppUsage
Tim Murray56f9e6f2014-05-16 11:47:26 -0700108 static int sPointerSize;
109
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700110 static {
111 sInitialized = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700112 if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
113 try {
Tim Murray2f2472c2013-08-22 14:55:26 -0700114 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
115 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
116 sRuntime = get_runtime.invoke(null);
117 registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
118 registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
119 } catch (Exception e) {
120 Log.e(LOG_TAG, "Error loading GC methods: " + e);
121 throw new RSRuntimeException("Error loading GC methods: " + e);
122 }
123 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700124 System.loadLibrary("rs_jni");
125 _nInit();
126 sInitialized = true;
Tim Murray56f9e6f2014-05-16 11:47:26 -0700127 sPointerSize = rsnSystemGetPointerSize();
Dan Morrille4d9a012013-03-28 18:10:43 -0700128 } catch (UnsatisfiedLinkError e) {
129 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
130 throw new RSRuntimeException("Error loading RS jni library: " + e);
131 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700132 }
133 }
134
Jason Sams2e1872f2010-08-17 16:25:41 -0700135 // Non-threadsafe functions.
Tim Murrayeff663f2013-11-15 13:08:30 -0800136 native long nDeviceCreate();
137 native void nDeviceDestroy(long dev);
138 native void nDeviceSetConfig(long dev, int param, int value);
139 native int nContextGetUserMessage(long con, int[] data);
140 native String nContextGetErrorMessage(long con);
141 native int nContextPeekMessage(long con, int[] subID);
142 native void nContextInitToClient(long con);
143 native void nContextDeinitToClient(long con);
Jason Sams3eaa3382009-06-10 15:04:38 -0700144
Tim Murray67cc2d02014-02-06 16:39:38 -0800145 // this should be a monotonically increasing ID
146 // used in conjunction with the API version of a device
Jason Samsf7642302015-05-12 14:06:56 -0700147 static final long sMinorVersion = 1;
Tim Murray67cc2d02014-02-06 16:39:38 -0800148
149 /**
Miao Wangf9d518a2015-05-14 14:53:30 -0700150 * @hide
151 *
152 * Only exist to be compatible with old version RenderScript Support lib.
153 * Will eventually be removed.
154 *
155 * @return Always return 1
156 *
157 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100158 @UnsupportedAppUsage
Miao Wangf9d518a2015-05-14 14:53:30 -0700159 public static long getMinorID() {
160 return 1;
161 }
162
163
164 /**
Tim Murray67cc2d02014-02-06 16:39:38 -0800165 * Returns an identifier that can be used to identify a particular
166 * minor version of RS.
167 *
Jason Sams6a420b52015-03-30 15:31:26 -0700168 * @return The minor RenderScript version number
169 *
Tim Murray67cc2d02014-02-06 16:39:38 -0800170 */
Jason Samsf7642302015-05-12 14:06:56 -0700171 public static long getMinorVersion() {
172 return sMinorVersion;
Tim Murray67cc2d02014-02-06 16:39:38 -0800173 }
174
Jason Sams02d56d92013-04-12 16:40:50 -0700175 /**
176 * ContextType specifies the specific type of context to be created.
177 *
178 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800179 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700180 /**
181 * NORMAL context, this is the default and what shipping apps should
182 * use.
183 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800184 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700185
186 /**
187 * DEBUG context, perform extra runtime checks to validate the
188 * kernels and APIs are being used as intended. Get and SetElementAt
189 * will be bounds checked in this mode.
190 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800191 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700192
193 /**
194 * PROFILE context, Intended to be used once the first time an
195 * application is run on a new device. This mode allows the runtime to
196 * do additional testing and performance tuning.
197 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800198 PROFILE (2);
199
200 int mID;
201 ContextType(int id) {
202 mID = id;
203 }
204 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800205
Stephen Hines42028a82013-04-17 19:22:01 -0700206 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800207 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700208
Jason Sams2e1872f2010-08-17 16:25:41 -0700209 // Methods below are wrapped to protect the non-threadsafe
210 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800211 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700212 int colorMin, int colorPref,
213 int alphaMin, int alphaPref,
214 int depthMin, int depthPref,
215 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700216 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800217 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700218 int colorMin, int colorPref,
219 int alphaMin, int alphaPref,
220 int depthMin, int depthPref,
221 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700222 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700223 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700224 alphaMin, alphaPref, depthMin, depthPref,
225 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700226 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700227 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800228 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
229 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800230 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700231 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800232 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700233 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800234 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800235
236 // take teardown lock
237 // teardown lock can only be taken when no objects are being destroyed
238 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
239 wlock.lock();
240
241 long curCon = mContext;
242 // context is considered dead as of this point
243 mContext = 0;
244
245 wlock.unlock();
246 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700247 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800248 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700249 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800250 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700251 rsnContextSetSurface(mContext, w, h, sur);
252 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800253 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700254 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
255 validate();
256 rsnContextSetSurfaceTexture(mContext, w, h, sur);
257 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800258 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700259 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800260 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700261 rsnContextSetPriority(mContext, p);
262 }
Tim Murray47f31582015-04-07 15:43:24 -0700263 native void rsnContextSetCacheDir(long con, String cacheDir);
264 synchronized void nContextSetCacheDir(String cacheDir) {
265 validate();
266 rsnContextSetCacheDir(mContext, cacheDir);
267 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800268 native void rsnContextDump(long con, int bits);
Jason Sams2e1872f2010-08-17 16:25:41 -0700269 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800270 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700271 rsnContextDump(mContext, bits);
272 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800273 native void rsnContextFinish(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700274 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800275 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700276 rsnContextFinish(mContext);
277 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700278
Tim Murrayeff663f2013-11-15 13:08:30 -0800279 native void rsnContextSendMessage(long con, int id, int[] data);
Jason Sams455d6442013-02-05 19:20:18 -0800280 synchronized void nContextSendMessage(int id, int[] data) {
281 validate();
282 rsnContextSendMessage(mContext, id, data);
283 }
284
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000285 native void rsnContextBindRootScript(long con, long script);
286 synchronized void nContextBindRootScript(long script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800287 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700288 rsnContextBindRootScript(mContext, script);
289 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800290 native void rsnContextBindSampler(long con, int sampler, int slot);
Jason Sams2e1872f2010-08-17 16:25:41 -0700291 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800292 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700293 rsnContextBindSampler(mContext, sampler, slot);
294 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000295 native void rsnContextBindProgramStore(long con, long pfs);
296 synchronized void nContextBindProgramStore(long pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800297 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700298 rsnContextBindProgramStore(mContext, pfs);
299 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000300 native void rsnContextBindProgramFragment(long con, long pf);
301 synchronized void nContextBindProgramFragment(long pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800302 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700303 rsnContextBindProgramFragment(mContext, pf);
304 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000305 native void rsnContextBindProgramVertex(long con, long pv);
306 synchronized void nContextBindProgramVertex(long pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800307 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700308 rsnContextBindProgramVertex(mContext, pv);
309 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000310 native void rsnContextBindProgramRaster(long con, long pr);
311 synchronized void nContextBindProgramRaster(long pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800312 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700313 rsnContextBindProgramRaster(mContext, pr);
314 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800315 native void rsnContextPause(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700316 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800317 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700318 rsnContextPause(mContext);
319 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800320 native void rsnContextResume(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700321 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800322 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700323 rsnContextResume(mContext);
324 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700325
Yang Ni281c3252014-10-24 08:52:24 -0700326 native long rsnClosureCreate(long con, long kernelID, long returnValue,
327 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
328 long[] depFieldIDs);
329 synchronized long nClosureCreate(long kernelID, long returnValue,
330 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
331 long[] depFieldIDs) {
332 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700333 long c = rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
Yang Ni281c3252014-10-24 08:52:24 -0700334 sizes, depClosures, depFieldIDs);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700335 if (c == 0) {
336 throw new RSRuntimeException("Failed creating closure.");
337 }
338 return c;
Yang Ni281c3252014-10-24 08:52:24 -0700339 }
340
Yang Nibe392ad2015-01-23 17:16:02 -0800341 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
342 long[] fieldIDs, long[] values, int[] sizes);
343 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
344 long[] fieldIDs, long[] values, int[] sizes) {
345 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700346 long c = rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
Yang Nibe392ad2015-01-23 17:16:02 -0800347 values, sizes);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700348 if (c == 0) {
349 throw new RSRuntimeException("Failed creating closure.");
350 }
351 return c;
Yang Nibe392ad2015-01-23 17:16:02 -0800352 }
353
Yang Ni281c3252014-10-24 08:52:24 -0700354 native void rsnClosureSetArg(long con, long closureID, int index,
355 long value, int size);
356 synchronized void nClosureSetArg(long closureID, int index, long value,
357 int size) {
358 validate();
359 rsnClosureSetArg(mContext, closureID, index, value, size);
360 }
361
362 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
363 long value, int size);
364 // Does this have to be synchronized?
365 synchronized void nClosureSetGlobal(long closureID, long fieldID,
366 long value, int size) {
367 validate(); // TODO: is this necessary?
368 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
369 }
370
Yang Ni35be56c2015-04-02 17:47:56 -0700371 native long rsnScriptGroup2Create(long con, String name, String cachePath,
372 long[] closures);
373 synchronized long nScriptGroup2Create(String name, String cachePath,
374 long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700375 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700376 long g = rsnScriptGroup2Create(mContext, name, cachePath, closures);
377 if (g == 0) {
378 throw new RSRuntimeException("Failed creating script group.");
379 }
380 return g;
Yang Ni281c3252014-10-24 08:52:24 -0700381 }
382
383 native void rsnScriptGroup2Execute(long con, long groupID);
384 synchronized void nScriptGroup2Execute(long groupID) {
385 validate();
386 rsnScriptGroup2Execute(mContext, groupID);
387 }
388
Tim Murray460a0492013-11-19 12:45:54 -0800389 native void rsnAssignName(long con, long obj, byte[] name);
390 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800391 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700392 rsnAssignName(mContext, obj, name);
393 }
Tim Murray460a0492013-11-19 12:45:54 -0800394 native String rsnGetName(long con, long obj);
395 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800396 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700397 return rsnGetName(mContext, obj);
398 }
Tim Murray06b45672014-01-07 11:13:56 -0800399
400 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800401 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800402 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800403 // There is a race condition here. The calling code may be run
404 // by the gc while teardown is occuring. This protects againts
405 // deleting dead objects.
406 if (mContext != 0) {
407 rsnObjDestroy(mContext, id);
408 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700409 }
Jason Samsfe08d992009-05-27 14:45:32 -0700410
Tim Murray460a0492013-11-19 12:45:54 -0800411 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
412 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800413 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700414 return rsnElementCreate(mContext, type, kind, norm, vecSize);
415 }
Ashok Bhat98071552014-02-12 09:54:43 +0000416 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
417 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800418 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700419 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700420 }
Tim Murray460a0492013-11-19 12:45:54 -0800421 native void rsnElementGetNativeData(long con, long id, int[] elementData);
422 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800423 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700424 rsnElementGetNativeData(mContext, id, elementData);
425 }
Tim Murray460a0492013-11-19 12:45:54 -0800426 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000427 long[] IDs, String[] names, int[] arraySizes);
428 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800429 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700430 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700431 }
Jason Sams768bc022009-09-21 19:41:04 -0700432
Tim Murray460a0492013-11-19 12:45:54 -0800433 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
434 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800435 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800436 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700437 }
Ashok Bhat98071552014-02-12 09:54:43 +0000438 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
439 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800440 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700441 rsnTypeGetNativeData(mContext, id, typeData);
442 }
Jason Sams768bc022009-09-21 19:41:04 -0700443
Ashok Bhat98071552014-02-12 09:54:43 +0000444 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
445 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800446 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800447 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700448 }
Tim Murray460a0492013-11-19 12:45:54 -0800449 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
450 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800451 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800452 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700453 }
Tim Murraya3145512012-12-04 17:59:29 -0800454
Tim Murray460a0492013-11-19 12:45:54 -0800455 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
456 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800457 validate();
458 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
459 }
460
Tim Murray460a0492013-11-19 12:45:54 -0800461 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
462 synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800463 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800464 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800465 }
Tim Murray460a0492013-11-19 12:45:54 -0800466 native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
467 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800468 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700469 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
470 }
Tim Murray460a0492013-11-19 12:45:54 -0800471 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
472 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800473 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800474 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
475 }
476
Tim Murray460a0492013-11-19 12:45:54 -0800477 native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
478 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800479 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800480 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
481 }
482
Tim Murray460a0492013-11-19 12:45:54 -0800483 native void rsnAllocationSyncAll(long con, long alloc, int src);
484 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800485 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800486 rsnAllocationSyncAll(mContext, alloc, src);
487 }
Miao Wang0facf022015-11-25 11:21:13 -0800488
489 native ByteBuffer rsnAllocationGetByteBuffer(long con, long alloc, long[] stride, int xBytesSize, int dimY, int dimZ);
490 synchronized ByteBuffer nAllocationGetByteBuffer(long alloc, long[] stride, int xBytesSize, int dimY, int dimZ) {
491 validate();
492 return rsnAllocationGetByteBuffer(mContext, alloc, stride, xBytesSize, dimY, dimZ);
493 }
494
Miao Wang8c150922015-10-26 17:44:10 -0700495 native void rsnAllocationSetupBufferQueue(long con, long alloc, int numAlloc);
496 synchronized void nAllocationSetupBufferQueue(long alloc, int numAlloc) {
497 validate();
498 rsnAllocationSetupBufferQueue(mContext, alloc, numAlloc);
499 }
500 native void rsnAllocationShareBufferQueue(long con, long alloc1, long alloc2);
501 synchronized void nAllocationShareBufferQueue(long alloc1, long alloc2) {
502 validate();
503 rsnAllocationShareBufferQueue(mContext, alloc1, alloc2);
504 }
Tim Murray460a0492013-11-19 12:45:54 -0800505 native Surface rsnAllocationGetSurface(long con, long alloc);
506 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800507 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800508 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700509 }
Tim Murray460a0492013-11-19 12:45:54 -0800510 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
511 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800512 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700513 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800514 }
Tim Murray460a0492013-11-19 12:45:54 -0800515 native void rsnAllocationIoSend(long con, long alloc);
516 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800517 validate();
518 rsnAllocationIoSend(mContext, alloc);
519 }
Miao Wang8c150922015-10-26 17:44:10 -0700520 native long rsnAllocationIoReceive(long con, long alloc);
521 synchronized long nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800522 validate();
Miao Wang8c150922015-10-26 17:44:10 -0700523 return rsnAllocationIoReceive(mContext, alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800524 }
525
Tim Murray460a0492013-11-19 12:45:54 -0800526 native void rsnAllocationGenerateMipmaps(long con, long alloc);
527 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800528 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800529 rsnAllocationGenerateMipmaps(mContext, alloc);
530 }
Tim Murray460a0492013-11-19 12:45:54 -0800531 native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
532 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800533 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800534 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700535 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700536
Jason Sams49a05d72010-12-29 14:31:29 -0800537
Miao Wang87e908d2015-03-02 15:15:15 -0800538 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
539 int mSize, boolean usePadding);
540 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
541 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800542 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800543 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700544 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700545
Miao Wangc8e237e2015-02-20 18:36:32 -0800546 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
547 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 -0800548 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800549 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700550 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700551
Tim Murrayeff663f2013-11-15 13:08:30 -0800552 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800553 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700554 int dstMip, int dstFace,
555 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800556 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700557 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800558 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700559 int dstMip, int dstFace,
560 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800561 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700562 int srcMip, int srcFace) {
563 validate();
564 rsnAllocationData2D(mContext,
565 dstAlloc, dstXoff, dstYoff,
566 dstMip, dstFace,
567 width, height,
568 srcAlloc, srcXoff, srcYoff,
569 srcMip, srcFace);
570 }
571
Tim Murray460a0492013-11-19 12:45:54 -0800572 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800573 int w, int h, Object d, int sizeBytes, int dt,
574 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800575 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800576 int w, int h, Object d, int sizeBytes, Element.DataType dt,
577 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800578 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800579 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700580 }
Jason Sams21659ac2013-11-06 15:08:07 -0800581
Tim Murray460a0492013-11-19 12:45:54 -0800582 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
583 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800584 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800585 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
586 }
Jason Sams49a05d72010-12-29 14:31:29 -0800587
Tim Murrayeff663f2013-11-15 13:08:30 -0800588 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800589 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700590 int dstMip,
591 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800592 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700593 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800594 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700595 int dstMip,
596 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800597 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700598 int srcMip) {
599 validate();
600 rsnAllocationData3D(mContext,
601 dstAlloc, dstXoff, dstYoff, dstZoff,
602 dstMip, width, height, depth,
603 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
604 }
605
Tim Murray460a0492013-11-19 12:45:54 -0800606 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800607 int w, int h, int depth, Object d, int sizeBytes, int dt,
608 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800609 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800610 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
611 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700612 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800613 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
614 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700615 }
Jason Samsb05d6892013-04-09 15:59:24 -0700616
Miao Wang87e908d2015-03-02 15:15:15 -0800617 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
618 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800619 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800620 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800621 }
Jason Sams21659ac2013-11-06 15:08:07 -0800622
Tim Murray460a0492013-11-19 12:45:54 -0800623 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800624 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800625 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800626 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800627 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800628 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800629 }
Jason Sams21659ac2013-11-06 15:08:07 -0800630
Miao Wangc8e237e2015-02-20 18:36:32 -0800631 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800632 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800633 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800634 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800635 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800636 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800637 }
638
Tim Murray460a0492013-11-19 12:45:54 -0800639 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800640 int w, int h, Object d, int sizeBytes, int dt,
641 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800642 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800643 int w, int h, Object d, int sizeBytes, Element.DataType dt,
644 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800645 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800646 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700647 }
Jason Sams21659ac2013-11-06 15:08:07 -0800648
Miao Wangc8e237e2015-02-20 18:36:32 -0800649 native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800650 int w, int h, int depth, Object d, int sizeBytes, int dt,
651 int mSize, boolean usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800652 synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800653 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
654 int mSize, boolean usePadding) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800655 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800656 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800657 }
658
Tim Murray460a0492013-11-19 12:45:54 -0800659 native long rsnAllocationGetType(long con, long id);
660 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800661 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700662 return rsnAllocationGetType(mContext, id);
663 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700664
Tim Murray460a0492013-11-19 12:45:54 -0800665 native void rsnAllocationResize1D(long con, long id, int dimX);
666 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800667 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700668 rsnAllocationResize1D(mContext, id, dimX);
669 }
Jason Sams5edc6082010-10-05 13:32:49 -0700670
Jason Sams46ba27e32015-02-06 17:45:15 -0800671 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
672 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
673 validate();
674 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
675 }
676
677 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
678 int mip, int face, int a1, int a2, int a3, int a4);
679 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
680 int mip, int face, int a1, int a2, int a3, int a4) {
681 validate();
682 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
683 }
684
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000685 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
686 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800687 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700688 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
689 }
Tim Murray460a0492013-11-19 12:45:54 -0800690 native long rsnFileA3DCreateFromFile(long con, String path);
691 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800692 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800693 return rsnFileA3DCreateFromFile(mContext, path);
694 }
Tim Murray460a0492013-11-19 12:45:54 -0800695 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
696 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800697 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800698 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
699 }
Tim Murray460a0492013-11-19 12:45:54 -0800700 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
701 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800702 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700703 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
704 }
Tim Murray460a0492013-11-19 12:45:54 -0800705 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
706 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800707 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700708 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
709 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000710 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
711 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800712 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700713 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
714 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700715
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000716 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
717 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800718 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700719 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
720 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000721 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
722 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800723 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800724 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
725 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000726 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
727 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800728 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800729 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
730 }
Jason Sams22534172009-08-04 16:58:20 -0700731
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700732
Tim Murray460a0492013-11-19 12:45:54 -0800733 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
734 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800735 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700736 rsnScriptBindAllocation(mContext, script, alloc, slot);
737 }
Tim Murray460a0492013-11-19 12:45:54 -0800738 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
739 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800740 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700741 rsnScriptSetTimeZone(mContext, script, timeZone);
742 }
Tim Murray460a0492013-11-19 12:45:54 -0800743 native void rsnScriptInvoke(long con, long id, int slot);
744 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800745 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700746 rsnScriptInvoke(mContext, id, slot);
747 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700748
749 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
750 long aout, byte[] params, int[] limits);
751
752 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
753 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700754 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700755 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700756 }
757
David Gross4a457852016-06-02 14:46:55 -0700758 native void rsnScriptReduce(long con, long id, int slot, long[] ains,
Matt Wala36eb1f72015-07-20 15:35:27 -0700759 long aout, int[] limits);
David Gross4a457852016-06-02 14:46:55 -0700760 synchronized void nScriptReduce(long id, int slot, long ains[], long aout,
Matt Wala36eb1f72015-07-20 15:35:27 -0700761 int[] limits) {
762 validate();
David Gross4a457852016-06-02 14:46:55 -0700763 rsnScriptReduce(mContext, id, slot, ains, aout, limits);
David Gross26ef7a732016-01-12 12:19:15 -0800764 }
765
Tim Murray460a0492013-11-19 12:45:54 -0800766 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
767 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800768 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700769 rsnScriptInvokeV(mContext, id, slot, params);
770 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700771
Tim Murray460a0492013-11-19 12:45:54 -0800772 native void rsnScriptSetVarI(long con, long id, int slot, int val);
773 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800774 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700775 rsnScriptSetVarI(mContext, id, slot, val);
776 }
Tim Murray460a0492013-11-19 12:45:54 -0800777 native int rsnScriptGetVarI(long con, long id, int slot);
778 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700779 validate();
780 return rsnScriptGetVarI(mContext, id, slot);
781 }
782
Tim Murray460a0492013-11-19 12:45:54 -0800783 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
784 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800785 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700786 rsnScriptSetVarJ(mContext, id, slot, val);
787 }
Tim Murray460a0492013-11-19 12:45:54 -0800788 native long rsnScriptGetVarJ(long con, long id, int slot);
789 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700790 validate();
791 return rsnScriptGetVarJ(mContext, id, slot);
792 }
793
Tim Murray460a0492013-11-19 12:45:54 -0800794 native void rsnScriptSetVarF(long con, long id, int slot, float val);
795 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800796 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700797 rsnScriptSetVarF(mContext, id, slot, val);
798 }
Tim Murray460a0492013-11-19 12:45:54 -0800799 native float rsnScriptGetVarF(long con, long id, int slot);
800 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700801 validate();
802 return rsnScriptGetVarF(mContext, id, slot);
803 }
Tim Murray460a0492013-11-19 12:45:54 -0800804 native void rsnScriptSetVarD(long con, long id, int slot, double val);
805 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800806 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700807 rsnScriptSetVarD(mContext, id, slot, val);
808 }
Tim Murray460a0492013-11-19 12:45:54 -0800809 native double rsnScriptGetVarD(long con, long id, int slot);
810 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700811 validate();
812 return rsnScriptGetVarD(mContext, id, slot);
813 }
Tim Murray460a0492013-11-19 12:45:54 -0800814 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
815 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800816 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700817 rsnScriptSetVarV(mContext, id, slot, val);
818 }
Tim Murray460a0492013-11-19 12:45:54 -0800819 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
820 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700821 validate();
822 rsnScriptGetVarV(mContext, id, slot, val);
823 }
Tim Murray460a0492013-11-19 12:45:54 -0800824 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
825 long e, int[] dims);
826 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
827 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700828 validate();
829 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
830 }
Tim Murray460a0492013-11-19 12:45:54 -0800831 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
832 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800833 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800834 rsnScriptSetVarObj(mContext, id, slot, val);
835 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700836
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000837 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700838 byte[] script, int length);
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100839 @UnsupportedAppUsage
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000840 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800841 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700842 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700843 }
Jason Samsebfb4362009-09-23 13:57:02 -0700844
Tim Murray460a0492013-11-19 12:45:54 -0800845 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
846 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700847 validate();
848 return rsnScriptIntrinsicCreate(mContext, id, eid);
849 }
850
Tim Murray460a0492013-11-19 12:45:54 -0800851 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
852 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700853 validate();
854 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
855 }
856
Yang Nibe392ad2015-01-23 17:16:02 -0800857 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
858 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
859 validate();
860 return rsnScriptInvokeIDCreate(mContext, sid, slot);
861 }
862
Tim Murray460a0492013-11-19 12:45:54 -0800863 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
864 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700865 validate();
866 return rsnScriptFieldIDCreate(mContext, sid, slot);
867 }
868
Ashok Bhat98071552014-02-12 09:54:43 +0000869 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
870 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700871 validate();
872 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
873 }
874
Tim Murray460a0492013-11-19 12:45:54 -0800875 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
876 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700877 validate();
878 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
879 }
880
Tim Murray460a0492013-11-19 12:45:54 -0800881 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
882 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700883 validate();
884 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
885 }
886
Tim Murray460a0492013-11-19 12:45:54 -0800887 native void rsnScriptGroupExecute(long con, long group);
888 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700889 validate();
890 rsnScriptGroupExecute(mContext, group);
891 }
892
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000893 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700894 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000895 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700896 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800897 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700898 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700899 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800900
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000901 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700902 boolean depthMask, boolean dither,
903 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000904 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700905 boolean depthMask, boolean dither,
906 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800907 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700908 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
909 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700910 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700911
Tim Murray460a0492013-11-19 12:45:54 -0800912 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
913 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800914 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700915 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700916 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700917
Tim Murray460a0492013-11-19 12:45:54 -0800918 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
919 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800920 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700921 rsnProgramBindConstants(mContext, pv, slot, mID);
922 }
Tim Murray460a0492013-11-19 12:45:54 -0800923 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
924 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800925 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700926 rsnProgramBindTexture(mContext, vpf, slot, a);
927 }
Tim Murray460a0492013-11-19 12:45:54 -0800928 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
929 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800930 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700931 rsnProgramBindSampler(mContext, vpf, slot, s);
932 }
Ashok Bhat98071552014-02-12 09:54:43 +0000933 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
934 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800935 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800936 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700937 }
Ashok Bhat98071552014-02-12 09:54:43 +0000938 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
939 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800940 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800941 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700942 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700943
Ashok Bhat98071552014-02-12 09:54:43 +0000944 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
945 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800946 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700947 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800948 }
Tim Murray460a0492013-11-19 12:45:54 -0800949 native int rsnMeshGetVertexBufferCount(long con, long id);
950 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800951 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700952 return rsnMeshGetVertexBufferCount(mContext, id);
953 }
Tim Murray460a0492013-11-19 12:45:54 -0800954 native int rsnMeshGetIndexCount(long con, long id);
955 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800956 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700957 return rsnMeshGetIndexCount(mContext, id);
958 }
Ashok Bhat98071552014-02-12 09:54:43 +0000959 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
960 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800961 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700962 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
963 }
Ashok Bhat98071552014-02-12 09:54:43 +0000964 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
965 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800966 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700967 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
968 }
969
Tim Murray25207df2015-01-12 16:47:56 -0800970 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
971 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
972 float alpha, long A, long B, float beta, long C, int incX, int incY,
973 int KL, int KU);
974 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
975 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
976 float alpha, long A, long B, float beta, long C, int incX, int incY,
977 int KL, int KU) {
978 validate();
979 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
980 }
981
982 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
983 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
984 double alpha, long A, long B, double beta, long C, int incX, int incY,
985 int KL, int KU);
986 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
987 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
988 double alpha, long A, long B, double beta, long C, int incX, int incY,
989 int KL, int KU) {
990 validate();
991 rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
992 }
993
994 native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA,
995 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
996 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
997 int KL, int KU);
998 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
999 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
1000 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
1001 int KL, int KU) {
1002 validate();
1003 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
1004 }
1005
1006 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
1007 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
1008 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
1009 int KL, int KU);
1010 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
1011 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
1012 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
1013 int KL, int KU) {
1014 validate();
1015 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
1016 }
1017
Tim Murray9cb16a22015-04-01 11:07:16 -07001018 native void rsnScriptIntrinsicBLAS_BNNM(long con, long id, int M, int N, int K,
1019 long A, int a_offset, long B, int b_offset, long C, int c_offset,
1020 int c_mult_int);
1021 synchronized void nScriptIntrinsicBLAS_BNNM(long id, int M, int N, int K,
1022 long A, int a_offset, long B, int b_offset, long C, int c_offset,
1023 int c_mult_int) {
1024 validate();
1025 rsnScriptIntrinsicBLAS_BNNM(mContext, id, M, N, K, A, a_offset, B, b_offset, C, c_offset, c_mult_int);
1026 }
1027
1028
Tim Murray25207df2015-01-12 16:47:56 -08001029
Tim Murrayeff663f2013-11-15 13:08:30 -08001030 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -08001031 private boolean mDestroyed = false;
1032
Romain Guy650a3eb2009-08-31 14:06:43 -07001033 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001034 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001035
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001036 volatile Element mElement_U8;
1037 volatile Element mElement_I8;
1038 volatile Element mElement_U16;
1039 volatile Element mElement_I16;
1040 volatile Element mElement_U32;
1041 volatile Element mElement_I32;
1042 volatile Element mElement_U64;
1043 volatile Element mElement_I64;
1044 volatile Element mElement_F16;
1045 volatile Element mElement_F32;
1046 volatile Element mElement_F64;
1047 volatile Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -07001048
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001049 volatile Element mElement_ELEMENT;
1050 volatile Element mElement_TYPE;
1051 volatile Element mElement_ALLOCATION;
1052 volatile Element mElement_SAMPLER;
1053 volatile Element mElement_SCRIPT;
1054 volatile Element mElement_MESH;
1055 volatile Element mElement_PROGRAM_FRAGMENT;
1056 volatile Element mElement_PROGRAM_VERTEX;
1057 volatile Element mElement_PROGRAM_RASTER;
1058 volatile Element mElement_PROGRAM_STORE;
1059 volatile Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -07001060
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001061 volatile Element mElement_A_8;
1062 volatile Element mElement_RGB_565;
1063 volatile Element mElement_RGB_888;
1064 volatile Element mElement_RGBA_5551;
1065 volatile Element mElement_RGBA_4444;
1066 volatile Element mElement_RGBA_8888;
Jason Sams3c0dfba2009-09-27 17:50:38 -07001067
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001068 volatile Element mElement_HALF_2;
1069 volatile Element mElement_HALF_3;
1070 volatile Element mElement_HALF_4;
Jason Samsa5835a22014-11-05 15:16:26 -08001071
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001072 volatile Element mElement_FLOAT_2;
1073 volatile Element mElement_FLOAT_3;
1074 volatile Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001075
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001076 volatile Element mElement_DOUBLE_2;
1077 volatile Element mElement_DOUBLE_3;
1078 volatile Element mElement_DOUBLE_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001079
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001080 volatile Element mElement_UCHAR_2;
1081 volatile Element mElement_UCHAR_3;
1082 volatile Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001083
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001084 volatile Element mElement_CHAR_2;
1085 volatile Element mElement_CHAR_3;
1086 volatile Element mElement_CHAR_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001087
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001088 volatile Element mElement_USHORT_2;
1089 volatile Element mElement_USHORT_3;
1090 volatile Element mElement_USHORT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001091
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001092 volatile Element mElement_SHORT_2;
1093 volatile Element mElement_SHORT_3;
1094 volatile Element mElement_SHORT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001095
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001096 volatile Element mElement_UINT_2;
1097 volatile Element mElement_UINT_3;
1098 volatile Element mElement_UINT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001099
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001100 volatile Element mElement_INT_2;
1101 volatile Element mElement_INT_3;
1102 volatile Element mElement_INT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001103
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001104 volatile Element mElement_ULONG_2;
1105 volatile Element mElement_ULONG_3;
1106 volatile Element mElement_ULONG_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001107
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001108 volatile Element mElement_LONG_2;
1109 volatile Element mElement_LONG_3;
1110 volatile Element mElement_LONG_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001111
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001112 volatile Element mElement_YUV;
Tim Murray932e78e2013-09-03 11:42:26 -07001113
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001114 volatile Element mElement_MATRIX_4X4;
1115 volatile Element mElement_MATRIX_3X3;
1116 volatile Element mElement_MATRIX_2X2;
Jason Sams1d45c472010-08-25 14:31:48 -07001117
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001118 volatile Sampler mSampler_CLAMP_NEAREST;
1119 volatile Sampler mSampler_CLAMP_LINEAR;
1120 volatile Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1121 volatile Sampler mSampler_WRAP_NEAREST;
1122 volatile Sampler mSampler_WRAP_LINEAR;
1123 volatile Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
1124 volatile Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1125 volatile Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1126 volatile Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001127
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001128 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1129 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001130 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1131 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001132
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001133 ProgramRaster mProgramRaster_CULL_BACK;
1134 ProgramRaster mProgramRaster_CULL_FRONT;
1135 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001136
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001137 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001138 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001139
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001140 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001141 * The base class from which an application should derive in order
1142 * to receive RS messages from scripts. When a script calls {@code
1143 * rsSendToClient}, the data fields will be filled, and the run
1144 * method will be called on a separate thread. This will occur
1145 * some time after {@code rsSendToClient} completes in the script,
1146 * as {@code rsSendToClient} is asynchronous. Message handlers are
1147 * not guaranteed to have completed when {@link
1148 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001149 *
1150 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001151 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001152 protected int[] mData;
1153 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001154 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001155 public void run() {
1156 }
1157 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001158 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001159 * If an application is expecting messages, it should set this
1160 * field to an instance of {@link RSMessageHandler}. This
1161 * instance will receive all the user messages sent from {@code
1162 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001163 *
1164 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +01001165 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001166 RSMessageHandler mMessageCallback = null;
1167
1168 public void setMessageHandler(RSMessageHandler msg) {
1169 mMessageCallback = msg;
1170 }
1171 public RSMessageHandler getMessageHandler() {
1172 return mMessageCallback;
1173 }
Jason Sams516c3192009-10-06 13:58:47 -07001174
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001175 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001176 * Place a message into the message queue to be sent back to the message
1177 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001178 *
1179 * @param id
1180 * @param data
1181 */
1182 public void sendMessage(int id, int[] data) {
1183 nContextSendMessage(id, data);
1184 }
1185
1186 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001187 * The runtime error handler base class. An application should derive from this class
1188 * if it wishes to install an error handler. When errors occur at runtime,
1189 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001190 *
1191 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001192 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001193 protected String mErrorMessage;
1194 protected int mErrorNum;
1195 public void run() {
1196 }
1197 }
Jason Sams27676fe2010-11-10 17:00:59 -08001198
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001199 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001200 * Application Error handler. All runtime errors will be dispatched to the
1201 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001202 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001203 * This will cause program termaination.
1204 *
1205 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001206 RSErrorHandler mErrorCallback = null;
1207
1208 public void setErrorHandler(RSErrorHandler msg) {
1209 mErrorCallback = msg;
1210 }
1211 public RSErrorHandler getErrorHandler() {
1212 return mErrorCallback;
1213 }
Jason Sams1c415172010-11-08 17:06:46 -08001214
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001215 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001216 * RenderScript worker thread priority enumeration. The default value is
1217 * NORMAL. Applications wishing to do background processing should set
1218 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001219 */
Jason Sams7d787b42009-11-15 12:14:26 -08001220 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001221 // These values used to represent official thread priority values
1222 // now they are simply enums to be used by the runtime side
1223 LOW (15),
1224 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001225
1226 int mID;
1227 Priority(int id) {
1228 mID = id;
1229 }
1230 }
1231
Jason Sams678cc7f2014-03-05 16:09:02 -08001232 void validateObject(BaseObj o) {
1233 if (o != null) {
1234 if (o.mRS != this) {
1235 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1236 }
1237 }
1238 }
1239
Mathew Inwoodf0c90b12018-08-01 10:05:11 +01001240 @UnsupportedAppUsage
Jason Sams771bebb2009-12-07 12:40:12 -08001241 void validate() {
1242 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001243 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001244 }
1245 }
1246
Jason Sams27676fe2010-11-10 17:00:59 -08001247
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001248 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001249 * Change the priority of the worker threads for this context.
1250 *
1251 * @param p New priority to be set.
1252 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001253 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001254 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001255 nContextSetPriority(p.mID);
1256 }
1257
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001258 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001259 RenderScript mRS;
1260 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001261 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001262
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001263 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1264 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1265 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1266 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1267 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001268 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001269
Stephen Hines42028a82013-04-17 19:22:01 -07001270 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001271 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001272
Jason Sams516c3192009-10-06 13:58:47 -07001273 MessageThread(RenderScript rs) {
1274 super("RSMessageThread");
1275 mRS = rs;
1276
1277 }
1278
1279 public void run() {
1280 // This function is a temporary solution. The final solution will
1281 // used typed allocations where the message id is the type indicator.
1282 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001283 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001284 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001285 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001286 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001287 int size = mAuxData[1];
1288 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001289
1290 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1291 if ((size>>2) >= rbuf.length) {
1292 rbuf = new int[(size + 3) >> 2];
1293 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001294 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1295 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001296 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001297 }
Jason Sams1c415172010-11-08 17:06:46 -08001298
1299 if(mRS.mMessageCallback != null) {
1300 mRS.mMessageCallback.mData = rbuf;
1301 mRS.mMessageCallback.mID = subID;
1302 mRS.mMessageCallback.mLength = size;
1303 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001304 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001305 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001306 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001307 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001308 }
Jason Sams1c415172010-11-08 17:06:46 -08001309
1310 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1311 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1312
Stephen Hines42028a82013-04-17 19:22:01 -07001313 // Throw RSRuntimeException under the following conditions:
1314 //
1315 // 1) It is an unknown fatal error.
1316 // 2) It is a debug fatal error, and we are not in a
1317 // debug context.
1318 // 3) It is a debug fatal error, and we do not have an
1319 // error callback.
1320 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1321 (subID >= RS_ERROR_FATAL_DEBUG &&
1322 (mRS.mContextType != ContextType.DEBUG ||
1323 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001324 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1325 }
1326
Jason Sams1c415172010-11-08 17:06:46 -08001327 if(mRS.mErrorCallback != null) {
1328 mRS.mErrorCallback.mErrorMessage = e;
1329 mRS.mErrorCallback.mErrorNum = subID;
1330 mRS.mErrorCallback.run();
1331 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001332 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001333 // Do not throw here. In these cases, we do not have
1334 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001335 }
1336 continue;
1337 }
1338
Jason Sams739c8262013-04-11 18:07:52 -07001339 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001340 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1341 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1342 throw new RSDriverException("Error processing message from RenderScript.");
1343 }
1344 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1345 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001346 continue;
1347 }
1348
Jason Sams1c415172010-11-08 17:06:46 -08001349 // 2: teardown.
1350 // But we want to avoid starving other threads during
1351 // teardown by yielding until the next line in the destructor
1352 // can execute to set mRun = false
1353 try {
1354 sleep(1, 0);
1355 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001356 }
Jason Sams516c3192009-10-06 13:58:47 -07001357 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001358 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001359 }
1360 }
1361
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001362 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001363 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001364 if (ctx != null) {
1365 mApplicationContext = ctx.getApplicationContext();
1366 }
Tim Murray06b45672014-01-07 11:13:56 -08001367 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001368 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001369 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001370 } catch (Exception e) {
1371 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1372 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1373 }
1374
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001375 }
1376
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001377 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001378 * Gets the application context associated with the RenderScript context.
1379 *
1380 * @return The application context.
1381 */
1382 public final Context getApplicationContext() {
1383 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001384 }
1385
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001386 /**
Yang Ni689f6372016-03-10 16:12:31 -08001387 * Name of the file that holds the object cache.
1388 */
1389 private static String mCachePath;
1390
1391 /**
1392 * Gets the path to the code cache.
1393 */
1394 static synchronized String getCachePath() {
1395 if (mCachePath == null) {
1396 final String CACHE_PATH = "com.android.renderscript.cache";
1397 if (RenderScriptCacheDir.mCacheDir == null) {
1398 throw new RSRuntimeException("RenderScript code cache directory uninitialized.");
1399 }
1400 File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
1401 mCachePath = f.getAbsolutePath();
1402 f.mkdirs();
1403 }
1404 return mCachePath;
1405 }
1406
1407 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001408 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001409 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001410 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001411 * @return RenderScript
1412 */
Jason Samse16da122015-03-18 17:04:18 -07001413 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001414 if (!sInitialized) {
1415 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1416 return null;
1417 }
1418
verena beckhamc9659ea2015-05-22 16:47:53 +01001419 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER |
Stephen McGroarty88891e62015-09-02 15:54:05 +01001420 CREATE_FLAG_WAIT_FOR_ATTACH)) != 0) {
Jason Samsb69c7912014-05-20 18:48:35 -07001421 throw new RSIllegalArgumentException("Invalid flags passed.");
1422 }
1423
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001424 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001425
Yang Nicb939dc2016-04-04 10:23:57 -07001426 long device = rs.nDeviceCreate();
1427 rs.mContext = rs.nContextCreate(device, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001428 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001429 rs.mContextFlags = flags;
1430 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001431 if (rs.mContext == 0) {
1432 throw new RSDriverException("Failed to create RS context.");
1433 }
Tim Murray47f31582015-04-07 15:43:24 -07001434
1435 // set up cache directory for entire context
Yang Ni689f6372016-03-10 16:12:31 -08001436 rs.nContextSetCacheDir(RenderScript.getCachePath());
Tim Murray47f31582015-04-07 15:43:24 -07001437
Jason Sams704ff642010-02-09 16:05:07 -08001438 rs.mMessageThread = new MessageThread(rs);
1439 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001440 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001441 }
1442
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001443 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001444 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001445 *
1446 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001447 *
1448 * @param ctx The context.
1449 * @return RenderScript
1450 */
1451 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001452 return create(ctx, ContextType.NORMAL);
1453 }
1454
1455 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001456 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001457 *
Jason Samse16da122015-03-18 17:04:18 -07001458 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001459 *
1460 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001461 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001462 * @return RenderScript
1463 */
1464 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001465 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001466 }
1467
Miao Wanga4e5adf2015-03-23 11:09:56 -07001468
1469 /**
Jason Samse16da122015-03-18 17:04:18 -07001470 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001471 *
Jason Samse16da122015-03-18 17:04:18 -07001472 * The returned context will be cached for future reuse within
1473 * the process. When an application is finished using
1474 * RenderScript it should call releaseAllContexts()
1475 *
1476 * A process context is a context designed for easy creation and
1477 * lifecycle management. Multiple calls to this function will
1478 * return the same object provided they are called with the same
1479 * options. This allows it to be used any time a RenderScript
1480 * context is needed.
1481 *
1482 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001483 *
1484 * @param ctx The context.
1485 * @param ct The type of context to be created.
1486 * @param flags The OR of the CREATE_FLAG_* options desired
1487 * @return RenderScript
1488 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001489 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001490 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001491 return create(ctx, v, ct, flags);
1492 }
1493
1494 /**
1495 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1496 *
1497 * Used by the RenderScriptThunker to maintain backward compatibility.
1498 *
1499 * @hide
1500 * @param ctx The context.
1501 * @param sdkVersion The target SDK Version.
1502 * @return RenderScript
1503 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +01001504 @UnsupportedAppUsage
Miao Wanga4e5adf2015-03-23 11:09:56 -07001505 public static RenderScript create(Context ctx, int sdkVersion) {
1506 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1507 }
1508
1509 /**
1510 * Gets or creates a RenderScript context of the specified type.
1511 *
Miao Wanga4e5adf2015-03-23 11:09:56 -07001512 * @param ctx The context.
1513 * @param ct The type of context to be created.
1514 * @param sdkVersion The target SDK Version.
1515 * @param flags The OR of the CREATE_FLAG_* options desired
1516 * @return RenderScript
1517 */
Mathew Inwoodf0c90b12018-08-01 10:05:11 +01001518 @UnsupportedAppUsage
Jason Sams6a420b52015-03-30 15:31:26 -07001519 private static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
Miao Wanga4e5adf2015-03-23 11:09:56 -07001520 if (sdkVersion < 23) {
1521 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001522 }
1523
1524 synchronized (mProcessContextList) {
1525 for (RenderScript prs : mProcessContextList) {
1526 if ((prs.mContextType == ct) &&
1527 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001528 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001529
1530 return prs;
1531 }
1532 }
1533
Miao Wanga4e5adf2015-03-23 11:09:56 -07001534 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001535 prs.mIsProcessContext = true;
1536 mProcessContextList.add(prs);
1537 return prs;
1538 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001539 }
1540
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001541 /**
Jason Samse16da122015-03-18 17:04:18 -07001542 * Releases all the process contexts. This is the same as
1543 * calling .destroy() on each unique context retreived with
1544 * create(...). If no contexts have been created this
1545 * function does nothing.
1546 *
1547 * Typically you call this when your application is losing focus
1548 * and will not be using a context for some time.
1549 *
1550 * This has no effect on a context created with
1551 * createMultiContext()
1552 */
1553 public static void releaseAllContexts() {
1554 ArrayList<RenderScript> oldList;
1555 synchronized (mProcessContextList) {
1556 oldList = mProcessContextList;
1557 mProcessContextList = new ArrayList<RenderScript>();
1558 }
1559
1560 for (RenderScript prs : oldList) {
1561 prs.mIsProcessContext = false;
1562 prs.destroy();
1563 }
1564 oldList.clear();
1565 }
1566
1567
1568
1569 /**
1570 * Create a RenderScript context.
1571 *
1572 * This is an advanced function intended for applications which
1573 * need to create more than one RenderScript context to be used
1574 * at the same time.
1575 *
1576 * If you need a single context please use create()
1577 *
Jason Samse16da122015-03-18 17:04:18 -07001578 * @param ctx The context.
1579 * @return RenderScript
1580 */
1581 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1582 return internalCreate(ctx, API_number, ct, flags);
1583 }
1584
1585
1586 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001587 * Print the currently available debugging information about the state of
1588 * the RS context to the log.
1589 *
Jason Sams27676fe2010-11-10 17:00:59 -08001590 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001591 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001592 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001593 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001594 }
1595
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001596 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001597 * Wait for any pending asynchronous opeations (such as copies to a RS
1598 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001599 *
1600 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001601 public void finish() {
1602 nContextFinish();
1603 }
1604
Jason Samsd22a6f02015-02-19 17:19:52 -08001605 private void helpDestroy() {
1606 boolean shouldDestroy = false;
1607 synchronized(this) {
1608 if (!mDestroyed) {
1609 shouldDestroy = true;
1610 mDestroyed = true;
1611 }
1612 }
1613
1614 if (shouldDestroy) {
1615 nContextFinish();
1616
1617 nContextDeinitToClient(mContext);
1618 mMessageThread.mRun = false;
Miao Wang4a574802016-05-10 16:44:11 -07001619 // Interrupt mMessageThread so it gets to see immediately that mRun is false
1620 // and exit rightaway.
1621 mMessageThread.interrupt();
Pirama Arumuga Nainar2f25ce772015-10-02 12:06:10 -07001622
1623 // Wait for mMessageThread to join. Try in a loop, in case this thread gets interrupted
Pirama Arumuga Nainar83461d72015-10-02 16:38:08 -07001624 // during the wait. If interrupted, set the "interrupted" status of the current thread.
1625 boolean hasJoined = false, interrupted = false;
Pirama Arumuga Nainar2f25ce772015-10-02 12:06:10 -07001626 while (!hasJoined) {
1627 try {
1628 mMessageThread.join();
1629 hasJoined = true;
Pirama Arumuga Nainar83461d72015-10-02 16:38:08 -07001630 } catch (InterruptedException e) {
1631 interrupted = true;
Pirama Arumuga Nainar2f25ce772015-10-02 12:06:10 -07001632 }
Jason Samsd22a6f02015-02-19 17:19:52 -08001633 }
Pirama Arumuga Nainar83461d72015-10-02 16:38:08 -07001634 if (interrupted) {
1635 Log.v(LOG_TAG, "Interrupted during wait for MessageThread to join");
1636 Thread.currentThread().interrupt();
1637 }
Jason Samsd22a6f02015-02-19 17:19:52 -08001638
1639 nContextDestroy();
Jason Samsd22a6f02015-02-19 17:19:52 -08001640 }
1641 }
1642
1643 protected void finalize() throws Throwable {
1644 helpDestroy();
1645 super.finalize();
1646 }
1647
1648
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001649 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001650 * Destroys this RenderScript context. Once this function is called,
1651 * using this context or any objects belonging to this context is
1652 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001653 *
Jason Samse16da122015-03-18 17:04:18 -07001654 * API 23+, this function is a NOP if the context was created
1655 * with create(). Please use releaseAllContexts() to clean up
1656 * contexts created with the create function.
1657 *
Jason Sams27676fe2010-11-10 17:00:59 -08001658 */
Jason Samsf5b45962009-08-25 14:49:07 -07001659 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001660 if (mIsProcessContext) {
1661 // users cannot destroy a process context
1662 return;
1663 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001664 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001665 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001666 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001667
Jason Samsa9e7a052009-09-25 14:51:22 -07001668 boolean isAlive() {
1669 return mContext != 0;
1670 }
1671
Tim Murray460a0492013-11-19 12:45:54 -08001672 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001673 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001674 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001675 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001676 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001677 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001678}