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