| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1 | /* |
| Stephen Hines | be74bdd | 2012-02-03 15:29:36 -0800 | [diff] [blame] | 2 | * Copyright (C) 2008-2012 The Android Open Source Project |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 3 | * |
| 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 Sams | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 17 | package android.renderscript; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 18 | |
| Tim Murray | 47f3158 | 2015-04-07 15:43:24 -0700 | [diff] [blame] | 19 | import java.io.File; |
| Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 20 | import java.lang.reflect.Method; |
| Tim Murray | 06b4567 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 21 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 22 | |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 23 | import android.content.Context; |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 24 | import android.content.res.AssetManager; |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 26 | import android.graphics.SurfaceTexture; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | import android.view.Surface; |
| Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 29 | import android.os.SystemProperties; |
| Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 30 | import android.os.Trace; |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 31 | import java.util.ArrayList; |
| Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 32 | |
| Matt Wala | 36eb1f7 | 2015-07-20 15:35:27 -0700 | [diff] [blame] | 33 | // TODO: Clean up the whitespace that separates methods in this class. |
| 34 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 35 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 36 | * This class provides access to a RenderScript context, which controls RenderScript |
| 37 | * initialization, resource management, and teardown. An instance of the RenderScript |
| 38 | * class must be created before any other RS objects can be created. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 39 | * |
| Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 40 | * <div class="special reference"> |
| 41 | * <h3>Developer Guides</h3> |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 42 | * <p>For more information about creating an application that uses RenderScript, read the |
| 43 | * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p> |
| Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 44 | * </div> |
| Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 45 | **/ |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 46 | public class RenderScript { |
| Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 47 | static final long TRACE_TAG = Trace.TRACE_TAG_RS; |
| 48 | |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 49 | static final String LOG_TAG = "RenderScript_jni"; |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 50 | static final boolean DEBUG = false; |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 51 | @SuppressWarnings({"UnusedDeclaration", "deprecation"}) |
| Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 52 | static final boolean LOG_ENABLED = false; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 53 | |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 54 | static private ArrayList<RenderScript> mProcessContextList = new ArrayList<RenderScript>(); |
| 55 | private boolean mIsProcessContext = false; |
| 56 | private int mContextFlags = 0; |
| 57 | private int mContextSdkVersion = 0; |
| 58 | |
| 59 | |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 60 | private Context mApplicationContext; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 61 | |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 62 | /* |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 63 | * We use a class initializer to allow the native code to cache some |
| 64 | * field offsets. |
| 65 | */ |
| Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 66 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove? |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 67 | static boolean sInitialized; |
| 68 | native static void _nInit(); |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 69 | |
| Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 70 | static Object sRuntime; |
| 71 | static Method registerNativeAllocation; |
| 72 | static Method registerNativeFree; |
| Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 73 | |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 74 | /* |
| Tim Murray | fd710e7 | 2014-06-06 11:10:45 -0700 | [diff] [blame] | 75 | * Context creation flag that specifies a normal context. |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 76 | */ |
| Tim Murray | fd710e7 | 2014-06-06 11:10:45 -0700 | [diff] [blame] | 77 | public static final int CREATE_FLAG_NONE = 0x0000; |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Context creation flag which specifies a context optimized for low |
| 81 | * latency over peak performance. This is a hint and may have no effect |
| 82 | * on some implementations. |
| 83 | */ |
| Tim Murray | fd710e7 | 2014-06-06 11:10:45 -0700 | [diff] [blame] | 84 | public static final int CREATE_FLAG_LOW_LATENCY = 0x0002; |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * Context creation flag which specifies a context optimized for long |
| 88 | * battery life over peak performance. This is a hint and may have no effect |
| 89 | * on some implementations. |
| 90 | */ |
| Tim Murray | fd710e7 | 2014-06-06 11:10:45 -0700 | [diff] [blame] | 91 | public static final int CREATE_FLAG_LOW_POWER = 0x0004; |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 92 | |
| Stephen McGroarty | 62cb9bd | 2015-05-08 15:56:58 +0100 | [diff] [blame] | 93 | /** |
| 94 | * @hide |
| 95 | * Context creation flag which instructs the implementation to wait for |
| 96 | * a debugger to be attached before continuing execution. |
| 97 | */ |
| 98 | public static final int CREATE_FLAG_WAIT_FOR_ATTACH = 0x0008; |
| 99 | |
| verena beckham | c9659ea | 2015-05-22 16:47:53 +0100 | [diff] [blame] | 100 | /** |
| 101 | * @hide |
| 102 | * Context creation flag which specifies that optimization level 0 is |
| 103 | * passed to the device compiler upon execution of the RenderScript kernel. |
| 104 | * The default optimization level is 3. |
| 105 | */ |
| 106 | public static final int CREATE_FLAG_OPT_LEVEL_0 = 0x0010; |
| 107 | |
| Tim Murray | 56f9e6f | 2014-05-16 11:47:26 -0700 | [diff] [blame] | 108 | /* |
| 109 | * Detect the bitness of the VM to allow FieldPacker to do the right thing. |
| 110 | */ |
| 111 | static native int rsnSystemGetPointerSize(); |
| 112 | static int sPointerSize; |
| 113 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 114 | static { |
| 115 | sInitialized = false; |
| Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 116 | if (!SystemProperties.getBoolean("config.disable_renderscript", false)) { |
| 117 | try { |
| Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 118 | Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime"); |
| 119 | Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime"); |
| 120 | sRuntime = get_runtime.invoke(null); |
| 121 | registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE); |
| 122 | registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE); |
| 123 | } catch (Exception e) { |
| 124 | Log.e(LOG_TAG, "Error loading GC methods: " + e); |
| 125 | throw new RSRuntimeException("Error loading GC methods: " + e); |
| 126 | } |
| 127 | try { |
| Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 128 | System.loadLibrary("rs_jni"); |
| 129 | _nInit(); |
| 130 | sInitialized = true; |
| Tim Murray | 56f9e6f | 2014-05-16 11:47:26 -0700 | [diff] [blame] | 131 | sPointerSize = rsnSystemGetPointerSize(); |
| Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 132 | } catch (UnsatisfiedLinkError e) { |
| 133 | Log.e(LOG_TAG, "Error loading RS jni library: " + e); |
| 134 | throw new RSRuntimeException("Error loading RS jni library: " + e); |
| 135 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 139 | // Non-threadsafe functions. |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 140 | native long nDeviceCreate(); |
| 141 | native void nDeviceDestroy(long dev); |
| 142 | native void nDeviceSetConfig(long dev, int param, int value); |
| 143 | native int nContextGetUserMessage(long con, int[] data); |
| 144 | native String nContextGetErrorMessage(long con); |
| 145 | native int nContextPeekMessage(long con, int[] subID); |
| 146 | native void nContextInitToClient(long con); |
| 147 | native void nContextDeinitToClient(long con); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 148 | |
| Tim Murray | 67cc2d0 | 2014-02-06 16:39:38 -0800 | [diff] [blame] | 149 | // this should be a monotonically increasing ID |
| 150 | // used in conjunction with the API version of a device |
| Jason Sams | f764230 | 2015-05-12 14:06:56 -0700 | [diff] [blame] | 151 | static final long sMinorVersion = 1; |
| Tim Murray | 67cc2d0 | 2014-02-06 16:39:38 -0800 | [diff] [blame] | 152 | |
| 153 | /** |
| Miao Wang | f9d518a | 2015-05-14 14:53:30 -0700 | [diff] [blame] | 154 | * @hide |
| 155 | * |
| 156 | * Only exist to be compatible with old version RenderScript Support lib. |
| 157 | * Will eventually be removed. |
| 158 | * |
| 159 | * @return Always return 1 |
| 160 | * |
| 161 | */ |
| 162 | public static long getMinorID() { |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /** |
| Tim Murray | 67cc2d0 | 2014-02-06 16:39:38 -0800 | [diff] [blame] | 168 | * Returns an identifier that can be used to identify a particular |
| 169 | * minor version of RS. |
| 170 | * |
| Jason Sams | 6a420b5 | 2015-03-30 15:31:26 -0700 | [diff] [blame] | 171 | * @return The minor RenderScript version number |
| 172 | * |
| Tim Murray | 67cc2d0 | 2014-02-06 16:39:38 -0800 | [diff] [blame] | 173 | */ |
| Jason Sams | f764230 | 2015-05-12 14:06:56 -0700 | [diff] [blame] | 174 | public static long getMinorVersion() { |
| 175 | return sMinorVersion; |
| Tim Murray | 67cc2d0 | 2014-02-06 16:39:38 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 178 | /** |
| 179 | * ContextType specifies the specific type of context to be created. |
| 180 | * |
| 181 | */ |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 182 | public enum ContextType { |
| Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 183 | /** |
| 184 | * NORMAL context, this is the default and what shipping apps should |
| 185 | * use. |
| 186 | */ |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 187 | NORMAL (0), |
| Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * DEBUG context, perform extra runtime checks to validate the |
| 191 | * kernels and APIs are being used as intended. Get and SetElementAt |
| 192 | * will be bounds checked in this mode. |
| 193 | */ |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 194 | DEBUG (1), |
| Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * PROFILE context, Intended to be used once the first time an |
| 198 | * application is run on a new device. This mode allows the runtime to |
| 199 | * do additional testing and performance tuning. |
| 200 | */ |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 201 | PROFILE (2); |
| 202 | |
| 203 | int mID; |
| 204 | ContextType(int id) { |
| 205 | mID = id; |
| 206 | } |
| 207 | } |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 208 | |
| Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 209 | ContextType mContextType; |
| Tim Murray | 06b4567 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 210 | ReentrantReadWriteLock mRWLock; |
| Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 211 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 212 | // Methods below are wrapped to protect the non-threadsafe |
| 213 | // lockless fifo. |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 214 | native long rsnContextCreateGL(long dev, int ver, int sdkVer, |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 215 | int colorMin, int colorPref, |
| 216 | int alphaMin, int alphaPref, |
| 217 | int depthMin, int depthPref, |
| 218 | int stencilMin, int stencilPref, |
| Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 219 | int samplesMin, int samplesPref, float samplesQ, int dpi); |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 220 | synchronized long nContextCreateGL(long dev, int ver, int sdkVer, |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 221 | int colorMin, int colorPref, |
| 222 | int alphaMin, int alphaPref, |
| 223 | int depthMin, int depthPref, |
| 224 | int stencilMin, int stencilPref, |
| Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 225 | int samplesMin, int samplesPref, float samplesQ, int dpi) { |
| Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 226 | return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref, |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 227 | alphaMin, alphaPref, depthMin, depthPref, |
| 228 | stencilMin, stencilPref, |
| Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 229 | samplesMin, samplesPref, samplesQ, dpi); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 230 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 231 | native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType); |
| 232 | synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) { |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 233 | return rsnContextCreate(dev, ver, sdkVer, contextType); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 234 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 235 | native void rsnContextDestroy(long con); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 236 | synchronized void nContextDestroy() { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 237 | validate(); |
| Tim Murray | 06b4567 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 238 | |
| 239 | // take teardown lock |
| 240 | // teardown lock can only be taken when no objects are being destroyed |
| 241 | ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock(); |
| 242 | wlock.lock(); |
| 243 | |
| 244 | long curCon = mContext; |
| 245 | // context is considered dead as of this point |
| 246 | mContext = 0; |
| 247 | |
| 248 | wlock.unlock(); |
| 249 | rsnContextDestroy(curCon); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 250 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 251 | native void rsnContextSetSurface(long con, int w, int h, Surface sur); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 252 | synchronized void nContextSetSurface(int w, int h, Surface sur) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 253 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 254 | rsnContextSetSurface(mContext, w, h, sur); |
| 255 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 256 | native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur); |
| Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 257 | synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) { |
| 258 | validate(); |
| 259 | rsnContextSetSurfaceTexture(mContext, w, h, sur); |
| 260 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 261 | native void rsnContextSetPriority(long con, int p); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 262 | synchronized void nContextSetPriority(int p) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 263 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 264 | rsnContextSetPriority(mContext, p); |
| 265 | } |
| Tim Murray | 47f3158 | 2015-04-07 15:43:24 -0700 | [diff] [blame] | 266 | native void rsnContextSetCacheDir(long con, String cacheDir); |
| 267 | synchronized void nContextSetCacheDir(String cacheDir) { |
| 268 | validate(); |
| 269 | rsnContextSetCacheDir(mContext, cacheDir); |
| 270 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 271 | native void rsnContextDump(long con, int bits); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 272 | synchronized void nContextDump(int bits) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 273 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 274 | rsnContextDump(mContext, bits); |
| 275 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 276 | native void rsnContextFinish(long con); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 277 | synchronized void nContextFinish() { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 278 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 279 | rsnContextFinish(mContext); |
| 280 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 281 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 282 | native void rsnContextSendMessage(long con, int id, int[] data); |
| Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 283 | synchronized void nContextSendMessage(int id, int[] data) { |
| 284 | validate(); |
| 285 | rsnContextSendMessage(mContext, id, data); |
| 286 | } |
| 287 | |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 288 | native void rsnContextBindRootScript(long con, long script); |
| 289 | synchronized void nContextBindRootScript(long script) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 290 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 291 | rsnContextBindRootScript(mContext, script); |
| 292 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 293 | native void rsnContextBindSampler(long con, int sampler, int slot); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 294 | synchronized void nContextBindSampler(int sampler, int slot) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 295 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 296 | rsnContextBindSampler(mContext, sampler, slot); |
| 297 | } |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 298 | native void rsnContextBindProgramStore(long con, long pfs); |
| 299 | synchronized void nContextBindProgramStore(long pfs) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 300 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 301 | rsnContextBindProgramStore(mContext, pfs); |
| 302 | } |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 303 | native void rsnContextBindProgramFragment(long con, long pf); |
| 304 | synchronized void nContextBindProgramFragment(long pf) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 305 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 306 | rsnContextBindProgramFragment(mContext, pf); |
| 307 | } |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 308 | native void rsnContextBindProgramVertex(long con, long pv); |
| 309 | synchronized void nContextBindProgramVertex(long pv) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 310 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 311 | rsnContextBindProgramVertex(mContext, pv); |
| 312 | } |
| Narayan Kamath | 78c0ce5 | 2014-03-19 10:15:51 +0000 | [diff] [blame] | 313 | native void rsnContextBindProgramRaster(long con, long pr); |
| 314 | synchronized void nContextBindProgramRaster(long pr) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 315 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 316 | rsnContextBindProgramRaster(mContext, pr); |
| 317 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 318 | native void rsnContextPause(long con); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 319 | synchronized void nContextPause() { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 320 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 321 | rsnContextPause(mContext); |
| 322 | } |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 323 | native void rsnContextResume(long con); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 324 | synchronized void nContextResume() { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 325 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 326 | rsnContextResume(mContext); |
| 327 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 328 | |
| Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 329 | native long rsnClosureCreate(long con, long kernelID, long returnValue, |
| 330 | long[] fieldIDs, long[] values, int[] sizes, long[] depClosures, |
| 331 | long[] depFieldIDs); |
| 332 | synchronized long nClosureCreate(long kernelID, long returnValue, |
| 333 | long[] fieldIDs, long[] values, int[] sizes, long[] depClosures, |
| 334 | long[] depFieldIDs) { |
| 335 | validate(); |
| Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 336 | long c = rsnClosureCreate(mContext, kernelID, returnValue, fieldIDs, values, |
| Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 337 | sizes, depClosures, depFieldIDs); |
| Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 338 | if (c == 0) { |
| 339 | throw new RSRuntimeException("Failed creating closure."); |
| 340 | } |
| 341 | return c; |
| Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 344 | native long rsnInvokeClosureCreate(long con, long invokeID, byte[] params, |
| 345 | long[] fieldIDs, long[] values, int[] sizes); |
| 346 | synchronized long nInvokeClosureCreate(long invokeID, byte[] params, |
| 347 | long[] fieldIDs, long[] values, int[] sizes) { |
| 348 | validate(); |
| Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 349 | long c = rsnInvokeClosureCreate(mContext, invokeID, params, fieldIDs, |
| Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 350 | values, sizes); |
| Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 351 | if (c == 0) { |
| 352 | throw new RSRuntimeException("Failed creating closure."); |
| 353 | } |
| 354 | return c; |
| Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 357 | native void rsnClosureSetArg(long con, long closureID, int index, |
| 358 | long value, int size); |
| 359 | synchronized void nClosureSetArg(long closureID, int index, long value, |
| 360 | int size) { |
| 361 | validate(); |
| 362 | rsnClosureSetArg(mContext, closureID, index, value, size); |
| 363 | } |
| 364 | |
| 365 | native void rsnClosureSetGlobal(long con, long closureID, long fieldID, |
| 366 | long value, int size); |
| 367 | // Does this have to be synchronized? |
| 368 | synchronized void nClosureSetGlobal(long closureID, long fieldID, |
| 369 | long value, int size) { |
| 370 | validate(); // TODO: is this necessary? |
| 371 | rsnClosureSetGlobal(mContext, closureID, fieldID, value, size); |
| 372 | } |
| 373 | |
| Yang Ni | 35be56c | 2015-04-02 17:47:56 -0700 | [diff] [blame] | 374 | native long rsnScriptGroup2Create(long con, String name, String cachePath, |
| 375 | long[] closures); |
| 376 | synchronized long nScriptGroup2Create(String name, String cachePath, |
| 377 | long[] closures) { |
| Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 378 | validate(); |
| Yang Ni | 17c2d7a | 2015-04-30 16:13:54 -0700 | [diff] [blame] | 379 | long g = rsnScriptGroup2Create(mContext, name, cachePath, closures); |
| 380 | if (g == 0) { |
| 381 | throw new RSRuntimeException("Failed creating script group."); |
| 382 | } |
| 383 | return g; |
| Yang Ni | 281c325 | 2014-10-24 08:52:24 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | native void rsnScriptGroup2Execute(long con, long groupID); |
| 387 | synchronized void nScriptGroup2Execute(long groupID) { |
| 388 | validate(); |
| 389 | rsnScriptGroup2Execute(mContext, groupID); |
| 390 | } |
| 391 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 392 | native void rsnAssignName(long con, long obj, byte[] name); |
| 393 | synchronized void nAssignName(long obj, byte[] name) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 394 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 395 | rsnAssignName(mContext, obj, name); |
| 396 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 397 | native String rsnGetName(long con, long obj); |
| 398 | synchronized String nGetName(long obj) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 399 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 400 | return rsnGetName(mContext, obj); |
| 401 | } |
| Tim Murray | 06b4567 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 402 | |
| 403 | // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 404 | native void rsnObjDestroy(long con, long id); |
| Tim Murray | 06b4567 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 405 | void nObjDestroy(long id) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 406 | // There is a race condition here. The calling code may be run |
| 407 | // by the gc while teardown is occuring. This protects againts |
| 408 | // deleting dead objects. |
| 409 | if (mContext != 0) { |
| 410 | rsnObjDestroy(mContext, id); |
| 411 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 412 | } |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 413 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 414 | native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize); |
| 415 | synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 416 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 417 | return rsnElementCreate(mContext, type, kind, norm, vecSize); |
| 418 | } |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 419 | native long rsnElementCreate2(long con, long[] elements, String[] names, int[] arraySizes); |
| 420 | synchronized long nElementCreate2(long[] elements, String[] names, int[] arraySizes) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 421 | validate(); |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 422 | return rsnElementCreate2(mContext, elements, names, arraySizes); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 423 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 424 | native void rsnElementGetNativeData(long con, long id, int[] elementData); |
| 425 | synchronized void nElementGetNativeData(long id, int[] elementData) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 426 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 427 | rsnElementGetNativeData(mContext, id, elementData); |
| 428 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 429 | native void rsnElementGetSubElements(long con, long id, |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 430 | long[] IDs, String[] names, int[] arraySizes); |
| 431 | synchronized void nElementGetSubElements(long id, long[] IDs, String[] names, int[] arraySizes) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 432 | validate(); |
| Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 433 | rsnElementGetSubElements(mContext, id, IDs, names, arraySizes); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 434 | } |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 435 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 436 | native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv); |
| 437 | synchronized long nTypeCreate(long eid, int x, int y, int z, boolean mips, boolean faces, int yuv) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 438 | validate(); |
| Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 439 | return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 440 | } |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 441 | native void rsnTypeGetNativeData(long con, long id, long[] typeData); |
| 442 | synchronized void nTypeGetNativeData(long id, long[] typeData) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 443 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 444 | rsnTypeGetNativeData(mContext, id, typeData); |
| 445 | } |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 446 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 447 | native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, long pointer); |
| 448 | synchronized long nAllocationCreateTyped(long type, int mip, int usage, long pointer) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 449 | validate(); |
| Jason Sams | 857d0c7 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 450 | return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 451 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 452 | native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage); |
| 453 | synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 454 | validate(); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 455 | return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 456 | } |
| Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 457 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 458 | native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage); |
| 459 | synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) { |
| Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 460 | validate(); |
| 461 | return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage); |
| 462 | } |
| 463 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 464 | native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage); |
| 465 | synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 466 | validate(); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 467 | return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 468 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 469 | native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp); |
| 470 | synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 471 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 472 | return rsnAllocationCreateBitmapRef(mContext, type, bmp); |
| 473 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 474 | native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage); |
| 475 | synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 476 | validate(); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 477 | return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage); |
| 478 | } |
| 479 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 480 | native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp); |
| 481 | synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 482 | validate(); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 483 | rsnAllocationCopyToBitmap(mContext, alloc, bmp); |
| 484 | } |
| 485 | |
| 486 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 487 | native void rsnAllocationSyncAll(long con, long alloc, int src); |
| 488 | synchronized void nAllocationSyncAll(long alloc, int src) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 489 | validate(); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 490 | rsnAllocationSyncAll(mContext, alloc, src); |
| 491 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 492 | native Surface rsnAllocationGetSurface(long con, long alloc); |
| 493 | synchronized Surface nAllocationGetSurface(long alloc) { |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 494 | validate(); |
| Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 495 | return rsnAllocationGetSurface(mContext, alloc); |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 496 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 497 | native void rsnAllocationSetSurface(long con, long alloc, Surface sur); |
| 498 | synchronized void nAllocationSetSurface(long alloc, Surface sur) { |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 499 | validate(); |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 500 | rsnAllocationSetSurface(mContext, alloc, sur); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 501 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 502 | native void rsnAllocationIoSend(long con, long alloc); |
| 503 | synchronized void nAllocationIoSend(long alloc) { |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 504 | validate(); |
| 505 | rsnAllocationIoSend(mContext, alloc); |
| 506 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 507 | native void rsnAllocationIoReceive(long con, long alloc); |
| 508 | synchronized void nAllocationIoReceive(long alloc) { |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 509 | validate(); |
| 510 | rsnAllocationIoReceive(mContext, alloc); |
| 511 | } |
| 512 | |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 513 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 514 | native void rsnAllocationGenerateMipmaps(long con, long alloc); |
| 515 | synchronized void nAllocationGenerateMipmaps(long alloc) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 516 | validate(); |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 517 | rsnAllocationGenerateMipmaps(mContext, alloc); |
| 518 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 519 | native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp); |
| 520 | synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 521 | validate(); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 522 | rsnAllocationCopyFromBitmap(mContext, alloc, bmp); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 523 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 524 | |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 525 | |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 526 | native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt, |
| 527 | int mSize, boolean usePadding); |
| 528 | synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt, |
| 529 | int mSize, boolean usePadding) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 530 | validate(); |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 531 | rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 532 | } |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 533 | |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 534 | native void rsnAllocationElementData(long con,long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes); |
| 535 | synchronized void nAllocationElementData(long id, int xoff, int yoff, int zoff, int mip, int compIdx, byte[] d, int sizeBytes) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 536 | validate(); |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 537 | rsnAllocationElementData(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 538 | } |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 539 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 540 | native void rsnAllocationData2D(long con, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 541 | long dstAlloc, int dstXoff, int dstYoff, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 542 | int dstMip, int dstFace, |
| 543 | int width, int height, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 544 | long srcAlloc, int srcXoff, int srcYoff, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 545 | int srcMip, int srcFace); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 546 | synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 547 | int dstMip, int dstFace, |
| 548 | int width, int height, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 549 | long srcAlloc, int srcXoff, int srcYoff, |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 550 | int srcMip, int srcFace) { |
| 551 | validate(); |
| 552 | rsnAllocationData2D(mContext, |
| 553 | dstAlloc, dstXoff, dstYoff, |
| 554 | dstMip, dstFace, |
| 555 | width, height, |
| 556 | srcAlloc, srcXoff, srcYoff, |
| 557 | srcMip, srcFace); |
| 558 | } |
| 559 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 560 | native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 561 | int w, int h, Object d, int sizeBytes, int dt, |
| 562 | int mSize, boolean usePadding); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 563 | synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 564 | int w, int h, Object d, int sizeBytes, Element.DataType dt, |
| 565 | int mSize, boolean usePadding) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 566 | validate(); |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 567 | rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 568 | } |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 569 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 570 | native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b); |
| 571 | synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, Bitmap b) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 572 | validate(); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 573 | rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b); |
| 574 | } |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 575 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 576 | native void rsnAllocationData3D(long con, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 577 | long dstAlloc, int dstXoff, int dstYoff, int dstZoff, |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 578 | int dstMip, |
| 579 | int width, int height, int depth, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 580 | long srcAlloc, int srcXoff, int srcYoff, int srcZoff, |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 581 | int srcMip); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 582 | synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff, |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 583 | int dstMip, |
| 584 | int width, int height, int depth, |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 585 | long srcAlloc, int srcXoff, int srcYoff, int srcZoff, |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 586 | int srcMip) { |
| 587 | validate(); |
| 588 | rsnAllocationData3D(mContext, |
| 589 | dstAlloc, dstXoff, dstYoff, dstZoff, |
| 590 | dstMip, width, height, depth, |
| 591 | srcAlloc, srcXoff, srcYoff, srcZoff, srcMip); |
| 592 | } |
| 593 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 594 | native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 595 | int w, int h, int depth, Object d, int sizeBytes, int dt, |
| 596 | int mSize, boolean usePadding); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 597 | synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 598 | int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt, |
| 599 | int mSize, boolean usePadding) { |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 600 | validate(); |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 601 | rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, |
| 602 | dt.mID, mSize, usePadding); |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 603 | } |
| Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 604 | |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 605 | native void rsnAllocationRead(long con, long id, Object d, int dt, int mSize, boolean usePadding); |
| 606 | synchronized void nAllocationRead(long id, Object d, Element.DataType dt, int mSize, boolean usePadding) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 607 | validate(); |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 608 | rsnAllocationRead(mContext, id, d, dt.mID, mSize, usePadding); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 609 | } |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 610 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 611 | native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 612 | int sizeBytes, int dt, int mSize, boolean usePadding); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 613 | synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 614 | int sizeBytes, Element.DataType dt, int mSize, boolean usePadding) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 615 | validate(); |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 616 | rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID, mSize, usePadding); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 617 | } |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 618 | |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 619 | native void rsnAllocationElementRead(long con,long id, int xoff, int yoff, int zoff, |
| Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 620 | int mip, int compIdx, byte[] d, int sizeBytes); |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 621 | synchronized void nAllocationElementRead(long id, int xoff, int yoff, int zoff, |
| Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 622 | int mip, int compIdx, byte[] d, int sizeBytes) { |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 623 | validate(); |
| Miao Wang | 45cec0a | 2015-03-04 16:40:21 -0800 | [diff] [blame] | 624 | rsnAllocationElementRead(mContext, id, xoff, yoff, zoff, mip, compIdx, d, sizeBytes); |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 625 | } |
| 626 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 627 | native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 628 | int w, int h, Object d, int sizeBytes, int dt, |
| 629 | int mSize, boolean usePadding); |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 630 | synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 631 | int w, int h, Object d, int sizeBytes, Element.DataType dt, |
| 632 | int mSize, boolean usePadding) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 633 | validate(); |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 634 | rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID, mSize, usePadding); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 635 | } |
| Jason Sams | 21659ac | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 636 | |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 637 | native void rsnAllocationRead3D(long con, long id, int xoff, int yoff, int zoff, int mip, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 638 | int w, int h, int depth, Object d, int sizeBytes, int dt, |
| 639 | int mSize, boolean usePadding); |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 640 | synchronized void nAllocationRead3D(long id, int xoff, int yoff, int zoff, int mip, |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 641 | int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt, |
| 642 | int mSize, boolean usePadding) { |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 643 | validate(); |
| Miao Wang | 87e908d | 2015-03-02 15:15:15 -0800 | [diff] [blame] | 644 | rsnAllocationRead3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID, mSize, usePadding); |
| Miao Wang | c8e237e | 2015-02-20 18:36:32 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 647 | native long rsnAllocationGetType(long con, long id); |
| 648 | synchronized long nAllocationGetType(long id) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 649 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 650 | return rsnAllocationGetType(mContext, id); |
| 651 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 652 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 653 | native void rsnAllocationResize1D(long con, long id, int dimX); |
| 654 | synchronized void nAllocationResize1D(long id, int dimX) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 655 | validate(); |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 656 | rsnAllocationResize1D(mContext, id, dimX); |
| 657 | } |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 658 | |
| Jason Sams | 46ba27e3 | 2015-02-06 17:45:15 -0800 | [diff] [blame] | 659 | native long rsnAllocationAdapterCreate(long con, long allocId, long typeId); |
| 660 | synchronized long nAllocationAdapterCreate(long allocId, long typeId) { |
| 661 | validate(); |
| 662 | return rsnAllocationAdapterCreate(mContext, allocId, typeId); |
| 663 | } |
| 664 | |
| 665 | native void rsnAllocationAdapterOffset(long con, long id, int x, int y, int z, |
| 666 | int mip, int face, int a1, int a2, int a3, int a4); |
| 667 | synchronized void nAllocationAdapterOffset(long id, int x, int y, int z, |
| 668 | int mip, int face, int a1, int a2, int a3, int a4) { |
| 669 | validate(); |
| 670 | rsnAllocationAdapterOffset(mContext, id, x, y, z, mip, face, a1, a2, a3, a4); |
| 671 | } |
| 672 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 673 | native long rsnFileA3DCreateFromAssetStream(long con, long assetStream); |
| 674 | synchronized long nFileA3DCreateFromAssetStream(long assetStream) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 675 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 676 | return rsnFileA3DCreateFromAssetStream(mContext, assetStream); |
| 677 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 678 | native long rsnFileA3DCreateFromFile(long con, String path); |
| 679 | synchronized long nFileA3DCreateFromFile(String path) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 680 | validate(); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 681 | return rsnFileA3DCreateFromFile(mContext, path); |
| 682 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 683 | native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path); |
| 684 | synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 685 | validate(); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 686 | return rsnFileA3DCreateFromAsset(mContext, mgr, path); |
| 687 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 688 | native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D); |
| 689 | synchronized int nFileA3DGetNumIndexEntries(long fileA3D) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 690 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 691 | return rsnFileA3DGetNumIndexEntries(mContext, fileA3D); |
| 692 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 693 | native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names); |
| 694 | synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 695 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 696 | rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names); |
| 697 | } |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 698 | native long rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index); |
| 699 | synchronized long nFileA3DGetEntryByIndex(long fileA3D, int index) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 700 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 701 | return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index); |
| 702 | } |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 703 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 704 | native long rsnFontCreateFromFile(long con, String fileName, float size, int dpi); |
| 705 | synchronized long nFontCreateFromFile(String fileName, float size, int dpi) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 706 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 707 | return rsnFontCreateFromFile(mContext, fileName, size, dpi); |
| 708 | } |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 709 | native long rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, long assetStream); |
| 710 | synchronized long nFontCreateFromAssetStream(String name, float size, int dpi, long assetStream) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 711 | validate(); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 712 | return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream); |
| 713 | } |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 714 | native long rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi); |
| 715 | synchronized long nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 716 | validate(); |
| Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 717 | return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi); |
| 718 | } |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 719 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 720 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 721 | native void rsnScriptBindAllocation(long con, long script, long alloc, int slot); |
| 722 | synchronized void nScriptBindAllocation(long script, long alloc, int slot) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 723 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 724 | rsnScriptBindAllocation(mContext, script, alloc, slot); |
| 725 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 726 | native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone); |
| 727 | synchronized void nScriptSetTimeZone(long script, byte[] timeZone) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 728 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 729 | rsnScriptSetTimeZone(mContext, script, timeZone); |
| 730 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 731 | native void rsnScriptInvoke(long con, long id, int slot); |
| 732 | synchronized void nScriptInvoke(long id, int slot) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 733 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 734 | rsnScriptInvoke(mContext, id, slot); |
| 735 | } |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 736 | |
| 737 | native void rsnScriptForEach(long con, long id, int slot, long[] ains, |
| 738 | long aout, byte[] params, int[] limits); |
| 739 | |
| 740 | synchronized void nScriptForEach(long id, int slot, long[] ains, long aout, |
| 741 | byte[] params, int[] limits) { |
| Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 742 | validate(); |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 743 | rsnScriptForEach(mContext, id, slot, ains, aout, params, limits); |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| Matt Wala | 36eb1f7 | 2015-07-20 15:35:27 -0700 | [diff] [blame] | 746 | native void rsnScriptReduce(long con, long id, int slot, long ain, |
| 747 | long aout, int[] limits); |
| 748 | synchronized void nScriptReduce(long id, int slot, long ain, long aout, |
| 749 | int[] limits) { |
| 750 | validate(); |
| 751 | rsnScriptReduce(mContext, id, slot, ain, aout, limits); |
| 752 | } |
| 753 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 754 | native void rsnScriptInvokeV(long con, long id, int slot, byte[] params); |
| 755 | synchronized void nScriptInvokeV(long id, int slot, byte[] params) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 756 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 757 | rsnScriptInvokeV(mContext, id, slot, params); |
| 758 | } |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 759 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 760 | native void rsnScriptSetVarI(long con, long id, int slot, int val); |
| 761 | synchronized void nScriptSetVarI(long id, int slot, int val) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 762 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 763 | rsnScriptSetVarI(mContext, id, slot, val); |
| 764 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 765 | native int rsnScriptGetVarI(long con, long id, int slot); |
| 766 | synchronized int nScriptGetVarI(long id, int slot) { |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 767 | validate(); |
| 768 | return rsnScriptGetVarI(mContext, id, slot); |
| 769 | } |
| 770 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 771 | native void rsnScriptSetVarJ(long con, long id, int slot, long val); |
| 772 | synchronized void nScriptSetVarJ(long id, int slot, long val) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 773 | validate(); |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 774 | rsnScriptSetVarJ(mContext, id, slot, val); |
| 775 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 776 | native long rsnScriptGetVarJ(long con, long id, int slot); |
| 777 | synchronized long nScriptGetVarJ(long id, int slot) { |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 778 | validate(); |
| 779 | return rsnScriptGetVarJ(mContext, id, slot); |
| 780 | } |
| 781 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 782 | native void rsnScriptSetVarF(long con, long id, int slot, float val); |
| 783 | synchronized void nScriptSetVarF(long id, int slot, float val) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 784 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 785 | rsnScriptSetVarF(mContext, id, slot, val); |
| 786 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 787 | native float rsnScriptGetVarF(long con, long id, int slot); |
| 788 | synchronized float nScriptGetVarF(long id, int slot) { |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 789 | validate(); |
| 790 | return rsnScriptGetVarF(mContext, id, slot); |
| 791 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 792 | native void rsnScriptSetVarD(long con, long id, int slot, double val); |
| 793 | synchronized void nScriptSetVarD(long id, int slot, double val) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 794 | validate(); |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 795 | rsnScriptSetVarD(mContext, id, slot, val); |
| 796 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 797 | native double rsnScriptGetVarD(long con, long id, int slot); |
| 798 | synchronized double nScriptGetVarD(long id, int slot) { |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 799 | validate(); |
| 800 | return rsnScriptGetVarD(mContext, id, slot); |
| 801 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 802 | native void rsnScriptSetVarV(long con, long id, int slot, byte[] val); |
| 803 | synchronized void nScriptSetVarV(long id, int slot, byte[] val) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 804 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 805 | rsnScriptSetVarV(mContext, id, slot, val); |
| 806 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 807 | native void rsnScriptGetVarV(long con, long id, int slot, byte[] val); |
| 808 | synchronized void nScriptGetVarV(long id, int slot, byte[] val) { |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 809 | validate(); |
| 810 | rsnScriptGetVarV(mContext, id, slot, val); |
| 811 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 812 | native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val, |
| 813 | long e, int[] dims); |
| 814 | synchronized void nScriptSetVarVE(long id, int slot, byte[] val, |
| 815 | long e, int[] dims) { |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 816 | validate(); |
| 817 | rsnScriptSetVarVE(mContext, id, slot, val, e, dims); |
| 818 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 819 | native void rsnScriptSetVarObj(long con, long id, int slot, long val); |
| 820 | synchronized void nScriptSetVarObj(long id, int slot, long val) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 821 | validate(); |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 822 | rsnScriptSetVarObj(mContext, id, slot, val); |
| 823 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 824 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 825 | native long rsnScriptCCreate(long con, String resName, String cacheDir, |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 826 | byte[] script, int length); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 827 | synchronized long nScriptCCreate(String resName, String cacheDir, byte[] script, int length) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 828 | validate(); |
| Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 829 | return rsnScriptCCreate(mContext, resName, cacheDir, script, length); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 830 | } |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 831 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 832 | native long rsnScriptIntrinsicCreate(long con, int id, long eid); |
| 833 | synchronized long nScriptIntrinsicCreate(int id, long eid) { |
| Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 834 | validate(); |
| 835 | return rsnScriptIntrinsicCreate(mContext, id, eid); |
| 836 | } |
| 837 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 838 | native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig); |
| 839 | synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) { |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 840 | validate(); |
| 841 | return rsnScriptKernelIDCreate(mContext, sid, slot, sig); |
| 842 | } |
| 843 | |
| Yang Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 844 | native long rsnScriptInvokeIDCreate(long con, long sid, int slot); |
| 845 | synchronized long nScriptInvokeIDCreate(long sid, int slot) { |
| 846 | validate(); |
| 847 | return rsnScriptInvokeIDCreate(mContext, sid, slot); |
| 848 | } |
| 849 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 850 | native long rsnScriptFieldIDCreate(long con, long sid, int slot); |
| 851 | synchronized long nScriptFieldIDCreate(long sid, int slot) { |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 852 | validate(); |
| 853 | return rsnScriptFieldIDCreate(mContext, sid, slot); |
| 854 | } |
| 855 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 856 | native long rsnScriptGroupCreate(long con, long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types); |
| 857 | synchronized long nScriptGroupCreate(long[] kernels, long[] src, long[] dstk, long[] dstf, long[] types) { |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 858 | validate(); |
| 859 | return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types); |
| 860 | } |
| 861 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 862 | native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc); |
| 863 | synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) { |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 864 | validate(); |
| 865 | rsnScriptGroupSetInput(mContext, group, kernel, alloc); |
| 866 | } |
| 867 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 868 | native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc); |
| 869 | synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) { |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 870 | validate(); |
| 871 | rsnScriptGroupSetOutput(mContext, group, kernel, alloc); |
| 872 | } |
| 873 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 874 | native void rsnScriptGroupExecute(long con, long group); |
| 875 | synchronized void nScriptGroupExecute(long group) { |
| Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 876 | validate(); |
| 877 | rsnScriptGroupExecute(mContext, group); |
| 878 | } |
| 879 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 880 | native long rsnSamplerCreate(long con, int magFilter, int minFilter, |
| Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 881 | int wrapS, int wrapT, int wrapR, float aniso); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 882 | synchronized long nSamplerCreate(int magFilter, int minFilter, |
| Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 883 | int wrapS, int wrapT, int wrapR, float aniso) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 884 | validate(); |
| Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 885 | return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 886 | } |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 887 | |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 888 | native long rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a, |
| Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 889 | boolean depthMask, boolean dither, |
| 890 | int srcMode, int dstMode, int depthFunc); |
| Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 891 | synchronized long nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a, |
| Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 892 | boolean depthMask, boolean dither, |
| 893 | int srcMode, int dstMode, int depthFunc) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 894 | validate(); |
| Jason Sams | bd184c5 | 2011-04-06 11:44:47 -0700 | [diff] [blame] | 895 | return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode, |
| 896 | dstMode, depthFunc); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 897 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 898 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 899 | native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode); |
| 900 | synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 901 | validate(); |
| Jason Sams | 94aaed3 | 2011-09-23 14:18:53 -0700 | [diff] [blame] | 902 | return rsnProgramRasterCreate(mContext, pointSprite, cullMode); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 903 | } |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 904 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 905 | native void rsnProgramBindConstants(long con, long pv, int slot, long mID); |
| 906 | synchronized void nProgramBindConstants(long pv, int slot, long mID) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 907 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 908 | rsnProgramBindConstants(mContext, pv, slot, mID); |
| 909 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 910 | native void rsnProgramBindTexture(long con, long vpf, int slot, long a); |
| 911 | synchronized void nProgramBindTexture(long vpf, int slot, long a) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 912 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 913 | rsnProgramBindTexture(mContext, vpf, slot, a); |
| 914 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 915 | native void rsnProgramBindSampler(long con, long vpf, int slot, long s); |
| 916 | synchronized void nProgramBindSampler(long vpf, int slot, long s) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 917 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 918 | rsnProgramBindSampler(mContext, vpf, slot, s); |
| 919 | } |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 920 | native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, long[] params); |
| 921 | synchronized long nProgramFragmentCreate(String shader, String[] texNames, long[] params) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 922 | validate(); |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 923 | return rsnProgramFragmentCreate(mContext, shader, texNames, params); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 924 | } |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 925 | native long rsnProgramVertexCreate(long con, String shader, String[] texNames, long[] params); |
| 926 | synchronized long nProgramVertexCreate(String shader, String[] texNames, long[] params) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 927 | validate(); |
| Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 928 | return rsnProgramVertexCreate(mContext, shader, texNames, params); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 929 | } |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 930 | |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 931 | native long rsnMeshCreate(long con, long[] vtx, long[] idx, int[] prim); |
| 932 | synchronized long nMeshCreate(long[] vtx, long[] idx, int[] prim) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 933 | validate(); |
| Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 934 | return rsnMeshCreate(mContext, vtx, idx, prim); |
| Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 935 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 936 | native int rsnMeshGetVertexBufferCount(long con, long id); |
| 937 | synchronized int nMeshGetVertexBufferCount(long id) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 938 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 939 | return rsnMeshGetVertexBufferCount(mContext, id); |
| 940 | } |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 941 | native int rsnMeshGetIndexCount(long con, long id); |
| 942 | synchronized int nMeshGetIndexCount(long id) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 943 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 944 | return rsnMeshGetIndexCount(mContext, id); |
| 945 | } |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 946 | native void rsnMeshGetVertices(long con, long id, long[] vtxIds, int vtxIdCount); |
| 947 | synchronized void nMeshGetVertices(long id, long[] vtxIds, int vtxIdCount) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 948 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 949 | rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount); |
| 950 | } |
| Ashok Bhat | 9807155 | 2014-02-12 09:54:43 +0000 | [diff] [blame] | 951 | native void rsnMeshGetIndices(long con, long id, long[] idxIds, int[] primitives, int vtxIdCount); |
| 952 | synchronized void nMeshGetIndices(long id, long[] idxIds, int[] primitives, int vtxIdCount) { |
| Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 953 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 954 | rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount); |
| 955 | } |
| 956 | |
| Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 957 | native void rsnScriptIntrinsicBLAS_Single(long con, long id, int func, int TransA, |
| 958 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 959 | float alpha, long A, long B, float beta, long C, int incX, int incY, |
| 960 | int KL, int KU); |
| 961 | synchronized void nScriptIntrinsicBLAS_Single(long id, int func, int TransA, |
| 962 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 963 | float alpha, long A, long B, float beta, long C, int incX, int incY, |
| 964 | int KL, int KU) { |
| 965 | validate(); |
| 966 | rsnScriptIntrinsicBLAS_Single(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU); |
| 967 | } |
| 968 | |
| 969 | native void rsnScriptIntrinsicBLAS_Double(long con, long id, int func, int TransA, |
| 970 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 971 | double alpha, long A, long B, double beta, long C, int incX, int incY, |
| 972 | int KL, int KU); |
| 973 | synchronized void nScriptIntrinsicBLAS_Double(long id, int func, int TransA, |
| 974 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 975 | double alpha, long A, long B, double beta, long C, int incX, int incY, |
| 976 | int KL, int KU) { |
| 977 | validate(); |
| 978 | rsnScriptIntrinsicBLAS_Double(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alpha, A, B, beta, C, incX, incY, KL, KU); |
| 979 | } |
| 980 | |
| 981 | native void rsnScriptIntrinsicBLAS_Complex(long con, long id, int func, int TransA, |
| 982 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 983 | float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY, |
| 984 | int KL, int KU); |
| 985 | synchronized void nScriptIntrinsicBLAS_Complex(long id, int func, int TransA, |
| 986 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 987 | float alphaX, float alphaY, long A, long B, float betaX, float betaY, long C, int incX, int incY, |
| 988 | int KL, int KU) { |
| 989 | validate(); |
| 990 | rsnScriptIntrinsicBLAS_Complex(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU); |
| 991 | } |
| 992 | |
| 993 | native void rsnScriptIntrinsicBLAS_Z(long con, long id, int func, int TransA, |
| 994 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 995 | double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY, |
| 996 | int KL, int KU); |
| 997 | synchronized void nScriptIntrinsicBLAS_Z(long id, int func, int TransA, |
| 998 | int TransB, int Side, int Uplo, int Diag, int M, int N, int K, |
| 999 | double alphaX, double alphaY, long A, long B, double betaX, double betaY, long C, int incX, int incY, |
| 1000 | int KL, int KU) { |
| 1001 | validate(); |
| 1002 | rsnScriptIntrinsicBLAS_Z(mContext, id, func, TransA, TransB, Side, Uplo, Diag, M, N, K, alphaX, alphaY, A, B, betaX, betaY, C, incX, incY, KL, KU); |
| 1003 | } |
| 1004 | |
| Tim Murray | 9cb16a2 | 2015-04-01 11:07:16 -0700 | [diff] [blame] | 1005 | native void rsnScriptIntrinsicBLAS_BNNM(long con, long id, int M, int N, int K, |
| 1006 | long A, int a_offset, long B, int b_offset, long C, int c_offset, |
| 1007 | int c_mult_int); |
| 1008 | synchronized void nScriptIntrinsicBLAS_BNNM(long id, int M, int N, int K, |
| 1009 | long A, int a_offset, long B, int b_offset, long C, int c_offset, |
| 1010 | int c_mult_int) { |
| 1011 | validate(); |
| 1012 | rsnScriptIntrinsicBLAS_BNNM(mContext, id, M, N, K, A, a_offset, B, b_offset, C, c_offset, c_mult_int); |
| 1013 | } |
| 1014 | |
| 1015 | |
| Tim Murray | 25207df | 2015-01-12 16:47:56 -0800 | [diff] [blame] | 1016 | |
| Tim Murray | eff663f | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 1017 | long mDev; |
| 1018 | long mContext; |
| Jason Sams | d22a6f0 | 2015-02-19 17:19:52 -0800 | [diff] [blame] | 1019 | private boolean mDestroyed = false; |
| 1020 | |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 1021 | @SuppressWarnings({"FieldCanBeLocal"}) |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1022 | MessageThread mMessageThread; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1023 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 1024 | Element mElement_U8; |
| 1025 | Element mElement_I8; |
| 1026 | Element mElement_U16; |
| 1027 | Element mElement_I16; |
| 1028 | Element mElement_U32; |
| 1029 | Element mElement_I32; |
| Stephen Hines | 52d8363 | 2010-10-11 16:10:42 -0700 | [diff] [blame] | 1030 | Element mElement_U64; |
| Stephen Hines | ef1dac2 | 2010-10-01 15:39:33 -0700 | [diff] [blame] | 1031 | Element mElement_I64; |
| Jason Sams | a5835a2 | 2014-11-05 15:16:26 -0800 | [diff] [blame] | 1032 | Element mElement_F16; |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 1033 | Element mElement_F32; |
| Stephen Hines | 02f41705 | 2010-09-30 15:19:22 -0700 | [diff] [blame] | 1034 | Element mElement_F64; |
| Jason Sams | f110d4b | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 1035 | Element mElement_BOOLEAN; |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 1036 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 1037 | Element mElement_ELEMENT; |
| 1038 | Element mElement_TYPE; |
| 1039 | Element mElement_ALLOCATION; |
| 1040 | Element mElement_SAMPLER; |
| 1041 | Element mElement_SCRIPT; |
| 1042 | Element mElement_MESH; |
| 1043 | Element mElement_PROGRAM_FRAGMENT; |
| 1044 | Element mElement_PROGRAM_VERTEX; |
| 1045 | Element mElement_PROGRAM_RASTER; |
| 1046 | Element mElement_PROGRAM_STORE; |
| Stephen Hines | 3a29141 | 2012-04-11 17:27:29 -0700 | [diff] [blame] | 1047 | Element mElement_FONT; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 1048 | |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 1049 | Element mElement_A_8; |
| 1050 | Element mElement_RGB_565; |
| 1051 | Element mElement_RGB_888; |
| 1052 | Element mElement_RGBA_5551; |
| 1053 | Element mElement_RGBA_4444; |
| 1054 | Element mElement_RGBA_8888; |
| 1055 | |
| Jason Sams | a5835a2 | 2014-11-05 15:16:26 -0800 | [diff] [blame] | 1056 | Element mElement_HALF_2; |
| 1057 | Element mElement_HALF_3; |
| 1058 | Element mElement_HALF_4; |
| 1059 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 1060 | Element mElement_FLOAT_2; |
| 1061 | Element mElement_FLOAT_3; |
| 1062 | Element mElement_FLOAT_4; |
| Stephen Hines | 836c4a5 | 2011-06-01 14:38:10 -0700 | [diff] [blame] | 1063 | |
| 1064 | Element mElement_DOUBLE_2; |
| 1065 | Element mElement_DOUBLE_3; |
| 1066 | Element mElement_DOUBLE_4; |
| 1067 | |
| 1068 | Element mElement_UCHAR_2; |
| 1069 | Element mElement_UCHAR_3; |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 1070 | Element mElement_UCHAR_4; |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 1071 | |
| Stephen Hines | 836c4a5 | 2011-06-01 14:38:10 -0700 | [diff] [blame] | 1072 | Element mElement_CHAR_2; |
| 1073 | Element mElement_CHAR_3; |
| 1074 | Element mElement_CHAR_4; |
| 1075 | |
| 1076 | Element mElement_USHORT_2; |
| 1077 | Element mElement_USHORT_3; |
| 1078 | Element mElement_USHORT_4; |
| 1079 | |
| 1080 | Element mElement_SHORT_2; |
| 1081 | Element mElement_SHORT_3; |
| 1082 | Element mElement_SHORT_4; |
| 1083 | |
| 1084 | Element mElement_UINT_2; |
| 1085 | Element mElement_UINT_3; |
| 1086 | Element mElement_UINT_4; |
| 1087 | |
| 1088 | Element mElement_INT_2; |
| 1089 | Element mElement_INT_3; |
| 1090 | Element mElement_INT_4; |
| 1091 | |
| 1092 | Element mElement_ULONG_2; |
| 1093 | Element mElement_ULONG_3; |
| 1094 | Element mElement_ULONG_4; |
| 1095 | |
| 1096 | Element mElement_LONG_2; |
| 1097 | Element mElement_LONG_3; |
| 1098 | Element mElement_LONG_4; |
| 1099 | |
| Tim Murray | 932e78e | 2013-09-03 11:42:26 -0700 | [diff] [blame] | 1100 | Element mElement_YUV; |
| 1101 | |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 1102 | Element mElement_MATRIX_4X4; |
| 1103 | Element mElement_MATRIX_3X3; |
| 1104 | Element mElement_MATRIX_2X2; |
| 1105 | |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1106 | Sampler mSampler_CLAMP_NEAREST; |
| 1107 | Sampler mSampler_CLAMP_LINEAR; |
| 1108 | Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR; |
| 1109 | Sampler mSampler_WRAP_NEAREST; |
| 1110 | Sampler mSampler_WRAP_LINEAR; |
| 1111 | Sampler mSampler_WRAP_LINEAR_MIP_LINEAR; |
| Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 1112 | Sampler mSampler_MIRRORED_REPEAT_NEAREST; |
| 1113 | Sampler mSampler_MIRRORED_REPEAT_LINEAR; |
| 1114 | Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR; |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 1115 | |
| Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 1116 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST; |
| 1117 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH; |
| Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 1118 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST; |
| 1119 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH; |
| Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 1120 | |
| Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 1121 | ProgramRaster mProgramRaster_CULL_BACK; |
| 1122 | ProgramRaster mProgramRaster_CULL_FRONT; |
| 1123 | ProgramRaster mProgramRaster_CULL_NONE; |
| Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 1124 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1125 | /////////////////////////////////////////////////////////////////////////////////// |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 1126 | // |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1127 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1128 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1129 | * The base class from which an application should derive in order |
| 1130 | * to receive RS messages from scripts. When a script calls {@code |
| 1131 | * rsSendToClient}, the data fields will be filled, and the run |
| 1132 | * method will be called on a separate thread. This will occur |
| 1133 | * some time after {@code rsSendToClient} completes in the script, |
| 1134 | * as {@code rsSendToClient} is asynchronous. Message handlers are |
| 1135 | * not guaranteed to have completed when {@link |
| 1136 | * android.renderscript.RenderScript#finish} returns. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1137 | * |
| 1138 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1139 | public static class RSMessageHandler implements Runnable { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1140 | protected int[] mData; |
| 1141 | protected int mID; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1142 | protected int mLength; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1143 | public void run() { |
| 1144 | } |
| 1145 | } |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1146 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1147 | * If an application is expecting messages, it should set this |
| 1148 | * field to an instance of {@link RSMessageHandler}. This |
| 1149 | * instance will receive all the user messages sent from {@code |
| 1150 | * sendToClient} by scripts from this context. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1151 | * |
| 1152 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1153 | RSMessageHandler mMessageCallback = null; |
| 1154 | |
| 1155 | public void setMessageHandler(RSMessageHandler msg) { |
| 1156 | mMessageCallback = msg; |
| 1157 | } |
| 1158 | public RSMessageHandler getMessageHandler() { |
| 1159 | return mMessageCallback; |
| 1160 | } |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1161 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1162 | /** |
| Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 1163 | * Place a message into the message queue to be sent back to the message |
| 1164 | * handler once all previous commands have been executed. |
| Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1165 | * |
| 1166 | * @param id |
| 1167 | * @param data |
| 1168 | */ |
| 1169 | public void sendMessage(int id, int[] data) { |
| 1170 | nContextSendMessage(id, data); |
| 1171 | } |
| 1172 | |
| 1173 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1174 | * The runtime error handler base class. An application should derive from this class |
| 1175 | * if it wishes to install an error handler. When errors occur at runtime, |
| 1176 | * the fields in this class will be filled, and the run method will be called. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1177 | * |
| 1178 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1179 | public static class RSErrorHandler implements Runnable { |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1180 | protected String mErrorMessage; |
| 1181 | protected int mErrorNum; |
| 1182 | public void run() { |
| 1183 | } |
| 1184 | } |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1185 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1186 | /** |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1187 | * Application Error handler. All runtime errors will be dispatched to the |
| 1188 | * instance of RSAsyncError set here. If this field is null a |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1189 | * {@link RSRuntimeException} will instead be thrown with details about the error. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1190 | * This will cause program termaination. |
| 1191 | * |
| 1192 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1193 | RSErrorHandler mErrorCallback = null; |
| 1194 | |
| 1195 | public void setErrorHandler(RSErrorHandler msg) { |
| 1196 | mErrorCallback = msg; |
| 1197 | } |
| 1198 | public RSErrorHandler getErrorHandler() { |
| 1199 | return mErrorCallback; |
| 1200 | } |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1201 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1202 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1203 | * RenderScript worker thread priority enumeration. The default value is |
| 1204 | * NORMAL. Applications wishing to do background processing should set |
| 1205 | * their priority to LOW to avoid starving forground processes. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1206 | */ |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 1207 | public enum Priority { |
| Jason Sams | c9870c1 | 2015-01-21 12:55:14 -0800 | [diff] [blame] | 1208 | // These values used to represent official thread priority values |
| 1209 | // now they are simply enums to be used by the runtime side |
| 1210 | LOW (15), |
| 1211 | NORMAL (-8); |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 1212 | |
| 1213 | int mID; |
| 1214 | Priority(int id) { |
| 1215 | mID = id; |
| 1216 | } |
| 1217 | } |
| 1218 | |
| Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 1219 | void validateObject(BaseObj o) { |
| 1220 | if (o != null) { |
| 1221 | if (o.mRS != this) { |
| 1222 | throw new RSIllegalArgumentException("Attempting to use an object across contexts."); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1227 | void validate() { |
| 1228 | if (mContext == 0) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 1229 | throw new RSInvalidStateException("Calling RS with no Context active."); |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1233 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1234 | /** |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1235 | * Change the priority of the worker threads for this context. |
| 1236 | * |
| 1237 | * @param p New priority to be set. |
| 1238 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1239 | public void setPriority(Priority p) { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 1240 | validate(); |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 1241 | nContextSetPriority(p.mID); |
| 1242 | } |
| 1243 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1244 | static class MessageThread extends Thread { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1245 | RenderScript mRS; |
| 1246 | boolean mRun = true; |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1247 | int[] mAuxData = new int[2]; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1248 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1249 | static final int RS_MESSAGE_TO_CLIENT_NONE = 0; |
| 1250 | static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1; |
| 1251 | static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; |
| 1252 | static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; |
| 1253 | static final int RS_MESSAGE_TO_CLIENT_USER = 4; |
| Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1254 | static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1255 | |
| Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1256 | static final int RS_ERROR_FATAL_DEBUG = 0x0800; |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1257 | static final int RS_ERROR_FATAL_UNKNOWN = 0x1000; |
| Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 1258 | |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1259 | MessageThread(RenderScript rs) { |
| 1260 | super("RSMessageThread"); |
| 1261 | mRS = rs; |
| 1262 | |
| 1263 | } |
| 1264 | |
| 1265 | public void run() { |
| 1266 | // This function is a temporary solution. The final solution will |
| 1267 | // used typed allocations where the message id is the type indicator. |
| 1268 | int[] rbuf = new int[16]; |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1269 | mRS.nContextInitToClient(mRS.mContext); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1270 | while(mRun) { |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 1271 | rbuf[0] = 0; |
| Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 1272 | int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1273 | int size = mAuxData[1]; |
| 1274 | int subID = mAuxData[0]; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1275 | |
| 1276 | if (msg == RS_MESSAGE_TO_CLIENT_USER) { |
| 1277 | if ((size>>2) >= rbuf.length) { |
| 1278 | rbuf = new int[(size + 3) >> 2]; |
| 1279 | } |
| Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 1280 | if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) != |
| 1281 | RS_MESSAGE_TO_CLIENT_USER) { |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1282 | throw new RSDriverException("Error processing message from RenderScript."); |
| Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 1283 | } |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1284 | |
| 1285 | if(mRS.mMessageCallback != null) { |
| 1286 | mRS.mMessageCallback.mData = rbuf; |
| 1287 | mRS.mMessageCallback.mID = subID; |
| 1288 | mRS.mMessageCallback.mLength = size; |
| 1289 | mRS.mMessageCallback.run(); |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 1290 | } else { |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1291 | throw new RSInvalidStateException("Received a message from the script with no message handler installed."); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1292 | } |
| Stephen Hines | ab98bb6 | 2010-09-24 14:38:30 -0700 | [diff] [blame] | 1293 | continue; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1294 | } |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1295 | |
| 1296 | if (msg == RS_MESSAGE_TO_CLIENT_ERROR) { |
| 1297 | String e = mRS.nContextGetErrorMessage(mRS.mContext); |
| 1298 | |
| Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1299 | // Throw RSRuntimeException under the following conditions: |
| 1300 | // |
| 1301 | // 1) It is an unknown fatal error. |
| 1302 | // 2) It is a debug fatal error, and we are not in a |
| 1303 | // debug context. |
| 1304 | // 3) It is a debug fatal error, and we do not have an |
| 1305 | // error callback. |
| 1306 | if (subID >= RS_ERROR_FATAL_UNKNOWN || |
| 1307 | (subID >= RS_ERROR_FATAL_DEBUG && |
| 1308 | (mRS.mContextType != ContextType.DEBUG || |
| 1309 | mRS.mErrorCallback == null))) { |
| Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 1310 | throw new RSRuntimeException("Fatal error " + subID + ", details: " + e); |
| 1311 | } |
| 1312 | |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1313 | if(mRS.mErrorCallback != null) { |
| 1314 | mRS.mErrorCallback.mErrorMessage = e; |
| 1315 | mRS.mErrorCallback.mErrorNum = subID; |
| 1316 | mRS.mErrorCallback.run(); |
| 1317 | } else { |
| Jason Sams | a4b7bc9 | 2013-02-05 15:05:39 -0800 | [diff] [blame] | 1318 | android.util.Log.e(LOG_TAG, "non fatal RS error, " + e); |
| Stephen Hines | be74bdd | 2012-02-03 15:29:36 -0800 | [diff] [blame] | 1319 | // Do not throw here. In these cases, we do not have |
| 1320 | // a fatal error. |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1321 | } |
| 1322 | continue; |
| 1323 | } |
| 1324 | |
| Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1325 | if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) { |
| Tim Murray | b730d86 | 2014-08-18 16:14:24 -0700 | [diff] [blame] | 1326 | if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) != |
| 1327 | RS_MESSAGE_TO_CLIENT_NEW_BUFFER) { |
| 1328 | throw new RSDriverException("Error processing message from RenderScript."); |
| 1329 | } |
| 1330 | long bufferID = ((long)rbuf[1] << 32L) + ((long)rbuf[0] & 0xffffffffL); |
| 1331 | Allocation.sendBufferNotification(bufferID); |
| Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1332 | continue; |
| 1333 | } |
| 1334 | |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1335 | // 2: teardown. |
| 1336 | // But we want to avoid starving other threads during |
| 1337 | // teardown by yielding until the next line in the destructor |
| 1338 | // can execute to set mRun = false |
| 1339 | try { |
| 1340 | sleep(1, 0); |
| 1341 | } catch(InterruptedException e) { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1342 | } |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1343 | } |
| Tim Murray | da67deb | 2013-05-09 12:02:50 -0700 | [diff] [blame] | 1344 | //Log.d(LOG_TAG, "MessageThread exiting."); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1348 | RenderScript(Context ctx) { |
| Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1349 | mContextType = ContextType.NORMAL; |
| Jason Sams | 1a4e1f3e | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1350 | if (ctx != null) { |
| 1351 | mApplicationContext = ctx.getApplicationContext(); |
| 1352 | } |
| Tim Murray | 06b4567 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 1353 | mRWLock = new ReentrantReadWriteLock(); |
| Tim Murray | aefbd5f | 2014-12-12 11:34:48 -0800 | [diff] [blame] | 1354 | try { |
| Tim Murray | d11a658 | 2014-12-16 09:59:09 -0800 | [diff] [blame] | 1355 | registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake |
| Tim Murray | aefbd5f | 2014-12-12 11:34:48 -0800 | [diff] [blame] | 1356 | } catch (Exception e) { |
| 1357 | Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e); |
| 1358 | throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e); |
| 1359 | } |
| 1360 | |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1361 | } |
| 1362 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1363 | /** |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1364 | * Gets the application context associated with the RenderScript context. |
| 1365 | * |
| 1366 | * @return The application context. |
| 1367 | */ |
| 1368 | public final Context getApplicationContext() { |
| 1369 | return mApplicationContext; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1372 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1373 | * Create a RenderScript context. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1374 | * |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1375 | * @param ctx The context. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1376 | * @return RenderScript |
| 1377 | */ |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1378 | private static RenderScript internalCreate(Context ctx, int sdkVersion, ContextType ct, int flags) { |
| Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 1379 | if (!sInitialized) { |
| 1380 | Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash"); |
| 1381 | return null; |
| 1382 | } |
| 1383 | |
| verena beckham | c9659ea | 2015-05-22 16:47:53 +0100 | [diff] [blame] | 1384 | if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER | |
| 1385 | CREATE_FLAG_WAIT_FOR_ATTACH | CREATE_FLAG_OPT_LEVEL_0)) != 0) { |
| Jason Sams | b69c791 | 2014-05-20 18:48:35 -0700 | [diff] [blame] | 1386 | throw new RSIllegalArgumentException("Invalid flags passed."); |
| 1387 | } |
| 1388 | |
| Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1389 | RenderScript rs = new RenderScript(ctx); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1390 | |
| 1391 | rs.mDev = rs.nDeviceCreate(); |
| Tim Murray | fd710e7 | 2014-06-06 11:10:45 -0700 | [diff] [blame] | 1392 | rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID); |
| Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1393 | rs.mContextType = ct; |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1394 | rs.mContextFlags = flags; |
| 1395 | rs.mContextSdkVersion = sdkVersion; |
| Jason Sams | 2698536 | 2011-05-03 15:01:58 -0700 | [diff] [blame] | 1396 | if (rs.mContext == 0) { |
| 1397 | throw new RSDriverException("Failed to create RS context."); |
| 1398 | } |
| Tim Murray | 47f3158 | 2015-04-07 15:43:24 -0700 | [diff] [blame] | 1399 | |
| 1400 | // set up cache directory for entire context |
| 1401 | final String CACHE_PATH = "com.android.renderscript.cache"; |
| 1402 | File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH); |
| 1403 | String mCachePath = f.getAbsolutePath(); |
| 1404 | f.mkdirs(); |
| 1405 | rs.nContextSetCacheDir(mCachePath); |
| 1406 | |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1407 | rs.mMessageThread = new MessageThread(rs); |
| 1408 | rs.mMessageThread.start(); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1409 | return rs; |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 1410 | } |
| 1411 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1412 | /** |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1413 | * calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE) |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1414 | * |
| 1415 | * See documentation for @create for details |
| Jason Sams | 1a4e1f3e | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1416 | * |
| 1417 | * @param ctx The context. |
| 1418 | * @return RenderScript |
| 1419 | */ |
| 1420 | public static RenderScript create(Context ctx) { |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1421 | return create(ctx, ContextType.NORMAL); |
| 1422 | } |
| 1423 | |
| 1424 | /** |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1425 | * calls create(ctx, ct, CREATE_FLAG_NONE) |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1426 | * |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1427 | * See documentation for @create for details |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1428 | * |
| 1429 | * @param ctx The context. |
| Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 1430 | * @param ct The type of context to be created. |
| Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1431 | * @return RenderScript |
| 1432 | */ |
| 1433 | public static RenderScript create(Context ctx, ContextType ct) { |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1434 | return create(ctx, ct, CREATE_FLAG_NONE); |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1437 | |
| 1438 | /** |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1439 | * Gets or creates a RenderScript context of the specified type. |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 1440 | * |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1441 | * The returned context will be cached for future reuse within |
| 1442 | * the process. When an application is finished using |
| 1443 | * RenderScript it should call releaseAllContexts() |
| 1444 | * |
| 1445 | * A process context is a context designed for easy creation and |
| 1446 | * lifecycle management. Multiple calls to this function will |
| 1447 | * return the same object provided they are called with the same |
| 1448 | * options. This allows it to be used any time a RenderScript |
| 1449 | * context is needed. |
| 1450 | * |
| 1451 | * Prior to API 23 this always created a new context. |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 1452 | * |
| 1453 | * @param ctx The context. |
| 1454 | * @param ct The type of context to be created. |
| 1455 | * @param flags The OR of the CREATE_FLAG_* options desired |
| 1456 | * @return RenderScript |
| 1457 | */ |
| Tim Murray | fd710e7 | 2014-06-06 11:10:45 -0700 | [diff] [blame] | 1458 | public static RenderScript create(Context ctx, ContextType ct, int flags) { |
| Jason Sams | 26e9051 | 2014-05-07 14:23:27 -0700 | [diff] [blame] | 1459 | int v = ctx.getApplicationInfo().targetSdkVersion; |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1460 | return create(ctx, v, ct, flags); |
| 1461 | } |
| 1462 | |
| 1463 | /** |
| 1464 | * calls create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE) |
| 1465 | * |
| 1466 | * Used by the RenderScriptThunker to maintain backward compatibility. |
| 1467 | * |
| 1468 | * @hide |
| 1469 | * @param ctx The context. |
| 1470 | * @param sdkVersion The target SDK Version. |
| 1471 | * @return RenderScript |
| 1472 | */ |
| 1473 | public static RenderScript create(Context ctx, int sdkVersion) { |
| 1474 | return create(ctx, sdkVersion, ContextType.NORMAL, CREATE_FLAG_NONE); |
| 1475 | } |
| 1476 | |
| 1477 | /** |
| 1478 | * Gets or creates a RenderScript context of the specified type. |
| 1479 | * |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1480 | * @param ctx The context. |
| 1481 | * @param ct The type of context to be created. |
| 1482 | * @param sdkVersion The target SDK Version. |
| 1483 | * @param flags The OR of the CREATE_FLAG_* options desired |
| 1484 | * @return RenderScript |
| 1485 | */ |
| Jason Sams | 6a420b5 | 2015-03-30 15:31:26 -0700 | [diff] [blame] | 1486 | private static RenderScript create(Context ctx, int sdkVersion, ContextType ct, int flags) { |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1487 | if (sdkVersion < 23) { |
| 1488 | return internalCreate(ctx, sdkVersion, ct, flags); |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | synchronized (mProcessContextList) { |
| 1492 | for (RenderScript prs : mProcessContextList) { |
| 1493 | if ((prs.mContextType == ct) && |
| 1494 | (prs.mContextFlags == flags) && |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1495 | (prs.mContextSdkVersion == sdkVersion)) { |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1496 | |
| 1497 | return prs; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| Miao Wang | a4e5adf | 2015-03-23 11:09:56 -0700 | [diff] [blame] | 1501 | RenderScript prs = internalCreate(ctx, sdkVersion, ct, flags); |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1502 | prs.mIsProcessContext = true; |
| 1503 | mProcessContextList.add(prs); |
| 1504 | return prs; |
| 1505 | } |
| Jason Sams | 1a4e1f3e | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1506 | } |
| 1507 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1508 | /** |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1509 | * Releases all the process contexts. This is the same as |
| 1510 | * calling .destroy() on each unique context retreived with |
| 1511 | * create(...). If no contexts have been created this |
| 1512 | * function does nothing. |
| 1513 | * |
| 1514 | * Typically you call this when your application is losing focus |
| 1515 | * and will not be using a context for some time. |
| 1516 | * |
| 1517 | * This has no effect on a context created with |
| 1518 | * createMultiContext() |
| 1519 | */ |
| 1520 | public static void releaseAllContexts() { |
| 1521 | ArrayList<RenderScript> oldList; |
| 1522 | synchronized (mProcessContextList) { |
| 1523 | oldList = mProcessContextList; |
| 1524 | mProcessContextList = new ArrayList<RenderScript>(); |
| 1525 | } |
| 1526 | |
| 1527 | for (RenderScript prs : oldList) { |
| 1528 | prs.mIsProcessContext = false; |
| 1529 | prs.destroy(); |
| 1530 | } |
| 1531 | oldList.clear(); |
| 1532 | } |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | /** |
| 1537 | * Create a RenderScript context. |
| 1538 | * |
| 1539 | * This is an advanced function intended for applications which |
| 1540 | * need to create more than one RenderScript context to be used |
| 1541 | * at the same time. |
| 1542 | * |
| 1543 | * If you need a single context please use create() |
| 1544 | * |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1545 | * @param ctx The context. |
| 1546 | * @return RenderScript |
| 1547 | */ |
| 1548 | public static RenderScript createMultiContext(Context ctx, ContextType ct, int flags, int API_number) { |
| 1549 | return internalCreate(ctx, API_number, ct, flags); |
| 1550 | } |
| 1551 | |
| 1552 | |
| 1553 | /** |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1554 | * Print the currently available debugging information about the state of |
| 1555 | * the RS context to the log. |
| 1556 | * |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1557 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1558 | public void contextDump() { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 1559 | validate(); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1560 | nContextDump(0); |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 1561 | } |
| 1562 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1563 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1564 | * Wait for any pending asynchronous opeations (such as copies to a RS |
| 1565 | * allocation or RS script executions) to complete. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1566 | * |
| 1567 | */ |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 1568 | public void finish() { |
| 1569 | nContextFinish(); |
| 1570 | } |
| 1571 | |
| Jason Sams | d22a6f0 | 2015-02-19 17:19:52 -0800 | [diff] [blame] | 1572 | private void helpDestroy() { |
| 1573 | boolean shouldDestroy = false; |
| 1574 | synchronized(this) { |
| 1575 | if (!mDestroyed) { |
| 1576 | shouldDestroy = true; |
| 1577 | mDestroyed = true; |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | if (shouldDestroy) { |
| 1582 | nContextFinish(); |
| 1583 | |
| 1584 | nContextDeinitToClient(mContext); |
| 1585 | mMessageThread.mRun = false; |
| 1586 | try { |
| 1587 | mMessageThread.join(); |
| 1588 | } catch(InterruptedException e) { |
| 1589 | } |
| 1590 | |
| 1591 | nContextDestroy(); |
| 1592 | |
| 1593 | nDeviceDestroy(mDev); |
| 1594 | mDev = 0; |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | protected void finalize() throws Throwable { |
| 1599 | helpDestroy(); |
| 1600 | super.finalize(); |
| 1601 | } |
| 1602 | |
| 1603 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1604 | /** |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1605 | * Destroys this RenderScript context. Once this function is called, |
| 1606 | * using this context or any objects belonging to this context is |
| 1607 | * illegal. |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1608 | * |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1609 | * API 23+, this function is a NOP if the context was created |
| 1610 | * with create(). Please use releaseAllContexts() to clean up |
| 1611 | * contexts created with the create function. |
| 1612 | * |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1613 | */ |
| Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 1614 | public void destroy() { |
| Jason Sams | e16da12 | 2015-03-18 17:04:18 -0700 | [diff] [blame] | 1615 | if (mIsProcessContext) { |
| 1616 | // users cannot destroy a process context |
| 1617 | return; |
| 1618 | } |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 1619 | validate(); |
| Jason Sams | d22a6f0 | 2015-02-19 17:19:52 -0800 | [diff] [blame] | 1620 | helpDestroy(); |
| Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 1621 | } |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1622 | |
| Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 1623 | boolean isAlive() { |
| 1624 | return mContext != 0; |
| 1625 | } |
| 1626 | |
| Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1627 | long safeID(BaseObj o) { |
| Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 1628 | if(o != null) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1629 | return o.getID(this); |
| Jason Sams | d8e4161 | 2009-08-20 17:22:40 -0700 | [diff] [blame] | 1630 | } |
| Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 1631 | return 0; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1632 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1633 | } |