blob: 45f0ca61ff8048230e96c41b942d665d01d3ef2b [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
Jason Samsa6f338c2012-02-24 16:22:16 -080019import java.io.File;
Tim Murray2f2472c2013-08-22 14:55:26 -070020import java.lang.reflect.Method;
Tim Murray06b45672014-01-07 11:13:56 -080021import java.util.concurrent.locks.ReentrantReadWriteLock;
Jason Sams36e612a2009-07-31 16:26:13 -070022
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080023import android.content.Context;
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080024import android.content.res.AssetManager;
Jason Samsb8c5a842009-07-31 20:40:47 -070025import android.graphics.Bitmap;
Jason Samsfaa32b32011-06-20 16:58:04 -070026import android.graphics.SurfaceTexture;
Glenn Kasten260c77a2011-06-01 17:25:54 -070027import android.os.Process;
Jason Sams36e612a2009-07-31 16:26:13 -070028import android.util.Log;
29import android.view.Surface;
Dan Morrille4d9a012013-03-28 18:10:43 -070030import android.os.SystemProperties;
Tim Murray6d7a53c2013-05-23 16:59:23 -070031import android.os.Trace;
Jason Samse16da122015-03-18 17:04:18 -070032import java.util.ArrayList;
Stephen Hines4382467a2011-08-01 15:02:34 -070033
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070034/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070035 * This class provides access to a RenderScript context, which controls RenderScript
36 * initialization, resource management, and teardown. An instance of the RenderScript
37 * class must be created before any other RS objects can be created.
Jason Sams27676fe2010-11-10 17:00:59 -080038 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080039 * <div class="special reference">
40 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070041 * <p>For more information about creating an application that uses RenderScript, read the
42 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080043 * </div>
Jason Samse29d4712009-07-23 15:19:03 -070044 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070045public class RenderScript {
Tim Murray6d7a53c2013-05-23 16:59:23 -070046 static final long TRACE_TAG = Trace.TRACE_TAG_RS;
47
Jason Sams3bc47d42009-11-12 15:10:25 -080048 static final String LOG_TAG = "RenderScript_jni";
Jason Samsbf6ef8d72010-12-06 15:59:59 -080049 static final boolean DEBUG = false;
Romain Guy650a3eb2009-08-31 14:06:43 -070050 @SuppressWarnings({"UnusedDeclaration", "deprecation"})
Joe Onorato43a17652011-04-06 19:22:23 -070051 static final boolean LOG_ENABLED = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070052
Jason Samse16da122015-03-18 17:04:18 -070053 static private ArrayList<RenderScript> mProcessContextList = new ArrayList<RenderScript>();
54 private boolean mIsProcessContext = false;
55 private int mContextFlags = 0;
56 private int mContextSdkVersion = 0;
57
58
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080059 private Context mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070060
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080061 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070062 * We use a class initializer to allow the native code to cache some
63 * field offsets.
64 */
Dan Morrille4d9a012013-03-28 18:10:43 -070065 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
Jason Samsbf6ef8d72010-12-06 15:59:59 -080066 static boolean sInitialized;
67 native static void _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070068
Tim Murray2f2472c2013-08-22 14:55:26 -070069 static Object sRuntime;
70 static Method registerNativeAllocation;
71 static Method registerNativeFree;
Jason Samsdba3ba52009-07-30 14:56:12 -070072
Jason Sams26e90512014-05-07 14:23:27 -070073 /*
Tim Murrayfd710e72014-06-06 11:10:45 -070074 * Context creation flag that specifies a normal context.
Jason Sams26e90512014-05-07 14:23:27 -070075 */
Tim Murrayfd710e72014-06-06 11:10:45 -070076 public static final int CREATE_FLAG_NONE = 0x0000;
Jason Sams26e90512014-05-07 14:23:27 -070077
78 /*
79 * Context creation flag which specifies a context optimized for low
80 * latency over peak performance. This is a hint and may have no effect
81 * on some implementations.
82 */
Tim Murrayfd710e72014-06-06 11:10:45 -070083 public static final int CREATE_FLAG_LOW_LATENCY = 0x0002;
Jason Sams26e90512014-05-07 14:23:27 -070084
85 /*
86 * Context creation flag which specifies a context optimized for long
87 * battery life over peak performance. This is a hint and may have no effect
88 * on some implementations.
89 */
Tim Murrayfd710e72014-06-06 11:10:45 -070090 public static final int CREATE_FLAG_LOW_POWER = 0x0004;
Jason Sams26e90512014-05-07 14:23:27 -070091
Tim Murray56f9e6f2014-05-16 11:47:26 -070092 /*
93 * Detect the bitness of the VM to allow FieldPacker to do the right thing.
94 */
95 static native int rsnSystemGetPointerSize();
96 static int sPointerSize;
97
Jack Palevich60aa3ea2009-05-26 13:45:08 -070098 static {
99 sInitialized = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700100 if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
101 try {
Tim Murray2f2472c2013-08-22 14:55:26 -0700102 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
103 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
104 sRuntime = get_runtime.invoke(null);
105 registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
106 registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
107 } catch (Exception e) {
108 Log.e(LOG_TAG, "Error loading GC methods: " + e);
109 throw new RSRuntimeException("Error loading GC methods: " + e);
110 }
111 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700112 System.loadLibrary("rs_jni");
113 _nInit();
114 sInitialized = true;
Tim Murray56f9e6f2014-05-16 11:47:26 -0700115 sPointerSize = rsnSystemGetPointerSize();
Dan Morrille4d9a012013-03-28 18:10:43 -0700116 } catch (UnsatisfiedLinkError e) {
117 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
118 throw new RSRuntimeException("Error loading RS jni library: " + e);
119 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700120 }
121 }
122
Jason Sams2e1872f2010-08-17 16:25:41 -0700123 // Non-threadsafe functions.
Tim Murrayeff663f2013-11-15 13:08:30 -0800124 native long nDeviceCreate();
125 native void nDeviceDestroy(long dev);
126 native void nDeviceSetConfig(long dev, int param, int value);
127 native int nContextGetUserMessage(long con, int[] data);
128 native String nContextGetErrorMessage(long con);
129 native int nContextPeekMessage(long con, int[] subID);
130 native void nContextInitToClient(long con);
131 native void nContextDeinitToClient(long con);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700132
Stephen Hines7d25a822013-04-09 23:51:56 -0700133 static File mCacheDir;
Jason Samsa6f338c2012-02-24 16:22:16 -0800134
Tim Murray67cc2d02014-02-06 16:39:38 -0800135 // this should be a monotonically increasing ID
136 // used in conjunction with the API version of a device
137 static final long sMinorID = 1;
138
139 /**
140 * Returns an identifier that can be used to identify a particular
141 * minor version of RS.
142 *
143 * @hide
144 */
145 public static long getMinorID() {
146 return sMinorID;
147 }
148
Jason Samsa6f338c2012-02-24 16:22:16 -0800149 /**
150 * Sets the directory to use as a persistent storage for the
151 * renderscript object file cache.
152 *
153 * @hide
154 * @param cacheDir A directory the current process can write to
155 */
Jason Samsa6f338c2012-02-24 16:22:16 -0800156 public static void setupDiskCache(File cacheDir) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700157 if (!sInitialized) {
158 Log.e(LOG_TAG, "RenderScript.setupDiskCache() called when disabled");
159 return;
160 }
161
Stephen Hines7d25a822013-04-09 23:51:56 -0700162 // Defer creation of cache path to nScriptCCreate().
163 mCacheDir = cacheDir;
Jason Samsa6f338c2012-02-24 16:22:16 -0800164 }
165
Jason Sams02d56d92013-04-12 16:40:50 -0700166 /**
167 * ContextType specifies the specific type of context to be created.
168 *
169 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800170 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700171 /**
172 * NORMAL context, this is the default and what shipping apps should
173 * use.
174 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800175 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700176
177 /**
178 * DEBUG context, perform extra runtime checks to validate the
179 * kernels and APIs are being used as intended. Get and SetElementAt
180 * will be bounds checked in this mode.
181 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800182 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700183
184 /**
185 * PROFILE context, Intended to be used once the first time an
186 * application is run on a new device. This mode allows the runtime to
187 * do additional testing and performance tuning.
188 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800189 PROFILE (2);
190
191 int mID;
192 ContextType(int id) {
193 mID = id;
194 }
195 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800196
Stephen Hines42028a82013-04-17 19:22:01 -0700197 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800198 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700199
Jason Sams2e1872f2010-08-17 16:25:41 -0700200 // Methods below are wrapped to protect the non-threadsafe
201 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800202 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700203 int colorMin, int colorPref,
204 int alphaMin, int alphaPref,
205 int depthMin, int depthPref,
206 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700207 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800208 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700209 int colorMin, int colorPref,
210 int alphaMin, int alphaPref,
211 int depthMin, int depthPref,
212 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700213 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700214 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700215 alphaMin, alphaPref, depthMin, depthPref,
216 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700217 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700218 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800219 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
220 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800221 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700222 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800223 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700224 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800225 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800226
227 // take teardown lock
228 // teardown lock can only be taken when no objects are being destroyed
229 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
230 wlock.lock();
231
232 long curCon = mContext;
233 // context is considered dead as of this point
234 mContext = 0;
235
236 wlock.unlock();
237 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700238 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800239 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700240 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800241 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700242 rsnContextSetSurface(mContext, w, h, sur);
243 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800244 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700245 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
246 validate();
247 rsnContextSetSurfaceTexture(mContext, w, h, sur);
248 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800249 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700250 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800251 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700252 rsnContextSetPriority(mContext, p);
253 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800254 native void rsnContextDump(long con, int bits);
Jason Sams2e1872f2010-08-17 16:25:41 -0700255 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800256 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700257 rsnContextDump(mContext, bits);
258 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800259 native void rsnContextFinish(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700260 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800261 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700262 rsnContextFinish(mContext);
263 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700264
Tim Murrayeff663f2013-11-15 13:08:30 -0800265 native void rsnContextSendMessage(long con, int id, int[] data);
Jason Sams455d6442013-02-05 19:20:18 -0800266 synchronized void nContextSendMessage(int id, int[] data) {
267 validate();
268 rsnContextSendMessage(mContext, id, data);
269 }
270
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000271 native void rsnContextBindRootScript(long con, long script);
272 synchronized void nContextBindRootScript(long script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800273 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700274 rsnContextBindRootScript(mContext, script);
275 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800276 native void rsnContextBindSampler(long con, int sampler, int slot);
Jason Sams2e1872f2010-08-17 16:25:41 -0700277 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800278 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700279 rsnContextBindSampler(mContext, sampler, slot);
280 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000281 native void rsnContextBindProgramStore(long con, long pfs);
282 synchronized void nContextBindProgramStore(long pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800283 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700284 rsnContextBindProgramStore(mContext, pfs);
285 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000286 native void rsnContextBindProgramFragment(long con, long pf);
287 synchronized void nContextBindProgramFragment(long pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800288 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700289 rsnContextBindProgramFragment(mContext, pf);
290 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000291 native void rsnContextBindProgramVertex(long con, long pv);
292 synchronized void nContextBindProgramVertex(long pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800293 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700294 rsnContextBindProgramVertex(mContext, pv);
295 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000296 native void rsnContextBindProgramRaster(long con, long pr);
297 synchronized void nContextBindProgramRaster(long pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800298 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700299 rsnContextBindProgramRaster(mContext, pr);
300 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800301 native void rsnContextPause(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700302 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800303 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700304 rsnContextPause(mContext);
305 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800306 native void rsnContextResume(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700307 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800308 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700309 rsnContextResume(mContext);
310 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700311
Yang Ni281c3252014-10-24 08:52:24 -0700312 native long rsnClosureCreate(long con, long kernelID, long returnValue,
313 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
314 long[] depFieldIDs);
315 synchronized long nClosureCreate(long kernelID, long returnValue,
316 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
317 long[] depFieldIDs) {
318 validate();
319 return rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
320 sizes, depClosures, depFieldIDs);
321 }
322
Yang Nibe392ad2015-01-23 17:16:02 -0800323 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
324 long[] fieldIDs, long[] values, int[] sizes);
325 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
326 long[] fieldIDs, long[] values, int[] sizes) {
327 validate();
328 return rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
329 values, sizes);
330 }
331
Yang Ni281c3252014-10-24 08:52:24 -0700332 native void rsnClosureSetArg(long con, long closureID, int index,
333 long value, int size);
334 synchronized void nClosureSetArg(long closureID, int index, long value,
335 int size) {
336 validate();
337 rsnClosureSetArg(mContext, closureID, index, value, size);
338 }
339
340 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
341 long value, int size);
342 // Does this have to be synchronized?
343 synchronized void nClosureSetGlobal(long closureID, long fieldID,
344 long value, int size) {
345 validate(); // TODO: is this necessary?
346 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
347 }
348
Yang Niebf63402015-01-16 11:06:26 -0800349 native long rsnScriptGroup2Create(long con, String cachePath, long[] closures);
350 synchronized long nScriptGroup2Create(String cachePath, long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700351 validate();
Yang Niebf63402015-01-16 11:06:26 -0800352 return rsnScriptGroup2Create(mContext, cachePath, closures);
Yang Ni281c3252014-10-24 08:52:24 -0700353 }
354
355 native void rsnScriptGroup2Execute(long con, long groupID);
356 synchronized void nScriptGroup2Execute(long groupID) {
357 validate();
358 rsnScriptGroup2Execute(mContext, groupID);
359 }
360
Tim Murray460a0492013-11-19 12:45:54 -0800361 native void rsnAssignName(long con, long obj, byte[] name);
362 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800363 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700364 rsnAssignName(mContext, obj, name);
365 }
Tim Murray460a0492013-11-19 12:45:54 -0800366 native String rsnGetName(long con, long obj);
367 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800368 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700369 return rsnGetName(mContext, obj);
370 }
Tim Murray06b45672014-01-07 11:13:56 -0800371
372 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800373 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800374 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800375 // There is a race condition here. The calling code may be run
376 // by the gc while teardown is occuring. This protects againts
377 // deleting dead objects.
378 if (mContext != 0) {
379 rsnObjDestroy(mContext, id);
380 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700381 }
Jason Samsfe08d992009-05-27 14:45:32 -0700382
Tim Murray460a0492013-11-19 12:45:54 -0800383 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
384 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800385 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700386 return rsnElementCreate(mContext, type, kind, norm, vecSize);
387 }
Ashok Bhat98071552014-02-12 09:54:43 +0000388 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
389 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800390 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700391 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700392 }
Tim Murray460a0492013-11-19 12:45:54 -0800393 native void rsnElementGetNativeData(long con, long id, int[] elementData);
394 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800395 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700396 rsnElementGetNativeData(mContext, id, elementData);
397 }
Tim Murray460a0492013-11-19 12:45:54 -0800398 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000399 long[] IDs, String[] names, int[] arraySizes);
400 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800401 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700402 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700403 }
Jason Sams768bc022009-09-21 19:41:04 -0700404
Tim Murray460a0492013-11-19 12:45:54 -0800405 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
406 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800407 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800408 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700409 }
Ashok Bhat98071552014-02-12 09:54:43 +0000410 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
411 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800412 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700413 rsnTypeGetNativeData(mContext, id, typeData);
414 }
Jason Sams768bc022009-09-21 19:41:04 -0700415
Ashok Bhat98071552014-02-12 09:54:43 +0000416 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
417 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800418 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800419 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700420 }
Tim Murray460a0492013-11-19 12:45:54 -0800421 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
422 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800423 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800424 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700425 }
Tim Murraya3145512012-12-04 17:59:29 -0800426
Tim Murray460a0492013-11-19 12:45:54 -0800427 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
428 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800429 validate();
430 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
431 }
432
Tim Murray460a0492013-11-19 12:45:54 -0800433 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
434 synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800435 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800436 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800437 }
Tim Murray460a0492013-11-19 12:45:54 -0800438 native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
439 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800440 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700441 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
442 }
Tim Murray460a0492013-11-19 12:45:54 -0800443 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
444 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800445 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800446 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
447 }
448
Tim Murray460a0492013-11-19 12:45:54 -0800449 native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
450 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800451 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800452 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
453 }
454
455
Tim Murray460a0492013-11-19 12:45:54 -0800456 native void rsnAllocationSyncAll(long con, long alloc, int src);
457 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800458 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800459 rsnAllocationSyncAll(mContext, alloc, src);
460 }
Tim Murray460a0492013-11-19 12:45:54 -0800461 native Surface rsnAllocationGetSurface(long con, long alloc);
462 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800463 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800464 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700465 }
Tim Murray460a0492013-11-19 12:45:54 -0800466 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
467 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800468 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700469 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800470 }
Tim Murray460a0492013-11-19 12:45:54 -0800471 native void rsnAllocationIoSend(long con, long alloc);
472 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800473 validate();
474 rsnAllocationIoSend(mContext, alloc);
475 }
Tim Murray460a0492013-11-19 12:45:54 -0800476 native void rsnAllocationIoReceive(long con, long alloc);
477 synchronized void nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800478 validate();
479 rsnAllocationIoReceive(mContext, alloc);
480 }
481
Jason Sams615e7ce2012-01-13 14:01:20 -0800482
Tim Murray460a0492013-11-19 12:45:54 -0800483 native void rsnAllocationGenerateMipmaps(long con, long alloc);
484 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800485 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800486 rsnAllocationGenerateMipmaps(mContext, alloc);
487 }
Tim Murray460a0492013-11-19 12:45:54 -0800488 native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
489 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800490 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800491 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700492 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700493
Jason Sams49a05d72010-12-29 14:31:29 -0800494
Miao Wang87e908d2015-03-02 15:15:15 -0800495 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
496 int mSize, boolean usePadding);
497 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
498 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800499 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800500 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700501 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700502
Miao Wangc8e237e2015-02-20 18:36:32 -0800503 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
504 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 -0800505 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800506 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700507 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700508
Tim Murrayeff663f2013-11-15 13:08:30 -0800509 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800510 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700511 int dstMip, int dstFace,
512 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800513 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700514 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800515 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700516 int dstMip, int dstFace,
517 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800518 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700519 int srcMip, int srcFace) {
520 validate();
521 rsnAllocationData2D(mContext,
522 dstAlloc, dstXoff, dstYoff,
523 dstMip, dstFace,
524 width, height,
525 srcAlloc, srcXoff, srcYoff,
526 srcMip, srcFace);
527 }
528
Tim Murray460a0492013-11-19 12:45:54 -0800529 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800530 int w, int h, Object d, int sizeBytes, int dt,
531 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800532 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800533 int w, int h, Object d, int sizeBytes, Element.DataType dt,
534 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800535 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800536 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700537 }
Jason Sams21659ac2013-11-06 15:08:07 -0800538
Tim Murray460a0492013-11-19 12:45:54 -0800539 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
540 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800541 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800542 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
543 }
Jason Sams49a05d72010-12-29 14:31:29 -0800544
Tim Murrayeff663f2013-11-15 13:08:30 -0800545 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800546 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700547 int dstMip,
548 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800549 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700550 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800551 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700552 int dstMip,
553 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800554 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700555 int srcMip) {
556 validate();
557 rsnAllocationData3D(mContext,
558 dstAlloc, dstXoff, dstYoff, dstZoff,
559 dstMip, width, height, depth,
560 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
561 }
562
Tim Murray460a0492013-11-19 12:45:54 -0800563 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800564 int w, int h, int depth, Object d, int sizeBytes, int dt,
565 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800566 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800567 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
568 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700569 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800570 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
571 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700572 }
Jason Samsb05d6892013-04-09 15:59:24 -0700573
Miao Wang87e908d2015-03-02 15:15:15 -0800574 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
575 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800576 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800577 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800578 }
Jason Sams21659ac2013-11-06 15:08:07 -0800579
Tim Murray460a0492013-11-19 12:45:54 -0800580 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800581 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800582 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800583 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800584 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800585 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800586 }
Jason Sams21659ac2013-11-06 15:08:07 -0800587
Miao Wangc8e237e2015-02-20 18:36:32 -0800588 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800589 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800590 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800591 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800592 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800593 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800594 }
595
Tim Murray460a0492013-11-19 12:45:54 -0800596 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800597 int w, int h, Object d, int sizeBytes, int dt,
598 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800599 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800600 int w, int h, Object d, int sizeBytes, Element.DataType dt,
601 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800602 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800603 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700604 }
Jason Sams21659ac2013-11-06 15:08:07 -0800605
Miao Wangc8e237e2015-02-20 18:36:32 -0800606 native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800607 int w, int h, int depth, Object d, int sizeBytes, int dt,
608 int mSize, boolean usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800609 synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800610 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
611 int mSize, boolean usePadding) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800612 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800613 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800614 }
615
Tim Murray460a0492013-11-19 12:45:54 -0800616 native long rsnAllocationGetType(long con, long id);
617 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800618 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700619 return rsnAllocationGetType(mContext, id);
620 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700621
Tim Murray460a0492013-11-19 12:45:54 -0800622 native void rsnAllocationResize1D(long con, long id, int dimX);
623 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800624 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700625 rsnAllocationResize1D(mContext, id, dimX);
626 }
Jason Sams5edc6082010-10-05 13:32:49 -0700627
Jason Sams46ba27e32015-02-06 17:45:15 -0800628 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
629 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
630 validate();
631 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
632 }
633
634 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
635 int mip, int face, int a1, int a2, int a3, int a4);
636 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
637 int mip, int face, int a1, int a2, int a3, int a4) {
638 validate();
639 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
640 }
641
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000642 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
643 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800644 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700645 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
646 }
Tim Murray460a0492013-11-19 12:45:54 -0800647 native long rsnFileA3DCreateFromFile(long con, String path);
648 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800649 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800650 return rsnFileA3DCreateFromFile(mContext, path);
651 }
Tim Murray460a0492013-11-19 12:45:54 -0800652 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
653 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800654 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800655 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
656 }
Tim Murray460a0492013-11-19 12:45:54 -0800657 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
658 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800659 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700660 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
661 }
Tim Murray460a0492013-11-19 12:45:54 -0800662 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
663 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800664 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700665 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
666 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000667 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
668 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800669 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700670 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
671 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700672
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000673 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
674 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800675 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700676 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
677 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000678 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
679 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800680 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800681 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
682 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000683 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
684 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800685 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800686 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
687 }
Jason Sams22534172009-08-04 16:58:20 -0700688
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700689
Tim Murray460a0492013-11-19 12:45:54 -0800690 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
691 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800692 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700693 rsnScriptBindAllocation(mContext, script, alloc, slot);
694 }
Tim Murray460a0492013-11-19 12:45:54 -0800695 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
696 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800697 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700698 rsnScriptSetTimeZone(mContext, script, timeZone);
699 }
Tim Murray460a0492013-11-19 12:45:54 -0800700 native void rsnScriptInvoke(long con, long id, int slot);
701 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800702 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700703 rsnScriptInvoke(mContext, id, slot);
704 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700705
706 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
707 long aout, byte[] params, int[] limits);
708
709 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
710 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700711 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700712 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700713 }
714
Tim Murray460a0492013-11-19 12:45:54 -0800715 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
716 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800717 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700718 rsnScriptInvokeV(mContext, id, slot, params);
719 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700720
Tim Murray460a0492013-11-19 12:45:54 -0800721 native void rsnScriptSetVarI(long con, long id, int slot, int val);
722 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800723 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700724 rsnScriptSetVarI(mContext, id, slot, val);
725 }
Tim Murray460a0492013-11-19 12:45:54 -0800726 native int rsnScriptGetVarI(long con, long id, int slot);
727 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700728 validate();
729 return rsnScriptGetVarI(mContext, id, slot);
730 }
731
Tim Murray460a0492013-11-19 12:45:54 -0800732 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
733 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800734 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700735 rsnScriptSetVarJ(mContext, id, slot, val);
736 }
Tim Murray460a0492013-11-19 12:45:54 -0800737 native long rsnScriptGetVarJ(long con, long id, int slot);
738 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700739 validate();
740 return rsnScriptGetVarJ(mContext, id, slot);
741 }
742
Tim Murray460a0492013-11-19 12:45:54 -0800743 native void rsnScriptSetVarF(long con, long id, int slot, float val);
744 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800745 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700746 rsnScriptSetVarF(mContext, id, slot, val);
747 }
Tim Murray460a0492013-11-19 12:45:54 -0800748 native float rsnScriptGetVarF(long con, long id, int slot);
749 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700750 validate();
751 return rsnScriptGetVarF(mContext, id, slot);
752 }
Tim Murray460a0492013-11-19 12:45:54 -0800753 native void rsnScriptSetVarD(long con, long id, int slot, double val);
754 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800755 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700756 rsnScriptSetVarD(mContext, id, slot, val);
757 }
Tim Murray460a0492013-11-19 12:45:54 -0800758 native double rsnScriptGetVarD(long con, long id, int slot);
759 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700760 validate();
761 return rsnScriptGetVarD(mContext, id, slot);
762 }
Tim Murray460a0492013-11-19 12:45:54 -0800763 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
764 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800765 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700766 rsnScriptSetVarV(mContext, id, slot, val);
767 }
Tim Murray460a0492013-11-19 12:45:54 -0800768 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
769 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700770 validate();
771 rsnScriptGetVarV(mContext, id, slot, val);
772 }
Tim Murray460a0492013-11-19 12:45:54 -0800773 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
774 long e, int[] dims);
775 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
776 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700777 validate();
778 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
779 }
Tim Murray460a0492013-11-19 12:45:54 -0800780 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
781 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800782 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800783 rsnScriptSetVarObj(mContext, id, slot, val);
784 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700785
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000786 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700787 byte[] script, int length);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000788 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800789 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700790 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700791 }
Jason Samsebfb4362009-09-23 13:57:02 -0700792
Tim Murray460a0492013-11-19 12:45:54 -0800793 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
794 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700795 validate();
796 return rsnScriptIntrinsicCreate(mContext, id, eid);
797 }
798
Tim Murray460a0492013-11-19 12:45:54 -0800799 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
800 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700801 validate();
802 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
803 }
804
Yang Nibe392ad2015-01-23 17:16:02 -0800805 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
806 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
807 validate();
808 return rsnScriptInvokeIDCreate(mContext, sid, slot);
809 }
810
Tim Murray460a0492013-11-19 12:45:54 -0800811 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
812 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700813 validate();
814 return rsnScriptFieldIDCreate(mContext, sid, slot);
815 }
816
Ashok Bhat98071552014-02-12 09:54:43 +0000817 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
818 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700819 validate();
820 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
821 }
822
Tim Murray460a0492013-11-19 12:45:54 -0800823 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
824 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700825 validate();
826 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
827 }
828
Tim Murray460a0492013-11-19 12:45:54 -0800829 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
830 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700831 validate();
832 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
833 }
834
Tim Murray460a0492013-11-19 12:45:54 -0800835 native void rsnScriptGroupExecute(long con, long group);
836 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700837 validate();
838 rsnScriptGroupExecute(mContext, group);
839 }
840
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000841 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700842 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000843 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700844 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800845 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700846 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700847 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800848
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000849 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700850 boolean depthMask, boolean dither,
851 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000852 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700853 boolean depthMask, boolean dither,
854 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800855 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700856 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
857 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700858 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700859
Tim Murray460a0492013-11-19 12:45:54 -0800860 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
861 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800862 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700863 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700864 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700865
Tim Murray460a0492013-11-19 12:45:54 -0800866 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
867 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800868 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700869 rsnProgramBindConstants(mContext, pv, slot, mID);
870 }
Tim Murray460a0492013-11-19 12:45:54 -0800871 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
872 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800873 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700874 rsnProgramBindTexture(mContext, vpf, slot, a);
875 }
Tim Murray460a0492013-11-19 12:45:54 -0800876 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
877 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800878 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700879 rsnProgramBindSampler(mContext, vpf, slot, s);
880 }
Ashok Bhat98071552014-02-12 09:54:43 +0000881 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
882 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800883 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800884 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700885 }
Ashok Bhat98071552014-02-12 09:54:43 +0000886 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
887 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800888 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800889 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700890 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700891
Ashok Bhat98071552014-02-12 09:54:43 +0000892 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
893 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800894 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700895 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800896 }
Tim Murray460a0492013-11-19 12:45:54 -0800897 native int rsnMeshGetVertexBufferCount(long con, long id);
898 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800899 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700900 return rsnMeshGetVertexBufferCount(mContext, id);
901 }
Tim Murray460a0492013-11-19 12:45:54 -0800902 native int rsnMeshGetIndexCount(long con, long id);
903 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800904 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700905 return rsnMeshGetIndexCount(mContext, id);
906 }
Ashok Bhat98071552014-02-12 09:54:43 +0000907 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
908 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800909 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700910 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
911 }
Ashok Bhat98071552014-02-12 09:54:43 +0000912 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
913 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800914 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700915 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
916 }
917
Tim Murray25207df2015-01-12 16:47:56 -0800918 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
919 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
920 float alpha, long A, long B, float beta, long C, int incX, int incY,
921 int KL, int KU);
922 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
923 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
924 float alpha, long A, long B, float beta, long C, int incX, int incY,
925 int KL, int KU) {
926 validate();
927 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
928 }
929
930 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
931 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
932 double alpha, long A, long B, double beta, long C, int incX, int incY,
933 int KL, int KU);
934 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
935 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
936 double alpha, long A, long B, double beta, long C, int incX, int incY,
937 int KL, int KU) {
938 validate();
939 rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
940 }
941
942 native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA,
943 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
944 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
945 int KL, int KU);
946 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
947 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
948 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
949 int KL, int KU) {
950 validate();
951 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
952 }
953
954 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
955 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
956 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
957 int KL, int KU);
958 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
959 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
960 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
961 int KL, int KU) {
962 validate();
963 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
964 }
965
966
Tim Murrayeff663f2013-11-15 13:08:30 -0800967 long mDev;
968 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -0800969 private boolean mDestroyed = false;
970
Romain Guy650a3eb2009-08-31 14:06:43 -0700971 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800972 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700973
Jason Sams8cb39de2010-06-01 15:47:01 -0700974 Element mElement_U8;
975 Element mElement_I8;
976 Element mElement_U16;
977 Element mElement_I16;
978 Element mElement_U32;
979 Element mElement_I32;
Stephen Hines52d83632010-10-11 16:10:42 -0700980 Element mElement_U64;
Stephen Hinesef1dac22010-10-01 15:39:33 -0700981 Element mElement_I64;
Jason Samsa5835a22014-11-05 15:16:26 -0800982 Element mElement_F16;
Jason Sams8cb39de2010-06-01 15:47:01 -0700983 Element mElement_F32;
Stephen Hines02f417052010-09-30 15:19:22 -0700984 Element mElement_F64;
Jason Samsf110d4b2010-06-21 17:42:41 -0700985 Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -0700986
Jason Sams8cb39de2010-06-01 15:47:01 -0700987 Element mElement_ELEMENT;
988 Element mElement_TYPE;
989 Element mElement_ALLOCATION;
990 Element mElement_SAMPLER;
991 Element mElement_SCRIPT;
992 Element mElement_MESH;
993 Element mElement_PROGRAM_FRAGMENT;
994 Element mElement_PROGRAM_VERTEX;
995 Element mElement_PROGRAM_RASTER;
996 Element mElement_PROGRAM_STORE;
Stephen Hines3a291412012-04-11 17:27:29 -0700997 Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -0700998
Jason Sams3c0dfba2009-09-27 17:50:38 -0700999 Element mElement_A_8;
1000 Element mElement_RGB_565;
1001 Element mElement_RGB_888;
1002 Element mElement_RGBA_5551;
1003 Element mElement_RGBA_4444;
1004 Element mElement_RGBA_8888;
1005
Jason Samsa5835a22014-11-05 15:16:26 -08001006 Element mElement_HALF_2;
1007 Element mElement_HALF_3;
1008 Element mElement_HALF_4;
1009
Jason Sams8cb39de2010-06-01 15:47:01 -07001010 Element mElement_FLOAT_2;
1011 Element mElement_FLOAT_3;
1012 Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001013
1014 Element mElement_DOUBLE_2;
1015 Element mElement_DOUBLE_3;
1016 Element mElement_DOUBLE_4;
1017
1018 Element mElement_UCHAR_2;
1019 Element mElement_UCHAR_3;
Jason Sams8cb39de2010-06-01 15:47:01 -07001020 Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001021
Stephen Hines836c4a52011-06-01 14:38:10 -07001022 Element mElement_CHAR_2;
1023 Element mElement_CHAR_3;
1024 Element mElement_CHAR_4;
1025
1026 Element mElement_USHORT_2;
1027 Element mElement_USHORT_3;
1028 Element mElement_USHORT_4;
1029
1030 Element mElement_SHORT_2;
1031 Element mElement_SHORT_3;
1032 Element mElement_SHORT_4;
1033
1034 Element mElement_UINT_2;
1035 Element mElement_UINT_3;
1036 Element mElement_UINT_4;
1037
1038 Element mElement_INT_2;
1039 Element mElement_INT_3;
1040 Element mElement_INT_4;
1041
1042 Element mElement_ULONG_2;
1043 Element mElement_ULONG_3;
1044 Element mElement_ULONG_4;
1045
1046 Element mElement_LONG_2;
1047 Element mElement_LONG_3;
1048 Element mElement_LONG_4;
1049
Tim Murray932e78e2013-09-03 11:42:26 -07001050 Element mElement_YUV;
1051
Jason Sams1d45c472010-08-25 14:31:48 -07001052 Element mElement_MATRIX_4X4;
1053 Element mElement_MATRIX_3X3;
1054 Element mElement_MATRIX_2X2;
1055
Jason Sams4d339932010-05-11 14:03:58 -07001056 Sampler mSampler_CLAMP_NEAREST;
1057 Sampler mSampler_CLAMP_LINEAR;
1058 Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1059 Sampler mSampler_WRAP_NEAREST;
1060 Sampler mSampler_WRAP_LINEAR;
1061 Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
Tim Murray6b9b2ca2013-02-15 13:25:55 -08001062 Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1063 Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1064 Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001065
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001066 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1067 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001068 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1069 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001070
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001071 ProgramRaster mProgramRaster_CULL_BACK;
1072 ProgramRaster mProgramRaster_CULL_FRONT;
1073 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001074
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001075 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001076 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001077
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001078 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001079 * The base class from which an application should derive in order
1080 * to receive RS messages from scripts. When a script calls {@code
1081 * rsSendToClient}, the data fields will be filled, and the run
1082 * method will be called on a separate thread. This will occur
1083 * some time after {@code rsSendToClient} completes in the script,
1084 * as {@code rsSendToClient} is asynchronous. Message handlers are
1085 * not guaranteed to have completed when {@link
1086 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001087 *
1088 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001089 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001090 protected int[] mData;
1091 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001092 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001093 public void run() {
1094 }
1095 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001096 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001097 * If an application is expecting messages, it should set this
1098 * field to an instance of {@link RSMessageHandler}. This
1099 * instance will receive all the user messages sent from {@code
1100 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001101 *
1102 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001103 RSMessageHandler mMessageCallback = null;
1104
1105 public void setMessageHandler(RSMessageHandler msg) {
1106 mMessageCallback = msg;
1107 }
1108 public RSMessageHandler getMessageHandler() {
1109 return mMessageCallback;
1110 }
Jason Sams516c3192009-10-06 13:58:47 -07001111
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001112 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001113 * Place a message into the message queue to be sent back to the message
1114 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001115 *
1116 * @param id
1117 * @param data
1118 */
1119 public void sendMessage(int id, int[] data) {
1120 nContextSendMessage(id, data);
1121 }
1122
1123 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001124 * The runtime error handler base class. An application should derive from this class
1125 * if it wishes to install an error handler. When errors occur at runtime,
1126 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001127 *
1128 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001129 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001130 protected String mErrorMessage;
1131 protected int mErrorNum;
1132 public void run() {
1133 }
1134 }
Jason Sams27676fe2010-11-10 17:00:59 -08001135
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001136 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001137 * Application Error handler. All runtime errors will be dispatched to the
1138 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001139 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001140 * This will cause program termaination.
1141 *
1142 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001143 RSErrorHandler mErrorCallback = null;
1144
1145 public void setErrorHandler(RSErrorHandler msg) {
1146 mErrorCallback = msg;
1147 }
1148 public RSErrorHandler getErrorHandler() {
1149 return mErrorCallback;
1150 }
Jason Sams1c415172010-11-08 17:06:46 -08001151
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001152 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001153 * RenderScript worker thread priority enumeration. The default value is
1154 * NORMAL. Applications wishing to do background processing should set
1155 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001156 */
Jason Sams7d787b42009-11-15 12:14:26 -08001157 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001158 // These values used to represent official thread priority values
1159 // now they are simply enums to be used by the runtime side
1160 LOW (15),
1161 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001162
1163 int mID;
1164 Priority(int id) {
1165 mID = id;
1166 }
1167 }
1168
Jason Sams678cc7f2014-03-05 16:09:02 -08001169 void validateObject(BaseObj o) {
1170 if (o != null) {
1171 if (o.mRS != this) {
1172 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1173 }
1174 }
1175 }
1176
Jason Sams771bebb2009-12-07 12:40:12 -08001177 void validate() {
1178 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001179 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001180 }
1181 }
1182
Jason Sams27676fe2010-11-10 17:00:59 -08001183
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001184 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001185 * Change the priority of the worker threads for this context.
1186 *
1187 * @param p New priority to be set.
1188 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001189 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001190 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001191 nContextSetPriority(p.mID);
1192 }
1193
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001194 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001195 RenderScript mRS;
1196 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001197 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001198
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001199 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1200 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1201 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1202 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1203 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001204 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001205
Stephen Hines42028a82013-04-17 19:22:01 -07001206 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001207 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001208
Jason Sams516c3192009-10-06 13:58:47 -07001209 MessageThread(RenderScript rs) {
1210 super("RSMessageThread");
1211 mRS = rs;
1212
1213 }
1214
1215 public void run() {
1216 // This function is a temporary solution. The final solution will
1217 // used typed allocations where the message id is the type indicator.
1218 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001219 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001220 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001221 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001222 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001223 int size = mAuxData[1];
1224 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001225
1226 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1227 if ((size>>2) >= rbuf.length) {
1228 rbuf = new int[(size + 3) >> 2];
1229 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001230 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1231 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001232 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001233 }
Jason Sams1c415172010-11-08 17:06:46 -08001234
1235 if(mRS.mMessageCallback != null) {
1236 mRS.mMessageCallback.mData = rbuf;
1237 mRS.mMessageCallback.mID = subID;
1238 mRS.mMessageCallback.mLength = size;
1239 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001240 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001241 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001242 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001243 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001244 }
Jason Sams1c415172010-11-08 17:06:46 -08001245
1246 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1247 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1248
Stephen Hines42028a82013-04-17 19:22:01 -07001249 // Throw RSRuntimeException under the following conditions:
1250 //
1251 // 1) It is an unknown fatal error.
1252 // 2) It is a debug fatal error, and we are not in a
1253 // debug context.
1254 // 3) It is a debug fatal error, and we do not have an
1255 // error callback.
1256 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1257 (subID >= RS_ERROR_FATAL_DEBUG &&
1258 (mRS.mContextType != ContextType.DEBUG ||
1259 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001260 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1261 }
1262
Jason Sams1c415172010-11-08 17:06:46 -08001263 if(mRS.mErrorCallback != null) {
1264 mRS.mErrorCallback.mErrorMessage = e;
1265 mRS.mErrorCallback.mErrorNum = subID;
1266 mRS.mErrorCallback.run();
1267 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001268 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001269 // Do not throw here. In these cases, we do not have
1270 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001271 }
1272 continue;
1273 }
1274
Jason Sams739c8262013-04-11 18:07:52 -07001275 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001276 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1277 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1278 throw new RSDriverException("Error processing message from RenderScript.");
1279 }
1280 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1281 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001282 continue;
1283 }
1284
Jason Sams1c415172010-11-08 17:06:46 -08001285 // 2: teardown.
1286 // But we want to avoid starving other threads during
1287 // teardown by yielding until the next line in the destructor
1288 // can execute to set mRun = false
1289 try {
1290 sleep(1, 0);
1291 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001292 }
Jason Sams516c3192009-10-06 13:58:47 -07001293 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001294 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001295 }
1296 }
1297
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001298 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001299 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001300 if (ctx != null) {
1301 mApplicationContext = ctx.getApplicationContext();
1302 }
Tim Murray06b45672014-01-07 11:13:56 -08001303 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001304 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001305 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001306 } catch (Exception e) {
1307 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1308 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1309 }
1310
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001311 }
1312
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001313 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001314 * Gets the application context associated with the RenderScript context.
1315 *
1316 * @return The application context.
1317 */
1318 public final Context getApplicationContext() {
1319 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001320 }
1321
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001322 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001323 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001324 *
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001325 * @hide
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001326 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001327 * @return RenderScript
1328 */
Jason Samse16da122015-03-18 17:04:18 -07001329 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001330 if (!sInitialized) {
1331 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1332 return null;
1333 }
1334
Jason Samsb69c7912014-05-20 18:48:35 -07001335 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER)) != 0) {
1336 throw new RSIllegalArgumentException("Invalid flags passed.");
1337 }
1338
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001339 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001340
1341 rs.mDev = rs.nDeviceCreate();
Tim Murrayfd710e72014-06-06 11:10:45 -07001342 rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001343 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001344 rs.mContextFlags = flags;
1345 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001346 if (rs.mContext == 0) {
1347 throw new RSDriverException("Failed to create RS context.");
1348 }
Jason Sams704ff642010-02-09 16:05:07 -08001349 rs.mMessageThread = new MessageThread(rs);
1350 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001351 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001352 }
1353
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001354 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001355 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001356 *
1357 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001358 *
1359 * @param ctx The context.
1360 * @return RenderScript
1361 */
1362 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001363 return create(ctx, ContextType.NORMAL);
1364 }
1365
1366 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001367 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001368 *
Jason Samse16da122015-03-18 17:04:18 -07001369 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001370 *
1371 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001372 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001373 * @return RenderScript
1374 */
1375 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001376 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001377 }
1378
Miao Wanga4e5adf2015-03-23 11:09:56 -07001379
1380 /**
Jason Samse16da122015-03-18 17:04:18 -07001381 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001382 *
Jason Samse16da122015-03-18 17:04:18 -07001383 * The returned context will be cached for future reuse within
1384 * the process. When an application is finished using
1385 * RenderScript it should call releaseAllContexts()
1386 *
1387 * A process context is a context designed for easy creation and
1388 * lifecycle management. Multiple calls to this function will
1389 * return the same object provided they are called with the same
1390 * options. This allows it to be used any time a RenderScript
1391 * context is needed.
1392 *
1393 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001394 *
1395 * @param ctx The context.
1396 * @param ct The type of context to be created.
1397 * @param flags The OR of the CREATE_FLAG_* options desired
1398 * @return RenderScript
1399 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001400 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001401 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001402 return create(ctx, v, ct, flags);
1403 }
1404
1405 /**
1406 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1407 *
1408 * Used by the RenderScriptThunker to maintain backward compatibility.
1409 *
1410 * @hide
1411 * @param ctx The context.
1412 * @param sdkVersion The target SDK Version.
1413 * @return RenderScript
1414 */
1415 public static RenderScript create(Context ctx, int sdkVersion) {
1416 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1417 }
1418
1419 /**
1420 * Gets or creates a RenderScript context of the specified type.
1421 *
1422 * @hide
1423 * @param ctx The context.
1424 * @param ct The type of context to be created.
1425 * @param sdkVersion The target SDK Version.
1426 * @param flags The OR of the CREATE_FLAG_* options desired
1427 * @return RenderScript
1428 */
1429 public static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
1430 if (sdkVersion < 23) {
1431 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001432 }
1433
1434 synchronized (mProcessContextList) {
1435 for (RenderScript prs : mProcessContextList) {
1436 if ((prs.mContextType == ct) &&
1437 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001438 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001439
1440 return prs;
1441 }
1442 }
1443
Miao Wanga4e5adf2015-03-23 11:09:56 -07001444 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001445 prs.mIsProcessContext = true;
1446 mProcessContextList.add(prs);
1447 return prs;
1448 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001449 }
1450
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001451 /**
Jason Samse16da122015-03-18 17:04:18 -07001452 * @hide
1453 *
1454 * Releases all the process contexts. This is the same as
1455 * calling .destroy() on each unique context retreived with
1456 * create(...). If no contexts have been created this
1457 * function does nothing.
1458 *
1459 * Typically you call this when your application is losing focus
1460 * and will not be using a context for some time.
1461 *
1462 * This has no effect on a context created with
1463 * createMultiContext()
1464 */
1465 public static void releaseAllContexts() {
1466 ArrayList<RenderScript> oldList;
1467 synchronized (mProcessContextList) {
1468 oldList = mProcessContextList;
1469 mProcessContextList = new ArrayList<RenderScript>();
1470 }
1471
1472 for (RenderScript prs : oldList) {
1473 prs.mIsProcessContext = false;
1474 prs.destroy();
1475 }
1476 oldList.clear();
1477 }
1478
1479
1480
1481 /**
1482 * Create a RenderScript context.
1483 *
1484 * This is an advanced function intended for applications which
1485 * need to create more than one RenderScript context to be used
1486 * at the same time.
1487 *
1488 * If you need a single context please use create()
1489 *
1490 * @hide
1491 * @param ctx The context.
1492 * @return RenderScript
1493 */
1494 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1495 return internalCreate(ctx, API_number, ct, flags);
1496 }
1497
1498
1499 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001500 * Print the currently available debugging information about the state of
1501 * the RS context to the log.
1502 *
Jason Sams27676fe2010-11-10 17:00:59 -08001503 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001504 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001505 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001506 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001507 }
1508
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001509 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001510 * Wait for any pending asynchronous opeations (such as copies to a RS
1511 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001512 *
1513 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001514 public void finish() {
1515 nContextFinish();
1516 }
1517
Jason Samsd22a6f02015-02-19 17:19:52 -08001518 private void helpDestroy() {
1519 boolean shouldDestroy = false;
1520 synchronized(this) {
1521 if (!mDestroyed) {
1522 shouldDestroy = true;
1523 mDestroyed = true;
1524 }
1525 }
1526
1527 if (shouldDestroy) {
1528 nContextFinish();
1529
1530 nContextDeinitToClient(mContext);
1531 mMessageThread.mRun = false;
1532 try {
1533 mMessageThread.join();
1534 } catch(InterruptedException e) {
1535 }
1536
1537 nContextDestroy();
1538
1539 nDeviceDestroy(mDev);
1540 mDev = 0;
1541 }
1542 }
1543
1544 protected void finalize() throws Throwable {
1545 helpDestroy();
1546 super.finalize();
1547 }
1548
1549
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001550 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001551 * Destroys this RenderScript context. Once this function is called,
1552 * using this context or any objects belonging to this context is
1553 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001554 *
Jason Samse16da122015-03-18 17:04:18 -07001555 * API 23+, this function is a NOP if the context was created
1556 * with create(). Please use releaseAllContexts() to clean up
1557 * contexts created with the create function.
1558 *
Jason Sams27676fe2010-11-10 17:00:59 -08001559 */
Jason Samsf5b45962009-08-25 14:49:07 -07001560 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001561 if (mIsProcessContext) {
1562 // users cannot destroy a process context
1563 return;
1564 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001565 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001566 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001567 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001568
Jason Samsa9e7a052009-09-25 14:51:22 -07001569 boolean isAlive() {
1570 return mContext != 0;
1571 }
1572
Tim Murray460a0492013-11-19 12:45:54 -08001573 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001574 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001575 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001576 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001577 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001578 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001579}