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