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