blob: e7f210b5156d6d8f8e0573786605b26d2d10064d [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
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070033/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070034 * This class provides access to a RenderScript context, which controls RenderScript
35 * initialization, resource management, and teardown. An instance of the RenderScript
36 * class must be created before any other RS objects can be created.
Jason Sams27676fe2010-11-10 17:00:59 -080037 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080038 * <div class="special reference">
39 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070040 * <p>For more information about creating an application that uses RenderScript, read the
41 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080042 * </div>
Jason Samse29d4712009-07-23 15:19:03 -070043 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070044public class RenderScript {
Tim Murray6d7a53c2013-05-23 16:59:23 -070045 static final long TRACE_TAG = Trace.TRACE_TAG_RS;
46
Jason Sams3bc47d42009-11-12 15:10:25 -080047 static final String LOG_TAG = "RenderScript_jni";
Jason Samsbf6ef8d72010-12-06 15:59:59 -080048 static final boolean DEBUG = false;
Romain Guy650a3eb2009-08-31 14:06:43 -070049 @SuppressWarnings({"UnusedDeclaration", "deprecation"})
Joe Onorato43a17652011-04-06 19:22:23 -070050 static final boolean LOG_ENABLED = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070051
Jason Samse16da122015-03-18 17:04:18 -070052 static private ArrayList<RenderScript> mProcessContextList = new ArrayList<RenderScript>();
53 private boolean mIsProcessContext = false;
54 private int mContextFlags = 0;
55 private int mContextSdkVersion = 0;
56
57
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080058 private Context mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070059
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080060 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070061 * We use a class initializer to allow the native code to cache some
62 * field offsets.
63 */
Dan Morrille4d9a012013-03-28 18:10:43 -070064 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
Jason Samsbf6ef8d72010-12-06 15:59:59 -080065 static boolean sInitialized;
66 native static void _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070067
Tim Murray2f2472c2013-08-22 14:55:26 -070068 static Object sRuntime;
69 static Method registerNativeAllocation;
70 static Method registerNativeFree;
Jason Samsdba3ba52009-07-30 14:56:12 -070071
Jason Sams26e90512014-05-07 14:23:27 -070072 /*
Tim Murrayfd710e72014-06-06 11:10:45 -070073 * Context creation flag that specifies a normal context.
Jason Sams26e90512014-05-07 14:23:27 -070074 */
Tim Murrayfd710e72014-06-06 11:10:45 -070075 public static final int CREATE_FLAG_NONE = 0x0000;
Jason Sams26e90512014-05-07 14:23:27 -070076
77 /*
78 * Context creation flag which specifies a context optimized for low
79 * latency over peak performance. This is a hint and may have no effect
80 * on some implementations.
81 */
Tim Murrayfd710e72014-06-06 11:10:45 -070082 public static final int CREATE_FLAG_LOW_LATENCY = 0x0002;
Jason Sams26e90512014-05-07 14:23:27 -070083
84 /*
85 * Context creation flag which specifies a context optimized for long
86 * battery life over peak performance. This is a hint and may have no effect
87 * on some implementations.
88 */
Tim Murrayfd710e72014-06-06 11:10:45 -070089 public static final int CREATE_FLAG_LOW_POWER = 0x0004;
Jason Sams26e90512014-05-07 14:23:27 -070090
Tim Murray56f9e6f2014-05-16 11:47:26 -070091 /*
92 * Detect the bitness of the VM to allow FieldPacker to do the right thing.
93 */
94 static native int rsnSystemGetPointerSize();
95 static int sPointerSize;
96
Jack Palevich60aa3ea2009-05-26 13:45:08 -070097 static {
98 sInitialized = false;
Dan Morrille4d9a012013-03-28 18:10:43 -070099 if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
100 try {
Tim Murray2f2472c2013-08-22 14:55:26 -0700101 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
102 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
103 sRuntime = get_runtime.invoke(null);
104 registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
105 registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
106 } catch (Exception e) {
107 Log.e(LOG_TAG, "Error loading GC methods: " + e);
108 throw new RSRuntimeException("Error loading GC methods: " + e);
109 }
110 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700111 System.loadLibrary("rs_jni");
112 _nInit();
113 sInitialized = true;
Tim Murray56f9e6f2014-05-16 11:47:26 -0700114 sPointerSize = rsnSystemGetPointerSize();
Dan Morrille4d9a012013-03-28 18:10:43 -0700115 } catch (UnsatisfiedLinkError e) {
116 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
117 throw new RSRuntimeException("Error loading RS jni library: " + e);
118 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700119 }
120 }
121
Jason Sams2e1872f2010-08-17 16:25:41 -0700122 // Non-threadsafe functions.
Tim Murrayeff663f2013-11-15 13:08:30 -0800123 native long nDeviceCreate();
124 native void nDeviceDestroy(long dev);
125 native void nDeviceSetConfig(long dev, int param, int value);
126 native int nContextGetUserMessage(long con, int[] data);
127 native String nContextGetErrorMessage(long con);
128 native int nContextPeekMessage(long con, int[] subID);
129 native void nContextInitToClient(long con);
130 native void nContextDeinitToClient(long con);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700131
Tim Murray67cc2d02014-02-06 16:39:38 -0800132 // this should be a monotonically increasing ID
133 // used in conjunction with the API version of a device
134 static final long sMinorID = 1;
135
136 /**
137 * Returns an identifier that can be used to identify a particular
138 * minor version of RS.
139 *
Jason Sams6a420b52015-03-30 15:31:26 -0700140 * @return The minor RenderScript version number
141 *
Tim Murray67cc2d02014-02-06 16:39:38 -0800142 */
143 public static long getMinorID() {
144 return sMinorID;
145 }
146
Jason Sams02d56d92013-04-12 16:40:50 -0700147 /**
148 * ContextType specifies the specific type of context to be created.
149 *
150 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800151 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700152 /**
153 * NORMAL context, this is the default and what shipping apps should
154 * use.
155 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800156 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700157
158 /**
159 * DEBUG context, perform extra runtime checks to validate the
160 * kernels and APIs are being used as intended. Get and SetElementAt
161 * will be bounds checked in this mode.
162 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800163 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700164
165 /**
166 * PROFILE context, Intended to be used once the first time an
167 * application is run on a new device. This mode allows the runtime to
168 * do additional testing and performance tuning.
169 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800170 PROFILE (2);
171
172 int mID;
173 ContextType(int id) {
174 mID = id;
175 }
176 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800177
Stephen Hines42028a82013-04-17 19:22:01 -0700178 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800179 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700180
Jason Sams2e1872f2010-08-17 16:25:41 -0700181 // Methods below are wrapped to protect the non-threadsafe
182 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800183 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700184 int colorMin, int colorPref,
185 int alphaMin, int alphaPref,
186 int depthMin, int depthPref,
187 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700188 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800189 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700190 int colorMin, int colorPref,
191 int alphaMin, int alphaPref,
192 int depthMin, int depthPref,
193 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700194 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700195 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700196 alphaMin, alphaPref, depthMin, depthPref,
197 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700198 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700199 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800200 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
201 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800202 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700203 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800204 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700205 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800206 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800207
208 // take teardown lock
209 // teardown lock can only be taken when no objects are being destroyed
210 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
211 wlock.lock();
212
213 long curCon = mContext;
214 // context is considered dead as of this point
215 mContext = 0;
216
217 wlock.unlock();
218 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700219 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800220 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700221 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800222 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700223 rsnContextSetSurface(mContext, w, h, sur);
224 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800225 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700226 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
227 validate();
228 rsnContextSetSurfaceTexture(mContext, w, h, sur);
229 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800230 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700231 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800232 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700233 rsnContextSetPriority(mContext, p);
234 }
Tim Murray47f31582015-04-07 15:43:24 -0700235 native void rsnContextSetCacheDir(long con, String cacheDir);
236 synchronized void nContextSetCacheDir(String cacheDir) {
237 validate();
238 rsnContextSetCacheDir(mContext, cacheDir);
239 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800240 native void rsnContextDump(long con, int bits);
Jason Sams2e1872f2010-08-17 16:25:41 -0700241 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800242 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700243 rsnContextDump(mContext, bits);
244 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800245 native void rsnContextFinish(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700246 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800247 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700248 rsnContextFinish(mContext);
249 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700250
Tim Murrayeff663f2013-11-15 13:08:30 -0800251 native void rsnContextSendMessage(long con, int id, int[] data);
Jason Sams455d6442013-02-05 19:20:18 -0800252 synchronized void nContextSendMessage(int id, int[] data) {
253 validate();
254 rsnContextSendMessage(mContext, id, data);
255 }
256
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000257 native void rsnContextBindRootScript(long con, long script);
258 synchronized void nContextBindRootScript(long script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800259 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700260 rsnContextBindRootScript(mContext, script);
261 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800262 native void rsnContextBindSampler(long con, int sampler, int slot);
Jason Sams2e1872f2010-08-17 16:25:41 -0700263 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800264 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700265 rsnContextBindSampler(mContext, sampler, slot);
266 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000267 native void rsnContextBindProgramStore(long con, long pfs);
268 synchronized void nContextBindProgramStore(long pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800269 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700270 rsnContextBindProgramStore(mContext, pfs);
271 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000272 native void rsnContextBindProgramFragment(long con, long pf);
273 synchronized void nContextBindProgramFragment(long pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800274 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700275 rsnContextBindProgramFragment(mContext, pf);
276 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000277 native void rsnContextBindProgramVertex(long con, long pv);
278 synchronized void nContextBindProgramVertex(long pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800279 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700280 rsnContextBindProgramVertex(mContext, pv);
281 }
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000282 native void rsnContextBindProgramRaster(long con, long pr);
283 synchronized void nContextBindProgramRaster(long pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800284 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700285 rsnContextBindProgramRaster(mContext, pr);
286 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800287 native void rsnContextPause(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700288 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800289 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700290 rsnContextPause(mContext);
291 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800292 native void rsnContextResume(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700293 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800294 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700295 rsnContextResume(mContext);
296 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700297
Yang Ni281c3252014-10-24 08:52:24 -0700298 native long rsnClosureCreate(long con, long kernelID, long returnValue,
299 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
300 long[] depFieldIDs);
301 synchronized long nClosureCreate(long kernelID, long returnValue,
302 long[] fieldIDs, long[] values, int[] sizes, long[] depClosures,
303 long[] depFieldIDs) {
304 validate();
305 return rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
306 sizes, depClosures, depFieldIDs);
307 }
308
Yang Nibe392ad2015-01-23 17:16:02 -0800309 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
310 long[] fieldIDs, long[] values, int[] sizes);
311 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
312 long[] fieldIDs, long[] values, int[] sizes) {
313 validate();
314 return rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
315 values, sizes);
316 }
317
Yang Ni281c3252014-10-24 08:52:24 -0700318 native void rsnClosureSetArg(long con, long closureID, int index,
319 long value, int size);
320 synchronized void nClosureSetArg(long closureID, int index, long value,
321 int size) {
322 validate();
323 rsnClosureSetArg(mContext, closureID, index, value, size);
324 }
325
326 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
327 long value, int size);
328 // Does this have to be synchronized?
329 synchronized void nClosureSetGlobal(long closureID, long fieldID,
330 long value, int size) {
331 validate(); // TODO: is this necessary?
332 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
333 }
334
Yang Ni35be56c2015-04-02 17:47:56 -0700335 native long rsnScriptGroup2Create(long con, String name, String cachePath,
336 long[] closures);
337 synchronized long nScriptGroup2Create(String name, String cachePath,
338 long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700339 validate();
Yang Ni35be56c2015-04-02 17:47:56 -0700340 return rsnScriptGroup2Create(mContext, name, cachePath, closures);
Yang Ni281c3252014-10-24 08:52:24 -0700341 }
342
343 native void rsnScriptGroup2Execute(long con, long groupID);
344 synchronized void nScriptGroup2Execute(long groupID) {
345 validate();
346 rsnScriptGroup2Execute(mContext, groupID);
347 }
348
Tim Murray460a0492013-11-19 12:45:54 -0800349 native void rsnAssignName(long con, long obj, byte[] name);
350 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800351 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700352 rsnAssignName(mContext, obj, name);
353 }
Tim Murray460a0492013-11-19 12:45:54 -0800354 native String rsnGetName(long con, long obj);
355 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800356 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700357 return rsnGetName(mContext, obj);
358 }
Tim Murray06b45672014-01-07 11:13:56 -0800359
360 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800361 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800362 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800363 // There is a race condition here. The calling code may be run
364 // by the gc while teardown is occuring. This protects againts
365 // deleting dead objects.
366 if (mContext != 0) {
367 rsnObjDestroy(mContext, id);
368 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700369 }
Jason Samsfe08d992009-05-27 14:45:32 -0700370
Tim Murray460a0492013-11-19 12:45:54 -0800371 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
372 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800373 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700374 return rsnElementCreate(mContext, type, kind, norm, vecSize);
375 }
Ashok Bhat98071552014-02-12 09:54:43 +0000376 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
377 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800378 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700379 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700380 }
Tim Murray460a0492013-11-19 12:45:54 -0800381 native void rsnElementGetNativeData(long con, long id, int[] elementData);
382 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800383 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700384 rsnElementGetNativeData(mContext, id, elementData);
385 }
Tim Murray460a0492013-11-19 12:45:54 -0800386 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000387 long[] IDs, String[] names, int[] arraySizes);
388 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800389 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700390 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700391 }
Jason Sams768bc022009-09-21 19:41:04 -0700392
Tim Murray460a0492013-11-19 12:45:54 -0800393 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
394 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800395 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800396 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700397 }
Ashok Bhat98071552014-02-12 09:54:43 +0000398 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
399 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800400 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700401 rsnTypeGetNativeData(mContext, id, typeData);
402 }
Jason Sams768bc022009-09-21 19:41:04 -0700403
Ashok Bhat98071552014-02-12 09:54:43 +0000404 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
405 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800406 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800407 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700408 }
Tim Murray460a0492013-11-19 12:45:54 -0800409 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
410 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800411 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800412 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700413 }
Tim Murraya3145512012-12-04 17:59:29 -0800414
Tim Murray460a0492013-11-19 12:45:54 -0800415 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
416 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800417 validate();
418 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
419 }
420
Tim Murray460a0492013-11-19 12:45:54 -0800421 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
422 synchronized long nAllocationCubeCreateFromBitmap(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 rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800425 }
Tim Murray460a0492013-11-19 12:45:54 -0800426 native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
427 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800428 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700429 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
430 }
Tim Murray460a0492013-11-19 12:45:54 -0800431 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
432 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800433 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800434 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
435 }
436
Tim Murray460a0492013-11-19 12:45:54 -0800437 native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
438 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800439 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800440 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
441 }
442
443
Tim Murray460a0492013-11-19 12:45:54 -0800444 native void rsnAllocationSyncAll(long con, long alloc, int src);
445 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800446 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800447 rsnAllocationSyncAll(mContext, alloc, src);
448 }
Tim Murray460a0492013-11-19 12:45:54 -0800449 native Surface rsnAllocationGetSurface(long con, long alloc);
450 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800451 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800452 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700453 }
Tim Murray460a0492013-11-19 12:45:54 -0800454 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
455 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800456 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700457 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800458 }
Tim Murray460a0492013-11-19 12:45:54 -0800459 native void rsnAllocationIoSend(long con, long alloc);
460 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800461 validate();
462 rsnAllocationIoSend(mContext, alloc);
463 }
Tim Murray460a0492013-11-19 12:45:54 -0800464 native void rsnAllocationIoReceive(long con, long alloc);
465 synchronized void nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800466 validate();
467 rsnAllocationIoReceive(mContext, alloc);
468 }
469
Jason Sams615e7ce2012-01-13 14:01:20 -0800470
Tim Murray460a0492013-11-19 12:45:54 -0800471 native void rsnAllocationGenerateMipmaps(long con, long alloc);
472 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800473 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800474 rsnAllocationGenerateMipmaps(mContext, alloc);
475 }
Tim Murray460a0492013-11-19 12:45:54 -0800476 native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
477 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800478 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800479 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700480 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700481
Jason Sams49a05d72010-12-29 14:31:29 -0800482
Miao Wang87e908d2015-03-02 15:15:15 -0800483 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
484 int mSize, boolean usePadding);
485 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
486 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800487 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800488 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700489 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700490
Miao Wangc8e237e2015-02-20 18:36:32 -0800491 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
492 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 -0800493 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800494 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700495 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700496
Tim Murrayeff663f2013-11-15 13:08:30 -0800497 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800498 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700499 int dstMip, int dstFace,
500 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800501 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700502 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800503 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700504 int dstMip, int dstFace,
505 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800506 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700507 int srcMip, int srcFace) {
508 validate();
509 rsnAllocationData2D(mContext,
510 dstAlloc, dstXoff, dstYoff,
511 dstMip, dstFace,
512 width, height,
513 srcAlloc, srcXoff, srcYoff,
514 srcMip, srcFace);
515 }
516
Tim Murray460a0492013-11-19 12:45:54 -0800517 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800518 int w, int h, Object d, int sizeBytes, int dt,
519 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800520 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800521 int w, int h, Object d, int sizeBytes, Element.DataType dt,
522 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800523 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800524 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700525 }
Jason Sams21659ac2013-11-06 15:08:07 -0800526
Tim Murray460a0492013-11-19 12:45:54 -0800527 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
528 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800529 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800530 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
531 }
Jason Sams49a05d72010-12-29 14:31:29 -0800532
Tim Murrayeff663f2013-11-15 13:08:30 -0800533 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800534 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700535 int dstMip,
536 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800537 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700538 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800539 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700540 int dstMip,
541 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800542 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700543 int srcMip) {
544 validate();
545 rsnAllocationData3D(mContext,
546 dstAlloc, dstXoff, dstYoff, dstZoff,
547 dstMip, width, height, depth,
548 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
549 }
550
Tim Murray460a0492013-11-19 12:45:54 -0800551 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800552 int w, int h, int depth, Object d, int sizeBytes, int dt,
553 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800554 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800555 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
556 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700557 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800558 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
559 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700560 }
Jason Samsb05d6892013-04-09 15:59:24 -0700561
Miao Wang87e908d2015-03-02 15:15:15 -0800562 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
563 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800564 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800565 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800566 }
Jason Sams21659ac2013-11-06 15:08:07 -0800567
Tim Murray460a0492013-11-19 12:45:54 -0800568 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800569 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800570 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800571 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800572 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800573 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800574 }
Jason Sams21659ac2013-11-06 15:08:07 -0800575
Miao Wangc8e237e2015-02-20 18:36:32 -0800576 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800577 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800578 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800579 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800580 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800581 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800582 }
583
Tim Murray460a0492013-11-19 12:45:54 -0800584 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800585 int w, int h, Object d, int sizeBytes, int dt,
586 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800587 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800588 int w, int h, Object d, int sizeBytes, Element.DataType dt,
589 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800590 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800591 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700592 }
Jason Sams21659ac2013-11-06 15:08:07 -0800593
Miao Wangc8e237e2015-02-20 18:36:32 -0800594 native void rsnAllocationRead3D(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);
Miao Wangc8e237e2015-02-20 18:36:32 -0800597 synchronized void nAllocationRead3D(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) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800600 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800601 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800602 }
603
Tim Murray460a0492013-11-19 12:45:54 -0800604 native long rsnAllocationGetType(long con, long id);
605 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800606 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700607 return rsnAllocationGetType(mContext, id);
608 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700609
Tim Murray460a0492013-11-19 12:45:54 -0800610 native void rsnAllocationResize1D(long con, long id, int dimX);
611 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800612 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700613 rsnAllocationResize1D(mContext, id, dimX);
614 }
Jason Sams5edc6082010-10-05 13:32:49 -0700615
Jason Sams46ba27e32015-02-06 17:45:15 -0800616 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
617 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
618 validate();
619 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
620 }
621
622 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
623 int mip, int face, int a1, int a2, int a3, int a4);
624 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
625 int mip, int face, int a1, int a2, int a3, int a4) {
626 validate();
627 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
628 }
629
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000630 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
631 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800632 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700633 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
634 }
Tim Murray460a0492013-11-19 12:45:54 -0800635 native long rsnFileA3DCreateFromFile(long con, String path);
636 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800637 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800638 return rsnFileA3DCreateFromFile(mContext, path);
639 }
Tim Murray460a0492013-11-19 12:45:54 -0800640 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
641 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800642 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800643 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
644 }
Tim Murray460a0492013-11-19 12:45:54 -0800645 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
646 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800647 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700648 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
649 }
Tim Murray460a0492013-11-19 12:45:54 -0800650 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
651 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800652 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700653 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
654 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000655 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
656 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800657 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700658 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
659 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700660
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000661 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
662 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800663 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700664 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
665 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000666 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
667 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800668 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800669 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
670 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000671 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
672 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800673 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800674 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
675 }
Jason Sams22534172009-08-04 16:58:20 -0700676
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700677
Tim Murray460a0492013-11-19 12:45:54 -0800678 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
679 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800680 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700681 rsnScriptBindAllocation(mContext, script, alloc, slot);
682 }
Tim Murray460a0492013-11-19 12:45:54 -0800683 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
684 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800685 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700686 rsnScriptSetTimeZone(mContext, script, timeZone);
687 }
Tim Murray460a0492013-11-19 12:45:54 -0800688 native void rsnScriptInvoke(long con, long id, int slot);
689 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800690 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700691 rsnScriptInvoke(mContext, id, slot);
692 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700693
694 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
695 long aout, byte[] params, int[] limits);
696
697 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
698 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700699 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700700 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700701 }
702
Tim Murray460a0492013-11-19 12:45:54 -0800703 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
704 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800705 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700706 rsnScriptInvokeV(mContext, id, slot, params);
707 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700708
Tim Murray460a0492013-11-19 12:45:54 -0800709 native void rsnScriptSetVarI(long con, long id, int slot, int val);
710 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800711 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700712 rsnScriptSetVarI(mContext, id, slot, val);
713 }
Tim Murray460a0492013-11-19 12:45:54 -0800714 native int rsnScriptGetVarI(long con, long id, int slot);
715 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700716 validate();
717 return rsnScriptGetVarI(mContext, id, slot);
718 }
719
Tim Murray460a0492013-11-19 12:45:54 -0800720 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
721 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800722 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700723 rsnScriptSetVarJ(mContext, id, slot, val);
724 }
Tim Murray460a0492013-11-19 12:45:54 -0800725 native long rsnScriptGetVarJ(long con, long id, int slot);
726 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700727 validate();
728 return rsnScriptGetVarJ(mContext, id, slot);
729 }
730
Tim Murray460a0492013-11-19 12:45:54 -0800731 native void rsnScriptSetVarF(long con, long id, int slot, float val);
732 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800733 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700734 rsnScriptSetVarF(mContext, id, slot, val);
735 }
Tim Murray460a0492013-11-19 12:45:54 -0800736 native float rsnScriptGetVarF(long con, long id, int slot);
737 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700738 validate();
739 return rsnScriptGetVarF(mContext, id, slot);
740 }
Tim Murray460a0492013-11-19 12:45:54 -0800741 native void rsnScriptSetVarD(long con, long id, int slot, double val);
742 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800743 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700744 rsnScriptSetVarD(mContext, id, slot, val);
745 }
Tim Murray460a0492013-11-19 12:45:54 -0800746 native double rsnScriptGetVarD(long con, long id, int slot);
747 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700748 validate();
749 return rsnScriptGetVarD(mContext, id, slot);
750 }
Tim Murray460a0492013-11-19 12:45:54 -0800751 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
752 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800753 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700754 rsnScriptSetVarV(mContext, id, slot, val);
755 }
Tim Murray460a0492013-11-19 12:45:54 -0800756 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
757 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700758 validate();
759 rsnScriptGetVarV(mContext, id, slot, val);
760 }
Tim Murray460a0492013-11-19 12:45:54 -0800761 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
762 long e, int[] dims);
763 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
764 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700765 validate();
766 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
767 }
Tim Murray460a0492013-11-19 12:45:54 -0800768 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
769 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800770 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800771 rsnScriptSetVarObj(mContext, id, slot, val);
772 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700773
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000774 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700775 byte[] script, int length);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000776 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800777 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700778 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700779 }
Jason Samsebfb4362009-09-23 13:57:02 -0700780
Tim Murray460a0492013-11-19 12:45:54 -0800781 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
782 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700783 validate();
784 return rsnScriptIntrinsicCreate(mContext, id, eid);
785 }
786
Tim Murray460a0492013-11-19 12:45:54 -0800787 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
788 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700789 validate();
790 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
791 }
792
Yang Nibe392ad2015-01-23 17:16:02 -0800793 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
794 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
795 validate();
796 return rsnScriptInvokeIDCreate(mContext, sid, slot);
797 }
798
Tim Murray460a0492013-11-19 12:45:54 -0800799 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
800 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700801 validate();
802 return rsnScriptFieldIDCreate(mContext, sid, slot);
803 }
804
Ashok Bhat98071552014-02-12 09:54:43 +0000805 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
806 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700807 validate();
808 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
809 }
810
Tim Murray460a0492013-11-19 12:45:54 -0800811 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
812 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700813 validate();
814 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
815 }
816
Tim Murray460a0492013-11-19 12:45:54 -0800817 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
818 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700819 validate();
820 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
821 }
822
Tim Murray460a0492013-11-19 12:45:54 -0800823 native void rsnScriptGroupExecute(long con, long group);
824 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700825 validate();
826 rsnScriptGroupExecute(mContext, group);
827 }
828
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000829 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700830 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000831 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700832 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800833 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700834 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700835 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800836
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000837 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700838 boolean depthMask, boolean dither,
839 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000840 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700841 boolean depthMask, boolean dither,
842 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800843 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700844 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
845 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700846 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700847
Tim Murray460a0492013-11-19 12:45:54 -0800848 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
849 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800850 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700851 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700852 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700853
Tim Murray460a0492013-11-19 12:45:54 -0800854 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
855 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800856 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700857 rsnProgramBindConstants(mContext, pv, slot, mID);
858 }
Tim Murray460a0492013-11-19 12:45:54 -0800859 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
860 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800861 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700862 rsnProgramBindTexture(mContext, vpf, slot, a);
863 }
Tim Murray460a0492013-11-19 12:45:54 -0800864 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
865 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800866 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700867 rsnProgramBindSampler(mContext, vpf, slot, s);
868 }
Ashok Bhat98071552014-02-12 09:54:43 +0000869 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
870 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800871 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800872 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700873 }
Ashok Bhat98071552014-02-12 09:54:43 +0000874 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
875 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800876 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800877 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700878 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700879
Ashok Bhat98071552014-02-12 09:54:43 +0000880 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
881 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800882 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700883 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800884 }
Tim Murray460a0492013-11-19 12:45:54 -0800885 native int rsnMeshGetVertexBufferCount(long con, long id);
886 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800887 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700888 return rsnMeshGetVertexBufferCount(mContext, id);
889 }
Tim Murray460a0492013-11-19 12:45:54 -0800890 native int rsnMeshGetIndexCount(long con, long id);
891 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800892 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700893 return rsnMeshGetIndexCount(mContext, id);
894 }
Ashok Bhat98071552014-02-12 09:54:43 +0000895 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
896 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800897 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700898 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
899 }
Ashok Bhat98071552014-02-12 09:54:43 +0000900 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
901 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800902 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700903 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
904 }
905
Tim Murray25207df2015-01-12 16:47:56 -0800906 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
907 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
908 float alpha, long A, long B, float beta, long C, int incX, int incY,
909 int KL, int KU);
910 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
911 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
912 float alpha, long A, long B, float beta, long C, int incX, int incY,
913 int KL, int KU) {
914 validate();
915 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
916 }
917
918 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
919 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
920 double alpha, long A, long B, double beta, long C, int incX, int incY,
921 int KL, int KU);
922 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
923 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
924 double alpha, long A, long B, double beta, long C, int incX, int incY,
925 int KL, int KU) {
926 validate();
927 rsnScriptIntrinsicBLAS_Double(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_Complex(long con, long id, int func, int TransA,
931 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
932 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
933 int KL, int KU);
934 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
935 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
936 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
937 int KL, int KU) {
938 validate();
939 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
940 }
941
942 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
943 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
944 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
945 int KL, int KU);
946 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
947 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
948 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
949 int KL, int KU) {
950 validate();
951 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
952 }
953
Tim Murray9cb16a22015-04-01 11:07:16 -0700954 native void rsnScriptIntrinsicBLAS_BNNM(long con, long id, int M, int N, int K,
955 long A, int a_offset, long B, int b_offset, long C, int c_offset,
956 int c_mult_int);
957 synchronized void nScriptIntrinsicBLAS_BNNM(long id, int M, int N, int K,
958 long A, int a_offset, long B, int b_offset, long C, int c_offset,
959 int c_mult_int) {
960 validate();
961 rsnScriptIntrinsicBLAS_BNNM(mContext, id, M, N, K, A, a_offset, B, b_offset, C, c_offset, c_mult_int);
962 }
963
964
Tim Murray25207df2015-01-12 16:47:56 -0800965
Tim Murrayeff663f2013-11-15 13:08:30 -0800966 long mDev;
967 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -0800968 private boolean mDestroyed = false;
969
Romain Guy650a3eb2009-08-31 14:06:43 -0700970 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800971 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700972
Jason Sams8cb39de2010-06-01 15:47:01 -0700973 Element mElement_U8;
974 Element mElement_I8;
975 Element mElement_U16;
976 Element mElement_I16;
977 Element mElement_U32;
978 Element mElement_I32;
Stephen Hines52d83632010-10-11 16:10:42 -0700979 Element mElement_U64;
Stephen Hinesef1dac22010-10-01 15:39:33 -0700980 Element mElement_I64;
Jason Samsa5835a22014-11-05 15:16:26 -0800981 Element mElement_F16;
Jason Sams8cb39de2010-06-01 15:47:01 -0700982 Element mElement_F32;
Stephen Hines02f417052010-09-30 15:19:22 -0700983 Element mElement_F64;
Jason Samsf110d4b2010-06-21 17:42:41 -0700984 Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -0700985
Jason Sams8cb39de2010-06-01 15:47:01 -0700986 Element mElement_ELEMENT;
987 Element mElement_TYPE;
988 Element mElement_ALLOCATION;
989 Element mElement_SAMPLER;
990 Element mElement_SCRIPT;
991 Element mElement_MESH;
992 Element mElement_PROGRAM_FRAGMENT;
993 Element mElement_PROGRAM_VERTEX;
994 Element mElement_PROGRAM_RASTER;
995 Element mElement_PROGRAM_STORE;
Stephen Hines3a291412012-04-11 17:27:29 -0700996 Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -0700997
Jason Sams3c0dfba2009-09-27 17:50:38 -0700998 Element mElement_A_8;
999 Element mElement_RGB_565;
1000 Element mElement_RGB_888;
1001 Element mElement_RGBA_5551;
1002 Element mElement_RGBA_4444;
1003 Element mElement_RGBA_8888;
1004
Jason Samsa5835a22014-11-05 15:16:26 -08001005 Element mElement_HALF_2;
1006 Element mElement_HALF_3;
1007 Element mElement_HALF_4;
1008
Jason Sams8cb39de2010-06-01 15:47:01 -07001009 Element mElement_FLOAT_2;
1010 Element mElement_FLOAT_3;
1011 Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001012
1013 Element mElement_DOUBLE_2;
1014 Element mElement_DOUBLE_3;
1015 Element mElement_DOUBLE_4;
1016
1017 Element mElement_UCHAR_2;
1018 Element mElement_UCHAR_3;
Jason Sams8cb39de2010-06-01 15:47:01 -07001019 Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001020
Stephen Hines836c4a52011-06-01 14:38:10 -07001021 Element mElement_CHAR_2;
1022 Element mElement_CHAR_3;
1023 Element mElement_CHAR_4;
1024
1025 Element mElement_USHORT_2;
1026 Element mElement_USHORT_3;
1027 Element mElement_USHORT_4;
1028
1029 Element mElement_SHORT_2;
1030 Element mElement_SHORT_3;
1031 Element mElement_SHORT_4;
1032
1033 Element mElement_UINT_2;
1034 Element mElement_UINT_3;
1035 Element mElement_UINT_4;
1036
1037 Element mElement_INT_2;
1038 Element mElement_INT_3;
1039 Element mElement_INT_4;
1040
1041 Element mElement_ULONG_2;
1042 Element mElement_ULONG_3;
1043 Element mElement_ULONG_4;
1044
1045 Element mElement_LONG_2;
1046 Element mElement_LONG_3;
1047 Element mElement_LONG_4;
1048
Tim Murray932e78e2013-09-03 11:42:26 -07001049 Element mElement_YUV;
1050
Jason Sams1d45c472010-08-25 14:31:48 -07001051 Element mElement_MATRIX_4X4;
1052 Element mElement_MATRIX_3X3;
1053 Element mElement_MATRIX_2X2;
1054
Jason Sams4d339932010-05-11 14:03:58 -07001055 Sampler mSampler_CLAMP_NEAREST;
1056 Sampler mSampler_CLAMP_LINEAR;
1057 Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1058 Sampler mSampler_WRAP_NEAREST;
1059 Sampler mSampler_WRAP_LINEAR;
1060 Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
Tim Murray6b9b2ca2013-02-15 13:25:55 -08001061 Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1062 Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1063 Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001064
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001065 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1066 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001067 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1068 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001069
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001070 ProgramRaster mProgramRaster_CULL_BACK;
1071 ProgramRaster mProgramRaster_CULL_FRONT;
1072 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001073
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001074 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001075 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001076
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001077 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001078 * The base class from which an application should derive in order
1079 * to receive RS messages from scripts. When a script calls {@code
1080 * rsSendToClient}, the data fields will be filled, and the run
1081 * method will be called on a separate thread. This will occur
1082 * some time after {@code rsSendToClient} completes in the script,
1083 * as {@code rsSendToClient} is asynchronous. Message handlers are
1084 * not guaranteed to have completed when {@link
1085 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001086 *
1087 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001088 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001089 protected int[] mData;
1090 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001091 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001092 public void run() {
1093 }
1094 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001095 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001096 * If an application is expecting messages, it should set this
1097 * field to an instance of {@link RSMessageHandler}. This
1098 * instance will receive all the user messages sent from {@code
1099 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001100 *
1101 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001102 RSMessageHandler mMessageCallback = null;
1103
1104 public void setMessageHandler(RSMessageHandler msg) {
1105 mMessageCallback = msg;
1106 }
1107 public RSMessageHandler getMessageHandler() {
1108 return mMessageCallback;
1109 }
Jason Sams516c3192009-10-06 13:58:47 -07001110
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001111 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001112 * Place a message into the message queue to be sent back to the message
1113 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001114 *
1115 * @param id
1116 * @param data
1117 */
1118 public void sendMessage(int id, int[] data) {
1119 nContextSendMessage(id, data);
1120 }
1121
1122 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001123 * The runtime error handler base class. An application should derive from this class
1124 * if it wishes to install an error handler. When errors occur at runtime,
1125 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001126 *
1127 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001128 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001129 protected String mErrorMessage;
1130 protected int mErrorNum;
1131 public void run() {
1132 }
1133 }
Jason Sams27676fe2010-11-10 17:00:59 -08001134
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001135 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001136 * Application Error handler. All runtime errors will be dispatched to the
1137 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001138 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001139 * This will cause program termaination.
1140 *
1141 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001142 RSErrorHandler mErrorCallback = null;
1143
1144 public void setErrorHandler(RSErrorHandler msg) {
1145 mErrorCallback = msg;
1146 }
1147 public RSErrorHandler getErrorHandler() {
1148 return mErrorCallback;
1149 }
Jason Sams1c415172010-11-08 17:06:46 -08001150
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001151 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001152 * RenderScript worker thread priority enumeration. The default value is
1153 * NORMAL. Applications wishing to do background processing should set
1154 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001155 */
Jason Sams7d787b42009-11-15 12:14:26 -08001156 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001157 // These values used to represent official thread priority values
1158 // now they are simply enums to be used by the runtime side
1159 LOW (15),
1160 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001161
1162 int mID;
1163 Priority(int id) {
1164 mID = id;
1165 }
1166 }
1167
Jason Sams678cc7f2014-03-05 16:09:02 -08001168 void validateObject(BaseObj o) {
1169 if (o != null) {
1170 if (o.mRS != this) {
1171 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1172 }
1173 }
1174 }
1175
Jason Sams771bebb2009-12-07 12:40:12 -08001176 void validate() {
1177 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001178 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001179 }
1180 }
1181
Jason Sams27676fe2010-11-10 17:00:59 -08001182
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001183 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001184 * Change the priority of the worker threads for this context.
1185 *
1186 * @param p New priority to be set.
1187 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001188 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001189 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001190 nContextSetPriority(p.mID);
1191 }
1192
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001193 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001194 RenderScript mRS;
1195 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001196 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001197
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001198 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1199 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1200 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1201 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1202 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001203 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001204
Stephen Hines42028a82013-04-17 19:22:01 -07001205 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001206 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001207
Jason Sams516c3192009-10-06 13:58:47 -07001208 MessageThread(RenderScript rs) {
1209 super("RSMessageThread");
1210 mRS = rs;
1211
1212 }
1213
1214 public void run() {
1215 // This function is a temporary solution. The final solution will
1216 // used typed allocations where the message id is the type indicator.
1217 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001218 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001219 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001220 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001221 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001222 int size = mAuxData[1];
1223 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001224
1225 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1226 if ((size>>2) >= rbuf.length) {
1227 rbuf = new int[(size + 3) >> 2];
1228 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001229 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1230 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001231 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001232 }
Jason Sams1c415172010-11-08 17:06:46 -08001233
1234 if(mRS.mMessageCallback != null) {
1235 mRS.mMessageCallback.mData = rbuf;
1236 mRS.mMessageCallback.mID = subID;
1237 mRS.mMessageCallback.mLength = size;
1238 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001239 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001240 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001241 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001242 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001243 }
Jason Sams1c415172010-11-08 17:06:46 -08001244
1245 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1246 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1247
Stephen Hines42028a82013-04-17 19:22:01 -07001248 // Throw RSRuntimeException under the following conditions:
1249 //
1250 // 1) It is an unknown fatal error.
1251 // 2) It is a debug fatal error, and we are not in a
1252 // debug context.
1253 // 3) It is a debug fatal error, and we do not have an
1254 // error callback.
1255 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1256 (subID >= RS_ERROR_FATAL_DEBUG &&
1257 (mRS.mContextType != ContextType.DEBUG ||
1258 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001259 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1260 }
1261
Jason Sams1c415172010-11-08 17:06:46 -08001262 if(mRS.mErrorCallback != null) {
1263 mRS.mErrorCallback.mErrorMessage = e;
1264 mRS.mErrorCallback.mErrorNum = subID;
1265 mRS.mErrorCallback.run();
1266 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001267 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001268 // Do not throw here. In these cases, we do not have
1269 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001270 }
1271 continue;
1272 }
1273
Jason Sams739c8262013-04-11 18:07:52 -07001274 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001275 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1276 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1277 throw new RSDriverException("Error processing message from RenderScript.");
1278 }
1279 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1280 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001281 continue;
1282 }
1283
Jason Sams1c415172010-11-08 17:06:46 -08001284 // 2: teardown.
1285 // But we want to avoid starving other threads during
1286 // teardown by yielding until the next line in the destructor
1287 // can execute to set mRun = false
1288 try {
1289 sleep(1, 0);
1290 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001291 }
Jason Sams516c3192009-10-06 13:58:47 -07001292 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001293 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001294 }
1295 }
1296
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001297 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001298 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001299 if (ctx != null) {
1300 mApplicationContext = ctx.getApplicationContext();
1301 }
Tim Murray06b45672014-01-07 11:13:56 -08001302 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001303 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001304 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001305 } catch (Exception e) {
1306 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1307 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1308 }
1309
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001310 }
1311
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001312 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001313 * Gets the application context associated with the RenderScript context.
1314 *
1315 * @return The application context.
1316 */
1317 public final Context getApplicationContext() {
1318 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001319 }
1320
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001321 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001322 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001323 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001324 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001325 * @return RenderScript
1326 */
Jason Samse16da122015-03-18 17:04:18 -07001327 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001328 if (!sInitialized) {
1329 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1330 return null;
1331 }
1332
Jason Samsb69c7912014-05-20 18:48:35 -07001333 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER)) != 0) {
1334 throw new RSIllegalArgumentException("Invalid flags passed.");
1335 }
1336
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001337 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001338
1339 rs.mDev = rs.nDeviceCreate();
Tim Murrayfd710e72014-06-06 11:10:45 -07001340 rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001341 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001342 rs.mContextFlags = flags;
1343 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001344 if (rs.mContext == 0) {
1345 throw new RSDriverException("Failed to create RS context.");
1346 }
Tim Murray47f31582015-04-07 15:43:24 -07001347
1348 // set up cache directory for entire context
1349 final String CACHE_PATH = "com.android.renderscript.cache";
1350 File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
1351 String mCachePath = f.getAbsolutePath();
1352 f.mkdirs();
1353 rs.nContextSetCacheDir(mCachePath);
1354
Jason Sams704ff642010-02-09 16:05:07 -08001355 rs.mMessageThread = new MessageThread(rs);
1356 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001357 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001358 }
1359
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001360 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001361 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001362 *
1363 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001364 *
1365 * @param ctx The context.
1366 * @return RenderScript
1367 */
1368 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001369 return create(ctx, ContextType.NORMAL);
1370 }
1371
1372 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001373 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001374 *
Jason Samse16da122015-03-18 17:04:18 -07001375 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001376 *
1377 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001378 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001379 * @return RenderScript
1380 */
1381 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001382 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001383 }
1384
Miao Wanga4e5adf2015-03-23 11:09:56 -07001385
1386 /**
Jason Samse16da122015-03-18 17:04:18 -07001387 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001388 *
Jason Samse16da122015-03-18 17:04:18 -07001389 * The returned context will be cached for future reuse within
1390 * the process. When an application is finished using
1391 * RenderScript it should call releaseAllContexts()
1392 *
1393 * A process context is a context designed for easy creation and
1394 * lifecycle management. Multiple calls to this function will
1395 * return the same object provided they are called with the same
1396 * options. This allows it to be used any time a RenderScript
1397 * context is needed.
1398 *
1399 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001400 *
1401 * @param ctx The context.
1402 * @param ct The type of context to be created.
1403 * @param flags The OR of the CREATE_FLAG_* options desired
1404 * @return RenderScript
1405 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001406 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001407 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001408 return create(ctx, v, ct, flags);
1409 }
1410
1411 /**
1412 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1413 *
1414 * Used by the RenderScriptThunker to maintain backward compatibility.
1415 *
1416 * @hide
1417 * @param ctx The context.
1418 * @param sdkVersion The target SDK Version.
1419 * @return RenderScript
1420 */
1421 public static RenderScript create(Context ctx, int sdkVersion) {
1422 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1423 }
1424
1425 /**
1426 * Gets or creates a RenderScript context of the specified type.
1427 *
Miao Wanga4e5adf2015-03-23 11:09:56 -07001428 * @param ctx The context.
1429 * @param ct The type of context to be created.
1430 * @param sdkVersion The target SDK Version.
1431 * @param flags The OR of the CREATE_FLAG_* options desired
1432 * @return RenderScript
1433 */
Jason Sams6a420b52015-03-30 15:31:26 -07001434 private static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
Miao Wanga4e5adf2015-03-23 11:09:56 -07001435 if (sdkVersion < 23) {
1436 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001437 }
1438
1439 synchronized (mProcessContextList) {
1440 for (RenderScript prs : mProcessContextList) {
1441 if ((prs.mContextType == ct) &&
1442 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001443 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001444
1445 return prs;
1446 }
1447 }
1448
Miao Wanga4e5adf2015-03-23 11:09:56 -07001449 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001450 prs.mIsProcessContext = true;
1451 mProcessContextList.add(prs);
1452 return prs;
1453 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001454 }
1455
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001456 /**
Jason Samse16da122015-03-18 17:04:18 -07001457 * Releases all the process contexts. This is the same as
1458 * calling .destroy() on each unique context retreived with
1459 * create(...). If no contexts have been created this
1460 * function does nothing.
1461 *
1462 * Typically you call this when your application is losing focus
1463 * and will not be using a context for some time.
1464 *
1465 * This has no effect on a context created with
1466 * createMultiContext()
1467 */
1468 public static void releaseAllContexts() {
1469 ArrayList<RenderScript> oldList;
1470 synchronized (mProcessContextList) {
1471 oldList = mProcessContextList;
1472 mProcessContextList = new ArrayList<RenderScript>();
1473 }
1474
1475 for (RenderScript prs : oldList) {
1476 prs.mIsProcessContext = false;
1477 prs.destroy();
1478 }
1479 oldList.clear();
1480 }
1481
1482
1483
1484 /**
1485 * Create a RenderScript context.
1486 *
1487 * This is an advanced function intended for applications which
1488 * need to create more than one RenderScript context to be used
1489 * at the same time.
1490 *
1491 * If you need a single context please use create()
1492 *
Jason Samse16da122015-03-18 17:04:18 -07001493 * @param ctx The context.
1494 * @return RenderScript
1495 */
1496 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1497 return internalCreate(ctx, API_number, ct, flags);
1498 }
1499
1500
1501 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001502 * Print the currently available debugging information about the state of
1503 * the RS context to the log.
1504 *
Jason Sams27676fe2010-11-10 17:00:59 -08001505 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001506 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001507 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001508 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001509 }
1510
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001511 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001512 * Wait for any pending asynchronous opeations (such as copies to a RS
1513 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001514 *
1515 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001516 public void finish() {
1517 nContextFinish();
1518 }
1519
Jason Samsd22a6f02015-02-19 17:19:52 -08001520 private void helpDestroy() {
1521 boolean shouldDestroy = false;
1522 synchronized(this) {
1523 if (!mDestroyed) {
1524 shouldDestroy = true;
1525 mDestroyed = true;
1526 }
1527 }
1528
1529 if (shouldDestroy) {
1530 nContextFinish();
1531
1532 nContextDeinitToClient(mContext);
1533 mMessageThread.mRun = false;
1534 try {
1535 mMessageThread.join();
1536 } catch(InterruptedException e) {
1537 }
1538
1539 nContextDestroy();
1540
1541 nDeviceDestroy(mDev);
1542 mDev = 0;
1543 }
1544 }
1545
1546 protected void finalize() throws Throwable {
1547 helpDestroy();
1548 super.finalize();
1549 }
1550
1551
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001552 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001553 * Destroys this RenderScript context. Once this function is called,
1554 * using this context or any objects belonging to this context is
1555 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001556 *
Jason Samse16da122015-03-18 17:04:18 -07001557 * API 23+, this function is a NOP if the context was created
1558 * with create(). Please use releaseAllContexts() to clean up
1559 * contexts created with the create function.
1560 *
Jason Sams27676fe2010-11-10 17:00:59 -08001561 */
Jason Samsf5b45962009-08-25 14:49:07 -07001562 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001563 if (mIsProcessContext) {
1564 // users cannot destroy a process context
1565 return;
1566 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001567 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001568 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001569 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001570
Jason Samsa9e7a052009-09-25 14:51:22 -07001571 boolean isAlive() {
1572 return mContext != 0;
1573 }
1574
Tim Murray460a0492013-11-19 12:45:54 -08001575 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001576 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001577 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001578 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001579 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001580 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001581}