blob: 8b1a0324956ae91aa3144a864a518955ee4488d7 [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
Jason Samsf7642302015-05-12 14:06:56 -0700134 static final long sMinorVersion = 1;
Tim Murray67cc2d02014-02-06 16:39:38 -0800135
136 /**
Miao Wangf9d518a2015-05-14 14:53:30 -0700137 * @hide
138 *
139 * Only exist to be compatible with old version RenderScript Support lib.
140 * Will eventually be removed.
141 *
142 * @return Always return 1
143 *
144 */
145 public static long getMinorID() {
146 return 1;
147 }
148
149
150 /**
Tim Murray67cc2d02014-02-06 16:39:38 -0800151 * Returns an identifier that can be used to identify a particular
152 * minor version of RS.
153 *
Jason Sams6a420b52015-03-30 15:31:26 -0700154 * @return The minor RenderScript version number
155 *
Tim Murray67cc2d02014-02-06 16:39:38 -0800156 */
Jason Samsf7642302015-05-12 14:06:56 -0700157 public static long getMinorVersion() {
158 return sMinorVersion;
Tim Murray67cc2d02014-02-06 16:39:38 -0800159 }
160
Jason Sams02d56d92013-04-12 16:40:50 -0700161 /**
162 * ContextType specifies the specific type of context to be created.
163 *
164 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800165 public enum ContextType {
Jason Sams02d56d92013-04-12 16:40:50 -0700166 /**
167 * NORMAL context, this is the default and what shipping apps should
168 * use.
169 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800170 NORMAL (0),
Jason Sams02d56d92013-04-12 16:40:50 -0700171
172 /**
173 * DEBUG context, perform extra runtime checks to validate the
174 * kernels and APIs are being used as intended. Get and SetElementAt
175 * will be bounds checked in this mode.
176 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800177 DEBUG (1),
Jason Sams02d56d92013-04-12 16:40:50 -0700178
179 /**
180 * PROFILE context, Intended to be used once the first time an
181 * application is run on a new device. This mode allows the runtime to
182 * do additional testing and performance tuning.
183 */
Jason Samsadd26dc2013-02-22 18:43:45 -0800184 PROFILE (2);
185
186 int mID;
187 ContextType(int id) {
188 mID = id;
189 }
190 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800191
Stephen Hines42028a82013-04-17 19:22:01 -0700192 ContextType mContextType;
Tim Murray06b45672014-01-07 11:13:56 -0800193 ReentrantReadWriteLock mRWLock;
Stephen Hines42028a82013-04-17 19:22:01 -0700194
Jason Sams2e1872f2010-08-17 16:25:41 -0700195 // Methods below are wrapped to protect the non-threadsafe
196 // lockless fifo.
Tim Murrayeff663f2013-11-15 13:08:30 -0800197 native long rsnContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700198 int colorMin, int colorPref,
199 int alphaMin, int alphaPref,
200 int depthMin, int depthPref,
201 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700202 int samplesMin, int samplesPref, float samplesQ, int dpi);
Tim Murrayeff663f2013-11-15 13:08:30 -0800203 synchronized long nContextCreateGL(long dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700204 int colorMin, int colorPref,
205 int alphaMin, int alphaPref,
206 int depthMin, int depthPref,
207 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700208 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700209 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700210 alphaMin, alphaPref, depthMin, depthPref,
211 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700212 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700213 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800214 native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
215 synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
Jason Samsadd26dc2013-02-22 18:43:45 -0800216 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700217 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800218 native void rsnContextDestroy(long con);
Jason Sams2e1872f2010-08-17 16:25:41 -0700219 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800220 validate();
Tim Murray06b45672014-01-07 11:13:56 -0800221
222 // take teardown lock
223 // teardown lock can only be taken when no objects are being destroyed
224 ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
225 wlock.lock();
226
227 long curCon = mContext;
228 // context is considered dead as of this point
229 mContext = 0;
230
231 wlock.unlock();
232 rsnContextDestroy(curCon);
Jason Sams2e1872f2010-08-17 16:25:41 -0700233 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800234 native void rsnContextSetSurface(long con, int w, int h, Surface sur);
Jason Sams2e1872f2010-08-17 16:25:41 -0700235 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800236 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700237 rsnContextSetSurface(mContext, w, h, sur);
238 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800239 native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur);
Jason Samsfaa32b32011-06-20 16:58:04 -0700240 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
241 validate();
242 rsnContextSetSurfaceTexture(mContext, w, h, sur);
243 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800244 native void rsnContextSetPriority(long con, int p);
Jason Sams2e1872f2010-08-17 16:25:41 -0700245 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800246 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700247 rsnContextSetPriority(mContext, p);
248 }
Tim Murray47f31582015-04-07 15:43:24 -0700249 native void rsnContextSetCacheDir(long con, String cacheDir);
250 synchronized void nContextSetCacheDir(String cacheDir) {
251 validate();
252 rsnContextSetCacheDir(mContext, cacheDir);
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();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700319 long c = rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values,
Yang Ni281c3252014-10-24 08:52:24 -0700320 sizes, depClosures, depFieldIDs);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700321 if (c == 0) {
322 throw new RSRuntimeException("Failed creating closure.");
323 }
324 return c;
Yang Ni281c3252014-10-24 08:52:24 -0700325 }
326
Yang Nibe392ad2015-01-23 17:16:02 -0800327 native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params,
328 long[] fieldIDs, long[] values, int[] sizes);
329 synchronized long nInvokeClosureCreate(long invokeID, byte[] params,
330 long[] fieldIDs, long[] values, int[] sizes) {
331 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700332 long c = rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs,
Yang Nibe392ad2015-01-23 17:16:02 -0800333 values, sizes);
Yang Ni17c2d7a2015-04-30 16:13:54 -0700334 if (c == 0) {
335 throw new RSRuntimeException("Failed creating closure.");
336 }
337 return c;
Yang Nibe392ad2015-01-23 17:16:02 -0800338 }
339
Yang Ni281c3252014-10-24 08:52:24 -0700340 native void rsnClosureSetArg(long con, long closureID, int index,
341 long value, int size);
342 synchronized void nClosureSetArg(long closureID, int index, long value,
343 int size) {
344 validate();
345 rsnClosureSetArg(mContext, closureID, index, value, size);
346 }
347
348 native void rsnClosureSetGlobal(long con, long closureID, long fieldID,
349 long value, int size);
350 // Does this have to be synchronized?
351 synchronized void nClosureSetGlobal(long closureID, long fieldID,
352 long value, int size) {
353 validate(); // TODO: is this necessary?
354 rsnClosureSetGlobal(mContext, closureID, fieldID, value, size);
355 }
356
Yang Ni35be56c2015-04-02 17:47:56 -0700357 native long rsnScriptGroup2Create(long con, String name, String cachePath,
358 long[] closures);
359 synchronized long nScriptGroup2Create(String name, String cachePath,
360 long[] closures) {
Yang Ni281c3252014-10-24 08:52:24 -0700361 validate();
Yang Ni17c2d7a2015-04-30 16:13:54 -0700362 long g = rsnScriptGroup2Create(mContext, name, cachePath, closures);
363 if (g == 0) {
364 throw new RSRuntimeException("Failed creating script group.");
365 }
366 return g;
Yang Ni281c3252014-10-24 08:52:24 -0700367 }
368
369 native void rsnScriptGroup2Execute(long con, long groupID);
370 synchronized void nScriptGroup2Execute(long groupID) {
371 validate();
372 rsnScriptGroup2Execute(mContext, groupID);
373 }
374
Tim Murray460a0492013-11-19 12:45:54 -0800375 native void rsnAssignName(long con, long obj, byte[] name);
376 synchronized void nAssignName(long obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800377 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700378 rsnAssignName(mContext, obj, name);
379 }
Tim Murray460a0492013-11-19 12:45:54 -0800380 native String rsnGetName(long con, long obj);
381 synchronized String nGetName(long obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800382 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700383 return rsnGetName(mContext, obj);
384 }
Tim Murray06b45672014-01-07 11:13:56 -0800385
386 // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
Tim Murray460a0492013-11-19 12:45:54 -0800387 native void rsnObjDestroy(long con, long id);
Tim Murray06b45672014-01-07 11:13:56 -0800388 void nObjDestroy(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800389 // There is a race condition here. The calling code may be run
390 // by the gc while teardown is occuring. This protects againts
391 // deleting dead objects.
392 if (mContext != 0) {
393 rsnObjDestroy(mContext, id);
394 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700395 }
Jason Samsfe08d992009-05-27 14:45:32 -0700396
Tim Murray460a0492013-11-19 12:45:54 -0800397 native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize);
398 synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800399 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700400 return rsnElementCreate(mContext, type, kind, norm, vecSize);
401 }
Ashok Bhat98071552014-02-12 09:54:43 +0000402 native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes);
403 synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800404 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700405 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700406 }
Tim Murray460a0492013-11-19 12:45:54 -0800407 native void rsnElementGetNativeData(long con, long id, int[] elementData);
408 synchronized void nElementGetNativeData(long id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800409 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700410 rsnElementGetNativeData(mContext, id, elementData);
411 }
Tim Murray460a0492013-11-19 12:45:54 -0800412 native void rsnElementGetSubElements(long con, long id,
Ashok Bhat98071552014-02-12 09:54:43 +0000413 long[] IDs, String[] names, int[] arraySizes);
414 synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800415 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700416 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700417 }
Jason Sams768bc022009-09-21 19:41:04 -0700418
Tim Murray460a0492013-11-19 12:45:54 -0800419 native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
420 synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800421 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800422 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700423 }
Ashok Bhat98071552014-02-12 09:54:43 +0000424 native void rsnTypeGetNativeData(long con, long id, long[] typeData);
425 synchronized void nTypeGetNativeData(long id, long[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800426 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700427 rsnTypeGetNativeData(mContext, id, typeData);
428 }
Jason Sams768bc022009-09-21 19:41:04 -0700429
Ashok Bhat98071552014-02-12 09:54:43 +0000430 native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer);
431 synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800432 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800433 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700434 }
Tim Murray460a0492013-11-19 12:45:54 -0800435 native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
436 synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800437 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800438 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700439 }
Tim Murraya3145512012-12-04 17:59:29 -0800440
Tim Murray460a0492013-11-19 12:45:54 -0800441 native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
442 synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
Tim Murraya3145512012-12-04 17:59:29 -0800443 validate();
444 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
445 }
446
Tim Murray460a0492013-11-19 12:45:54 -0800447 native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
448 synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800449 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800450 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800451 }
Tim Murray460a0492013-11-19 12:45:54 -0800452 native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
453 synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800454 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700455 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
456 }
Tim Murray460a0492013-11-19 12:45:54 -0800457 native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
458 synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800459 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800460 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
461 }
462
Tim Murray460a0492013-11-19 12:45:54 -0800463 native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
464 synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800465 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800466 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
467 }
468
469
Tim Murray460a0492013-11-19 12:45:54 -0800470 native void rsnAllocationSyncAll(long con, long alloc, int src);
471 synchronized void nAllocationSyncAll(long alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800472 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800473 rsnAllocationSyncAll(mContext, alloc, src);
474 }
Tim Murray460a0492013-11-19 12:45:54 -0800475 native Surface rsnAllocationGetSurface(long con, long alloc);
476 synchronized Surface nAllocationGetSurface(long alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800477 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800478 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700479 }
Tim Murray460a0492013-11-19 12:45:54 -0800480 native void rsnAllocationSetSurface(long con, long alloc, Surface sur);
481 synchronized void nAllocationSetSurface(long alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800482 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700483 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800484 }
Tim Murray460a0492013-11-19 12:45:54 -0800485 native void rsnAllocationIoSend(long con, long alloc);
486 synchronized void nAllocationIoSend(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800487 validate();
488 rsnAllocationIoSend(mContext, alloc);
489 }
Tim Murray460a0492013-11-19 12:45:54 -0800490 native void rsnAllocationIoReceive(long con, long alloc);
491 synchronized void nAllocationIoReceive(long alloc) {
Jason Sams163766c2012-02-15 12:04:24 -0800492 validate();
493 rsnAllocationIoReceive(mContext, alloc);
494 }
495
Jason Sams615e7ce2012-01-13 14:01:20 -0800496
Tim Murray460a0492013-11-19 12:45:54 -0800497 native void rsnAllocationGenerateMipmaps(long con, long alloc);
498 synchronized void nAllocationGenerateMipmaps(long alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800499 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800500 rsnAllocationGenerateMipmaps(mContext, alloc);
501 }
Tim Murray460a0492013-11-19 12:45:54 -0800502 native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
503 synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800504 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800505 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700506 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700507
Jason Sams49a05d72010-12-29 14:31:29 -0800508
Miao Wang87e908d2015-03-02 15:15:15 -0800509 native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt,
510 int mSize, boolean usePadding);
511 synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt,
512 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800513 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800514 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700515 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700516
Miao Wangc8e237e2015-02-20 18:36:32 -0800517 native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes);
518 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 -0800519 validate();
Miao Wangc8e237e2015-02-20 18:36:32 -0800520 rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700521 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700522
Tim Murrayeff663f2013-11-15 13:08:30 -0800523 native void rsnAllocationData2D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800524 long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700525 int dstMip, int dstFace,
526 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800527 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700528 int srcMip, int srcFace);
Tim Murray460a0492013-11-19 12:45:54 -0800529 synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700530 int dstMip, int dstFace,
531 int width, int height,
Tim Murray460a0492013-11-19 12:45:54 -0800532 long srcAlloc, int srcXoff, int srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700533 int srcMip, int srcFace) {
534 validate();
535 rsnAllocationData2D(mContext,
536 dstAlloc, dstXoff, dstYoff,
537 dstMip, dstFace,
538 width, height,
539 srcAlloc, srcXoff, srcYoff,
540 srcMip, srcFace);
541 }
542
Tim Murray460a0492013-11-19 12:45:54 -0800543 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800544 int w, int h, Object d, int sizeBytes, int dt,
545 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800546 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800547 int w, int h, Object d, int sizeBytes, Element.DataType dt,
548 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800549 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800550 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700551 }
Jason Sams21659ac2013-11-06 15:08:07 -0800552
Tim Murray460a0492013-11-19 12:45:54 -0800553 native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b);
554 synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800555 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800556 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
557 }
Jason Sams49a05d72010-12-29 14:31:29 -0800558
Tim Murrayeff663f2013-11-15 13:08:30 -0800559 native void rsnAllocationData3D(long con,
Tim Murray460a0492013-11-19 12:45:54 -0800560 long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700561 int dstMip,
562 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800563 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700564 int srcMip);
Tim Murray460a0492013-11-19 12:45:54 -0800565 synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700566 int dstMip,
567 int width, int height, int depth,
Tim Murray460a0492013-11-19 12:45:54 -0800568 long srcAlloc, int srcXoff, int srcYoff, int srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700569 int srcMip) {
570 validate();
571 rsnAllocationData3D(mContext,
572 dstAlloc, dstXoff, dstYoff, dstZoff,
573 dstMip, width, height, depth,
574 srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
575 }
576
Tim Murray460a0492013-11-19 12:45:54 -0800577 native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800578 int w, int h, int depth, Object d, int sizeBytes, int dt,
579 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800580 synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800581 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
582 int mSize, boolean usePadding) {
Jason Samsb05d6892013-04-09 15:59:24 -0700583 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800584 rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes,
585 dt.mID, mSize, usePadding);
Jason Samsb05d6892013-04-09 15:59:24 -0700586 }
Jason Samsb05d6892013-04-09 15:59:24 -0700587
Miao Wang87e908d2015-03-02 15:15:15 -0800588 native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding);
589 synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800590 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800591 rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800592 }
Jason Sams21659ac2013-11-06 15:08:07 -0800593
Tim Murray460a0492013-11-19 12:45:54 -0800594 native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800595 int sizeBytes, int dt, int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800596 synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d,
Miao Wang87e908d2015-03-02 15:15:15 -0800597 int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800598 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800599 rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Samsfa445b92011-01-07 17:00:07 -0800600 }
Jason Sams21659ac2013-11-06 15:08:07 -0800601
Miao Wangc8e237e2015-02-20 18:36:32 -0800602 native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800603 int mip, int compIdx, byte[] d, int sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800604 synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -0800605 int mip, int compIdx, byte[] d, int sizeBytes) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800606 validate();
Miao Wang45cec0a2015-03-04 16:40:21 -0800607 rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -0800608 }
609
Tim Murray460a0492013-11-19 12:45:54 -0800610 native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800611 int w, int h, Object d, int sizeBytes, int dt,
612 int mSize, boolean usePadding);
Tim Murray460a0492013-11-19 12:45:54 -0800613 synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face,
Miao Wang87e908d2015-03-02 15:15:15 -0800614 int w, int h, Object d, int sizeBytes, Element.DataType dt,
615 int mSize, boolean usePadding) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800616 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800617 rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding);
Jason Sams2e1872f2010-08-17 16:25:41 -0700618 }
Jason Sams21659ac2013-11-06 15:08:07 -0800619
Miao Wangc8e237e2015-02-20 18:36:32 -0800620 native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800621 int w, int h, int depth, Object d, int sizeBytes, int dt,
622 int mSize, boolean usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800623 synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip,
Miao Wang87e908d2015-03-02 15:15:15 -0800624 int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt,
625 int mSize, boolean usePadding) {
Miao Wangc8e237e2015-02-20 18:36:32 -0800626 validate();
Miao Wang87e908d2015-03-02 15:15:15 -0800627 rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding);
Miao Wangc8e237e2015-02-20 18:36:32 -0800628 }
629
Tim Murray460a0492013-11-19 12:45:54 -0800630 native long rsnAllocationGetType(long con, long id);
631 synchronized long nAllocationGetType(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800632 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700633 return rsnAllocationGetType(mContext, id);
634 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700635
Tim Murray460a0492013-11-19 12:45:54 -0800636 native void rsnAllocationResize1D(long con, long id, int dimX);
637 synchronized void nAllocationResize1D(long id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800638 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700639 rsnAllocationResize1D(mContext, id, dimX);
640 }
Jason Sams5edc6082010-10-05 13:32:49 -0700641
Jason Sams46ba27e32015-02-06 17:45:15 -0800642 native long rsnAllocationAdapterCreate(long con, long allocId, long typeId);
643 synchronized long nAllocationAdapterCreate(long allocId, long typeId) {
644 validate();
645 return rsnAllocationAdapterCreate(mContext, allocId, typeId);
646 }
647
648 native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z,
649 int mip, int face, int a1, int a2, int a3, int a4);
650 synchronized void nAllocationAdapterOffset(long id, int x, int y, int z,
651 int mip, int face, int a1, int a2, int a3, int a4) {
652 validate();
653 rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4);
654 }
655
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000656 native long rsnFileA3DCreateFromAssetStream(long con, long assetStream);
657 synchronized long nFileA3DCreateFromAssetStream(long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800658 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700659 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
660 }
Tim Murray460a0492013-11-19 12:45:54 -0800661 native long rsnFileA3DCreateFromFile(long con, String path);
662 synchronized long nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800663 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800664 return rsnFileA3DCreateFromFile(mContext, path);
665 }
Tim Murray460a0492013-11-19 12:45:54 -0800666 native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path);
667 synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800668 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800669 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
670 }
Tim Murray460a0492013-11-19 12:45:54 -0800671 native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D);
672 synchronized int nFileA3DGetNumIndexEntries(long fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800673 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700674 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
675 }
Tim Murray460a0492013-11-19 12:45:54 -0800676 native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names);
677 synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800678 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700679 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
680 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000681 native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index);
682 synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800683 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700684 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
685 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700686
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000687 native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi);
688 synchronized long nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800689 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700690 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
691 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000692 native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream);
693 synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800694 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800695 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
696 }
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000697 native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi);
698 synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800699 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800700 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
701 }
Jason Sams22534172009-08-04 16:58:20 -0700702
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700703
Tim Murray460a0492013-11-19 12:45:54 -0800704 native void rsnScriptBindAllocation(long con, long script, long alloc, int slot);
705 synchronized void nScriptBindAllocation(long script, long alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800706 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700707 rsnScriptBindAllocation(mContext, script, alloc, slot);
708 }
Tim Murray460a0492013-11-19 12:45:54 -0800709 native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone);
710 synchronized void nScriptSetTimeZone(long script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800711 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700712 rsnScriptSetTimeZone(mContext, script, timeZone);
713 }
Tim Murray460a0492013-11-19 12:45:54 -0800714 native void rsnScriptInvoke(long con, long id, int slot);
715 synchronized void nScriptInvoke(long id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800716 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700717 rsnScriptInvoke(mContext, id, slot);
718 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700719
720 native void rsnScriptForEach(long con, long id, int slot, long[] ains,
721 long aout, byte[] params, int[] limits);
722
723 synchronized void nScriptForEach(long id, int slot, long[] ains, long aout,
724 byte[] params, int[] limits) {
Jason Sams6e494d32011-04-27 16:33:11 -0700725 validate();
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700726 rsnScriptForEach(mContext, id, slot, ains, aout, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700727 }
728
Tim Murray460a0492013-11-19 12:45:54 -0800729 native void rsnScriptInvokeV(long con, long id, int slot, byte[] params);
730 synchronized void nScriptInvokeV(long id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800731 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700732 rsnScriptInvokeV(mContext, id, slot, params);
733 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700734
Tim Murray460a0492013-11-19 12:45:54 -0800735 native void rsnScriptSetVarI(long con, long id, int slot, int val);
736 synchronized void nScriptSetVarI(long id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800737 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700738 rsnScriptSetVarI(mContext, id, slot, val);
739 }
Tim Murray460a0492013-11-19 12:45:54 -0800740 native int rsnScriptGetVarI(long con, long id, int slot);
741 synchronized int nScriptGetVarI(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700742 validate();
743 return rsnScriptGetVarI(mContext, id, slot);
744 }
745
Tim Murray460a0492013-11-19 12:45:54 -0800746 native void rsnScriptSetVarJ(long con, long id, int slot, long val);
747 synchronized void nScriptSetVarJ(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800748 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700749 rsnScriptSetVarJ(mContext, id, slot, val);
750 }
Tim Murray460a0492013-11-19 12:45:54 -0800751 native long rsnScriptGetVarJ(long con, long id, int slot);
752 synchronized long nScriptGetVarJ(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700753 validate();
754 return rsnScriptGetVarJ(mContext, id, slot);
755 }
756
Tim Murray460a0492013-11-19 12:45:54 -0800757 native void rsnScriptSetVarF(long con, long id, int slot, float val);
758 synchronized void nScriptSetVarF(long id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800759 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700760 rsnScriptSetVarF(mContext, id, slot, val);
761 }
Tim Murray460a0492013-11-19 12:45:54 -0800762 native float rsnScriptGetVarF(long con, long id, int slot);
763 synchronized float nScriptGetVarF(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700764 validate();
765 return rsnScriptGetVarF(mContext, id, slot);
766 }
Tim Murray460a0492013-11-19 12:45:54 -0800767 native void rsnScriptSetVarD(long con, long id, int slot, double val);
768 synchronized void nScriptSetVarD(long id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800769 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700770 rsnScriptSetVarD(mContext, id, slot, val);
771 }
Tim Murray460a0492013-11-19 12:45:54 -0800772 native double rsnScriptGetVarD(long con, long id, int slot);
773 synchronized double nScriptGetVarD(long id, int slot) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700774 validate();
775 return rsnScriptGetVarD(mContext, id, slot);
776 }
Tim Murray460a0492013-11-19 12:45:54 -0800777 native void rsnScriptSetVarV(long con, long id, int slot, byte[] val);
778 synchronized void nScriptSetVarV(long id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800779 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700780 rsnScriptSetVarV(mContext, id, slot, val);
781 }
Tim Murray460a0492013-11-19 12:45:54 -0800782 native void rsnScriptGetVarV(long con, long id, int slot, byte[] val);
783 synchronized void nScriptGetVarV(long id, int slot, byte[] val) {
Tim Murray7c4caad2013-04-10 16:21:40 -0700784 validate();
785 rsnScriptGetVarV(mContext, id, slot, val);
786 }
Tim Murray460a0492013-11-19 12:45:54 -0800787 native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val,
788 long e, int[] dims);
789 synchronized void nScriptSetVarVE(long id, int slot, byte[] val,
790 long e, int[] dims) {
Stephen Hinesadeb8092012-04-20 14:26:06 -0700791 validate();
792 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
793 }
Tim Murray460a0492013-11-19 12:45:54 -0800794 native void rsnScriptSetVarObj(long con, long id, int slot, long val);
795 synchronized void nScriptSetVarObj(long id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800796 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800797 rsnScriptSetVarObj(mContext, id, slot, val);
798 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700799
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000800 native long rsnScriptCCreate(long con, String resName, String cacheDir,
Jason Samse4a06c52011-03-16 16:29:28 -0700801 byte[] script, int length);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000802 synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800803 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700804 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700805 }
Jason Samsebfb4362009-09-23 13:57:02 -0700806
Tim Murray460a0492013-11-19 12:45:54 -0800807 native long rsnScriptIntrinsicCreate(long con, int id, long eid);
808 synchronized long nScriptIntrinsicCreate(int id, long eid) {
Jason Sams6ab97682012-08-10 12:09:43 -0700809 validate();
810 return rsnScriptIntrinsicCreate(mContext, id, eid);
811 }
812
Tim Murray460a0492013-11-19 12:45:54 -0800813 native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig);
814 synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -0700815 validate();
816 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
817 }
818
Yang Nibe392ad2015-01-23 17:16:02 -0800819 native long rsnScriptInvokeIDCreate(long con, long sid, int slot);
820 synchronized long nScriptInvokeIDCreate(long sid, int slot) {
821 validate();
822 return rsnScriptInvokeIDCreate(mContext, sid, slot);
823 }
824
Tim Murray460a0492013-11-19 12:45:54 -0800825 native long rsnScriptFieldIDCreate(long con, long sid, int slot);
826 synchronized long nScriptFieldIDCreate(long sid, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700827 validate();
828 return rsnScriptFieldIDCreate(mContext, sid, slot);
829 }
830
Ashok Bhat98071552014-02-12 09:54:43 +0000831 native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types);
832 synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) {
Jason Sams08a81582012-09-18 12:32:10 -0700833 validate();
834 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
835 }
836
Tim Murray460a0492013-11-19 12:45:54 -0800837 native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc);
838 synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700839 validate();
840 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
841 }
842
Tim Murray460a0492013-11-19 12:45:54 -0800843 native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc);
844 synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) {
Jason Sams08a81582012-09-18 12:32:10 -0700845 validate();
846 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
847 }
848
Tim Murray460a0492013-11-19 12:45:54 -0800849 native void rsnScriptGroupExecute(long con, long group);
850 synchronized void nScriptGroupExecute(long group) {
Jason Sams08a81582012-09-18 12:32:10 -0700851 validate();
852 rsnScriptGroupExecute(mContext, group);
853 }
854
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000855 native long rsnSamplerCreate(long con, int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700856 int wrapS, int wrapT, int wrapR, float aniso);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000857 synchronized long nSamplerCreate(int magFilter, int minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700858 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800859 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700860 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700861 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800862
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000863 native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700864 boolean depthMask, boolean dither,
865 int srcMode, int dstMode, int depthFunc);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000866 synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
Jason Sams331bf9b2011-04-06 11:23:54 -0700867 boolean depthMask, boolean dither,
868 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800869 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700870 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
871 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700872 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700873
Tim Murray460a0492013-11-19 12:45:54 -0800874 native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode);
875 synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800876 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700877 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700878 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700879
Tim Murray460a0492013-11-19 12:45:54 -0800880 native void rsnProgramBindConstants(long con, long pv, int slot, long mID);
881 synchronized void nProgramBindConstants(long pv, int slot, long mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800882 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700883 rsnProgramBindConstants(mContext, pv, slot, mID);
884 }
Tim Murray460a0492013-11-19 12:45:54 -0800885 native void rsnProgramBindTexture(long con, long vpf, int slot, long a);
886 synchronized void nProgramBindTexture(long vpf, int slot, long a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800887 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700888 rsnProgramBindTexture(mContext, vpf, slot, a);
889 }
Tim Murray460a0492013-11-19 12:45:54 -0800890 native void rsnProgramBindSampler(long con, long vpf, int slot, long s);
891 synchronized void nProgramBindSampler(long vpf, int slot, long s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800892 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700893 rsnProgramBindSampler(mContext, vpf, slot, s);
894 }
Ashok Bhat98071552014-02-12 09:54:43 +0000895 native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params);
896 synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800897 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800898 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700899 }
Ashok Bhat98071552014-02-12 09:54:43 +0000900 native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params);
901 synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800902 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800903 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700904 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700905
Ashok Bhat98071552014-02-12 09:54:43 +0000906 native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim);
907 synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800908 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700909 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800910 }
Tim Murray460a0492013-11-19 12:45:54 -0800911 native int rsnMeshGetVertexBufferCount(long con, long id);
912 synchronized int nMeshGetVertexBufferCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800913 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700914 return rsnMeshGetVertexBufferCount(mContext, id);
915 }
Tim Murray460a0492013-11-19 12:45:54 -0800916 native int rsnMeshGetIndexCount(long con, long id);
917 synchronized int nMeshGetIndexCount(long id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800918 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700919 return rsnMeshGetIndexCount(mContext, id);
920 }
Ashok Bhat98071552014-02-12 09:54:43 +0000921 native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount);
922 synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800923 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700924 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
925 }
Ashok Bhat98071552014-02-12 09:54:43 +0000926 native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount);
927 synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800928 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700929 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
930 }
931
Tim Murray25207df2015-01-12 16:47:56 -0800932 native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA,
933 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
934 float alpha, long A, long B, float beta, long C, int incX, int incY,
935 int KL, int KU);
936 synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA,
937 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
938 float alpha, long A, long B, float beta, long C, int incX, int incY,
939 int KL, int KU) {
940 validate();
941 rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
942 }
943
944 native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA,
945 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
946 double alpha, long A, long B, double beta, long C, int incX, int incY,
947 int KL, int KU);
948 synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA,
949 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
950 double alpha, long A, long B, double beta, long C, int incX, int incY,
951 int KL, int KU) {
952 validate();
953 rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU);
954 }
955
956 native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA,
957 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
958 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
959 int KL, int KU);
960 synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA,
961 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
962 float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY,
963 int KL, int KU) {
964 validate();
965 rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
966 }
967
968 native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA,
969 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
970 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
971 int KL, int KU);
972 synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA,
973 int TransB, int Side, int Uplo, int Diag, int M, int N, int K,
974 double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY,
975 int KL, int KU) {
976 validate();
977 rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU);
978 }
979
Tim Murray9cb16a22015-04-01 11:07:16 -0700980 native void rsnScriptIntrinsicBLAS_BNNM(long con, long id, int M, int N, int K,
981 long A, int a_offset, long B, int b_offset, long C, int c_offset,
982 int c_mult_int);
983 synchronized void nScriptIntrinsicBLAS_BNNM(long id, int M, int N, int K,
984 long A, int a_offset, long B, int b_offset, long C, int c_offset,
985 int c_mult_int) {
986 validate();
987 rsnScriptIntrinsicBLAS_BNNM(mContext, id, M, N, K, A, a_offset, B, b_offset, C, c_offset, c_mult_int);
988 }
989
990
Tim Murray25207df2015-01-12 16:47:56 -0800991
Tim Murrayeff663f2013-11-15 13:08:30 -0800992 long mDev;
993 long mContext;
Jason Samsd22a6f02015-02-19 17:19:52 -0800994 private boolean mDestroyed = false;
995
Romain Guy650a3eb2009-08-31 14:06:43 -0700996 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800997 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700998
Jason Sams8cb39de2010-06-01 15:47:01 -0700999 Element mElement_U8;
1000 Element mElement_I8;
1001 Element mElement_U16;
1002 Element mElement_I16;
1003 Element mElement_U32;
1004 Element mElement_I32;
Stephen Hines52d83632010-10-11 16:10:42 -07001005 Element mElement_U64;
Stephen Hinesef1dac22010-10-01 15:39:33 -07001006 Element mElement_I64;
Jason Samsa5835a22014-11-05 15:16:26 -08001007 Element mElement_F16;
Jason Sams8cb39de2010-06-01 15:47:01 -07001008 Element mElement_F32;
Stephen Hines02f417052010-09-30 15:19:22 -07001009 Element mElement_F64;
Jason Samsf110d4b2010-06-21 17:42:41 -07001010 Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -07001011
Jason Sams8cb39de2010-06-01 15:47:01 -07001012 Element mElement_ELEMENT;
1013 Element mElement_TYPE;
1014 Element mElement_ALLOCATION;
1015 Element mElement_SAMPLER;
1016 Element mElement_SCRIPT;
1017 Element mElement_MESH;
1018 Element mElement_PROGRAM_FRAGMENT;
1019 Element mElement_PROGRAM_VERTEX;
1020 Element mElement_PROGRAM_RASTER;
1021 Element mElement_PROGRAM_STORE;
Stephen Hines3a291412012-04-11 17:27:29 -07001022 Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -07001023
Jason Sams3c0dfba2009-09-27 17:50:38 -07001024 Element mElement_A_8;
1025 Element mElement_RGB_565;
1026 Element mElement_RGB_888;
1027 Element mElement_RGBA_5551;
1028 Element mElement_RGBA_4444;
1029 Element mElement_RGBA_8888;
1030
Jason Samsa5835a22014-11-05 15:16:26 -08001031 Element mElement_HALF_2;
1032 Element mElement_HALF_3;
1033 Element mElement_HALF_4;
1034
Jason Sams8cb39de2010-06-01 15:47:01 -07001035 Element mElement_FLOAT_2;
1036 Element mElement_FLOAT_3;
1037 Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -07001038
1039 Element mElement_DOUBLE_2;
1040 Element mElement_DOUBLE_3;
1041 Element mElement_DOUBLE_4;
1042
1043 Element mElement_UCHAR_2;
1044 Element mElement_UCHAR_3;
Jason Sams8cb39de2010-06-01 15:47:01 -07001045 Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -08001046
Stephen Hines836c4a52011-06-01 14:38:10 -07001047 Element mElement_CHAR_2;
1048 Element mElement_CHAR_3;
1049 Element mElement_CHAR_4;
1050
1051 Element mElement_USHORT_2;
1052 Element mElement_USHORT_3;
1053 Element mElement_USHORT_4;
1054
1055 Element mElement_SHORT_2;
1056 Element mElement_SHORT_3;
1057 Element mElement_SHORT_4;
1058
1059 Element mElement_UINT_2;
1060 Element mElement_UINT_3;
1061 Element mElement_UINT_4;
1062
1063 Element mElement_INT_2;
1064 Element mElement_INT_3;
1065 Element mElement_INT_4;
1066
1067 Element mElement_ULONG_2;
1068 Element mElement_ULONG_3;
1069 Element mElement_ULONG_4;
1070
1071 Element mElement_LONG_2;
1072 Element mElement_LONG_3;
1073 Element mElement_LONG_4;
1074
Tim Murray932e78e2013-09-03 11:42:26 -07001075 Element mElement_YUV;
1076
Jason Sams1d45c472010-08-25 14:31:48 -07001077 Element mElement_MATRIX_4X4;
1078 Element mElement_MATRIX_3X3;
1079 Element mElement_MATRIX_2X2;
1080
Jason Sams4d339932010-05-11 14:03:58 -07001081 Sampler mSampler_CLAMP_NEAREST;
1082 Sampler mSampler_CLAMP_LINEAR;
1083 Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
1084 Sampler mSampler_WRAP_NEAREST;
1085 Sampler mSampler_WRAP_LINEAR;
1086 Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
Tim Murray6b9b2ca2013-02-15 13:25:55 -08001087 Sampler mSampler_MIRRORED_REPEAT_NEAREST;
1088 Sampler mSampler_MIRRORED_REPEAT_LINEAR;
1089 Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -07001090
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001091 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
1092 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001093 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
1094 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001095
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -07001096 ProgramRaster mProgramRaster_CULL_BACK;
1097 ProgramRaster mProgramRaster_CULL_FRONT;
1098 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -07001099
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001100 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -07001101 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001102
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001103 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001104 * The base class from which an application should derive in order
1105 * to receive RS messages from scripts. When a script calls {@code
1106 * rsSendToClient}, the data fields will be filled, and the run
1107 * method will be called on a separate thread. This will occur
1108 * some time after {@code rsSendToClient} completes in the script,
1109 * as {@code rsSendToClient} is asynchronous. Message handlers are
1110 * not guaranteed to have completed when {@link
1111 * android.renderscript.RenderScript#finish} returns.
Jason Sams27676fe2010-11-10 17:00:59 -08001112 *
1113 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001114 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -07001115 protected int[] mData;
1116 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -08001117 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -07001118 public void run() {
1119 }
1120 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001121 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001122 * If an application is expecting messages, it should set this
1123 * field to an instance of {@link RSMessageHandler}. This
1124 * instance will receive all the user messages sent from {@code
1125 * sendToClient} by scripts from this context.
Jason Sams27676fe2010-11-10 17:00:59 -08001126 *
1127 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001128 RSMessageHandler mMessageCallback = null;
1129
1130 public void setMessageHandler(RSMessageHandler msg) {
1131 mMessageCallback = msg;
1132 }
1133 public RSMessageHandler getMessageHandler() {
1134 return mMessageCallback;
1135 }
Jason Sams516c3192009-10-06 13:58:47 -07001136
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001137 /**
Jason Sams02d56d92013-04-12 16:40:50 -07001138 * Place a message into the message queue to be sent back to the message
1139 * handler once all previous commands have been executed.
Jason Sams455d6442013-02-05 19:20:18 -08001140 *
1141 * @param id
1142 * @param data
1143 */
1144 public void sendMessage(int id, int[] data) {
1145 nContextSendMessage(id, data);
1146 }
1147
1148 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001149 * The runtime error handler base class. An application should derive from this class
1150 * if it wishes to install an error handler. When errors occur at runtime,
1151 * the fields in this class will be filled, and the run method will be called.
Jason Sams27676fe2010-11-10 17:00:59 -08001152 *
1153 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001154 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -08001155 protected String mErrorMessage;
1156 protected int mErrorNum;
1157 public void run() {
1158 }
1159 }
Jason Sams27676fe2010-11-10 17:00:59 -08001160
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001161 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001162 * Application Error handler. All runtime errors will be dispatched to the
1163 * instance of RSAsyncError set here. If this field is null a
Tim Murrayc11e25c2013-04-09 11:01:01 -07001164 * {@link RSRuntimeException} will instead be thrown with details about the error.
Jason Sams27676fe2010-11-10 17:00:59 -08001165 * This will cause program termaination.
1166 *
1167 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001168 RSErrorHandler mErrorCallback = null;
1169
1170 public void setErrorHandler(RSErrorHandler msg) {
1171 mErrorCallback = msg;
1172 }
1173 public RSErrorHandler getErrorHandler() {
1174 return mErrorCallback;
1175 }
Jason Sams1c415172010-11-08 17:06:46 -08001176
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001177 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001178 * RenderScript worker thread priority enumeration. The default value is
1179 * NORMAL. Applications wishing to do background processing should set
1180 * their priority to LOW to avoid starving forground processes.
Jason Sams27676fe2010-11-10 17:00:59 -08001181 */
Jason Sams7d787b42009-11-15 12:14:26 -08001182 public enum Priority {
Jason Samsc9870c12015-01-21 12:55:14 -08001183 // These values used to represent official thread priority values
1184 // now they are simply enums to be used by the runtime side
1185 LOW (15),
1186 NORMAL (-8);
Jason Sams7d787b42009-11-15 12:14:26 -08001187
1188 int mID;
1189 Priority(int id) {
1190 mID = id;
1191 }
1192 }
1193
Jason Sams678cc7f2014-03-05 16:09:02 -08001194 void validateObject(BaseObj o) {
1195 if (o != null) {
1196 if (o.mRS != this) {
1197 throw new RSIllegalArgumentException("Attempting to use an object across contexts.");
1198 }
1199 }
1200 }
1201
Jason Sams771bebb2009-12-07 12:40:12 -08001202 void validate() {
1203 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -07001204 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -08001205 }
1206 }
1207
Jason Sams27676fe2010-11-10 17:00:59 -08001208
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001209 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001210 * Change the priority of the worker threads for this context.
1211 *
1212 * @param p New priority to be set.
1213 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001214 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -08001215 validate();
Jason Sams7d787b42009-11-15 12:14:26 -08001216 nContextSetPriority(p.mID);
1217 }
1218
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001219 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -07001220 RenderScript mRS;
1221 boolean mRun = true;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001222 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -08001223
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001224 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1225 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1226 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1227 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1228 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams739c8262013-04-11 18:07:52 -07001229 static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
Jason Sams516c3192009-10-06 13:58:47 -07001230
Stephen Hines42028a82013-04-17 19:22:01 -07001231 static final int RS_ERROR_FATAL_DEBUG = 0x0800;
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001232 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -08001233
Jason Sams516c3192009-10-06 13:58:47 -07001234 MessageThread(RenderScript rs) {
1235 super("RSMessageThread");
1236 mRS = rs;
1237
1238 }
1239
1240 public void run() {
1241 // This function is a temporary solution. The final solution will
1242 // used typed allocations where the message id is the type indicator.
1243 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -07001244 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001245 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -07001246 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -07001247 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001248 int size = mAuxData[1];
1249 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -08001250
1251 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
1252 if ((size>>2) >= rbuf.length) {
1253 rbuf = new int[(size + 3) >> 2];
1254 }
Jason Samsedbfabd2011-05-17 15:01:29 -07001255 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1256 RS_MESSAGE_TO_CLIENT_USER) {
Tim Murrayc11e25c2013-04-09 11:01:01 -07001257 throw new RSDriverException("Error processing message from RenderScript.");
Jason Samsedbfabd2011-05-17 15:01:29 -07001258 }
Jason Sams1c415172010-11-08 17:06:46 -08001259
1260 if(mRS.mMessageCallback != null) {
1261 mRS.mMessageCallback.mData = rbuf;
1262 mRS.mMessageCallback.mID = subID;
1263 mRS.mMessageCallback.mLength = size;
1264 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -07001265 } else {
Jason Sams1c415172010-11-08 17:06:46 -08001266 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -07001267 }
Stephen Hinesab98bb62010-09-24 14:38:30 -07001268 continue;
Jason Sams516c3192009-10-06 13:58:47 -07001269 }
Jason Sams1c415172010-11-08 17:06:46 -08001270
1271 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
1272 String e = mRS.nContextGetErrorMessage(mRS.mContext);
1273
Stephen Hines42028a82013-04-17 19:22:01 -07001274 // Throw RSRuntimeException under the following conditions:
1275 //
1276 // 1) It is an unknown fatal error.
1277 // 2) It is a debug fatal error, and we are not in a
1278 // debug context.
1279 // 3) It is a debug fatal error, and we do not have an
1280 // error callback.
1281 if (subID >= RS_ERROR_FATAL_UNKNOWN ||
1282 (subID >= RS_ERROR_FATAL_DEBUG &&
1283 (mRS.mContextType != ContextType.DEBUG ||
1284 mRS.mErrorCallback == null))) {
Jason Samsadd9d962010-11-22 16:20:16 -08001285 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1286 }
1287
Jason Sams1c415172010-11-08 17:06:46 -08001288 if(mRS.mErrorCallback != null) {
1289 mRS.mErrorCallback.mErrorMessage = e;
1290 mRS.mErrorCallback.mErrorNum = subID;
1291 mRS.mErrorCallback.run();
1292 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -08001293 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08001294 // Do not throw here. In these cases, we do not have
1295 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001296 }
1297 continue;
1298 }
1299
Jason Sams739c8262013-04-11 18:07:52 -07001300 if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
Tim Murrayb730d862014-08-18 16:14:24 -07001301 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1302 RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1303 throw new RSDriverException("Error processing message from RenderScript.");
1304 }
1305 long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL);
1306 Allocation.sendBufferNotification(bufferID);
Jason Sams739c8262013-04-11 18:07:52 -07001307 continue;
1308 }
1309
Jason Sams1c415172010-11-08 17:06:46 -08001310 // 2: teardown.
1311 // But we want to avoid starving other threads during
1312 // teardown by yielding until the next line in the destructor
1313 // can execute to set mRun = false
1314 try {
1315 sleep(1, 0);
1316 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001317 }
Jason Sams516c3192009-10-06 13:58:47 -07001318 }
Tim Murrayda67deb2013-05-09 12:02:50 -07001319 //Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001320 }
1321 }
1322
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001323 RenderScript(Context ctx) {
Stephen Hines42028a82013-04-17 19:22:01 -07001324 mContextType = ContextType.NORMAL;
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001325 if (ctx != null) {
1326 mApplicationContext = ctx.getApplicationContext();
1327 }
Tim Murray06b45672014-01-07 11:13:56 -08001328 mRWLock = new ReentrantReadWriteLock();
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001329 try {
Tim Murrayd11a6582014-12-16 09:59:09 -08001330 registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake
Tim Murrayaefbd5f2014-12-12 11:34:48 -08001331 } catch (Exception e) {
1332 Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
1333 throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
1334 }
1335
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001336 }
1337
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001338 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001339 * Gets the application context associated with the RenderScript context.
1340 *
1341 * @return The application context.
1342 */
1343 public final Context getApplicationContext() {
1344 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001345 }
1346
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001347 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001348 * Create a RenderScript context.
Jason Sams27676fe2010-11-10 17:00:59 -08001349 *
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001350 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001351 * @return RenderScript
1352 */
Jason Samse16da122015-03-18 17:04:18 -07001353 private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001354 if (!sInitialized) {
1355 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1356 return null;
1357 }
1358
Jason Samsb69c7912014-05-20 18:48:35 -07001359 if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER)) != 0) {
1360 throw new RSIllegalArgumentException("Invalid flags passed.");
1361 }
1362
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001363 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001364
1365 rs.mDev = rs.nDeviceCreate();
Tim Murrayfd710e72014-06-06 11:10:45 -07001366 rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID);
Stephen Hines42028a82013-04-17 19:22:01 -07001367 rs.mContextType = ct;
Jason Samse16da122015-03-18 17:04:18 -07001368 rs.mContextFlags = flags;
1369 rs.mContextSdkVersion = sdkVersion;
Jason Sams26985362011-05-03 15:01:58 -07001370 if (rs.mContext == 0) {
1371 throw new RSDriverException("Failed to create RS context.");
1372 }
Tim Murray47f31582015-04-07 15:43:24 -07001373
1374 // set up cache directory for entire context
1375 final String CACHE_PATH = "com.android.renderscript.cache";
1376 File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH);
1377 String mCachePath = f.getAbsolutePath();
1378 f.mkdirs();
1379 rs.nContextSetCacheDir(mCachePath);
1380
Jason Sams704ff642010-02-09 16:05:07 -08001381 rs.mMessageThread = new MessageThread(rs);
1382 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001383 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001384 }
1385
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001386 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001387 * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE)
Jason Samse16da122015-03-18 17:04:18 -07001388 *
1389 * See documentation for @create for details
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001390 *
1391 * @param ctx The context.
1392 * @return RenderScript
1393 */
1394 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001395 return create(ctx, ContextType.NORMAL);
1396 }
1397
1398 /**
Miao Wanga4e5adf2015-03-23 11:09:56 -07001399 * calls create(ctx, ct, CREATE_FLAG_NONE)
Jason Samsadd26dc2013-02-22 18:43:45 -08001400 *
Jason Samse16da122015-03-18 17:04:18 -07001401 * See documentation for @create for details
Jason Samsadd26dc2013-02-22 18:43:45 -08001402 *
1403 * @param ctx The context.
Jason Sams02d56d92013-04-12 16:40:50 -07001404 * @param ct The type of context to be created.
Jason Samsadd26dc2013-02-22 18:43:45 -08001405 * @return RenderScript
1406 */
1407 public static RenderScript create(Context ctx, ContextType ct) {
Jason Samse16da122015-03-18 17:04:18 -07001408 return create(ctx, ct, CREATE_FLAG_NONE);
Jason Sams26e90512014-05-07 14:23:27 -07001409 }
1410
Miao Wanga4e5adf2015-03-23 11:09:56 -07001411
1412 /**
Jason Samse16da122015-03-18 17:04:18 -07001413 * Gets or creates a RenderScript context of the specified type.
Jason Sams26e90512014-05-07 14:23:27 -07001414 *
Jason Samse16da122015-03-18 17:04:18 -07001415 * The returned context will be cached for future reuse within
1416 * the process. When an application is finished using
1417 * RenderScript it should call releaseAllContexts()
1418 *
1419 * A process context is a context designed for easy creation and
1420 * lifecycle management. Multiple calls to this function will
1421 * return the same object provided they are called with the same
1422 * options. This allows it to be used any time a RenderScript
1423 * context is needed.
1424 *
1425 * Prior to API 23 this always created a new context.
Jason Sams26e90512014-05-07 14:23:27 -07001426 *
1427 * @param ctx The context.
1428 * @param ct The type of context to be created.
1429 * @param flags The OR of the CREATE_FLAG_* options desired
1430 * @return RenderScript
1431 */
Tim Murrayfd710e72014-06-06 11:10:45 -07001432 public static RenderScript create(Context ctx, ContextType ct, int flags) {
Jason Sams26e90512014-05-07 14:23:27 -07001433 int v = ctx.getApplicationInfo().targetSdkVersion;
Miao Wanga4e5adf2015-03-23 11:09:56 -07001434 return create(ctx, v, ct, flags);
1435 }
1436
1437 /**
1438 * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE)
1439 *
1440 * Used by the RenderScriptThunker to maintain backward compatibility.
1441 *
1442 * @hide
1443 * @param ctx The context.
1444 * @param sdkVersion The target SDK Version.
1445 * @return RenderScript
1446 */
1447 public static RenderScript create(Context ctx, int sdkVersion) {
1448 return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE);
1449 }
1450
1451 /**
1452 * Gets or creates a RenderScript context of the specified type.
1453 *
Miao Wanga4e5adf2015-03-23 11:09:56 -07001454 * @param ctx The context.
1455 * @param ct The type of context to be created.
1456 * @param sdkVersion The target SDK Version.
1457 * @param flags The OR of the CREATE_FLAG_* options desired
1458 * @return RenderScript
1459 */
Jason Sams6a420b52015-03-30 15:31:26 -07001460 private static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) {
Miao Wanga4e5adf2015-03-23 11:09:56 -07001461 if (sdkVersion < 23) {
1462 return internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001463 }
1464
1465 synchronized (mProcessContextList) {
1466 for (RenderScript prs : mProcessContextList) {
1467 if ((prs.mContextType == ct) &&
1468 (prs.mContextFlags == flags) &&
Miao Wanga4e5adf2015-03-23 11:09:56 -07001469 (prs.mContextSdkVersion == sdkVersion)) {
Jason Samse16da122015-03-18 17:04:18 -07001470
1471 return prs;
1472 }
1473 }
1474
Miao Wanga4e5adf2015-03-23 11:09:56 -07001475 RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags);
Jason Samse16da122015-03-18 17:04:18 -07001476 prs.mIsProcessContext = true;
1477 mProcessContextList.add(prs);
1478 return prs;
1479 }
Jason Sams1a4e1f3e2012-02-24 17:51:24 -08001480 }
1481
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001482 /**
Jason Samse16da122015-03-18 17:04:18 -07001483 * Releases all the process contexts. This is the same as
1484 * calling .destroy() on each unique context retreived with
1485 * create(...). If no contexts have been created this
1486 * function does nothing.
1487 *
1488 * Typically you call this when your application is losing focus
1489 * and will not be using a context for some time.
1490 *
1491 * This has no effect on a context created with
1492 * createMultiContext()
1493 */
1494 public static void releaseAllContexts() {
1495 ArrayList<RenderScript> oldList;
1496 synchronized (mProcessContextList) {
1497 oldList = mProcessContextList;
1498 mProcessContextList = new ArrayList<RenderScript>();
1499 }
1500
1501 for (RenderScript prs : oldList) {
1502 prs.mIsProcessContext = false;
1503 prs.destroy();
1504 }
1505 oldList.clear();
1506 }
1507
1508
1509
1510 /**
1511 * Create a RenderScript context.
1512 *
1513 * This is an advanced function intended for applications which
1514 * need to create more than one RenderScript context to be used
1515 * at the same time.
1516 *
1517 * If you need a single context please use create()
1518 *
Jason Samse16da122015-03-18 17:04:18 -07001519 * @param ctx The context.
1520 * @return RenderScript
1521 */
1522 public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) {
1523 return internalCreate(ctx, API_number, ct, flags);
1524 }
1525
1526
1527 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001528 * Print the currently available debugging information about the state of
1529 * the RS context to the log.
1530 *
Jason Sams27676fe2010-11-10 17:00:59 -08001531 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001532 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001533 validate();
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001534 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001535 }
1536
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001537 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001538 * Wait for any pending asynchronous opeations (such as copies to a RS
1539 * allocation or RS script executions) to complete.
Jason Sams27676fe2010-11-10 17:00:59 -08001540 *
1541 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001542 public void finish() {
1543 nContextFinish();
1544 }
1545
Jason Samsd22a6f02015-02-19 17:19:52 -08001546 private void helpDestroy() {
1547 boolean shouldDestroy = false;
1548 synchronized(this) {
1549 if (!mDestroyed) {
1550 shouldDestroy = true;
1551 mDestroyed = true;
1552 }
1553 }
1554
1555 if (shouldDestroy) {
1556 nContextFinish();
1557
1558 nContextDeinitToClient(mContext);
1559 mMessageThread.mRun = false;
1560 try {
1561 mMessageThread.join();
1562 } catch(InterruptedException e) {
1563 }
1564
1565 nContextDestroy();
1566
1567 nDeviceDestroy(mDev);
1568 mDev = 0;
1569 }
1570 }
1571
1572 protected void finalize() throws Throwable {
1573 helpDestroy();
1574 super.finalize();
1575 }
1576
1577
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001578 /**
Tim Murrayc11e25c2013-04-09 11:01:01 -07001579 * Destroys this RenderScript context. Once this function is called,
1580 * using this context or any objects belonging to this context is
1581 * illegal.
Jason Sams27676fe2010-11-10 17:00:59 -08001582 *
Jason Samse16da122015-03-18 17:04:18 -07001583 * API 23+, this function is a NOP if the context was created
1584 * with create(). Please use releaseAllContexts() to clean up
1585 * contexts created with the create function.
1586 *
Jason Sams27676fe2010-11-10 17:00:59 -08001587 */
Jason Samsf5b45962009-08-25 14:49:07 -07001588 public void destroy() {
Jason Samse16da122015-03-18 17:04:18 -07001589 if (mIsProcessContext) {
1590 // users cannot destroy a process context
1591 return;
1592 }
Jason Sams5dbfe932010-01-27 14:41:43 -08001593 validate();
Jason Samsd22a6f02015-02-19 17:19:52 -08001594 helpDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001595 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001596
Jason Samsa9e7a052009-09-25 14:51:22 -07001597 boolean isAlive() {
1598 return mContext != 0;
1599 }
1600
Tim Murray460a0492013-11-19 12:45:54 -08001601 long safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001602 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001603 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001604 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001605 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001606 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001607}