blob: a2967e8a2c47bf848ce963781174e4e58a60d59a [file] [log] [blame]
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001/*
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08002 * Copyright (C) 2008-2012 The Android Open Source Project
Jack Palevich60aa3ea2009-05-26 13:45:08 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Sams94d8e90a2009-06-10 16:09:05 -070017package android.renderscript;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070018
Tim Murray47f31582015-04-07 15:43:24 -070019import java.io.File;
Tim Murray2f2472c2013-08-22 14:55:26 -070020import java.lang.reflect.Method;
Tim Murray06b45672014-01-07 11:13:56 -080021import java.util.concurrent.locks.ReentrantReadWriteLock;
Jason Sams36e612a2009-07-31 16:26:13 -070022
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080023import android.content.Context;
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080024import android.content.res.AssetManager;
Jason Samsb8c5a842009-07-31 20:40:47 -070025import android.graphics.Bitmap;
Jason Samsfaa32b32011-06-20 16:58:04 -070026import android.graphics.SurfaceTexture;
Jason Sams36e612a2009-07-31 16:26:13 -070027import android.util.Log;
28import android.view.Surface;
Dan Morrille4d9a012013-03-28 18:10:43 -070029import android.os.SystemProperties;
Tim Murray6d7a53c2013-05-23 16:59:23 -070030import android.os.Trace;
Jason Samse16da122015-03-18 17:04:18 -070031import java.util.ArrayList;
Stephen Hines4382467a2011-08-01 15:02:34 -070032
Matt Wala36eb1f72015-07-20 15:35:27 -070033// TODO: Clean up the whitespace that separates methods in this class.
34
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070035/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070036 * This class provides access to a RenderScript context, which controls RenderScript
37 * initialization, resource management, and teardown. An instance of the RenderScript
38 * class must be created before any other RS objects can be created.
Jason Sams27676fe2010-11-10 17:00:59 -080039 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080040 * <div class="special reference">
41 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070042 * <p>For more information about creating an application that uses RenderScript, read the
43 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080044 * </div>
Jason Samse29d4712009-07-23 15:19:03 -070045 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070046public class RenderScript {
Tim Murray6d7a53c2013-05-23 16:59:23 -070047 static final long TRACE_TAG = Trace.TRACE_TAG_RS;
48
Jason Sams3bc47d42009-11-12 15:10:25 -080049 static final String LOG_TAG = "RenderScript_jni";
Jason Samsbf6ef8d72010-12-06 15:59:59 -080050 static final boolean DEBUG = false;
Romain Guy650a3eb2009-08-31 14:06:43 -070051 @SuppressWarnings({"UnusedDeclaration", "deprecation"})
Joe Onorato43a17652011-04-06 19:22:23 -070052 static final boolean LOG_ENABLED = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070053
Jason Samse16da122015-03-18 17:04:18 -070054 static private ArrayList<RenderScript> mProcessContextList = new ArrayList<RenderScript>();
55 private boolean mIsProcessContext = false;
56 private int mContextFlags = 0;
57 private int mContextSdkVersion = 0;
58
59
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080060 private Context mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070061
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080062 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070063 * We use a class initializer to allow the native code to cache some
64 * field offsets.
65 */
Dan Morrille4d9a012013-03-28 18:10:43 -070066 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
Jason Samsbf6ef8d72010-12-06 15:59:59 -080067 static boolean sInitialized;
68 native static void _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070069
Tim Murray2f2472c2013-08-22 14:55:26 -070070 static Object sRuntime;
71 static Method registerNativeAllocation;
72 static Method registerNativeFree;
Jason Samsdba3ba52009-07-30 14:56:12 -070073
Jason Sams26e90512014-05-07 14:23:27 -070074 /*
Tim Murrayfd710e72014-06-06 11:10:45 -070075 * Context creation flag that specifies a normal context.
Jason Sams26e90512014-05-07 14:23:27 -070076 */
Tim Murrayfd710e72014-06-06 11:10:45 -070077 public static final int CREATE_FLAG_NONE = 0x0000;
Jason Sams26e90512014-05-07 14:23:27 -070078
79 /*
80 * Context creation flag which specifies a context optimized for low
81 * latency over peak performance. This is a hint and may have no effect
82 * on some implementations.
83 */
Tim Murrayfd710e72014-06-06 11:10:45 -070084 public static final int CREATE_FLAG_LOW_LATENCY = 0x0002;
Jason Sams26e90512014-05-07 14:23:27 -070085
86 /*
87 * Context creation flag which specifies a context optimized for long
88 * battery life over peak performance. This is a hint and may have no effect
89 * on some implementations.
90 */
Tim Murrayfd710e72014-06-06 11:10:45 -070091 public static final int CREATE_FLAG_LOW_POWER = 0x0004;
Jason Sams26e90512014-05-07 14:23:27 -070092
Stephen McGroarty62cb9bd2015-05-08 15:56:58 +010093 /**
94 * @hide
95 * Context creation flag which instructs the implementation to wait for
96 * a debugger to be attached before continuing execution.
97 */
98 public static final int CREATE_FLAG_WAIT_FOR_ATTACH = 0x0008;
99
verena beckhamc9659ea2015-05-22 16:47:53 +0100100 /**
101 * @hide
102 * Context creation flag which specifies that optimization level 0 is
103 * passed to the device compiler upon execution of the RenderScript kernel.
104 * The default optimization level is 3.
105 */
106 public static final int CREATE_FLAG_OPT_LEVEL_0 = 0x0010;
107
Tim Murray56f9e6f2014-05-16 11:47:26 -0700108 /*
109 * Detect the bitness of the VM to allow FieldPacker to do the right thing.
110 */
111 static native int rsnSystemGetPointerSize();
112 static int sPointerSize;
113
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700114 static {
115 sInitialized = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700116 if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
117 try {
Tim Murray2f2472c2013-08-22 14:55:26 -0700118 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
119 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
120 sRuntime = get_runtime.invoke(null);
121 registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
122 registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
123 } catch (Exception e) {
124 Log.e(LOG_TAG, "Error loading GC methods: " + e);
125 throw new RSRuntimeException("Error loading GC methods: " + e);
126 }
127 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700128 System.loadLibrary("rs_jni");
129 _nInit();
130 sInitialized = true;
Tim Murray56f9e6f2014-05-16 11:47:26 -0700131 sPointerSize = rsnSystemGetPointerSize();
Dan Morrille4d9a012013-03-28 18:10:43 -0700132 } catch (UnsatisfiedLinkError e) {
133 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
134 throw new RSRuntimeException("Error loading RS jni library: " + e);
135 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700136 }
137 }
138
Jason Sams2e1872f2010-08-17 16:25:41 -0700139 // Non-threadsafe functions.
Tim Murrayeff663f2013-11-15 13:08:30 -0800140 native long nDeviceCreate();
141 native void nDeviceDestroy(long dev);
142 native void nDeviceSetConfig(long dev, int param, int value);
143 native int nContextGetUserMessage(long con, int[] data);
144 native String nContextGetErrorMessage(long con);
145 native int nContextPeekMessage(long con, int[] subID);
146 native void nContextInitToClient(long con);
147 native void nContextDeinitToClient(long con);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700148
Tim Murray67cc2d02014-02-06 16:39:38 -0800149 // this should be a monotonically increasing ID
150 // used in conjunction with the API version of a device
Jason Samsf7642302015-05-12 14:06:56 -0700151 static final long sMinorVersion = 1;
Tim Murray67cc2d02014-02-06 16:39:38 -0800152
153 /**
Miao Wangf9d518a2015-05-14 14:53:30 -0700154 * @hide
155 *
156 * Only exist to be compatible with old version RenderScript Support lib.
157 * Will eventually be removed.
158 *
159 * @return Always return 1
160 *
161 */
162 public static long getMinorID() {
163 return 1;
164 }
165
166
167 /**
Tim Murray67cc2d02014-02-06 16:39:38 -0800168 * Returns an identifier that can be used to identify a particular
169 * minor version of RS.
170 *
Jason Sams6a420b52015-03-30 15:31:26 -0700171 * @return The minor RenderScript version number
172 *
Tim Murray67cc2d02014-02-06 16:39:38 -0800173 */
Jason Samsf7642302015-05-12 14:06:56 -0700174 public static long getMinorVersion() {
175 return sMinorVersion;
Tim Murray67cc2d02014-02-06 16:39:38 -0800176 }
177
Jason Sams02d56d92013-04-12 16:40:50 -0700178 /**
179 * ContextType specifies the specific type of context to be created.
180 *
181 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800182 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700183 /**
184 * NORMAL context, this is the default and what shipping apps should
185 * use.
186 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800187 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700188
189 /**
190 * DEBUG context, perform extra runtime checks to validate the
191 * kernels and APIs are being used as intended. Get and SetElementAt
192 * will be bounds checked in this mode.
193 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800194 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700195
196 /**
197 * PROFILE context, Intended to be used once the first time an
198 * application is run on a new device. This mode allows the runtime to
199 * do additional testing and performance tuning.
200 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800201 PROFILE (2);
202
203 int mID;
204 ContextType(int id) {
205 mID = id;
206 }
207 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800208
Stephen Hines42028a82013-04-17 19:22:01 -0700209 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800210 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700211
Jason Sams2e1872f2010-08-17 16:25:41 -0700212 // Methods below are wrapped to protect the non-threadsafe
213 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800214 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700215 int colorMin, int colorPref,
216 int alphaMin, int alphaPref,
217 int depthMin, int depthPref,
218 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700219 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800220 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700221 int colorMin, int colorPref,
222 int alphaMin, int alphaPref,
223 int depthMin, int depthPref,
224 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700225 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700226 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700227 alphaMin, alphaPref, depthMin, depthPref,
228 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700229 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700230 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800231 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
232 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800233 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700234 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800235 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700236 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800237 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800238
239 // take teardown lock
240 // teardown lock can only be taken when no objects are being destroyed
241 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
242 wlock.lock();
243
244 long curCon = mContext;
245 // context is considered dead as of this point
246 mContext = 0;
247
248 wlock.unlock();
249 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700250 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800251 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700252 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800253 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700254 rsnContextSetSurface(mContext, w, h, sur);
255 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800256 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700257 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
258 validate();
259 rsnContextSetSurfaceTexture(mContext, w, h, sur);
260 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800261 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700262 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800263 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700264 rsnContextSetPriority(mContext, p);
265 }
Tim Murray47f31582015-04-07 15:43:24 -0700266 native void rsnContextSetCacheDir(long con, String cacheDir);
267 synchronized void nContextSetCacheDir(String cacheDir) {
268 validate();
269 rsnContextSetCacheDir(mContext, cacheDir);
270 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800271 native void rsnContextDump(long con, int bits);
Jason Sams2e1872f2010-08-17 16:25:41 -0700272 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800273 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700274 rsnContextDump(mContext, bits);
275 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800276 native void rsnContextFinish(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700277 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800278 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700279 rsnContextFinish(mContext);
280 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700281
Tim Murrayeff663f2013-11-15 13:08:30 -0800282 native void rsnContextSendMessage(long con, int id, int[] data);
Jason Sams455d6442013-02-05 19:20:18 -0800283 synchronized void nContextSendMessage(int id, int[] data) {
284 validate();
285 rsnContextSendMessage(mContext, id, data);
286 }
287
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000288 native void rsnContextBindRootScript(long con, long script);
289 synchronized void nContextBindRootScript(long script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800290 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700291 rsnContextBindRootScript(mContext, script);
292 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800293 native void rsnContextBindSampler(long con, int sampler, int slot);
Jason Sams2e1872f2010-08-17 16:25:41 -0700294 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800295 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700296 rsnContextBindSampler(mContext, sampler, slot);
297 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000298 native void rsnContextBindProgramStore(long con, long pfs);
299 synchronized void nContextBindProgramStore(long pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800300 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700301 rsnContextBindProgramStore(mContext, pfs);
302 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000303 native void rsnContextBindProgramFragment(long con, long pf);
304 synchronized void nContextBindProgramFragment(long pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800305 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700306 rsnContextBindProgramFragment(mContext, pf);
307 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000308 native void rsnContextBindProgramVertex(long con, long pv);
309 synchronized void nContextBindProgramVertex(long pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800310 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700311 rsnContextBindProgramVertex(mContext, pv);
312 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000313 native void rsnContextBindProgramRaster(long con, long pr);
314 synchronized void nContextBindProgramRaster(long pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800315 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700316 rsnContextBindProgramRaster(mContext, pr);
317 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800318 native void rsnContextPause(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700319 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800320 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700321 rsnContextPause(mContext);
322 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800323 native void rsnContextResume(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700324 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800325 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700326 rsnContextResume(mContext);
327 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700328
Yang Ni281c3252014-10-24 08:52:24 -0700329 native long rsnClosureCreate(long con, long kernelID, long returnValue,
330 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
331 long[] depFieldIDs);
332 synchronized long nClosureCreate(long kernelID, long returnValue,
333 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
334 long[] depFieldIDs) {
335 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700336 long c = rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
Yang Ni281c3252014-10-24 08:52:24 -0700337 sizes, depClosures, depFieldIDs);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700338 if (c == 0) {
339 throw new RSRuntimeException("Failed creating closure.");
340 }
341 return c;
Yang Ni281c3252014-10-24 08:52:24 -0700342 }
343
Yang Nibe392ad2015-01-23 17:16:02 -0800344 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
345 long[] fieldIDs, long[] values, int[] sizes);
346 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
347 long[] fieldIDs, long[] values, int[] sizes) {
348 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700349 long c = rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
Yang Nibe392ad2015-01-23 17:16:02 -0800350 values, sizes);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700351 if (c == 0) {
352 throw new RSRuntimeException("Failed creating closure.");
353 }
354 return c;
Yang Nibe392ad2015-01-23 17:16:02 -0800355 }
356
Yang Ni281c3252014-10-24 08:52:24 -0700357 native void rsnClosureSetArg(long con, long closureID, int index,
358 long value, int size);
359 synchronized void nClosureSetArg(long closureID, int index, long value,
360 int size) {
361 validate();
362 rsnClosureSetArg(mContext, closureID, index, value, size);
363 }
364
365 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
366 long value, int size);
367 // Does this have to be synchronized?
368 synchronized void nClosureSetGlobal(long closureID, long fieldID,
369 long value, int size) {
370 validate(); // TODO: is this necessary?
371 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
372 }
373
Yang Ni35be56c2015-04-02 17:47:56 -0700374 native long rsnScriptGroup2Create(long con, String name, String cachePath,
375 long[] closures);
376 synchronized long nScriptGroup2Create(String name, String cachePath,
377 long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700378 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700379 long g = rsnScriptGroup2Create(mContext, name, cachePath, closures);
380 if (g == 0) {
381 throw new RSRuntimeException("Failed creating script group.");
382 }
383 return g;
Yang Ni281c3252014-10-24 08:52:24 -0700384 }
385
386 native void rsnScriptGroup2Execute(long con, long groupID);
387 synchronized void nScriptGroup2Execute(long groupID) {
388 validate();
389 rsnScriptGroup2Execute(mContext, groupID);
390 }
391
Tim Murray460a0492013-11-19 12:45:54 -0800392 native void rsnAssignName(long con, long obj, byte[] name);
393 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800394 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700395 rsnAssignName(mContext, obj, name);
396 }
Tim Murray460a0492013-11-19 12:45:54 -0800397 native String rsnGetName(long con, long obj);
398 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800399 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700400 return rsnGetName(mContext, obj);
401 }
Tim Murray06b45672014-01-07 11:13:56 -0800402
403 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800404 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800405 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800406 // There is a race condition here. The calling code may be run
407 // by the gc while teardown is occuring. This protects againts
408 // deleting dead objects.
409 if (mContext != 0) {
410 rsnObjDestroy(mContext, id);
411 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700412 }
Jason Samsfe08d992009-05-27 14:45:32 -0700413
Tim Murray460a0492013-11-19 12:45:54 -0800414 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
415 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800416 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700417 return rsnElementCreate(mContext, type, kind, norm, vecSize);
418 }
Ashok Bhat98071552014-02-12 09:54:43 +0000419 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
420 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800421 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700422 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700423 }
Tim Murray460a0492013-11-19 12:45:54 -0800424 native void rsnElementGetNativeData(long con, long id, int[] elementData);
425 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800426 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700427 rsnElementGetNativeData(mContext, id, elementData);
428 }
Tim Murray460a0492013-11-19 12:45:54 -0800429 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000430 long[] IDs, String[] names, int[] arraySizes);
431 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800432 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700433 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700434 }
Jason Sams768bc022009-09-21 19:41:04 -0700435
Tim Murray460a0492013-11-19 12:45:54 -0800436 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
437 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800438 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800439 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700440 }
Ashok Bhat98071552014-02-12 09:54:43 +0000441 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
442 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800443 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700444 rsnTypeGetNativeData(mContext, id, typeData);
445 }
Jason Sams768bc022009-09-21 19:41:04 -0700446
Ashok Bhat98071552014-02-12 09:54:43 +0000447 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
448 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800449 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800450 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700451 }
Tim Murray460a0492013-11-19 12:45:54 -0800452 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
453 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800454 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800455 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700456 }
Tim Murraya3145512012-12-04 17:59:29 -0800457
Tim Murray460a0492013-11-19 12:45:54 -0800458 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
459 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800460 validate();
461 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
462 }
463
Tim Murray460a0492013-11-19 12:45:54 -0800464 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
465 synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800466 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800467 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800468 }
Tim Murray460a0492013-11-19 12:45:54 -0800469 native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
470 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800471 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700472 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
473 }
Tim Murray460a0492013-11-19 12:45:54 -0800474 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
475 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800476 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800477 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
478 }
479
Tim Murray460a0492013-11-19 12:45:54 -0800480 native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
481 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800482 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800483 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
484 }
485
486
Tim Murray460a0492013-11-19 12:45:54 -0800487 native void rsnAllocationSyncAll(long con, long alloc, int src);
488 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800489 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800490 rsnAllocationSyncAll(mContext, alloc, src);
491 }
Tim Murray460a0492013-11-19 12:45:54 -0800492 native Surface rsnAllocationGetSurface(long con, long alloc);
493 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800494 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800495 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700496 }
Tim Murray460a0492013-11-19 12:45:54 -0800497 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
498 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800499 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700500 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800501 }
Tim Murray460a0492013-11-19 12:45:54 -0800502 native void rsnAllocationIoSend(long con, long alloc);
503 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800504 validate();
505 rsnAllocationIoSend(mContext, alloc);
506 }
Tim Murray460a0492013-11-19 12:45:54 -0800507 native void rsnAllocationIoReceive(long con, long alloc);
508 synchronized void nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800509 validate();
510 rsnAllocationIoReceive(mContext, alloc);
511 }
512
Jason Sams615e7ce2012-01-13 14:01:20 -0800513
Tim Murray460a0492013-11-19 12:45:54 -0800514 native void rsnAllocationGenerateMipmaps(long con, long alloc);
515 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800516 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800517 rsnAllocationGenerateMipmaps(mContext, alloc);
518 }
Tim Murray460a0492013-11-19 12:45:54 -0800519 native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
520 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800521 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800522 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700523 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700524
Jason Sams49a05d72010-12-29 14:31:29 -0800525
Miao Wang87e908d2015-03-02 15:15:15 -0800526 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
527 int mSize, boolean usePadding);
528 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
529 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800530 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800531 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700532 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700533
Miao Wangc8e237e2015-02-20 18:36:32 -0800534 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
535 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 -0800536 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800537 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700538 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700539
Tim Murrayeff663f2013-11-15 13:08:30 -0800540 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800541 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700542 int dstMip, int dstFace,
543 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800544 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700545 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800546 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700547 int dstMip, int dstFace,
548 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800549 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700550 int srcMip, int srcFace) {
551 validate();
552 rsnAllocationData2D(mContext,
553 dstAlloc, dstXoff, dstYoff,
554 dstMip, dstFace,
555 width, height,
556 srcAlloc, srcXoff, srcYoff,
557 srcMip, srcFace);
558 }
559
Tim Murray460a0492013-11-19 12:45:54 -0800560 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800561 int w, int h, Object d, int sizeBytes, int dt,
562 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800563 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800564 int w, int h, Object d, int sizeBytes, Element.DataType dt,
565 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800566 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800567 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700568 }
Jason Sams21659ac2013-11-06 15:08:07 -0800569
Tim Murray460a0492013-11-19 12:45:54 -0800570 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
571 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800572 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800573 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
574 }
Jason Sams49a05d72010-12-29 14:31:29 -0800575
Tim Murrayeff663f2013-11-15 13:08:30 -0800576 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800577 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700578 int dstMip,
579 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800580 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700581 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800582 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700583 int dstMip,
584 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800585 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700586 int srcMip) {
587 validate();
588 rsnAllocationData3D(mContext,
589 dstAlloc, dstXoff, dstYoff, dstZoff,
590 dstMip, width, height, depth,
591 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
592 }
593
Tim Murray460a0492013-11-19 12:45:54 -0800594 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800595 int w, int h, int depth, Object d, int sizeBytes, int dt,
596 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800597 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800598 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
599 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700600 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800601 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
602 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700603 }
Jason Samsb05d6892013-04-09 15:59:24 -0700604
Miao Wang87e908d2015-03-02 15:15:15 -0800605 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
606 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800607 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800608 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800609 }
Jason Sams21659ac2013-11-06 15:08:07 -0800610
Tim Murray460a0492013-11-19 12:45:54 -0800611 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800612 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800613 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800614 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800615 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800616 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800617 }
Jason Sams21659ac2013-11-06 15:08:07 -0800618
Miao Wangc8e237e2015-02-20 18:36:32 -0800619 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800620 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800621 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800622 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800623 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800624 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800625 }
626
Tim Murray460a0492013-11-19 12:45:54 -0800627 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800628 int w, int h, Object d, int sizeBytes, int dt,
629 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800630 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800631 int w, int h, Object d, int sizeBytes, Element.DataType dt,
632 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800633 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800634 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700635 }
Jason Sams21659ac2013-11-06 15:08:07 -0800636
Miao Wangc8e237e2015-02-20 18:36:32 -0800637 native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800638 int w, int h, int depth, Object d, int sizeBytes, int dt,
639 int mSize, boolean usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800640 synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800641 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
642 int mSize, boolean usePadding) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800643 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800644 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800645 }
646
Tim Murray460a0492013-11-19 12:45:54 -0800647 native long rsnAllocationGetType(long con, long id);
648 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800649 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700650 return rsnAllocationGetType(mContext, id);
651 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700652
Tim Murray460a0492013-11-19 12:45:54 -0800653 native void rsnAllocationResize1D(long con, long id, int dimX);
654 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800655 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700656 rsnAllocationResize1D(mContext, id, dimX);
657 }
Jason Sams5edc6082010-10-05 13:32:49 -0700658
Jason Sams46ba27e32015-02-06 17:45:15 -0800659 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
660 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
661 validate();
662 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
663 }
664
665 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
666 int mip, int face, int a1, int a2, int a3, int a4);
667 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
668 int mip, int face, int a1, int a2, int a3, int a4) {
669 validate();
670 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
671 }
672
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000673 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
674 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800675 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700676 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
677 }
Tim Murray460a0492013-11-19 12:45:54 -0800678 native long rsnFileA3DCreateFromFile(long con, String path);
679 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800680 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800681 return rsnFileA3DCreateFromFile(mContext, path);
682 }
Tim Murray460a0492013-11-19 12:45:54 -0800683 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
684 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800685 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800686 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
687 }
Tim Murray460a0492013-11-19 12:45:54 -0800688 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
689 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800690 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700691 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
692 }
Tim Murray460a0492013-11-19 12:45:54 -0800693 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
694 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800695 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700696 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
697 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000698 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
699 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800700 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700701 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
702 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700703
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000704 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
705 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800706 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700707 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
708 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000709 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
710 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800711 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800712 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
713 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000714 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
715 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800716 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800717 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
718 }
Jason Sams22534172009-08-04 16:58:20 -0700719
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700720
Tim Murray460a0492013-11-19 12:45:54 -0800721 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
722 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800723 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700724 rsnScriptBindAllocation(mContext, script, alloc, slot);
725 }
Tim Murray460a0492013-11-19 12:45:54 -0800726 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
727 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800728 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700729 rsnScriptSetTimeZone(mContext, script, timeZone);
730 }
Tim Murray460a0492013-11-19 12:45:54 -0800731 native void rsnScriptInvoke(long con, long id, int slot);
732 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800733 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700734 rsnScriptInvoke(mContext, id, slot);
735 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700736
737 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
738 long aout, byte[] params, int[] limits);
739
740 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
741 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700742 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700743 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700744 }
745
Matt Wala36eb1f72015-07-20 15:35:27 -0700746 native void rsnScriptReduce(long con, long id, int slot, long ain,
747 long aout, int[] limits);
748 synchronized void nScriptReduce(long id, int slot, long ain, long aout,
749 int[] limits) {
750 validate();
751 rsnScriptReduce(mContext, id, slot, ain, aout, limits);
752 }
753
Tim Murray460a0492013-11-19 12:45:54 -0800754 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
755 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800756 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700757 rsnScriptInvokeV(mContext, id, slot, params);
758 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700759
Tim Murray460a0492013-11-19 12:45:54 -0800760 native void rsnScriptSetVarI(long con, long id, int slot, int val);
761 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800762 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700763 rsnScriptSetVarI(mContext, id, slot, val);
764 }
Tim Murray460a0492013-11-19 12:45:54 -0800765 native int rsnScriptGetVarI(long con, long id, int slot);
766 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700767 validate();
768 return rsnScriptGetVarI(mContext, id, slot);
769 }
770
Tim Murray460a0492013-11-19 12:45:54 -0800771 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
772 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800773 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700774 rsnScriptSetVarJ(mContext, id, slot, val);
775 }
Tim Murray460a0492013-11-19 12:45:54 -0800776 native long rsnScriptGetVarJ(long con, long id, int slot);
777 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700778 validate();
779 return rsnScriptGetVarJ(mContext, id, slot);
780 }
781
Tim Murray460a0492013-11-19 12:45:54 -0800782 native void rsnScriptSetVarF(long con, long id, int slot, float val);
783 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800784 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700785 rsnScriptSetVarF(mContext, id, slot, val);
786 }
Tim Murray460a0492013-11-19 12:45:54 -0800787 native float rsnScriptGetVarF(long con, long id, int slot);
788 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700789 validate();
790 return rsnScriptGetVarF(mContext, id, slot);
791 }
Tim Murray460a0492013-11-19 12:45:54 -0800792 native void rsnScriptSetVarD(long con, long id, int slot, double val);
793 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800794 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700795 rsnScriptSetVarD(mContext, id, slot, val);
796 }
Tim Murray460a0492013-11-19 12:45:54 -0800797 native double rsnScriptGetVarD(long con, long id, int slot);
798 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700799 validate();
800 return rsnScriptGetVarD(mContext, id, slot);
801 }
Tim Murray460a0492013-11-19 12:45:54 -0800802 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
803 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800804 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700805 rsnScriptSetVarV(mContext, id, slot, val);
806 }
Tim Murray460a0492013-11-19 12:45:54 -0800807 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
808 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700809 validate();
810 rsnScriptGetVarV(mContext, id, slot, val);
811 }
Tim Murray460a0492013-11-19 12:45:54 -0800812 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
813 long e, int[] dims);
814 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
815 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700816 validate();
817 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
818 }
Tim Murray460a0492013-11-19 12:45:54 -0800819 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
820 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800821 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800822 rsnScriptSetVarObj(mContext, id, slot, val);
823 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700824
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000825 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700826 byte[] script, int length);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000827 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800828 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700829 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700830 }
Jason Samsebfb4362009-09-23 13:57:02 -0700831
Tim Murray460a0492013-11-19 12:45:54 -0800832 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
833 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700834 validate();
835 return rsnScriptIntrinsicCreate(mContext, id, eid);
836 }
837
Tim Murray460a0492013-11-19 12:45:54 -0800838 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
839 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700840 validate();
841 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
842 }
843
Yang Nibe392ad2015-01-23 17:16:02 -0800844 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
845 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
846 validate();
847 return rsnScriptInvokeIDCreate(mContext, sid, slot);
848 }
849
Tim Murray460a0492013-11-19 12:45:54 -0800850 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
851 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700852 validate();
853 return rsnScriptFieldIDCreate(mContext, sid, slot);
854 }
855
Ashok Bhat98071552014-02-12 09:54:43 +0000856 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
857 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700858 validate();
859 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
860 }
861
Tim Murray460a0492013-11-19 12:45:54 -0800862 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
863 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700864 validate();
865 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
866 }
867
Tim Murray460a0492013-11-19 12:45:54 -0800868 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
869 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700870 validate();
871 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
872 }
873
Tim Murray460a0492013-11-19 12:45:54 -0800874 native void rsnScriptGroupExecute(long con, long group);
875 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700876 validate();
877 rsnScriptGroupExecute(mContext, group);
878 }
879
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000880 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700881 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000882 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700883 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800884 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700885 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700886 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800887
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000888 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700889 boolean depthMask, boolean dither,
890 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000891 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700892 boolean depthMask, boolean dither,
893 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800894 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700895 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
896 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700897 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700898
Tim Murray460a0492013-11-19 12:45:54 -0800899 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
900 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800901 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700902 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700903 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700904
Tim Murray460a0492013-11-19 12:45:54 -0800905 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
906 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800907 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700908 rsnProgramBindConstants(mContext, pv, slot, mID);
909 }
Tim Murray460a0492013-11-19 12:45:54 -0800910 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
911 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800912 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700913 rsnProgramBindTexture(mContext, vpf, slot, a);
914 }
Tim Murray460a0492013-11-19 12:45:54 -0800915 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
916 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800917 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700918 rsnProgramBindSampler(mContext, vpf, slot, s);
919 }
Ashok Bhat98071552014-02-12 09:54:43 +0000920 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
921 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800922 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800923 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700924 }
Ashok Bhat98071552014-02-12 09:54:43 +0000925 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
926 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800927 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800928 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700929 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700930
Ashok Bhat98071552014-02-12 09:54:43 +0000931 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
932 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800933 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700934 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800935 }
Tim Murray460a0492013-11-19 12:45:54 -0800936 native int rsnMeshGetVertexBufferCount(long con, long id);
937 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800938 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700939 return rsnMeshGetVertexBufferCount(mContext, id);
940 }
Tim Murray460a0492013-11-19 12:45:54 -0800941 native int rsnMeshGetIndexCount(long con, long id);
942 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800943 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700944 return rsnMeshGetIndexCount(mContext, id);
945 }
Ashok Bhat98071552014-02-12 09:54:43 +0000946 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
947 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800948 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700949 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
950 }
Ashok Bhat98071552014-02-12 09:54:43 +0000951 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
952 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800953 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700954 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
955 }
956
Tim Murray25207df2015-01-12 16:47:56 -0800957 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
958 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
959 float alpha, long A, long B, float beta, long C, int incX, int incY,
960 int KL, int KU);
961 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
962 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
963 float alpha, long A, long B, float beta, long C, int incX, int incY,
964 int KL, int KU) {
965 validate();
966 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
967 }
968
969 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
970 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
971 double alpha, long A, long B, double beta, long C, int incX, int incY,
972 int KL, int KU);
973 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
974 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
975 double alpha, long A, long B, double beta, long C, int incX, int incY,
976 int KL, int KU) {
977 validate();
978 rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
979 }
980
981 native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA,
982 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
983 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
984 int KL, int KU);
985 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
986 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
987 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
988 int KL, int KU) {
989 validate();
990 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
991 }
992
993 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
994 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
995 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
996 int KL, int KU);
997 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
998 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
999 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
1000 int KL, int KU) {
1001 validate();
1002 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
1003 }
1004
Tim Murray9cb16a22015-04-01 11:07:16 -07001005 native void rsnScriptIntrinsicBLAS_BNNM(long con, long id, int M, int N, int K,
1006 long A, int a_offset, long B, int b_offset, long C, int c_offset,
1007 int c_mult_int);
1008 synchronized void nScriptIntrinsicBLAS_BNNM(long id, int M, int N, int K,
1009 long A, int a_offset, long B, int b_offset, long C, int c_offset,
1010 int c_mult_int) {
1011 validate();
1012 rsnScriptIntrinsicBLAS_BNNM(mContext, id, M, N, K, A, a_offset, B, b_offset, C, c_offset, c_mult_int);
1013 }
1014
1015
Tim Murray25207df2015-01-12 16:47:56 -08001016
Tim Murrayeff663f2013-11-15 13:08:30 -08001017 long mDev;
1018 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -08001019 private boolean mDestroyed = false;
1020
Romain Guy650a3eb2009-08-31 14:06:43 -07001021 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001022 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001023
Jason Sams8cb39de2010-06-01 15:47:01 -07001024 Element mElement_U8;
1025 Element mElement_I8;
1026 Element mElement_U16;
1027 Element mElement_I16;
1028 Element mElement_U32;
1029 Element mElement_I32;
Stephen Hines52d83632010-10-11 16:10:42 -07001030 Element mElement_U64;
Stephen Hinesef1dac22010-10-01 15:39:33 -07001031 Element mElement_I64;
Jason Samsa5835a22014-11-05 15:16:26 -08001032 Element mElement_F16;
Jason Sams8cb39de2010-06-01 15:47:01 -07001033 Element mElement_F32;
Stephen Hines02f417052010-09-30 15:19:22 -07001034 Element mElement_F64;
Jason Samsf110d4b2010-06-21 17:42:41 -07001035 Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -07001036
Jason Sams8cb39de2010-06-01 15:47:01 -07001037 Element mElement_ELEMENT;
1038 Element mElement_TYPE;
1039 Element mElement_ALLOCATION;
1040 Element mElement_SAMPLER;
1041 Element mElement_SCRIPT;
1042 Element mElement_MESH;
1043 Element mElement_PROGRAM_FRAGMENT;
1044 Element mElement_PROGRAM_VERTEX;
1045 Element mElement_PROGRAM_RASTER;
1046 Element mElement_PROGRAM_STORE;
Stephen Hines3a291412012-04-11 17:27:29 -07001047 Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -07001048
Jason Sams3c0dfba2009-09-27 17:50:38 -07001049 Element mElement_A_8;
1050 Element mElement_RGB_565;
1051 Element mElement_RGB_888;
1052 Element mElement_RGBA_5551;
1053 Element mElement_RGBA_4444;
1054 Element mElement_RGBA_8888;
1055
Jason Samsa5835a22014-11-05 15:16:26 -08001056 Element mElement_HALF_2;
1057 Element mElement_HALF_3;
1058 Element mElement_HALF_4;
1059
Jason Sams8cb39de2010-06-01 15:47:01 -07001060 Element mElement_FLOAT_2;
1061 Element mElement_FLOAT_3;
1062 Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001063
1064 Element mElement_DOUBLE_2;
1065 Element mElement_DOUBLE_3;
1066 Element mElement_DOUBLE_4;
1067
1068 Element mElement_UCHAR_2;
1069 Element mElement_UCHAR_3;
Jason Sams8cb39de2010-06-01 15:47:01 -07001070 Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001071
Stephen Hines836c4a52011-06-01 14:38:10 -07001072 Element mElement_CHAR_2;
1073 Element mElement_CHAR_3;
1074 Element mElement_CHAR_4;
1075
1076 Element mElement_USHORT_2;
1077 Element mElement_USHORT_3;
1078 Element mElement_USHORT_4;
1079
1080 Element mElement_SHORT_2;
1081 Element mElement_SHORT_3;
1082 Element mElement_SHORT_4;
1083
1084 Element mElement_UINT_2;
1085 Element mElement_UINT_3;
1086 Element mElement_UINT_4;
1087
1088 Element mElement_INT_2;
1089 Element mElement_INT_3;
1090 Element mElement_INT_4;
1091
1092 Element mElement_ULONG_2;
1093 Element mElement_ULONG_3;
1094 Element mElement_ULONG_4;
1095
1096 Element mElement_LONG_2;
1097 Element mElement_LONG_3;
1098 Element mElement_LONG_4;
1099
Tim Murray932e78e2013-09-03 11:42:26 -07001100 Element mElement_YUV;
1101
Jason Sams1d45c472010-08-25 14:31:48 -07001102 Element mElement_MATRIX_4X4;
1103 Element mElement_MATRIX_3X3;
1104 Element mElement_MATRIX_2X2;
1105
Jason Sams4d339932010-05-11 14:03:58 -07001106 Sampler mSampler_CLAMP_NEAREST;
1107 Sampler mSampler_CLAMP_LINEAR;
1108 Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1109 Sampler mSampler_WRAP_NEAREST;
1110 Sampler mSampler_WRAP_LINEAR;
1111 Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
Tim Murray6b9b2ca2013-02-15 13:25:55 -08001112 Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1113 Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1114 Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001115
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001116 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1117 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001118 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1119 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001120
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001121 ProgramRaster mProgramRaster_CULL_BACK;
1122 ProgramRaster mProgramRaster_CULL_FRONT;
1123 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001124
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001125 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001126 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001127
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001128 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001129 * The base class from which an application should derive in order
1130 * to receive RS messages from scripts. When a script calls {@code
1131 * rsSendToClient}, the data fields will be filled, and the run
1132 * method will be called on a separate thread. This will occur
1133 * some time after {@code rsSendToClient} completes in the script,
1134 * as {@code rsSendToClient} is asynchronous. Message handlers are
1135 * not guaranteed to have completed when {@link
1136 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001137 *
1138 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001139 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001140 protected int[] mData;
1141 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001142 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001143 public void run() {
1144 }
1145 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001146 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001147 * If an application is expecting messages, it should set this
1148 * field to an instance of {@link RSMessageHandler}. This
1149 * instance will receive all the user messages sent from {@code
1150 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001151 *
1152 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001153 RSMessageHandler mMessageCallback = null;
1154
1155 public void setMessageHandler(RSMessageHandler msg) {
1156 mMessageCallback = msg;
1157 }
1158 public RSMessageHandler getMessageHandler() {
1159 return mMessageCallback;
1160 }
Jason Sams516c3192009-10-06 13:58:47 -07001161
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001162 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001163 * Place a message into the message queue to be sent back to the message
1164 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001165 *
1166 * @param id
1167 * @param data
1168 */
1169 public void sendMessage(int id, int[] data) {
1170 nContextSendMessage(id, data);
1171 }
1172
1173 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001174 * The runtime error handler base class. An application should derive from this class
1175 * if it wishes to install an error handler. When errors occur at runtime,
1176 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001177 *
1178 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001179 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001180 protected String mErrorMessage;
1181 protected int mErrorNum;
1182 public void run() {
1183 }
1184 }
Jason Sams27676fe2010-11-10 17:00:59 -08001185
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001186 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001187 * Application Error handler. All runtime errors will be dispatched to the
1188 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001189 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001190 * This will cause program termaination.
1191 *
1192 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001193 RSErrorHandler mErrorCallback = null;
1194
1195 public void setErrorHandler(RSErrorHandler msg) {
1196 mErrorCallback = msg;
1197 }
1198 public RSErrorHandler getErrorHandler() {
1199 return mErrorCallback;
1200 }
Jason Sams1c415172010-11-08 17:06:46 -08001201
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001202 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001203 * RenderScript worker thread priority enumeration. The default value is
1204 * NORMAL. Applications wishing to do background processing should set
1205 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001206 */
Jason Sams7d787b42009-11-15 12:14:26 -08001207 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001208 // These values used to represent official thread priority values
1209 // now they are simply enums to be used by the runtime side
1210 LOW (15),
1211 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001212
1213 int mID;
1214 Priority(int id) {
1215 mID = id;
1216 }
1217 }
1218
Jason Sams678cc7f2014-03-05 16:09:02 -08001219 void validateObject(BaseObj o) {
1220 if (o != null) {
1221 if (o.mRS != this) {
1222 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1223 }
1224 }
1225 }
1226
Jason Sams771bebb2009-12-07 12:40:12 -08001227 void validate() {
1228 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001229 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001230 }
1231 }
1232
Jason Sams27676fe2010-11-10 17:00:59 -08001233
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001234 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001235 * Change the priority of the worker threads for this context.
1236 *
1237 * @param p New priority to be set.
1238 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001239 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001240 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001241 nContextSetPriority(p.mID);
1242 }
1243
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001244 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001245 RenderScript mRS;
1246 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001247 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001248
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001249 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1250 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1251 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1252 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1253 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001254 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001255
Stephen Hines42028a82013-04-17 19:22:01 -07001256 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001257 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001258
Jason Sams516c3192009-10-06 13:58:47 -07001259 MessageThread(RenderScript rs) {
1260 super("RSMessageThread");
1261 mRS = rs;
1262
1263 }
1264
1265 public void run() {
1266 // This function is a temporary solution. The final solution will
1267 // used typed allocations where the message id is the type indicator.
1268 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001269 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001270 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001271 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001272 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001273 int size = mAuxData[1];
1274 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001275
1276 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1277 if ((size>>2) >= rbuf.length) {
1278 rbuf = new int[(size + 3) >> 2];
1279 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001280 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1281 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001282 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001283 }
Jason Sams1c415172010-11-08 17:06:46 -08001284
1285 if(mRS.mMessageCallback != null) {
1286 mRS.mMessageCallback.mData = rbuf;
1287 mRS.mMessageCallback.mID = subID;
1288 mRS.mMessageCallback.mLength = size;
1289 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001290 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001291 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001292 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001293 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001294 }
Jason Sams1c415172010-11-08 17:06:46 -08001295
1296 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1297 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1298
Stephen Hines42028a82013-04-17 19:22:01 -07001299 // Throw RSRuntimeException under the following conditions:
1300 //
1301 // 1) It is an unknown fatal error.
1302 // 2) It is a debug fatal error, and we are not in a
1303 // debug context.
1304 // 3) It is a debug fatal error, and we do not have an
1305 // error callback.
1306 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1307 (subID >= RS_ERROR_FATAL_DEBUG &&
1308 (mRS.mContextType != ContextType.DEBUG ||
1309 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001310 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1311 }
1312
Jason Sams1c415172010-11-08 17:06:46 -08001313 if(mRS.mErrorCallback != null) {
1314 mRS.mErrorCallback.mErrorMessage = e;
1315 mRS.mErrorCallback.mErrorNum = subID;
1316 mRS.mErrorCallback.run();
1317 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001318 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001319 // Do not throw here. In these cases, we do not have
1320 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001321 }
1322 continue;
1323 }
1324
Jason Sams739c8262013-04-11 18:07:52 -07001325 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001326 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1327 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1328 throw new RSDriverException("Error processing message from RenderScript.");
1329 }
1330 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1331 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001332 continue;
1333 }
1334
Jason Sams1c415172010-11-08 17:06:46 -08001335 // 2: teardown.
1336 // But we want to avoid starving other threads during
1337 // teardown by yielding until the next line in the destructor
1338 // can execute to set mRun = false
1339 try {
1340 sleep(1, 0);
1341 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001342 }
Jason Sams516c3192009-10-06 13:58:47 -07001343 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001344 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001345 }
1346 }
1347
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001348 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001349 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001350 if (ctx != null) {
1351 mApplicationContext = ctx.getApplicationContext();
1352 }
Tim Murray06b45672014-01-07 11:13:56 -08001353 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001354 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001355 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001356 } catch (Exception e) {
1357 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1358 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1359 }
1360
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001361 }
1362
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001363 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001364 * Gets the application context associated with the RenderScript context.
1365 *
1366 * @return The application context.
1367 */
1368 public final Context getApplicationContext() {
1369 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001370 }
1371
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001372 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001373 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001374 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001375 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001376 * @return RenderScript
1377 */
Jason Samse16da122015-03-18 17:04:18 -07001378 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001379 if (!sInitialized) {
1380 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1381 return null;
1382 }
1383
verena beckhamc9659ea2015-05-22 16:47:53 +01001384 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER |
1385 CREATE_FLAG_WAIT_FOR_ATTACH | CREATE_FLAG_OPT_LEVEL_0)) != 0) {
Jason Samsb69c7912014-05-20 18:48:35 -07001386 throw new RSIllegalArgumentException("Invalid flags passed.");
1387 }
1388
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001389 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001390
1391 rs.mDev = rs.nDeviceCreate();
Tim Murrayfd710e72014-06-06 11:10:45 -07001392 rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001393 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001394 rs.mContextFlags = flags;
1395 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001396 if (rs.mContext == 0) {
1397 throw new RSDriverException("Failed to create RS context.");
1398 }
Tim Murray47f31582015-04-07 15:43:24 -07001399
1400 // set up cache directory for entire context
1401 final String CACHE_PATH = "com.android.renderscript.cache";
1402 File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
1403 String mCachePath = f.getAbsolutePath();
1404 f.mkdirs();
1405 rs.nContextSetCacheDir(mCachePath);
1406
Jason Sams704ff642010-02-09 16:05:07 -08001407 rs.mMessageThread = new MessageThread(rs);
1408 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001409 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001410 }
1411
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001412 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001413 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001414 *
1415 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001416 *
1417 * @param ctx The context.
1418 * @return RenderScript
1419 */
1420 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001421 return create(ctx, ContextType.NORMAL);
1422 }
1423
1424 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001425 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001426 *
Jason Samse16da122015-03-18 17:04:18 -07001427 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001428 *
1429 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001430 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001431 * @return RenderScript
1432 */
1433 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001434 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001435 }
1436
Miao Wanga4e5adf2015-03-23 11:09:56 -07001437
1438 /**
Jason Samse16da122015-03-18 17:04:18 -07001439 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001440 *
Jason Samse16da122015-03-18 17:04:18 -07001441 * The returned context will be cached for future reuse within
1442 * the process. When an application is finished using
1443 * RenderScript it should call releaseAllContexts()
1444 *
1445 * A process context is a context designed for easy creation and
1446 * lifecycle management. Multiple calls to this function will
1447 * return the same object provided they are called with the same
1448 * options. This allows it to be used any time a RenderScript
1449 * context is needed.
1450 *
1451 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001452 *
1453 * @param ctx The context.
1454 * @param ct The type of context to be created.
1455 * @param flags The OR of the CREATE_FLAG_* options desired
1456 * @return RenderScript
1457 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001458 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001459 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001460 return create(ctx, v, ct, flags);
1461 }
1462
1463 /**
1464 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1465 *
1466 * Used by the RenderScriptThunker to maintain backward compatibility.
1467 *
1468 * @hide
1469 * @param ctx The context.
1470 * @param sdkVersion The target SDK Version.
1471 * @return RenderScript
1472 */
1473 public static RenderScript create(Context ctx, int sdkVersion) {
1474 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1475 }
1476
1477 /**
1478 * Gets or creates a RenderScript context of the specified type.
1479 *
Miao Wanga4e5adf2015-03-23 11:09:56 -07001480 * @param ctx The context.
1481 * @param ct The type of context to be created.
1482 * @param sdkVersion The target SDK Version.
1483 * @param flags The OR of the CREATE_FLAG_* options desired
1484 * @return RenderScript
1485 */
Jason Sams6a420b52015-03-30 15:31:26 -07001486 private static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
Miao Wanga4e5adf2015-03-23 11:09:56 -07001487 if (sdkVersion < 23) {
1488 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001489 }
1490
1491 synchronized (mProcessContextList) {
1492 for (RenderScript prs : mProcessContextList) {
1493 if ((prs.mContextType == ct) &&
1494 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001495 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001496
1497 return prs;
1498 }
1499 }
1500
Miao Wanga4e5adf2015-03-23 11:09:56 -07001501 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001502 prs.mIsProcessContext = true;
1503 mProcessContextList.add(prs);
1504 return prs;
1505 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001506 }
1507
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001508 /**
Jason Samse16da122015-03-18 17:04:18 -07001509 * Releases all the process contexts. This is the same as
1510 * calling .destroy() on each unique context retreived with
1511 * create(...). If no contexts have been created this
1512 * function does nothing.
1513 *
1514 * Typically you call this when your application is losing focus
1515 * and will not be using a context for some time.
1516 *
1517 * This has no effect on a context created with
1518 * createMultiContext()
1519 */
1520 public static void releaseAllContexts() {
1521 ArrayList<RenderScript> oldList;
1522 synchronized (mProcessContextList) {
1523 oldList = mProcessContextList;
1524 mProcessContextList = new ArrayList<RenderScript>();
1525 }
1526
1527 for (RenderScript prs : oldList) {
1528 prs.mIsProcessContext = false;
1529 prs.destroy();
1530 }
1531 oldList.clear();
1532 }
1533
1534
1535
1536 /**
1537 * Create a RenderScript context.
1538 *
1539 * This is an advanced function intended for applications which
1540 * need to create more than one RenderScript context to be used
1541 * at the same time.
1542 *
1543 * If you need a single context please use create()
1544 *
Jason Samse16da122015-03-18 17:04:18 -07001545 * @param ctx The context.
1546 * @return RenderScript
1547 */
1548 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1549 return internalCreate(ctx, API_number, ct, flags);
1550 }
1551
1552
1553 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001554 * Print the currently available debugging information about the state of
1555 * the RS context to the log.
1556 *
Jason Sams27676fe2010-11-10 17:00:59 -08001557 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001558 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001559 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001560 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001561 }
1562
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001563 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001564 * Wait for any pending asynchronous opeations (such as copies to a RS
1565 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001566 *
1567 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001568 public void finish() {
1569 nContextFinish();
1570 }
1571
Jason Samsd22a6f02015-02-19 17:19:52 -08001572 private void helpDestroy() {
1573 boolean shouldDestroy = false;
1574 synchronized(this) {
1575 if (!mDestroyed) {
1576 shouldDestroy = true;
1577 mDestroyed = true;
1578 }
1579 }
1580
1581 if (shouldDestroy) {
1582 nContextFinish();
1583
1584 nContextDeinitToClient(mContext);
1585 mMessageThread.mRun = false;
1586 try {
1587 mMessageThread.join();
1588 } catch(InterruptedException e) {
1589 }
1590
1591 nContextDestroy();
1592
1593 nDeviceDestroy(mDev);
1594 mDev = 0;
1595 }
1596 }
1597
1598 protected void finalize() throws Throwable {
1599 helpDestroy();
1600 super.finalize();
1601 }
1602
1603
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001604 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001605 * Destroys this RenderScript context. Once this function is called,
1606 * using this context or any objects belonging to this context is
1607 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001608 *
Jason Samse16da122015-03-18 17:04:18 -07001609 * API 23+, this function is a NOP if the context was created
1610 * with create(). Please use releaseAllContexts() to clean up
1611 * contexts created with the create function.
1612 *
Jason Sams27676fe2010-11-10 17:00:59 -08001613 */
Jason Samsf5b45962009-08-25 14:49:07 -07001614 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001615 if (mIsProcessContext) {
1616 // users cannot destroy a process context
1617 return;
1618 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001619 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001620 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001621 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001622
Jason Samsa9e7a052009-09-25 14:51:22 -07001623 boolean isAlive() {
1624 return mContext != 0;
1625 }
1626
Tim Murray460a0492013-11-19 12:45:54 -08001627 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001628 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001629 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001630 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001631 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001632 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001633}