blob: f4c27771c846d3c60a075fdbc869e0fdeea0f0b7 [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
Austin Wanga63a2c02019-12-19 06:38:19 +000019import android.annotation.UnsupportedAppUsage;
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080020import android.content.Context;
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080021import android.content.res.AssetManager;
Jason Samsb8c5a842009-07-31 20:40:47 -070022import android.graphics.Bitmap;
Jason Samsfaa32b32011-06-20 16:58:04 -070023import android.graphics.SurfaceTexture;
Dan Morrille4d9a012013-03-28 18:10:43 -070024import android.os.SystemProperties;
Tim Murray6d7a53c2013-05-23 16:59:23 -070025import android.os.Trace;
Miao Wang0facf022015-11-25 11:21:13 -080026import android.util.Log;
27import android.view.Surface;
Stephen Hines4382467a2011-08-01 15:02:34 -070028
Hans Boehmda3cee62019-02-11 11:01:03 -080029import java.io.File;
30import java.lang.reflect.Method;
31import java.nio.ByteBuffer;
32import java.util.ArrayList;
33import java.util.concurrent.locks.ReentrantReadWriteLock;
34
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 Inwood15324472018-08-06 11:18:49 +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);
Hans Boehmda3cee62019-02-11 11:01:03 -0800117 registerNativeAllocation =
118 vm_runtime.getDeclaredMethod("registerNativeAllocation", Long.TYPE);
119 registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Long.TYPE);
Tim Murray2f2472c2013-08-22 14:55:26 -0700120 } catch (Exception e) {
121 Log.e(LOG_TAG, "Error loading GC methods: " + e);
122 throw new RSRuntimeException("Error loading GC methods: " + e);
123 }
124 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700125 System.loadLibrary("rs_jni");
126 _nInit();
127 sInitialized = true;
Tim Murray56f9e6f2014-05-16 11:47:26 -0700128 sPointerSize = rsnSystemGetPointerSize();
Dan Morrille4d9a012013-03-28 18:10:43 -0700129 } catch (UnsatisfiedLinkError e) {
130 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
131 throw new RSRuntimeException("Error loading RS jni library: " + e);
132 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700133 }
134 }
135
Jason Sams2e1872f2010-08-17 16:25:41 -0700136 // Non-threadsafe functions.
Tim Murrayeff663f2013-11-15 13:08:30 -0800137 native long nDeviceCreate();
138 native void nDeviceDestroy(long dev);
139 native void nDeviceSetConfig(long dev, int param, int value);
140 native int nContextGetUserMessage(long con, int[] data);
141 native String nContextGetErrorMessage(long con);
142 native int nContextPeekMessage(long con, int[] subID);
143 native void nContextInitToClient(long con);
144 native void nContextDeinitToClient(long con);
Jason Sams3eaa3382009-06-10 15:04:38 -0700145
Tim Murray67cc2d02014-02-06 16:39:38 -0800146 // this should be a monotonically increasing ID
147 // used in conjunction with the API version of a device
Jason Samsf7642302015-05-12 14:06:56 -0700148 static final long sMinorVersion = 1;
Tim Murray67cc2d02014-02-06 16:39:38 -0800149
150 /**
Miao Wangf9d518a2015-05-14 14:53:30 -0700151 * @hide
152 *
153 * Only exist to be compatible with old version RenderScript Support lib.
154 * Will eventually be removed.
155 *
156 * @return Always return 1
157 *
158 */
Mathew Inwood15324472018-08-06 11:18:49 +0100159 @UnsupportedAppUsage
Miao Wangf9d518a2015-05-14 14:53:30 -0700160 public static long getMinorID() {
161 return 1;
162 }
163
164
165 /**
Tim Murray67cc2d02014-02-06 16:39:38 -0800166 * Returns an identifier that can be used to identify a particular
167 * minor version of RS.
168 *
Jason Sams6a420b52015-03-30 15:31:26 -0700169 * @return The minor RenderScript version number
170 *
Tim Murray67cc2d02014-02-06 16:39:38 -0800171 */
Jason Samsf7642302015-05-12 14:06:56 -0700172 public static long getMinorVersion() {
173 return sMinorVersion;
Tim Murray67cc2d02014-02-06 16:39:38 -0800174 }
175
Jason Sams02d56d92013-04-12 16:40:50 -0700176 /**
177 * ContextType specifies the specific type of context to be created.
178 *
179 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800180 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700181 /**
182 * NORMAL context, this is the default and what shipping apps should
183 * use.
184 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800185 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700186
187 /**
188 * DEBUG context, perform extra runtime checks to validate the
189 * kernels and APIs are being used as intended. Get and SetElementAt
190 * will be bounds checked in this mode.
191 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800192 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700193
194 /**
195 * PROFILE context, Intended to be used once the first time an
196 * application is run on a new device. This mode allows the runtime to
197 * do additional testing and performance tuning.
198 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800199 PROFILE (2);
200
201 int mID;
202 ContextType(int id) {
203 mID = id;
204 }
205 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800206
Stephen Hines42028a82013-04-17 19:22:01 -0700207 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800208 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700209
Jason Sams2e1872f2010-08-17 16:25:41 -0700210 // Methods below are wrapped to protect the non-threadsafe
211 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800212 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700213 int colorMin, int colorPref,
214 int alphaMin, int alphaPref,
215 int depthMin, int depthPref,
216 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700217 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800218 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700219 int colorMin, int colorPref,
220 int alphaMin, int alphaPref,
221 int depthMin, int depthPref,
222 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700223 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700224 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700225 alphaMin, alphaPref, depthMin, depthPref,
226 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700227 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700228 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800229 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
230 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800231 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700232 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800233 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700234 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800235 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800236
237 // take teardown lock
238 // teardown lock can only be taken when no objects are being destroyed
239 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
240 wlock.lock();
241
242 long curCon = mContext;
243 // context is considered dead as of this point
244 mContext = 0;
245
246 wlock.unlock();
247 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700248 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800249 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700250 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800251 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700252 rsnContextSetSurface(mContext, w, h, sur);
253 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800254 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700255 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
256 validate();
257 rsnContextSetSurfaceTexture(mContext, w, h, sur);
258 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800259 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700260 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800261 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700262 rsnContextSetPriority(mContext, p);
263 }
Tim Murray47f31582015-04-07 15:43:24 -0700264 native void rsnContextSetCacheDir(long con, String cacheDir);
265 synchronized void nContextSetCacheDir(String cacheDir) {
266 validate();
267 rsnContextSetCacheDir(mContext, cacheDir);
268 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800269 native void rsnContextDump(long con, int bits);
Jason Sams2e1872f2010-08-17 16:25:41 -0700270 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800271 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700272 rsnContextDump(mContext, bits);
273 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800274 native void rsnContextFinish(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700275 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800276 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700277 rsnContextFinish(mContext);
278 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700279
Tim Murrayeff663f2013-11-15 13:08:30 -0800280 native void rsnContextSendMessage(long con, int id, int[] data);
Jason Sams455d6442013-02-05 19:20:18 -0800281 synchronized void nContextSendMessage(int id, int[] data) {
282 validate();
283 rsnContextSendMessage(mContext, id, data);
284 }
285
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000286 native void rsnContextBindRootScript(long con, long script);
287 synchronized void nContextBindRootScript(long script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800288 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700289 rsnContextBindRootScript(mContext, script);
290 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800291 native void rsnContextBindSampler(long con, int sampler, int slot);
Jason Sams2e1872f2010-08-17 16:25:41 -0700292 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800293 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700294 rsnContextBindSampler(mContext, sampler, slot);
295 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000296 native void rsnContextBindProgramStore(long con, long pfs);
297 synchronized void nContextBindProgramStore(long pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800298 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700299 rsnContextBindProgramStore(mContext, pfs);
300 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000301 native void rsnContextBindProgramFragment(long con, long pf);
302 synchronized void nContextBindProgramFragment(long pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800303 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700304 rsnContextBindProgramFragment(mContext, pf);
305 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000306 native void rsnContextBindProgramVertex(long con, long pv);
307 synchronized void nContextBindProgramVertex(long pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800308 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700309 rsnContextBindProgramVertex(mContext, pv);
310 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000311 native void rsnContextBindProgramRaster(long con, long pr);
312 synchronized void nContextBindProgramRaster(long pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800313 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700314 rsnContextBindProgramRaster(mContext, pr);
315 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800316 native void rsnContextPause(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700317 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800318 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700319 rsnContextPause(mContext);
320 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800321 native void rsnContextResume(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700322 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800323 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700324 rsnContextResume(mContext);
325 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700326
Yang Ni281c3252014-10-24 08:52:24 -0700327 native long rsnClosureCreate(long con, long kernelID, long returnValue,
328 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
329 long[] depFieldIDs);
330 synchronized long nClosureCreate(long kernelID, long returnValue,
331 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
332 long[] depFieldIDs) {
333 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700334 long c = rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
Yang Ni281c3252014-10-24 08:52:24 -0700335 sizes, depClosures, depFieldIDs);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700336 if (c == 0) {
337 throw new RSRuntimeException("Failed creating closure.");
338 }
339 return c;
Yang Ni281c3252014-10-24 08:52:24 -0700340 }
341
Yang Nibe392ad2015-01-23 17:16:02 -0800342 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
343 long[] fieldIDs, long[] values, int[] sizes);
344 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
345 long[] fieldIDs, long[] values, int[] sizes) {
346 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700347 long c = rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
Yang Nibe392ad2015-01-23 17:16:02 -0800348 values, sizes);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700349 if (c == 0) {
350 throw new RSRuntimeException("Failed creating closure.");
351 }
352 return c;
Yang Nibe392ad2015-01-23 17:16:02 -0800353 }
354
Yang Ni281c3252014-10-24 08:52:24 -0700355 native void rsnClosureSetArg(long con, long closureID, int index,
356 long value, int size);
357 synchronized void nClosureSetArg(long closureID, int index, long value,
358 int size) {
359 validate();
360 rsnClosureSetArg(mContext, closureID, index, value, size);
361 }
362
363 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
364 long value, int size);
365 // Does this have to be synchronized?
366 synchronized void nClosureSetGlobal(long closureID, long fieldID,
367 long value, int size) {
368 validate(); // TODO: is this necessary?
369 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
370 }
371
Yang Ni35be56c2015-04-02 17:47:56 -0700372 native long rsnScriptGroup2Create(long con, String name, String cachePath,
373 long[] closures);
374 synchronized long nScriptGroup2Create(String name, String cachePath,
375 long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700376 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700377 long g = rsnScriptGroup2Create(mContext, name, cachePath, closures);
378 if (g == 0) {
379 throw new RSRuntimeException("Failed creating script group.");
380 }
381 return g;
Yang Ni281c3252014-10-24 08:52:24 -0700382 }
383
384 native void rsnScriptGroup2Execute(long con, long groupID);
385 synchronized void nScriptGroup2Execute(long groupID) {
386 validate();
387 rsnScriptGroup2Execute(mContext, groupID);
388 }
389
Tim Murray460a0492013-11-19 12:45:54 -0800390 native void rsnAssignName(long con, long obj, byte[] name);
391 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800392 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700393 rsnAssignName(mContext, obj, name);
394 }
Tim Murray460a0492013-11-19 12:45:54 -0800395 native String rsnGetName(long con, long obj);
396 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800397 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700398 return rsnGetName(mContext, obj);
399 }
Tim Murray06b45672014-01-07 11:13:56 -0800400
401 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800402 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800403 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800404 // There is a race condition here. The calling code may be run
405 // by the gc while teardown is occuring. This protects againts
406 // deleting dead objects.
407 if (mContext != 0) {
408 rsnObjDestroy(mContext, id);
409 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700410 }
Jason Samsfe08d992009-05-27 14:45:32 -0700411
Tim Murray460a0492013-11-19 12:45:54 -0800412 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
413 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800414 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700415 return rsnElementCreate(mContext, type, kind, norm, vecSize);
416 }
Ashok Bhat98071552014-02-12 09:54:43 +0000417 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
418 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800419 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700420 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700421 }
Tim Murray460a0492013-11-19 12:45:54 -0800422 native void rsnElementGetNativeData(long con, long id, int[] elementData);
423 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800424 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700425 rsnElementGetNativeData(mContext, id, elementData);
426 }
Tim Murray460a0492013-11-19 12:45:54 -0800427 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000428 long[] IDs, String[] names, int[] arraySizes);
429 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800430 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700431 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700432 }
Jason Sams768bc022009-09-21 19:41:04 -0700433
Tim Murray460a0492013-11-19 12:45:54 -0800434 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
435 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800436 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800437 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700438 }
Ashok Bhat98071552014-02-12 09:54:43 +0000439 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
440 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800441 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700442 rsnTypeGetNativeData(mContext, id, typeData);
443 }
Jason Sams768bc022009-09-21 19:41:04 -0700444
Ashok Bhat98071552014-02-12 09:54:43 +0000445 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
446 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800447 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800448 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700449 }
Leon Scroggins III71fae622019-03-26 16:28:41 -0400450 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, long bitmapHandle,
451 int usage);
Tim Murray460a0492013-11-19 12:45:54 -0800452 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800453 validate();
Leon Scroggins III71fae622019-03-26 16:28:41 -0400454 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp.getNativeInstance(), usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700455 }
Tim Murraya3145512012-12-04 17:59:29 -0800456
Leon Scroggins III71fae622019-03-26 16:28:41 -0400457 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, long bitmapHandle,
458 int usage);
459 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp,
460 int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800461 validate();
Leon Scroggins III71fae622019-03-26 16:28:41 -0400462 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp.getNativeInstance(),
463 usage);
Tim Murraya3145512012-12-04 17:59:29 -0800464 }
465
Leon Scroggins III71fae622019-03-26 16:28:41 -0400466 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, long bitmapHandle,
467 int usage);
Tim Murray460a0492013-11-19 12:45:54 -0800468 synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800469 validate();
Leon Scroggins III71fae622019-03-26 16:28:41 -0400470 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp.getNativeInstance(),
471 usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800472 }
Leon Scroggins III71fae622019-03-26 16:28:41 -0400473 native long rsnAllocationCreateBitmapRef(long con, long type, long bitmapHandle);
Tim Murray460a0492013-11-19 12:45:54 -0800474 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800475 validate();
Leon Scroggins III71fae622019-03-26 16:28:41 -0400476 return rsnAllocationCreateBitmapRef(mContext, type, bmp.getNativeInstance());
Jason Sams2e1872f2010-08-17 16:25:41 -0700477 }
Tim Murray460a0492013-11-19 12:45:54 -0800478 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
479 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800480 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800481 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
482 }
483
Leon Scroggins III71fae622019-03-26 16:28:41 -0400484 native void rsnAllocationCopyToBitmap(long con, long alloc, long bitmapHandle);
Tim Murray460a0492013-11-19 12:45:54 -0800485 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800486 validate();
Leon Scroggins III71fae622019-03-26 16:28:41 -0400487 rsnAllocationCopyToBitmap(mContext, alloc, bmp.getNativeInstance());
Jason Sams4ef66502010-12-10 16:03:15 -0800488 }
489
Tim Murray460a0492013-11-19 12:45:54 -0800490 native void rsnAllocationSyncAll(long con, long alloc, int src);
491 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800492 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800493 rsnAllocationSyncAll(mContext, alloc, src);
494 }
Miao Wang0facf022015-11-25 11:21:13 -0800495
Leon Scroggins III71fae622019-03-26 16:28:41 -0400496 native ByteBuffer rsnAllocationGetByteBuffer(long con, long alloc, long[] stride,
497 int xBytesSize, int dimY, int dimZ);
498 synchronized ByteBuffer nAllocationGetByteBuffer(long alloc, long[] stride, int xBytesSize,
499 int dimY, int dimZ) {
Miao Wang0facf022015-11-25 11:21:13 -0800500 validate();
501 return rsnAllocationGetByteBuffer(mContext, alloc, stride, xBytesSize, dimY, dimZ);
502 }
503
Miao Wang8c150922015-10-26 17:44:10 -0700504 native void rsnAllocationSetupBufferQueue(long con, long alloc, int numAlloc);
505 synchronized void nAllocationSetupBufferQueue(long alloc, int numAlloc) {
506 validate();
507 rsnAllocationSetupBufferQueue(mContext, alloc, numAlloc);
508 }
509 native void rsnAllocationShareBufferQueue(long con, long alloc1, long alloc2);
510 synchronized void nAllocationShareBufferQueue(long alloc1, long alloc2) {
511 validate();
512 rsnAllocationShareBufferQueue(mContext, alloc1, alloc2);
513 }
Tim Murray460a0492013-11-19 12:45:54 -0800514 native Surface rsnAllocationGetSurface(long con, long alloc);
515 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800516 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800517 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700518 }
Tim Murray460a0492013-11-19 12:45:54 -0800519 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
520 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800521 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700522 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800523 }
Tim Murray460a0492013-11-19 12:45:54 -0800524 native void rsnAllocationIoSend(long con, long alloc);
525 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800526 validate();
527 rsnAllocationIoSend(mContext, alloc);
528 }
Miao Wang8c150922015-10-26 17:44:10 -0700529 native long rsnAllocationIoReceive(long con, long alloc);
530 synchronized long nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800531 validate();
Miao Wang8c150922015-10-26 17:44:10 -0700532 return rsnAllocationIoReceive(mContext, alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800533 }
534
Tim Murray460a0492013-11-19 12:45:54 -0800535 native void rsnAllocationGenerateMipmaps(long con, long alloc);
536 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800537 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800538 rsnAllocationGenerateMipmaps(mContext, alloc);
539 }
Leon Scroggins III71fae622019-03-26 16:28:41 -0400540 native void rsnAllocationCopyFromBitmap(long con, long alloc, long bitmapHandle);
Tim Murray460a0492013-11-19 12:45:54 -0800541 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800542 validate();
Leon Scroggins III71fae622019-03-26 16:28:41 -0400543 rsnAllocationCopyFromBitmap(mContext, alloc, bmp.getNativeInstance());
Jason Sams2e1872f2010-08-17 16:25:41 -0700544 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700545
Jason Sams49a05d72010-12-29 14:31:29 -0800546
Miao Wang87e908d2015-03-02 15:15:15 -0800547 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
548 int mSize, boolean usePadding);
549 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
550 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800551 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800552 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700553 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700554
Miao Wangc8e237e2015-02-20 18:36:32 -0800555 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
556 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 -0800557 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800558 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700559 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700560
Tim Murrayeff663f2013-11-15 13:08:30 -0800561 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800562 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700563 int dstMip, int dstFace,
564 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800565 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700566 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800567 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700568 int dstMip, int dstFace,
569 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800570 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700571 int srcMip, int srcFace) {
572 validate();
573 rsnAllocationData2D(mContext,
574 dstAlloc, dstXoff, dstYoff,
575 dstMip, dstFace,
576 width, height,
577 srcAlloc, srcXoff, srcYoff,
578 srcMip, srcFace);
579 }
580
Tim Murray460a0492013-11-19 12:45:54 -0800581 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800582 int w, int h, Object d, int sizeBytes, int dt,
583 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800584 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800585 int w, int h, Object d, int sizeBytes, Element.DataType dt,
586 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800587 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800588 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700589 }
Jason Sams21659ac2013-11-06 15:08:07 -0800590
Tim Murray460a0492013-11-19 12:45:54 -0800591 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
592 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800593 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800594 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
595 }
Jason Sams49a05d72010-12-29 14:31:29 -0800596
Tim Murrayeff663f2013-11-15 13:08:30 -0800597 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800598 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700599 int dstMip,
600 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800601 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700602 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800603 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700604 int dstMip,
605 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800606 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700607 int srcMip) {
608 validate();
609 rsnAllocationData3D(mContext,
610 dstAlloc, dstXoff, dstYoff, dstZoff,
611 dstMip, width, height, depth,
612 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
613 }
614
Tim Murray460a0492013-11-19 12:45:54 -0800615 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800616 int w, int h, int depth, Object d, int sizeBytes, int dt,
617 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800618 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800619 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
620 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700621 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800622 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
623 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700624 }
Jason Samsb05d6892013-04-09 15:59:24 -0700625
Miao Wang87e908d2015-03-02 15:15:15 -0800626 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
627 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800628 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800629 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800630 }
Jason Sams21659ac2013-11-06 15:08:07 -0800631
Tim Murray460a0492013-11-19 12:45:54 -0800632 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800633 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800634 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800635 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800636 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800637 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800638 }
Jason Sams21659ac2013-11-06 15:08:07 -0800639
Miao Wangc8e237e2015-02-20 18:36:32 -0800640 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800641 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800642 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800643 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800644 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800645 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800646 }
647
Tim Murray460a0492013-11-19 12:45:54 -0800648 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800649 int w, int h, Object d, int sizeBytes, int dt,
650 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800651 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800652 int w, int h, Object d, int sizeBytes, Element.DataType dt,
653 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800654 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800655 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700656 }
Jason Sams21659ac2013-11-06 15:08:07 -0800657
Miao Wangc8e237e2015-02-20 18:36:32 -0800658 native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800659 int w, int h, int depth, Object d, int sizeBytes, int dt,
660 int mSize, boolean usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800661 synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800662 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
663 int mSize, boolean usePadding) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800664 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800665 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800666 }
667
Tim Murray460a0492013-11-19 12:45:54 -0800668 native long rsnAllocationGetType(long con, long id);
669 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800670 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700671 return rsnAllocationGetType(mContext, id);
672 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700673
Tim Murray460a0492013-11-19 12:45:54 -0800674 native void rsnAllocationResize1D(long con, long id, int dimX);
675 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800676 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700677 rsnAllocationResize1D(mContext, id, dimX);
678 }
Jason Sams5edc6082010-10-05 13:32:49 -0700679
Jason Sams46ba27e32015-02-06 17:45:15 -0800680 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
681 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
682 validate();
683 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
684 }
685
686 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
687 int mip, int face, int a1, int a2, int a3, int a4);
688 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
689 int mip, int face, int a1, int a2, int a3, int a4) {
690 validate();
691 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
692 }
693
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000694 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
695 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800696 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700697 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
698 }
Tim Murray460a0492013-11-19 12:45:54 -0800699 native long rsnFileA3DCreateFromFile(long con, String path);
700 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800701 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800702 return rsnFileA3DCreateFromFile(mContext, path);
703 }
Tim Murray460a0492013-11-19 12:45:54 -0800704 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
705 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800706 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800707 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
708 }
Tim Murray460a0492013-11-19 12:45:54 -0800709 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
710 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800711 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700712 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
713 }
Tim Murray460a0492013-11-19 12:45:54 -0800714 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
715 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800716 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700717 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
718 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000719 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
720 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800721 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700722 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
723 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700724
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000725 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
726 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800727 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700728 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
729 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000730 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
731 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800732 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800733 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
734 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000735 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
736 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800737 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800738 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
739 }
Jason Sams22534172009-08-04 16:58:20 -0700740
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700741
Tim Murray460a0492013-11-19 12:45:54 -0800742 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
743 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800744 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700745 rsnScriptBindAllocation(mContext, script, alloc, slot);
746 }
Tim Murray460a0492013-11-19 12:45:54 -0800747 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
748 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800749 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700750 rsnScriptSetTimeZone(mContext, script, timeZone);
751 }
Tim Murray460a0492013-11-19 12:45:54 -0800752 native void rsnScriptInvoke(long con, long id, int slot);
753 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800754 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700755 rsnScriptInvoke(mContext, id, slot);
756 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700757
758 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
759 long aout, byte[] params, int[] limits);
760
761 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
762 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700763 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700764 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700765 }
766
David Gross4a457852016-06-02 14:46:55 -0700767 native void rsnScriptReduce(long con, long id, int slot, long[] ains,
Matt Wala36eb1f72015-07-20 15:35:27 -0700768 long aout, int[] limits);
David Gross4a457852016-06-02 14:46:55 -0700769 synchronized void nScriptReduce(long id, int slot, long ains[], long aout,
Matt Wala36eb1f72015-07-20 15:35:27 -0700770 int[] limits) {
771 validate();
David Gross4a457852016-06-02 14:46:55 -0700772 rsnScriptReduce(mContext, id, slot, ains, aout, limits);
David Gross26ef7a732016-01-12 12:19:15 -0800773 }
774
Tim Murray460a0492013-11-19 12:45:54 -0800775 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
776 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800777 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700778 rsnScriptInvokeV(mContext, id, slot, params);
779 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700780
Tim Murray460a0492013-11-19 12:45:54 -0800781 native void rsnScriptSetVarI(long con, long id, int slot, int val);
782 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800783 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700784 rsnScriptSetVarI(mContext, id, slot, val);
785 }
Tim Murray460a0492013-11-19 12:45:54 -0800786 native int rsnScriptGetVarI(long con, long id, int slot);
787 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700788 validate();
789 return rsnScriptGetVarI(mContext, id, slot);
790 }
791
Tim Murray460a0492013-11-19 12:45:54 -0800792 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
793 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800794 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700795 rsnScriptSetVarJ(mContext, id, slot, val);
796 }
Tim Murray460a0492013-11-19 12:45:54 -0800797 native long rsnScriptGetVarJ(long con, long id, int slot);
798 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700799 validate();
800 return rsnScriptGetVarJ(mContext, id, slot);
801 }
802
Tim Murray460a0492013-11-19 12:45:54 -0800803 native void rsnScriptSetVarF(long con, long id, int slot, float val);
804 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800805 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700806 rsnScriptSetVarF(mContext, id, slot, val);
807 }
Tim Murray460a0492013-11-19 12:45:54 -0800808 native float rsnScriptGetVarF(long con, long id, int slot);
809 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700810 validate();
811 return rsnScriptGetVarF(mContext, id, slot);
812 }
Tim Murray460a0492013-11-19 12:45:54 -0800813 native void rsnScriptSetVarD(long con, long id, int slot, double val);
814 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800815 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700816 rsnScriptSetVarD(mContext, id, slot, val);
817 }
Tim Murray460a0492013-11-19 12:45:54 -0800818 native double rsnScriptGetVarD(long con, long id, int slot);
819 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700820 validate();
821 return rsnScriptGetVarD(mContext, id, slot);
822 }
Tim Murray460a0492013-11-19 12:45:54 -0800823 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
824 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800825 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700826 rsnScriptSetVarV(mContext, id, slot, val);
827 }
Tim Murray460a0492013-11-19 12:45:54 -0800828 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
829 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700830 validate();
831 rsnScriptGetVarV(mContext, id, slot, val);
832 }
Tim Murray460a0492013-11-19 12:45:54 -0800833 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
834 long e, int[] dims);
835 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
836 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700837 validate();
838 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
839 }
Tim Murray460a0492013-11-19 12:45:54 -0800840 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
841 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800842 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800843 rsnScriptSetVarObj(mContext, id, slot, val);
844 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700845
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000846 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700847 byte[] script, int length);
Mathew Inwood15324472018-08-06 11:18:49 +0100848 @UnsupportedAppUsage
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000849 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800850 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700851 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700852 }
Jason Samsebfb4362009-09-23 13:57:02 -0700853
Tim Murray460a0492013-11-19 12:45:54 -0800854 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
855 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700856 validate();
857 return rsnScriptIntrinsicCreate(mContext, id, eid);
858 }
859
Tim Murray460a0492013-11-19 12:45:54 -0800860 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
861 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700862 validate();
863 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
864 }
865
Yang Nibe392ad2015-01-23 17:16:02 -0800866 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
867 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
868 validate();
869 return rsnScriptInvokeIDCreate(mContext, sid, slot);
870 }
871
Tim Murray460a0492013-11-19 12:45:54 -0800872 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
873 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700874 validate();
875 return rsnScriptFieldIDCreate(mContext, sid, slot);
876 }
877
Ashok Bhat98071552014-02-12 09:54:43 +0000878 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
879 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700880 validate();
881 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
882 }
883
Tim Murray460a0492013-11-19 12:45:54 -0800884 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
885 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700886 validate();
887 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
888 }
889
Tim Murray460a0492013-11-19 12:45:54 -0800890 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
891 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700892 validate();
893 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
894 }
895
Tim Murray460a0492013-11-19 12:45:54 -0800896 native void rsnScriptGroupExecute(long con, long group);
897 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700898 validate();
899 rsnScriptGroupExecute(mContext, group);
900 }
901
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000902 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700903 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000904 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700905 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800906 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700907 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700908 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800909
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000910 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700911 boolean depthMask, boolean dither,
912 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000913 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700914 boolean depthMask, boolean dither,
915 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800916 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700917 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
918 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700919 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700920
Tim Murray460a0492013-11-19 12:45:54 -0800921 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
922 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800923 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700924 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700925 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700926
Tim Murray460a0492013-11-19 12:45:54 -0800927 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
928 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800929 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700930 rsnProgramBindConstants(mContext, pv, slot, mID);
931 }
Tim Murray460a0492013-11-19 12:45:54 -0800932 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
933 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800934 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700935 rsnProgramBindTexture(mContext, vpf, slot, a);
936 }
Tim Murray460a0492013-11-19 12:45:54 -0800937 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
938 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800939 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700940 rsnProgramBindSampler(mContext, vpf, slot, s);
941 }
Ashok Bhat98071552014-02-12 09:54:43 +0000942 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
943 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800944 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800945 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700946 }
Ashok Bhat98071552014-02-12 09:54:43 +0000947 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
948 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800949 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800950 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700951 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700952
Ashok Bhat98071552014-02-12 09:54:43 +0000953 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
954 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800955 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700956 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800957 }
Tim Murray460a0492013-11-19 12:45:54 -0800958 native int rsnMeshGetVertexBufferCount(long con, long id);
959 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800960 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700961 return rsnMeshGetVertexBufferCount(mContext, id);
962 }
Tim Murray460a0492013-11-19 12:45:54 -0800963 native int rsnMeshGetIndexCount(long con, long id);
964 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800965 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700966 return rsnMeshGetIndexCount(mContext, id);
967 }
Ashok Bhat98071552014-02-12 09:54:43 +0000968 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
969 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800970 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700971 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
972 }
Ashok Bhat98071552014-02-12 09:54:43 +0000973 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
974 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800975 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700976 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
977 }
978
Tim Murray25207df2015-01-12 16:47:56 -0800979 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
980 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
981 float alpha, long A, long B, float beta, long C, int incX, int incY,
982 int KL, int KU);
983 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
984 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
985 float alpha, long A, long B, float beta, long C, int incX, int incY,
986 int KL, int KU) {
987 validate();
988 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
989 }
990
991 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
992 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
993 double alpha, long A, long B, double beta, long C, int incX, int incY,
994 int KL, int KU);
995 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
996 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
997 double alpha, long A, long B, double beta, long C, int incX, int incY,
998 int KL, int KU) {
999 validate();
1000 rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
1001 }
1002
1003 native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA,
1004 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
1005 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
1006 int KL, int KU);
1007 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
1008 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
1009 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
1010 int KL, int KU) {
1011 validate();
1012 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
1013 }
1014
1015 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
1016 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
1017 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
1018 int KL, int KU);
1019 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
1020 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
1021 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
1022 int KL, int KU) {
1023 validate();
1024 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
1025 }
1026
Tim Murray9cb16a22015-04-01 11:07:16 -07001027 native void rsnScriptIntrinsicBLAS_BNNM(long con, long id, int M, int N, int K,
1028 long A, int a_offset, long B, int b_offset, long C, int c_offset,
1029 int c_mult_int);
1030 synchronized void nScriptIntrinsicBLAS_BNNM(long id, int M, int N, int K,
1031 long A, int a_offset, long B, int b_offset, long C, int c_offset,
1032 int c_mult_int) {
1033 validate();
1034 rsnScriptIntrinsicBLAS_BNNM(mContext, id, M, N, K, A, a_offset, B, b_offset, C, c_offset, c_mult_int);
1035 }
1036
1037
Tim Murray25207df2015-01-12 16:47:56 -08001038
Tim Murrayeff663f2013-11-15 13:08:30 -08001039 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -08001040 private boolean mDestroyed = false;
1041
Romain Guy650a3eb2009-08-31 14:06:43 -07001042 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001043 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001044
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001045 volatile Element mElement_U8;
1046 volatile Element mElement_I8;
1047 volatile Element mElement_U16;
1048 volatile Element mElement_I16;
1049 volatile Element mElement_U32;
1050 volatile Element mElement_I32;
1051 volatile Element mElement_U64;
1052 volatile Element mElement_I64;
1053 volatile Element mElement_F16;
1054 volatile Element mElement_F32;
1055 volatile Element mElement_F64;
1056 volatile Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -07001057
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001058 volatile Element mElement_ELEMENT;
1059 volatile Element mElement_TYPE;
1060 volatile Element mElement_ALLOCATION;
1061 volatile Element mElement_SAMPLER;
1062 volatile Element mElement_SCRIPT;
1063 volatile Element mElement_MESH;
1064 volatile Element mElement_PROGRAM_FRAGMENT;
1065 volatile Element mElement_PROGRAM_VERTEX;
1066 volatile Element mElement_PROGRAM_RASTER;
1067 volatile Element mElement_PROGRAM_STORE;
1068 volatile Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -07001069
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001070 volatile Element mElement_A_8;
1071 volatile Element mElement_RGB_565;
1072 volatile Element mElement_RGB_888;
1073 volatile Element mElement_RGBA_5551;
1074 volatile Element mElement_RGBA_4444;
1075 volatile Element mElement_RGBA_8888;
Jason Sams3c0dfba2009-09-27 17:50:38 -07001076
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001077 volatile Element mElement_HALF_2;
1078 volatile Element mElement_HALF_3;
1079 volatile Element mElement_HALF_4;
Jason Samsa5835a22014-11-05 15:16:26 -08001080
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001081 volatile Element mElement_FLOAT_2;
1082 volatile Element mElement_FLOAT_3;
1083 volatile Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001084
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001085 volatile Element mElement_DOUBLE_2;
1086 volatile Element mElement_DOUBLE_3;
1087 volatile Element mElement_DOUBLE_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001088
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001089 volatile Element mElement_UCHAR_2;
1090 volatile Element mElement_UCHAR_3;
1091 volatile Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001092
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001093 volatile Element mElement_CHAR_2;
1094 volatile Element mElement_CHAR_3;
1095 volatile Element mElement_CHAR_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001096
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001097 volatile Element mElement_USHORT_2;
1098 volatile Element mElement_USHORT_3;
1099 volatile Element mElement_USHORT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001100
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001101 volatile Element mElement_SHORT_2;
1102 volatile Element mElement_SHORT_3;
1103 volatile Element mElement_SHORT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001104
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001105 volatile Element mElement_UINT_2;
1106 volatile Element mElement_UINT_3;
1107 volatile Element mElement_UINT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001108
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001109 volatile Element mElement_INT_2;
1110 volatile Element mElement_INT_3;
1111 volatile Element mElement_INT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001112
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001113 volatile Element mElement_ULONG_2;
1114 volatile Element mElement_ULONG_3;
1115 volatile Element mElement_ULONG_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001116
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001117 volatile Element mElement_LONG_2;
1118 volatile Element mElement_LONG_3;
1119 volatile Element mElement_LONG_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001120
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001121 volatile Element mElement_YUV;
Tim Murray932e78e2013-09-03 11:42:26 -07001122
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001123 volatile Element mElement_MATRIX_4X4;
1124 volatile Element mElement_MATRIX_3X3;
1125 volatile Element mElement_MATRIX_2X2;
Jason Sams1d45c472010-08-25 14:31:48 -07001126
Yang Ni6bdfe0f2016-04-18 16:56:16 -07001127 volatile Sampler mSampler_CLAMP_NEAREST;
1128 volatile Sampler mSampler_CLAMP_LINEAR;
1129 volatile Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1130 volatile Sampler mSampler_WRAP_NEAREST;
1131 volatile Sampler mSampler_WRAP_LINEAR;
1132 volatile Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
1133 volatile Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1134 volatile Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1135 volatile Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001136
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001137 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1138 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001139 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1140 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001141
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001142 ProgramRaster mProgramRaster_CULL_BACK;
1143 ProgramRaster mProgramRaster_CULL_FRONT;
1144 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001145
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001146 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001147 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001148
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001149 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001150 * The base class from which an application should derive in order
1151 * to receive RS messages from scripts. When a script calls {@code
1152 * rsSendToClient}, the data fields will be filled, and the run
1153 * method will be called on a separate thread. This will occur
1154 * some time after {@code rsSendToClient} completes in the script,
1155 * as {@code rsSendToClient} is asynchronous. Message handlers are
1156 * not guaranteed to have completed when {@link
1157 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001158 *
1159 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001160 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001161 protected int[] mData;
1162 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001163 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001164 public void run() {
1165 }
1166 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001167 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001168 * If an application is expecting messages, it should set this
1169 * field to an instance of {@link RSMessageHandler}. This
1170 * instance will receive all the user messages sent from {@code
1171 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001172 *
1173 */
Mathew Inwood15324472018-08-06 11:18:49 +01001174 @UnsupportedAppUsage
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001175 RSMessageHandler mMessageCallback = null;
1176
1177 public void setMessageHandler(RSMessageHandler msg) {
1178 mMessageCallback = msg;
1179 }
1180 public RSMessageHandler getMessageHandler() {
1181 return mMessageCallback;
1182 }
Jason Sams516c3192009-10-06 13:58:47 -07001183
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001184 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001185 * Place a message into the message queue to be sent back to the message
1186 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001187 *
1188 * @param id
1189 * @param data
1190 */
1191 public void sendMessage(int id, int[] data) {
1192 nContextSendMessage(id, data);
1193 }
1194
1195 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001196 * The runtime error handler base class. An application should derive from this class
1197 * if it wishes to install an error handler. When errors occur at runtime,
1198 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001199 *
1200 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001201 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001202 protected String mErrorMessage;
1203 protected int mErrorNum;
1204 public void run() {
1205 }
1206 }
Jason Sams27676fe2010-11-10 17:00:59 -08001207
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001208 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001209 * Application Error handler. All runtime errors will be dispatched to the
1210 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001211 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001212 * This will cause program termaination.
1213 *
1214 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001215 RSErrorHandler mErrorCallback = null;
1216
1217 public void setErrorHandler(RSErrorHandler msg) {
1218 mErrorCallback = msg;
1219 }
1220 public RSErrorHandler getErrorHandler() {
1221 return mErrorCallback;
1222 }
Jason Sams1c415172010-11-08 17:06:46 -08001223
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001224 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001225 * RenderScript worker thread priority enumeration. The default value is
1226 * NORMAL. Applications wishing to do background processing should set
1227 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001228 */
Jason Sams7d787b42009-11-15 12:14:26 -08001229 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001230 // These values used to represent official thread priority values
1231 // now they are simply enums to be used by the runtime side
1232 LOW (15),
1233 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001234
1235 int mID;
1236 Priority(int id) {
1237 mID = id;
1238 }
1239 }
1240
Jason Sams678cc7f2014-03-05 16:09:02 -08001241 void validateObject(BaseObj o) {
1242 if (o != null) {
1243 if (o.mRS != this) {
1244 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1245 }
1246 }
1247 }
1248
Mathew Inwood15324472018-08-06 11:18:49 +01001249 @UnsupportedAppUsage
Jason Sams771bebb2009-12-07 12:40:12 -08001250 void validate() {
1251 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001252 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001253 }
1254 }
1255
Jason Sams27676fe2010-11-10 17:00:59 -08001256
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001257 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001258 * Change the priority of the worker threads for this context.
1259 *
1260 * @param p New priority to be set.
1261 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001262 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001263 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001264 nContextSetPriority(p.mID);
1265 }
1266
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001267 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001268 RenderScript mRS;
1269 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001270 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001271
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001272 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1273 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1274 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1275 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1276 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001277 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001278
Stephen Hines42028a82013-04-17 19:22:01 -07001279 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001280 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001281
Jason Sams516c3192009-10-06 13:58:47 -07001282 MessageThread(RenderScript rs) {
1283 super("RSMessageThread");
1284 mRS = rs;
1285
1286 }
1287
1288 public void run() {
1289 // This function is a temporary solution. The final solution will
1290 // used typed allocations where the message id is the type indicator.
1291 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001292 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001293 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001294 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001295 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001296 int size = mAuxData[1];
1297 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001298
1299 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1300 if ((size>>2) >= rbuf.length) {
1301 rbuf = new int[(size + 3) >> 2];
1302 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001303 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1304 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001305 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001306 }
Jason Sams1c415172010-11-08 17:06:46 -08001307
1308 if(mRS.mMessageCallback != null) {
1309 mRS.mMessageCallback.mData = rbuf;
1310 mRS.mMessageCallback.mID = subID;
1311 mRS.mMessageCallback.mLength = size;
1312 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001313 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001314 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001315 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001316 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001317 }
Jason Sams1c415172010-11-08 17:06:46 -08001318
1319 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1320 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1321
Stephen Hines42028a82013-04-17 19:22:01 -07001322 // Throw RSRuntimeException under the following conditions:
1323 //
1324 // 1) It is an unknown fatal error.
1325 // 2) It is a debug fatal error, and we are not in a
1326 // debug context.
1327 // 3) It is a debug fatal error, and we do not have an
1328 // error callback.
1329 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1330 (subID >= RS_ERROR_FATAL_DEBUG &&
1331 (mRS.mContextType != ContextType.DEBUG ||
1332 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001333 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1334 }
1335
Jason Sams1c415172010-11-08 17:06:46 -08001336 if(mRS.mErrorCallback != null) {
1337 mRS.mErrorCallback.mErrorMessage = e;
1338 mRS.mErrorCallback.mErrorNum = subID;
1339 mRS.mErrorCallback.run();
1340 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001341 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001342 // Do not throw here. In these cases, we do not have
1343 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001344 }
1345 continue;
1346 }
1347
Jason Sams739c8262013-04-11 18:07:52 -07001348 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001349 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1350 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1351 throw new RSDriverException("Error processing message from RenderScript.");
1352 }
1353 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1354 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001355 continue;
1356 }
1357
Jason Sams1c415172010-11-08 17:06:46 -08001358 // 2: teardown.
1359 // But we want to avoid starving other threads during
1360 // teardown by yielding until the next line in the destructor
1361 // can execute to set mRun = false
1362 try {
1363 sleep(1, 0);
1364 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001365 }
Jason Sams516c3192009-10-06 13:58:47 -07001366 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001367 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001368 }
1369 }
1370
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001371 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001372 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001373 if (ctx != null) {
1374 mApplicationContext = ctx.getApplicationContext();
1375 }
Tim Murray06b45672014-01-07 11:13:56 -08001376 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001377 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001378 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001379 } catch (Exception e) {
1380 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1381 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1382 }
1383
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001384 }
1385
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001386 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001387 * Gets the application context associated with the RenderScript context.
1388 *
1389 * @return The application context.
1390 */
1391 public final Context getApplicationContext() {
1392 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001393 }
1394
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001395 /**
Yang Ni689f6372016-03-10 16:12:31 -08001396 * Name of the file that holds the object cache.
1397 */
1398 private static String mCachePath;
1399
1400 /**
1401 * Gets the path to the code cache.
1402 */
1403 static synchronized String getCachePath() {
1404 if (mCachePath == null) {
1405 final String CACHE_PATH = "com.android.renderscript.cache";
1406 if (RenderScriptCacheDir.mCacheDir == null) {
1407 throw new RSRuntimeException("RenderScript code cache directory uninitialized.");
1408 }
1409 File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
1410 mCachePath = f.getAbsolutePath();
1411 f.mkdirs();
1412 }
1413 return mCachePath;
1414 }
1415
1416 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001417 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001418 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001419 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001420 * @return RenderScript
1421 */
Jason Samse16da122015-03-18 17:04:18 -07001422 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001423 if (!sInitialized) {
1424 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1425 return null;
1426 }
1427
verena beckhamc9659ea2015-05-22 16:47:53 +01001428 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER |
Stephen McGroarty88891e62015-09-02 15:54:05 +01001429 CREATE_FLAG_WAIT_FOR_ATTACH)) != 0) {
Jason Samsb69c7912014-05-20 18:48:35 -07001430 throw new RSIllegalArgumentException("Invalid flags passed.");
1431 }
1432
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001433 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001434
Yang Nicb939dc2016-04-04 10:23:57 -07001435 long device = rs.nDeviceCreate();
1436 rs.mContext = rs.nContextCreate(device, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001437 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001438 rs.mContextFlags = flags;
1439 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001440 if (rs.mContext == 0) {
1441 throw new RSDriverException("Failed to create RS context.");
1442 }
Tim Murray47f31582015-04-07 15:43:24 -07001443
1444 // set up cache directory for entire context
Yang Ni689f6372016-03-10 16:12:31 -08001445 rs.nContextSetCacheDir(RenderScript.getCachePath());
Tim Murray47f31582015-04-07 15:43:24 -07001446
Jason Sams704ff642010-02-09 16:05:07 -08001447 rs.mMessageThread = new MessageThread(rs);
1448 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001449 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001450 }
1451
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001452 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001453 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001454 *
1455 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001456 *
1457 * @param ctx The context.
1458 * @return RenderScript
1459 */
1460 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001461 return create(ctx, ContextType.NORMAL);
1462 }
1463
1464 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001465 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001466 *
Jason Samse16da122015-03-18 17:04:18 -07001467 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001468 *
1469 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001470 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001471 * @return RenderScript
1472 */
1473 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001474 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001475 }
1476
Miao Wanga4e5adf2015-03-23 11:09:56 -07001477
1478 /**
Jason Samse16da122015-03-18 17:04:18 -07001479 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001480 *
Jason Samse16da122015-03-18 17:04:18 -07001481 * The returned context will be cached for future reuse within
1482 * the process. When an application is finished using
1483 * RenderScript it should call releaseAllContexts()
1484 *
1485 * A process context is a context designed for easy creation and
1486 * lifecycle management. Multiple calls to this function will
1487 * return the same object provided they are called with the same
1488 * options. This allows it to be used any time a RenderScript
1489 * context is needed.
1490 *
1491 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001492 *
1493 * @param ctx The context.
1494 * @param ct The type of context to be created.
1495 * @param flags The OR of the CREATE_FLAG_* options desired
1496 * @return RenderScript
1497 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001498 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001499 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001500 return create(ctx, v, ct, flags);
1501 }
1502
1503 /**
1504 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1505 *
1506 * Used by the RenderScriptThunker to maintain backward compatibility.
1507 *
1508 * @hide
1509 * @param ctx The context.
1510 * @param sdkVersion The target SDK Version.
1511 * @return RenderScript
1512 */
Mathew Inwood15324472018-08-06 11:18:49 +01001513 @UnsupportedAppUsage
Miao Wanga4e5adf2015-03-23 11:09:56 -07001514 public static RenderScript create(Context ctx, int sdkVersion) {
1515 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1516 }
1517
1518 /**
1519 * Gets or creates a RenderScript context of the specified type.
1520 *
Miao Wanga4e5adf2015-03-23 11:09:56 -07001521 * @param ctx The context.
1522 * @param ct The type of context to be created.
1523 * @param sdkVersion The target SDK Version.
1524 * @param flags The OR of the CREATE_FLAG_* options desired
1525 * @return RenderScript
1526 */
Mathew Inwood15324472018-08-06 11:18:49 +01001527 @UnsupportedAppUsage
Jason Sams6a420b52015-03-30 15:31:26 -07001528 private static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
Miao Wanga4e5adf2015-03-23 11:09:56 -07001529 if (sdkVersion < 23) {
1530 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001531 }
1532
1533 synchronized (mProcessContextList) {
1534 for (RenderScript prs : mProcessContextList) {
1535 if ((prs.mContextType == ct) &&
1536 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001537 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001538
1539 return prs;
1540 }
1541 }
1542
Miao Wanga4e5adf2015-03-23 11:09:56 -07001543 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001544 prs.mIsProcessContext = true;
1545 mProcessContextList.add(prs);
1546 return prs;
1547 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001548 }
1549
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001550 /**
Jason Samse16da122015-03-18 17:04:18 -07001551 * Releases all the process contexts. This is the same as
1552 * calling .destroy() on each unique context retreived with
1553 * create(...). If no contexts have been created this
1554 * function does nothing.
1555 *
1556 * Typically you call this when your application is losing focus
1557 * and will not be using a context for some time.
1558 *
1559 * This has no effect on a context created with
1560 * createMultiContext()
1561 */
1562 public static void releaseAllContexts() {
1563 ArrayList<RenderScript> oldList;
1564 synchronized (mProcessContextList) {
1565 oldList = mProcessContextList;
1566 mProcessContextList = new ArrayList<RenderScript>();
1567 }
1568
1569 for (RenderScript prs : oldList) {
1570 prs.mIsProcessContext = false;
1571 prs.destroy();
1572 }
1573 oldList.clear();
1574 }
1575
1576
1577
1578 /**
1579 * Create a RenderScript context.
1580 *
1581 * This is an advanced function intended for applications which
1582 * need to create more than one RenderScript context to be used
1583 * at the same time.
1584 *
1585 * If you need a single context please use create()
1586 *
Jason Samse16da122015-03-18 17:04:18 -07001587 * @param ctx The context.
1588 * @return RenderScript
1589 */
1590 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1591 return internalCreate(ctx, API_number, ct, flags);
1592 }
1593
1594
1595 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001596 * Print the currently available debugging information about the state of
1597 * the RS context to the log.
1598 *
Jason Sams27676fe2010-11-10 17:00:59 -08001599 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001600 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001601 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001602 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001603 }
1604
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001605 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001606 * Wait for any pending asynchronous opeations (such as copies to a RS
1607 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001608 *
1609 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001610 public void finish() {
1611 nContextFinish();
1612 }
1613
Jason Samsd22a6f02015-02-19 17:19:52 -08001614 private void helpDestroy() {
1615 boolean shouldDestroy = false;
1616 synchronized(this) {
1617 if (!mDestroyed) {
1618 shouldDestroy = true;
1619 mDestroyed = true;
1620 }
1621 }
1622
1623 if (shouldDestroy) {
1624 nContextFinish();
1625
1626 nContextDeinitToClient(mContext);
1627 mMessageThread.mRun = false;
Miao Wang4a574802016-05-10 16:44:11 -07001628 // Interrupt mMessageThread so it gets to see immediately that mRun is false
1629 // and exit rightaway.
1630 mMessageThread.interrupt();
Pirama Arumuga Nainar2f25ce772015-10-02 12:06:10 -07001631
1632 // Wait for mMessageThread to join. Try in a loop, in case this thread gets interrupted
Pirama Arumuga Nainar83461d72015-10-02 16:38:08 -07001633 // during the wait. If interrupted, set the "interrupted" status of the current thread.
1634 boolean hasJoined = false, interrupted = false;
Pirama Arumuga Nainar2f25ce772015-10-02 12:06:10 -07001635 while (!hasJoined) {
1636 try {
1637 mMessageThread.join();
1638 hasJoined = true;
Pirama Arumuga Nainar83461d72015-10-02 16:38:08 -07001639 } catch (InterruptedException e) {
1640 interrupted = true;
Pirama Arumuga Nainar2f25ce772015-10-02 12:06:10 -07001641 }
Jason Samsd22a6f02015-02-19 17:19:52 -08001642 }
Pirama Arumuga Nainar83461d72015-10-02 16:38:08 -07001643 if (interrupted) {
1644 Log.v(LOG_TAG, "Interrupted during wait for MessageThread to join");
1645 Thread.currentThread().interrupt();
1646 }
Jason Samsd22a6f02015-02-19 17:19:52 -08001647
1648 nContextDestroy();
Jason Samsd22a6f02015-02-19 17:19:52 -08001649 }
1650 }
1651
1652 protected void finalize() throws Throwable {
1653 helpDestroy();
1654 super.finalize();
1655 }
1656
1657
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001658 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001659 * Destroys this RenderScript context. Once this function is called,
1660 * using this context or any objects belonging to this context is
1661 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001662 *
Jason Samse16da122015-03-18 17:04:18 -07001663 * API 23+, this function is a NOP if the context was created
1664 * with create(). Please use releaseAllContexts() to clean up
1665 * contexts created with the create function.
1666 *
Jason Sams27676fe2010-11-10 17:00:59 -08001667 */
Jason Samsf5b45962009-08-25 14:49:07 -07001668 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001669 if (mIsProcessContext) {
1670 // users cannot destroy a process context
1671 return;
1672 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001673 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001674 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001675 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001676
Jason Samsa9e7a052009-09-25 14:51:22 -07001677 boolean isAlive() {
1678 return mContext != 0;
1679 }
1680
Tim Murray460a0492013-11-19 12:45:54 -08001681 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001682 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001683 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001684 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001685 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001686 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001687}